Repository: polygene-java Updated Branches: refs/heads/develop 3d33ead72 -> 2bdc626a3
build: integrate tools/generator-polygene into the build system ./gradlew :tools:generator:check now runs ~30 permutations, 1m30s here You can also target the test task only: ./gradlew :tools:generator:npmTest A dedicated task can run all the permutations, but it takes a while: ./gradlew :tools:generator:npmTestAll Both tasks automatically installs node, npm, node dependencies and reuse the staged maven repository with the Polygene artifacts. The generators tests then use a Gradle init script to add that local staged maven repository to all builds invocations. I changed the tests to only to ./gradlew classes instead of ./gradlew build, this makes the tests faster. A JUnit compatible test report file is generated so Jenkins can take that into account. The only brittle thing is putting the Polygene version into the package.json file, which is done in-place. I couldnât find a better way for now. Direct npm command line usage still works: npm run test npm run test_all but youâll need to invoke a Gradle task first: ./gradle :tools:generator:generateStageMavenRepositoryInitScript Project: http://git-wip-us.apache.org/repos/asf/polygene-java/repo Commit: http://git-wip-us.apache.org/repos/asf/polygene-java/commit/2bdc626a Tree: http://git-wip-us.apache.org/repos/asf/polygene-java/tree/2bdc626a Diff: http://git-wip-us.apache.org/repos/asf/polygene-java/diff/2bdc626a Branch: refs/heads/develop Commit: 2bdc626a3d76ed6c189be50cdb9d4b52e490b225 Parents: 3d33ead Author: Paul Merlin <[email protected]> Authored: Sun Apr 23 17:40:59 2017 +0200 Committer: Paul Merlin <[email protected]> Committed: Sun Apr 23 17:40:59 2017 +0200 ---------------------------------------------------------------------- .gitignore | 1 + buildSrc/build.gradle | 1 + .../DependenciesDeclarationExtension.groovy | 1 + .../distributions/DistributionsPlugin.groovy | 13 ++- .../gradle/structure/tools/NpmToolPlugin.groovy | 49 +++++++++++ .../gradle-plugins/polygene-tool-npm.properties | 18 ++++ dependencies.gradle | 6 ++ settings.gradle | 2 +- tools/generator-polygene/app/index.js | 3 +- .../app/templates/buildtool/gradle-root.tmpl | 1 - .../buildtool/gradle-wrapper.properties_ | 2 +- .../app/templates/buildtool/settings.tmpl | 16 ---- tools/generator-polygene/build.gradle | 87 ++++++++++++++++++++ tools/generator-polygene/package.json | 7 +- tools/generator-polygene/test/generator_test.js | 39 +++++---- 15 files changed, 203 insertions(+), 43 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/polygene-java/blob/2bdc626a/.gitignore ---------------------------------------------------------------------- diff --git a/.gitignore b/.gitignore index 368ccc0..0fa55ee 100644 --- a/.gitignore +++ b/.gitignore @@ -19,3 +19,4 @@ private/cache node_modules gradle-user-home profile-out* +npm-debug.log \ No newline at end of file http://git-wip-us.apache.org/repos/asf/polygene-java/blob/2bdc626a/buildSrc/build.gradle ---------------------------------------------------------------------- diff --git a/buildSrc/build.gradle b/buildSrc/build.gradle index af68367..b5ac8d6 100644 --- a/buildSrc/build.gradle +++ b/buildSrc/build.gradle @@ -34,6 +34,7 @@ dependencies { compile 'org.apache.httpcomponents:httpclient:4.5.2' compile 'org.apache.httpcomponents:httpmime:4.5.2' compile 'com.bmuschko:gradle-docker-plugin:3.0.5' + compile 'com.moowork.gradle:gradle-node-plugin:1.1.1' testCompile 'junit:junit:4.12' testCompile( 'org.spockframework:spock-core:1.0-groovy-2.4' ) { exclude module: 'groovy-all' } http://git-wip-us.apache.org/repos/asf/polygene-java/blob/2bdc626a/buildSrc/src/main/groovy/org/apache/polygene/gradle/dependencies/DependenciesDeclarationExtension.groovy ---------------------------------------------------------------------- diff --git a/buildSrc/src/main/groovy/org/apache/polygene/gradle/dependencies/DependenciesDeclarationExtension.groovy b/buildSrc/src/main/groovy/org/apache/polygene/gradle/dependencies/DependenciesDeclarationExtension.groovy index afd1ede..9277e62 100644 --- a/buildSrc/src/main/groovy/org/apache/polygene/gradle/dependencies/DependenciesDeclarationExtension.groovy +++ b/buildSrc/src/main/groovy/org/apache/polygene/gradle/dependencies/DependenciesDeclarationExtension.groovy @@ -31,4 +31,5 @@ class DependenciesDeclarationExtension BiConsumer<DependencySubstitution, ModuleComponentSelector> dependencySubstitutionSpec final Map<String, String> buildToolsVersions = [ : ] final Map<String, String> dockerImagesVersions = [ : ] + final Map<String, String> nodeVersions = [ : ] } http://git-wip-us.apache.org/repos/asf/polygene-java/blob/2bdc626a/buildSrc/src/main/groovy/org/apache/polygene/gradle/structure/distributions/DistributionsPlugin.groovy ---------------------------------------------------------------------- diff --git a/buildSrc/src/main/groovy/org/apache/polygene/gradle/structure/distributions/DistributionsPlugin.groovy b/buildSrc/src/main/groovy/org/apache/polygene/gradle/structure/distributions/DistributionsPlugin.groovy index 7de632c..fc03c76 100644 --- a/buildSrc/src/main/groovy/org/apache/polygene/gradle/structure/distributions/DistributionsPlugin.groovy +++ b/buildSrc/src/main/groovy/org/apache/polygene/gradle/structure/distributions/DistributionsPlugin.groovy @@ -458,8 +458,13 @@ class DistributionsPlugin implements Plugin<Project> task.group = TaskGroups.DISTRIBUTION task.description = 'Stages published binaries as a maven repository in the build directory.' releaseSpec.publishedProjects.each { p -> - task.dependsOn "${ p.path }:uploadStageArchives" - task.from "${ p.buildDir }/stage/archives" + p.afterEvaluate { evaluatedProject -> + if( p.plugins.hasPlugin( PublishedCodePlugin ) ) + { + task.dependsOn "${ p.path }:uploadStageArchives" + task.from "${ p.buildDir }/stage/archives" + } + } } task.into project.file( "$project.buildDir/stage/maven-binaries" ) } as Action<Sync> ) @@ -507,8 +512,8 @@ class DistributionsPlugin implements Plugin<Project> } // Copy Maven artifacts using the Gradle IDE Model // Include sources if available, otherwise include javadoc if available - IdeDependenciesExtractor dependenciesExtractor = new IdeDependenciesExtractor() - def ideDependencies = dependenciesExtractor.extractRepoFileDependencies project.dependencies, + IdeDependenciesExtractor dependenciesExtractor = new IdeDependenciesExtractor() + def ideDependencies = dependenciesExtractor.extractRepoFileDependencies project.dependencies, [ configuration ], [ ], true, true ideDependencies.each { IdeExtendedRepoFileDependency ideDependency -> http://git-wip-us.apache.org/repos/asf/polygene-java/blob/2bdc626a/buildSrc/src/main/groovy/org/apache/polygene/gradle/structure/tools/NpmToolPlugin.groovy ---------------------------------------------------------------------- diff --git a/buildSrc/src/main/groovy/org/apache/polygene/gradle/structure/tools/NpmToolPlugin.groovy b/buildSrc/src/main/groovy/org/apache/polygene/gradle/structure/tools/NpmToolPlugin.groovy new file mode 100644 index 0000000..fde64e9 --- /dev/null +++ b/buildSrc/src/main/groovy/org/apache/polygene/gradle/structure/tools/NpmToolPlugin.groovy @@ -0,0 +1,49 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.polygene.gradle.structure.tools + +import com.moowork.gradle.node.NodeExtension +import com.moowork.gradle.node.NodePlugin +import com.moowork.gradle.node.npm.NpmTask +import org.apache.polygene.gradle.BasePlugin +import org.apache.polygene.gradle.dependencies.DependenciesDeclarationExtension +import org.apache.polygene.gradle.dependencies.DependenciesPlugin +import org.gradle.api.Plugin +import org.gradle.api.Project + +class NpmToolPlugin implements Plugin<Project> +{ + @Override + void apply( Project project ) + { + project.plugins.apply BasePlugin + project.plugins.apply DependenciesPlugin + project.plugins.apply NodePlugin + def dependencies = project.rootProject.extensions.getByType( DependenciesDeclarationExtension ) + def node = project.extensions.getByType NodeExtension + node.download = true + node.workDir = project.file( "${ project.buildDir }/node-install" ) + node.npmWorkDir = node.workDir + node.version = dependencies.nodeVersions.node + node.npmVersion = dependencies.nodeVersions.npm + project.tasks.withType( NpmTask ) { NpmTask task -> + task.group = 'node' + task.workingDir = project.projectDir + } + } +} http://git-wip-us.apache.org/repos/asf/polygene-java/blob/2bdc626a/buildSrc/src/main/resources/META-INF/gradle-plugins/polygene-tool-npm.properties ---------------------------------------------------------------------- diff --git a/buildSrc/src/main/resources/META-INF/gradle-plugins/polygene-tool-npm.properties b/buildSrc/src/main/resources/META-INF/gradle-plugins/polygene-tool-npm.properties new file mode 100644 index 0000000..497a480 --- /dev/null +++ b/buildSrc/src/main/resources/META-INF/gradle-plugins/polygene-tool-npm.properties @@ -0,0 +1,18 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +implementation-class=org.apache.polygene.gradle.structure.tools.NpmToolPlugin http://git-wip-us.apache.org/repos/asf/polygene-java/blob/2bdc626a/dependencies.gradle ---------------------------------------------------------------------- diff --git a/dependencies.gradle b/dependencies.gradle index 8e467f4..9cce72d 100644 --- a/dependencies.gradle +++ b/dependencies.gradle @@ -255,6 +255,12 @@ dependencies.dependencySubstitutionSpec = { DependencySubstitution substitution, } } +// NodeJS +dependencies.nodeVersions << [ + node: '6.10.2', + npm: '4.4.4' +] + // Build Tools dependencies.buildToolsVersions << [ jacoco: '0.7.9' http://git-wip-us.apache.org/repos/asf/polygene-java/blob/2bdc626a/settings.gradle ---------------------------------------------------------------------- diff --git a/settings.gradle b/settings.gradle index 0cee4a7..3c44077 100644 --- a/settings.gradle +++ b/settings.gradle @@ -80,7 +80,7 @@ include 'core:api', 'extensions:serialization-messagepack', 'tools:model-detail', 'tools:envisage', -// 'tools:generator-polygene', + 'tools:generator-polygene', // 'tools:qidea', 'tests:regression', 'tests:performance', http://git-wip-us.apache.org/repos/asf/polygene-java/blob/2bdc626a/tools/generator-polygene/app/index.js ---------------------------------------------------------------------- diff --git a/tools/generator-polygene/app/index.js b/tools/generator-polygene/app/index.js index a4a4702..e106698 100644 --- a/tools/generator-polygene/app/index.js +++ b/tools/generator-polygene/app/index.js @@ -21,8 +21,7 @@ var generators = require('yeoman-generator'); var fs = require('fs'); -// TODO: Automate the version here in build system. -var polygeneVersion = "3.0-RC0"; +var polygeneVersion = require(__dirname + '/../package.json').polygene_version; var polygene = {}; http://git-wip-us.apache.org/repos/asf/polygene-java/blob/2bdc626a/tools/generator-polygene/app/templates/buildtool/gradle-root.tmpl ---------------------------------------------------------------------- diff --git a/tools/generator-polygene/app/templates/buildtool/gradle-root.tmpl b/tools/generator-polygene/app/templates/buildtool/gradle-root.tmpl index a6c1f92..52b61d5 100644 --- a/tools/generator-polygene/app/templates/buildtool/gradle-root.tmpl +++ b/tools/generator-polygene/app/templates/buildtool/gradle-root.tmpl @@ -31,7 +31,6 @@ allprojects() { defaultTasks 'assemble' repositories { - mavenLocal() mavenCentral() maven { name 'restlet-repo'; url 'http://maven.restlet.org/' } <% if( polygene.entitystore == 'Jdbm' ) { http://git-wip-us.apache.org/repos/asf/polygene-java/blob/2bdc626a/tools/generator-polygene/app/templates/buildtool/gradle-wrapper.properties_ ---------------------------------------------------------------------- diff --git a/tools/generator-polygene/app/templates/buildtool/gradle-wrapper.properties_ b/tools/generator-polygene/app/templates/buildtool/gradle-wrapper.properties_ index c90307d..63a2f23 100644 --- a/tools/generator-polygene/app/templates/buildtool/gradle-wrapper.properties_ +++ b/tools/generator-polygene/app/templates/buildtool/gradle-wrapper.properties_ @@ -21,4 +21,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-3.5-all.zip http://git-wip-us.apache.org/repos/asf/polygene-java/blob/2bdc626a/tools/generator-polygene/app/templates/buildtool/settings.tmpl ---------------------------------------------------------------------- diff --git a/tools/generator-polygene/app/templates/buildtool/settings.tmpl b/tools/generator-polygene/app/templates/buildtool/settings.tmpl index 9576305..b46209f 100644 --- a/tools/generator-polygene/app/templates/buildtool/settings.tmpl +++ b/tools/generator-polygene/app/templates/buildtool/settings.tmpl @@ -26,19 +26,3 @@ if( polygene.applicationtype === 'Rest API' ) { %> <% } %> rootProject.name = '<%= polygene.name %>' - -validateProject(rootProject, "") - -def validateProject(project, parentName) -{ - assert project.projectDir.isDirectory() - if( new File("$project.projectDir/src/main/java").exists() ) - { - assert project.buildFile.isFile() - } - if( parentName.length() > 0 ) - println "Project: " + project.name - project.children.each { child -> - validateProject(child, project.name) - } -} http://git-wip-us.apache.org/repos/asf/polygene-java/blob/2bdc626a/tools/generator-polygene/build.gradle ---------------------------------------------------------------------- diff --git a/tools/generator-polygene/build.gradle b/tools/generator-polygene/build.gradle new file mode 100644 index 0000000..119f702 --- /dev/null +++ b/tools/generator-polygene/build.gradle @@ -0,0 +1,87 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * + */ + +apply plugin: 'polygene-tool-npm' + +description = "Apache Polygene⢠Project Generator." + +/** + * Modifies package.json in-place to set `polygene_version`. + * Loaded by the generator, see `app/index.js` + */ +def setsCurrentVersionToPackageJson = task( 'setsCurrentVersionToPackageJson' ) { + outputs.upToDateWhen { false } + doLast { + def packageJson = file( 'package.json' ) + packageJson.text = packageJson.text.replaceFirst( /\"polygene_version\": \".*\"/, "\"polygene_version\": \"${project.version}\"" ) + } +} + +/** + * Generate a Gradle init script that registers a maven repository with the currently built artifacts. + * Used by the generator tests. + */ +def generateStageMavenRepositoryInitScript = task( 'generateStageMavenRepositoryInitScript' ) { + def initScript = file( "$buildDir/stagedMavenRepoInitScript.gradle" ) + def repoDir = file( "${ rootProject.rootDir }/distributions/build/stage/maven-binaries" ) + dependsOn ':distributions:stageBinariesMavenRepository' + inputs.property 'polygene_version', project.version + outputs.file initScript + doLast { + initScript.parentFile.mkdirs() + initScript.text = """ + allprojects { + repositories { + maven { + url = "file://${ repoDir.absolutePath }" + } + } + } + """.stripIndent() + } +} + +/** + * Runs the generator tests. + */ +def npmTest = task( 'npmTest', type: NpmTask ) { + dependsOn 'npmInstall', setsCurrentVersionToPackageJson, generateStageMavenRepositoryInitScript + description = 'Runs Polygene generator tests' + args = [ 'run', 'test' ] + inputs.file file( 'package.json' ) + inputs.dir file( 'app' ) + inputs.dir file( 'test' ) + outputs.dir file( "${ buildDir }/reports/tests/npmTest" ) +} +check.dependsOn npmTest + + +/** + * Runs ALL the generator tests. + */ +task( 'npmTestAll', type: NpmTask ) { + dependsOn 'npmInstall', setsCurrentVersionToPackageJson, generateStageMavenRepositoryInitScript + description = 'Runs ALL possible permutations of the Polygene generator tests' + args = [ 'run', 'test_all' ] + inputs.file file( 'package.json' ) + inputs.dir file( 'app' ) + inputs.dir file( 'test' ) + outputs.dir file( "${ buildDir }/reports/tests/npmTestAll" ) +} http://git-wip-us.apache.org/repos/asf/polygene-java/blob/2bdc626a/tools/generator-polygene/package.json ---------------------------------------------------------------------- diff --git a/tools/generator-polygene/package.json b/tools/generator-polygene/package.json index 621773f..5841810 100644 --- a/tools/generator-polygene/package.json +++ b/tools/generator-polygene/package.json @@ -1,9 +1,11 @@ { "name": "generator-polygene", "version": "3.0.0-RC0", + "polygene_version": "0", "description": "Generates an Apache Polygene project.", "scripts": { - "test": "./node_modules/mocha/bin/mocha test/**/*_test.js" + "test": "./node_modules/mocha/bin/mocha test/**/*_test.js --reporter mocha-junit-reporter --reporter-options mochaFile=../../reports/tests/npmTest/generator-polygene.xml", + "test_all": "TEST_ALL=yes ./node_modules/mocha/bin/mocha test/**/*_test.js --reporter mocha-junit-reporter --reporter-options mochaFile=../../reports/tests/npmTestAll/generator-polygene.xml" }, "files": [ "app" @@ -17,9 +19,10 @@ }, "devDependencies": { "mocha": "3.2.0", + "mocha-junit-reporter": "1.13.0", "path": "0.12.7", "shelljs": "0.7.7", "yeoman-assert": "3.0.0", "yeoman-test": "1.6.0" } -} +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/polygene-java/blob/2bdc626a/tools/generator-polygene/test/generator_test.js ---------------------------------------------------------------------- diff --git a/tools/generator-polygene/test/generator_test.js b/tools/generator-polygene/test/generator_test.js index 264ebf4..4779b0a 100644 --- a/tools/generator-polygene/test/generator_test.js +++ b/tools/generator-polygene/test/generator_test.js @@ -97,35 +97,42 @@ featuresset.forEach(function (feature) { }); // All Tests !!!! -appTypes.forEach(function (appType) { - entityStores.forEach(function (entitystore) { - indexings.forEach(function (indexing) { - serializations.forEach(function (serialization) { - cachings.forEach(function (caching) { - metricses.forEach(function (metrics) { - featuresset.forEach(function (features) { - test(appType, entitystore, indexing, serialization, caching, metrics, features) +if(process.env.TEST_ALL == 'yes') { + appTypes.forEach(function (appType) { + entityStores.forEach(function (entitystore) { + indexings.forEach(function (indexing) { + serializations.forEach(function (serialization) { + cachings.forEach(function (caching) { + metricses.forEach(function (metrics) { + featuresset.forEach(function (features) { + test(appType, entitystore, indexing, serialization, caching, metrics, features) + }); }); }); }); }); }); }); -}); +} function test(appType, entityStore, indexing, serialization, caching, metrics, features) { describe('polygene-generator', function () { - this.timeout(10000); - it('generates a Gradle buildable ' + appType + ' Apache Polygene project with ' + var testName = 'generates a Gradle buildable Apache Polygene project with ' + entityStore + 'EntityStore, ' + indexing + 'Indexing, ' - + serialization + 'Serialzation, ' + + serialization + 'Serialization, ' + caching + 'Caching, ' - + metrics + 'Metrics, ' - + ' and ' + features + '.', + + metrics + 'Metrics'; + if(features) { + testName += ', and ' + features; + } + testName += '.'; + var testDirName = testName.replace(new RegExp('[, ]','g'), '_'); + it(testName, function () { + this.timeout(10000); return helpers.run(path.join(__dirname, '../app')) - .inDir(path.join(__dirname, '../build/test-project')) + .inDir(path.join(__dirname, '../build/npm-test/'+testDirName)) .withPrompts({ name: 'test-project', packageName: 'org.apache.polygene.generator.test', @@ -144,5 +151,5 @@ function test(appType, entityStore, indexing, serialization, caching, metrics, f function buildAndVerify(dir) { assert.file(['gradlew', 'settings.gradle', 'build.gradle']); - assert(shell.exec(path.join(dir, 'gradlew') + ' build').code == 0); + assert(shell.exec(path.join(dir, 'gradlew') + ' classes --init-script ../../stagedMavenRepoInitScript.gradle').code == 0); }
