Search in sources :

Example 1 with ArtifactModel

use of org.apache.camel.tooling.model.ArtifactModel in project cq-maven-plugin by l2x6.

the class SyncExtensionListMojo method execute.

/**
 * 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 {
    final Path localRepositoryPath = Paths.get(localRepository);
    final String camelVersion = findCamelVersion(localRepositoryPath);
    try {
        final NetHttpTransport HTTP_TRANSPORT = GoogleNetHttpTransport.newTrustedTransport();
        final JsonFactory JSON_FACTORY = JacksonFactory.getDefaultInstance();
        final List<String> SCOPES = Collections.singletonList(SheetsScopes.SPREADSHEETS);
        final Comparator<ArtifactModel<?>> comparator = CqCatalog.compareArtifactId().thenComparing(BaseModel.compareTitle());
        final Sheets service = new Sheets.Builder(HTTP_TRANSPORT, JSON_FACTORY, getCredentials(HTTP_TRANSPORT, JSON_FACTORY, SCOPES)).setApplicationName(APPLICATION_NAME).build();
        try (GavCqCatalog camelCatalog = GavCqCatalog.open(localRepositoryPath, Flavor.camel, camelVersion, repositories, repoSystem, repoSession);
            GavCqCatalog camelQuarkusCatalog = GavCqCatalog.open(localRepositoryPath, Flavor.camelQuarkus, camelQuarkusVersion, repositories, repoSystem, repoSession)) {
            Map<Kind, Map<String, NativeSupport>> nativeSupportsMap = new HashMap<>();
            CqCatalog.kinds().forEach(kind -> {
                Map<String, NativeSupport> nativeSupports = new HashMap<>();
                nativeSupportsMap.put(kind, nativeSupports);
                getLog().info("Updating " + CqCommonUtils.humanPlural(kind));
                final Set<String> allSchemes = new LinkedHashSet<>();
                final Map<String, ArtifactModel<?>> camelModels = new LinkedHashMap<>();
                camelCatalog.models(kind).filter(CqCatalog::isFirstScheme).sorted(comparator).forEach(m -> {
                    camelModels.put(m.getName(), m);
                    allSchemes.add(m.getName());
                });
                final Map<String, ArtifactModel<?>> cqModels = new LinkedHashMap<>();
                camelQuarkusCatalog.models(kind).filter(CqCatalog::isFirstScheme).sorted(comparator).forEach(m -> {
                    cqModels.put(m.getName(), m);
                    allSchemes.add(m.getName());
                });
                /* Go through extensions available in the spreadsheet and update them */
                final Sheet sheet = Sheet.read(service, googleSpreadsheetId, kind, getLog(), Column.artifactModelColumns());
                for (String scheme : allSchemes) {
                    sheet.update(scheme, camelModels.get(scheme), cqModels.get(scheme), nativeSupportsMap);
                }
                sheet.update(Comparator.comparing(Record::getArtifactIdBase).thenComparing(Record::getScheme));
            });
            {
                final Kind kind = Kind.eip;
                getLog().info("Updating " + CqCommonUtils.humanPlural(kind));
                final Set<String> allSchemes = new LinkedHashSet<>();
                final Map<String, EipModel> camelModels = new LinkedHashMap<>();
                camelCatalog.eips().sorted(BaseModel.compareTitle()).forEach(m -> {
                    camelModels.put(m.getName(), m);
                    allSchemes.add(m.getName());
                });
                final Map<String, EipModel> cqModels = new LinkedHashMap<>();
                // camelQuarkusCatalog.eips()
                // .sorted(BaseModel.compareTitle())
                // .forEach(m -> {
                // cqModels.put(m.getName(), m);
                // allSchemes.add(m.getName());
                // });
                Map<String, Set<String>> occurrences = findOccurrences(allSchemes, Paths.get("."), getLog());
                /* Go through extensions available in the spreadsheet and update them */
                final Sheet sheet = Sheet.read(service, googleSpreadsheetId, kind, getLog(), Column.eipColumns());
                for (String scheme : allSchemes) {
                    sheet.updateBase(scheme, camelModels.get(scheme), cqModels.get(scheme), occurrences.get(scheme), nativeSupportsMap);
                }
                sheet.update(Comparator.comparing(Record::getKind).thenComparing(Record::getScheme));
            }
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Arrays(java.util.Arrays) Flavor(org.l2x6.cq.common.CqCatalog.Flavor) GoogleClientSecrets(com.google.api.client.googleapis.auth.oauth2.GoogleClientSecrets) Parameter(org.apache.maven.plugins.annotations.Parameter) MavenProject(org.apache.maven.project.MavenProject) Locale(java.util.Locale) Map(java.util.Map) Path(java.nio.file.Path) CqCommonUtils(org.l2x6.cq.common.CqCommonUtils) EnumMap(java.util.EnumMap) JacksonFactory(com.google.api.client.json.jackson2.JacksonFactory) FileDataStoreFactory(com.google.api.client.util.store.FileDataStoreFactory) LocalServerReceiver(com.google.api.client.extensions.jetty.auth.oauth2.LocalServerReceiver) Set(java.util.Set) GoogleNetHttpTransport(com.google.api.client.googleapis.javanet.GoogleNetHttpTransport) Reader(java.io.Reader) SheetsScopes(com.google.api.services.sheets.v4.SheetsScopes) Collectors(java.util.stream.Collectors) FileNotFoundException(java.io.FileNotFoundException) StandardCharsets(java.nio.charset.StandardCharsets) Objects(java.util.Objects) Sheets(com.google.api.services.sheets.v4.Sheets) List(java.util.List) Stream(java.util.stream.Stream) Entry(java.util.Map.Entry) CqCatalog(org.l2x6.cq.common.CqCatalog) Optional(java.util.Optional) GoogleAuthorizationCodeFlow(com.google.api.client.googleapis.auth.oauth2.GoogleAuthorizationCodeFlow) AbstractMojo(org.apache.maven.plugin.AbstractMojo) Model(org.apache.maven.model.Model) RepositorySystem(org.eclipse.aether.RepositorySystem) Component(org.apache.maven.plugins.annotations.Component) HashMap(java.util.HashMap) RepositorySystemSession(org.eclipse.aether.RepositorySystemSession) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) ValueRange(com.google.api.services.sheets.v4.model.ValueRange) Mojo(org.apache.maven.plugins.annotations.Mojo) Credential(com.google.api.client.auth.oauth2.Credential) ArtifactModel(org.apache.camel.tooling.model.ArtifactModel) LinkedHashSet(java.util.LinkedHashSet) GavCqCatalog(org.l2x6.cq.common.CqCatalog.GavCqCatalog) NetHttpTransport(com.google.api.client.http.javanet.NetHttpTransport) Files(java.nio.file.Files) Kind(org.apache.camel.catalog.Kind) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) BaseModel(org.apache.camel.tooling.model.BaseModel) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) Log(org.apache.maven.plugin.logging.Log) InputStreamReader(java.io.InputStreamReader) File(java.io.File) MojoFailureException(org.apache.maven.plugin.MojoFailureException) RemoteRepository(org.eclipse.aether.repository.RemoteRepository) Paths(java.nio.file.Paths) JsonFactory(com.google.api.client.json.JsonFactory) EipModel(org.apache.camel.tooling.model.EipModel) Comparator(java.util.Comparator) AuthorizationCodeInstalledApp(com.google.api.client.extensions.java6.auth.oauth2.AuthorizationCodeInstalledApp) Collections(java.util.Collections) Record(org.l2x6.cq.maven.prod.SyncExtensionListMojo.Sheet.Record) GavCqCatalog(org.l2x6.cq.common.CqCatalog.GavCqCatalog) Set(java.util.Set) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) JsonFactory(com.google.api.client.json.JsonFactory) CqCatalog(org.l2x6.cq.common.CqCatalog) GavCqCatalog(org.l2x6.cq.common.CqCatalog.GavCqCatalog) LinkedHashMap(java.util.LinkedHashMap) GoogleNetHttpTransport(com.google.api.client.googleapis.javanet.GoogleNetHttpTransport) NetHttpTransport(com.google.api.client.http.javanet.NetHttpTransport) Kind(org.apache.camel.catalog.Kind) Record(org.l2x6.cq.maven.prod.SyncExtensionListMojo.Sheet.Record) Sheets(com.google.api.services.sheets.v4.Sheets) Path(java.nio.file.Path) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MojoFailureException(org.apache.maven.plugin.MojoFailureException) ArtifactModel(org.apache.camel.tooling.model.ArtifactModel) Map(java.util.Map) EnumMap(java.util.EnumMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap)

