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