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 org.kuali.common.util.Assert; 019import org.kuali.common.util.nullify.NullUtils; 020 021import com.google.common.base.Optional; 022 023/** 024 * Simple pojo representing a Maven dependency. 025 */ 026public final class Dependency { 027 028 private final String groupId; 029 private final String artifactId; 030 private final String version; 031 private final Optional<String> classifier; 032 // Type is usually the same thing as "packaging" from the Artifact object, but not always. 033 // For example, "test-jar" is physically packaged into a jar file but is labeled in the Maven 034 // dependency list as <type>test-jar</type> 035 private final String type; 036 private final String scope; 037 038 public String getGroupId() { 039 return groupId; 040 } 041 042 public String getArtifactId() { 043 return artifactId; 044 } 045 046 public String getVersion() { 047 return version; 048 } 049 050 public Optional<String> getClassifier() { 051 return classifier; 052 } 053 054 public String getType() { 055 return type; 056 } 057 058 public String getScope() { 059 return scope; 060 } 061 062 public static class Builder { 063 064 public static final String DEFAULT_TYPE = Artifact.Builder.DEFAULT_TYPE; 065 public static final String DEFAULT_SCOPE = "compile"; 066 067 // Required 068 private final String groupId; 069 private final String artifactId; 070 private final String version; 071 072 // Optional 073 private Optional<String> classifier = Optional.absent(); 074 private String type = DEFAULT_TYPE; 075 private String scope = DEFAULT_SCOPE; 076 077 public Builder(String groupId, String artifactId, String version) { 078 this.groupId = groupId; 079 this.artifactId = artifactId; 080 this.version = version; 081 } 082 083 public Builder classifier(String classifier) { 084 this.classifier = Optional.fromNullable(NullUtils.trimToNull(classifier)); 085 return this; 086 } 087 088 public Builder type(String type) { 089 this.type = type; 090 return this; 091 } 092 093 public Builder scope(String scope) { 094 this.scope = scope; 095 return this; 096 } 097 098 public Dependency build() { 099 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}