001/**
002 * Copyright 2010-2014 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package org.kuali.common.util.maven.model;
017
018import static com.google.common.base.Optional.absent;
019import static com.google.common.base.Optional.fromNullable;
020import static org.kuali.common.util.base.Precondition.checkNotBlank;
021import static org.kuali.common.util.nullify.NullUtils.trimToNull;
022
023import com.google.common.base.Optional;
024
025/**
026 * Simple pojo uniquely identifying a physical software artifact. Strongly modeled after Maven's Artifact object
027 */
028public final class Artifact {
029
030        private final String groupId;
031        private final String artifactId;
032        private final String version;
033        private final Optional<String> classifier;
034        private final String type;
035
036        public String getGroupId() {
037                return groupId;
038        }
039
040        public String getArtifactId() {
041                return artifactId;
042        }
043
044        public String getVersion() {
045                return version;
046        }
047
048        public Optional<String> getClassifier() {
049                return classifier;
050        }
051
052        public String getType() {
053                return type;
054        }
055
056        public static Builder builder(String groupId, String artifactId, String version) {
057                return new Builder(groupId, artifactId, version);
058        }
059
060        public static class Builder {
061
062                public static final String DEFAULT_TYPE = "jar";
063
064                // Required
065                private final String groupId;
066                private final String artifactId;
067                private final String version;
068
069                // Optional
070                private Optional<String> classifier = absent();
071                private String type = DEFAULT_TYPE;
072
073                public Builder(String groupId, String artifactId, String version) {
074                        this.groupId = groupId;
075                        this.artifactId = artifactId;
076                        this.version = version;
077                }
078
079                public Builder classifier(String classifier) {
080                        return withClassifier(fromNullable(trimToNull(classifier)));
081                }
082
083                public Builder withClassifier(Optional<String> classifier) {
084                        this.classifier = classifier;
085                        return this;
086                }
087
088                public Builder type(String type) {
089                        this.type = type;
090                        return this;
091                }
092
093                public Artifact build() {
094                        return validate(new Artifact(this));
095                }
096
097                private static Artifact validate(Artifact instance) {
098                        checkNotBlank(instance.groupId, "groupId");
099                        checkNotBlank(instance.artifactId, "artifactId");
100                        checkNotBlank(instance.type, "type");
101                        checkNotBlank(instance.classifier, "classifier");
102                        return instance;
103                }
104
105        }
106
107        private Artifact(Builder builder) {
108                this.groupId = builder.groupId;
109                this.artifactId = builder.artifactId;
110                this.version = builder.version;
111                this.classifier = builder.classifier;
112                this.type = builder.type;
113        }
114
115}