Skip to content

Commit 47aecbf

Browse files
committed
A few more console adjustments:
* Move "run" tasks to rhino-tools from rhino-all * Document various ways to run the shell # Conflicts: # rhino-all/build.gradle
1 parent c0f01fa commit 47aecbf

File tree

9 files changed

+122
-40
lines changed

9 files changed

+122
-40
lines changed

README.md

Lines changed: 51 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,21 @@ Rhino is an implementation of JavaScript in Java.
88

99
Rhino is licensed under the [MPL 2.0](./LICENSE.txt).
1010

11+
## Summary
12+
13+
Rhino requires Java 11 or higher to run, and 17 or higher to build. Java 21
14+
or 25 is highly recommended.
15+
16+
To build and run a Rhino shell:
17+
18+
./gradlew run -q --console=plain
19+
20+
To run the tests:
21+
22+
git submodule init
23+
git submodule update
24+
./gradlew check
25+
1126
## Releases
1227

1328
The current release is <a href="https://github.com/mozilla/rhino/releases/tag/Rhino1_9_0_Release">Rhino 1.9.0</a>. Please see the [Release Notes](./RELEASE-NOTES.md).
@@ -43,11 +58,9 @@ features from ES6, and ES2016+ are implemented in Rhino.
4358

4459
Information for script builders and embedders:
4560

