Big reorganization into module-compatible structure

Follow Gradle conventions for a multi-module build.
Top level modules:

* rhino-runtime: Basic Rhino runtime, enough to run scripts
* rhino-tools: Adds Shell, compiler, "Global" object
* rhino-xml: Add E4X
* rhino: Uber-JAR containing all of the above
* rhino-engine: Java ScriptEngine plug-in
* tests: Tests, which depend on all above

Add proper Java module-info files for each module, and sure that
everything works correctly in the new module system.
This commit is contained in:
Greg Brail 2023-07-31 15:47:41 -07:00
Родитель c6a873f61f
Коммит e3d6b16aa2
4653 изменённых файлов: 281 добавлений и 597 удалений

17
.github/workflows/gradle.yml поставляемый
Просмотреть файл

@ -15,7 +15,7 @@ jobs:
# Some tests require more CPU, and all can use multiple CPUs
max-parallel: 1
matrix:
java: [ '8', '11', '17' ]
java: [ '11', '17' ]
name: Rhino Java ${{ matrix.java }}
steps:
- name: Checkout
@ -31,21 +31,12 @@ jobs:
with:
java-version: ${{ matrix.java }}
distribution: 'adopt'
- if: matrix.java == '8'
name: Check everything with Gradle on Java 8
run: ./gradlew check jacocoTestReport
- if: matrix.java != '8'
name: Check everything with Gradle, modular Java
- name: Check everything with Gradle
run: >-
./gradlew check jacocoTestReport
-Dorg.gradle.jvmargs="--add-exports jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED
--add-exports jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED
--add-exports jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED
--add-exports jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED
--add-exports jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED"
./gradlew check
- name: Upload results
uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 # v3.1.3
with:
name: reports
path: buildGradle/reports
path: build/reports

8
.gitignore поставляемый
Просмотреть файл

@ -4,27 +4,25 @@
# build directories
build/
lib/
buildGradle
# artifacts
*.zip
*.iml
.idea/
out/
target/
.gradle
*~
# eclipse
.classpath
.project
test262
bin/
.settings/
# idea
rhino.ipr
rhino.iws
# VSCode
.vscode

2
.gitmodules поставляемый
Просмотреть файл

@ -1,3 +1,3 @@
[submodule "test262"]
path = test262
path = tests/test262
url = https://github.com/tc39/test262.git

Просмотреть файл

