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.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   * Default implementation of {@link Type} and Resolver {@link ArtifactType}.
40   *
41   * @since 4.0.0
42   * @deprecated since 4.0.0, use {@code maven-api-impl} jar instead
43   */
44  @Deprecated(since = "4.0.0")
45  public class DefaultType implements Type, ArtifactType {
46      private final String id;
47      private final Language language;
48      private final String extension;
49      private final String classifier;
50      private final boolean includesDependencies;
51      private final Set<PathType> pathTypes;
52      private final Map<String, String> properties;
53  
54      public DefaultType(
55              String id,
56              Language language,
57              String extension,
58              String classifier,
59              boolean includesDependencies,
60              PathType... pathTypes) {
61          this.id = requireNonNull(id, "id");
62          this.language = requireNonNull(language, "language");
63          this.extension = requireNonNull(extension, "extension");
64          this.classifier = classifier;
65          this.includesDependencies = includesDependencies;
66          this.pathTypes = Collections.unmodifiableSet(new HashSet<>(Arrays.asList(pathTypes)));
67  
68          Map<String, String> properties = new HashMap<>();
69          properties.put(ArtifactProperties.TYPE, id);
70          properties.put(ArtifactProperties.LANGUAGE, language.id());
71          properties.put(MavenArtifactProperties.INCLUDES_DEPENDENCIES, Boolean.toString(includesDependencies));
72          properties.put(
73                  MavenArtifactProperties.CONSTITUTES_BUILD_PATH,
74                  String.valueOf(this.pathTypes.contains(JavaPathType.CLASSES)));
75          this.properties = Collections.unmodifiableMap(properties);
76      }
77  
78      @Override
79      public String id() {
80          return id;
81      }
82  
83      @Override
84      public String getId() {
85          return id();
86      }
87  
88      @Override
89      public Language getLanguage() {
90          return language;
91      }
92  
93      @Override
94      public String getExtension() {
95          return extension;
96      }
97  
98      @Override
99      public String getClassifier() {
100         return classifier;
101     }
102 
103     @Override
104     public boolean isIncludesDependencies() {
105         return this.includesDependencies;
106     }
107 
108     @Override
109     public Set<PathType> getPathTypes() {
110         return this.pathTypes;
111     }
112 
113     @Override
114     public Map<String, String> getProperties() {
115         return properties;
116     }
117 }