Skip to content

Commit

Permalink
Basic impl for apache#147
Browse files Browse the repository at this point in the history
  • Loading branch information
lburgazzoli committed Aug 19, 2019
1 parent 9470371 commit a1f43ff
Show file tree
Hide file tree
Showing 14 changed files with 402 additions and 22 deletions.
3 changes: 0 additions & 3 deletions build-parent/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -71,19 +71,16 @@
<artifactId>camel-quarkus-core-deployment</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-http-common-deployment</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-jetty-common-deployment</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-xml-common-deployment</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Properties;
import java.util.Set;
import java.util.function.BiConsumer;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import javax.inject.Inject;
Expand Down Expand Up @@ -56,9 +57,11 @@
import org.eclipse.microprofile.config.ConfigProvider;
import org.jboss.jandex.ClassInfo;
import org.jboss.jandex.DotName;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

class CamelInitProcessor {
private static final Logger LOGGER = LoggerFactory.getLogger(CamelInitProcessor.class);

@Inject
ApplicationArchivesBuildItem applicationArchivesBuildItem;
Expand All @@ -69,8 +72,12 @@ class CamelInitProcessor {

@Record(ExecutionTime.STATIC_INIT)
@BuildStep(applicationArchiveMarkers = { CamelSupport.CAMEL_SERVICE_BASE_PATH, CamelSupport.CAMEL_ROOT_PACKAGE_DIRECTORY })
CamelRuntimeBuildItem createInitTask(RecorderContext recorderContext, CamelRecorder recorder,
CamelRuntimeBuildItem createInitTask(
RecorderContext recorderContext,
CamelRecorder recorder,
List<CamelRegistryBuildItem> registryItems,
BuildProducer<RuntimeBeanBuildItem> runtimeBeans) {

Properties properties = new Properties();
Config configProvider = ConfigProvider.getConfig();
for (String property : configProvider.getPropertyNames()) {
Expand All @@ -85,22 +92,37 @@ CamelRuntimeBuildItem createInitTask(RecorderContext recorderContext, CamelRecor
RuntimeRegistry registry = new RuntimeRegistry();
final List<RuntimeValue<?>> builders;
if (buildTimeConfig.deferInitPhase) {
builders = getBuildTimeRouteBuilderClasses().map(recorderContext::newInstance)
.collect(Collectors.toList());
builders = getBuildTimeRouteBuilderClasses()
.map(recorderContext::newInstance)
.collect(Collectors.toList());
} else {
builders = new ArrayList<>();
}

visitServices((name, type) -> {
LoggerFactory.getLogger(CamelInitProcessor.class).debug("Binding camel service {} with type {}", name, type);
registry.bind(name, type,
recorderContext.newInstance(type.getName()));
});
services().filter(
si -> registryItems.stream().noneMatch(
c -> Objects.equals(si.name, c.getName()) && c.getType().isAssignableFrom(si.type)
)
).forEach(
si -> {
LOGGER.debug("Binding camel service {} with type {}", si.name, si.type);

registry.bind(
si.name,
si.type,
recorderContext.newInstance(si.type.getName())
);
}
);

RuntimeValue<CamelRuntime> camelRuntime = recorder.create(registry, properties, builders, buildTimeConfig);

runtimeBeans
.produce(RuntimeBeanBuildItem.builder(CamelRuntime.class).setRuntimeValue(camelRuntime).build());
runtimeBeans.produce(RuntimeBeanBuildItem.builder(CamelRuntime.class).setRuntimeValue(camelRuntime).build());

for (CamelRegistryBuildItem item: registryItems) {
LOGGER.debug("Binding item with name: {}, type {}", item.getName(), item.getType());
recorder.bind(camelRuntime, item.getName(), item.getType(), item.getValue());
}

return new CamelRuntimeBuildItem(camelRuntime);
}
Expand All @@ -113,8 +135,7 @@ AdditionalBeanBuildItem createCamelProducers(
CamelRecorder recorder,
BuildProducer<BeanContainerListenerBuildItem> listeners) {

listeners
.produce(new BeanContainerListenerBuildItem(recorder.initRuntimeInjection(runtime.getRuntime())));
listeners.produce(new BeanContainerListenerBuildItem(recorder.initRuntimeInjection(runtime.getRuntime())));

return AdditionalBeanBuildItem.unremovableOf(CamelProducers.class);
}
Expand Down Expand Up @@ -163,12 +184,15 @@ protected Stream<String> getBuildTimeRouteBuilderClasses() {
.map(ClassInfo::toString);
}

protected void visitServices(BiConsumer<String, Class<?>> consumer) {
CamelSupport.resources(applicationArchivesBuildItem, CamelSupport.CAMEL_SERVICE_BASE_PATH)
.forEach(p -> visitService(p, consumer));
protected Stream<ServiceInfo> services() {
return CamelSupport.resources(applicationArchivesBuildItem, CamelSupport.CAMEL_SERVICE_BASE_PATH)
.map(this::services)
.flatMap(Collection::stream);
}

protected void visitService(Path p, BiConsumer<String, Class<?>> consumer) {
protected List<ServiceInfo> services(Path p) {
List<ServiceInfo> answer = new ArrayList<>();

String name = p.getFileName().toString();
try (InputStream is = Files.newInputStream(p)) {
Properties props = new Properties();
Expand All @@ -179,11 +203,33 @@ protected void visitService(Path p, BiConsumer<String, Class<?>> consumer) {
String clazz = entry.getValue().toString();
Class<?> cl = Class.forName(clazz);

consumer.accept(name, cl);
answer.add(new ServiceInfo(name, cl));
}
}
} catch (Exception e) {
throw new RuntimeException(e);
}

return answer;
}

static class ServiceInfo {
final String name;
final Class<?> type;

public ServiceInfo(String name, Class<?> type) {
this.name = name;
this.type = type;
}

@Override
public String toString() {
return "ServiceInfo{" +
"name='" + name + '\'' +
", type=" + type +
'}';
}
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.camel.quarkus.core.deployment;

import java.util.Objects;

import io.quarkus.builder.item.MultiBuildItem;

public final class CamelRegistryBuildItem extends MultiBuildItem {
private final String name;
private final Class<?> type;
private final Object value;

public CamelRegistryBuildItem(String name, Object value) {
this.name = Objects.requireNonNull(name);
this.value = Objects.requireNonNull(value);
this.type = Objects.requireNonNull(value).getClass();
}

public CamelRegistryBuildItem(String name, Class<?> type, Object value) {
this.name = Objects.requireNonNull(name);
this.type = Objects.requireNonNull(type);
this.value = Objects.requireNonNull(value);
}

public String getName() {
return name;
}

public Class<?> getType() {
return type;
}

public Object getValue() {
return value;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,15 @@ public RuntimeValue<CamelRuntime> create(
return new RuntimeValue<>(runtime);
}

public void bind(
RuntimeValue<CamelRuntime> runtime,
String name,
Class<?> type,
Object instance) {

runtime.getValue().getRegistry().bind(name, type, instance);
}

public void init(
BeanContainer beanContainer,
RuntimeValue<CamelRuntime> runtime,
Expand Down
49 changes: 49 additions & 0 deletions integration-tests/core-support/deployment/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-integration-test-core-support-parent</artifactId>
<version>0.1.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>camel-quarkus-integration-test-core-support-deployment</artifactId>
<name>Camel Quarkus :: Integration Tests :: Core :: Support :: Deployment</name>
<description>The camel integration tests</description>

<dependencies>
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-core-deployment</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-log-deployment</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-integration-test-core-support</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<annotationProcessorPaths>
<path>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-extension-processor</artifactId>
<version>${quarkus.version}</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.camel.quarkus.core.support.deployment;

import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.deployment.builditem.FeatureBuildItem;

public class Feature {
private static final String FEATURE = "camel-core-support";

@BuildStep
FeatureBuildItem feature() {
return new FeatureBuildItem(FEATURE);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.camel.quarkus.core.support.deployment;

import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.deployment.annotations.ExecutionTime;
import io.quarkus.deployment.annotations.Record;
import org.apache.camel.quarkus.core.deployment.CamelRegistryBuildItem;

public class SupportBuildStep {
@Record(ExecutionTime.STATIC_INIT)
@BuildStep
CamelRegistryBuildItem logComponent(SupportRecorder recorder) {
return recorder.logComponent();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.camel.quarkus.core.support.deployment;

import io.quarkus.runtime.annotations.Recorder;
import org.apache.camel.component.log.LogComponent;
import org.apache.camel.quarkus.core.deployment.CamelRegistryBuildItem;
import org.apache.camel.support.processor.DefaultExchangeFormatter;

@Recorder
public class SupportRecorder {
CamelRegistryBuildItem logComponent() {
DefaultExchangeFormatter def = new DefaultExchangeFormatter();
def.setShowAll(true);
def.setMultiline(true);

LogComponent component = new LogComponent();
component.setExchangeFormatter(def);

return new CamelRegistryBuildItem(
"log",
LogComponent.class,
component
);
}
}

0 comments on commit a1f43ff

Please sign in to comment.