public Artifact setProperties( Map<String, String> properties ) { if ( this.properties.equals( properties ) || ( properties == null && this.properties.isEmpty() ) ) { return this; } return new DefaultArtifact( groupId, artifactId, classifier, extension, version, file, copy( properties ) ); }
/** * Creates a new artifact with the specified coordinates and properties. If not specified in the artifact * coordinates, the artifact's extension defaults to {@code jar} and classifier to an empty string. * * @param coords The artifact coordinates in the format * {@code <groupId>:<artifactId>[:<extension>[:<classifier>]]:<version>}, must not be {@code null}. * @param properties The artifact properties, may be {@code null}. */ public DefaultArtifact( String coords, Map<String, String> properties ) { Pattern p = Pattern.compile( "([^: ]+):([^: ]+)(:([^: ]*)(:([^: ]+))?)?:([^: ]+)" ); Matcher m = p.matcher( coords ); if ( !m.matches() ) { throw new IllegalArgumentException( "Bad artifact coordinates " + coords + ", expected format is <groupId>:<artifactId>[:<extension>[:<classifier>]]:<version>" ); } groupId = m.group( 1 ); artifactId = m.group( 2 ); extension = get( m.group( 4 ), "jar" ); classifier = get( m.group( 6 ), "" ); version = m.group( 7 ); file = null; this.properties = copy( properties ); }
/** * Creates a new artifact with the specified coordinates, properties and file. Passing {@code null} for any of the * coordinates is equivalent to specifying an empty string. * * @param groupId The group identifier of the artifact, may be {@code null}. * @param artifactId The artifact identifier of the artifact, may be {@code null}. * @param classifier The classifier of the artifact, may be {@code null}. * @param extension The file extension of the artifact, may be {@code null}. * @param version The version of the artifact, may be {@code null}. * @param properties The properties of the artifact, may be {@code null} if none. * @param file The resolved file of the artifact, may be {@code null}. */ public DefaultArtifact( String groupId, String artifactId, String classifier, String extension, String version, Map<String, String> properties, File file ) { this.groupId = emptify( groupId ); this.artifactId = emptify( artifactId ); this.classifier = emptify( classifier ); this.extension = emptify( extension ); this.version = emptify( version ); this.file = file; this.properties = copy( properties ); }