@ -1,515 +0,0 @@
plugins {
id 'java'
id 'idea'
id 'eclipse'
id 'maven-publish'
id 'signing'
id 'jacoco'
id 'distribution'
id 'checkstyle'
id 'com.diffplug.spotless' version "5.12.1"
id 'com.github.spotbugs' version "4.7.1"
}
tasks.withType(JavaCompile) {
sourceCompatibility = 1.8
targetCompatibility = 1.8
options.encoding = "UTF-8"
options.compilerArgs = [ "-Xlint:deprecation,unchecked" ]
}
compileTestJava {
options.compilerArgs = [ ]
}
repositories {
mavenCentral()
}
sourceSets {
main {
java {
srcDirs 'src', 'toolsrc', 'xmlimplsrc'
}
resources {
srcDirs 'src', 'toolsrc'
exclude "build.xml"
exclude "manifest"
}
}
test {
java {
srcDirs "testsrc", 'examples'
exclude 'tests/**'
}
resources {
srcDirs "testsrc"
}
}
jmh {
java {
srcDirs "benchmarks"
}
compileClasspath += sourceSets.test.runtimeClasspath
runtimeClasspath += sourceSets.test.runtimeClasspath
}
}
dependencies {
testImplementation "junit:junit:4.13.2"
testImplementation "org.yaml:snakeyaml:1.28"
testImplementation "javax.xml.soap:javax.xml.soap-api:1.4.0"
jmhImplementation project
jmhImplementation 'org.openjdk.jmh:jmh-core:1.27'
jmhAnnotationProcessor 'org.openjdk.jmh:jmh-generator-annprocess:1.27'
}
test {
useJUnit()
exclude "**/benchmarks/**"
jvmArgs += '-Xss1280k'
if (JavaVersion.current() > JavaVersion.VERSION_1_8) {
jvmArgs += ['--add-opens', 'java.desktop/javax.swing.table=ALL-UNNAMED']
}
jacoco.excludes = ['**/testsrc_tests_ecma_3_RegExp_perlstress*']
systemProperty 'java.awt.headless', 'true'
systemProperty 'mozilla.js.tests', 'testsrc/tests'
systemProperty 'mozilla.js.tests.timeout', 60000
systemProperty 'user.language', 'en'
systemProperty 'user.country', 'US'
systemProperty 'user.timezone', 'America/Los_Angeles'
systemProperty 'file.encoding', 'UTF-8'
if (System.getProperty('quick') != null) {
systemProperty 'TEST_OPTLEVEL', -1
} else if (System.getProperty('optLevel')) {
systemProperty 'TEST_OPTLEVEL', System.getProperty('optLevel')
}
systemProperty 'test262properties', System.getProperty('test262properties')
if (System.getProperty('updateTest262properties') != null) {
systemProperty 'updateTest262properties', System.getProperty('updateTest262properties')
}
maxHeapSize = "1g"
testLogging.showStandardStreams = true
// Many tests do not clean up contexts properly. This makes the tests much
// more resilient at the expense of performance.
forkEvery = 1
maxParallelForks = 64
}
task sunSpiderBenchmark(type: JavaExec) {
classpath = sourceSets.jmh.runtimeClasspath
mainClass = 'org.openjdk.jmh.Main'
args '-f', '1', '-bm', 'avgt', 'SunSpider'
}
task v8Benchmark(type: JavaExec) {
classpath = sourceSets.jmh.runtimeClasspath
mainClass = 'org.openjdk.jmh.Main'
args '-f', '1', '-i', '10', '-bm', 'avgt', '-tu', 'us', 'V8'
}
task testBenchmark() {}
testBenchmark.dependsOn sunSpiderBenchmark
testBenchmark.dependsOn v8Benchmark
task microBenchmark(type: JavaExec, description: 'JMH micro benchmark') {
def benchmark = System.getProperty('benchmark')
if (benchmark == null) {
benchmark = "MathBenchmark"
}
classpath = sourceSets.jmh.runtimeClasspath
mainClass = 'org.openjdk.jmh.Main'
args '-f', '1', '-bm', 'avgt', '-tu', 'ns', '-r', '5', benchmark
}
task listBenchmarks(type: JavaExec, description: 'JMH benchmarks') {
classpath = sourceSets.jmh.runtimeClasspath
mainClass = 'org.openjdk.jmh.Main'
args '-lp'
}
task jmhHelp(type: JavaExec, description: 'JMH benchmarks') {
classpath = sourceSets.jmh.runtimeClasspath
mainClass = 'org.openjdk.jmh.Main'
args '-help'
}
idea {
module {
excludeDirs += file('testsrc/tests/src')
excludeDirs += file('buildGradle')
excludeDirs += file('build')
excludeDirs += file('.idea')
excludeDirs += file('lib')
}
}
tasks.withType(AbstractArchiveTask).configureEach {
// Reproducible jar files
preserveFileTimestamps = false
reproducibleFileOrder = true
}
task runtimeJar(type: Jar) {
dependsOn compileJava
archiveBaseName = 'rhino-runtime'
from sourceSets.main.output
from ('LICENSE.txt') {
into 'META-INF'
}
from ('NOTICE.txt') {
into 'META-INF'
}
excludes = ["org/mozilla/javascript/tools", "org/mozilla/javascript/engine/**", "META-INF/services/**"]
manifest {
attributes(
"Manifest-Version": "1.0",
"Implementation-Version": project.version,
"Implementation-Title": "Mozilla Rhino",
"Implementation-Vendor": "Mozilla Foundation",
"Implementation-URL": "http://www.mozilla.org/rhino",
"Bundle-ManifestVersion": "2",
"Bundle-SymbolicName": "org.mozilla.rhino-runtime",
"Bundle-Version": project.version.replaceAll("-.*", ""),
"Export-Package": "org.mozilla.javascript,org.mozilla.javascript.ast,org.mozilla.javascript.annotations",
"Import-Package": "javax.lang.model,javax.script"
)
}
}
task engineJar(type: Jar) {
dependsOn compileJava
archiveBaseName = 'rhino-engine'
from (sourceSets.main.output) {
include 'org/mozilla/javascript/engine/**'
include 'META-INF/services/**'
}
from ('LICENSE.txt') {
into 'META-INF'
}
manifest {
attributes(
"Manifest-Version": "1.0",
"Implementation-Version": project.version,
"Implementation-Title": "Mozilla Rhino ScriptEngine",
"Implementation-Vendor": "Mozilla Foundation",
"Implementation-URL": "http://www.mozilla.org/rhino",
"Automatic-Module-Name": "org.mozilla.rhino.engine"
)
}
}
jar {
dependsOn compileJava
from ('LICENSE.txt') {
into 'META-INF'
}
from ('NOTICE.txt') {
into 'META-INF'
}
from ('NOTICE-tools.txt') {
into 'META-INF'
}
from sourceSets.main.output
excludes = ["org/mozilla/javascript/engine/**", "META-INF/services/**"]
// Class ImplementationVersion uses 'Implementation-Title'
manifest {
attributes(
"Manifest-Version": "1.0",
"Main-Class": "org.mozilla.javascript.tools.shell.Main",
"Implementation-Version": project.version,
"Implementation-Title": "Mozilla Rhino",
"Implementation-Vendor": "Mozilla Foundation",
"Implementation-URL": "http://www.mozilla.org/rhino",
"Automatic-Module-Name": "org.mozilla.rhino",
"Bundle-ManifestVersion": "2",
"Bundle-SymbolicName": "org.mozilla.rhino",
"Bundle-Version": project.version.replaceAll("-.*", ""),
"Export-Package": "org.mozilla.javascript,org.mozilla.javascript.ast,org.mozilla.javascript.annotations",
"Import-Package": "javax.lang.model,javax.script"
)
}
}
javadoc {
options.addBooleanOption("-allow-script-in-comments", true)
options.addStringOption('Xdoclint:html', '-quiet')
}
task javadocJar(type: Jar) {
archiveClassifier = 'javadoc'
from javadoc
}
task runtimeJavadocJar(type: Jar) {
archiveClassifier = 'javadoc'
from javadoc
exclude 'org/mozilla/javascript/tools', 'org/mozilla/javascript/engine'
}
task engineJavadocJar(type: Jar) {
archiveClassifier = 'javadoc'
from javadoc
include 'org/mozilla/javascript/engine/**'
}
task sourceJar(type: Jar) {
from sourceSets.main.allJava
archiveClassifier = 'sources'
from ('LICENSE.txt') {
into 'META-INF'
}
from ('NOTICE.txt') {
into 'META-INF'
}
from ('NOTICE-tools.txt') {
into 'META-INF'
}
}
task runtimeSourceJar(type: Jar) {
archiveClassifier = 'sources'
from sourceSets.main.allJava
exclude 'org/mozilla/javascript/tools', 'org/mozilla/javascript/engine'
from ('LICENSE.txt') {
into 'META-INF'
}
from ('NOTICE.txt') {
into 'META-INF'
}
}
task engineSourceJar(type: Jar) {
archiveClassifier = 'sources'
from sourceSets.main.allJava
include 'org/mozilla/javascript/engine/**'
from ('LICENSE.txt') {
into 'META-INF'
}
}
publishing {
publications {
rhino(MavenPublication) {
groupId 'org.mozilla'
artifactId 'rhino'
artifacts = [jar, sourceJar, javadocJar]
pom.withXml {
def root = asNode()
root.appendNode('description', """
Rhino is an open-source implementation of JavaScript written entirely in Java.
It is typically embedded into Java applications to provide scripting to end users.
Full jar including tools, excluding the JSR-223 Script Engine wrapper.
""")
root.appendNode("url", "https://mozilla.github.io/rhino/")
def p = root.appendNode("parent")
p.appendNode("groupId", "org.sonatype.oss")
p.appendNode("artifactId", "oss-parent")
p.appendNode("version", "7")
def l = root.appendNode("licenses").appendNode("license")
l.appendNode("name", "Mozilla Public License, Version 2.0")
l.appendNode("url", "http://www.mozilla.org/MPL/2.0/index.txt")
def scm = root.appendNode("scm")
scm.appendNode("connection", "scm:git:git@github.com:mozilla/rhino.git")
scm.appendNode("developerConnection", "scm:git:git@github.com:mozilla/rhino.git")
scm.appendNode("url", "git@github.com:mozilla/rhino.git")
def o = root.appendNode("organization")
o.appendNode("name", "The Mozilla Foundation")
o.appendNode("url", "http://www.mozilla.org")
}
}
rhinoruntime(MavenPublication) {
groupId 'org.mozilla'
artifactId 'rhino-runtime'
artifacts = [runtimeJar, runtimeSourceJar, runtimeJavadocJar]
pom.withXml {
def root = asNode()
root.appendNode('description', """
Rhino JavaScript runtime jar, excludes tools & JSR-223 Script Engine wrapper.
""")
root.appendNode("url", "https://mozilla.github.io/rhino/")
def p = root.appendNode("parent")
p.appendNode("groupId", "org.sonatype.oss")
p.appendNode("artifactId", "oss-parent")
p.appendNode("version", "7")
def l = root.appendNode("licenses").appendNode("license")
l.appendNode("name", "Mozilla Public License, Version 2.0")
l.appendNode("url", "http://www.mozilla.org/MPL/2.0/index.txt")
def scm = root.appendNode("scm")
scm.appendNode("connection", "scm:git:git@github.com:mozilla/rhino.git")
scm.appendNode("developerConnection", "scm:git:git@github.com:mozilla/rhino.git")
scm.appendNode("url", "git@github.com:mozilla/rhino.git")
def o = root.appendNode("organization")
o.appendNode("name", "The Mozilla Foundation")
o.appendNode("url", "http://www.mozilla.org")
}
}
rhinoengine(MavenPublication) {
groupId 'org.mozilla'
artifactId 'rhino-engine'
artifacts = [engineJar, engineSourceJar, engineJavadocJar]
pom.withXml {
def root = asNode()
root.appendNode('description', """
Rhino Javascript JSR-223 Script Engine wrapper.
""")
root.appendNode("url", "https://mozilla.github.io/rhino/")
def p = root.appendNode("parent")
p.appendNode("groupId", "org.sonatype.oss")
p.appendNode("artifactId", "oss-parent")
p.appendNode("version", "7")
def l = root.appendNode("licenses").appendNode("license")
l.appendNode("name", "Mozilla Public License, Version 2.0")
l.appendNode("url", "http://www.mozilla.org/MPL/2.0/index.txt")
def scm = root.appendNode("scm")
scm.appendNode("connection", "scm:git:git@github.com:mozilla/rhino.git")
scm.appendNode("developerConnection", "scm:git:git@github.com:mozilla/rhino.git")
scm.appendNode("url", "git@github.com:mozilla/rhino.git")
def o = root.appendNode("organization")
o.appendNode("name", "The Mozilla Foundation")
o.appendNode("url", "http://www.mozilla.org")
def deps = root.appendNode("dependencies")
def rhino = deps.appendNode("dependency")
rhino.appendNode("groupId", "org.mozilla")
rhino.appendNode("artifactId", "rhino")
rhino.appendNode("version", getVersion())
}
}
}
if (project.hasProperty("mavenPassword")) {
repositories {
maven {
credentials {
username mavenUser
password mavenPassword
}
if (project.version.endsWith('-SNAPSHOT')) {
url mavenSnapshotRepo
} else {
url mavenReleaseRepo
}
}
}
}
}
signing {
if (project.hasProperty('SIGNINGKEY')) {
// Check for ORG_GRADLE_PROJECT_SIGNINGKEY environment variable for use in CI system.
// Otherwise, do not sign.
def signingKey = getProperty('SIGNINGKEY')
def signingPassword = getProperty('SIGNINGPASSWORD')
useInMemoryPgpKeys(signingKey, signingPassword)
sign publishing.publications.rhino
sign publishing.publications.rhinoengine
sign publishing.publications.rhinoruntime
}
}
spotbugs {
effort = "less"
reportLevel = "medium"
excludeFilter = file("./spotbugs-exclude.xml")
}
spotless {
java {
googleJavaFormat().aosp()
}
}
if (JavaVersion.current() > JavaVersion.VERSION_15
&& (!System.properties.containsKey('org.gradle.jvmargs')
|| !System.properties.get('org.gradle.jvmargs').contains('com.sun.tools.javac.api'))
&& (!project.hasProperty('org.gradle.jvmargs')
|| !project.property('org.gradle.jvmargs').contains('com.sun.tools.javac.api'))) {
tasks.named('check') {
doFirst {
logger.warn('WARNING: spotless plugin removed from check due to bug, ' + \
'see README for a workaround when building with Java 16+.')
}
}
spotless.enforceCheck false
}
jacocoTestReport {
dependsOn test
reports {
csv.required = true
html.required = true
}
}
checkstyle {
configFile = file("${projectDir}/checkstyle.xml")
sourceSets = [ project.sourceSets.main ]
}
distributions {
main {
contents {
from(sourceSets.main.java) {
into 'rhino' + project.version + '/src'
}
from(sourceSets.main.resources) {
exclude '**/*.java'
into 'rhino' + project.version + '/src'
}
from(javadoc.destinationDir) {
into 'rhino' + project.version + '/docs'
}
from(jar.outputs.files) {
into 'rhino' + project.version + '/lib'
}
from(runtimeJar.outputs.files) {
into 'rhino' + project.version + '/lib'
}
from(engineJar.outputs.files) {
into 'rhino' + project.version + '/lib'
}
from(file(".")) {
include '*.txt', '*.md', 'build.gradle', 'gradle.properties',
'gradle/**', 'gradlew', 'man/*.1'
into 'rhino' + project.version
}
into "/"
}
}
}
distTar {
dependsOn javadoc, jar
compression = Compression.GZIP
archiveExtension = 'tar.gz'
}
distZip.dependsOn javadoc, jar, sourceJar, runtimeSourceJar

