]> git.argeo.org Git - gpl/argeo-slc.git/blob - org.argeo.slc.repo/src/org/eclipse/aether/artifact/DefaultArtifactType.java
Fix Makefile clean target
[gpl/argeo-slc.git] / org.argeo.slc.repo / src / org / eclipse / aether / artifact / DefaultArtifactType.java
1 /*******************************************************************************
2 * Copyright (c) 2010, 2013 Sonatype, Inc.
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 * Sonatype, Inc. - initial API and implementation
10 *******************************************************************************/
11 package org.eclipse.aether.artifact;
12
13 import java.util.Collections;
14 import java.util.HashMap;
15 import java.util.Map;
16
17 /**
18 * A simple artifact type.
19 */
20 public final class DefaultArtifactType
21 implements ArtifactType
22 {
23
24 private final String id;
25
26 private final String extension;
27
28 private final String classifier;
29
30 private final Map<String, String> properties;
31
32 /**
33 * Creates a new artifact type with the specified identifier. This constructor assumes the usual file extension
34 * equals the given type id and that the usual classifier is empty. Additionally, the properties
35 * {@link ArtifactProperties#LANGUAGE}, {@link ArtifactProperties#CONSTITUTES_BUILD_PATH} and
36 * {@link ArtifactProperties#INCLUDES_DEPENDENCIES} will be set to {@code "none"}, {@code true} and {@code false},
37 * respectively.
38 *
39 * @param id The identifier of the type which will also be used as the value for the {@link ArtifactProperties#TYPE}
40 * property, must not be {@code null} or empty.
41 */
42 public DefaultArtifactType( String id )
43 {
44 this( id, id, "", "none", false, false );
45 }
46
47 /**
48 * Creates a new artifact type with the specified properties. Additionally, the properties
49 * {@link ArtifactProperties#CONSTITUTES_BUILD_PATH} and {@link ArtifactProperties#INCLUDES_DEPENDENCIES} will be
50 * set to {@code true} and {@code false}, respectively.
51 *
52 * @param id The identifier of the type which will also be used as the value for the {@link ArtifactProperties#TYPE}
53 * property, must not be {@code null} or empty.
54 * @param extension The usual file extension for artifacts of this type, may be {@code null}.
55 * @param classifier The usual classifier for artifacts of this type, may be {@code null}.
56 * @param language The value for the {@link ArtifactProperties#LANGUAGE} property, may be {@code null}.
57 */
58 public DefaultArtifactType( String id, String extension, String classifier, String language )
59 {
60 this( id, extension, classifier, language, true, false );
61 }
62
63 /**
64 * Creates a new artifact type with the specified properties.
65 *
66 * @param id The identifier of the type which will also be used as the value for the {@link ArtifactProperties#TYPE}
67 * property, must not be {@code null} or empty.
68 * @param extension The usual file extension for artifacts of this type, may be {@code null}.
69 * @param classifier The usual classifier for artifacts of this type, may be {@code null}.
70 * @param language The value for the {@link ArtifactProperties#LANGUAGE} property, may be {@code null}.
71 * @param constitutesBuildPath The value for the {@link ArtifactProperties#CONSTITUTES_BUILD_PATH} property.
72 * @param includesDependencies The value for the {@link ArtifactProperties#INCLUDES_DEPENDENCIES} property.
73 */
74 public DefaultArtifactType( String id, String extension, String classifier, String language,
75 boolean constitutesBuildPath, boolean includesDependencies )
76 {
77 if ( id == null || id.length() < 0 )
78 {
79 throw new IllegalArgumentException( "no type id specified" );
80 }
81 this.id = id;
82 this.extension = emptify( extension );
83 this.classifier = emptify( classifier );
84 Map<String, String> props = new HashMap<String, String>();
85 props.put( ArtifactProperties.TYPE, id );
86 props.put( ArtifactProperties.LANGUAGE, ( language != null && language.length() > 0 ) ? language : "none" );
87 props.put( ArtifactProperties.INCLUDES_DEPENDENCIES, Boolean.toString( includesDependencies ) );
88 props.put( ArtifactProperties.CONSTITUTES_BUILD_PATH, Boolean.toString( constitutesBuildPath ) );
89 properties = Collections.unmodifiableMap( props );
90 }
91
92 /**
93 * Creates a new artifact type with the specified properties.
94 *
95 * @param id The identifier of the type, must not be {@code null} or empty.
96 * @param extension The usual file extension for artifacts of this type, may be {@code null}.
97 * @param classifier The usual classifier for artifacts of this type, may be {@code null}.
98 * @param properties The properties for artifacts of this type, may be {@code null}.
99 */
100 public DefaultArtifactType( String id, String extension, String classifier, Map<String, String> properties )
101 {
102 if ( id == null || id.length() < 0 )
103 {
104 throw new IllegalArgumentException( "no type id specified" );
105 }
106 this.id = id;
107 this.extension = emptify( extension );
108 this.classifier = emptify( classifier );
109 this.properties = AbstractArtifact.copyProperties( properties );
110 }
111
112 private static String emptify( String str )
113 {
114 return ( str == null ) ? "" : str;
115 }
116
117 public String getId()
118 {
119 return id;
120 }
121
122 public String getExtension()
123 {
124 return extension;
125 }
126
127 public String getClassifier()
128 {
129 return classifier;
130 }
131
132 public Map<String, String> getProperties()
133 {
134 return properties;
135 }
136
137 }