001/**
002 * Copyright 2010-2013 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 org.kuali.common.util.Assert;
019import org.kuali.common.util.nullify.NullUtils;
020
021import com.google.common.base.Optional;
022
023/**
024 * Simple pojo uniquely identifying a physical software artifact. Strongly modeled after Maven's Artifact object
025 */
026public final class Artifact {
027
028        private final String groupId;
029        private final String artifactId;
030        private final String version;
031        private final Optional<String> classifier;
032        private final String type;
033
034        public String getGroupId() {
035                return groupId;
036        }
037
038        public String getArtifactId() {
039                return artifactId;
040        }
041
042        public String getVersion() {
043                return version;
044        }
045
046        public Optional<String> getClassifier() {
047                return classifier;
048        }
049
050        public String getType() {
051                return type;
052        }
053
054        public static class Builder {
055
056                public static final String DEFAULT_TYPE = "jar";
057
058                // Required
059                private final String groupId;
060                private final String artifactId;
061                private final String version;
062
063                // Optional
064                private Optional<String> classifier = Optional.absent();
065                private String type = DEFAULT_TYPE;
066
067                public Builder(String groupId, String artifactId, String version) {
068                        this.groupId = groupId;
069                        this.artifactId = artifactId;
070                        this.version = version;
071                }
072
073                public Builder classifier(String classifier) {
074                        this.classifier = Optional.fromNullable(NullUtils.trimToNull(classifier));
075                        return this;
076                }
077
078                public Builder type(String type) {
079                        this.type = type;
080                        return this;
081                }
082
083                public Artifact build() {
084                        Assert.noBlanks(groupId, artifactId, version, type);
085                        Assert.noNulls(classifier);
086                        if (classifier.isPresent()) {
087                                Assert.noBlanks(classifier.get());
088                        }
089                        return new Artifact(this);
090                }
091
092        }
093
094        private Artifact(Builder builder) {
095                this.groupId = builder.groupId;
096                this.artifactId = builder.artifactId;
097                this.version = builder.version;
098                this.classifier = builder.classifier;
099                this.type = builder.type;
100        }
101
102}