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.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   * Default implementation of {@link Type} and Resolver {@link ArtifactType}.
36   *
37   * @since 4.0.0
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 }