-
Notifications
You must be signed in to change notification settings - Fork 194
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ref #4426: Support CSimple expressions with all DSLs
- Loading branch information
1 parent
93e8725
commit 54144df
Showing
33 changed files
with
1,046 additions
and
207 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
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. | ||
--> | ||
<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"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>org.apache.camel.quarkus</groupId> | ||
<artifactId>camel-quarkus-support-language-parent</artifactId> | ||
<version>2.17.0-SNAPSHOT</version> | ||
<relativePath>../pom.xml</relativePath> | ||
</parent> | ||
|
||
<artifactId>camel-quarkus-support-language-deployment</artifactId> | ||
<name>Camel Quarkus :: Support :: Language :: Deployment</name> | ||
|
||
<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-support-language</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.camel</groupId> | ||
<artifactId>camel-main</artifactId> | ||
</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> |
48 changes: 48 additions & 0 deletions
48
...c/main/java/org/apache/camel/quarkus/support/language/deployment/ExpressionBuildItem.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* 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.support.language.deployment; | ||
|
||
import io.quarkus.builder.item.MultiBuildItem; | ||
|
||
/** | ||
* {@code ExpressionBuildItem} represents an expression in a given language that has been extracted from the route | ||
* definitions. | ||
*/ | ||
public final class ExpressionBuildItem extends MultiBuildItem { | ||
|
||
final String language; | ||
final String expression; | ||
final boolean predicate; | ||
|
||
public ExpressionBuildItem(String language, String expression, boolean predicate) { | ||
this.language = language; | ||
this.expression = expression; | ||
this.predicate = predicate; | ||
} | ||
|
||
public String getLanguage() { | ||
return language; | ||
} | ||
|
||
public String getExpression() { | ||
return expression; | ||
} | ||
|
||
public boolean isPredicate() { | ||
return predicate; | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
...apache/camel/quarkus/support/language/deployment/ExpressionExtractionResultBuildItem.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* 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.support.language.deployment; | ||
|
||
import io.quarkus.builder.item.SimpleBuildItem; | ||
|
||
/** | ||
* {@code ExpressionBuildItem} represents the result of the expression extraction process. | ||
*/ | ||
public final class ExpressionExtractionResultBuildItem extends SimpleBuildItem { | ||
|
||
final boolean success; | ||
|
||
public ExpressionExtractionResultBuildItem(boolean success) { | ||
this.success = success; | ||
} | ||
|
||
public boolean isSuccess() { | ||
return success; | ||
} | ||
} |
92 changes: 92 additions & 0 deletions
92
...n/java/org/apache/camel/quarkus/support/language/deployment/LanguageSupportProcessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
/* | ||
* 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.support.language.deployment; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import io.quarkus.bootstrap.classloading.QuarkusClassLoader; | ||
import io.quarkus.deployment.annotations.BuildProducer; | ||
import io.quarkus.deployment.annotations.BuildStep; | ||
import org.apache.camel.builder.RouteBuilder; | ||
import org.apache.camel.quarkus.core.CamelConfig; | ||
import org.apache.camel.quarkus.core.deployment.spi.CamelRoutesBuilderClassBuildItem; | ||
import org.apache.camel.quarkus.support.language.deployment.dm.DryModeLanguage; | ||
import org.apache.camel.quarkus.support.language.deployment.dm.DryModeMain; | ||
import org.jboss.logging.Logger; | ||
|
||
class LanguageSupportProcessor { | ||
|
||
private static final Logger LOG = Logger.getLogger(LanguageSupportProcessor.class); | ||
|
||
@BuildStep | ||
ExpressionExtractionResultBuildItem extractExpressions(CamelConfig config, | ||
List<CamelRoutesBuilderClassBuildItem> routesBuilderClasses, | ||
BuildProducer<ExpressionBuildItem> producer) throws Exception { | ||
if (config.expression.extractionEnabled) { | ||
final ClassLoader loader = Thread.currentThread().getContextClassLoader(); | ||
if (!(loader instanceof QuarkusClassLoader)) { | ||
throw new IllegalStateException( | ||
QuarkusClassLoader.class.getSimpleName() + " expected as the context class loader"); | ||
} | ||
final List<Class<?>> routeBuilderClasses = new ArrayList<>(routesBuilderClasses.size()); | ||
for (CamelRoutesBuilderClassBuildItem routesBuilderClass : routesBuilderClasses) { | ||
final String className = routesBuilderClass.getDotName().toString(); | ||
final Class<?> cl = loader.loadClass(className); | ||
|
||
if (RouteBuilder.class.isAssignableFrom(cl)) { | ||
routeBuilderClasses.add(cl); | ||
} else { | ||
LOG.warnf("Language expressions occurring in %s won't be compiled at build time", cl); | ||
} | ||
} | ||
try { | ||
DryModeMain main = new DryModeMain("Expression Extractor", routeBuilderClasses.toArray(new Class<?>[0])); | ||
main.start(); | ||
main.run(); | ||
for (DryModeLanguage language : main.getLanguages()) { | ||
final String name = language.getName(); | ||
for (String exp : language.getPredicates()) { | ||
producer.produce(new ExpressionBuildItem(name, exp, true)); | ||
} | ||
for (String exp : language.getExpressions()) { | ||
producer.produce(new ExpressionBuildItem(name, exp, false)); | ||
} | ||
} | ||
return new ExpressionExtractionResultBuildItem(true); | ||
} catch (Exception e) { | ||
switch (config.expression.onBuildTimeAnalysisFailure) { | ||
case fail: | ||
throw new RuntimeException( | ||
"Could not extract language expressions." | ||
+ "You may want to set quarkus.camel.expression.on-build-time-analysis-failure to warn or ignore if you do not use languages in your routes", | ||
e); | ||
case warn: | ||
LOG.warn("Could not extract language expressions.", e); | ||
break; | ||
case ignore: | ||
LOG.debug("Could not extract language expressions", e); | ||
break; | ||
default: | ||
throw new IllegalStateException("Unexpected " + CamelConfig.FailureRemedy.class.getSimpleName() + ": " | ||
+ config.expression.onBuildTimeAnalysisFailure); | ||
} | ||
} | ||
} | ||
return new ExpressionExtractionResultBuildItem(false); | ||
} | ||
} |
Oops, something went wrong.