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 01e5cffc29c8c..270772645adf5 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 @@ -419,8 +419,7 @@ private String findInCompileSourceRoots(String name) { } private String findInCompileSourceRoots(List list, String name) { - for (Object obj : list) { - String dir = (String) obj; + for (String dir : list) { dir = asRelativeFile(dir); if (name.startsWith(dir)) { return name.substring(dir.length() + 1); diff --git a/tooling/camel-tooling-model/src/main/java/org/apache/camel/tooling/model/Strings.java b/tooling/camel-tooling-model/src/main/java/org/apache/camel/tooling/model/Strings.java index 5491f891601b7..6eaf1a4d10744 100644 --- a/tooling/camel-tooling-model/src/main/java/org/apache/camel/tooling/model/Strings.java +++ b/tooling/camel-tooling-model/src/main/java/org/apache/camel/tooling/model/Strings.java @@ -116,40 +116,6 @@ public static String wrapWords(String line, String wordSep, String lineSep, int offset = next + 1; } } - /* - while (inputLineLength - offset > watermark) { - if (line.charAt(offset) == ' ') { - ++offset; - } else { - int spaceToWrapAt = line.lastIndexOf(' ', watermark + offset); - int spaces = 0; - for (int i = offset; i < spaceToWrapAt; i++) { - spaces += line.charAt(i) == ' ' ? 1 : 0; - } - if (spaceToWrapAt >= offset) { - sb.append(line, offset, spaceToWrapAt); - sb.append(newLine); - offset = spaceToWrapAt + 1; - } else if (wrapLongWords) { - sb.append(line, offset, watermark + offset); - sb.append(newLine); - offset += watermark; - } else { - spaceToWrapAt = line.indexOf(' ', watermark + offset); - if (spaceToWrapAt >= 0) { - sb.append(line, offset, spaceToWrapAt); - sb.append(newLine); - offset = spaceToWrapAt + 1; - } else { - sb.append(line, offset, line.length()); - offset = inputLineLength; - } - } - } - } - - sb.append(line, offset, line.length()); - */ return sb.toString(); } } diff --git a/tooling/camel-tooling-util/src/main/java/org/apache/camel/tooling/util/FileUtil.java b/tooling/camel-tooling-util/src/main/java/org/apache/camel/tooling/util/FileUtil.java index b5d01d3c21a82..4fe3bd72a5a44 100644 --- a/tooling/camel-tooling-util/src/main/java/org/apache/camel/tooling/util/FileUtil.java +++ b/tooling/camel-tooling-util/src/main/java/org/apache/camel/tooling/util/FileUtil.java @@ -83,10 +83,7 @@ private static boolean doUpdateFile(Path path, byte[] newdata) throws IOExceptio Files.delete(path); return true; } else { - byte[] olddata = new byte[0]; - if (Files.exists(path) && Files.isReadable(path)) { - olddata = Files.readAllBytes(path); - } + final byte[] olddata = readFile(path); if (Arrays.equals(olddata, newdata)) { return false; } @@ -97,6 +94,14 @@ private static boolean doUpdateFile(Path path, byte[] newdata) throws IOExceptio } } + private static byte[] readFile(Path path) throws IOException { + if (Files.isReadable(path)) { + return Files.readAllBytes(path); + } + + return new byte[0]; + } + /** * Read the content of the input file and update the target accordingly * diff --git a/tooling/maven/bom-generator-maven-plugin/src/main/java/org/apache/camel/maven/bom/generator/DependencySet.java b/tooling/maven/bom-generator-maven-plugin/src/main/java/org/apache/camel/maven/bom/generator/DependencySet.java index 44c46943bb972..2c5b391b30fec 100644 --- a/tooling/maven/bom-generator-maven-plugin/src/main/java/org/apache/camel/maven/bom/generator/DependencySet.java +++ b/tooling/maven/bom-generator-maven-plugin/src/main/java/org/apache/camel/maven/bom/generator/DependencySet.java @@ -28,9 +28,6 @@ public class DependencySet { private Set excludes = new HashSet<>(); - public DependencySet() { - } - public Set getIncludes() { return includes; } diff --git a/tooling/maven/bom-generator-maven-plugin/src/main/java/org/apache/camel/maven/bom/generator/ExternalBomConflictCheck.java b/tooling/maven/bom-generator-maven-plugin/src/main/java/org/apache/camel/maven/bom/generator/ExternalBomConflictCheck.java index f58ff49878aae..8f99b1db76e15 100644 --- a/tooling/maven/bom-generator-maven-plugin/src/main/java/org/apache/camel/maven/bom/generator/ExternalBomConflictCheck.java +++ b/tooling/maven/bom-generator-maven-plugin/src/main/java/org/apache/camel/maven/bom/generator/ExternalBomConflictCheck.java @@ -27,9 +27,6 @@ public class ExternalBomConflictCheck { private String version; - public ExternalBomConflictCheck() { - } - public String getGroupId() { return groupId; } diff --git a/tooling/maven/bom-generator-maven-plugin/src/main/java/org/apache/camel/maven/bom/generator/ExternalBomConflictCheckSet.java b/tooling/maven/bom-generator-maven-plugin/src/main/java/org/apache/camel/maven/bom/generator/ExternalBomConflictCheckSet.java index 19e8823749fff..e07a784fe1cab 100644 --- a/tooling/maven/bom-generator-maven-plugin/src/main/java/org/apache/camel/maven/bom/generator/ExternalBomConflictCheckSet.java +++ b/tooling/maven/bom-generator-maven-plugin/src/main/java/org/apache/camel/maven/bom/generator/ExternalBomConflictCheckSet.java @@ -26,9 +26,6 @@ public class ExternalBomConflictCheckSet { private Set boms = new HashSet<>(); - public ExternalBomConflictCheckSet() { - } - public Set getBoms() { return boms; } diff --git a/tooling/maven/camel-api-component-maven-plugin/src/main/java/org/apache/camel/maven/AbstractApiMethodGeneratorMojo.java b/tooling/maven/camel-api-component-maven-plugin/src/main/java/org/apache/camel/maven/AbstractApiMethodGeneratorMojo.java index 88cd7a3f9b5a5..de8e87dd8b6f1 100644 --- a/tooling/maven/camel-api-component-maven-plugin/src/main/java/org/apache/camel/maven/AbstractApiMethodGeneratorMojo.java +++ b/tooling/maven/camel-api-component-maven-plugin/src/main/java/org/apache/camel/maven/AbstractApiMethodGeneratorMojo.java @@ -167,7 +167,7 @@ private VelocityContext getApiMethodContext(List return context; } - public File getApiMethodFile() throws MojoExecutionException { + public File getApiMethodFile() { final StringBuilder fileName = new StringBuilder(); fileName.append(outPackage.replace(".", Matcher.quoteReplacement(File.separator))).append(File.separator); fileName.append(getEnumName()).append(".java"); @@ -190,7 +190,7 @@ private VelocityContext getApiTestContext(List m return context; } - private String getTestFilePath() throws MojoExecutionException { + private String getTestFilePath() { final StringBuilder fileName = new StringBuilder(); fileName.append(componentPackage.replace(".", Matcher.quoteReplacement(File.separator))).append(File.separator); fileName.append(getUnitTestName()).append(".java"); @@ -259,7 +259,7 @@ private VelocityContext getEndpointContext(List return context; } - private File getConfigurationFile() throws MojoExecutionException { + private File getConfigurationFile() { final StringBuilder fileName = new StringBuilder(); // endpoint configuration goes in component package fileName.append(componentPackage.replace(".", Matcher.quoteReplacement(File.separator))).append(File.separator); @@ -312,18 +312,28 @@ public static String getType(Class clazz) { } } + /* + * This is used when configuring the plugin instead of directly, which is why it reports as unused + * without the annotation + */ + @SuppressWarnings("unused") public String getAliases() { StringBuilder sb = new StringBuilder(); sb.append("{"); if (!aliases.isEmpty()) { StringJoiner sj = new StringJoiner(", "); aliases.forEach(a -> sj.add("\"" + a.getMethodPattern() + "=" + a.getMethodAlias() + "\"")); - sb.append(sj.toString()); + sb.append(sj); } sb.append("}"); return sb.toString(); } + /* + * This is used when configuring the plugin instead of directly, which is why it reports as unused + * without the annotation + */ + @SuppressWarnings("unused") public static String getApiMethodsForParam(List models, ApiMethodArg argument) { StringBuilder sb = new StringBuilder(); @@ -368,6 +378,11 @@ public static String getApiMethodsForParam(List return "{" + answer + "}"; } + /* + * This is used when configuring the plugin instead of directly, which is why it reports as unused + * without the annotation + */ + @SuppressWarnings("unused") public static String getTestName(ApiMethodParser.ApiMethodModel model) { final StringBuilder builder = new StringBuilder(); final String name = model.getMethod().getName(); @@ -381,15 +396,30 @@ public static String getTestName(ApiMethodParser.ApiMethodModel model) { return builder.toString(); } + /* + * This is used when configuring the plugin instead of directly, which is why it reports as unused + * without the annotation + */ + @SuppressWarnings("unused") public static boolean isVoidType(Class resultType) { return resultType == Void.TYPE; } + /* + * This is used when configuring the plugin instead of directly, which is why it reports as unused + * without the annotation + */ + @SuppressWarnings("unused") public String getExchangePropertyPrefix() { // exchange property prefix return "Camel" + componentName + "."; } + /* + * This is used when configuring the plugin instead of directly, which is why it reports as unused + * without the annotation + */ + @SuppressWarnings("unused") public static String getResultDeclaration(Class resultType) { if (resultType.isPrimitive()) { return ClassUtils.primitiveToWrapper(resultType).getSimpleName(); @@ -410,10 +440,20 @@ public static String getResultDeclaration(Class resultType) { PRIMITIVE_VALUES.put(Double.TYPE, "0.0d"); } + /* + * This is used when configuring the plugin instead of directly, which is why it reports as unused + * without the annotation + */ + @SuppressWarnings("unused") public boolean hasDoc(ApiMethodArg argument) { return argument.getDescription() != null && !argument.getDescription().isEmpty(); } + /* + * This is used when configuring the plugin instead of directly, which is why it reports as unused + * without the annotation + */ + @SuppressWarnings("unused") public String getDoc(ApiMethodArg argument) { if (argument.getDescription() == null || argument.getDescription().isEmpty()) { return ""; @@ -421,6 +461,11 @@ public String getDoc(ApiMethodArg argument) { return argument.getDescription(); } + /* + * This is used when configuring the plugin instead of directly, which is why it reports as unused + * without the annotation + */ + @SuppressWarnings("unused") public String getApiName(String apiName) { if (apiName == null || apiName.isEmpty()) { return "DEFAULT"; @@ -428,6 +473,11 @@ public String getApiName(String apiName) { return apiName; } + /* + * This is used when configuring the plugin instead of directly, which is why it reports as unused + * without the annotation + */ + @SuppressWarnings("unused") public String getApiDescription(String apiDescription) { if (apiDescription == null) { return ""; @@ -435,6 +485,11 @@ public String getApiDescription(String apiDescription) { return apiDescription; } + /* + * This is used when configuring the plugin instead of directly, which is why it reports as unused + * without the annotation + */ + @SuppressWarnings("unused") public boolean isOptionalParameter(ApiMethodArg argument) { String name = argument.getName(); if (nullableOptions != null) { @@ -447,6 +502,28 @@ public boolean isOptionalParameter(ApiMethodArg argument) { return false; } + /* + * This is used when configuring the plugin instead of directly, which is why it reports as unused + * without the annotation + */ + @SuppressWarnings("unused") + public String getCanonicalName(ApiMethodArg argument) { + // replace primitives with wrapper classes (as that makes them option and avoid boolean because false by default) + final Class type = argument.getType(); + if (type.isPrimitive()) { + return getCanonicalName(ClassUtils.primitiveToWrapper(type)); + } + String fqn = argument.getRawTypeArgs(); + // the type may use $ for classloader, so replace it back with dot + fqn = fqn.replace('$', '.'); + return fqn; + } + + /* + * This is used when configuring the plugin instead of directly, which is why it reports as unused + * without the annotation + */ + @SuppressWarnings("unused") public String getApiMethods(List models) { models.sort((o1, o2) -> o1.getName().compareToIgnoreCase(o2.getName())); @@ -469,7 +546,7 @@ public String getApiMethods(List models) { sb.append(", signatures={"); StringJoiner sj = new StringJoiner(", "); signatures.forEach(s -> sj.add("\"" + s + "\"")); - sb.append(sj.toString()); + sb.append(sj); sb.append("}"); } sb.append(")"); @@ -494,6 +571,11 @@ private List getSignatures(List models, return list; } + /* + * This is used when configuring the plugin instead of directly, which is why it reports as unused + * without the annotation + */ + @SuppressWarnings("unused") public static String getDefaultArgValue(Class aClass) { if (aClass.isPrimitive()) { // lookup default primitive value string @@ -504,6 +586,11 @@ public static String getDefaultArgValue(Class aClass) { } } + /* + * This is used when configuring the plugin instead of directly, which is why it reports as unused + * without the annotation + */ + @SuppressWarnings("unused") public static String getBeanPropertySuffix(String parameter) { // capitalize first character StringBuilder builder = new StringBuilder(); @@ -511,17 +598,4 @@ public static String getBeanPropertySuffix(String parameter) { builder.append(parameter, 1, parameter.length()); return builder.toString(); } - - public String getCanonicalName(ApiMethodArg argument) throws MojoExecutionException { - // replace primitives with wrapper classes (as that makes them option and avoid boolean because false by default) - final Class type = argument.getType(); - if (type.isPrimitive()) { - return getCanonicalName(ClassUtils.primitiveToWrapper(type)); - } - - String fqn = argument.getRawTypeArgs(); - // the type may use $ for classloader, so replace it back with dot - fqn = fqn.replace('$', '.'); - return fqn; - } } diff --git a/tooling/maven/camel-api-component-maven-plugin/src/main/java/org/apache/camel/maven/ApiComponentGeneratorMojo.java b/tooling/maven/camel-api-component-maven-plugin/src/main/java/org/apache/camel/maven/ApiComponentGeneratorMojo.java index ad6e8be990c9e..6548d8826b250 100644 --- a/tooling/maven/camel-api-component-maven-plugin/src/main/java/org/apache/camel/maven/ApiComponentGeneratorMojo.java +++ b/tooling/maven/camel-api-component-maven-plugin/src/main/java/org/apache/camel/maven/ApiComponentGeneratorMojo.java @@ -319,12 +319,22 @@ private StringBuilder getFileBuilder() { return fileName; } + /* + * This is used when configuring the plugin instead of directly, which is why it reports as unused + * without the annotation + */ + @SuppressWarnings("unused") public static String getApiMethod(String proxyClass, String classPrefix) { String proxyClassWithCanonicalName = getProxyClassWithCanonicalName(proxyClass); String prefix = classPrefix != null ? classPrefix : ""; return prefix + proxyClassWithCanonicalName.substring(proxyClassWithCanonicalName.lastIndexOf('.') + 1) + "ApiMethod"; } + /* + * This is used when configuring the plugin instead of directly, which is why it reports as unused + * without the annotation + */ + @SuppressWarnings("unused") public static String getEndpointConfig(String proxyClass, String classPrefix) { String proxyClassWithCanonicalName = getProxyClassWithCanonicalName(proxyClass); String prefix = classPrefix != null ? classPrefix : ""; @@ -336,6 +346,11 @@ private static String getProxyClassWithCanonicalName(String proxyClass) { return proxyClass.replace("$", ""); } + /* + * This is used when configuring the plugin instead of directly, which is why it reports as unused + * without the annotation + */ + @SuppressWarnings("unused") public static String getEnumConstant(String enumValue) { if (enumValue == null || enumValue.isEmpty()) { return "DEFAULT"; @@ -347,6 +362,11 @@ public static String getEnumConstant(String enumValue) { return value; } + /* + * This is used when configuring the plugin instead of directly, which is why it reports as unused + * without the annotation + */ + @SuppressWarnings("unused") public static String getNullableOptionValues(String[] nullableOptions) { if (nullableOptions == null || nullableOptions.length == 0) { return ""; diff --git a/tooling/maven/camel-api-component-maven-plugin/src/main/java/org/apache/camel/maven/JavaSourceParser.java b/tooling/maven/camel-api-component-maven-plugin/src/main/java/org/apache/camel/maven/JavaSourceParser.java index 97d383edd45f7..1d965419c66f4 100644 --- a/tooling/maven/camel-api-component-maven-plugin/src/main/java/org/apache/camel/maven/JavaSourceParser.java +++ b/tooling/maven/camel-api-component-maven-plugin/src/main/java/org/apache/camel/maven/JavaSourceParser.java @@ -69,7 +69,7 @@ public class JavaSourceParser { private Map> parameterDocs = new LinkedHashMap<>(); @SuppressWarnings("unchecked") - public synchronized void parse(InputStream in, String innerClass) throws Exception { + public synchronized void parse(InputStream in, String innerClass) { AbstractGenericCapableJavaSource rootClazz = (AbstractGenericCapableJavaSource) Roaster.parse(in); AbstractGenericCapableJavaSource clazz = rootClazz; @@ -287,7 +287,7 @@ private static String resolveType( for (Type arg : types) { sj.add(resolveType(rootClazz, clazz, ms, arg)); } - answer = answer + "<" + sj.toString() + ">"; + answer = answer + "<" + sj + ">"; } } return answer; diff --git a/tooling/maven/camel-eip-documentation-enricher-maven-plugin/src/main/java/org/apache/camel/maven/EipDocumentationEnricherMojo.java b/tooling/maven/camel-eip-documentation-enricher-maven-plugin/src/main/java/org/apache/camel/maven/EipDocumentationEnricherMojo.java index 31f2aca7bffe5..2467dffe5fec2 100644 --- a/tooling/maven/camel-eip-documentation-enricher-maven-plugin/src/main/java/org/apache/camel/maven/EipDocumentationEnricherMojo.java +++ b/tooling/maven/camel-eip-documentation-enricher-maven-plugin/src/main/java/org/apache/camel/maven/EipDocumentationEnricherMojo.java @@ -123,7 +123,7 @@ public class EipDocumentationEnricherMojo extends AbstractMojo { protected MavenProject project; @Override - public void execute() throws MojoExecutionException, MojoFailureException { + public void execute() throws MojoExecutionException { if (pathToModelDir == null) { throw new MojoExecutionException("pathToModelDir parameter must not be null"); }