You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by or...@apache.org on 2022/01/04 15:57:22 UTC
[camel] branch main updated: (chores) camel-csimple-maven-plugin: cleanup code duplication
This is an automated email from the ASF dual-hosted git repository.
orpiske 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 05e80da (chores) camel-csimple-maven-plugin: cleanup code duplication
05e80da is described below
commit 05e80da91921d90e91c2eadee849ac292cf552e7
Author: Otavio Rodolfo Piske <op...@redhat.com>
AuthorDate: Tue Jan 4 14:50:33 2022 +0100
(chores) camel-csimple-maven-plugin: cleanup code duplication
---
.../java/org/apache/camel/maven/GenerateMojo.java | 73 +++++++++++++---------
1 file changed, 45 insertions(+), 28 deletions(-)
diff --git a/catalog/camel-csimple-maven-plugin/src/main/java/org/apache/camel/maven/GenerateMojo.java b/catalog/camel-csimple-maven-plugin/src/main/java/org/apache/camel/maven/GenerateMojo.java
index 8bdc986..01e5cff 100644
--- a/catalog/camel-csimple-maven-plugin/src/main/java/org/apache/camel/maven/GenerateMojo.java
+++ b/catalog/camel-csimple-maven-plugin/src/main/java/org/apache/camel/maven/GenerateMojo.java
@@ -349,10 +349,7 @@ public class GenerateMojo extends AbstractExecMojo {
// exclude take precedence
if (excludes != null) {
for (String exclude : excludes.split(",")) {
- exclude = exclude.trim();
- // try both with and without directory in the name
- String fqn = stripRootPath(asRelativeFile(file.getAbsolutePath()));
- boolean match = PatternHelper.matchPattern(fqn, exclude) || PatternHelper.matchPattern(file.getName(), exclude);
+ boolean match = isMatch(exclude, file);
if (match) {
return false;
}
@@ -362,10 +359,7 @@ public class GenerateMojo extends AbstractExecMojo {
// include
if (includes != null) {
for (String include : includes.split(",")) {
- include = include.trim();
- // try both with and without directory in the name
- String fqn = stripRootPath(asRelativeFile(file.getAbsolutePath()));
- boolean match = PatternHelper.matchPattern(fqn, include) || PatternHelper.matchPattern(file.getName(), include);
+ boolean match = isMatch(include, file);
if (match) {
return true;
}
@@ -378,6 +372,13 @@ public class GenerateMojo extends AbstractExecMojo {
return true;
}
+ private boolean isMatch(String include, File file) {
+ include = include.trim();
+ // try both with and without directory in the name
+ String fqn = stripRootPath(asRelativeFile(file.getAbsolutePath()));
+ return PatternHelper.matchPattern(fqn, include) || PatternHelper.matchPattern(file.getName(), include);
+ }
+
private String asRelativeFile(String name) {
String answer = name;
@@ -395,15 +396,29 @@ public class GenerateMojo extends AbstractExecMojo {
private String stripRootPath(String name) {
// strip out any leading source / resource directory
- List list = project.getCompileSourceRoots();
- for (Object obj : list) {
- String dir = (String) obj;
- dir = asRelativeFile(dir);
- if (name.startsWith(dir)) {
- return name.substring(dir.length() + 1);
- }
+ String compileSourceRoot = findInCompileSourceRoots(name);
+ if (compileSourceRoot != null) {
+ return compileSourceRoot;
+ }
+
+ String buildPath = findInResources(name);
+ if (buildPath != null) {
+ return buildPath;
+ }
+
+ return name;
+ }
+
+ private String findInCompileSourceRoots(String name) {
+ String compileSourceRoot = findInCompileSourceRoots(project.getCompileSourceRoots(), name);
+ if (compileSourceRoot != null) {
+ return compileSourceRoot;
}
- list = project.getTestCompileSourceRoots();
+
+ return findInCompileSourceRoots(project.getTestCompileSourceRoots(), name);
+ }
+
+ private String findInCompileSourceRoots(List<String> list, String name) {
for (Object obj : list) {
String dir = (String) obj;
dir = asRelativeFile(dir);
@@ -411,24 +426,26 @@ public class GenerateMojo extends AbstractExecMojo {
return name.substring(dir.length() + 1);
}
}
- List resources = project.getResources();
- for (Object obj : resources) {
- Resource resource = (Resource) obj;
- String dir = asRelativeFile(resource.getDirectory());
- if (name.startsWith(dir)) {
- return name.substring(dir.length() + 1);
- }
+ return null;
+ }
+
+ private String findInResources(String name) {
+ String buildPath = findInResources(project.getResources(), name);
+ if (buildPath != null) {
+ return buildPath;
}
- resources = project.getTestResources();
- for (Object obj : resources) {
- Resource resource = (Resource) obj;
+
+ return findInResources(project.getTestResources(), name);
+ }
+
+ private String findInResources(List<Resource> resources, String name) {
+ for (Resource resource : resources) {
String dir = asRelativeFile(resource.getDirectory());
if (name.startsWith(dir)) {
return name.substring(dir.length() + 1);
}
}
-
- return name;
+ return null;
}
public static boolean updateResource(Path out, String data) {