use of io.fabric8.maven.core.util.ResourceFileType in project fabric8-maven-plugin by fabric8io.
the class ImageStreamService method writeImageStreams.
private File writeImageStreams(File target, KubernetesList entity) throws MojoExecutionException, IOException {
final File targetWithoutExt;
final ResourceFileType type;
String ext = "";
try {
ext = FilenameUtils.getExtension(target.getPath());
type = ResourceFileType.fromExtension(ext);
String p = target.getAbsolutePath();
targetWithoutExt = new File(p.substring(0, p.length() - ext.length() - 1));
} catch (IllegalArgumentException exp) {
throw new MojoExecutionException(String.format("Invalid extension '%s' for ImageStream target file '%s'. Allowed extensions: yml, json", ext, target.getPath()), exp);
}
return KubernetesResourceUtil.writeResource(entity, targetWithoutExt, type);
}
use of io.fabric8.maven.core.util.ResourceFileType in project fabric8-maven-plugin by fabric8io.
the class AbstractResourceMojo method writeIndividualResources.
private static void writeIndividualResources(KubernetesList resources, File targetDir, ResourceFileType resourceFileType, Logger log, Boolean generateRoute) throws MojoExecutionException {
for (HasMetadata item : resources.getItems()) {
String name = KubernetesHelper.getName(item);
if (Strings.isNullOrBlank(name)) {
log.error("No name for generated item %s", item);
continue;
}
String itemFile = KubernetesResourceUtil.getNameWithSuffix(name, item.getKind());
if (!(item.getKind().equalsIgnoreCase("Route") && !generateRoute)) {
File itemTarget = new File(targetDir, itemFile);
writeResource(itemTarget, item, resourceFileType);
}
}
}
use of io.fabric8.maven.core.util.ResourceFileType in project fabric8-maven-plugin by fabric8io.
the class AbstractResourceMojo method writeResourcesIndividualAndComposite.
public static File writeResourcesIndividualAndComposite(KubernetesList resources, File resourceFileBase, ResourceFileType resourceFileType, Logger log, Boolean generateRoute) throws MojoExecutionException {
// Creating a new items list. This will be used to generate openshift.yml
List<HasMetadata> newItemList = new ArrayList<>();
if (!generateRoute) {
// if flag is set false, this will remove the Route resource from resources list
for (HasMetadata item : resources.getItems()) {
if (item.getKind().equalsIgnoreCase("Route")) {
continue;
}
newItemList.add(item);
}
// update the resource with new list
resources.setItems(newItemList);
}
// entity is object which will be sent to writeResource for openshift.yml
// if generateRoute is false, this will be set to resources with new list
// otherwise it will be set to resources with old list.
Object entity = resources;
// if the list contains a single Template lets unwrap it
// in resources already new or old as per condition is set.
// no need to worry about this for dropping Route.
Template template = getSingletonTemplate(resources);
if (template != null) {
entity = template;
}
File file = writeResource(resourceFileBase, entity, resourceFileType);
// write separate files, one for each resource item
// resources passed to writeIndividualResources is also new one.
writeIndividualResources(resources, resourceFileBase, resourceFileType, log, generateRoute);
return file;
}
Aggregations