Example 2 with ArtifactModel

use of org.apache.camel.tooling.model.ArtifactModel in project cq-maven-plugin by l2x6.

the class CreateExtensionMojo method generateExtensionProjects.

void generateExtensionProjects(Configuration cfg, TemplateParams.Builder templateParams) {
    final Path extParentPomPath = getExtensionProjectBaseDir().resolve("pom.xml");
    evalTemplate(cfg, "parent-pom.xml", extParentPomPath, templateParams.build());
    final Path extensionRuntimeBaseDir = getExtensionRuntimeBaseDir();
    if (createConvenienceDirs) {
        createDirectories(extensionRuntimeBaseDir.resolve("src/main/java").resolve(templateParams.getJavaPackageBasePath()));
    // TODO: createDirectories(extensionRuntimeBaseDir.resolve("src/main/doc"));
    }
    evalTemplate(cfg, "runtime-pom.xml", extensionRuntimeBaseDir.resolve("pom.xml"), templateParams.build());
    final boolean deprecated = models.stream().anyMatch(ArtifactModel::isDeprecated);
    final TemplateParams quarkusExtensionYamlParams = CqUtils.quarkusExtensionYamlParams(models, artifactIdBase, nameBase, description, keywords, !nativeSupported, deprecated, nativeSupported, ExtensionStatus.of(nativeSupported), runtimeBomPath.getParent().getParent().getParent(), getLog(), new ArrayList<>());
    final Path metaInfDir = extensionRuntimeBaseDir.resolve("src/main/resources/META-INF");
    try {
        Files.createDirectories(metaInfDir);
    } catch (IOException e) {
        throw new RuntimeException("Could not create " + metaInfDir, e);
    }
    evalTemplate(cfg, "quarkus-extension.yaml", metaInfDir.resolve("quarkus-extension.yaml"), quarkusExtensionYamlParams);
    evalTemplate(cfg, "deployment-pom.xml", getExtensionDeploymentBaseDir().resolve("pom.xml"), templateParams.build());
    final Path processorPath = getExtensionDeploymentBaseDir().resolve("src/main/java").resolve(templateParams.getJavaPackageBasePath()).resolve("deployment").resolve(CqUtils.toCapCamelCase(templateParams.getArtifactIdBase()) + "Processor.java");
    evalTemplate(cfg, "Processor.java", processorPath, templateParams.build());
}
Also used : Path(java.nio.file.Path) ArtifactModel(org.apache.camel.tooling.model.ArtifactModel) IOException(java.io.IOException)

