use of org.apache.camel.tooling.model.EipModel 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.EipModel in project camel-spring-boot by apache.
the class SpringBootAutoConfigurationMojo method executeModels.
private void executeModels(JarFile componentJar, Map<String, Supplier<String>> files) throws MojoExecutionException, MojoFailureException {
String json;
// Hystrix
json = loadModelJson(files, "hystrixConfiguration");
if (json != null) {
EipModel model = JsonMapper.generateEipModel(json);
int pos = model.getJavaType().lastIndexOf(".");
String pkg = model.getJavaType().substring(0, pos) + ".springboot";
// Generate properties, auto-configuration for camel-core-starter
createEipModelConfigurationSource(pkg, model, "camel.hystrix", true);
}
// Resilience4j
json = loadModelJson(files, "resilience4jConfiguration");
if (json != null) {
EipModel model = JsonMapper.generateEipModel(json);
int pos = model.getJavaType().lastIndexOf(".");
String pkg = model.getJavaType().substring(0, pos) + ".springboot";
// Generate properties, auto-configuration for camel-core-starter
createEipModelConfigurationSource(pkg, model, "camel.resilience4j", true);
}
// Consul
json = loadModelJson(files, "consulServiceDiscovery");
if (json != null) {
EipModel model = JsonMapper.generateEipModel(json);
int pos = model.getJavaType().lastIndexOf(".");
String pkg = model.getJavaType().substring(0, pos) + ".springboot";
// Generate properties, auto-configuration for camel-core-starter
createEipModelConfigurationSource(pkg, model, "camel.cloud.consul.service-discovery", true);
}
// DNS
json = loadModelJson(files, "dnsServiceDiscovery");
if (json != null) {
EipModel model = JsonMapper.generateEipModel(json);
int pos = model.getJavaType().lastIndexOf(".");
String pkg = model.getJavaType().substring(0, pos) + ".springboot";
// Generate properties, auto-configuration for camel-core-starter
createEipModelConfigurationSource(pkg, model, "camel.cloud.dns.service-discovery", true);
}
// Etcd
json = loadModelJson(files, "etcdServiceDiscovery");
if (json != null) {
EipModel model = JsonMapper.generateEipModel(json);
int pos = model.getJavaType().lastIndexOf(".");
String pkg = model.getJavaType().substring(0, pos) + ".springboot";
// Generate properties, auto-configuration for camel-core-starter
createEipModelConfigurationSource(pkg, model, "camel.cloud.etcd.service-discovery", true);
}
// Kubernetes
json = loadModelJson(files, "kubernetesServiceDiscovery");
if (json != null) {
EipModel model = JsonMapper.generateEipModel(json);
int pos = model.getJavaType().lastIndexOf(".");
String pkg = model.getJavaType().substring(0, pos) + ".springboot";
// Generate properties, auto-configuration happens in
// camel-kubernetes-starter
createEipModelConfigurationSource(pkg, model, "camel.cloud.kubernetes.service-discovery", true);
}
// Ribbon
json = loadModelJson(files, "ribbonLoadBalancer");
if (json != null) {
EipModel model = JsonMapper.generateEipModel(json);
int pos = model.getJavaType().lastIndexOf(".");
String pkg = model.getJavaType().substring(0, pos) + ".springboot";
// Generate properties, auto-configuration for camel-core-starter
createEipModelConfigurationSource(pkg, model, "camel.cloud.ribbon.load-balancer", true);
}
// Rest
json = loadModelJson(files, "restConfiguration");
if (json != null) {
EipModel model = JsonMapper.generateEipModel(json);
int pos = model.getJavaType().lastIndexOf(".");
String pkg = model.getJavaType().substring(0, pos) + ".springboot";
// Generate properties, auto-configuration for camel-core-starter
createRestConfigurationSource(pkg, model, "camel.rest");
createRestModuleAutoConfigurationSource(pkg, model);
}
}
Aggregations