Search in sources :

Example 1 with GeneratorContext

use of io.fabric8.maven.generator.api.GeneratorContext in project fabric8-maven-plugin by fabric8io.

the class GeneratorManager method generate.

public static List<ImageConfiguration> generate(List<ImageConfiguration> imageConfigs, GeneratorContext genCtx, boolean prePackagePhase) throws MojoExecutionException {
    List<ImageConfiguration> ret = imageConfigs;
    PluginServiceFactory<GeneratorContext> pluginFactory = genCtx.isUseProjectClasspath() ? new PluginServiceFactory<GeneratorContext>(genCtx, ClassUtil.createProjectClassLoader(genCtx.getProject(), genCtx.getLogger())) : new PluginServiceFactory<GeneratorContext>(genCtx);
    List<Generator> generators = pluginFactory.createServiceObjects("META-INF/fabric8/generator-default", "META-INF/fabric8/fabric8-generator-default", "META-INF/fabric8/generator", "META-INF/fabric8-generator");
    ProcessorConfig config = genCtx.getConfig();
    Logger log = genCtx.getLogger();
    List<Generator> usableGenerators = config.prepareProcessors(generators, "generator");
    log.verbose("Generators:");
    for (Generator generator : usableGenerators) {
        log.verbose(" - %s", generator.getName());
        if (generator.isApplicable(ret)) {
            log.info("Running generator %s", generator.getName());
            ret = generator.customize(ret, prePackagePhase);
        }
    }
    return ret;
}
Also used : ImageConfiguration(io.fabric8.maven.docker.config.ImageConfiguration) GeneratorContext(io.fabric8.maven.generator.api.GeneratorContext) Logger(io.fabric8.maven.docker.util.Logger) Generator(io.fabric8.maven.generator.api.Generator) ProcessorConfig(io.fabric8.maven.core.config.ProcessorConfig)

Example 2 with GeneratorContext

use of io.fabric8.maven.generator.api.GeneratorContext in project fabric8-maven-plugin by fabric8io.

the class PushMojo method customizeConfig.

/**
 * Customization hook called by the base plugin.
 *
 * @param configs configuration to customize
 * @return the configuration customized by our generators.
 */
@Override
public List<ImageConfiguration> customizeConfig(List<ImageConfiguration> configs) {
    try {
        ProcessorConfig generatorConfig = ProfileUtil.blendProfileWithConfiguration(ProfileUtil.GENERATOR_CONFIG, profile, resourceDir, generator);
        GeneratorContext ctx = new GeneratorContext.Builder().config(generatorConfig).project(project).session(session).goalFinder(goalFinder).goalName("fabric8:push").logger(log).mode(mode).strategy(buildStrategy).useProjectClasspath(false).build();
        return GeneratorManager.generate(configs, ctx, true);
    } catch (Exception e) {
        throw new IllegalArgumentException("Cannot extract generator config: " + e, e);
    }
}
Also used : GeneratorContext(io.fabric8.maven.generator.api.GeneratorContext) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MojoFailureException(org.apache.maven.plugin.MojoFailureException) ProcessorConfig(io.fabric8.maven.core.config.ProcessorConfig)

Example 3 with GeneratorContext

use of io.fabric8.maven.generator.api.GeneratorContext in project fabric8-maven-plugin by fabric8io.

the class ResourceMojo method getResolvedImages.

private List<ImageConfiguration> getResolvedImages(List<ImageConfiguration> images, final Logger log) throws MojoExecutionException {
    List<ImageConfiguration> ret;
    ret = ConfigHelper.resolveImages(log, images, new ConfigHelper.Resolver() {

        @Override
        public List<ImageConfiguration> resolve(ImageConfiguration image) {
            return imageConfigResolver.resolve(image, project, session);
        }
    }, // no filter on image name yet (TODO: Maybe add this, too ?)
    null, new ConfigHelper.Customizer() {

        @Override
        public List<ImageConfiguration> customizeConfig(List<ImageConfiguration> configs) {
            try {
                GeneratorContext ctx = new GeneratorContext.Builder().config(extractGeneratorConfig()).project(project).session(session).goalFinder(goalFinder).goalName("fabric8:resource").logger(log).mode(mode).strategy(buildStrategy).useProjectClasspath(useProjectClasspath).build();
                return GeneratorManager.generate(configs, ctx, true);
            } catch (Exception e) {
                throw new IllegalArgumentException("Cannot extract generator: " + e, e);
            }
        }
    });
    Date now = getBuildReferenceDate();
    storeReferenceDateInPluginContext(now);
    String minimalApiVersion = ConfigHelper.initAndValidate(ret, null, /* no minimal api version */
    new ImageNameFormatter(project, now), log);
    return ret;
}
Also used : ImageConfigResolver(io.fabric8.maven.docker.config.handler.ImageConfigResolver) ImageConfiguration(io.fabric8.maven.docker.config.ImageConfiguration) ImageNameFormatter(io.fabric8.maven.docker.util.ImageNameFormatter) List(java.util.List) ArrayList(java.util.ArrayList) GeneratorContext(io.fabric8.maven.generator.api.GeneratorContext) MavenFilteringException(org.apache.maven.shared.filtering.MavenFilteringException) Fabric8ServiceException(io.fabric8.maven.core.service.Fabric8ServiceException) IOException(java.io.IOException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MojoFailureException(org.apache.maven.plugin.MojoFailureException) ConstraintViolationException(javax.validation.ConstraintViolationException) Date(java.util.Date)

Example 4 with GeneratorContext

use of io.fabric8.maven.generator.api.GeneratorContext in project fabric8-maven-plugin by fabric8io.

the class JavaRunGeneratorTest method fromSelector.

@Test
public void fromSelector() throws IOException {
    Object[] data = { "3.1.123", PlatformMode.kubernetes, null, "java.upstream.docker", "3.1.redhat-101", PlatformMode.kubernetes, null, "java.redhat.docker", "3.1.123", PlatformMode.openshift, OpenShiftBuildStrategy.docker, "java.upstream.docker", "3.1.redhat-101", PlatformMode.openshift, OpenShiftBuildStrategy.docker, "java.redhat.docker", "3.1.123", PlatformMode.openshift, OpenShiftBuildStrategy.s2i, "java.upstream.s2i", "3.1.redhat-101", PlatformMode.openshift, OpenShiftBuildStrategy.s2i, "java.redhat.s2i" };
    Properties imageProps = getDefaultImageProps();
    for (int i = 0; i < data.length; i += 4) {
        prepareExpectation((String) data[i], (PlatformMode) data[i + 1], (OpenShiftBuildStrategy) data[i + 2]);
        final GeneratorContext context = ctx;
        FromSelector selector = new FromSelector.Default(context, "java");
        String from = selector.getFrom();
        assertEquals(imageProps.getProperty((String) data[i + 3]), from);
    }
}
Also used : GeneratorContext(io.fabric8.maven.generator.api.GeneratorContext) FromSelector(io.fabric8.maven.generator.api.FromSelector) Test(org.junit.Test)

Example 5 with GeneratorContext

use of io.fabric8.maven.generator.api.GeneratorContext in project fabric8-maven-plugin by fabric8io.

the class WatchMojo method customizeConfig.

@Override
public List<ImageConfiguration> customizeConfig(List<ImageConfiguration> configs) {
    try {
        Fabric8ServiceHub serviceHub = getFabric8ServiceHub();
        GeneratorContext ctx = new GeneratorContext.Builder().config(extractGeneratorConfig()).project(project).session(session).goalFinder(goalFinder).goalName("fabric8:watch").logger(log).mode(mode).strategy(buildStrategy).useProjectClasspath(useProjectClasspath).artifactResolver(serviceHub.getArtifactResolverService()).build();
        return GeneratorManager.generate(configs, ctx, false);
    } catch (MojoExecutionException e) {
        throw new IllegalArgumentException("Cannot extract generator config: " + e, e);
    }
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) Fabric8ServiceHub(io.fabric8.maven.core.service.Fabric8ServiceHub) GeneratorContext(io.fabric8.maven.generator.api.GeneratorContext)

Aggregations

GeneratorContext (io.fabric8.maven.generator.api.GeneratorContext)8 ProcessorConfig (io.fabric8.maven.core.config.ProcessorConfig)5 ImageConfiguration (io.fabric8.maven.docker.config.ImageConfiguration)5 ArrayList (java.util.ArrayList)4 Test (org.junit.Test)4 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)3 MavenProject (org.apache.maven.project.MavenProject)3 MojoFailureException (org.apache.maven.plugin.MojoFailureException)2 Fabric8ServiceException (io.fabric8.maven.core.service.Fabric8ServiceException)1 Fabric8ServiceHub (io.fabric8.maven.core.service.Fabric8ServiceHub)1 ImageConfigResolver (io.fabric8.maven.docker.config.handler.ImageConfigResolver)1 ImageNameFormatter (io.fabric8.maven.docker.util.ImageNameFormatter)1 Logger (io.fabric8.maven.docker.util.Logger)1 FromSelector (io.fabric8.maven.generator.api.FromSelector)1 Generator (io.fabric8.maven.generator.api.Generator)1 IOException (java.io.IOException)1 Date (java.util.Date)1 List (java.util.List)1 ConstraintViolationException (javax.validation.ConstraintViolationException)1 MavenFilteringException (org.apache.maven.shared.filtering.MavenFilteringException)1