Example 3 with ArtifactModel

use of org.apache.camel.tooling.model.ArtifactModel in project cq-maven-plugin by l2x6.

the class CreateTestMojo method execute.

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
    basePath = getRootModuleDirectory();
    if (extensionsDir == null) {
        extensionsDir = nativeSupported ? basePath.resolve(CQ_EXTENSIONS_DIR).toFile() : basePath.resolve(CQ_EXTENSIONS_JVM_DIR).toFile();
    }
    extensionsPath = extensionsDir.toPath();
    final CqCatalog cqCatalog = new CqCatalog(Flavor.camel);
    this.models = cqCatalog.filterModels(artifactIdBase).collect(Collectors.toList());
    final List<ArtifactModel<?>> primaryModels = cqCatalog.primaryModel(artifactIdBase);
    switch(primaryModels.size()) {
        case 0:
            throw new IllegalStateException("Could not find name " + artifactIdBase + " in Camel catalog");
        default:
            this.model = primaryModels.get(0);
            break;
    }
    if (artifactIdPrefix == null) {
        artifactIdPrefix = "";
    }
    artifactId = artifactIdPrefix == null || artifactIdPrefix.isEmpty() ? artifactIdBase : artifactIdPrefix + artifactIdBase;
    if (nameBase == null) {
        nameBase = model.getTitle();
        if (nameBase == null) {
            throw new MojoFailureException("Name not found for " + artifactIdBase);
        }
    }
    if (namePrefix == null) {
        namePrefix = "";
    }
    extensionsPomPath = this.extensionsPath.resolve("pom.xml");
    extensionsModel = CqCommonUtils.readPom(extensionsPomPath, getCharset());
    this.groupId = getGroupId(extensionsModel);
    this.version = CqUtils.getVersion(extensionsModel);
    cfg = CqUtils.getTemplateConfig(basePath, CqUtils.DEFAULT_TEMPLATES_URI_BASE, templatesUriBase, encoding);
    doExecute();
}
Also used : ArtifactModel(org.apache.camel.tooling.model.ArtifactModel) MojoFailureException(org.apache.maven.plugin.MojoFailureException) CqCatalog(org.l2x6.cq.common.CqCatalog)

