This is an automated email from the ASF dual-hosted git repository. acosentino pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git
The following commit(s) were added to refs/heads/master by this push: new 6277cf6 Improve the maven deployment of the synthetic test jars new 5086fe6 Merge pull request #206 from ppalaga/i184.2 6277cf6 is described below commit 6277cf6dc50712a64465b286183d5a964aab7117 Author: Peter Palaga <ppal...@redhat.com> AuthorDate: Fri Sep 20 11:56:16 2019 +0200 Improve the maven deployment of the synthetic test jars --- build/scripts/generate-test-poms.groovy | 101 ++++++++++++++++++++-- integration-tests/install-reusable-test-jar.txt | 1 - integration-tests/pom.xml | 110 +++++++----------------- pom.xml | 6 ++ 4 files changed, 131 insertions(+), 87 deletions(-) diff --git a/build/scripts/generate-test-poms.groovy b/build/scripts/generate-test-poms.groovy index 3380388..4f04a18 100644 --- a/build/scripts/generate-test-poms.groovy +++ b/build/scripts/generate-test-poms.groovy @@ -53,15 +53,25 @@ */ import groovy.io.FileType +import static org.twdata.maven.mojoexecutor.MojoExecutor.Element +import static org.twdata.maven.mojoexecutor.MojoExecutor.* +import org.apache.maven.project.MavenProject +import org.apache.maven.execution.MavenSession +import org.apache.maven.model.Plugin -new File(project.basedir, 'target').mkdirs() +final String command = properties['itest.jar.command'] -project.basedir.eachFile FileType.DIRECTORIES, { dir -> - final File pomXml = new File(dir, 'pom.xml') - if (pomXml.exists()) { - def pomXmlProject = new XmlParser().parseText(pomXml.getText('UTF-8')) +static boolean isItestModule(MavenProject project) { + return 'jar'.equals(project.packaging) && new File(project.basedir, 'pom.xml').getText('UTF-8').contains('<goal>native-image</goal>') +} + +static void install(MavenProject project, MavenSession session) { + + if (isItestModule(project)) { + def pomXmlProject = new XmlParser().parseText(new File(project.basedir, 'pom.xml').getText('UTF-8')) final String oldArtifactId = pomXmlProject.artifactId.text() final String newArtifactId = oldArtifactId + '-tests' + pomXmlProject.artifactId[0].value = newArtifactId pomXmlProject.name.each { n -> n.value = n.text() + ' :: Tests' } @@ -82,10 +92,89 @@ project.basedir.eachFile FileType.DIRECTORIES, { dir -> pomXmlProject.build.each { n -> n.parent().remove(n) } pomXmlProject.profiles.each { n -> n.parent().remove(n) } - new File(project.basedir, 'target/'+ newArtifactId + '-pom.xml').withWriter( 'UTF-8' ) { out -> + final File outputPom = newPomPath(project, project.artifactId) + outputPom.withWriter( 'UTF-8' ) { out -> final XmlNodePrinter printer = new XmlNodePrinter(new PrintWriter(out)) printer.preserveWhitespace = true printer.print(pomXmlProject) } + final File testJar = testJarPath(project, project.basedir, project.artifactId) + + Class bpmClass = Class.forName("org.apache.maven.plugin.BuildPluginManager"); + Object buildPluginManager = session.lookup(bpmClass.getName()); + executeMojo( + managedPlugin("org.apache.maven.plugins", "maven-install-plugin", project), + goal("install-file"), + configuration( + element("pomFile", outputPom.toString()), + element("version", project.version), + element("file", testJar.toString()) + ), + executionEnvironment( + project, + session, + buildPluginManager + ) + ) + } + +} + +static Plugin managedPlugin(String groupId, String artifactId, MavenProject project) { + for (p in project.build.plugins) { + if (groupId.equals(p.groupId) && artifactId.equals(p.artifactId)) { + println 'Resolved version ' + p.version + ' for ' + groupId +':'+artifactId + return plugin(groupId, artifactId, p.version) + } + } + throw new IllegalStateException('Could not find a managed version of '+ groupId + ':' + artifactId) +} + + +static File newPomPath(MavenProject project, String oldArtifactId) { + return new File(project.basedir, 'target/'+ oldArtifactId + '-tests-pom.xml') +} +static File testJarPath(MavenProject project, File oldDir, String oldArtifactId) { + return new File(oldDir, 'target/' + oldArtifactId + '-' + project.version + '-tests.jar') +} + +static void deploy(MavenProject project, MavenSession session) { + if (isItestModule(project)) { + def distManagementRepo = project.version.endsWith('-SNAPSHOT') ? project.distributionManagement.snapshotRepository : project.distributionManagement.repository + + final File outputPom = newPomPath(project, project.artifactId) + final File testJar = testJarPath(project, project.basedir, project.artifactId) + + Class bpmClass = Class.forName("org.apache.maven.plugin.BuildPluginManager"); + Object buildPluginManager = session.lookup(bpmClass.getName()); + + List<Element> config = []; + config.add(element("repositoryId", distManagementRepo.id)) + config.add(element("url", distManagementRepo.url)) + config.add(element("pomFile", outputPom.toString())) + config.add(element("version", project.version)) + config.add(element("file", testJar.toString())) + + final File testSources = new File(testJar.toString().replace('.jar', '-sources.jar')) + if (testSources.exists()) { + config.add(element("sources", testSources.toString())) + } + final File testJavaDoc = new File(testJar.toString().replace('.jar', '-javadoc.jar')) + if (testJavaDoc.exists()) { + config.add(element("javadoc", testJavaDoc.toString())) + } + + executeMojo( + managedPlugin("org.apache.maven.plugins", "maven-deploy-plugin", project), + goal("deploy-file"), + configuration(config.toArray(new Element[config.size()])), + executionEnvironment( + project, + session, + buildPluginManager + ) + ) } } + + diff --git a/integration-tests/install-reusable-test-jar.txt b/integration-tests/install-reusable-test-jar.txt deleted file mode 100644 index 47207ce..0000000 --- a/integration-tests/install-reusable-test-jar.txt +++ /dev/null @@ -1 +0,0 @@ -This file activates the install-reusable-test-jar profile \ No newline at end of file diff --git a/integration-tests/pom.xml b/integration-tests/pom.xml index 93d975a..180bd6e 100644 --- a/integration-tests/pom.xml +++ b/integration-tests/pom.xml @@ -140,96 +140,46 @@ <artifactId>groovy-maven-plugin</artifactId> <executions> <execution> - <inherited>false</inherited> - <id>generate-test-poms</id> + <id>install-test-poms</id> <goals> <goal>execute</goal> </goals> - <phase>validate</phase> + <phase>install</phase> <configuration> - <source>file:///${project.basedir}/../build/scripts/generate-test-poms.groovy</source> + <source><![CDATA[ + File dir = project.basedir + for (; dir != null && !new File(dir, '.mvn').exists(); dir = dir.getParentFile()) {} + new GroovyShell().parse(new File(dir, 'build/scripts/generate-test-poms.groovy')) + .install(project, session) + ]]></source> + </configuration> + </execution> + <execution> + <id>deploy-test-poms</id> + <goals> + <goal>execute</goal> + </goals> + <phase>install</phase> + <configuration> + <source><![CDATA[ + File dir = project.basedir + for (; dir != null && !new File(dir, '.mvn').exists(); dir = dir.getParentFile()) {} + new GroovyShell().parse(new File(dir, 'build/scripts/generate-test-poms.groovy')) + .deploy(project, session) + ]]></source> </configuration> </execution> </executions> + <dependencies> + <dependency> + <groupId>org.twdata.maven</groupId> + <artifactId>mojo-executor</artifactId> + <version>2.3.0</version> + </dependency> + </dependencies> </plugin> </plugins> </build> - <profiles> - <profile> - <!-- installs and deploys the test jar under a separate artifactId and with a modified pom. - See /build/scripts/generate-test-poms.groovy --> - <id>install-reusable-test-jar</id> - <activation> - <file> - <!-- activate only in the submodules --> - <exists>../install-reusable-test-jar.txt</exists> - </file> - </activation> - <build> - <plugins> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-install-plugin</artifactId> - <executions> - <execution> - <id>install-reusable-test-jar</id> - <goals> - <goal>install-file</goal> - </goals> - <phase>install</phase> - <configuration> - <pomFile>${basedir}/../target/${project.artifactId}-tests-pom.xml</pomFile> - <version>${project.version}</version> - <file>${basedir}/target/${project.artifactId}-${project.version}-tests.jar</file> - </configuration> - </execution> - </executions> - </plugin> - <plugin> - <groupId>org.codehaus.gmaven</groupId> - <artifactId>groovy-maven-plugin</artifactId> - <executions> - <execution> - <id>set-deployer-properties</id> - <goals> - <goal>execute</goal> - </goals> - <phase>deploy</phase> - <configuration> - <source><![CDATA[ - def distManagementRepo = project.version.endsWith('-SNAPSHOT') ? project.distributionManagement.snapshotRepository : project.distributionManagement.repository - project.properties.setProperty('deploy.test.jar.repositoryId', distManagementRepo.id) - project.properties.setProperty('deploy.test.jar.url', distManagementRepo.url) - ]]></source> - </configuration> - </execution> - </executions> - </plugin> - <plugin> - <groupId>org.apache.maven.plugins</groupId> - <artifactId>maven-deploy-plugin</artifactId> - <executions> - <execution> - <id>deploy-reusable-test-jar</id> - <goals> - <goal>deploy-file</goal> - </goals> - <phase>deploy</phase> - <configuration> - <repositoryId>${deploy.test.jar.repositoryId}</repositoryId><!-- set via groovy above --> - <url>${deploy.test.jar.url}</url><!-- set via groovy above --> - <pomFile>${basedir}/../target/${project.artifactId}-tests-pom.xml</pomFile> - <version>${project.version}</version> - <file>${basedir}/target/${project.artifactId}-${project.version}-tests.jar</file> - </configuration> - </execution> - </executions> - </plugin> - </plugins> - </build> - </profile> - </profiles> - </project> diff --git a/pom.xml b/pom.xml index 0159f1d..0a78ec1 100644 --- a/pom.xml +++ b/pom.xml @@ -170,6 +170,12 @@ <plugin> <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-deploy-plugin</artifactId> + <version>${maven-deploy-plugin.version}</version> + </plugin> + + <plugin> + <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-enforcer-plugin</artifactId> <executions> <execution>