This is an automated email from the ASF dual-hosted git repository.
apupier pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push:
new 7c0644752e17 PrepareCatalogMojo: support incremental build and extract
artifactId from pom.xml
7c0644752e17 is described below
commit 7c0644752e17c80aebfcd4b6e459a3ee42ee2344
Author: Aurélien Pupier <[email protected]>
AuthorDate: Tue Dec 1 16:03:55 2026 +0100
PrepareCatalogMojo: support incremental build and extract artifactId from
pom.xml
- Check target/classes first, fall back to src/generated/resources to avoid
remote artifact download
- Extract artifactId from pom.xml when downloading component jar from Maven
repository (handling module directories that differ from artifactId, e.g.
camel-box-component -> camel-box)
- Look up camel-core model classes via getComponentClassesDirectory
- Add PrepareCatalogMojoTest covering extractArtifactId
Co-authored-by: IBM Bob 2.2.1
Signed-off-by: Aurélien Pupier <[email protected]>
---
.../camel/maven/packaging/PrepareCatalogMojo.java | 58 +++++++++++--
.../maven/packaging/PrepareCatalogMojoTest.java | 98 ++++++++++++++++++++++
2 files changed, 149 insertions(+), 7 deletions(-)
diff --git
a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/PrepareCatalogMojo.java
b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/PrepareCatalogMojo.java
index 120359391e87..66630d7702cb 100644
---
a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/PrepareCatalogMojo.java
+++
b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/PrepareCatalogMojo.java
@@ -66,6 +66,7 @@ import org.apache.camel.util.json.Jsoner;
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.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.project.MavenProject;
@@ -294,18 +295,23 @@ public class PrepareCatalogMojo extends AbstractMojo {
}
/**
- * Gives the {@code target/classes} directory if it already exists,
otherwise downloads the corresponding artifact
- * and unzips its content into the {@code target/classes} directory to
support incremental build.
+ * Gives the {@code target/classes} directory if it already exists,
otherwise checks {@code src/generated/resources}
+ * or downloads the corresponding artifact and unzips its content into the
{@code target/classes} directory to
+ * support incremental builds.
*
* @param componentRootDirectory the root directory of a given component
- * @return the path to the {@code target/classes}
directory.
+ * @return the path to the component classes or
resources directory.
*/
private Path getComponentClassesDirectory(Path componentRootDirectory) {
Path result = componentRootDirectory.resolve("target/classes");
if (Files.exists(result)) {
return result;
}
- String artifactId = componentRootDirectory.getFileName().toString();
+ Path srcGen = componentRootDirectory.resolve(SRC_GENERATED_RESOURCES);
+ if (Files.isDirectory(srcGen)) {
+ return srcGen;
+ }
+ String artifactId = extractArtifactId(componentRootDirectory,
getLog());
ArtifactRequest req = new ArtifactRequest()
.setRepositories(this.repositories)
.setArtifact(new DefaultArtifact("org.apache.camel",
artifactId, "jar", project.getVersion()));
@@ -322,6 +328,42 @@ public class PrepareCatalogMojo extends AbstractMojo {
return result;
}
+ static String extractArtifactId(Path componentRootDirectory) {
+ return extractArtifactId(componentRootDirectory, null);
+ }
+
+ static String extractArtifactId(Path componentRootDirectory, Log log) {
+ Path pom = componentRootDirectory.resolve("pom.xml");
+ if (Files.exists(pom)) {
+ try {
+ boolean inParent = false;
+ for (String line : Files.readAllLines(pom)) {
+ if (line.contains("<parent>") &&
line.contains("</parent>")) {
+ continue;
+ }
+ if (line.contains("<parent>")) {
+ inParent = true;
+ }
+ if (line.contains("</parent>")) {
+ inParent = false;
+ continue;
+ }
+ if (!inParent) {
+ String artifactId = Strings.between(line,
"<artifactId>", "</artifactId>");
+ if (artifactId != null) {
+ return artifactId.trim();
+ }
+ }
+ }
+ } catch (IOException e) {
+ if (log != null) {
+ log.debug("Failed to read artifactId from %s, falling back
to directory name".formatted(pom), e);
+ }
+ }
+ }
+ return componentRootDirectory.getFileName().toString();
+ }
+
/**
* Unzips the given jar file into the given target directory.
*
@@ -472,8 +514,9 @@ public class PrepareCatalogMojo extends AbstractMojo {
Map<String, Set<String>> usedLabels = new TreeMap<>();
// find all json files in camel-core
- Path coreDirTarget =
modelDir.resolve("target/classes/META-INF/org/apache/camel/model");
- Path coreModelAppDirTarget =
modelDir.resolve("target/classes/META-INF/org/apache/camel/model/app");
+ Path modelClassesDir = getComponentClassesDirectory(modelDir);
+ Path coreDirTarget =
modelClassesDir.resolve("META-INF/org/apache/camel/model");
+ Path coreModelAppDirTarget =
modelClassesDir.resolve("META-INF/org/apache/camel/model/app");
jsonFiles = allJsonFiles.stream()
.filter(p -> p.startsWith(coreDirTarget))
.filter(p -> !p.startsWith(coreModelAppDirTarget))
@@ -537,7 +580,8 @@ public class PrepareCatalogMojo extends AbstractMojo {
Set<Path> jsonFiles;
// find all json files in camel-core
- Path coreDirTarget =
modelDir.resolve("target/classes/META-INF/org/apache/camel/model/app");
+ Path modelClassesDir = getComponentClassesDirectory(modelDir);
+ Path coreDirTarget =
modelClassesDir.resolve("META-INF/org/apache/camel/model/app");
jsonFiles = allJsonFiles.stream()
.filter(p -> p.startsWith(coreDirTarget))
.collect(Collectors.toCollection(TreeSet::new));
diff --git
a/tooling/maven/camel-package-maven-plugin/src/test/java/org/apache/camel/maven/packaging/PrepareCatalogMojoTest.java
b/tooling/maven/camel-package-maven-plugin/src/test/java/org/apache/camel/maven/packaging/PrepareCatalogMojoTest.java
new file mode 100644
index 000000000000..3405805256e3
--- /dev/null
+++
b/tooling/maven/camel-package-maven-plugin/src/test/java/org/apache/camel/maven/packaging/PrepareCatalogMojoTest.java
@@ -0,0 +1,98 @@
+/*
+ * 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.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class PrepareCatalogMojoTest {
+
+ @TempDir
+ Path tempDir;
+
+ @Test
+ void extractArtifactIdStandardPom() throws IOException {
+ Path moduleDir = tempDir.resolve("camel-box-component");
+ Files.createDirectories(moduleDir);
+ String pomContent = """
+ <?xml version="1.0" encoding="UTF-8"?>
+ <project xmlns="http://maven.apache.org/POM/4.0.0">
+ <parent>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-box-parent</artifactId>
+ <version>4.24.0-SNAPSHOT</version>
+ </parent>
+ <artifactId>camel-box</artifactId>
+ <packaging>jar</packaging>
+ </project>
+ """;
+ Files.writeString(moduleDir.resolve("pom.xml"), pomContent);
+
+ String artifactId = PrepareCatalogMojo.extractArtifactId(moduleDir);
+ assertThat(artifactId).isEqualTo("camel-box");
+ }
+
+ @Test
+ void extractArtifactIdSingleLineParent() throws IOException {
+ Path moduleDir = tempDir.resolve("camel-salesforce-component");
+ Files.createDirectories(moduleDir);
+ String pomContent = """
+ <?xml version="1.0" encoding="UTF-8"?>
+ <project xmlns="http://maven.apache.org/POM/4.0.0">
+
<parent><artifactId>camel-salesforce-parent</artifactId></parent>
+ <artifactId>camel-salesforce</artifactId>
+ </project>
+ """;
+ Files.writeString(moduleDir.resolve("pom.xml"), pomContent);
+
+ String artifactId = PrepareCatalogMojo.extractArtifactId(moduleDir);
+ assertThat(artifactId).isEqualTo("camel-salesforce");
+ }
+
+ @Test
+ void extractArtifactIdFallsBackToDirectoryNameWhenNoPom() {
+ Path moduleDir = tempDir.resolve("camel-custom-dir");
+ String artifactId = PrepareCatalogMojo.extractArtifactId(moduleDir);
+ assertThat(artifactId).isEqualTo("camel-custom-dir");
+ }
+
+ @Test
+ void
extractArtifactIdFallsBackToDirectoryNameWhenNoArtifactIdOutsideParent() throws
IOException {
+ Path moduleDir = tempDir.resolve("camel-no-artifact-id");
+ Files.createDirectories(moduleDir);
+ String pomContent = """
+ <?xml version="1.0" encoding="UTF-8"?>
+ <project xmlns="http://maven.apache.org/POM/4.0.0">
+ <parent>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-parent</artifactId>
+ <version>4.24.0-SNAPSHOT</version>
+ </parent>
+ </project>
+ """;
+ Files.writeString(moduleDir.resolve("pom.xml"), pomContent);
+
+ String artifactId = PrepareCatalogMojo.extractArtifactId(moduleDir);
+ assertThat(artifactId).isEqualTo("camel-no-artifact-id");
+ }
+}