View Javadoc
1   package org.codehaus.mojo.webstart.dependency.filenaming;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with work for additional information
7    * regarding copyright ownership.  The ASF licenses file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import org.apache.commons.lang.StringUtils;
23  import org.apache.maven.artifact.Artifact;
24  import org.codehaus.plexus.component.annotations.Component;
25  
26  /**
27   * Provide a simple dependency file naming strategy.
28   * <p/>
29   * The syntax of this naming strategy:
30   * <pre>artifactId[-classifier][(__V|.)version].extension</pre>
31   * <p/>
32   * <strong>Note: </strong> be ware, this naming strategy can cause name colision if
33   * artifactId is shared by artifacts with different groupId...).
34   *
35   * Created on 1/6/14.
36   *
37   * @author Tony Chemit <chemit@codelutin.com>
38   * @since 1.0-beta-5
39   */
40  @Component( role = DependencyFilenameStrategy.class, hint = SimpleDependencyFilenameStrategy.ROLE_HINT )
41  public class SimpleDependencyFilenameStrategy
42      extends AbstractDependencyFilenameStrategy
43      implements DependencyFilenameStrategy
44  {
45  
46      public static final String ROLE_HINT = "simple";
47  
48      /**
49       * {@inheritDoc}
50       */
51      public String getDependencyFileBasename( Artifact artifact, Boolean outputJarVersion, Boolean useUniqueVersions )
52      {
53          String filename = artifact.getArtifactId();
54  
55          if ( outputJarVersion != null )
56          {
57  
58              if ( outputJarVersion )
59              {
60                  filename += "__V";
61              }
62              else
63              {
64                  filename += "-";
65              }
66              
67              if ( useUniqueVersions != null && useUniqueVersions ) 
68              {
69              	filename += artifact.getBaseVersion();
70              }
71              else 
72              {
73              	filename += artifact.getVersion();
74              }
75          }
76  
77          if ( StringUtils.isNotEmpty( artifact.getClassifier() ) )
78          {
79              filename += "-" + artifact.getClassifier();
80          }
81  
82          return filename;
83      }
84  }