From 6ced23dd584d2937de62781b9631e280bf3cf949 Mon Sep 17 00:00:00 2001 From: Guillaume Nodet Date: Tue, 19 Feb 2019 17:51:13 +0100 Subject: [PATCH] [CAMEL-13177] Improve build speed --- catalog/camel-catalog/pom.xml | 13 +- parent/pom.xml | 3 +- .../camel-spring-boot-dependencies/pom.xml | 56 +++---- .../packaging/AbstractGeneratorMojo.java | 4 +- .../maven/packaging/PrepareCatalogMojo.java | 85 +++++++--- .../SpringBootAutoConfigurationMojo.java | 156 +++++++----------- 6 files changed, 157 insertions(+), 160 deletions(-) diff --git a/catalog/camel-catalog/pom.xml b/catalog/camel-catalog/pom.xml index e5fde17510b3b..8ea231e2e835c 100644 --- a/catalog/camel-catalog/pom.xml +++ b/catalog/camel-catalog/pom.xml @@ -33,6 +33,7 @@ Camel Catalog + !org.apache.camel.util.json,* 2.15.0 @@ -249,18 +250,6 @@ - - - org.apache.felix - maven-bundle-plugin - true - - - org.apache.camel.catalog* - org.apache.camel.language.simple;resolution:=optional,!org.json.simple,* - - - diff --git a/parent/pom.xml b/parent/pom.xml index 268319a498967..b5609c01d8e6e 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -161,7 +161,7 @@ 1.4.13 1.4.13_1 2.12.0 - 3.3.0 + 3.3.1-SNAPSHOT [3.1,4.0) 3.2.0 3.2.0 @@ -5475,6 +5475,7 @@ true true + true true diff --git a/platforms/spring-boot/spring-boot-dm/camel-spring-boot-dependencies/pom.xml b/platforms/spring-boot/spring-boot-dm/camel-spring-boot-dependencies/pom.xml index 73bac12c27aa8..d0b443e098a4a 100644 --- a/platforms/spring-boot/spring-boot-dm/camel-spring-boot-dependencies/pom.xml +++ b/platforms/spring-boot/spring-boot-dm/camel-spring-boot-dependencies/pom.xml @@ -3076,142 +3076,142 @@ org.apache.cxf.services.sts cxf-services-sts-core - 3.3.0 + 3.3.1-SNAPSHOT org.apache.cxf.services.ws-discovery cxf-services-ws-discovery-api - 3.3.0 + 3.3.1-SNAPSHOT org.apache.cxf cxf-core - 3.3.0 + 3.3.1-SNAPSHOT org.apache.cxf cxf-rt-bindings-soap - 3.3.0 + 3.3.1-SNAPSHOT org.apache.cxf cxf-rt-bindings-xml - 3.3.0 + 3.3.1-SNAPSHOT org.apache.cxf cxf-rt-databinding-jaxb - 3.3.0 + 3.3.1-SNAPSHOT org.apache.cxf cxf-rt-features-clustering - 3.3.0 + 3.3.1-SNAPSHOT org.apache.cxf cxf-rt-features-logging - 3.3.0 + 3.3.1-SNAPSHOT org.apache.cxf cxf-rt-frontend-jaxrs - 3.3.0 + 3.3.1-SNAPSHOT org.apache.cxf cxf-rt-frontend-jaxws - 3.3.0 + 3.3.1-SNAPSHOT org.apache.cxf cxf-rt-frontend-simple - 3.3.0 + 3.3.1-SNAPSHOT org.apache.cxf cxf-rt-management - 3.3.0 + 3.3.1-SNAPSHOT org.apache.cxf cxf-rt-rs-client - 3.3.0 + 3.3.1-SNAPSHOT org.apache.cxf cxf-rt-rs-extension-providers - 3.3.0 + 3.3.1-SNAPSHOT org.apache.cxf cxf-rt-rs-security-oauth2 - 3.3.0 + 3.3.1-SNAPSHOT org.apache.cxf cxf-rt-rs-service-description-swagger - 3.3.0 + 3.3.1-SNAPSHOT org.apache.cxf cxf-rt-transports-http - 3.3.0 + 3.3.1-SNAPSHOT org.apache.cxf cxf-rt-transports-http-jetty - 3.3.0 + 3.3.1-SNAPSHOT org.apache.cxf cxf-rt-transports-jms - 3.3.0 + 3.3.1-SNAPSHOT org.apache.cxf cxf-rt-transports-local - 3.3.0 + 3.3.1-SNAPSHOT org.apache.cxf cxf-rt-ws-addr - 3.3.0 + 3.3.1-SNAPSHOT org.apache.cxf cxf-rt-ws-mex - 3.3.0 + 3.3.1-SNAPSHOT org.apache.cxf cxf-rt-ws-policy - 3.3.0 + 3.3.1-SNAPSHOT org.apache.cxf cxf-rt-ws-rm - 3.3.0 + 3.3.1-SNAPSHOT org.apache.cxf cxf-rt-ws-security - 3.3.0 + 3.3.1-SNAPSHOT org.apache.cxf cxf-rt-ws-security-oauth2 - 3.3.0 + 3.3.1-SNAPSHOT org.apache.cxf cxf-rt-wsdl - 3.3.0 + 3.3.1-SNAPSHOT org.apache.cxf cxf-testutils - 3.3.0 + 3.3.1-SNAPSHOT org.apache.ftpserver 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 0e9aa042802da..ece77cc988efe 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 @@ -89,7 +89,9 @@ public static String createProperties(MavenProject project, String key, String v } public static void refresh(BuildContext buildContext, Path file) { - buildContext.refresh(file.toFile()); + if (buildContext != null) { + buildContext.refresh(file.toFile()); + } } public static void updateResource(BuildContext buildContext, Path out, String data) { 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 7f1da489ee05e..b005be6b21d94 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 @@ -221,9 +221,16 @@ protected void executeModel() throws MojoExecutionException, MojoFailureExceptio for (File file : jsonFiles) { File to = new File(modelsOutDir, file.getName()); - if (warnDups && to.exists()) { - duplicateJsonFiles.add(to); - getLog().warn("Duplicate model name detected: " + to); + if (to.exists()) { + if (warnDups) { + duplicateJsonFiles.add(to); + getLog().warn("Duplicate model name detected: " + to); + } else if (file.lastModified() < to.lastModified()) { + getLog().debug("Skipping generated file: " + to); + continue; + } else { + getLog().warn("Stale file: " + to); + } } try { copyFile(file, to); @@ -245,12 +252,7 @@ protected void executeModel() throws MojoExecutionException, MojoFailureExceptio String label = matcher.group(1); String[] labels = label.split(","); for (String s : labels) { - Set models = usedLabels.get(s); - if (models == null) { - models = new TreeSet<>(); - usedLabels.put(s, models); - } - models.add(name); + usedLabels.computeIfAbsent(s, k -> new TreeSet<>()).add(name); } } } @@ -394,9 +396,16 @@ protected Set executeComponents() throws MojoExecutionException, MojoFai for (File file : jsonFiles) { File to = new File(componentsOutDir, file.getName()); - if (warnDups && to.exists()) { - duplicateJsonFiles.add(to); - getLog().warn("Duplicate component name detected: " + to); + if (to.exists()) { + if (warnDups) { + duplicateJsonFiles.add(to); + getLog().warn("Duplicate component name detected: " + to); + } else if (file.lastModified() < to.lastModified()) { + getLog().debug("Skipping generated file: " + to); + continue; + } else { + getLog().warn("Stale file: " + to); + } } try { copyFile(file, to); @@ -577,9 +586,16 @@ protected Set executeDataFormats() throws MojoExecutionException, MojoFa for (File file : jsonFiles) { File to = new File(dataFormatsOutDir, file.getName()); - if (warnDups && to.exists()) { - duplicateJsonFiles.add(to); - getLog().warn("Duplicate dataformat name detected: " + to); + if (to.exists()) { + if (warnDups) { + duplicateJsonFiles.add(to); + getLog().warn("Duplicate dataformat name detected: " + to); + } else if (file.lastModified() < to.lastModified()) { + getLog().debug("Skipping generated file: " + to); + continue; + } else { + getLog().warn("Stale file: " + to); + } } try { copyFile(file, to); @@ -702,9 +718,16 @@ protected Set executeLanguages() throws MojoExecutionException, MojoFail for (File file : jsonFiles) { File to = new File(languagesOutDir, file.getName()); - if (warnDups && to.exists()) { - duplicateJsonFiles.add(to); - getLog().warn("Duplicate language name detected: " + to); + if (to.exists()) { + if (warnDups) { + duplicateJsonFiles.add(to); + getLog().warn("Duplicate language name detected: " + to); + } else if (file.lastModified() < to.lastModified()) { + getLog().debug("Skipping generated file: " + to); + continue; + } else { + getLog().warn("Stale file: " + to); + } } try { copyFile(file, to); @@ -844,9 +867,16 @@ private Set executeOthers() throws MojoFailureException { for (File file : jsonFiles) { File to = new File(othersOutDir, file.getName()); - if (warnDups && to.exists()) { - duplicateJsonFiles.add(to); - getLog().warn("Duplicate other name detected: " + to); + if (to.exists()) { + if (warnDups) { + duplicateJsonFiles.add(to); + getLog().warn("Duplicate other name detected: " + to); + } else if (file.lastModified() < to.lastModified()) { + getLog().debug("Skipping generated file: " + to); + continue; + } else { + getLog().warn("Stale file: " + to); + } } try { copyFile(file, to); @@ -1043,9 +1073,16 @@ protected void executeDocuments(Set components, Set dataformats, for (File file : adocFiles) { File to = new File(documentsOutDir, file.getName()); - if (warnDups && to.exists()) { - duplicateAdocFiles.add(to); - getLog().warn("Duplicate document name detected: " + to); + if (to.exists()) { + if (warnDups) { + duplicateAdocFiles.add(to); + getLog().warn("Duplicate document name detected: " + to); + } else if (file.lastModified() < to.lastModified()) { + getLog().debug("Skipping generated file: " + to); + continue; + } else { + getLog().warn("Stale file: " + to); + } } try { copyFile(file, to); 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 32b6c42be3876..1cce076386578 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 @@ -19,6 +19,7 @@ import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; +import java.io.IOError; import java.io.IOException; import java.io.InputStream; import java.lang.reflect.Modifier; @@ -37,6 +38,8 @@ import java.util.Map; import java.util.Set; import java.util.TreeSet; +import java.util.function.Function; +import java.util.function.Supplier; import java.util.regex.Pattern; import java.util.stream.Collectors; import javax.annotation.Generated; @@ -90,6 +93,7 @@ import org.springframework.context.annotation.Lazy; import org.springframework.context.annotation.Scope; +import static org.apache.camel.maven.packaging.AbstractGeneratorMojo.updateResource; import static org.apache.camel.maven.packaging.JSonSchemaHelper.getPropertyDefaultValue; import static org.apache.camel.maven.packaging.JSonSchemaHelper.getPropertyDescriptionValue; import static org.apache.camel.maven.packaging.JSonSchemaHelper.getPropertyJavaType; @@ -190,15 +194,42 @@ public void execute() throws MojoExecutionException, MojoFailureException { return; } - executeModels(); - executeComponent(); - executeDataFormat(); - executeLanguage(); + executeAll(); } - private void executeModels() throws MojoExecutionException, MojoFailureException { - final Set files = PackageHelper.findJsonFiles(buildDir, p -> p.isDirectory() || p.getName().endsWith(".json")); + private void executeAll() throws MojoExecutionException, MojoFailureException { + Map> files = + PackageHelper.findJsonFiles(buildDir, p -> p.isDirectory() || p.getName().endsWith(".json")) + .stream().collect(Collectors.toMap(Function.identity(), s -> cache(() -> loadJson(s)))); + executeModels(files); + executeComponent(files); + executeDataFormat(files); + executeLanguage(files); + } + + private static String loadJson(File file) { + try (InputStream is = new FileInputStream(file)) { + return loadText(is); + } catch (IOException e) { + throw new IOError(e); + } + } + + private static Supplier cache(Supplier supplier) { + return new Supplier() { + T value; + @Override + public T get() { + if (value == null) { + value = supplier.get(); + } + return value; + } + }; + } + + private void executeModels(Map> files) throws MojoExecutionException, MojoFailureException { String json; // Hystrix @@ -547,21 +578,16 @@ private void createRestModuleAutoConfigurationSource(String packageName, OtherMo + "return definition;" ); - sortImports(javaClass); - String fileName = packageName.replaceAll("\\.", "\\/") + "/" + name + ".java"; writeSourceIfChanged(javaClass, fileName); writeComponentSpringFactorySource(packageName, name); } - private void executeComponent() throws MojoExecutionException, MojoFailureException { + private void executeComponent(Map> jsonFiles) throws MojoExecutionException, MojoFailureException { // find the component names Set componentNames = new TreeSet<>(); findComponentNames(buildDir, componentNames); - final Set jsonFiles = new TreeSet<>(); - PackageHelper.findJsonFiles(buildDir, jsonFiles, new PackageHelper.CamelComponentsModelFilter()); - // create auto configuration for the components if (!componentNames.isEmpty()) { getLog().debug("Found " + componentNames.size() + " components"); @@ -603,14 +629,10 @@ private void executeComponent() throws MojoExecutionException, MojoFailureExcept } } - private void executeDataFormat() throws MojoExecutionException, MojoFailureException { + private void executeDataFormat(Map> jsonFiles) throws MojoExecutionException, MojoFailureException { // find the data format names List dataFormatNames = findDataFormatNames(); - final Set jsonFiles = new TreeSet<>(); - // we can reuse the component model filter - PackageHelper.findJsonFiles(buildDir, jsonFiles, new PackageHelper.CamelComponentsModelFilter()); - // create auto configuration for the data formats if (!dataFormatNames.isEmpty()) { getLog().debug("Found " + dataFormatNames.size() + " dataformats"); @@ -649,14 +671,10 @@ private void executeDataFormat() throws MojoExecutionException, MojoFailureExcep } } - private void executeLanguage() throws MojoExecutionException, MojoFailureException { + private void executeLanguage(Map> jsonFiles) throws MojoExecutionException, MojoFailureException { // find the language names List languageNames = findLanguageNames(); - final Set jsonFiles = new TreeSet<>(); - // we can reuse the component model filter - PackageHelper.findJsonFiles(buildDir, jsonFiles, new PackageHelper.CamelComponentsModelFilter()); - // create auto configuration for the languages if (!languageNames.isEmpty()) { getLog().debug("Found " + languageNames.size() + " languages"); @@ -1871,70 +1889,30 @@ private static void sortImports(Importer importer) { } } - private static String loadModelJson(Set jsonFiles, String modelName) { - try { - for (File file : jsonFiles) { - if (file.getName().equals(modelName + ".json")) { - String json = loadText(new FileInputStream(file)); - boolean isModel = json.contains("\"kind\": \"model\""); - if (isModel) { - return json; - } - } - } - } catch (IOException e) { - // ignore - } - return null; + private static String loadModelJson(Map> jsonFiles, String modelName) { + return loadJsonOfType(jsonFiles, modelName, "model"); } - private static String loadComponentJson(Set jsonFiles, String componentName) { - try { - for (File file : jsonFiles) { - if (file.getName().equals(componentName + ".json")) { - String json = loadText(new FileInputStream(file)); - boolean isComponent = json.contains("\"kind\": \"component\""); - if (isComponent) { - return json; - } - } - } - } catch (IOException e) { - // ignore - } - return null; + private static String loadComponentJson(Map> jsonFiles, String componentName) { + return loadJsonOfType(jsonFiles, componentName, "component"); } - private static String loadDataFormatJson(Set jsonFiles, String dataFormatName) { - try { - for (File file : jsonFiles) { - if (file.getName().equals(dataFormatName + ".json")) { - String json = loadText(new FileInputStream(file)); - boolean isDataFormat = json.contains("\"kind\": \"dataformat\""); - if (isDataFormat) { - return json; - } - } - } - } catch (IOException e) { - // ignore - } - return null; + private static String loadDataFormatJson(Map> jsonFiles, String dataFormatName) { + return loadJsonOfType(jsonFiles, dataFormatName, "dataformat"); } - private static String loadLanguageJson(Set jsonFiles, String languageName) { - try { - for (File file : jsonFiles) { - if (file.getName().equals(languageName + ".json")) { - String json = loadText(new FileInputStream(file)); - boolean isLanguage = json.contains("\"kind\": \"language\""); - if (isLanguage) { - return json; - } + private static String loadLanguageJson(Map> jsonFiles, String languageName) { + return loadJsonOfType(jsonFiles, languageName, "language"); + } + + private static String loadJsonOfType(Map> jsonFiles, String modelName, String type) { + for (Map.Entry> entry : jsonFiles.entrySet()) { + if (entry.getKey().getName().equals(modelName + ".json")) { + String json = entry.getValue().get(); + if (json.contains("\"kind\": \"" + type + "\"")) { + return json; } } - } catch (IOException e) { - // ignore } return null; } @@ -2184,24 +2162,14 @@ private void writeSourceIfChanged(String source, String fileName) throws MojoFai deleteFileOnMainArtifact(target); try { - InputStream is = getClass().getClassLoader().getResourceAsStream("license-header-java.txt"); - String header = loadText(is); - String code = source; - code = header + code; + String header; + try (InputStream is = getClass().getClassLoader().getResourceAsStream("license-header-java.txt")) { + header = loadText(is); + } + String code = header + source; getLog().debug("Source code generated:\n" + code); - if (target.exists()) { - String existing = FileUtils.readFileToString(target); - if (!code.equals(existing)) { - FileUtils.write(target, code, false); - getLog().info("Updated existing file: " + target); - } else { - getLog().debug("No changes to existing file: " + target); - } - } else { - FileUtils.write(target, code); - getLog().info("Created file: " + target); - } + updateResource(null, target.toPath(), code); } catch (Exception e) { throw new MojoFailureException("IOError with file " + target, e); }