Juan Hernandez has uploaded a new change for review. Change subject: core: Add support for annotation indexes ......................................................................
core: Add support for annotation indexes This change modifies the maven plugin that generates JBoss modules so that it creates annotation indexes. For each .jar file inside the module a new META-INF/jandex.idx resource will be added. These annotations index speeds up the deployment of the applications and are required in order to allow scanning of annotations from other modules, otherwise they are silently ignored. Change-Id: I3556fc385efc2ae138d2ad12b7d9d467bb5fff67 Related: https://bugzilla.redhat.com/1113485 Signed-off-by: Juan Hernandez <[email protected]> --- M backend/manager/dependencies/pom.xml M build-tools-root/jboss-modules-maven-plugin/pom.xml M build-tools-root/jboss-modules-maven-plugin/src/main/java/org/ovirt/engine/build/Module.java M build-tools-root/jboss-modules-maven-plugin/src/main/java/org/ovirt/engine/build/ModulesMojo.java M pom.xml 5 files changed, 89 insertions(+), 11 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/73/29473/1 diff --git a/backend/manager/dependencies/pom.xml b/backend/manager/dependencies/pom.xml index f42fae2..a7d5621 100644 --- a/backend/manager/dependencies/pom.xml +++ b/backend/manager/dependencies/pom.xml @@ -331,6 +331,7 @@ <groupId>org.ovirt.engine</groupId> <artifactId>jboss-modules-maven-plugin</artifactId> <configuration> + <generateIndex>false</generateIndex> <modules> <module> diff --git a/build-tools-root/jboss-modules-maven-plugin/pom.xml b/build-tools-root/jboss-modules-maven-plugin/pom.xml index 3d573a3..36a5bf0 100644 --- a/build-tools-root/jboss-modules-maven-plugin/pom.xml +++ b/build-tools-root/jboss-modules-maven-plugin/pom.xml @@ -21,7 +21,7 @@ </description> <artifactId>jboss-modules-maven-plugin</artifactId> - <version>1.0-SNAPSHOT</version> + <version>1.1-SNAPSHOT</version> <packaging>maven-plugin</packaging> <dependencies> @@ -68,6 +68,12 @@ <version>3.0</version> </dependency> + <dependency> + <groupId>org.jboss</groupId> + <artifactId>jandex</artifactId> + <version>1.0.3.Final</version> + </dependency> + </dependencies> <build> diff --git a/build-tools-root/jboss-modules-maven-plugin/src/main/java/org/ovirt/engine/build/Module.java b/build-tools-root/jboss-modules-maven-plugin/src/main/java/org/ovirt/engine/build/Module.java index 811c5d6..5fbddd0 100644 --- a/build-tools-root/jboss-modules-maven-plugin/src/main/java/org/ovirt/engine/build/Module.java +++ b/build-tools-root/jboss-modules-maven-plugin/src/main/java/org/ovirt/engine/build/Module.java @@ -1,3 +1,19 @@ +/* +* Copyright (c) 2014 Red Hat, Inc. +* +* Licensed 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.ovirt.engine.build; import org.apache.maven.artifact.Artifact; diff --git a/build-tools-root/jboss-modules-maven-plugin/src/main/java/org/ovirt/engine/build/ModulesMojo.java b/build-tools-root/jboss-modules-maven-plugin/src/main/java/org/ovirt/engine/build/ModulesMojo.java index 6707978..10ec253 100644 --- a/build-tools-root/jboss-modules-maven-plugin/src/main/java/org/ovirt/engine/build/ModulesMojo.java +++ b/build-tools-root/jboss-modules-maven-plugin/src/main/java/org/ovirt/engine/build/ModulesMojo.java @@ -1,3 +1,19 @@ +/* +* Copyright (c) 2014 Red Hat, Inc. +* +* Licensed 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.ovirt.engine.build; import java.io.File; @@ -17,6 +33,8 @@ import org.apache.maven.project.MavenProjectHelper; import org.codehaus.plexus.archiver.zip.ZipArchiver; import org.codehaus.plexus.util.FileUtils; +import org.jboss.jandex.Indexer; +import org.jboss.jandex.JarIndexer; @Mojo(name = "jboss-modules", defaultPhase = LifecyclePhase.PACKAGE, requiresDependencyCollection = ResolutionScope.COMPILE) public class ModulesMojo extends AbstractMojo { @@ -50,6 +68,13 @@ */ @Parameter(property = "modules") private List<Module> modules; + + /** + * This parameter indicates if the generated modules should include also + * annotation indexes. + */ + @Parameter(property = "generateIndex", defaultValue="true") + private boolean generateIndex; /** * The temporary directory where modules will be stored. @@ -161,23 +186,53 @@ "and group id \"" + module.getGroupId() + "\""); } - // Copy the artifact to the slot directory: + // Copy the artifact to the temporary directory (this is needed because the index generator has a bug and will + // remove the file if it isn't in the same file system that the temporary file it uses internally): File artifactFrom = matchingArtifact.getFile(); if (artifactFrom == null) { throw new MojoExecutionException( - "Can't find file for artifact id \"" + module.getArtifactId() + "\" " + - "and group id \"" + module.getGroupId() + "\""); + "Can't find file for artifact id \"" + module.getArtifactId() + "\" " + "and group id \"" + + module.getGroupId() + "\"" + ); } - File artifactTo = new File(slotDir, module.getResourcePath()); - getLog().info("Copying artifact to \"" + artifactTo + "\""); + File artifactTmp; try { - FileUtils.copyFile(artifactFrom, artifactTo); + artifactTmp = File.createTempFile("index", null); + FileUtils.copyFile(artifactFrom, artifactTmp); } catch (IOException exception) { throw new MojoExecutionException( - "Can't copy artifact from \"" + artifactFrom.getAbsolutePath() + "\" " + - "to \"" + artifactTo.getAbsolutePath() + "\"", - exception); + "Can't create temporary file for \"" + artifactFrom.getAbsolutePath() + "\".", + exception + ); + } + + // Add the annotations index to the temporary file: + if (generateIndex) { + getLog().info("Creating annotations index for \"" + artifactFrom.getAbsolutePath() + "\""); + try { + JarIndexer.createJarIndex(artifactTmp, new Indexer(), true, false, false); + } + catch (IOException exception) { + throw new MojoExecutionException( + "Can't add annotations index to \"" + artifactTmp.getAbsolutePath() + "\".", + exception + ); + } + } + + // Move the temporary artifact file (maybe modified to include the index) to the slot directory: + File artifactTo = new File(slotDir, module.getResourcePath()); + getLog().info("Copying artifact to \"" + artifactTo.getAbsolutePath() + "\""); + try { + FileUtils.rename(artifactTmp, artifactTo); + } + catch (IOException exception) { + throw new MojoExecutionException( + "Can't move temporary file \"" + artifactTmp.getAbsolutePath() + "\" to slot directory \"" + + slotDir.getAbsolutePath() + "\".", + exception + ); } } diff --git a/pom.xml b/pom.xml index 28050c1..d27760d 100644 --- a/pom.xml +++ b/pom.xml @@ -594,7 +594,7 @@ <plugin> <groupId>org.ovirt.engine</groupId> <artifactId>jboss-modules-maven-plugin</artifactId> - <version>1.0-SNAPSHOT</version> + <version>1.1-SNAPSHOT</version> <executions> <execution> <phase>package</phase> -- To view, visit http://gerrit.ovirt.org/29473 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I3556fc385efc2ae138d2ad12b7d9d467bb5fff67 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Juan Hernandez <[email protected]> _______________________________________________ Engine-patches mailing list [email protected] http://lists.ovirt.org/mailman/listinfo/engine-patches
