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