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;
}
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);
}
}
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;
}
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);
}
}
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);
}
}
Aggregations