12
buildSrc/build.gradle Normal file
Просмотреть файл

@ -0,0 +1,12 @@
plugins {
id 'groovy-gradle-plugin'
}
repositories {
gradlePluginPortal()
}
dependencies {
implementation 'com.diffplug.spotless:spotless-plugin-gradle:6.20.0'
implementation 'com.github.spotbugs.snom:spotbugs-gradle-plugin:5.0.14'
}

1
buildSrc/settings.gradle Normal file
Просмотреть файл

@ -0,0 +1 @@
rootProject.name = 'rhino-conventions'

Просмотреть файл

@ -0,0 +1,35 @@
plugins {
id 'java-library'
id 'com.diffplug.spotless'
}
repositories {
mavenCentral()
}
dependencies {
testImplementation "junit:junit:4.13.2"
testImplementation "org.yaml:snakeyaml:1.28"
testImplementation "javax.xml.soap:javax.xml.soap-api:1.4.0"
}
java {
toolchain {
languageVersion = JavaLanguageVersion.of(11)
}
}
compileJava {
options.compilerArgs = ['-Xlint:deprecation,unchecked']
}
test {
useJUnit()
}
spotless {
java {
// Newer versions of GoogleJavaFormat seem to require JDK 15+
googleJavaFormat('1.10.0').aosp()
}
}

