View Javadoc
1   /**
2    * Copyright 2010-2014 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.common.util.maven.model;
17  
18  import org.kuali.common.util.Assert;
19  import org.kuali.common.util.nullify.NullUtils;
20  
21  import com.google.common.base.Optional;
22  
23  /**
24   * Simple pojo representing a Maven dependency.
25   */
26  public final class Dependency {
27  
28  	private final String groupId;
29  	private final String artifactId;
30  	private final String version;
31  	private final Optional<String> classifier;
32  	// Type is usually the same thing as "packaging" from the Artifact object, but not always.
33  	// For example, "test-jar" is physically packaged into a jar file but is labeled in the Maven
34  	// dependency list as <type>test-jar</type>
35  	private final String type;
36  	private final String scope;
37  
38  	public String getGroupId() {
39  		return groupId;
40  	}
41  
42  	public String getArtifactId() {
43  		return artifactId;
44  	}
45  
46  	public String getVersion() {
47  		return version;
48  	}
49  
50  	public Optional<String> getClassifier() {
51  		return classifier;
52  	}
53  
54  	public String getType() {
55  		return type;
56  	}
57  
58  	public String getScope() {
59  		return scope;
60  	}
61  
62  	public static class Builder {
63  
64  		public static final String DEFAULT_TYPE = Artifact.Builder.DEFAULT_TYPE;
65  		public static final String DEFAULT_SCOPE = "compile";
66  
67  		// Required
68  		private final String groupId;
69  		private final String artifactId;
70  		private final String version;
71  
72  		// Optional
73  		private Optional<String> classifier = Optional.absent();
74  		private String type = DEFAULT_TYPE;
75  		private String scope = DEFAULT_SCOPE;
76  
77  		public Builder(String groupId, String artifactId, String version) {
78  			this.groupId = groupId;
79  			this.artifactId = artifactId;
80  			this.version = version;
81  		}
82  
83  		public Builder classifier(String classifier) {
84  			this.classifier = Optional.fromNullable(NullUtils.trimToNull(classifier));
85  			return this;
86  		}
87  
88  		public Builder type(String type) {
89  			this.type = type;
90  			return this;
91  		}
92  
93  		public Builder scope(String scope) {
94  			this.scope = scope;
95  			return this;
96  		}
97  
98  		public Dependency build() {
99  			Assert.noBlanks(groupId, artifactId, version, type, scope);
100 			Assert.noNulls(classifier);
101 			return new Dependency(this);
102 		}
103 	}
104 
105 	private Dependency(Builder builder) {
106 		this.groupId = builder.groupId;
107 		this.artifactId = builder.artifactId;
108 		this.version = builder.version;
109 		this.classifier = builder.classifier;
110 		this.type = builder.type;
111 		this.scope = builder.scope;
112 	}
113 
114 }