View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.maven.internal.impl.resolver.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.internal.impl.resolver.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   * Default implementation of {@link Type} and Resolver {@link ArtifactType}.
40   *
41   * @since 4.0.0
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 }