Example 4 with ArtifactModel

use of org.apache.camel.tooling.model.ArtifactModel in project camel-quarkus by apache.

the class UpdateExtensionDocPageMojo method execute.

/**
 * {@inheritDoc}
 */
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
    if (skip) {
        getLog().info("Skipping per user request");
        return;
    }
    final Charset charset = Charset.forName(encoding);
    final Path basePath = baseDir.toPath();
    if (!"runtime".equals(basePath.getFileName().toString())) {
        getLog().info("Skipping a module that is not a Quarkus extension runtime module");
        return;
    }
    final CqCatalog catalog = new CqCatalog();
    final Path multiModuleProjectDirectoryPath = multiModuleProjectDirectory.toPath();
    final CamelQuarkusExtension ext = CamelQuarkusExtension.read(basePath.resolve("pom.xml"));
    final Path quarkusAwsClienTestsDir = multiModuleProjectDirectoryPath.resolve("integration-test-groups/aws2-quarkus-client");
    final Path pomRelPath = multiModuleProjectDirectoryPath.relativize(basePath).resolve("pom.xml");
    if (!ext.getJvmSince().isPresent()) {
        throw new IllegalStateException(CamelQuarkusExtension.CAMEL_QUARKUS_JVM_SINCE + " property must defined in " + pomRelPath);
    }
    final String extensionsDir = basePath.getParent().getParent().getFileName().toString();
    if (!"extensions-jvm".equals(extensionsDir) && !ext.getNativeSince().isPresent()) {
        throw new IllegalStateException(CamelQuarkusExtension.CAMEL_QUARKUS_NATIVE_SINCE + " property must defined in " + pomRelPath);
    }
    final Configuration cfg = CqUtils.getTemplateConfig(basePath, AbstractDocGeneratorMojo.DEFAULT_TEMPLATES_URI_BASE, templatesUriBase, encoding);
    final List<ArtifactModel<?>> models = catalog.filterModels(ext.getRuntimeArtifactIdBase()).filter(artifactModel -> !artifactModel.getArtifactId().equals("camel-management")).sorted(BaseModel.compareTitle()).collect(Collectors.toList());
    final Map<String, Object> model = new HashMap<>();
    model.put("artifactIdBase", ext.getRuntimeArtifactIdBase());
    final String jvmSince = ext.getJvmSince().get();
    model.put("firstVersion", jvmSince);
    model.put("nativeSupported", ext.isNativeSupported());
    final String title = ext.getName().get();
    model.put("name", title);
    final String description = CqUtils.getDescription(models, ext.getDescription().orElse(null), getLog());
    model.put("description", description);
    model.put("status", ext.getStatus().getCapitalized());
    final boolean deprecated = CqUtils.isDeprecated(title, models, ext.isDeprecated());
    model.put("statusDeprecation", deprecated ? ext.getStatus().getCapitalized() + " Deprecated" : ext.getStatus().getCapitalized());
    model.put("deprecated", deprecated);
    model.put("unlisted", ext.isUnlisted());
    model.put("jvmSince", jvmSince);
    model.put("nativeSince", ext.getNativeSince().orElse("n/a"));
    if (lowerEqual_1_0_0(jvmSince)) {
        model.put("pageAliases", "extensions/" + ext.getRuntimeArtifactIdBase() + ".adoc");
    }
    model.put("intro", loadSection(basePath, "intro.adoc", charset, description));
    model.put("models", models);
    model.put("usage", loadSection(basePath, "usage.adoc", charset, null));
    model.put("configuration", loadSection(basePath, "configuration.adoc", charset, null));
    model.put("limitations", loadSection(basePath, "limitations.adoc", charset, null));
    model.put("activatesNativeSsl", ext.isNativeSupported() && detectNativeSsl(multiModuleProjectDirectory.toPath(), basePath, ext.getRuntimeArtifactId(), ext.getDependencies(), nativeSslActivators));
    model.put("activatesContextMapAll", ext.isNativeSupported() && detectComponentOrEndpointOption(catalog, ext.getRuntimeArtifactIdBase(), "allowContextMapAll"));
    model.put("activatesTransferException", ext.isNativeSupported() && detectComponentOrEndpointOption(catalog, ext.getRuntimeArtifactIdBase(), "transferException"));
    model.put("quarkusAwsClient", getQuarkusAwsClient(quarkusAwsClienTestsDir, ext.getRuntimeArtifactIdBase(), ext.getQuarkusAwsClientBaseName(), ext.getQuarkusAwsClientFqClassName(), ext.getRuntimePomXmlPath()));
    model.put("configOptions", listConfigOptions(basePath, multiModuleProjectDirectory.toPath()));
    model.put("humanReadableKind", new TemplateMethodModelEx() {

        @Override
        public Object exec(List arguments) throws TemplateModelException {
            if (arguments.size() != 1) {
                throw new TemplateModelException("Wrong argument count in toCamelCase()");
            }
            return CqUtils.humanReadableKind(Kind.valueOf(String.valueOf(arguments.get(0))));
        }
    });
    model.put("camelBitLink", new TemplateMethodModelEx() {

        @Override
        public Object exec(List arguments) throws TemplateModelException {
            if (arguments.size() != 2) {
                throw new TemplateModelException("Wrong argument count in camelBitLink()");
            }
            final ArtifactModel<?> model = (ArtifactModel<?>) DeepUnwrap.unwrap((TemplateModel) arguments.get(0));
            final String kind = model.getKind();
            if (CqCatalog.isFirstScheme(model)) {
                return camelBitLink(model);
            } else {
                final List<ArtifactModel<?>> models = (List<ArtifactModel<?>>) DeepUnwrap.unwrap((TemplateModel) arguments.get(1));
                final ArtifactModel<?> firstModel = CqCatalog.findFirstSchemeModel(model, models);
                return camelBitLink(firstModel);
            }
        }

        private String camelBitLink(ArtifactModel<?> model) {
            model = CqCatalog.toCamelDocsModel(model);
            final String kind = model.getKind();
            String name = model.getName();
            if (name.equals("xml-io-dsl")) {
                name = "java-xml-io-dsl";
            }
            return "xref:{cq-camel-components}:" + (!"component".equals(kind) ? kind + "s:" : ":") + name + (!"other".equals(kind) ? "-" + kind : "") + ".adoc";
        }
    });
    model.put("toAnchor", new TemplateMethodModelEx() {

        @Override
        public Object exec(List arguments) throws TemplateModelException {
            if (arguments.size() != 1) {
                throw new TemplateModelException("Wrong argument count in toAnchor()");
            }
            String string = String.valueOf(arguments.get(0));
            string = Normalizer.normalize(string, Normalizer.Form.NFKC).replaceAll("[àáâãäåāąă]", "a").replaceAll("[çćčĉċ]", "c").replaceAll("[ďđð]", "d").replaceAll("[èéêëēęěĕė]", "e").replaceAll("[ƒſ]", "f").replaceAll("[ĝğġģ]", "g").replaceAll("[ĥħ]", "h").replaceAll("[ìíîïīĩĭįı]", "i").replaceAll("[ijĵ]", "j").replaceAll("[ķĸ]", "k").replaceAll("[łľĺļŀ]", "l").replaceAll("[ñńňņʼnŋ]", "n").replaceAll("[òóôõöøōőŏœ]", "o").replaceAll("[Þþ]", "p").replaceAll("[ŕřŗ]", "r").replaceAll("[śšşŝș]", "s").replaceAll("[ťţŧț]", "t").replaceAll("[ùúûüūůűŭũų]", "u").replaceAll("[ŵ]", "w").replaceAll("[ýÿŷ]", "y").replaceAll("[žżź]", "z").replaceAll("[æ]", "ae").replaceAll("[ÀÁÂÃÄÅĀĄĂ]", "A").replaceAll("[ÇĆČĈĊ]", "C").replaceAll("[ĎĐÐ]", "D").replaceAll("[ÈÉÊËĒĘĚĔĖ]", "E").replaceAll("[ĜĞĠĢ]", "G").replaceAll("[ĤĦ]", "H").replaceAll("[ÌÍÎÏĪĨĬĮİ]", "I").replaceAll("[Ĵ]", "J").replaceAll("[Ķ]", "K").replaceAll("[ŁĽĹĻĿ]", "L").replaceAll("[ÑŃŇŅŊ]", "N").replaceAll("[ÒÓÔÕÖØŌŐŎ]", "O").replaceAll("[ŔŘŖ]", "R").replaceAll("[ŚŠŞŜȘ]", "S").replaceAll("[ÙÚÛÜŪŮŰŬŨŲ]", "U").replaceAll("[Ŵ]", "W").replaceAll("[ÝŶŸ]", "Y").replaceAll("[ŹŽŻ]", "Z").replaceAll("[ß]", "ss");
            // Apostrophes.
            string = string.replaceAll("([a-z])'s([^a-z])", "$1s$2");
            // Allow only letters, -, _, .
            string = string.replaceAll("[^\\w-_\\.]", "-").replaceAll("-{2,}", "-");
            // Get rid of any - at the start and end.
            string = string.replaceAll("-+$", "").replaceAll("^-+", "");
            return string.toLowerCase();
        }
    });
    final Path docPagePath = multiModuleProjectDirectoryPath.resolve("docs/modules/ROOT/pages/reference/extensions/" + ext.getRuntimeArtifactIdBase() + ".adoc");
    evalTemplate(charset, docPagePath, cfg, model, "extension-doc-page.adoc", "//");
    camelBits(charset, cfg, models, multiModuleProjectDirectoryPath, ext, model);
}
Also used : Path(java.nio.file.Path) TemplateModelException(freemarker.template.TemplateModelException) Configuration(freemarker.template.Configuration) HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Charset(java.nio.charset.Charset) ArtifactModel(org.apache.camel.tooling.model.ArtifactModel) TemplateMethodModelEx(freemarker.template.TemplateMethodModelEx) ArrayList(java.util.ArrayList) List(java.util.List)

