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.artifact.handler;
20  
21  import static java.util.Objects.requireNonNull;
22  
23  /**
24   * @author <a href="mailto:brett@apache.org">Brett Porter</a>
25   * @author Jason van Zyl
26   *
27   * @since 3.10.0
28   */
29  public final class ArtifactHandlerImpl implements ArtifactHandler {
30      public static final String LANGUAGE_NONE = "none";
31      public static final String LANGUAGE_JAVA = "java";
32  
33      private final String type;
34      private final String extension;
35      private final String classifier;
36      private final String packaging;
37      private final boolean includesDependencies;
38      private final String language;
39      private final boolean addedToClasspath;
40  
41      public ArtifactHandlerImpl(
42              String type,
43              String extension,
44              String classifier,
45              String packaging,
46              boolean includesDependencies,
47              String language,
48              boolean addedToClasspath) {
49          this.type = requireNonNull(type);
50          this.extension = extension;
51          this.classifier = classifier;
52          this.packaging = packaging;
53          this.includesDependencies = includesDependencies;
54          this.language = language;
55          this.addedToClasspath = addedToClasspath;
56      }
57  
58      public String getType() {
59          return type;
60      }
61  
62      @Override
63      public String getExtension() {
64          if (extension == null) {
65              return getType();
66          }
67          return extension;
68      }
69  
70      @Override
71      public String getClassifier() {
72          return classifier;
73      }
74  
75      @Deprecated
76      @Override
77      public String getDirectory() {
78          return getPackaging() + "s";
79      }
80  
81      @Override
82      public String getPackaging() {
83          if (packaging == null) {
84              return getType();
85          }
86          return packaging;
87      }
88  
89      @Override
90      public boolean isIncludesDependencies() {
91          return includesDependencies;
92      }
93  
94      @Override
95      public String getLanguage() {
96          if (language == null) {
97              return LANGUAGE_NONE;
98          }
99          return language;
100     }
101 
102     @Override
103     public boolean isAddedToClasspath() {
104         return addedToClasspath;
105     }
106 }