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   */
25  public class DefaultArtifactHandler implements ArtifactHandler {
26      private final String type;
27  
28      private String extension;
29  
30      private String classifier;
31  
32      private String directory;
33  
34      private String packaging;
35  
36      private boolean includesDependencies;
37  
38      private String language;
39  
40      @Deprecated
41      private boolean addedToClasspath;
42  
43      /**
44       * Default ctor for Plexus compatibility, as many plugins have artifact handlers declared in legacy Plexus XML.
45       * Do not use directly!
46       *
47       * @deprecated This ctor is present only for Plexus XML defined component compatibility, do not use it.
48       */
49      @Deprecated
50      public DefaultArtifactHandler() {
51          this.type = null;
52      }
53  
54      public DefaultArtifactHandler(final String type) {
55          this(type, null, null, null, null, false, null, false);
56      }
57  
58      @SuppressWarnings("checkstyle:ParameterNumber")
59      public DefaultArtifactHandler(
60              final String type,
61              final String extension,
62              final String classifier,
63              final String directory,
64              final String packaging,
65              final boolean includesDependencies,
66              final String language,
67              final boolean addedToClasspath) {
68          this.type = requireNonNull(type);
69          this.extension = extension;
70          this.classifier = classifier;
71          this.directory = directory;
72          this.packaging = packaging;
73          this.includesDependencies = includesDependencies;
74          this.language = language;
75          this.addedToClasspath = addedToClasspath;
76      }
77  
78      public String getType() {
79          return type;
80      }
81  
82      @Override
83      public String getExtension() {
84          if (extension == null) {
85              return type;
86          }
87          return extension;
88      }
89  
90      public void setExtension(final String extension) {
91          this.extension = extension;
92      }
93  
94      @Override
95      public String getClassifier() {
96          return classifier;
97      }
98  
99      public void setClassifier(final String classifier) {
100         this.classifier = classifier;
101     }
102 
103     @Override
104     public String getDirectory() {
105         if (directory == null) {
106             return getPackaging() + "s";
107         }
108         return directory;
109     }
110 
111     public void setDirectory(final String directory) {
112         this.directory = directory;
113     }
114 
115     @Override
116     public String getPackaging() {
117         if (packaging == null) {
118             return type;
119         }
120         return packaging;
121     }
122 
123     public void setPackaging(final String packaging) {
124         this.packaging = packaging;
125     }
126 
127     @Override
128     public boolean isIncludesDependencies() {
129         return includesDependencies;
130     }
131 
132     public void setIncludesDependencies(final boolean includesDependencies) {
133         this.includesDependencies = includesDependencies;
134     }
135 
136     @Override
137     public String getLanguage() {
138         if (language == null) {
139             return "none";
140         }
141 
142         return language;
143     }
144 
145     public void setLanguage(final String language) {
146         this.language = language;
147     }
148 
149     @Override
150     @Deprecated
151     public boolean isAddedToClasspath() {
152         return addedToClasspath;
153     }
154 
155     @Deprecated
156     public void setAddedToClasspath(final boolean addedToClasspath) {
157         this.addedToClasspath = addedToClasspath;
158     }
159 }