]>
git.argeo.org Git - gpl/argeo-slc.git/blob - org.argeo.slc.repo/src/org/argeo/slc/repo/osgi/SubArtifact.java
1 package org
.argeo
.slc
.repo
.osgi
;
6 import org
.eclipse
.aether
.artifact
.AbstractArtifact
;
7 import org
.eclipse
.aether
.artifact
.Artifact
;
10 * An artifact whose identity is derived from another artifact. <em>Note:</em>
11 * Instances of this class are immutable and the exposed mutators return new
12 * objects rather than changing the current instance.
14 final class SubArtifact
extends AbstractArtifact
{
16 private final Artifact mainArtifact
;
18 private final String classifier
;
20 private final String extension
;
22 private final File file
;
24 private final Map
<String
, String
> properties
;
27 * Creates a new sub artifact. The classifier and extension specified for this
28 * artifact may use the asterisk character "*" to refer to the corresponding
29 * property of the main artifact. For instance, the classifier "*-sources" can
30 * be used to refer to the source attachment of an artifact. Likewise, the
31 * extension "*.asc" can be used to refer to the GPG signature of an artifact.
33 * @param mainArtifact The artifact from which to derive the identity, must not
35 * @param classifier The classifier for this artifact, may be {@code null} if
37 * @param extension The extension for this artifact, may be {@code null} if
40 public SubArtifact(Artifact mainArtifact
, String classifier
, String extension
) {
41 this(mainArtifact
, classifier
, extension
, (File
) null);
45 * Creates a new sub artifact. The classifier and extension specified for this
46 * artifact may use the asterisk character "*" to refer to the corresponding
47 * property of the main artifact. For instance, the classifier "*-sources" can
48 * be used to refer to the source attachment of an artifact. Likewise, the
49 * extension "*.asc" can be used to refer to the GPG signature of an artifact.
51 * @param mainArtifact The artifact from which to derive the identity, must not
53 * @param classifier The classifier for this artifact, may be {@code null} if
55 * @param extension The extension for this artifact, may be {@code null} if
57 * @param file The file for this artifact, may be {@code null} if
60 public SubArtifact(Artifact mainArtifact
, String classifier
, String extension
, File file
) {
61 this(mainArtifact
, classifier
, extension
, null, file
);
65 * Creates a new sub artifact. The classifier and extension specified for this
66 * artifact may use the asterisk character "*" to refer to the corresponding
67 * property of the main artifact. For instance, the classifier "*-sources" can
68 * be used to refer to the source attachment of an artifact. Likewise, the
69 * extension "*.asc" can be used to refer to the GPG signature of an artifact.
71 * @param mainArtifact The artifact from which to derive the identity, must not
73 * @param classifier The classifier for this artifact, may be {@code null} if
75 * @param extension The extension for this artifact, may be {@code null} if
77 * @param properties The properties of the artifact, may be {@code null}.
79 public SubArtifact(Artifact mainArtifact
, String classifier
, String extension
, Map
<String
, String
> properties
) {
80 this(mainArtifact
, classifier
, extension
, properties
, null);
84 * Creates a new sub artifact. The classifier and extension specified for this
85 * artifact may use the asterisk character "*" to refer to the corresponding
86 * property of the main artifact. For instance, the classifier "*-sources" can
87 * be used to refer to the source attachment of an artifact. Likewise, the
88 * extension "*.asc" can be used to refer to the GPG signature of an artifact.
90 * @param mainArtifact The artifact from which to derive the identity, must not
92 * @param classifier The classifier for this artifact, may be {@code null} if
94 * @param extension The extension for this artifact, may be {@code null} if
96 * @param properties The properties of the artifact, may be {@code null}.
97 * @param file The file for this artifact, may be {@code null} if
100 public SubArtifact(Artifact mainArtifact
, String classifier
, String extension
, Map
<String
, String
> properties
,
102 if (mainArtifact
== null) {
103 throw new IllegalArgumentException("no artifact specified");
105 this.mainArtifact
= mainArtifact
;
106 this.classifier
= classifier
;
107 this.extension
= extension
;
109 this.properties
= copyProperties(properties
);
112 private SubArtifact(Artifact mainArtifact
, String classifier
, String extension
, File file
,
113 Map
<String
, String
> properties
) {
114 // NOTE: This constructor assumes immutability of the provided properties, for
116 this.mainArtifact
= mainArtifact
;
117 this.classifier
= classifier
;
118 this.extension
= extension
;
120 this.properties
= properties
;
123 public String
getGroupId() {
124 return mainArtifact
.getGroupId();
127 public String
getArtifactId() {
128 return mainArtifact
.getArtifactId();
131 public String
getVersion() {
132 return mainArtifact
.getVersion();
135 public String
getBaseVersion() {
136 return mainArtifact
.getBaseVersion();
139 public boolean isSnapshot() {
140 return mainArtifact
.isSnapshot();
143 public String
getClassifier() {
144 return expand(classifier
, mainArtifact
.getClassifier());
147 public String
getExtension() {
148 return expand(extension
, mainArtifact
.getExtension());
151 public File
getFile() {
155 public Artifact
setFile(File file
) {
156 if ((this.file
== null) ? file
== null : this.file
.equals(file
)) {
159 return new SubArtifact(mainArtifact
, classifier
, extension
, file
, properties
);
162 public Map
<String
, String
> getProperties() {
166 public Artifact
setProperties(Map
<String
, String
> properties
) {
167 if (this.properties
.equals(properties
) || (properties
== null && this.properties
.isEmpty())) {
170 return new SubArtifact(mainArtifact
, classifier
, extension
, properties
, file
);
173 private static String
expand(String pattern
, String replacement
) {
175 if (pattern
!= null) {
176 result
= pattern
.replace("*", replacement
);
178 if (replacement
.length() <= 0) {
179 if (pattern
.startsWith("*")) {
181 for (; i
< result
.length(); i
++) {
182 char c
= result
.charAt(i
);
183 if (c
!= '-' && c
!= '.') {
187 result
= result
.substring(i
);
189 if (pattern
.endsWith("*")) {
190 int i
= result
.length() - 1;
191 for (; i
>= 0; i
--) {
192 char c
= result
.charAt(i
);
193 if (c
!= '-' && c
!= '.') {
197 result
= result
.substring(0, i
+ 1);