Repository: camel Updated Branches: refs/heads/master aeb9d68af -> 0369f8e91
CAMEL-8365: Attach generate catalog to mvn build Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/452f0f6e Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/452f0f6e Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/452f0f6e Branch: refs/heads/master Commit: 452f0f6e7b2202a0bb648492b0a81f630686933d Parents: aeb9d68 Author: Claus Ibsen <davscl...@apache.org> Authored: Thu Feb 19 07:33:56 2015 +0100 Committer: Claus Ibsen <davscl...@apache.org> Committed: Thu Feb 19 07:34:07 2015 +0100 ---------------------------------------------------------------------- tooling/archetypes/pom.xml | 28 ++--------------- .../packaging/PackageArchetypeCatalogMojo.java | 33 +++++++++++++++++--- 2 files changed, 30 insertions(+), 31 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/452f0f6e/tooling/archetypes/pom.xml ---------------------------------------------------------------------- diff --git a/tooling/archetypes/pom.xml b/tooling/archetypes/pom.xml index df458b5..5f9abac 100644 --- a/tooling/archetypes/pom.xml +++ b/tooling/archetypes/pom.xml @@ -53,7 +53,7 @@ <build> <plugins> - <!-- generate archetype catalog --> + <!-- generate and attach Camel archetype catalog --> <plugin> <groupId>org.apache.camel</groupId> <artifactId>camel-package-maven-plugin</artifactId> @@ -61,37 +61,13 @@ <executions> <execution> <goals> - <goal>generate-archetype-catalog</goal> + <goal>generate-and-attach-archetype-catalog</goal> </goals> <phase>process-resources</phase> </execution> </executions> </plugin> - <!-- attach the generate archetype-catalog so its released to maven repo --> - <plugin> - <groupId>org.codehaus.mojo</groupId> - <artifactId>build-helper-maven-plugin</artifactId> - <executions> - <execution> - <id>attach-artifacts</id> - <phase>prepare-package</phase> - <goals> - <goal>attach-artifact</goal> - </goals> - <configuration> - <artifacts> - <artifact> - <file>target/classes/archetype-catalog.xml</file> - <type>xml</type> - <classifier>archetype-catalog</classifier> - </artifact> - </artifacts> - </configuration> - </execution> - </executions> - </plugin> - </plugins> <pluginManagement> http://git-wip-us.apache.org/repos/asf/camel/blob/452f0f6e/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/PackageArchetypeCatalogMojo.java ---------------------------------------------------------------------- diff --git a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/PackageArchetypeCatalogMojo.java b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/PackageArchetypeCatalogMojo.java index 16faa55..f7fdd8d 100644 --- a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/PackageArchetypeCatalogMojo.java +++ b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/PackageArchetypeCatalogMojo.java @@ -36,7 +36,7 @@ import static org.apache.camel.maven.packaging.StringHelper.between; /** * Creates the Maven catalog for the Camel archetypes * - * @goal generate-archetype-catalog + * @goal generate-and-attach-archetype-catalog * @execute phase="process-resources" */ public class PackageArchetypeCatalogMojo extends AbstractMojo { @@ -58,6 +58,13 @@ public class PackageArchetypeCatalogMojo extends AbstractMojo { protected File outDir; /** + * The build directory + * + * @parameter default-value="${project.build.directory}" + */ + protected File projectBuildDir; + + /** * Maven ProjectHelper. * * @component @@ -74,16 +81,19 @@ public class PackageArchetypeCatalogMojo extends AbstractMojo { */ public void execute() throws MojoExecutionException, MojoFailureException { try { - generateArchetypeCatalog(getLog(), project, projectHelper, outDir); + generateArchetypeCatalog(getLog(), project, projectHelper, projectBuildDir, outDir); } catch (IOException e) { throw new MojoFailureException("Error generating archetype catalog due " + e.getMessage(), e); } } - public static void generateArchetypeCatalog(Log log, MavenProject project, MavenProjectHelper projectHelper, File outDir) throws MojoExecutionException, IOException { + public static void generateArchetypeCatalog(Log log, MavenProject project, MavenProjectHelper projectHelper, File projectBuildDir, File outDir) throws MojoExecutionException, IOException { + + File rootDir = projectBuildDir.getParentFile(); + log.info("Scanning for Camel Maven Archetypes from root directory " + rootDir); - // find all archetypes - File[] dirs = new File(".").listFiles(new FileFilter() { + // find all archetypes which are in the parent dir of the build dir + File[] dirs = rootDir.listFiles(new FileFilter() { @Override public boolean accept(File pathname) { // skip web console as its deprecated @@ -182,6 +192,19 @@ public class PackageArchetypeCatalogMojo extends AbstractMojo { fos.close(); log.info("Saved archetype catalog to file " + out); + + try { + if (projectHelper != null) { + log.info("Attaching archetype catalog to Maven project: " + project.getArtifactId()); + + List<String> includes = new ArrayList<String>(); + includes.add("archetype-catalog.xml"); + projectHelper.addResource(project, outDir.getPath(), includes, new ArrayList<String>()); + projectHelper.attachArtifact(project, "xml", "archetype-catalog", out); + } + } catch (Exception e) { + throw new MojoExecutionException("Failed to attach artifact to Maven project. Reason: " + e, e); + } } }