Просмотреть файл

@ -0,0 +1,37 @@
plugins {
id 'rhino.java-conventions'
id 'com.github.spotbugs'
}
version = project.version
tasks.named('compileJava') {
options.javaModuleVersion = provider { version }
}
tasks.withType(Jar).configureEach {
manifest {
attributes (
"Implementation-Version": project.version,
"Implementation-Title": "Mozilla Rhino",
"Implementation-Vendor": "Mozilla Foundation",
"Implementation-URL": "http://github.com/mozilla/rhino",
)
}
}
spotbugs {
effort = "less"
reportLevel = "medium"
excludeFilter = file("${projectDir}/../spotbugs-exclude.xml")
}
spotbugsMain {
reports {
html {
required = true
outputLocation = file("$buildDir/reports/spotbugs/main/spotbugs.html")
stylesheet = 'fancy-hist.xsl'
}
}
}

9
examples/build.gradle Normal file
Просмотреть файл

@ -0,0 +1,9 @@
plugins {
id 'rhino.java-conventions'
}
dependencies {
implementation project(':rhino-runtime')
implementation project(':rhino-tools')
implementation project(':rhino-xml')
}

Просмотреть файл

Просмотреть файл

Просмотреть файл

Просмотреть файл

Просмотреть файл

Просмотреть файл

