This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch catalog in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git
commit 75ab87169268fbafac5f154744d8d7932371a116 Author: Claus Ibsen <[email protected]> AuthorDate: Tue Oct 8 09:24:12 2019 +0200 #75: Adding camel-quarkus-catalog (work in progress) --- tooling/maven/package-maven-plugin/pom.xml | 103 +++ .../apache/camel/quarkus/maven/PackageHelper.java | 179 ++++++ .../quarkus/maven/PrepareCatalogQuarkusMojo.java | 715 +++++++++++++++++++++ .../src/main/resources/META-INF/LICENSE.txt | 203 ++++++ .../src/main/resources/META-INF/NOTICE.txt | 11 + .../camel-quarkus-package-maven-plugin.properties | 16 + tooling/maven/pom.xml | 7 +- tooling/parent/pom.xml | 151 +++++ tooling/pom.xml | 1 + 9 files changed, 1382 insertions(+), 4 deletions(-) diff --git a/tooling/maven/package-maven-plugin/pom.xml b/tooling/maven/package-maven-plugin/pom.xml new file mode 100644 index 0000000..db07ee0 --- /dev/null +++ b/tooling/maven/package-maven-plugin/pom.xml @@ -0,0 +1,103 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + + 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. + +--> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + + <modelVersion>4.0.0</modelVersion> + <parent> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-tooling-maven</artifactId> + <version>0.2.1-SNAPSHOT</version> + </parent> + + <artifactId>camel-quarkus-package-maven-plugin</artifactId> + <packaging>maven-plugin</packaging> + + <name>Camel Quarkus :: Tooling :: Maven :: Camel Quarkus Package Maven Plugin</name> + <description>Maven plugin to help package Camel quarkus components and plugins</description> + + <dependencyManagement> + <dependencies> + <dependency> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>tooling-parent</artifactId> + <version>${project.version}</version> + <type>pom</type> + <scope>import</scope> + </dependency> + </dependencies> + </dependencyManagement> + + <dependencies> + <dependency> + <groupId>org.apache.maven</groupId> + <artifactId>maven-core</artifactId> + <exclusions> + <exclusion> + <groupId>org.codehaus.plexus</groupId> + <artifactId>plexus-classworlds</artifactId> + </exclusion> + <exclusion> + <groupId>org.codehaus.plexus</groupId> + <artifactId>plexus-component-annotations</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.apache.maven</groupId> + <artifactId>maven-artifact</artifactId> + </dependency> + <dependency> + <groupId>org.apache.maven</groupId> + <artifactId>maven-plugin-api</artifactId> + </dependency> + <dependency> + <groupId>org.apache.maven.plugin-tools</groupId> + <artifactId>maven-plugin-annotations</artifactId> + </dependency> + <dependency> + <groupId>org.codehaus.plexus</groupId> + <artifactId>plexus-container-default</artifactId> + </dependency> + <dependency> + <groupId>org.codehaus.plexus</groupId> + <artifactId>plexus-utils</artifactId> + </dependency> + <dependency> + <groupId>org.sonatype.plexus</groupId> + <artifactId>plexus-build-api</artifactId> + </dependency> + </dependencies> + + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-plugin-plugin</artifactId> + <configuration> + <mojoDependencies> + <dep>org.apache.maven:maven-plugin-api</dep> + </mojoDependencies> + </configuration> + </plugin> + </plugins> + </build> + +</project> diff --git a/tooling/maven/package-maven-plugin/src/main/java/org/apache/camel/quarkus/maven/PackageHelper.java b/tooling/maven/package-maven-plugin/src/main/java/org/apache/camel/quarkus/maven/PackageHelper.java new file mode 100644 index 0000000..098c99c --- /dev/null +++ b/tooling/maven/package-maven-plugin/src/main/java/org/apache/camel/quarkus/maven/PackageHelper.java @@ -0,0 +1,179 @@ +/* + * 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.quarkus.maven; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileFilter; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.LineNumberReader; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.HashMap; +import java.util.Map; +import java.util.Set; +import java.util.TreeSet; + +// TODO: Remove not needed stuff + +public final class PackageHelper { + + private PackageHelper() { + } + + /** + * Loads the entire stream into memory as a String and returns it. + * <p/> + * <b>Notice:</b> This implementation appends a <tt>\n</tt> as line + * terminator at the of the text. + * <p/> + * Warning, don't use for crazy big streams :) + */ + public static String loadText(InputStream in) throws IOException { + StringBuilder builder = new StringBuilder(); + InputStreamReader isr = new InputStreamReader(in); + try { + BufferedReader reader = new LineNumberReader(isr); + while (true) { + String line = reader.readLine(); + if (line != null) { + builder.append(line); + builder.append("\n"); + } else { + break; + } + } + return builder.toString(); + } finally { + isr.close(); + in.close(); + } + } + + public static void writeText(File file, String text) throws IOException { + FileOutputStream fos = new FileOutputStream(file, false); + try { + fos.write(text.getBytes()); + } finally { + fos.close(); + } + } + + public static String after(String text, String after) { + if (!text.contains(after)) { + return null; + } + return text.substring(text.indexOf(after) + after.length()); + } + + /** + * Parses the text as a map (eg key=value) + * @param data the data + * @return the map + */ + public static Map<String, String> parseAsMap(String data) { + Map<String, String> answer = new HashMap<>(); + if (data != null) { + String[] lines = data.split("\n"); + for (String line : lines) { + int idx = line.indexOf('='); + if (idx != -1) { + String key = line.substring(0, idx); + String value = line.substring(idx + 1); + // remove ending line break for the values + value = value.trim().replaceAll("\n", ""); + answer.put(key.trim(), value); + } + } + } + return answer; + } + + public static Set<File> findJsonFiles(File dir, FileFilter filter) { + Set<File> files = new TreeSet<>(); + findJsonFiles(dir, files, filter); + + return files; + } + + public static void findJsonFiles(File dir, Set<File> found, FileFilter filter) { + File[] files = dir.listFiles(filter); + if (files != null) { + for (File file : files) { + // skip files in root dirs as Camel does not store information there but others may do + boolean jsonFile = file.isFile() && file.getName().endsWith(".json"); + if (jsonFile) { + found.add(file); + } else if (file.isDirectory()) { + findJsonFiles(file, found, filter); + } + } + } + } + + public static class CamelComponentsModelFilter implements FileFilter { + + @Override + public boolean accept(File pathname) { + return pathname.isDirectory() || pathname.getName().endsWith(".json"); + } + } + + public static class CamelOthersModelFilter implements FileFilter { + + @Override + public boolean accept(File pathname) { + String name = pathname.getName(); + boolean special = "camel-core-osgi".equals(name) + || "camel-core-xml".equals(name) + || "camel-http-common".equals(name) + || "camel-jetty-common".equals(name); + boolean special2 = "camel-as2".equals(name) + || "camel-box".equals(name) + || "camel-linkedin".equals(name) + || "camel-olingo2".equals(name) + || "camel-olingo4".equals(name) + || "camel-salesforce".equals(name); + if (special || special2) { + return false; + } + + return pathname.isDirectory() || name.endsWith(".json"); + } + } + + public static File findCamelCoreDirectory(File dir) { + return findCamelDirectory(dir, "core/camel-core-engine"); + } + + public static File findCamelDirectory(File dir, String path) { + if (dir == null) { + return null; + } + Path p = dir.toPath().resolve(path); + if (Files.isDirectory(p)) { + return p.toFile(); + } else { + // okay walk up the parent dir + return findCamelDirectory(dir.getParentFile(), path); + } + } + +} diff --git a/tooling/maven/package-maven-plugin/src/main/java/org/apache/camel/quarkus/maven/PrepareCatalogQuarkusMojo.java b/tooling/maven/package-maven-plugin/src/main/java/org/apache/camel/quarkus/maven/PrepareCatalogQuarkusMojo.java new file mode 100644 index 0000000..59027a7 --- /dev/null +++ b/tooling/maven/package-maven-plugin/src/main/java/org/apache/camel/quarkus/maven/PrepareCatalogQuarkusMojo.java @@ -0,0 +1,715 @@ +/* + * 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.quarkus.maven; + +import java.io.File; +import java.io.FileFilter; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.nio.channels.FileChannel; +import java.util.ArrayList; +import java.util.Collections; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Set; +import java.util.TreeSet; +import java.util.regex.Pattern; + +import org.apache.maven.plugin.AbstractMojo; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.MojoFailureException; +import org.apache.maven.plugins.annotations.Component; +import org.apache.maven.plugins.annotations.Mojo; +import org.apache.maven.plugins.annotations.Parameter; +import org.apache.maven.project.MavenProject; +import org.apache.maven.project.MavenProjectHelper; + +import static org.apache.camel.quarkus.maven.PackageHelper.loadText; + +/** + * Prepares the Quarkus provider camel catalog to include component it supports + */ +@Mojo(name = "prepare-catalog-quarkus", threadSafe = true) +public class PrepareCatalogQuarkusMojo extends AbstractMojo { + + public static final int BUFFER_SIZE = 128 * 1024; + + private static final Pattern ARTIFACT_PATTERN = Pattern.compile("\"artifactId\": \"camel-(.*)\""); + + /** + * The maven project. + */ + @Parameter(property = "project", required = true, readonly = true) + protected MavenProject project; + + /** + * The output directory for components catalog + */ + @Parameter(defaultValue = "${project.build.directory}/classes/org/apache/camel/catalog/springboot/components") + protected File componentsOutDir; + + /** + * The output directory for dataformats catalog + */ + @Parameter(defaultValue = "${project.build.directory}/classes/org/apache/camel/catalog/springboot/dataformats") + protected File dataFormatsOutDir; + + /** + * The output directory for languages catalog + */ + @Parameter(defaultValue = "${project.build.directory}/classes/org/apache/camel/catalog/springboot/languages") + protected File languagesOutDir; + + /** + * The output directory for others catalog + */ + @Parameter(defaultValue = "${project.build.directory}/classes/org/apache/camel/catalog/springboot/others") + protected File othersOutDir; + + /** + * The directory where all spring-boot starters are + */ + @Parameter(defaultValue = "${project.build.directory}/../../../platforms/spring-boot/quarkus-starter") + protected File componentsStarterDir; + + /** + * The components directory where all the Apache Camel components are + */ + @Parameter(defaultValue = "${project.build.directory}/../../../components") + protected File componentsDir; + + /** + * The camel-core directory + */ + @Parameter(defaultValue = "${project.build.directory}/../../../core/camel-core-engine") + protected File coreDir; + + /** + * The camel-base directory + */ + @Parameter(defaultValue = "${project.build.directory}/../../../core/camel-base") + protected File baseDir; + + /** + * Maven ProjectHelper. + */ + @Component + private MavenProjectHelper projectHelper; + + /** + * Execute goal. + * + * @throws MojoExecutionException execution of the main class or one of the + * threads it generated failed. + * @throws MojoFailureException something bad happened... + */ + @Override + public void execute() throws MojoExecutionException, MojoFailureException { + Set<String> starters = findSpringBootStarters(); + executeComponents(starters); + executeDataFormats(starters); + executeLanguages(starters); + executeOthers(starters); + } + + protected void executeComponents(Set<String> starters) throws MojoExecutionException, MojoFailureException { + getLog().info("Copying all Camel component json descriptors"); + + // lets use sorted set/maps + Set<File> jsonFiles = new TreeSet<>(); + Set<File> componentFiles = new TreeSet<>(); + + // find all json files in components and camel-core + if (componentsDir != null && componentsDir.isDirectory()) { + File[] components = componentsDir.listFiles(); + if (components != null) { + for (File dir : components) { + if (dir.isDirectory() && !"target".equals(dir.getName())) { + File target = new File(dir, "target/classes"); + + // the directory must be in the list of known features + if (!starters.contains(dir.getName())) { + continue; + } + + // special for some which is in a sub dir + if ("camel-as2".equals(dir.getName())) { + target = new File(dir, "camel-as2-component/target/classes"); + } else if ("camel-box".equals(dir.getName())) { + target = new File(dir, "camel-box-component/target/classes"); + } else if ("camel-salesforce".equals(dir.getName())) { + target = new File(dir, "camel-salesforce-component/target/classes"); + } else if ("camel-linkedin".equals(dir.getName())) { + target = new File(dir, "camel-linkedin-component/target/classes"); + } else if ("camel-servicenow".equals(dir.getName())) { + target = new File(dir, "camel-servicenow-component/target/classes"); + } else { + // this module must be active with a source folder + File src = new File(dir, "src"); + boolean active = src.isDirectory() && src.exists(); + if (!active) { + continue; + } + } + + + findComponentFilesRecursive(target, jsonFiles, componentFiles, new CamelComponentsFileFilter()); + } + } + } + } + if (coreDir != null && coreDir.isDirectory()) { + File target = new File(coreDir, "target/classes"); + findComponentFilesRecursive(target, jsonFiles, componentFiles, new CamelComponentsFileFilter()); + } + + getLog().info("Found " + componentFiles.size() + " component.properties files"); + getLog().info("Found " + jsonFiles.size() + " component json files"); + + // make sure to create out dir + componentsOutDir.mkdirs(); + + for (File file : jsonFiles) { + // for spring-boot we need to amend the json file to use -starter as the artifact-id + try { + String text = loadText(new FileInputStream(file)); + + text = ARTIFACT_PATTERN.matcher(text).replaceFirst("\"artifactId\": \"camel-$1-starter\""); + + // write new json file + File to = new File(componentsOutDir, file.getName()); + FileOutputStream fos = new FileOutputStream(to, false); + + fos.write(text.getBytes()); + + fos.close(); + + } catch (IOException e) { + throw new MojoFailureException("Cannot write json file " + file, e); + } + } + + File all = new File(componentsOutDir, "../components.properties"); + try { + FileOutputStream fos = new FileOutputStream(all, false); + + String[] names = componentsOutDir.list(); + List<String> components = new ArrayList<>(); + // sort the names + for (String name : names) { + if (name.endsWith(".json")) { + // strip out .json from the name + String componentName = name.substring(0, name.length() - 5); + components.add(componentName); + } + } + + Collections.sort(components); + for (String name : components) { + fos.write(name.getBytes()); + fos.write("\n".getBytes()); + } + + fos.close(); + + } catch (IOException e) { + throw new MojoFailureException("Error writing to file " + all); + } + } + + protected void executeDataFormats(Set<String> starters) throws MojoExecutionException, MojoFailureException { + getLog().info("Copying all Camel dataformat json descriptors"); + + // lets use sorted set/maps + Set<File> jsonFiles = new TreeSet<>(); + Set<File> dataFormatFiles = new TreeSet<>(); + + // find all data formats from the components directory + if (componentsDir != null && componentsDir.isDirectory()) { + File[] dataFormats = componentsDir.listFiles(); + if (dataFormats != null) { + for (File dir : dataFormats) { + if (dir.isDirectory() && !"target".equals(dir.getName())) { + // the directory must be in the list of known starters + if (!starters.contains(dir.getName())) { + continue; + } + // this module must be active with a source folder + File src = new File(dir, "src"); + boolean active = src.isDirectory() && src.exists(); + if (!active) { + continue; + } + File target = new File(dir, "target/classes"); + findDataFormatFilesRecursive(target, jsonFiles, dataFormatFiles, new CamelDataFormatsFileFilter()); + } + } + } + } + if (coreDir != null && coreDir.isDirectory()) { + File target = new File(coreDir, "target/classes"); + findDataFormatFilesRecursive(target, jsonFiles, dataFormatFiles, new CamelDataFormatsFileFilter()); + } + + getLog().info("Found " + dataFormatFiles.size() + " dataformat.properties files"); + getLog().info("Found " + jsonFiles.size() + " dataformat json files"); + + // make sure to create out dir + dataFormatsOutDir.mkdirs(); + + for (File file : jsonFiles) { + // for spring-boot we need to amend the json file to use -starter as the artifact-id + try { + String text = loadText(new FileInputStream(file)); + + text = ARTIFACT_PATTERN.matcher(text).replaceFirst("\"artifactId\": \"camel-$1-starter\""); + + // write new json file + File to = new File(dataFormatsOutDir, file.getName()); + FileOutputStream fos = new FileOutputStream(to, false); + + fos.write(text.getBytes()); + + fos.close(); + + } catch (IOException e) { + throw new MojoFailureException("Cannot write json file " + file, e); + } + } + + File all = new File(dataFormatsOutDir, "../dataformats.properties"); + try { + FileOutputStream fos = new FileOutputStream(all, false); + + String[] names = dataFormatsOutDir.list(); + List<String> dataFormats = new ArrayList<>(); + // sort the names + for (String name : names) { + if (name.endsWith(".json")) { + // strip out .json from the name + String dataFormatName = name.substring(0, name.length() - 5); + dataFormats.add(dataFormatName); + } + } + + Collections.sort(dataFormats); + for (String name : dataFormats) { + fos.write(name.getBytes()); + fos.write("\n".getBytes()); + } + + fos.close(); + + } catch (IOException e) { + throw new MojoFailureException("Error writing to file " + all); + } + } + + protected void executeLanguages(Set<String> starters) throws MojoExecutionException, MojoFailureException { + getLog().info("Copying all Camel language json descriptors"); + + // lets use sorted set/maps + Set<File> jsonFiles = new TreeSet<>(); + Set<File> languageFiles = new TreeSet<>(); + + // find all languages from the components directory + if (componentsDir != null && componentsDir.isDirectory()) { + File[] languages = componentsDir.listFiles(); + if (languages != null) { + for (File dir : languages) { + // the directory must be in the list of known starters + if (!starters.contains(dir.getName())) { + continue; + } + // this module must be active with a source folder + File src = new File(dir, "src"); + boolean active = src.isDirectory() && src.exists(); + if (!active) { + continue; + } + if (dir.isDirectory() && !"target".equals(dir.getName())) { + File target = new File(dir, "target/classes"); + findLanguageFilesRecursive(target, jsonFiles, languageFiles, new CamelLanguagesFileFilter()); + } + } + } + } + if (baseDir != null && baseDir.isDirectory()) { + File target = new File(baseDir, "target/classes"); + findLanguageFilesRecursive(target, jsonFiles, languageFiles, new CamelLanguagesFileFilter()); + // also look in camel-jaxp + target = new File(coreDir, "../camel-jaxp/target/classes"); + findLanguageFilesRecursive(target, jsonFiles, languageFiles, new CamelLanguagesFileFilter()); + } + + getLog().info("Found " + languageFiles.size() + " language.properties files"); + getLog().info("Found " + jsonFiles.size() + " language json files"); + + // make sure to create out dir + languagesOutDir.mkdirs(); + + for (File file : jsonFiles) { + // for spring-boot we need to amend the json file to use -starter as the artifact-id + try { + String text = loadText(new FileInputStream(file)); + + text = ARTIFACT_PATTERN.matcher(text).replaceFirst("\"artifactId\": \"camel-$1-starter\""); + + // write new json file + File to = new File(languagesOutDir, file.getName()); + FileOutputStream fos = new FileOutputStream(to, false); + + fos.write(text.getBytes()); + + fos.close(); + + } catch (IOException e) { + throw new MojoFailureException("Cannot write json file " + file, e); + } + } + + File all = new File(languagesOutDir, "../languages.properties"); + try { + FileOutputStream fos = new FileOutputStream(all, false); + + String[] names = languagesOutDir.list(); + List<String> languages = new ArrayList<>(); + // sort the names + for (String name : names) { + if (name.endsWith(".json")) { + // strip out .json from the name + String languageName = name.substring(0, name.length() - 5); + languages.add(languageName); + } + } + + Collections.sort(languages); + for (String name : languages) { + fos.write(name.getBytes()); + fos.write("\n".getBytes()); + } + + fos.close(); + + } catch (IOException e) { + throw new MojoFailureException("Error writing to file " + all); + } + } + + protected void executeOthers(Set<String> starters) throws MojoExecutionException, MojoFailureException { + getLog().info("Copying all Camel other json descriptors"); + + // lets use sorted set/maps + Set<File> jsonFiles = new TreeSet<>(); + Set<File> otherFiles = new TreeSet<>(); + + // find all other from the components directory + if (componentsDir != null && componentsDir.isDirectory()) { + File[] others = componentsDir.listFiles(); + if (others != null) { + for (File dir : others) { + // the directory must be in the list of known starters + if (!starters.contains(dir.getName())) { + continue; + } + + // skip these special cases + boolean special = "camel-core-osgi".equals(dir.getName()) + || "camel-core-xml".equals(dir.getName()) + || "camel-http-common".equals(dir.getName()) + || "camel-jetty-common".equals(dir.getName()); + boolean special2 = "camel-as2".equals(dir.getName()) + || "camel-box".equals(dir.getName()) + || "camel-linkedin".equals(dir.getName()) + || "camel-olingo2".equals(dir.getName()) + || "camel-olingo4".equals(dir.getName()) + || "camel-servicenow".equals(dir.getName()) + || "camel-salesforce".equals(dir.getName()); + if (special || special2) { + continue; + } + + // this module must be active with a source folder + File src = new File(dir, "src"); + boolean active = src.isDirectory() && src.exists(); + if (!active) { + continue; + } + + if (dir.isDirectory() && !"target".equals(dir.getName())) { + File target = new File(dir, "target/classes"); + findOtherFilesRecursive(target, jsonFiles, otherFiles, new CamelOthersFileFilter()); + } + } + } + } + + getLog().info("Found " + otherFiles.size() + " other.properties files"); + getLog().info("Found " + jsonFiles.size() + " other json files"); + + // make sure to create out dir + othersOutDir.mkdirs(); + + for (File file : jsonFiles) { + // for spring-boot we need to amend the json file to use -starter as the artifact-id + try { + String text = loadText(new FileInputStream(file)); + + text = ARTIFACT_PATTERN.matcher(text).replaceFirst("\"artifactId\": \"camel-$1-starter\""); + + // write new json file + File to = new File(othersOutDir, file.getName()); + FileOutputStream fos = new FileOutputStream(to, false); + + fos.write(text.getBytes()); + + fos.close(); + + } catch (IOException e) { + throw new MojoFailureException("Cannot write json file " + file, e); + } + } + + File all = new File(othersOutDir, "../others.properties"); + try { + FileOutputStream fos = new FileOutputStream(all, false); + + String[] names = othersOutDir.list(); + List<String> others = new ArrayList<>(); + // sort the names + for (String name : names) { + if (name.endsWith(".json")) { + // strip out .json from the name + String otherName = name.substring(0, name.length() - 5); + others.add(otherName); + } + } + + Collections.sort(others); + for (String name : others) { + fos.write(name.getBytes()); + fos.write("\n".getBytes()); + } + + fos.close(); + + } catch (IOException e) { + throw new MojoFailureException("Error writing to file " + all); + } + } + + private void findComponentFilesRecursive(File dir, Set<File> found, Set<File> components, FileFilter filter) { + File[] files = dir.listFiles(filter); + if (files != null) { + for (File file : files) { + // skip files in root dirs as Camel does not store information there but others may do + boolean rootDir = "classes".equals(dir.getName()) || "META-INF".equals(dir.getName()); + boolean jsonFile = !rootDir && file.isFile() && file.getName().endsWith(".json"); + boolean componentFile = !rootDir && file.isFile() && file.getName().equals("component.properties"); + if (jsonFile) { + found.add(file); + } else if (componentFile) { + components.add(file); + } else if (file.isDirectory()) { + findComponentFilesRecursive(file, found, components, filter); + } + } + } + } + + private void findDataFormatFilesRecursive(File dir, Set<File> found, Set<File> dataFormats, FileFilter filter) { + File[] files = dir.listFiles(filter); + if (files != null) { + for (File file : files) { + // skip files in root dirs as Camel does not store information there but others may do + boolean rootDir = "classes".equals(dir.getName()) || "META-INF".equals(dir.getName()); + boolean jsonFile = !rootDir && file.isFile() && file.getName().endsWith(".json"); + boolean dataFormatFile = !rootDir && file.isFile() && file.getName().equals("dataformat.properties"); + if (jsonFile) { + found.add(file); + } else if (dataFormatFile) { + dataFormats.add(file); + } else if (file.isDirectory()) { + findDataFormatFilesRecursive(file, found, dataFormats, filter); + } + } + } + } + + private void findLanguageFilesRecursive(File dir, Set<File> found, Set<File> languages, FileFilter filter) { + File[] files = dir.listFiles(filter); + if (files != null) { + for (File file : files) { + // skip files in root dirs as Camel does not store information there but others may do + boolean rootDir = "classes".equals(dir.getName()) || "META-INF".equals(dir.getName()); + boolean jsonFile = !rootDir && file.isFile() && file.getName().endsWith(".json"); + boolean languageFile = !rootDir && file.isFile() && file.getName().equals("language.properties"); + if (jsonFile) { + found.add(file); + } else if (languageFile) { + languages.add(file); + } else if (file.isDirectory()) { + findLanguageFilesRecursive(file, found, languages, filter); + } + } + } + } + + private void findOtherFilesRecursive(File dir, Set<File> found, Set<File> others, FileFilter filter) { + File[] files = dir.listFiles(filter); + if (files != null) { + for (File file : files) { + // skip files in root dirs as Camel does not store information there but others may do + boolean rootDir = "classes".equals(dir.getName()) || "META-INF".equals(dir.getName()); + boolean jsonFile = rootDir && file.isFile() && file.getName().endsWith(".json"); + boolean otherFile = !rootDir && file.isFile() && file.getName().equals("other.properties"); + if (jsonFile) { + found.add(file); + } else if (otherFile) { + others.add(file); + } else if (file.isDirectory()) { + findOtherFilesRecursive(file, found, others, filter); + } + } + } + } + + private class CamelComponentsFileFilter implements FileFilter { + + @Override + public boolean accept(File pathname) { + if (pathname.isDirectory() && pathname.getName().equals("model")) { + // do not check the camel-core model packages as there is no components there + return false; + } + if (pathname.isFile() && pathname.getName().endsWith(".json")) { + // must be a components json file + try { + String json = loadText(new FileInputStream(pathname)); + return json != null && json.contains("\"kind\": \"component\""); + } catch (IOException e) { + // ignore + } + } + return pathname.isDirectory() || (pathname.isFile() && pathname.getName().equals("component.properties")); + } + } + + private class CamelDataFormatsFileFilter implements FileFilter { + + @Override + public boolean accept(File pathname) { + if (pathname.isDirectory() && pathname.getName().equals("model")) { + // do not check the camel-core model packages as there is no components there + return false; + } + if (pathname.isFile() && pathname.getName().endsWith(".json")) { + // must be a dataformat json file + try { + String json = loadText(new FileInputStream(pathname)); + return json != null && json.contains("\"kind\": \"dataformat\""); + } catch (IOException e) { + // ignore + } + } + return pathname.isDirectory() || (pathname.isFile() && pathname.getName().equals("dataformat.properties")); + } + } + + private class CamelLanguagesFileFilter implements FileFilter { + + @Override + public boolean accept(File pathname) { + if (pathname.isDirectory() && pathname.getName().equals("model")) { + // do not check the camel-core model packages as there is no components there + return false; + } + if (pathname.isFile() && pathname.getName().endsWith(".json")) { + // must be a language json file + try { + String json = loadText(new FileInputStream(pathname)); + return json != null && json.contains("\"kind\": \"language\""); + } catch (IOException e) { + // ignore + } + } + return pathname.isDirectory() || (pathname.isFile() && pathname.getName().equals("language.properties")); + } + } + + private class CamelOthersFileFilter implements FileFilter { + + @Override + public boolean accept(File pathname) { + if (pathname.isFile() && pathname.getName().endsWith(".json")) { + // must be a language json file + try { + String json = loadText(new FileInputStream(pathname)); + return json != null && json.contains("\"kind\": \"other\""); + } catch (IOException e) { + // ignore + } + } + return pathname.isDirectory() || (pathname.isFile() && pathname.getName().equals("other.properties")); + } + } + + public static void copyFile(File from, File to) throws IOException { + FileChannel in = null; + FileChannel out = null; + 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(); + } + } + } + } + + private Set<String> findSpringBootStarters() { + Set<String> answer = new LinkedHashSet<>(); + + String[] names = componentsStarterDir.list(); + if (names != null) { + for (String name : names) { + if (name.startsWith("camel-") && name.endsWith("-starter")) { + // remove ending -starter + String regular = name.substring(0, name.length() - 8); + answer.add(regular); + } + } + } + + getLog().info("Found " + answer.size() + " Camel Spring Boot starters from: " + componentsStarterDir); + + return answer; + } + +} diff --git a/tooling/maven/package-maven-plugin/src/main/resources/META-INF/LICENSE.txt b/tooling/maven/package-maven-plugin/src/main/resources/META-INF/LICENSE.txt new file mode 100644 index 0000000..6b0b127 --- /dev/null +++ b/tooling/maven/package-maven-plugin/src/main/resources/META-INF/LICENSE.txt @@ -0,0 +1,203 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed 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. + diff --git a/tooling/maven/package-maven-plugin/src/main/resources/META-INF/NOTICE.txt b/tooling/maven/package-maven-plugin/src/main/resources/META-INF/NOTICE.txt new file mode 100644 index 0000000..2e215bf --- /dev/null +++ b/tooling/maven/package-maven-plugin/src/main/resources/META-INF/NOTICE.txt @@ -0,0 +1,11 @@ + ========================================================================= + == NOTICE file corresponding to the section 4 d of == + == the Apache License, Version 2.0, == + == in this case for the Apache Camel distribution. == + ========================================================================= + + This product includes software developed by + The Apache Software Foundation (http://www.apache.org/). + + Please read the different LICENSE files present in the licenses directory of + this distribution. diff --git a/tooling/maven/package-maven-plugin/src/main/resources/camel-quarkus-package-maven-plugin.properties b/tooling/maven/package-maven-plugin/src/main/resources/camel-quarkus-package-maven-plugin.properties new file mode 100644 index 0000000..fa7a54b --- /dev/null +++ b/tooling/maven/package-maven-plugin/src/main/resources/camel-quarkus-package-maven-plugin.properties @@ -0,0 +1,16 @@ +## --------------------------------------------------------------------------- +## 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. +## --------------------------------------------------------------------------- diff --git a/tooling/maven/pom.xml b/tooling/maven/pom.xml index 4ec1b6c..95484e7 100644 --- a/tooling/maven/pom.xml +++ b/tooling/maven/pom.xml @@ -17,7 +17,8 @@ limitations under the License. --> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> @@ -32,9 +33,7 @@ <name>Camel Quarkus :: Tooling :: Maven</name> <modules> - <!-- - <module></module> - --> + <module>package-maven-plugin</module> </modules> </project> diff --git a/tooling/parent/pom.xml b/tooling/parent/pom.xml new file mode 100644 index 0000000..c801ef7 --- /dev/null +++ b/tooling/parent/pom.xml @@ -0,0 +1,151 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + + 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. + +--> +<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <modelVersion>4.0.0</modelVersion> + + <parent> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-tooling</artifactId> + <version>0.2.1-SNAPSHOT</version> + </parent> + + <artifactId>tooling-parent</artifactId> + <packaging>pom</packaging> + + <name>Camel Quarkus :: Tooling Parent</name> + <description>Camel Quarkus Tooling Parent POM</description> + + <properties> + + <!-- TODO: Update these --> + <maven-version>3.6.2</maven-version> + <maven-maven-plugin-descriptor-version>2.2.1</maven-maven-plugin-descriptor-version> + <maven-project-version>2.2.1</maven-project-version> + <maven-dependency-tree-version>3.0.1</maven-dependency-tree-version> + <maven-plugin-annotations-version>3.6.0</maven-plugin-annotations-version> + <maven-reporting-api-version>3.0</maven-reporting-api-version> + <maven-reporting-impl-version>3.0.0</maven-reporting-impl-version> + <maven-resolver-version>1.4.1</maven-resolver-version> + <plexus-build-api-version>0.0.7</plexus-build-api-version> + <plexus-container-default-version>2.0.0</plexus-container-default-version> + <plexus-utils-version>3.2.1</plexus-utils-version> + </properties> + + <dependencyManagement> + <dependencies> + <dependency> + <groupId>org.apache.maven</groupId> + <artifactId>maven-core</artifactId> + <version>${maven-version}</version> + <exclusions> + <exclusion> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-jdk14</artifactId> + </exclusion> + <exclusion> + <groupId>org.slf4j</groupId> + <artifactId>jcl-over-slf4j</artifactId> + </exclusion> + <exclusion> + <groupId>org.slf4j</groupId> + <artifactId>slf4j-nop</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.apache.maven</groupId> + <artifactId>maven-artifact</artifactId> + <version>${maven-version}</version> + </dependency> + <dependency> + <groupId>org.apache.maven</groupId> + <artifactId>maven-plugin-api</artifactId> + <version>${maven-version}</version> + </dependency> + <dependency> + <groupId>org.apache.maven</groupId> + <artifactId>maven-compat</artifactId> + <version>${maven-version}</version> + </dependency> + <dependency> + <groupId>org.apache.maven.plugin-tools</groupId> + <artifactId>maven-plugin-annotations</artifactId> + <version>${maven-plugin-annotations-version}</version> + </dependency> + <dependency> + <groupId>org.apache.maven</groupId> + <artifactId>maven-plugin-descriptor</artifactId> + <version>${maven-maven-plugin-descriptor-version}</version> + <exclusions> + <exclusion> + <groupId>log4j</groupId> + <artifactId>log4j</artifactId> + </exclusion> + </exclusions> + </dependency> + <dependency> + <groupId>org.apache.maven</groupId> + <artifactId>maven-project</artifactId> + <version>${maven-project-version}</version> + </dependency> + <dependency> + <groupId>org.apache.maven.shared</groupId> + <artifactId>maven-dependency-tree</artifactId> + <version>${maven-dependency-tree-version}</version> + </dependency> + <dependency> + <groupId>org.apache.maven.reporting</groupId> + <artifactId>maven-reporting-api</artifactId> + <version>${maven-reporting-api-version}</version> + </dependency> + <dependency> + <groupId>org.apache.maven.reporting</groupId> + <artifactId>maven-reporting-impl</artifactId> + <version>${maven-reporting-impl-version}</version> + </dependency> + <dependency> + <groupId>org.apache.maven.resolver</groupId> + <artifactId>maven-resolver-api</artifactId> + <version>${maven-resolver-version}</version> + </dependency> + <dependency> + <groupId>org.apache.maven.resolver</groupId> + <artifactId>maven-resolver-util</artifactId> + <version>${maven-resolver-version}</version> + </dependency> + <dependency> + <groupId>org.codehaus.plexus</groupId> + <artifactId>plexus-container-default</artifactId> + <version>${plexus-container-default-version}</version> + </dependency> + <dependency> + <groupId>org.codehaus.plexus</groupId> + <artifactId>plexus-utils</artifactId> + <version>${plexus-utils-version}</version> + </dependency> + <dependency> + <groupId>org.sonatype.plexus</groupId> + <artifactId>plexus-build-api</artifactId> + <version>${plexus-build-api-version}</version> + </dependency> + </dependencies> + </dependencyManagement> +</project> diff --git a/tooling/pom.xml b/tooling/pom.xml index 366832e..adaa167 100644 --- a/tooling/pom.xml +++ b/tooling/pom.xml @@ -32,6 +32,7 @@ <name>Camel Quarkus :: Tooling</name> <modules> + <module>parent</module> <module>maven</module> </modules>
