All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.apache.camel.maven.packaging.MainConfigurerMojo Maven / Gradle / Ivy

/*
 * 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;

import java.io.File;
import java.io.IOException;
import java.io.StringWriter;
import java.io.Writer;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.List;

import org.apache.camel.tooling.model.BaseOptionModel;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.springframework.util.ReflectionUtils;

/**
 * Generate configurer classes for camel-main.
 */
@Mojo(name = "generate-main-configurer", threadSafe = true, defaultPhase = LifecyclePhase.PROCESS_CLASSES)
public class MainConfigurerMojo extends AbstractGeneratorMojo {

    private static final String[] CLASS_NAMES = new String[]{
        "org.apache.camel.main.MainConfigurationProperties",
        "org.apache.camel.main.HystrixConfigurationProperties",
        "org.apache.camel.main.Resilience4jConfigurationProperties",
        "org.apache.camel.main.RestConfigurationProperties",
        "org.apache.camel.ExtendedCamelContext"};

    /**
     * The output directory for generated java source code
     */
    @Parameter(defaultValue = "${project.basedir}/src/generated/java")
    protected File srcOutDir;

    @Parameter(defaultValue = "${project.basedir}/src/generated/resources")
    protected File resourcesOutputDir;

    private DynamicClassLoader projectClassLoader;

    private static class Option extends BaseOptionModel {

        public Option(String name, Class type) {
            // we just use name, type
            setName(name);
            setJavaType(type.getName());
        }
    }

    @Override
    public void execute() throws MojoExecutionException, MojoFailureException {
        List cp = new ArrayList<>();
        cp.add(0, project.getBuild().getOutputDirectory());
        project.getDependencyArtifacts().forEach(a -> {
            if (a.isResolved() && a.getFile() != null) {
                cp.add(a.getFile().getPath());
            }
        });
        projectClassLoader = DynamicClassLoader.createDynamicClassLoader(cp);

        for (String fqn : CLASS_NAMES) {
            try {
                List




© 2015 - 2025 Weber Informatics LLC | Privacy Policy