Просмотреть файл

Просмотреть файл

Просмотреть файл

Просмотреть файл

Просмотреть файл

Просмотреть файл

Просмотреть файл

Просмотреть файл

Просмотреть файл

Просмотреть файл

Просмотреть файл

Просмотреть файл

Просмотреть файл

Просмотреть файл

@ -1,7 +1,6 @@
rootProject.name=rhino
group=org.mozilla
version=1.7.16-SNAPSHOT
buildDir=buildGradle
mavenSnapshotRepo=https://oss.sonatype.org/content/repositories/snapshots
mavenReleaseRepo=https://oss.sonatype.org/service/local/staging/deploy/maven2/
org.gradle.caching=true

2
gradle/wrapper/gradle-wrapper.properties поставляемый
Просмотреть файл

@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.2.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

10
gradlew поставляемый
Просмотреть файл

@ -1,7 +1,7 @@
#!/bin/sh
#
# Copyright © 2015-2021 the original authors.
# Copyright © 2015-2021 the original authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@ -32,10 +32,10 @@
# Busybox and similar reduced shells will NOT work, because this script
# requires all of these POSIX shell features:
# * functions;
# * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
# «${var#prefix}», «${var%suffix}», and «$( cmd )»;
# * compound commands having a testable exit status, especially «case»;
# * various built-in commands including «command», «set», and «ulimit».
# * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
# «${var#prefix}», «${var%suffix}», and «$( cmd )»;
# * compound commands having a testable exit status, especially «case»;
# * various built-in commands including «command», «set», and «ulimit».
#
# Important for patching:
#

Просмотреть файл

@ -0,0 +1,7 @@
plugins {
id 'rhino.library-conventions'
}
dependencies {
implementation project(':rhino-runtime')
}

Просмотреть файл

@ -0,0 +1,6 @@
module org.mozilla.rhino.engine {
exports org.mozilla.javascript.engine;
requires org.mozilla.rhino.runtime;
requires java.scripting;
}

Просмотреть файл

@ -0,0 +1,3 @@
plugins {
id 'rhino.library-conventions'
}

Просмотреть файл

@ -0,0 +1,16 @@
module org.mozilla.rhino.runtime {
exports org.mozilla.classfile;
exports org.mozilla.javascript;
exports org.mozilla.javascript.annotations;
exports org.mozilla.javascript.ast;
exports org.mozilla.javascript.commonjs.module;
exports org.mozilla.javascript.commonjs.module.provider;
exports org.mozilla.javascript.debug;
exports org.mozilla.javascript.optimizer;
exports org.mozilla.javascript.serialize;
exports org.mozilla.javascript.typedarrays;
exports org.mozilla.javascript.xml;
requires java.compiler;
requires java.desktop;
}

Некоторые файлы не были показаны из-за слишком большого количества измененных файлов Показать больше