use of io.quarkus.deployment.ApplicationArchive in project camel-quarkus by apache.
the class CamelProcessor method typeConverterRegistry.
/*
* Discover {@link TypeConverterLoader}.
*/
@SuppressWarnings("unchecked")
@Record(ExecutionTime.STATIC_INIT)
@BuildStep
CamelTypeConverterRegistryBuildItem typeConverterRegistry(CamelRecorder recorder, ApplicationArchivesBuildItem applicationArchives, List<CamelTypeConverterLoaderBuildItem> additionalLoaders, CombinedIndexBuildItem combinedIndex, BuildProducer<ReflectiveClassBuildItem> reflectiveClasses) {
IndexView index = combinedIndex.getIndex();
RuntimeValue<TypeConverterRegistry> typeConverterRegistry = recorder.createTypeConverterRegistry();
//
// This should be simplified by searching for classes implementing TypeConverterLoader but that
// would lead to have org.apache.camel.impl.converter.AnnotationTypeConverterLoader taken into
// account even if it should not.
//
final ClassLoader TCCL = Thread.currentThread().getContextClassLoader();
for (ApplicationArchive archive : applicationArchives.getAllApplicationArchives()) {
for (Path root : archive.getRootDirs()) {
Path path = root.resolve(BaseTypeConverterRegistry.META_INF_SERVICES_TYPE_CONVERTER_LOADER);
if (!Files.isRegularFile(path)) {
continue;
}
try {
Files.readAllLines(path, StandardCharsets.UTF_8).stream().map(String::trim).filter(l -> !l.isEmpty()).filter(l -> !l.startsWith("#")).map(l -> (Class<? extends TypeConverterLoader>) CamelSupport.loadClass(l, TCCL)).forEach(loader -> recorder.addTypeConverterLoader(typeConverterRegistry, loader));
} catch (IOException e) {
throw new RuntimeException("Error discovering TypeConverterLoader", e);
}
}
}
Set<String> internalConverters = new HashSet<>();
// ignore all @converters from org.apache.camel:camel-* dependencies
for (ApplicationArchive archive : applicationArchives.getAllApplicationArchives()) {
ArtifactKey artifactKey = archive.getKey();
if (artifactKey != null && "org.apache.camel".equals(artifactKey.getGroupId()) && artifactKey.getArtifactId().startsWith("camel-")) {
internalConverters.addAll(archive.getIndex().getAnnotations(DotName.createSimple(Converter.class.getName())).stream().filter(a -> a.target().kind() == AnnotationTarget.Kind.CLASS).map(a -> a.target().asClass().name().toString()).collect(Collectors.toSet()));
}
}
Set<Class> convertersClasses = index.getAnnotations(DotName.createSimple(Converter.class.getName())).stream().filter(a -> a.target().kind() == AnnotationTarget.Kind.CLASS && (a.value("generateBulkLoader") == null || !a.value("generateBulkLoader").asBoolean()) && (a.value("generateLoader") == null || !a.value("generateLoader").asBoolean())).map(a -> a.target().asClass().name().toString()).filter(s -> !internalConverters.contains(s)).map(s -> CamelSupport.loadClass(s, TCCL)).collect(Collectors.toSet());
recorder.loadAnnotatedConverters(typeConverterRegistry, convertersClasses);
//
for (CamelTypeConverterLoaderBuildItem item : additionalLoaders) {
recorder.addTypeConverterLoader(typeConverterRegistry, item.getValue());
}
return new CamelTypeConverterRegistryBuildItem(typeConverterRegistry);
}
use of io.quarkus.deployment.ApplicationArchive in project camel-quarkus by apache.
the class CamelSupport method services.
public static Stream<CamelServiceBuildItem> services(ApplicationArchivesBuildItem archives, PathFilter pathFilter) {
final Set<CamelServiceBuildItem> answer = new HashSet<>();
final Predicate<Path> filter = pathFilter.asPathPredicate();
for (ApplicationArchive archive : archives.getAllApplicationArchives()) {
for (Path root : archive.getRootDirectories()) {
final Path resourcePath = root.resolve(CAMEL_SERVICE_BASE_PATH);
if (!Files.isDirectory(resourcePath)) {
continue;
}
safeWalk(resourcePath).filter(Files::isRegularFile).forEach(file -> {
// the root archive may point to a jar file or the absolute path of
// a project's build output so we need to relativize to make the
// FastFactoryFinder work as expected
Path key = root.relativize(file);
if (filter.test(key)) {
String clazz = readProperties(file).getProperty("class");
if (clazz != null) {
answer.add(new CamelServiceBuildItem(key, clazz));
}
}
});
}
}
return answer.stream();
}
use of io.quarkus.deployment.ApplicationArchive in project camel-quarkus by apache.
the class CamelNativeImageProcessor method camelRuntimeCatalog.
/*
* Add camel catalog files to the native image.
*/
@BuildStep(onlyIf = CamelConfigFlags.RuntimeCatalogEnabled.class)
List<NativeImageResourceBuildItem> camelRuntimeCatalog(CamelConfig config, ApplicationArchivesBuildItem archives, List<CamelServicePatternBuildItem> servicePatterns) {
List<NativeImageResourceBuildItem> resources = new ArrayList<>();
final PathFilter pathFilter = servicePatterns.stream().collect(PathFilter.Builder::new, (builder, patterns) -> builder.patterns(patterns.isInclude(), patterns.getPatterns()), PathFilter.Builder::combine).build();
CamelSupport.services(archives, pathFilter).filter(service -> service.name != null && service.type != null && service.path != null).forEach(service -> {
String packageName = getPackageName(service.type);
String jsonPath = String.format("%s/%s.json", packageName.replace('.', '/'), service.name);
if (config.runtimeCatalog.components && service.path.startsWith(DefaultComponentResolver.RESOURCE_PATH)) {
resources.add(new NativeImageResourceBuildItem(jsonPath));
}
if (config.runtimeCatalog.dataformats && service.path.startsWith(DefaultDataFormatResolver.DATAFORMAT_RESOURCE_PATH)) {
resources.add(new NativeImageResourceBuildItem(jsonPath));
}
if (config.runtimeCatalog.languages && service.path.startsWith(DefaultLanguageResolver.LANGUAGE_RESOURCE_PATH)) {
resources.add(new NativeImageResourceBuildItem(jsonPath));
}
});
if (config.runtimeCatalog.models) {
for (ApplicationArchive archive : archives.getAllApplicationArchives()) {
for (Path root : archive.getRootDirectories()) {
final Path resourcePath = root.resolve(CamelContextHelper.MODEL_DOCUMENTATION_PREFIX);
if (!Files.isDirectory(resourcePath)) {
continue;
}
List<String> items = CamelSupport.safeWalk(resourcePath).filter(Files::isRegularFile).map(root::relativize).map(Path::toString).collect(Collectors.toList());
LOGGER.debug("Register catalog json: {}", items);
resources.add(new NativeImageResourceBuildItem(items));
}
}
}
return resources;
}
use of io.quarkus.deployment.ApplicationArchive in project automatiko-engine by automatiko-io.
the class AutomatikoQuarkusProcessor method reflectiveClassesRegistrationStep.
@BuildStep
public void reflectiveClassesRegistrationStep(ApplicationArchivesBuildItem archives, BuildProducer<ReflectiveHierarchyIgnoreWarningBuildItem> reflectiveHierarchy, BuildProducer<ReflectiveClassBuildItem> reflectiveClass) {
reflectiveClass.produce(new ReflectiveClassBuildItem(true, true, "io.automatiko.engine.api.event.AbstractDataEvent"));
reflectiveClass.produce(new ReflectiveClassBuildItem(true, true, "io.automatiko.engine.services.event.AbstractProcessDataEvent"));
reflectiveClass.produce(new ReflectiveClassBuildItem(true, true, "io.automatiko.engine.services.event.ProcessInstanceDataEvent"));
reflectiveClass.produce(new ReflectiveClassBuildItem(true, true, "io.automatiko.engine.services.event.UserTaskInstanceDataEvent"));
reflectiveClass.produce(new ReflectiveClassBuildItem(true, true, "io.automatiko.engine.services.event.VariableInstanceDataEvent"));
reflectiveClass.produce(new ReflectiveClassBuildItem(true, true, "io.automatiko.engine.services.event.impl.ProcessInstanceEventBody"));
reflectiveClass.produce(new ReflectiveClassBuildItem(true, true, "io.automatiko.engine.services.event.impl.NodeInstanceEventBody"));
reflectiveClass.produce(new ReflectiveClassBuildItem(true, true, "io.automatiko.engine.services.event.impl.ProcessErrorEventBody"));
reflectiveClass.produce(new ReflectiveClassBuildItem(true, true, "io.automatiko.engine.services.event.impl.VariableInstanceEventBody"));
reflectiveClass.produce(new ReflectiveClassBuildItem(true, true, "io.automatiko.engine.services.event.impl.UserTaskInstanceEventBody"));
reflectiveClass.produce(new ReflectiveClassBuildItem(false, false, "org.mvel2.optimizers.dynamic.DynamicOptimizer"));
reflectiveClass.produce(new ReflectiveClassBuildItem(false, false, "org.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer"));
reflectiveClass.produce(new ReflectiveClassBuildItem(true, true, ArrayList.class.getCanonicalName()));
reflectiveClass.produce(new ReflectiveClassBuildItem(true, true, byte[].class.getName()));
reflectiveClass.produce(new ReflectiveClassBuildItem(true, false, BaseWorkItem.class));
List<IndexView> archiveIndexes = new ArrayList<>();
for (ApplicationArchive i : archives.getAllApplicationArchives()) {
archiveIndexes.add(i.getIndex());
}
CompositeIndex archivesIndex = CompositeIndex.create(archiveIndexes);
// add functions classes found
reflectiveClass.produce(new ReflectiveClassBuildItem(true, false, "io.automatiko.engine.services.execution.BaseFunctions"));
archivesIndex.getAllKnownImplementors(createDotName("io.automatiko.engine.api.Functions")).stream().map(c -> c.name().toString()).forEach(c -> reflectiveClass.produce(new ReflectiveClassBuildItem(true, false, c)));
// DMN related
DotName classDotName = createDotName(CodeGenConstants.DMN_CLASS);
if (!archivesIndex.getAnnotations(classDotName).isEmpty() || archivesIndex.getClassByName(classDotName) != null) {
reflectiveHierarchy.produce(new ReflectiveHierarchyIgnoreWarningBuildItem(createDotName("org.kie.api.builder.Message$Level")));
reflectiveHierarchy.produce(new ReflectiveHierarchyIgnoreWarningBuildItem(createDotName("org.kie.dmn.api.core.DMNContext")));
reflectiveHierarchy.produce(new ReflectiveHierarchyIgnoreWarningBuildItem(createDotName("org.kie.dmn.api.core.DMNDecisionResult")));
reflectiveHierarchy.produce(new ReflectiveHierarchyIgnoreWarningBuildItem(createDotName("org.kie.dmn.api.core.DMNDecisionResult$DecisionEvaluationStatus")));
reflectiveHierarchy.produce(new ReflectiveHierarchyIgnoreWarningBuildItem(createDotName("org.kie.dmn.api.core.DMNMessage")));
reflectiveHierarchy.produce(new ReflectiveHierarchyIgnoreWarningBuildItem(createDotName("org.kie.dmn.api.core.DMNMessage$Severity")));
reflectiveHierarchy.produce(new ReflectiveHierarchyIgnoreWarningBuildItem(createDotName("org.kie.dmn.api.core.DMNMessageType")));
reflectiveHierarchy.produce(new ReflectiveHierarchyIgnoreWarningBuildItem(createDotName("org.kie.dmn.api.feel.runtime.events.FEELEvent")));
}
// jackson node classes for serializing JSON tree instances
reflectiveClass.produce(new ReflectiveClassBuildItem(true, true, "com.fasterxml.jackson.databind.node.TextNode"));
reflectiveClass.produce(new ReflectiveClassBuildItem(true, true, "com.fasterxml.jackson.databind.node.BinaryNode"));
reflectiveClass.produce(new ReflectiveClassBuildItem(true, true, "com.fasterxml.jackson.databind.node.BooleanNode"));
reflectiveClass.produce(new ReflectiveClassBuildItem(true, true, "com.fasterxml.jackson.databind.node.NullNode"));
reflectiveClass.produce(new ReflectiveClassBuildItem(true, true, "com.fasterxml.jackson.databind.node.BigIntegerNode"));
reflectiveClass.produce(new ReflectiveClassBuildItem(true, true, "com.fasterxml.jackson.databind.node.DecimalNode"));
reflectiveClass.produce(new ReflectiveClassBuildItem(true, true, "com.fasterxml.jackson.databind.node.DoubleNode"));
reflectiveClass.produce(new ReflectiveClassBuildItem(true, true, "com.fasterxml.jackson.databind.node.FloatNode"));
reflectiveClass.produce(new ReflectiveClassBuildItem(true, true, "com.fasterxml.jackson.databind.node.IntNode"));
reflectiveClass.produce(new ReflectiveClassBuildItem(true, true, "com.fasterxml.jackson.databind.node.LongNode"));
reflectiveClass.produce(new ReflectiveClassBuildItem(true, true, "com.fasterxml.jackson.databind.node.ShortNode"));
reflectiveClass.produce(new ReflectiveClassBuildItem(true, true, "com.fasterxml.jackson.databind.node.POJONode"));
reflectiveClass.produce(new ReflectiveClassBuildItem(true, true, "com.fasterxml.jackson.databind.node.ObjectNode"));
reflectiveClass.produce(new ReflectiveClassBuildItem(true, true, "com.fasterxml.jackson.databind.node.ArrayNode"));
reflectiveClass.produce(new ReflectiveClassBuildItem(true, true, Long.class.getCanonicalName()));
reflectiveClass.produce(new ReflectiveClassBuildItem(true, true, Integer.class.getCanonicalName()));
reflectiveClass.produce(new ReflectiveClassBuildItem(true, true, Boolean.class.getCanonicalName()));
reflectiveClass.produce(new ReflectiveClassBuildItem(true, true, String.class.getCanonicalName()));
}
Aggregations