Search in sources :

Example 6 with ArtifactModel

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

the class UpdateQuarkusMetadataMojo method execute.

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
    final CqCatalog catalog = new CqCatalog(Flavor.camel);
    final List<String> errors = new ArrayList<>();
    findExtensions().filter(extModule -> !extModule.getArtifactIdBase().startsWith("support-")).forEach(extModule -> {
        final String artifactIdBase = extModule.getArtifactIdBase();
        final Path quarkusExtensionsYamlPath = extModule.getExtensionDir().resolve("runtime/src/main/resources/META-INF/quarkus-extension.yaml");
        getLog().info("Regenerating " + multiModuleProjectDirectory.toPath().relativize(quarkusExtensionsYamlPath));
        final List<ArtifactModel<?>> models = catalog.primaryModel(artifactIdBase);
        final Model runtimePom = CqCommonUtils.readPom(extModule.getRuntimePomPath(), StandardCharsets.UTF_8);
        final Path relativeRuntimePomPath = multiModuleProjectDirectory.toPath().relativize(extModule.getRuntimePomPath());
        final String name = runtimePom.getName();
        if (!name.endsWith(NAME_SUFFIX)) {
            throw new RuntimeException("The name in " + relativeRuntimePomPath + " must end with '" + NAME_SUFFIX + "'; found: " + name);
        }
        final int startDelimPos = name.lastIndexOf(" :: ", name.length() - NAME_SUFFIX.length() - 1);
        if (startDelimPos < 0) {
            throw new RuntimeException("The name in " + relativeRuntimePomPath + " must start with '<whatever> :: '; found: " + name);
        }
        final String titleBase = name.substring(startDelimPos + 4, name.length() - NAME_SUFFIX.length());
        final String rawKeywords = (String) runtimePom.getProperties().getProperty("quarkus.metadata.keywords");
        final List<String> keywords = rawKeywords != null ? Arrays.asList(rawKeywords.split(",")) : Collections.emptyList();
        final boolean unlisted = !extModule.isNativeSupported() || Boolean.parseBoolean(runtimePom.getProperties().getProperty("quarkus.metadata.unlisted", "false"));
        final boolean deprecated = models.stream().anyMatch(ArtifactModel::isDeprecated) || Boolean.parseBoolean(runtimePom.getProperties().getProperty("quarkus.metadata.deprecated", "false"));
        final ExtensionStatus status = ExtensionStatus.valueOf(runtimePom.getProperties().getProperty("quarkus.metadata.status", ExtensionStatus.of(extModule.isNativeSupported()).toString()));
        final TemplateParams templateParams = CqUtils.quarkusExtensionYamlParams(models, artifactIdBase, titleBase, runtimePom.getDescription(), keywords, unlisted, deprecated, extModule.isNativeSupported(), status, multiModuleProjectDirectory.toPath(), getLog(), errors);
        final Configuration cfg = CqUtils.getTemplateConfig(multiModuleProjectDirectory.toPath(), CqUtils.DEFAULT_TEMPLATES_URI_BASE, templatesUriBase, encoding);
        CqUtils.evalTemplate(cfg, "quarkus-extension.yaml", quarkusExtensionsYamlPath, templateParams, m -> {
        });
    });
    if (!errors.isEmpty()) {
        throw new MojoFailureException(errors.stream().collect(Collectors.joining("\n")));
    }
}
Also used : CqCommonUtils(org.l2x6.cq.common.CqCommonUtils) Arrays(java.util.Arrays) Flavor(org.l2x6.cq.common.CqCatalog.Flavor) Parameter(org.apache.maven.plugins.annotations.Parameter) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) ExtensionStatus(org.l2x6.cq.maven.TemplateParams.ExtensionStatus) ArrayList(java.util.ArrayList) MojoFailureException(org.apache.maven.plugin.MojoFailureException) Mojo(org.apache.maven.plugins.annotations.Mojo) List(java.util.List) Configuration(freemarker.template.Configuration) CqCatalog(org.l2x6.cq.common.CqCatalog) ArtifactModel(org.apache.camel.tooling.model.ArtifactModel) Path(java.nio.file.Path) Collections(java.util.Collections) Model(org.apache.maven.model.Model) Path(java.nio.file.Path) Configuration(freemarker.template.Configuration) ArrayList(java.util.ArrayList) MojoFailureException(org.apache.maven.plugin.MojoFailureException) CqCatalog(org.l2x6.cq.common.CqCatalog) ArtifactModel(org.apache.camel.tooling.model.ArtifactModel) ExtensionStatus(org.l2x6.cq.maven.TemplateParams.ExtensionStatus) ArtifactModel(org.apache.camel.tooling.model.ArtifactModel) Model(org.apache.maven.model.Model)

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