Example 5 with ArtifactModel

use of org.apache.camel.tooling.model.ArtifactModel in project camel-quarkus by apache.

the class PrepareCatalogQuarkusMojo method execute.

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
    final Path catalogPath = catalogBaseDir.toPath().resolve(CqCatalog.CQ_CATALOG_DIR);
    final Map<String, Set<String>> schemesByKind = new LinkedHashMap<>();
    CqCatalog.kinds().forEach(kind -> schemesByKind.put(kind.name(), new TreeSet<>()));
    final CqCatalog catalog = CqCatalog.findFirstFromClassPath();
    if (extendClassPathCatalog) {
        catalog.store(catalogBaseDir.toPath());
        catalog.models().forEach(model -> schemesByKind.get(model.getKind()).add(model.getName()));
    }
    findExtensions().forEach(ext -> {
        final String artifactIdBase = ext.getArtifactIdBase();
        final Path schemaFile = ext.getExtensionDir().resolve("component/src/generated/resources/org/apache/camel/component/" + artifactIdBase + "/" + artifactIdBase + ".json").toAbsolutePath().normalize();
        if (Files.isRegularFile(schemaFile)) {
            try {
                final String schema = new String(Files.readAllBytes(schemaFile), StandardCharsets.UTF_8);
                final String capBase = artifactIdBase.substring(0, 1).toUpperCase() + artifactIdBase.substring(1);
                getLog().debug("Adding an extra component " + artifactIdBase + " " + "org.apache.camel.component." + artifactIdBase + "." + capBase + "Component " + schema);
                catalog.addComponent(artifactIdBase, "org.apache.camel.component." + artifactIdBase + "." + capBase + "Component", schema);
            } catch (IOException e) {
                throw new RuntimeException("Could not read " + schemaFile, e);
            }
        }
    });
    findExtensions().forEach(extPath -> {
        final String artifactIdBase = extPath.getArtifactIdBase();
        final List<ArtifactModel<?>> models = catalog.filterModels(artifactIdBase).collect(Collectors.toList());
        final Path runtimePomXmlPath = extPath.getExtensionDir().resolve("runtime/pom.xml").toAbsolutePath().normalize();
        final CamelQuarkusExtension ext = CamelQuarkusExtension.read(runtimePomXmlPath);
        final boolean nativeSupported = ext.isNativeSupported();
        if (models.isEmpty()) {
            final ArtifactModel<?> model;
            final Kind extKind = ext.getKind();
            if (extKind == Kind.component) {
                model = new ComponentModel();
            } else if (extKind == Kind.language) {
                model = new LanguageModel();
            } else if (extKind == Kind.dataformat) {
                model = new DataFormatModel();
            } else {
                model = new OtherModel();
            }
            final String name = ext.getRuntimeArtifactId().replace("camel-quarkus-", "");
            model.setName(name);
            final String title = ext.getName().orElseThrow(() -> new RuntimeException("name is missing in " + ext.getRuntimePomXmlPath()));
            model.setTitle(title);
            model.setDescription(ext.getDescription().orElseThrow(() -> new RuntimeException("description is missing in " + ext.getRuntimePomXmlPath())));
            model.setDeprecated(CqUtils.isDeprecated(title, models, ext.isDeprecated()));
            model.setLabel(ext.getLabel().orElse("quarkus"));
            update(model, ext, nativeSupported);
            CqCatalog.serialize(catalogPath, model);
            schemesByKind.get(model.getKind()).add(model.getName());
        } else {
            for (ArtifactModel<?> model : models) {
                update(model, ext, nativeSupported);
                CqCatalog.serialize(catalogPath, model);
                schemesByKind.get(model.getKind()).add(model.getName());
            }
        }
    });
    CqCatalog.kinds().forEach(kind -> {
        final Path newCatalog = catalogPath.resolve(kind.name() + "s.properties");
        try {
            Files.createDirectories(newCatalog.getParent());
            Files.write(newCatalog, schemesByKind.get(kind.name()).stream().collect(Collectors.joining("\n")).getBytes(StandardCharsets.UTF_8));
        } catch (IOException e) {
            throw new RuntimeException("Could not write to " + newCatalog);
        }
    });
}
Also used : Path(java.nio.file.Path) Set(java.util.Set) TreeSet(java.util.TreeSet) IOException(java.io.IOException) OtherModel(org.apache.camel.tooling.model.OtherModel) LinkedHashMap(java.util.LinkedHashMap) DataFormatModel(org.apache.camel.tooling.model.DataFormatModel) ArtifactModel(org.apache.camel.tooling.model.ArtifactModel) TreeSet(java.util.TreeSet) Kind(org.apache.camel.catalog.Kind) ComponentModel(org.apache.camel.tooling.model.ComponentModel) LanguageModel(org.apache.camel.tooling.model.LanguageModel)

Aggregations

ArtifactModel (org.apache.camel.tooling.model.ArtifactModel)6 Path (java.nio.file.Path)5 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 MojoFailureException (org.apache.maven.plugin.MojoFailureException)3 CqCatalog (org.l2x6.cq.common.CqCatalog)3 Configuration (freemarker.template.Configuration)2 StandardCharsets (java.nio.charset.StandardCharsets)2 Arrays (java.util.Arrays)2 Collections (java.util.Collections)2 HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 Credential (com.google.api.client.auth.oauth2.Credential)1 AuthorizationCodeInstalledApp (com.google.api.client.extensions.java6.auth.oauth2.AuthorizationCodeInstalledApp)1 LocalServerReceiver (com.google.api.client.extensions.jetty.auth.oauth2.LocalServerReceiver)1 GoogleAuthorizationCodeFlow (com.google.api.client.googleapis.auth.oauth2.GoogleAuthorizationCodeFlow)1 GoogleClientSecrets (com.google.api.client.googleapis.auth.oauth2.GoogleClientSecrets)1 GoogleNetHttpTransport (com.google.api.client.googleapis.javanet.GoogleNetHttpTransport)1 NetHttpTransport (com.google.api.client.http.javanet.NetHttpTransport)1