Search in sources :

Example 1 with GavCqCatalog

use of org.l2x6.cq.common.CqCatalog.GavCqCatalog in project cq-maven-plugin by l2x6.

the class VersionReportMojo method execute.

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
    final Path localRepositoryPath = Paths.get(localRepository);
    final String delim = "..";
    final int delimPos = versions.indexOf(delim);
    if (delimPos <= 0) {
        throw new IllegalStateException("Expected versions delimited by '..': found '" + versions + "'");
    }
    final String baselineVersion = versions.substring(0, delimPos);
    final String reportVersion = versions.substring(delimPos + delim.length());
    final StringBuilder counts = new StringBuilder();
    final StringBuilder details = new StringBuilder();
    try (GavCqCatalog currentCatalog = GavCqCatalog.open(localRepositoryPath, Flavor.camelQuarkus, reportVersion, repositories, repoSystem, repoSession);
        GavCqCatalog previousCatalog = GavCqCatalog.open(localRepositoryPath, Flavor.camelQuarkus, baselineVersion, repositories, repoSystem, repoSession)) {
        CqCatalog.kinds().forEach(kind -> {
            final String pluralName = CqUtils.toCapCamelCase(kind.name() + "s");
            final AtomicInteger cnt = new AtomicInteger();
            final String kindItem = pluralName + ":\n";
            details.append(kindItem);
            currentCatalog.models(kind).sorted(BaseModel.compareTitle()).forEach(currentModel -> {
                if (reportVersion.equals(currentModel.getFirstVersion())) {
                    /* added in this version */
                    details.append("• ").append(currentModel.getTitle());
                    if (!currentModel.isNativeSupported()) {
                        details.append(" (JVM only)");
                    }
                    details.append('\n');
                    cnt.incrementAndGet();
                } else {
                    /* added earlier */
                    if (currentModel.isNativeSupported()) {
                        /* It is native now, check whether was JVM in the previous version */
                        try {
                            BaseModel<?> previousModel = previousCatalog.load(kind, currentModel.getName());
                            if (previousModel != null && !previousModel.isNativeSupported()) {
                                details.append("• ").append(currentModel.getTitle()).append(" +native").append('\n');
                            }
                        } catch (RuntimeException e) {
                            if (e.getCause().getClass() == NoSuchFileException.class) {
                            }
                        }
                    }
                }
            });
            if (cnt.get() == 0) {
                details.delete(details.length() - kindItem.length(), details.length());
            } else {
                counts.append("• ").append(cnt.get()).append(" new ").append(kind.name()).append("s\n");
            }
        });
    }
    getLog().info("Counts:\n\n\n" + counts.toString() + "\n\n");
    getLog().info("Report:\n\n\n" + details.toString() + "\n\n");
}
Also used : Path(java.nio.file.Path) GavCqCatalog(org.l2x6.cq.common.CqCatalog.GavCqCatalog) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) NoSuchFileException(java.nio.file.NoSuchFileException)

Example 2 with GavCqCatalog

use of org.l2x6.cq.common.CqCatalog.GavCqCatalog 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 3 with GavCqCatalog

use of org.l2x6.cq.common.CqCatalog.GavCqCatalog in project cq-maven-plugin by l2x6.

the class ExportComponentCsvMojo 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 Path outputPath = outputDir.toPath();
    try (GavCqCatalog camelCatalog = GavCqCatalog.open(localRepositoryPath, Flavor.camel, camelCatalogVersion, repositories, repoSystem, repoSession);
        GavCqCatalog camelQuarkusCatalog = GavCqCatalog.open(localRepositoryPath, Flavor.camelQuarkus, camelQuarkusCatalogVersion, repositories, repoSystem, repoSession)) {
        CqCatalog.kinds().forEach(kind -> {
            final Path outputFile = outputPath.resolve(kind.name() + "s.csv");
            try (Writer out = Files.newBufferedWriter(outputFile, StandardCharsets.UTF_8)) {
                out.write("Priority\tGA product target\tTP2 done\tName\tScheme\tartifactId\tKind\tDeprecated\tCQ community\tProduct\tCommunity issue\tIntegration test\tSprint\tComment\n");
                camelCatalog.models(kind).filter(CqCatalog::isFirstScheme).sorted(CqCatalog.compareArtifactId().thenComparing(BaseModel.compareTitle())).forEach(model -> {
                    // prio
                    try {
                        // empty prio
                        out.write("\t");
                        // empty GA product target
                        out.write("\t");
                        // TP2 done
                        out.write("\t");
                        out.write(model.getTitle());
                        out.write('\t');
                        out.write(model.getName());
                        out.write('\t');
                        out.write(model.getArtifactId());
                        out.write('\t');
                        out.write(model.getKind());
                        out.write('\t');
                        out.write(String.valueOf(model.isDeprecated()));
                        out.write('\t');
                        out.write(quarkusCommunitySupport(camelQuarkusCatalog, kind, model));
                        out.write('\n');
                    } catch (IOException e) {
                        throw new RuntimeException("Could not write to " + outputFile, e);
                    }
                });
            } catch (IOException e) {
                throw new RuntimeException("Could not write to " + outputFile, e);
            }
        });
    }
}
Also used : Path(java.nio.file.Path) GavCqCatalog(org.l2x6.cq.common.CqCatalog.GavCqCatalog) IOException(java.io.IOException) Writer(java.io.Writer) GavCqCatalog(org.l2x6.cq.common.CqCatalog.GavCqCatalog) CqCatalog(org.l2x6.cq.common.CqCatalog)

Aggregations

Path (java.nio.file.Path)3 GavCqCatalog (org.l2x6.cq.common.CqCatalog.GavCqCatalog)3 IOException (java.io.IOException)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 JsonFactory (com.google.api.client.json.JsonFactory)1 JacksonFactory (com.google.api.client.json.jackson2.JacksonFactory)1 FileDataStoreFactory (com.google.api.client.util.store.FileDataStoreFactory)1 Sheets (com.google.api.services.sheets.v4.Sheets)1 SheetsScopes (com.google.api.services.sheets.v4.SheetsScopes)1 ValueRange (com.google.api.services.sheets.v4.model.ValueRange)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 InputStreamReader (java.io.InputStreamReader)1