]>
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> Instances of this class are immutable and
11 * the exposed mutators return new objects rather than changing the current instance.
13 final class SubArtifact
14 extends AbstractArtifact
17 private final Artifact mainArtifact
;
19 private final String classifier
;
21 private final String extension
;
23 private final File file
;
25 private final Map
<String
, String
> properties
;
28 * Creates a new sub artifact. The classifier and extension specified for this artifact may use the asterisk
29 * character "*" to refer to the corresponding property of the main artifact. For instance, the classifier
30 * "*-sources" can be used to refer to the source attachment of an artifact. Likewise, the extension "*.asc" can be
31 * used to refer to the GPG signature of an artifact.
33 * @param mainArtifact The artifact from which to derive the identity, must not be {@code null}.
34 * @param classifier The classifier for this artifact, may be {@code null} if none.
35 * @param extension The extension for this artifact, may be {@code null} if none.
37 public SubArtifact( Artifact mainArtifact
, String classifier
, String extension
)
39 this( mainArtifact
, classifier
, extension
, (File
) null );
43 * Creates a new sub artifact. The classifier and extension specified for this artifact may use the asterisk
44 * character "*" to refer to the corresponding property of the main artifact. For instance, the classifier
45 * "*-sources" can be used to refer to the source attachment of an artifact. Likewise, the extension "*.asc" can be
46 * used to refer to the GPG signature of an artifact.
48 * @param mainArtifact The artifact from which to derive the identity, must not be {@code null}.
49 * @param classifier The classifier for this artifact, may be {@code null} if none.
50 * @param extension The extension for this artifact, may be {@code null} if none.
51 * @param file The file for this artifact, may be {@code null} if unresolved.
53 public SubArtifact( Artifact mainArtifact
, String classifier
, String extension
, File file
)
55 this( mainArtifact
, classifier
, extension
, null, file
);
59 * Creates a new sub artifact. The classifier and extension specified for this artifact may use the asterisk
60 * character "*" to refer to the corresponding property of the main artifact. For instance, the classifier
61 * "*-sources" can be used to refer to the source attachment of an artifact. Likewise, the extension "*.asc" can be
62 * used to refer to the GPG signature of an artifact.
64 * @param mainArtifact The artifact from which to derive the identity, must not be {@code null}.
65 * @param classifier The classifier for this artifact, may be {@code null} if none.
66 * @param extension The extension for this artifact, may be {@code null} if none.
67 * @param properties The properties of the artifact, may be {@code null}.
69 public SubArtifact( Artifact mainArtifact
, String classifier
, String extension
, Map
<String
, String
> properties
)
71 this( mainArtifact
, classifier
, extension
, properties
, null );
75 * Creates a new sub artifact. The classifier and extension specified for this artifact may use the asterisk
76 * character "*" to refer to the corresponding property of the main artifact. For instance, the classifier
77 * "*-sources" can be used to refer to the source attachment of an artifact. Likewise, the extension "*.asc" can be
78 * used to refer to the GPG signature of an artifact.
80 * @param mainArtifact The artifact from which to derive the identity, must not be {@code null}.
81 * @param classifier The classifier for this artifact, may be {@code null} if none.
82 * @param extension The extension for this artifact, may be {@code null} if none.
83 * @param properties The properties of the artifact, may be {@code null}.
84 * @param file The file for this artifact, may be {@code null} if unresolved.
86 public SubArtifact( Artifact mainArtifact
, String classifier
, String extension
, Map
<String
, String
> properties
,
89 if ( mainArtifact
== null )
91 throw new IllegalArgumentException( "no artifact specified" );
93 this.mainArtifact
= mainArtifact
;
94 this.classifier
= classifier
;
95 this.extension
= extension
;
97 this.properties
= copyProperties( properties
);
100 private SubArtifact( Artifact mainArtifact
, String classifier
, String extension
, File file
,
101 Map
<String
, String
> properties
)
103 // NOTE: This constructor assumes immutability of the provided properties, for internal use only
104 this.mainArtifact
= mainArtifact
;
105 this.classifier
= classifier
;
106 this.extension
= extension
;
108 this.properties
= properties
;
111 public String
getGroupId()
113 return mainArtifact
.getGroupId();
116 public String
getArtifactId()
118 return mainArtifact
.getArtifactId();
121 public String
getVersion()
123 return mainArtifact
.getVersion();
126 public String
getBaseVersion()
128 return mainArtifact
.getBaseVersion();
131 public boolean isSnapshot()
133 return mainArtifact
.isSnapshot();
136 public String
getClassifier()
138 return expand( classifier
, mainArtifact
.getClassifier() );
141 public String
getExtension()
143 return expand( extension
, mainArtifact
.getExtension() );
146 public File
getFile()
151 public Artifact
setFile( File file
)
153 if ( ( this.file
== null ) ? file
== null : this.file
.equals( file
) )
157 return new SubArtifact( mainArtifact
, classifier
, extension
, file
, properties
);
160 public Map
<String
, String
> getProperties()
165 public Artifact
setProperties( Map
<String
, String
> properties
)
167 if ( this.properties
.equals( properties
) || ( properties
== null && this.properties
.isEmpty() ) )
171 return new SubArtifact( mainArtifact
, classifier
, extension
, properties
, file
);
174 private static String
expand( String pattern
, String replacement
)
177 if ( pattern
!= null )
179 result
= pattern
.replace( "*", replacement
);
181 if ( replacement
.length() <= 0 )
183 if ( pattern
.startsWith( "*" ) )
186 for ( ; i
< result
.length(); i
++ )
188 char c
= result
.charAt( i
);
189 if ( c
!= '-' && c
!= '.' )
194 result
= result
.substring( i
);
196 if ( pattern
.endsWith( "*" ) )
198 int i
= result
.length() - 1;
199 for ( ; i
>= 0; i
-- )
201 char c
= result
.charAt( i
);
202 if ( c
!= '-' && c
!= '.' )
207 result
= result
.substring( 0, i
+ 1 );