46-
[Archived](http://web.archive.org/web/20210304081342/https://developer.mozilla.org/en-US/docs/Mozilla/Projects/Rhino/Documentation)
61+
[Documentation](https://rhino.github.io)
4762

48-
JavaDoc for all the APIs:
49-
50-
[https://javadoc.io/doc/org.mozilla/rhino](https://javadoc.io/doc/org.mozilla/rhino)
63+
[JavaDoc](https://javadoc.io/doc/org.mozilla/rhino)
5164

5265
[List of projects using Rhino](USAGE.md)
5366

@@ -73,17 +86,31 @@ testing but which are not published to Maven Central:
7386
* **benchmarks**: Runs benchmarks using JMH.
7487
* **examples**: Surprisingly, this contains example code.
7588

89+
### Recommendations
90+
91+
All applications that embed rhino need the main "rhino" module. Many applications don't
92+
need anything else -- consider doing the same, for a few reasons:
93+
94+
* While "rhino-engine" implements the Java ScriptEngine interface, this is a strange
95+
abstraction that does not necessarily map well to Rhino.
96+
* "rhino-tools" includes the Global module, which many tools use because it includes
97+
handy built-in functions like "print" and "load". However, these are not part of any
98+
formal standard, and it includes functionality to launch programs and load
99+
files that you may not necessarily want in your environment. (Note that "rhino" includes
100+
an implementation of the "console" object that you may want to use instead.)
101+
76102
## Building
77103

78104
### Requirements
79105

80-
Rhino requires Java 17 or higher to build. The "spotless" tool, which enforces code formatting, will not
81-
run on older Java versions and you will receive a warning. If in doubt, Java 21 works great.
106+
It's recommended to build Rhino using Java 25. However, it will build with Java 17
107+
and up. The "spotless" tool, which enforces code formatting, will not
108+
run on older Java versions -- it will emit a warning.
82109

83110
Rhino runs on Java 11 and higher. The build tools use the "--release" flag to ensure that only
84111
features from Java 11 are used in the product.
85112

86-
The CI tools run the Rhino tests on Java 11, 17, and 21. Regardless of what version of Java you are
113+
The CI tools run the Rhino tests on Java 11, 17, 21, and 25. Regardless of what version of Java you are
87114
building with, you can test on another Java version using the RHINO_TEST_JAVA_VERSION environment variable.
88115

89116
### How to Build
@@ -100,8 +127,22 @@ To just run the Rhino shell, you can do this from the top-level directory:
100127

101128
Alternately, you can build an all-in-one JAR and run that:
102129

103-
./gradlew :rhino-all:build
104-
java -jar rhino-all/build/libs/rhino-all-1.7.16-SNAPSHOT.jar
130+
./gradlew shadowJar
131+
java -jar rhino-all/build/libs/rhino-all-2.0.0-SNAPSHOT.jar
132+
133+
And finally, you can extract the classpath and use it in a variety of ways:
134+
135+
export CLASSPATH=$(./gradlew -q printClasspath)
136+
java org.mozilla.javascript.tools.shell.Main
137+
138+
### JLine-Based Console
139+
140+
If the JLine library is present, the Rhino shell will use it for command-line
141+
editing. The commands above will all include JLine. However, the Gradle wrapper
142+
interferes with JLine's ability to manipulate the terminal. For the best CLI
143+
experience, use either of the last two options, instead of ./gradlew run.
144+
145+
### Benchmarking
105146

106147
You can also run the benchmarks:
107148

@@ -151,6 +192,7 @@ To see an aggregated coverage report for everything, which is probably what you
151192
./gradlew testCodeCoverageReport
152193

153194
The result is in:
195+
154196
./tests/build/reports/jacoco/testCodeCoverageReport/html
155197

156198
## Releasing and publishing new version

buildSrc/src/main/groovy/rhino.java-conventions.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ repositories {
2020
dependencies {
2121
testImplementation platform("org.junit:junit-bom:5.10.3")
2222
testImplementation "org.junit.jupiter:junit-jupiter"
23-
testImplementation "junit:junit:4.13.2"
23+
testImplementation libs.junit4
2424
testRuntimeOnly "org.junit.vintage:junit-vintage-engine"
2525
testRuntimeOnly "org.junit.platform:junit-platform-launcher"
2626
testImplementation "org.hamcrest:hamcrest:3.0"

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ org.gradle.caching=true
88
org.gradle.parallel=true
99
org.gradle.configuration-cache=true
1010
android.useAndroidX=true
11-
org.gradle.jvmargs=--enable-native-access=ALL-UNNAMED
11+
org.gradle.jvmargs=--enable-native-access=ALL-UNNAMED

gradle/libs.versions.toml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[versions]
2+
jline = '3.30.0'
3+
junit4 = '4.13.2'
4+
5+
[libraries]
6+
junit4 = { group = 'junit', name = 'junit', version.ref = 'junit4' }
7+
jline-terminal = { group = 'org.jline', name = 'jline-terminal', version.ref = 'jline' }
8+
jline-reader = { group = 'org.jline', name = 'jline-reader', version.ref = 'jline' }
9+
jline-ffm = { group = 'org.jline', name = 'jline-terminal-ffm', version.ref = 'jline' }
10+
jline-jni = { group = 'org.jline', name = 'jline-terminal-jni', version.ref = 'jline' }
11+
12+
[bundles]
13+
jline-runtime = [ 'jline-ffm', 'jline-jni' ]

it-android/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ if (!System.getenv("ANDROID_HOME") && !localProperties.get("sdk.dir")) {
6464
implementation project(':rhino-tools')
6565
implementation project(':rhino-xml')*/
6666

67-
testImplementation 'junit:junit:4.13.2'
67+
testImplementation libs.junit4
6868
androidTestImplementation 'androidx.test:runner:1.7.0'
6969
androidTestImplementation 'androidx.test.ext:junit:1.3.0'
7070
}

rhino-all/build.gradle

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,16 @@
11
plugins {
22
id 'rhino.library-conventions'
33
id 'com.gradleup.shadow' version '9.3.1'
4-
id 'application'
5-
}
6-
7-
application {
8-
mainClass = 'org.mozilla.javascript.tools.shell.Main'
9-
}
10-
11-
run {
12-
standardInput = System.in
134
}
145

156
dependencies {
167
implementation project(':rhino')
178
implementation project(':rhino-tools')
189
implementation project(':rhino-xml')
19-
runtimeOnly 'org.jline:jline-terminal:3.30.0'
20-
runtimeOnly 'org.jline:jline-reader:3.30.0'
21-
runtimeOnly 'org.jline:jline-terminal-ffm:3.30.0'
22-
runtimeOnly 'org.jline:jline-terminal-jni:3.30.0'
10+
// Include JLine so that the stand-alone JAR gets a nice terminal
11+
runtimeOnly libs.jline.terminal
12+
runtimeOnly libs.jline.reader
13+
runtimeOnly libs.bundles.jline.runtime
2314
}
2415

2516
shadowJar {
@@ -32,14 +23,9 @@ shadowJar {
3223
filesNotMatching('META-INF/services/**') {
3324
duplicatesStrategy = DuplicatesStrategy.FAIL // Or FAIL.
3425
}
35-
}
36-
37-
startScripts {
38-
dependsOn 'shadowJar'
39-
}
40-
41-
startShadowScripts {
42-
dependsOn 'jar'
26+
manifest {
27+
attributes 'Main-Class': 'org.mozilla.javascript.tools.shell.Main'
28+
}
4329
}
4430

4531
publishing {

rhino-tools/build.gradle

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,58 @@
11
plugins {
22
id 'rhino.library-conventions'
3+
id 'application'
4+
}
5+
6+
application {
7+
mainClass = 'org.mozilla.javascript.tools.shell.Main'
8+
}
9+
10+
configurations {
11+
shellOnly
312
}
413

514
dependencies {
615
implementation project(':rhino')
7-
compileOnly 'org.jline:jline-terminal:3.30.0'
8-
compileOnly 'org.jline:jline-reader:3.30.0'
16+
// Dependencies that ensure that we can compile with the JLine library
17+
compileOnly libs.jline.terminal
18+
compileOnly libs.jline.reader
19+
// Dependencies that add JLine only for the "run" task
20+
shellOnly libs.jline.terminal
21+
shellOnly libs.jline.reader
22+
shellOnly libs.bundles.jline.runtime
923
testImplementation project(':testutils')
1024
}
1125

26+
run {
27+
standardInput = System.in
28+
classpath = sourceSets.main.runtimeClasspath +
29+
configurations.shellOnly
30+
}
31+
32+
// This task makes it easier to write other command-line apps
33+
tasks.register('printClassPath') {
34+
def cp = sourceSets.main.runtimeClasspath + configurations.shellOnly
35+
inputs.files(cp)
36+
doLast {
37+
println cp.asPath
38+
}
39+
}
40+
41+
// Easy way to launch the debugger
42+
tasks.register('runDebugger', JavaExec) {
43+
mainClass = 'org.mozilla.javascript.tools.debugger.Main'
44+
classpath = sourceSets.main.runtimeClasspath
45+
}
46+
47+
// This does the same thing as "gradle run" but adds a bit of usability
48+
// since we also have a "runDebugger" task
49+
tasks.register('runCli', JavaExec) {
50+
mainClass = 'org.mozilla.javascript.tools.shell.Main'
51+
classpath = sourceSets.main.runtimeClasspath +
52+
configurations.shellOnly
53+
standardInput = System.in
54+
}
55+
1256
publishing {
1357
publications {
1458
rhinotools(MavenPublication) {

rhino-tools/src/main/java/org/mozilla/javascript/tools/shell/JLineConsoleProvider.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,7 @@ public Console newConsole() {
2929

3030
@Override
3131
public boolean isSupported() {
32-
// Only allow JLine to be used if we have full functionality.
33-
return (terminal != null
34-
&& !Terminal.TYPE_DUMB.equals(terminal.getType())
35-
&& !Terminal.TYPE_DUMB_COLOR.equals(terminal.getType()));
32+
return (terminal != null);
3633
}
3734

3835
@Override

testutils/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ dependencies {
88
implementation project(':rhino')
99
// We need this to be an "implementation" dependency because, in order to be shared
1010
// with tests in other projects, code in here must be in "main".
11-
implementation "junit:junit:4.13.2"
11+
implementation libs.junit4
1212
}

0 commit comments

Comments
 (0)