Search in sources :

Example 1 with ResourceFileType

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);
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ResourceFileType(io.fabric8.maven.core.util.ResourceFileType) File(java.io.File)

Example 2 with ResourceFileType

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);
        }
    }
}
Also used : HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) File(java.io.File)

Example 3 with 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;
}
Also used : HasMetadata(io.fabric8.kubernetes.api.model.HasMetadata) ArrayList(java.util.ArrayList) File(java.io.File) Template(io.fabric8.openshift.api.model.Template)

Aggregations

File (java.io.File)3 HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)2 ResourceFileType (io.fabric8.maven.core.util.ResourceFileType)1 Template (io.fabric8.openshift.api.model.Template)1 ArrayList (java.util.ArrayList)1 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)1