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);
}
}
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());
}
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();
}
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);
}
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);
}
});
}
Aggregations