use of io.fabric8.maven.generator.api.Generator in project jointware by isdream.
the class KubernetesExecutor method doCreate.
/**
**********************************************************************************
*
***********************************************************************************
*/
@Override
@SuppressWarnings({ "unchecked", "rawtypes" })
protected Object doCreate(Object client, String kind, Map<String, Map<String, Object>> params) throws Exception {
Createable instance = (Createable) getKindModel(client, kind);
KubernetesModelGenerator generator = new KubernetesModelGenerator(getObjectRef());
Object param = generator.toObject(params, kind);
return instance.create(param);
}
use of io.fabric8.maven.generator.api.Generator 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.Generator 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.Generator 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.Generator in project fabric8-maven-plugin by fabric8io.
the class BaseGenerator method addFrom.
/**
* Add the base image either from configuration or from a given selector
*
* @param builder for the build image configuration to add the from to.
*/
protected void addFrom(BuildImageConfiguration.Builder builder) {
String fromMode = getConfigWithSystemFallbackAndDefault(Config.fromMode, "fabric8.generator.fromMode", getFromModeDefault(context.getMode()));
String from = getConfigWithSystemFallbackAndDefault(Config.from, "fabric8.generator.from", null);
if ("docker".equalsIgnoreCase(fromMode)) {
String fromImage = from;
if (fromImage == null) {
fromImage = fromSelector != null ? fromSelector.getFrom() : null;
}
builder.from(fromImage);
log.info("Using Docker image %s as base / builder", fromImage);
} else if ("istag".equalsIgnoreCase(fromMode)) {
Map<String, String> fromExt = new HashMap<>();
if (from != null) {
ImageName iName = new ImageName(from);
// user/project is considered to be the namespace
String tag = iName.getTag();
if (StringUtils.isBlank(tag)) {
tag = "latest";
}
fromExt.put(OpenShiftBuildStrategy.SourceStrategy.name.key(), iName.getSimpleName() + ":" + tag);
if (iName.getUser() != null) {
fromExt.put(OpenShiftBuildStrategy.SourceStrategy.namespace.key(), iName.getUser());
}
fromExt.put(OpenShiftBuildStrategy.SourceStrategy.kind.key(), "ImageStreamTag");
} else {
fromExt = fromSelector != null ? fromSelector.getImageStreamTagFromExt() : null;
}
if (fromExt != null) {
String namespace = fromExt.get(OpenShiftBuildStrategy.SourceStrategy.namespace.key());
if (namespace != null) {
log.info("Using ImageStreamTag '%s' from namespace '%s' as builder image", fromExt.get(OpenShiftBuildStrategy.SourceStrategy.name.key()), namespace);
} else {
log.info("Using ImageStreamTag '%s' as builder image", fromExt.get(OpenShiftBuildStrategy.SourceStrategy.name.key()));
}
builder.fromExt(fromExt);
}
} else {
throw new IllegalArgumentException(String.format("Invalid 'fromMode' in generator configuration for '%s'", getName()));
}
}
Aggregations