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

io.fabric8.maven.docker.config.Arguments Maven / Gradle / Ivy

There is a newer version: 0.45.0
Show newest version
package io.fabric8.maven.docker.config;

import io.fabric8.maven.docker.util.EnvUtil;
import org.apache.maven.plugins.annotations.Parameter;

import java.io.Serializable;
import java.util.*;

public class Arguments implements Serializable {

    @Parameter
    private String shell;

    @Parameter
    private List exec;

    /**
     * Used to distinguish between shorter version
     *
     * 
     *   <cmd>
     *     <arg>echo</arg>
     *     <arg>Hello, world!</arg>
     *   </cmd>
     * 
* * from the full one * *
     *   <cmd>
     *     <exec>
     *       <arg>echo</arg>
     *       <arg>Hello, world!</arg>
     *     <exec>
     *   </cmd>
     * 
* * and throw a validation error if both specified. */ private List execInlined = new ArrayList<>(); public Arguments() { } public Arguments(String shell) { this.shell = shell; } public Arguments(List exec) { this.exec = exec; } /** * Used to support shell specified as a default parameter, e.g. * *
     *   <cmd>java -jar $HOME/server.jar</cmd>
     * 
* * Read more on * this and other useful techniques. * */ public void set(String shell) { setShell(shell); } public void setShell(String shell) { this.shell = shell; } public String getShell() { return shell; } public void setExec(List exec) { this.exec = exec; } /** * @see Arguments#execInlined */ @SuppressWarnings("unused") public void setArg(String arg) { this.execInlined.add(arg); } public List getExec() { return exec == null ? execInlined : exec; } public void validate() throws IllegalArgumentException { int valueSources = 0; if (shell != null) { valueSources ++; } if (exec != null && !exec.isEmpty()) { valueSources ++; } if (!execInlined.isEmpty()) { valueSources ++; } if (valueSources != 1){ throw new IllegalArgumentException("Argument conflict: either shell or args should be specified and only in one form."); } } public List asStrings() { if (shell != null) { return Arrays.asList(EnvUtil.splitOnSpaceWithEscape(shell)); } if (exec != null) { return Collections.unmodifiableList(exec); } return Collections.unmodifiableList(execInlined); } public static class Builder { private String shell; private List params; public static Builder get(){ return new Builder(); } public Builder withShell(String shell){ this.shell = shell; return this; } public Builder withParam(String param){ if (params == null) { params = new ArrayList<>(); } this.params.add(param); return this; } public Arguments build(){ Arguments a = new Arguments(); a.setShell(shell); a.setExec(params); return a; } } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy