This is an automated email from the ASF dual-hosted git repository. gnodet pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/master by this push: new 07861f8 Fix and speed up the build 07861f8 is described below commit 07861f8b867fb0daf96dd26c43c726a962ef3ce6 Author: Guillaume Nodet <gno...@gmail.com> AuthorDate: Wed Feb 5 07:13:16 2020 +0100 Fix and speed up the build --- components/pom.xml | 24 +-- core/camel-core/pom.xml | 12 ++ core/pom.xml | 33 +--- .../maven/packaging/AbstractGeneratorMojo.java | 11 ++ .../camel/maven/packaging/ComponentDslMojo.java | 14 +- .../camel/maven/packaging/EndpointDslMojo.java | 17 +- .../packaging/EndpointSchemaGeneratorMojo.java | 9 + .../apache/camel/maven/packaging/GenerateMojo.java | 219 +++++++++++++++++++++ .../camel/maven/packaging/PackageJandexMojo.java | 14 +- .../camel/maven/packaging/PackageJaxbMojo.java | 6 + .../camel/maven/packaging/PackageLegalMojo.java | 5 +- .../camel/maven/packaging/PackageModelMojo.java | 6 + .../maven/packaging/PrepareComponentMojo.java | 35 ++-- .../camel/maven/packaging/SchemaGeneratorMojo.java | 12 ++ .../camel/maven/packaging/SpiGeneratorMojo.java | 9 + .../TypeConverterLoaderGeneratorMojo.java | 11 ++ .../camel/maven/packaging/UpdateReadmeMojo.java | 27 ++- .../maven/packaging/ValidateComponentMojo.java | 29 +-- 18 files changed, 380 insertions(+), 113 deletions(-) diff --git a/components/pom.xml b/components/pom.xml index cba4adb..154ca5d 100644 --- a/components/pom.xml +++ b/components/pom.xml @@ -389,32 +389,10 @@ <execution> <id>generate</id> <goals> - <goal>jandex</goal> - <goal>generate-type-converter-loader</goal> - <goal>generate-spi</goal> - <goal>generate-endpoint-schema</goal> - <goal>prepare-components</goal> - <goal>generate-components-list</goal> + <goal>generate</goal> </goals> <phase>process-classes</phase> </execution> - <execution> - <id>validate</id> - <goals> - <goal>validate-components</goal> - <goal>generate-legal</goal> - <goal>generate-endpoint-dsl</goal> - <goal>generate-component-dsl</goal> - </goals> - <phase>prepare-package</phase> - </execution> - <execution> - <id>readme</id> - <goals> - <goal>update-readme</goal> - </goals> - <phase>package</phase> - </execution> </executions> </plugin> <plugin> diff --git a/core/camel-core/pom.xml b/core/camel-core/pom.xml index e74d09e..079a7f8 100644 --- a/core/camel-core/pom.xml +++ b/core/camel-core/pom.xml @@ -242,6 +242,18 @@ <build> <plugins> + <plugin> + <groupId>org.apache.camel</groupId> + <artifactId>camel-package-maven-plugin</artifactId> + <version>${project.version}</version> + <executions> + <execution> + <id>generate</id> + <phase>none</phase> + </execution> + </executions> + </plugin> + <!-- generate the attached tests jar --> <plugin> <artifactId>maven-jar-plugin</artifactId> diff --git a/core/pom.xml b/core/pom.xml index 549aa6f..03c0c7b 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -67,43 +67,12 @@ <version>${project.version}</version> <executions> <execution> - <id>generate-legal</id> - <goals> - <goal>generate-legal</goal> - </goals> - <phase>prepare-package</phase> - </execution> - <execution> <id>generate</id> <goals> - <goal>jandex</goal> - <goal>generate-schema</goal> - <goal>generate-type-converter-loader</goal> - <goal>generate-spi</goal> - <goal>generate-jaxb-list</goal> - <goal>generate-eips-list</goal> - <goal>generate-components-list</goal> - <goal>generate-dataformats-list</goal> - <goal>generate-languages-list</goal> - <goal>prepare-main</goal> - <goal>generate-xml-parser</goal> + <goal>generate</goal> </goals> <phase>process-classes</phase> </execution> - <execution> - <id>validate</id> - <goals> - <goal>validate-components</goal> - </goals> - <phase>prepare-package</phase> - </execution> - <execution> - <id>readme</id> - <goals> - <goal>update-readme</goal> - </goals> - <phase>package</phase> - </execution> </executions> </plugin> <plugin> diff --git a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/AbstractGeneratorMojo.java b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/AbstractGeneratorMojo.java index 7dd8fa8..612804e 100644 --- a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/AbstractGeneratorMojo.java +++ b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/AbstractGeneratorMojo.java @@ -27,6 +27,8 @@ import java.util.function.Supplier; import org.apache.camel.tooling.util.FileUtil; import org.apache.maven.model.Resource; import org.apache.maven.plugin.AbstractMojo; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.plugin.logging.Log; import org.apache.maven.plugins.annotations.Component; import org.apache.maven.plugins.annotations.Parameter; @@ -58,6 +60,15 @@ public abstract class AbstractGeneratorMojo extends AbstractMojo { @Component protected BuildContext buildContext; + public void execute(MavenProject project, + MavenProjectHelper projectHelper, + BuildContext buildContext) throws MojoFailureException, MojoExecutionException { + this.project = project; + this.projectHelper = projectHelper; + this.buildContext = buildContext; + execute(); + } + protected void addResourceDirectory(Path path) { projectHelper.addResource(project, path.toString(), Collections.singletonList("**/*"), Collections.emptyList()); } diff --git a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/ComponentDslMojo.java b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/ComponentDslMojo.java index 46f0596..4d28503 100644 --- a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/ComponentDslMojo.java +++ b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/ComponentDslMojo.java @@ -46,6 +46,9 @@ import org.apache.maven.plugins.annotations.LifecyclePhase; import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.plugins.annotations.ResolutionScope; +import org.apache.maven.project.MavenProject; +import org.apache.maven.project.MavenProjectHelper; +import org.sonatype.plexus.build.incremental.BuildContext; import static org.apache.camel.tooling.util.PackageHelper.findCamelDirectory; import static org.apache.camel.tooling.util.PackageHelper.loadText; @@ -64,7 +67,7 @@ public class ComponentDslMojo extends AbstractGeneratorMojo { /** * The base directory */ - @Parameter(defaultValue = "${basedir}") + @Parameter(defaultValue = "${project.basedir}") protected File baseDir; /** @@ -106,6 +109,15 @@ public class ComponentDslMojo extends AbstractGeneratorMojo { DynamicClassLoader projectClassLoader; @Override + public void execute(MavenProject project, MavenProjectHelper projectHelper, BuildContext buildContext) throws MojoFailureException, MojoExecutionException { + buildDir = new File(project.getBuild().getDirectory()); + baseDir = project.getBasedir(); + componentsDslPackageName = "org.apache.camel.builder.component"; + componentsDslFactoriesPackageName = "org.apache.camel.builder.component.dsl"; + super.execute(project, projectHelper, buildContext); + } + + @Override public void execute() throws MojoExecutionException, MojoFailureException { try { projectClassLoader = DynamicClassLoader.createDynamicClassLoader(project.getTestClasspathElements()); diff --git a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/EndpointDslMojo.java b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/EndpointDslMojo.java index 4db8b80..ba85056 100644 --- a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/EndpointDslMojo.java +++ b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/EndpointDslMojo.java @@ -60,6 +60,8 @@ import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.plugins.annotations.ResolutionScope; import org.apache.maven.project.MavenProject; +import org.apache.maven.project.MavenProjectHelper; +import org.sonatype.plexus.build.incremental.BuildContext; /** * Generate Endpoint DSL source files for Components. @@ -91,7 +93,7 @@ public class EndpointDslMojo extends AbstractGeneratorMojo { /** * The base directory */ - @Parameter(defaultValue = "${basedir}") + @Parameter(defaultValue = "${project.basedir}") protected File baseDir; /** @@ -127,6 +129,19 @@ public class EndpointDslMojo extends AbstractGeneratorMojo { DynamicClassLoader projectClassLoader; @Override + public void execute(MavenProject project, MavenProjectHelper projectHelper, BuildContext buildContext) throws MojoFailureException, MojoExecutionException { + buildDir = new File(project.getBuild().getDirectory()); + baseDir = project.getBasedir(); + endpointFactoriesPackageName = "org.apache.camel.builder.endpoint"; + componentsFactoriesPackageName = "org.apache.camel.builder.endpoint.dsl"; + generateEndpointBuilderFactory = true; + generateEndpointBuilders = true; + generateEndpointDsl = Boolean.parseBoolean(project.getProperties().getProperty("camel-generate-endpoint-dsl", "false")); + sourcesOutputDir = new File(project.getBasedir(), "src/generated/java"); + super.execute(project, projectHelper, buildContext); + } + + @Override public void execute() throws MojoExecutionException, MojoFailureException { if (!generateEndpointDsl) { return; diff --git a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/EndpointSchemaGeneratorMojo.java b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/EndpointSchemaGeneratorMojo.java index 931a6ca..9b63122 100644 --- a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/EndpointSchemaGeneratorMojo.java +++ b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/EndpointSchemaGeneratorMojo.java @@ -114,6 +114,15 @@ public class EndpointSchemaGeneratorMojo extends AbstractGeneratorMojo { @Override public void execute() throws MojoExecutionException, MojoFailureException { + if (classesDirectory == null) { + classesDirectory = new File(project.getBuild().getOutputDirectory()); + } + if (sourcesOutputDir == null) { + sourcesOutputDir = new File(project.getBasedir(), "src/generated/java"); + } + if (resourcesOutputDir == null) { + resourcesOutputDir = new File(project.getBasedir(), "src/generated/resources"); + } if (!classesDirectory.isDirectory()) { return; } diff --git a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/GenerateMojo.java b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/GenerateMojo.java new file mode 100644 index 0000000..b47d7e7 --- /dev/null +++ b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/GenerateMojo.java @@ -0,0 +1,219 @@ +/* + * 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.camel.maven.packaging; + +import java.io.File; +import java.io.IOError; +import java.io.IOException; +import java.io.Writer; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.Set; +import java.util.stream.Collectors; +import java.util.stream.Stream; +import java.util.zip.ZipFile; + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.execution.MavenSession; +import org.apache.maven.plugin.AbstractMojo; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.MojoFailureException; +import org.apache.maven.plugins.annotations.Component; +import org.apache.maven.plugins.annotations.LifecyclePhase; +import org.apache.maven.plugins.annotations.Mojo; +import org.apache.maven.plugins.annotations.Parameter; +import org.apache.maven.plugins.annotations.ResolutionScope; +import org.apache.maven.project.MavenProject; +import org.apache.maven.project.MavenProjectHelper; +import org.sonatype.plexus.build.incremental.BuildContext; + +/** + * + */ +@Mojo(name = "generate", threadSafe = true, requiresDependencyResolution = ResolutionScope.COMPILE_PLUS_RUNTIME, + defaultPhase = LifecyclePhase.PROCESS_CLASSES) +public class GenerateMojo extends AbstractMojo { + + @Parameter(property = "project", required = true, readonly = true) + protected MavenProject project; + @Component + protected MavenProjectHelper projectHelper; + @Component + protected BuildContext buildContext; + @Component + private MavenSession session; + @Parameter(defaultValue = "${showStaleFiles}") + private boolean showStaleFiles; + + @Override + public void execute() throws MojoExecutionException, MojoFailureException { + try { + if (!isUpToDate(project)) { + doExecute(); + writeIncrementalInfo(project); + } + } catch (Exception e) { + throw new MojoFailureException("Error generating data " + e.toString(), e); + } + } + + protected void doExecute() throws MojoFailureException, MojoExecutionException { + // jandex + invoke(PackageJandexMojo.class); + // generate-schema + invoke(SchemaGeneratorMojo.class); + // generate-type-converter-loader + invoke(TypeConverterLoaderGeneratorMojo.class); + // generate-spi + invoke(SpiGeneratorMojo.class); + // generate-jaxb-list + invoke(PackageJaxbMojo.class); + // generate-eips-list + invoke(PackageModelMojo.class); + // generate-endpoint-schema + invoke(EndpointSchemaGeneratorMojo.class); + // prepare-components + invoke(PrepareComponentMojo.class); + // prepare-main + invoke(PrepareCamelMainMojo.class); + // generate-xml-parser + invoke(ModelXmlParserGeneratorMojo.class); + // generate-legal + invoke(PackageLegalMojo.class); + // validate-components + invoke(ValidateComponentMojo.class); + // generate-endpoint-dsl + invoke(EndpointDslMojo.class); + // generate-component-dsl + invoke(ComponentDslMojo.class); + // update-readme + invoke(UpdateReadmeMojo.class); + } + + private void invoke(Class<? extends AbstractMojo> mojoClass) throws MojoExecutionException, MojoFailureException { + try { + AbstractMojo mojo = mojoClass.newInstance(); + mojo.setLog(getLog()); + mojo.setPluginContext(getPluginContext()); + ((AbstractGeneratorMojo) mojo).execute(project, projectHelper, buildContext); + + } catch (MojoExecutionException|MojoFailureException e) { + throw e; + } catch (Exception e) { + throw new MojoFailureException("Unable to create mojo", e); + } + } + + private void writeIncrementalInfo(MavenProject project) throws MojoExecutionException { + try { + Path cacheData = getIncrementalDataPath(project); + String curdata = getIncrementalData(); + Files.createDirectories(cacheData.getParent()); + try (Writer w = Files.newBufferedWriter(cacheData)) { + w.append(curdata); + } + } catch (IOException e) { + throw new MojoExecutionException("Error checking manifest uptodate status", e); + } + } + + private boolean isUpToDate(MavenProject project) throws MojoExecutionException { + try { + Path cacheData = getIncrementalDataPath(project); + String prvdata; + if (Files.isRegularFile(cacheData)) { + prvdata = new String(Files.readAllBytes(cacheData), StandardCharsets.UTF_8); + } else { + prvdata = null; + } + String curdata = getIncrementalData(); + if (curdata.equals(prvdata)) { + long lastmod = Files.getLastModifiedTime(cacheData).toMillis(); + Set<String> stale = Stream.concat(Stream.concat( + project.getCompileSourceRoots().stream().map(File::new), + Stream.of(new File(project.getBuild().getOutputDirectory()))), + project.getArtifacts().stream().map(Artifact::getFile)) + .flatMap(f -> newer(lastmod, f)).collect(Collectors.toSet()); + if (!stale.isEmpty()) { + getLog().info("Stale files detected, re-generating."); + if (showStaleFiles) { + getLog().info("Stale files: " + stale.stream().collect(Collectors.joining(", "))); + } else if (getLog().isDebugEnabled()) { + getLog().debug("Stale files: " + stale.stream().collect(Collectors.joining(", "))); + } + } else { + // everything is in order, skip + getLog().info("Skipping generation, everything is up to date."); + return true; + } + } else { + if (prvdata == null) { + getLog().info("No previous run data found, generating files."); + } else { + getLog().info("Configuration changed, re-generating files."); + } + } + } catch (IOException e) { + throw new MojoExecutionException("Error checking uptodate status", e); + } + return false; + } + + private String getIncrementalData() { + return ""; + } + + private Path getIncrementalDataPath(MavenProject project) { + return Paths.get(project.getBuild().getDirectory(), "camel-package-maven-plugin", "org.apache.camel_camel-package-maven-plugin_info_xx"); + } + + private long lastmod(Path p) { + try { + return Files.getLastModifiedTime(p).toMillis(); + } catch (IOException e) { + return 0; + } + } + + private Stream<String> newer(long lastmod, File file) { + try { + if (file.isDirectory()) { + return Files.walk(file.toPath()).filter(Files::isRegularFile).filter(p -> lastmod(p) > lastmod).map(Path::toString); + } else if (file.isFile()) { + if (lastmod(file.toPath()) > lastmod) { + if (file.getName().endsWith(".jar")) { + try (ZipFile zf = new ZipFile(file)) { + return zf.stream().filter(ze -> !ze.isDirectory()).filter(ze -> ze.getLastModifiedTime().toMillis() > lastmod) + .map(ze -> file.toString() + "!" + ze.getName()).collect(Collectors.toList()).stream(); + } + } else { + return Stream.of(file.toString()); + } + } else { + return Stream.empty(); + } + } else { + return Stream.empty(); + } + } catch (IOException e) { + throw new IOError(e); + } + } + +} diff --git a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/PackageJandexMojo.java b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/PackageJandexMojo.java index eb22d1b..741a77b 100644 --- a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/PackageJandexMojo.java +++ b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/PackageJandexMojo.java @@ -28,12 +28,16 @@ import java.util.stream.Collectors; import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.plugins.annotations.LifecyclePhase; import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.plugins.annotations.Parameter; +import org.apache.maven.project.MavenProject; +import org.apache.maven.project.MavenProjectHelper; import org.jboss.jandex.Index; import org.jboss.jandex.IndexWriter; import org.jboss.jandex.Indexer; +import org.sonatype.plexus.build.incremental.BuildContext; /** * Generate a Jandex index for classes compiled as part of the current project. @@ -41,7 +45,7 @@ import org.jboss.jandex.Indexer; * @author jdcasey */ @Mojo(name = "jandex", defaultPhase = LifecyclePhase.PROCESS_CLASSES, threadSafe = true) -public class PackageJandexMojo extends AbstractMojo { +public class PackageJandexMojo extends AbstractGeneratorMojo { @Parameter(defaultValue = "${project.build.outputDirectory}") protected File classesDirectory; @@ -57,6 +61,14 @@ public class PackageJandexMojo extends AbstractMojo { private boolean showStaleFiles; @Override + public void execute(MavenProject project, MavenProjectHelper projectHelper, BuildContext buildContext) throws MojoFailureException, MojoExecutionException { + classesDirectory = new File(project.getBuild().getOutputDirectory()); + index = new File(project.getBuild().getOutputDirectory(), "META-INF/jandex.idx"); + showStaleFiles = Boolean.parseBoolean(project.getProperties().getProperty("showStaleFiles", "false")); + super.execute(project, projectHelper, buildContext); + } + + @Override public void execute() throws MojoExecutionException { if (!classesDirectory.isDirectory()) { return; diff --git a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/PackageJaxbMojo.java b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/PackageJaxbMojo.java index fcdf714..5241859 100644 --- a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/PackageJaxbMojo.java +++ b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/PackageJaxbMojo.java @@ -83,6 +83,12 @@ public class PackageJaxbMojo extends AbstractGeneratorMojo { */ @Override public void execute() throws MojoExecutionException, MojoFailureException { + if (index == null) { + index = new File(project.getBuild().getDirectory(), "META-INF/jandex.idx"); + } + if (jaxbIndexOutDir == null) { + jaxbIndexOutDir = new File(project.getBasedir(), "src/generated/resources"); + } List<String> locations = new ArrayList<>(); locations.add(project.getBuild().getOutputDirectory()); diff --git a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/PackageLegalMojo.java b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/PackageLegalMojo.java index 7916cc7..2c875ce 100644 --- a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/PackageLegalMojo.java +++ b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/PackageLegalMojo.java @@ -38,7 +38,7 @@ public class PackageLegalMojo extends AbstractGeneratorMojo { /** * The output directory for generated components file */ - @Parameter(defaultValue = "${project.build.directory}/classes") + @Parameter(defaultValue = "${project.build.outputDirectory}") protected File legalOutDir; /** @@ -50,6 +50,9 @@ public class PackageLegalMojo extends AbstractGeneratorMojo { */ @Override public void execute() throws MojoExecutionException, MojoFailureException { + if (legalOutDir == null) { + legalOutDir = new File(project.getBuild().getOutputDirectory()); + } processLegal(legalOutDir.toPath()); } diff --git a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/PackageModelMojo.java b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/PackageModelMojo.java index a6b1d1f..3ffc51c 100644 --- a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/PackageModelMojo.java +++ b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/PackageModelMojo.java @@ -58,6 +58,12 @@ public class PackageModelMojo extends AbstractGeneratorMojo { */ @Override public void execute() throws MojoExecutionException, MojoFailureException { + if (buildDir == null) { + buildDir = new File(project.getBuild().getDirectory()); + } + if (outDir == null) { + outDir = new File(project.getBasedir(), "src/generated/resources"); + } File camelMetaDir = new File(outDir, "META-INF/services/org/apache/camel/"); camelMetaDir.mkdirs(); diff --git a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/PrepareComponentMojo.java b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/PrepareComponentMojo.java index bbfc135..cdd0c29 100644 --- a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/PrepareComponentMojo.java +++ b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/PrepareComponentMojo.java @@ -40,13 +40,7 @@ import org.sonatype.plexus.build.incremental.BuildContext; * auto-discovery in Camel and tooling. */ @Mojo(name = "prepare-components", threadSafe = true) -public class PrepareComponentMojo extends AbstractMojo { - - /** - * The maven project. - */ - @Parameter(property = "project", required = true, readonly = true) - protected MavenProject project; +public class PrepareComponentMojo extends AbstractGeneratorMojo { /** * The output directory for generated components file @@ -96,18 +90,20 @@ public class PrepareComponentMojo extends AbstractMojo { @Parameter(defaultValue = "${project.build.directory}") protected File buildDir; - /** - * Maven ProjectHelper. - */ - @Component - private MavenProjectHelper projectHelper; + @Parameter(defaultValue = "${camel-prepare-component}") + protected boolean prepareComponent; - /** - * build context to check changed files and mark them for refresh (used for - * m2e compatibility) - */ - @Component - private BuildContext buildContext; + @Override + public void execute(MavenProject project, MavenProjectHelper projectHelper, BuildContext buildContext) throws MojoFailureException, MojoExecutionException { + configurerSourceOutDir = new File(project.getBasedir(), "src/generated/java"); + configurerResourceOutDir = componentOutDir + = dataFormatOutDir = languageOutDir + = otherOutDir = schemaOutDir + = new File(project.getBasedir(), "src/generated/resources"); + buildDir = new File(project.getBuild().getDirectory()); + prepareComponent = Boolean.parseBoolean(project.getProperties().getProperty("camel-prepare-component", "false")); + super.execute(project, projectHelper, buildContext); + } /** * Execute goal. @@ -119,6 +115,9 @@ public class PrepareComponentMojo extends AbstractMojo { */ @Override public void execute() throws MojoExecutionException, MojoFailureException { + if (!prepareComponent) { + return; + } int count = 0; count += new PackageComponentMojo(getLog(), project, projectHelper, buildDir, componentOutDir, buildContext).prepareComponent(); diff --git a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/SchemaGeneratorMojo.java b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/SchemaGeneratorMojo.java index 73148e7..9eb0a1d 100644 --- a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/SchemaGeneratorMojo.java +++ b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/SchemaGeneratorMojo.java @@ -112,8 +112,20 @@ public class SchemaGeneratorMojo extends AbstractGeneratorMojo { protected IndexView indexView; protected Map<String, JavaClassSource> sources = new HashMap<>(); + public SchemaGeneratorMojo() { + } + @Override public void execute() throws MojoExecutionException, MojoFailureException { + if (classesDirectory == null) { + classesDirectory = new File(project.getBuild().getOutputDirectory()); + } + if (sourcesOutputDir == null) { + sourcesOutputDir = new File(project.getBasedir(), "src/generated/java"); + } + if (resourcesOutputDir == null) { + resourcesOutputDir = new File(project.getBasedir(), "src/generated/resources"); + } if (!classesDirectory.isDirectory()) { return; } diff --git a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/SpiGeneratorMojo.java b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/SpiGeneratorMojo.java index 11d9cfe..d1a4077 100644 --- a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/SpiGeneratorMojo.java +++ b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/SpiGeneratorMojo.java @@ -68,6 +68,15 @@ public class SpiGeneratorMojo extends AbstractGeneratorMojo { @Override public void execute() throws MojoExecutionException, MojoFailureException { + if (classesDirectory == null) { + classesDirectory = new File(project.getBuild().getOutputDirectory()); + } + if (sourcesOutputDir == null) { + sourcesOutputDir = new File(project.getBasedir(), "src/generated/java"); + } + if (resourcesOutputDir == null) { + resourcesOutputDir = new File(project.getBasedir(), "src/generated/resources"); + } if (!classesDirectory.isDirectory()) { return; } diff --git a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/TypeConverterLoaderGeneratorMojo.java b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/TypeConverterLoaderGeneratorMojo.java index 62be1ee..a538e4b 100644 --- a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/TypeConverterLoaderGeneratorMojo.java +++ b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/TypeConverterLoaderGeneratorMojo.java @@ -52,6 +52,8 @@ public class TypeConverterLoaderGeneratorMojo extends AbstractGeneratorMojo { public static final DotName CONVERTER_ANNOTATION = DotName.createSimple("org.apache.camel.Converter"); + @Parameter(defaultValue = "${project.build.outputDirectory}") + protected File classesDirectory; @Parameter(defaultValue = "${project.basedir}/src/generated/java") protected File sourcesOutputDir; @Parameter(defaultValue = "${project.basedir}/src/generated/resources") @@ -59,6 +61,15 @@ public class TypeConverterLoaderGeneratorMojo extends AbstractGeneratorMojo { @Override public void execute() throws MojoExecutionException, MojoFailureException { + if (classesDirectory == null) { + classesDirectory = new File(project.getBuild().getOutputDirectory()); + } + if (sourcesOutputDir == null) { + sourcesOutputDir = new File(project.getBasedir(), "src/generated/java"); + } + if (resourcesOutputDir == null) { + resourcesOutputDir = new File(project.getBasedir(), "src/generated/resources"); + } if ("pom".equals(project.getPackaging())) { return; } diff --git a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/UpdateReadmeMojo.java b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/UpdateReadmeMojo.java index be09a92..6ca5c64 100644 --- a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/UpdateReadmeMojo.java +++ b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/UpdateReadmeMojo.java @@ -41,10 +41,12 @@ import org.apache.camel.tooling.util.PackageHelper; import org.apache.camel.tooling.util.Strings; import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.plugins.annotations.Component; import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.project.MavenProject; +import org.apache.maven.project.MavenProjectHelper; import org.mvel2.templates.TemplateRuntime; import org.sonatype.plexus.build.incremental.BuildContext; @@ -53,13 +55,7 @@ import org.sonatype.plexus.build.incremental.BuildContext; * files in the project root directory. */ @Mojo(name = "update-readme", threadSafe = true) -public class UpdateReadmeMojo extends AbstractMojo { - - /** - * The maven project. - */ - @Parameter(property = "project", required = true, readonly = true) - protected MavenProject project; +public class UpdateReadmeMojo extends AbstractGeneratorMojo { /** * The project build directory @@ -70,13 +66,13 @@ public class UpdateReadmeMojo extends AbstractMojo { /** * The documentation directory */ - @Parameter(defaultValue = "${basedir}/src/main/docs") + @Parameter(defaultValue = "${project.basedir}/src/main/docs") protected File docDir; /** * The documentation EIP directory */ - @Parameter(defaultValue = "${basedir}/src/main/docs/eips") + @Parameter(defaultValue = "${project.basedir}/src/main/docs/eips") protected File eipDocDir; /** @@ -85,12 +81,13 @@ public class UpdateReadmeMojo extends AbstractMojo { @Parameter protected Boolean failFast; - /** - * build context to check changed files and mark them for refresh (used for - * m2e compatibility) - */ - @Component - private BuildContext buildContext; + @Override + public void execute(MavenProject project, MavenProjectHelper projectHelper, BuildContext buildContext) throws MojoFailureException, MojoExecutionException { + buildDir = new File(project.getBuild().getDirectory()); + docDir = new File(project.getBasedir(), "src/main/docs"); + eipDocDir = new File(project.getBasedir(), "src/main/docs/eips"); + super.execute(project, projectHelper, buildContext); + } @Override public void execute() throws MojoExecutionException { diff --git a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/ValidateComponentMojo.java b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/ValidateComponentMojo.java index 11ea086..acfd0b6 100644 --- a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/ValidateComponentMojo.java +++ b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/ValidateComponentMojo.java @@ -44,13 +44,7 @@ import org.sonatype.plexus.build.incremental.BuildContext; * each option */ @Mojo(name = "validate-components", threadSafe = true) -public class ValidateComponentMojo extends AbstractMojo { - - /** - * The maven project. - */ - @Parameter(property = "project", required = true, readonly = true) - protected MavenProject project; +public class ValidateComponentMojo extends AbstractGeneratorMojo { /** * Whether to validate if the components, data formats, and languages are @@ -62,23 +56,10 @@ public class ValidateComponentMojo extends AbstractMojo { /** * The output directory for generated components file */ - @Parameter(defaultValue = "${project.build.directory}/classes/") + @Parameter(defaultValue = "${project.build.outputDirectory}") protected File outDir; /** - * Maven ProjectHelper. - */ - @Component - private MavenProjectHelper projectHelper; - - /** - * build context to check changed files and mark them for refresh (used for - * m2e compatibility) - */ - @Component - private BuildContext buildContext; - - /** * Execute goal. * * @throws org.apache.maven.plugin.MojoExecutionException execution of the @@ -88,6 +69,12 @@ public class ValidateComponentMojo extends AbstractMojo { */ @Override public void execute() throws MojoExecutionException, MojoFailureException { + if (validate == null) { + validate = true; + } + if (outDir == null) { + outDir = new File(project.getBuild().getOutputDirectory()); + } if (!validate) { getLog().info("Validation disabled"); } else {