Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
import org.jboss.jandex.Index;
import org.jboss.jandex.IndexReader;

import static org.apache.camel.maven.packaging.generics.PackagePluginUtils.readJandexIndex;
import static org.apache.camel.tooling.util.ReflectionHelper.doWithMethods;
import static org.apache.camel.tooling.util.Strings.between;

Expand Down Expand Up @@ -160,13 +161,7 @@ protected void doExecute(File sourcesOutputDir, File resourcesOutputDir, List<St

// additional classes
if (classes != null && !classes.isEmpty()) {
Path output = Paths.get(project.getBuild().getOutputDirectory());
Index index;
try (InputStream is = Files.newInputStream(output.resolve("META-INF/jandex.idx"))) {
index = new IndexReader(is).read();
} catch (IOException e) {
throw new MojoExecutionException("IOException: " + e.getMessage(), e);
}
Index index = readJandexIndex(project);
for (String clazz : classes) {
ClassInfo ci = index.getClassByName(DotName.createSimple(clazz));
AnnotationInstance ai = ci != null ? ci.classAnnotation(CONFIGURER) : null;
Expand All @@ -192,6 +187,8 @@ protected void doExecute(File sourcesOutputDir, File resourcesOutputDir, List<St
}
}



private void addToSets(
AnnotationInstance annotation, Set<String> bootstrapAndExtendedSet, String currentClass, Set<String> bootstrapSet,
Set<String> extendedSet, Set<String> set) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -369,19 +369,14 @@ private boolean doCreateEndpointDsl(ComponentModel model, List<ComponentModel> a
private void processMasterScheme(
List<ComponentModel> aliases, List<Method> staticBuilders, JavaClass javaClass, JavaClass builderClass,
JavaClass dslClass) {
Method method;

// we only want the first alias (master scheme) as static builders
boolean firstAlias = true;

for (ComponentModel componentModel : aliases) {
String desc = getMainDescription(componentModel);
String methodName = camelCaseLower(componentModel.getScheme());
method = dslClass.addMethod().setStatic().setName(methodName)
.addParameter(String.class, "path")
.setReturnType(new GenericType(loadClass(builderClass.getCanonicalName())))
.setDefault()
.setBodyF("return %s.%s(%s);", javaClass.getName(), "endpointBuilder",
"\"" + componentModel.getScheme() + "\", path");
Method method = doAddMethod(javaClass, builderClass, dslClass, componentModel, methodName);
String javaDoc = desc;
javaDoc += "\n\n@param path " + pathParameterJavaDoc(componentModel);
javaDoc += "\n@return the dsl builder\n";
Expand Down Expand Up @@ -434,18 +429,22 @@ private void processMasterScheme(
}
}

private Method doAddMethod(JavaClass javaClass, JavaClass builderClass, JavaClass dslClass, ComponentModel componentModel, String methodName) {
return dslClass.addMethod().setStatic().setName(methodName)
.addParameter(String.class, "path")
.setReturnType(new GenericType(loadClass(builderClass.getCanonicalName())))
.setDefault()
.setBodyF("return %s.%s(%s);", javaClass.getName(), "endpointBuilder",
"\"" + componentModel.getScheme() + "\", path");
}

private void processAliases(
ComponentModel model, List<Method> staticBuilders, JavaClass javaClass, JavaClass builderClass,
JavaClass dslClass) {
Method method;
String desc = getMainDescription(model);
String methodName = camelCaseLower(model.getScheme());
method = dslClass.addMethod().setStatic().setName(methodName)
.addParameter(String.class, "path")
.setReturnType(new GenericType(loadClass(builderClass.getCanonicalName())))
.setDefault()
.setBodyF("return %s.%s(%s);", javaClass.getName(), "endpointBuilder",
"\"" + model.getScheme() + "\", path");
method = doAddMethod(javaClass, builderClass, dslClass, model, methodName);
String javaDoc = desc;
javaDoc += "\n\n@param path " + pathParameterJavaDoc(model);
javaDoc += "\n@return the dsl builder\n";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import org.jboss.jandex.Type;

import static org.apache.camel.maven.packaging.SchemaHelper.dashToCamelCase;
import static org.apache.camel.maven.packaging.generics.PackagePluginUtils.readJandexIndex;

@Mojo(name = "generate-type-converter-loader", threadSafe = true,
requiresDependencyResolution = ResolutionScope.COMPILE_PLUS_RUNTIME, defaultPhase = LifecyclePhase.PROCESS_CLASSES)
Expand Down Expand Up @@ -82,13 +83,7 @@ public void execute() throws MojoExecutionException, MojoFailureException {
return;
}

Path output = Paths.get(project.getBuild().getOutputDirectory());
Index index;
try (InputStream is = Files.newInputStream(output.resolve("META-INF/jandex.idx"))) {
index = new IndexReader(is).read();
} catch (IOException e) {
throw new MojoExecutionException("IOException: " + e.getMessage(), e);
}
Index index = readJandexIndex(project);

Map<String, ClassConverters> converters = new TreeMap<>();
List<MethodInfo> bulkConverters = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* 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.maven.packaging.generics;

import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.project.MavenProject;
import org.jboss.jandex.Index;
import org.jboss.jandex.IndexReader;

public class PackagePluginUtils {
private PackagePluginUtils() {

}

public static Index readJandexIndex(MavenProject project) throws MojoExecutionException {
Path output = Paths.get(project.getBuild().getOutputDirectory());
Index index;
try (InputStream is = Files.newInputStream(output.resolve("META-INF/jandex.idx"))) {
index = new IndexReader(is).read();
} catch (IOException e) {
throw new MojoExecutionException("IOException: " + e.getMessage(), e);
}
return index;
}

}