1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.repository.internal.type;
20
21 import java.util.Arrays;
22 import java.util.Collections;
23 import java.util.HashMap;
24 import java.util.HashSet;
25 import java.util.Map;
26 import java.util.Set;
27
28 import org.apache.maven.api.JavaPathType;
29 import org.apache.maven.api.Language;
30 import org.apache.maven.api.PathType;
31 import org.apache.maven.api.Type;
32 import org.apache.maven.repository.internal.artifact.MavenArtifactProperties;
33 import org.eclipse.aether.artifact.ArtifactProperties;
34 import org.eclipse.aether.artifact.ArtifactType;
35
36 import static java.util.Objects.requireNonNull;
37
38
39
40
41
42
43 public class DefaultType implements Type, ArtifactType {
44 private final String id;
45 private final Language language;
46 private final String extension;
47 private final String classifier;
48 private final boolean includesDependencies;
49 private final Set<PathType> pathTypes;
50 private final Map<String, String> properties;
51
52 public DefaultType(
53 String id,
54 Language language,
55 String extension,
56 String classifier,
57 boolean includesDependencies,
58 PathType... pathTypes) {
59 this.id = requireNonNull(id, "id");
60 this.language = requireNonNull(language, "language");
61 this.extension = requireNonNull(extension, "extension");
62 this.classifier = classifier;
63 this.includesDependencies = includesDependencies;
64 this.pathTypes = Collections.unmodifiableSet(new HashSet<>(Arrays.asList(pathTypes)));
65
66 Map<String, String> properties = new HashMap<>();
67 properties.put(ArtifactProperties.TYPE, id);
68 properties.put(ArtifactProperties.LANGUAGE, language.id());
69 properties.put(MavenArtifactProperties.INCLUDES_DEPENDENCIES, Boolean.toString(includesDependencies));
70 properties.put(
71 MavenArtifactProperties.CONSTITUTES_BUILD_PATH,
72 String.valueOf(this.pathTypes.contains(JavaPathType.CLASSES)));
73 this.properties = Collections.unmodifiableMap(properties);
74 }
75
76 @Override
77 public String id() {
78 return id;
79 }
80
81 @Override
82 public String getId() {
83 return id();
84 }
85
86 @Override
87 public Language getLanguage() {
88 return language;
89 }
90
91 @Override
92 public String getExtension() {
93 return extension;
94 }
95
96 @Override
97 public String getClassifier() {
98 return classifier;
99 }
100
101 @Override
102 public boolean isIncludesDependencies() {
103 return this.includesDependencies;
104 }
105
106 public Set<PathType> getPathTypes() {
107 return this.pathTypes;
108 }
109
110 @Override
111 public Map<String, String> getProperties() {
112 return properties;
113 }
114 }