use of org.l2x6.cq.common.CqCatalog 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);
}
}
use of org.l2x6.cq.common.CqCatalog 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();
}
use of org.l2x6.cq.common.CqCatalog 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")));
}
}
use of org.l2x6.cq.common.CqCatalog 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);
}
});
}
}
Aggregations