View Javadoc

1   /*
2    * Copyright (c) 2007 Creative Sphere Limited.
3    * All rights reserved. This program and the accompanying materials
4    * are made available under the terms of the Eclipse Public License v1.0
5    * which accompanies this distribution, and is available at
6    * http://www.eclipse.org/legal/epl-v10.html
7    *
8    * Contributors:
9    *
10   *   Creative Sphere - initial API and implementation
11   *
12   */
13  package org.abstracthorizon.extend.repository.maven.pom;
14  
15  import org.abstracthorizon.extend.server.deployment.ModuleId;
16  
17  public class Artifact extends ModuleId {
18  
19      public Artifact() {
20      }
21      
22      public Artifact(ModuleId copy) {
23          super(copy);
24      }
25      
26      public Artifact(Artifact copy) {
27          super(copy);
28      }
29      
30      public String toString(int indent) {
31          StringBuffer res = new StringBuffer();
32          if (groupId != null) {
33              ToStringHelper.valueTag("groupId", groupId, res, indent);
34          }
35          if (artifactId != null) {
36              ToStringHelper.valueTag("artifactId", artifactId, res, indent);
37          }
38          if (version != null) {
39              ToStringHelper.valueTag("version", version, res, indent);
40          }
41          if (type != null) {
42              ToStringHelper.valueTag("type", type, res, indent);
43          }
44          if (classifier != null) {
45              ToStringHelper.valueTag("classifier", classifier, res, indent);
46          }
47          return res.toString();
48      }
49  //
50  //    public String toString() {
51  //        return toString(0);
52  //    }
53  
54      public Artifact toPOMArtifact() {
55          if ("pom".equals(type)) {
56              return this;
57          } else {
58              Artifact pomArtifact = new Artifact(this);
59              pomArtifact.setType("pom");
60              pomArtifact.classifier = null;
61              return pomArtifact;
62          }
63      }
64  
65      public Artifact toSnapshotArtifact() {
66          if (version.toUpperCase().endsWith("-SNAPSHOT")) {
67              return this;
68          } else {
69              Artifact snapshot = new Artifact(this);
70              snapshot.setVersion(version + "-SNAPSHOT");
71              return snapshot;
72          }
73      }
74  
75      public Artifact toNonSnapshotArtifact() {
76          if (!version.toUpperCase().endsWith("-SNAPSHOT")) {
77              return this;
78          } else {
79              Artifact notSnapshot = new Artifact(this);
80              notSnapshot.setVersion(version.substring(0, version.length() - 9));
81              return notSnapshot;
82          }
83      }
84  
85  }