This is an automated email from the ASF dual-hosted git repository. aldettinger 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 7d4020e Fixed some warnings in camel-package-maven-plugin 7d4020e is described below commit 7d4020e756aab92a8899c1f401a89450ed04315e Author: aldettinger <aldettin...@gmail.com> AuthorDate: Mon May 14 18:25:51 2018 +0200 Fixed some warnings in camel-package-maven-plugin --- .../camel/maven/packaging/JSonSchemaHelper.java | 19 ++- .../maven/packaging/PackageDataFormatMojo.java | 80 ++++++------ .../camel/maven/packaging/PackageLanguageMojo.java | 141 +++++++++++---------- .../maven/packaging/PrepareCatalogKarafMojo.java | 31 ++--- .../camel/maven/packaging/PrepareCatalogMojo.java | 30 +++-- .../packaging/PrepareCatalogSpringBootMojo.java | 30 +++-- .../packaging/SpringBootAutoConfigurationMojo.java | 12 +- 7 files changed, 179 insertions(+), 164 deletions(-) diff --git a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/JSonSchemaHelper.java b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/JSonSchemaHelper.java index f49de19..027a7ae 100644 --- a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/JSonSchemaHelper.java +++ b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/JSonSchemaHelper.java @@ -36,7 +36,6 @@ public final class JSonSchemaHelper { * @param json the json * @return a list of all the rows, where each row is a set of key value pairs with metadata */ - @SuppressWarnings("unchecked") public static List<Map<String, String>> parseJsonSchema(String group, String json, boolean parseProperties) { List<Map<String, String>> answer = new ArrayList<>(); if (json == null) { @@ -47,24 +46,24 @@ public final class JSonSchemaHelper { try { JsonObject output = (JsonObject) Jsoner.deserialize(json); for (String key : output.keySet()) { - Map row = output.getMap(key); + Map<?, ?> row = output.getMap(key); if (key.equals(group)) { if (parseProperties) { // flattern each entry in the row with name as they key, and its value as the content (its a map also) for (Object obj : row.entrySet()) { - Map.Entry entry = (Map.Entry) obj; - Map<String, String> newRow = new LinkedHashMap(); + Map.Entry<?, ?> entry = (Map.Entry<?, ?>) obj; + Map<String, String> newRow = new LinkedHashMap<>(); newRow.put("name", entry.getKey().toString()); - Map newData = transformMap((Map) entry.getValue()); + Map<String, String> newData = transformMap((Map<?, ?>) entry.getValue()); newRow.putAll(newData); answer.add(newRow); } } else { // flattern each entry in the row as a list of single Map<key, value> elements - Map newData = transformMap(row); + Map<?, ?> newData = transformMap(row); for (Object obj : newData.entrySet()) { - Map.Entry entry = (Map.Entry) obj; + Map.Entry<?, ?> entry = (Map.Entry<?, ?>) obj; Map<String, String> newRow = new LinkedHashMap<>(); newRow.put(entry.getKey().toString(), entry.getValue().toString()); answer.add(newRow); @@ -80,16 +79,16 @@ public final class JSonSchemaHelper { return answer; } - private static Map<String, String> transformMap(Map jsonMap) { + private static Map<String, String> transformMap(Map<?, ?> jsonMap) { Map<String, String> answer = new LinkedHashMap<>(); for (Object rowObj : jsonMap.entrySet()) { - Map.Entry rowEntry = (Map.Entry) rowObj; + Map.Entry<?, ?> rowEntry = (Map.Entry<?, ?>) rowObj; // if its a list type then its an enum, and we need to parse it as a single line separated with comma // to be backwards compatible Object newValue = rowEntry.getValue(); if (newValue instanceof List) { - List list = (List) newValue; + List<?> list = (List<?>) newValue; CollectionStringBuffer csb = new CollectionStringBuffer(","); for (Object line : list) { csb.append(line); diff --git a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/PackageDataFormatMojo.java b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/PackageDataFormatMojo.java index 1818e7c..04280fa 100644 --- a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/PackageDataFormatMojo.java +++ b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/PackageDataFormatMojo.java @@ -147,7 +147,8 @@ public class PackageDataFormatMojo extends AbstractMojo { // is this from Apache Camel then the data format is out of the box and we should enrich the json schema with more details boolean apacheCamel = "org.apache.camel".equals(project.getGroupId()); - // find camel-core and grab the data format model from there, and enrich this model with information from this artifact + // find camel-core and grab the data format model from there, and enrich + // this model with information from this artifact // and create json schema model file for this data format try { if (apacheCamel && count > 0) { @@ -156,42 +157,45 @@ public class PackageDataFormatMojo extends AbstractMojo { File core = camelCore.getFile(); if (core != null) { URL url = new URL("file", null, core.getAbsolutePath()); - URLClassLoader loader = new URLClassLoader(new URL[]{url}); - for (Map.Entry<String, String> entry : javaTypes.entrySet()) { - String name = entry.getKey(); - String javaType = entry.getValue(); - String modelName = asModelName(name); - - InputStream is = loader.getResourceAsStream("org/apache/camel/model/dataformat/" + modelName + ".json"); - if (is == null) { - // use file input stream if we build camel-core itself, and thus do not have a JAR which can be loaded by URLClassLoader - is = new FileInputStream(new File(core, "org/apache/camel/model/dataformat/" + modelName + ".json")); - } - String json = loadText(is); - - DataFormatModel dataFormatModel = extractDataFormatModel(project, json, modelName, name, javaType); - log.debug("Model " + dataFormatModel); - - // build json schema for the data format - String properties = after(json, " \"properties\": {"); - - // special prepare for bindy/json properties - properties = prepareBindyProperties(name, properties); - properties = prepareJsonProperties(name, properties); - - String schema = createParameterJsonSchema(dataFormatModel, properties); - log.debug("JSon schema\n" + schema); - - // write this to the directory - File dir = new File(schemaOutDir, schemaSubDirectory(dataFormatModel.getJavaType())); - dir.mkdirs(); - - File out = new File(dir, name + ".json"); - OutputStream fos = buildContext.newFileOutputStream(out); - fos.write(schema.getBytes()); - fos.close(); - if (log.isDebugEnabled()) { - log.debug("Generated " + out + " containing JSon schema for " + name + " data format"); + try (URLClassLoader loader = new URLClassLoader(new URL[] {url})) { + for (Map.Entry<String, String> entry : javaTypes.entrySet()) { + String name = entry.getKey(); + String javaType = entry.getValue(); + String modelName = asModelName(name); + + InputStream is = loader.getResourceAsStream("org/apache/camel/model/dataformat/" + modelName + ".json"); + if (is == null) { + // use file input stream if we build + // camel-core itself, and thus do not have a + // JAR which can be loaded by URLClassLoader + is = new FileInputStream(new File(core, "org/apache/camel/model/dataformat/" + modelName + ".json")); + } + String json = loadText(is); + + DataFormatModel dataFormatModel = extractDataFormatModel(project, json, modelName, name, javaType); + log.debug("Model " + dataFormatModel); + + // build json schema for the data format + String properties = after(json, " \"properties\": {"); + + // special prepare for bindy/json properties + properties = prepareBindyProperties(name, properties); + properties = prepareJsonProperties(name, properties); + + String schema = createParameterJsonSchema(dataFormatModel, properties); + log.debug("JSon schema\n" + schema); + + // write this to the directory + File dir = new File(schemaOutDir, schemaSubDirectory(dataFormatModel.getJavaType())); + dir.mkdirs(); + + File out = new File(dir, name + ".json"); + OutputStream fos = buildContext.newFileOutputStream(out); + fos.write(schema.getBytes()); + fos.close(); + if (log.isDebugEnabled()) { + log.debug("Generated " + out + " containing JSon schema for " + name + " data format"); + } } } } @@ -433,7 +437,7 @@ public class PackageDataFormatMojo extends AbstractMojo { } // or its a component which has a dependency to camel-core - Iterator it = project.getDependencyArtifacts().iterator(); + Iterator<?> it = project.getDependencyArtifacts().iterator(); while (it.hasNext()) { artifact = (Artifact) it.next(); if (artifact.getGroupId().equals("org.apache.camel") && artifact.getArtifactId().equals("camel-core")) { diff --git a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/PackageLanguageMojo.java b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/PackageLanguageMojo.java index d0e9086..f10306d 100644 --- a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/PackageLanguageMojo.java +++ b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/PackageLanguageMojo.java @@ -144,10 +144,12 @@ public class PackageLanguageMojo extends AbstractMojo { } } - // is this from Apache Camel then the data format is out of the box and we should enrich the json schema with more details + // is this from Apache Camel then the data format is out of the box and + // we should enrich the json schema with more details boolean apacheCamel = "org.apache.camel".equals(project.getGroupId()); - // find camel-core and grab the language model from there, and enrich this model with information from this artifact + // find camel-core and grab the language model from there, and enrich + // this model with information from this artifact // and create json schema model file for this language try { if (apacheCamel && count > 0) { @@ -156,76 +158,81 @@ public class PackageLanguageMojo extends AbstractMojo { File core = camelCore.getFile(); if (core != null) { URL url = new URL("file", null, core.getAbsolutePath()); - URLClassLoader loader = new URLClassLoader(new URL[]{url}); - for (Map.Entry<String, String> entry : javaTypes.entrySet()) { - String name = entry.getKey(); - String javaType = entry.getValue(); - String modelName = asModelName(name); - - InputStream is = loader.getResourceAsStream("org/apache/camel/model/language/" + modelName + ".json"); - if (is == null) { - // use file input stream if we build camel-core itself, and thus do not have a JAR which can be loaded by URLClassLoader - is = new FileInputStream(new File(core, "org/apache/camel/model/language/" + modelName + ".json")); - } - String json = loadText(is); - LanguageModel languageModel = new LanguageModel(); - languageModel.setName(name); - languageModel.setTitle(""); - languageModel.setModelName(modelName); - languageModel.setLabel(""); - languageModel.setDescription(""); - languageModel.setJavaType(javaType); - languageModel.setGroupId(project.getGroupId()); - languageModel.setArtifactId(project.getArtifactId()); - languageModel.setVersion(project.getVersion()); - - List<Map<String, String>> rows = JSonSchemaHelper.parseJsonSchema("model", json, false); - for (Map<String, String> row : rows) { - if (row.containsKey("title")) { - // title may be special for some languages - String title = asTitle(name, row.get("title")); - languageModel.setTitle(title); - } - if (row.containsKey("description")) { - // description may be special for some languages - String desc = asDescription(name, row.get("description")); - languageModel.setDescription(desc); - } - if (row.containsKey("label")) { - languageModel.setLabel(row.get("label")); - } - if (row.containsKey("deprecated")) { - languageModel.setDeprecated(row.get("deprecated")); + try (URLClassLoader loader = new URLClassLoader(new URL[] {url})) { + for (Map.Entry<String, String> entry : javaTypes.entrySet()) { + String name = entry.getKey(); + String javaType = entry.getValue(); + String modelName = asModelName(name); + + InputStream is = loader.getResourceAsStream("org/apache/camel/model/language/" + modelName + ".json"); + if (is == null) { + // use file input stream if we build + // camel-core itself, and thus do not have a + // JAR which can be loaded by URLClassLoader + is = new FileInputStream(new File(core, "org/apache/camel/model/language/" + modelName + ".json")); } - if (row.containsKey("deprecationNote")) { - languageModel.setDeprecationNote(row.get("deprecationNote")); + String json = loadText(is); + LanguageModel languageModel = new LanguageModel(); + languageModel.setName(name); + languageModel.setTitle(""); + languageModel.setModelName(modelName); + languageModel.setLabel(""); + languageModel.setDescription(""); + languageModel.setJavaType(javaType); + languageModel.setGroupId(project.getGroupId()); + languageModel.setArtifactId(project.getArtifactId()); + languageModel.setVersion(project.getVersion()); + + List<Map<String, String>> rows = JSonSchemaHelper.parseJsonSchema("model", json, false); + for (Map<String, String> row : rows) { + if (row.containsKey("title")) { + // title may be special for some + // languages + String title = asTitle(name, row.get("title")); + languageModel.setTitle(title); + } + if (row.containsKey("description")) { + // description may be special for some + // languages + String desc = asDescription(name, row.get("description")); + languageModel.setDescription(desc); + } + if (row.containsKey("label")) { + languageModel.setLabel(row.get("label")); + } + if (row.containsKey("deprecated")) { + languageModel.setDeprecated(row.get("deprecated")); + } + if (row.containsKey("deprecationNote")) { + languageModel.setDeprecationNote(row.get("deprecationNote")); + } + if (row.containsKey("javaType")) { + languageModel.setModelJavaType(row.get("javaType")); + } + if (row.containsKey("firstVersion")) { + languageModel.setFirstVersion(row.get("firstVersion")); + } } - if (row.containsKey("javaType")) { - languageModel.setModelJavaType(row.get("javaType")); - } - if (row.containsKey("firstVersion")) { - languageModel.setFirstVersion(row.get("firstVersion")); - } - } - log.debug("Model " + languageModel); + log.debug("Model " + languageModel); - // build json schema for the data format - String properties = after(json, " \"properties\": {"); - String schema = createParameterJsonSchema(languageModel, properties); - log.debug("JSon schema\n" + schema); + // build json schema for the data format + String properties = after(json, " \"properties\": {"); + String schema = createParameterJsonSchema(languageModel, properties); + log.debug("JSon schema\n" + schema); - // write this to the directory - File dir = new File(schemaOutDir, schemaSubDirectory(languageModel.getJavaType())); - dir.mkdirs(); + // write this to the directory + File dir = new File(schemaOutDir, schemaSubDirectory(languageModel.getJavaType())); + dir.mkdirs(); - File out = new File(dir, name + ".json"); - OutputStream fos = buildContext.newFileOutputStream(out); - fos.write(schema.getBytes()); - fos.close(); + File out = new File(dir, name + ".json"); + OutputStream fos = buildContext.newFileOutputStream(out); + fos.write(schema.getBytes()); + fos.close(); - buildContext.refresh(out); - if (log.isDebugEnabled()) { - log.debug("Generated " + out + " containing JSon schema for " + name + " language"); + buildContext.refresh(out); + if (log.isDebugEnabled()) { + log.debug("Generated " + out + " containing JSon schema for " + name + " language"); + } } } } @@ -350,7 +357,7 @@ public class PackageLanguageMojo extends AbstractMojo { } // or its a component which has a dependency to camel-core - Iterator it = project.getDependencyArtifacts().iterator(); + Iterator<?> it = project.getDependencyArtifacts().iterator(); while (it.hasNext()) { artifact = (Artifact) it.next(); if (artifact.getGroupId().equals("org.apache.camel") && artifact.getArtifactId().equals("camel-core")) { diff --git a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/PrepareCatalogKarafMojo.java b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/PrepareCatalogKarafMojo.java index 9f9edb8..8a57af4 100644 --- a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/PrepareCatalogKarafMojo.java +++ b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/PrepareCatalogKarafMojo.java @@ -25,7 +25,6 @@ import java.io.InputStream; import java.nio.channels.FileChannel; import java.util.ArrayList; import java.util.Collections; -import java.util.HashSet; import java.util.LinkedHashSet; import java.util.List; import java.util.Set; @@ -602,21 +601,23 @@ public class PrepareCatalogKarafMojo extends AbstractMojo { public static void copyFile(File from, File to) throws IOException { FileChannel in = null; FileChannel out = null; - try { - in = new FileInputStream(from).getChannel(); - out = new FileOutputStream(to).getChannel(); + try (FileInputStream fis = new FileInputStream(from); FileOutputStream fos = new FileOutputStream(to)) { + try { + in = fis.getChannel(); + out = fos.getChannel(); - long size = in.size(); - long position = 0; - while (position < size) { - position += in.transferTo(position, BUFFER_SIZE, out); - } - } finally { - if (in != null) { - in.close(); - } - if (out != null) { - out.close(); + long size = in.size(); + long position = 0; + while (position < size) { + position += in.transferTo(position, BUFFER_SIZE, out); + } + } finally { + if (in != null) { + in.close(); + } + if (out != null) { + out.close(); + } } } } 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 22e3764..d12b84f 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 @@ -1601,21 +1601,23 @@ public class PrepareCatalogMojo extends AbstractMojo { public static void copyFile(File from, File to) throws IOException { FileChannel in = null; FileChannel out = null; - try { - in = new FileInputStream(from).getChannel(); - out = new FileOutputStream(to).getChannel(); + try (FileInputStream fis = new FileInputStream(from); FileOutputStream fos = new FileOutputStream(to)) { + try { + in = fis.getChannel(); + out = fos.getChannel(); - long size = in.size(); - long position = 0; - while (position < size) { - position += in.transferTo(position, BUFFER_SIZE, out); - } - } finally { - if (in != null) { - in.close(); - } - if (out != null) { - out.close(); + long size = in.size(); + long position = 0; + while (position < size) { + position += in.transferTo(position, BUFFER_SIZE, out); + } + } finally { + if (in != null) { + in.close(); + } + if (out != null) { + out.close(); + } } } } diff --git a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/PrepareCatalogSpringBootMojo.java b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/PrepareCatalogSpringBootMojo.java index 1cdbaa8..94ff4b9 100644 --- a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/PrepareCatalogSpringBootMojo.java +++ b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/PrepareCatalogSpringBootMojo.java @@ -643,21 +643,23 @@ public class PrepareCatalogSpringBootMojo extends AbstractMojo { public static void copyFile(File from, File to) throws IOException { FileChannel in = null; FileChannel out = null; - try { - in = new FileInputStream(from).getChannel(); - out = new FileOutputStream(to).getChannel(); + try (FileInputStream fis = new FileInputStream(from); FileOutputStream fos = new FileOutputStream(to)) { + try { + in = fis.getChannel(); + out = fos.getChannel(); - long size = in.size(); - long position = 0; - while (position < size) { - position += in.transferTo(position, BUFFER_SIZE, out); - } - } finally { - if (in != null) { - in.close(); - } - if (out != null) { - out.close(); + long size = in.size(); + long position = 0; + while (position < size) { + position += in.transferTo(position, BUFFER_SIZE, out); + } + } finally { + if (in != null) { + in.close(); + } + if (out != null) { + out.close(); + } } } } diff --git a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/SpringBootAutoConfigurationMojo.java b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/SpringBootAutoConfigurationMojo.java index 33b42fd..f7bcdd6 100644 --- a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/SpringBootAutoConfigurationMojo.java +++ b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/SpringBootAutoConfigurationMojo.java @@ -790,7 +790,7 @@ public class SpringBootAutoConfigurationMojo extends AbstractMojo { final PropertySource<JavaClassSource> prop = innerClass.addProperty(optionType, sourceProp.getName()); boolean anEnum; - Class optionClass; + Class<?> optionClass; if (!propType.isArray()) { optionClass = loadClass(projectClassLoader, optionType); anEnum = optionClass.isEnum(); @@ -930,8 +930,8 @@ public class SpringBootAutoConfigurationMojo extends AbstractMojo { } // try loading class, looking for inner classes if needed - private Class loadClass(ClassLoader projectClassLoader, String loadClassName) throws MojoFailureException { - Class optionClass; + private Class<?> loadClass(ClassLoader projectClassLoader, String loadClassName) throws MojoFailureException { + Class<?> optionClass; while (true) { try { optionClass = projectClassLoader.loadClass(loadClassName); @@ -962,7 +962,7 @@ public class SpringBootAutoConfigurationMojo extends AbstractMojo { } protected ClassLoader getProjectClassLoader() throws MojoFailureException { - final List classpathElements; + final List<?> classpathElements; try { classpathElements = project.getTestClasspathElements(); } catch (org.apache.maven.artifact.DependencyResolutionRequiredException e) { @@ -970,7 +970,7 @@ public class SpringBootAutoConfigurationMojo extends AbstractMojo { } final URL[] urls = new URL[classpathElements.size()]; int i = 0; - for (Iterator it = classpathElements.iterator(); it.hasNext(); i++) { + for (Iterator<?> it = classpathElements.iterator(); it.hasNext(); i++) { try { urls[i] = new File((String) it.next()).toURI().toURL(); } catch (MalformedURLException e) { @@ -1702,7 +1702,7 @@ public class SpringBootAutoConfigurationMojo extends AbstractMojo { return sb.toString(); } - private static void sortImports(Importer importer) { + private static void sortImports(Importer<JavaClassSource> importer) { // sort imports List<Import> imports = importer.getImports(); -- To stop receiving notification emails like this one, please contact aldettin...@apache.org.