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

org.jfrog.build.api.BuildAgent Maven / Gradle / Ivy

There is a newer version: 2.41.23
Show newest version


package org.jfrog.build.api;

import org.apache.commons.lang3.StringUtils;

import java.io.Serializable;

/**
 * Information about the agent that executed the build (e.g. Maven, Ant/Ivy, Gradle etc.)
 *
 * @author Tomer Cohen
 */
public class BuildAgent implements Serializable {

    private String name;
    private String version;

    /**
     * Default constructor
     */
    public BuildAgent() {
    }

    /**
     * Build the build agent from a full agent name in the following format: AGENT_NAME/AGENT_VERSION
     *
     * @param agent The agent name
     */
    public BuildAgent(String agent) {
        int slash = agent.indexOf('/');
        if (slash != -1 && slash < agent.length() - 1) {
            this.name = agent.substring(0, slash);
            this.version = agent.substring(slash + 1);
        } else {
            this.name = agent;
        }
    }

    /**
     * Main constructor
     *
     * @param name    Agent name
     * @param version Agent version
     */
    public BuildAgent(String name, String version) {
        this.name = name;
        this.version = version;
    }

    /**
     * Returns the name of the agent
     *
     * @return Agent name
     */
    public String getName() {
        return name;
    }

    /**
     * Sets the name of the agent
     *
     * @param name Agent name
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * Returns the version of the agent
     *
     * @return Agent version
     */
    public String getVersion() {
        return version;
    }

    /**
     * Sets the version of the agent
     *
     * @param version Agent version
     */
    public void setVersion(String version) {
        this.version = version;
    }

    /**
     * Returns the display representation of the agent
     *
     * @return AGENT_NAME/AGENT_VERSION
     */
    @Override
    public String toString() {
        StringBuilder toStringBuilder = new StringBuilder();
        if (StringUtils.isNotBlank(name)) {
            toStringBuilder.append(name);
        }
        if (StringUtils.isNotBlank(version)) {
            if (toStringBuilder.length() > 0) {
                toStringBuilder.append("/");
            }
            toStringBuilder.append(version);
        }
        return toStringBuilder.toString();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy