View Javadoc

1   /**
2    * Copyright (C) 2010-2012 Joerg Bellmann <joerg.bellmann@googlemail.com>
3    *
4    * Licensed under the Apache 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.apache.org/licenses/LICENSE-2.0
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 com.googlecode.t7mp;
17  
18  import java.io.File;
19  
20  import org.apache.commons.lang.StringUtils;
21  
22  /**
23   * TODO Comment.
24   * @author Joerg Bellmann
25   *
26   */
27  public abstract class AbstractArtifact {
28  
29      /**
30       * 
31       * @parameter
32       * @required
33       */
34      protected String groupId;
35  
36      /**
37       * 
38       * @parameter
39       * @required
40       */
41      protected String artifactId;
42  
43      /**
44       * 
45       * @parameter
46       */
47      protected String version;
48  
49      /**
50       * 
51       * @parameter
52       */
53      protected String type;
54  
55      /**
56       * 
57       * @parameter
58       */
59      protected String classifier;
60  
61      /**
62       * 
63       * @parameter
64       */
65      protected String systemPath;
66  
67      protected File file;
68  
69      public AbstractArtifact() {
70          // default constructor
71      }
72  
73      public AbstractArtifact(String groupId, String artifactId, String version, String classifier, String type) {
74          this.setGroupId(groupId);
75          this.setArtifactId(artifactId);
76          this.setVersion(version);
77          this.setClassifier(classifier);
78          this.setType(type);
79  
80      }
81  
82      public String getGroupId() {
83          return groupId;
84      }
85  
86      public void setGroupId(String groupId) {
87          this.groupId = groupId;
88      }
89  
90      public String getArtifactId() {
91          return artifactId;
92      }
93  
94      public void setArtifactId(String artifactId) {
95          this.artifactId = artifactId;
96      }
97  
98      public String getVersion() {
99          return version;
100     }
101 
102     public void setVersion(String version) {
103         this.version = version;
104     }
105 
106     public abstract String getType();
107 
108     public void setType(String type) {
109         this.type = type;
110     }
111 
112     public String getClassifier() {
113         return classifier;
114     }
115 
116     public void setClassifier(String classifier) {
117         this.classifier = classifier;
118     }
119 
120     public String getSystemPath() {
121         return this.systemPath;
122     }
123 
124     public void setSystemPath(String systemPath) {
125         this.systemPath = systemPath;
126     }
127 
128     public File getFile() {
129         return file;
130     }
131 
132     public void setFile(File file) {
133         this.file = file;
134     }
135 
136     public String getArtifactCoordinates() {
137         if (!StringUtils.isBlank(getSystemPath())) {
138             return getSystemPath();
139         } else {
140             return buildDefaultMavenCoordinates();
141         }
142     }
143 
144     /**
145      * The {@code <groupId>:<artifactId>[:<extension>[:<classifier>]]:<version>} of the artifact.
146      * 
147      */
148     protected String buildDefaultMavenCoordinates() {
149         StringBuilder sb = new StringBuilder();
150         sb.append(getGroupId()).append(":");
151         sb.append(getArtifactId());
152         if (StringUtils.isNotBlank(getType())) {
153             sb.append(":").append(getType());
154         }
155         if (StringUtils.isNotBlank(getClassifier())) {
156             sb.append(":").append(getClassifier());
157         }
158         sb.append(":");
159         sb.append(getVersion());
160         return sb.toString().trim();
161     }
162 
163     @Override
164     public String toString() {
165         return "Artifact[" + getArtifactCoordinates() + "]";
166     }
167 
168 }