View Javadoc
1   package org.argeo.slc.repo;
2   
3   import org.argeo.slc.CategorizedNameVersion;
4   import org.argeo.slc.build.Distribution;
5   import org.eclipse.aether.artifact.Artifact;
6   import org.eclipse.aether.artifact.DefaultArtifact;
7   
8   /** A {@link Distribution} based on an Aether {@link Artifact} */
9   public class ArtifactDistribution implements Distribution,
10  		CategorizedNameVersion {
11  	private final Artifact artifact;
12  
13  	public ArtifactDistribution(Artifact artifact) {
14  		this.artifact = artifact;
15  	}
16  
17  	public ArtifactDistribution(String coords) {
18  		this(new DefaultArtifact(coords));
19  	}
20  
21  	/** Aether coordinates of the underlying artifact. */
22  	public String getDistributionId() {
23  		return artifact.toString();
24  	}
25  
26  	public Artifact getArtifact() {
27  		return artifact;
28  	}
29  
30  	public String getName() {
31  		return getArtifact().getArtifactId();
32  	}
33  
34  	public String getVersion() {
35  		return getArtifact().getVersion();
36  	}
37  
38  	public String getCategory() {
39  		return getArtifact().getGroupId();
40  	}
41  
42  	@Override
43  	public int hashCode() {
44  		return artifact.hashCode();
45  	}
46  
47  	@Override
48  	public boolean equals(Object obj) {
49  		if (obj instanceof CategorizedNameVersion) {
50  			CategorizedNameVersion cnv = (CategorizedNameVersion) obj;
51  			return getCategory().equals(cnv.getCategory())
52  					&& getName().equals(cnv.getName())
53  					&& getVersion().equals(cnv.getVersion());
54  		} else
55  			return artifact.equals(obj);
56  	}
57  
58  	@Override
59  	public String toString() {
60  		return getDistributionId();
61  	}
62  
63  }