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

org.kuali.common.util.maven.model.Artifact Maven / Gradle / Ivy

There is a newer version: 4.4.17
Show newest version
/**
 * Copyright 2010-2014 The Kuali Foundation
 *
 * Licensed under the Educational Community License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.opensource.org/licenses/ecl2.php
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.kuali.common.util.maven.model;

import static com.google.common.base.Optional.absent;
import static com.google.common.base.Optional.fromNullable;
import static org.kuali.common.util.base.Precondition.checkNotBlank;
import static org.kuali.common.util.nullify.NullUtils.trimToNull;

import com.google.common.base.Optional;

/**
 * Simple pojo uniquely identifying a physical software artifact. Strongly modeled after Maven's Artifact object
 */
public final class Artifact {

	private final String groupId;
	private final String artifactId;
	private final String version;
	private final Optional classifier;
	private final String type;

	public String getGroupId() {
		return groupId;
	}

	public String getArtifactId() {
		return artifactId;
	}

	public String getVersion() {
		return version;
	}

	public Optional getClassifier() {
		return classifier;
	}

	public String getType() {
		return type;
	}

	public static Builder builder(String groupId, String artifactId, String version) {
		return new Builder(groupId, artifactId, version);
	}

	public static class Builder {

		public static final String DEFAULT_TYPE = "jar";

		// Required
		private final String groupId;
		private final String artifactId;
		private final String version;

		// Optional
		private Optional classifier = absent();
		private String type = DEFAULT_TYPE;

		public Builder(String groupId, String artifactId, String version) {
			this.groupId = groupId;
			this.artifactId = artifactId;
			this.version = version;
		}

		public Builder classifier(String classifier) {
			return withClassifier(fromNullable(trimToNull(classifier)));
		}

		public Builder withClassifier(Optional classifier) {
			this.classifier = classifier;
			return this;
		}

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

		public Artifact build() {
			return validate(new Artifact(this));
		}

		private static Artifact validate(Artifact instance) {
			checkNotBlank(instance.groupId, "groupId");
			checkNotBlank(instance.artifactId, "artifactId");
			checkNotBlank(instance.type, "type");
			checkNotBlank(instance.classifier, "classifier");
			return instance;
		}

	}

	private Artifact(Builder builder) {
		this.groupId = builder.groupId;
		this.artifactId = builder.artifactId;
		this.version = builder.version;
		this.classifier = builder.classifier;
		this.type = builder.type;
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy