All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jolokia.docker.maven.config.BuildImageConfiguration Maven / Gradle / Ivy

The newest version!
package org.jolokia.docker.maven.config;

import java.util.*;

import org.codehaus.plexus.archiver.tar.TarArchiver;
import org.jolokia.docker.maven.util.Logger;

/**
 * @author roland
 * @since 02.09.14
 */
public class BuildImageConfiguration {

    // Base Image name of the data image to use.
    /**
     * @parameter
     */
    private String from;

    /**
     * @parameter
     */
    private String registry;

    /**
     * @parameter
     */
    private String maintainer;

    /**
     * @parameter
     */
    private List ports;

    /**
     * RUN Commands within Build/Image
     * @parameter
     */
    private List runCmds;

    /**
     * @parameter default-value="true"
     */
    private boolean cleanup = true;

    /**
     * @parameter default-value="false"
     */
    private boolean nocache = false;

    /**
     * @parameter default-value="false"
     */
    private boolean optimise = false;

    /**
     * @paramter
     */
    private List volumes;

    /**
     * @paramter
     */
    private List tags;
    
    /**
     * @parameter
     */
    private Map env;

    /**
     * @parameter
     */
    private Map labels;

    /**
     * @parameter
     */
    private Arguments entryPoint;

    /**
     * @parameter
     * @deprecated
     */
    private String command;

    /**
     * @parameter
     */
    private String workdir;

    /**
     * @parameter
     */
    private Arguments cmd;

    /**
     * @parameter
     */
    private AssemblyConfiguration assembly;
    
    /**
     * @parameter
     */
    private boolean skip = false;

    /**
     * @parameter
     */
    private BuildTarArchiveCompression compression = BuildTarArchiveCompression.none;

    public BuildImageConfiguration() {}

    public String getFrom() {
        return from;
    }

    public String getRegistry() {
        return registry;
    }

    public String getMaintainer() {
        return maintainer;
    }

    public String getWorkdir() {
        return workdir;
    }

    public AssemblyConfiguration getAssemblyConfiguration() {
        return assembly;
    }

    public List getPorts() {
        return ports;
    }

    public List getVolumes() {
        return volumes != null ? volumes : Collections.emptyList();
    }

    public List getTags() {
        return tags != null ? tags : Collections.emptyList();
    }

    public Map getEnv() {
        return env;
    }

    public Map getLabels() {
        return labels;
    }

    public Arguments getCmd() {
        return cmd;
    }

    @Deprecated
    public String getCommand() {
        return command;
    }
    
    public boolean cleanup() {
        return cleanup;
    }

    public boolean nocache() {
        return nocache;
    }

    public boolean optimise() {
        return optimise;
    }

    public boolean skip() {
        return skip;
    }

    public BuildTarArchiveCompression getCompression() {
        return compression;
    }

    public Arguments getEntryPoint() {
        return entryPoint;
    }

    public List getRunCmds() {
        return runCmds;
    }

    public static class Builder {
        private final BuildImageConfiguration config = new BuildImageConfiguration();
        
        public Builder from(String from) {
            config.from = from;
            return this;
        }

        public Builder registry(String registry) {
            config.registry = registry;
            return this;
        }

        public Builder maintainer(String maintainer) {
            config.maintainer = maintainer;
            return this;
        }

        public Builder workdir(String workdir) {
            config.workdir = workdir;
            return this;
        }

        public Builder assembly(AssemblyConfiguration assembly) {
            config.assembly = assembly;
            return this;
        }
        
        public Builder ports(List ports) {
            config.ports = ports;
            return this;
        }

        public Builder runCmds(List theCmds) {
            if (config.runCmds == null) {
                config.runCmds = new ArrayList<>();
            }
            else
            	config.runCmds = theCmds;
            return this;
        }
        
        public Builder volumes(List volumes) {
            config.volumes = volumes;
            return this;
        }
        
        public Builder tags(List tags) {
            config.tags = tags;
            return this;
        }

        public Builder env(Map env) {
            config.env = env;
            return this;
        }

        public Builder labels(Map labels) {
            config.labels = labels;
            return this;
        }

        public Builder cmd(String cmd) {
            if (config.cmd == null) {
                config.cmd = new Arguments();
            }
            config.cmd.setShell(cmd);
            return this;
        }
        
        public Builder cleanup(String cleanup) { 
            if (cleanup != null) {
                config.cleanup = Boolean.valueOf(cleanup);
            }
            return this;
        }

        public Builder nocache(String nocache) {
            if (nocache != null) {
                config.nocache = Boolean.valueOf(nocache);
            }
            return this;
        }

        public Builder optimise(String optimise) {
            if (optimise != null) {
                config.optimise = Boolean.valueOf(optimise);
            }
            return this;
        }

        public Builder entryPoint(String entryPoint) {
            if (config.entryPoint == null) {
                config.entryPoint = new Arguments();
            }
            config.entryPoint.setShell(entryPoint);
            return this;
        }
        
        public Builder skip(String skip) {
            if (skip != null) {
                config.skip = Boolean.valueOf(skip);
            }
            return this;
        }

        public BuildImageConfiguration build() {
            return config;
        }
    }

    public void validate(Logger log) throws IllegalArgumentException {
        if (entryPoint != null) {
            entryPoint.validate();
        }
        if (cmd != null) {
            cmd.validate();
        }

        if (command != null) {
            log.warn(" in the  configuration is deprecated and will be be removed soon");
            log.warn("Please use  with nested  or  sections instead.");
            log.warn("");
            log.warn("More on this is explained in the user manual: ");
            log.warn("https://github.com/rhuss/docker-maven-plugin/blob/master/doc/manual.md#start-up-arguments");
            log.warn("");
            log.warn("Migration is trivial, see changelog to version 0.12.0 -->");
            log.warn("https://github.com/rhuss/docker-maven-plugin/blob/master/doc/changelog.md");
            log.warn("");
            log.warn("For now, the command is automatically translated for you to the shell form:");
            log.warn("   " + command + "");
        }

    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy