Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
AbstractFileNameMapping |
|
| 5.0;5 |
1 | package org.apache.maven.plugin.ear.output; | |
2 | ||
3 | import org.apache.maven.artifact.Artifact; | |
4 | ||
5 | /* | |
6 | * Licensed to the Apache Software Foundation (ASF) under one | |
7 | * or more contributor license agreements. See the NOTICE file | |
8 | * distributed with this work for additional information | |
9 | * regarding copyright ownership. The ASF licenses this file | |
10 | * to you under the Apache License, Version 2.0 (the | |
11 | * "License"); you may not use this file except in compliance | |
12 | * with the License. You may obtain a copy of the License at | |
13 | * | |
14 | * http://www.apache.org/licenses/LICENSE-2.0 | |
15 | * | |
16 | * Unless required by applicable law or agreed to in writing, | |
17 | * software distributed under the License is distributed on an | |
18 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | |
19 | * KIND, either express or implied. See the License for the | |
20 | * specific language governing permissions and limitations | |
21 | * under the License. | |
22 | */ | |
23 | ||
24 | /** | |
25 | * A base class used to generate the standard name of an | |
26 | * artifact instead of relying on the (potentially) wrong | |
27 | * file name provided by {@link org.apache.maven.artifact.Artifact#getFile()}. | |
28 | * | |
29 | * @author <a href="snicoll@apache.org">Stephane Nicoll</a> | |
30 | */ | |
31 | 30 | public abstract class AbstractFileNameMapping |
32 | implements FileNameMapping | |
33 | { | |
34 | ||
35 | ||
36 | /** | |
37 | * Generates a standard file name for the specified {@link Artifact}. | |
38 | * <p/> | |
39 | * Returns something like <tt>artifactId-version[-classifier].extension</tt> | |
40 | * if <tt>addVersion</tt> is true. Otherwise it generates something | |
41 | * like <tt>artifactId[-classifier].extension</tt> | |
42 | * | |
43 | * @param a the artifact to generate a filename from | |
44 | * @param addVersion whether the version should be added | |
45 | * @return the filename, with a standard format | |
46 | */ | |
47 | protected String generateFileName( final Artifact a, boolean addVersion ) | |
48 | { | |
49 | 16 | final String extension = a.getArtifactHandler().getExtension(); |
50 | ||
51 | 16 | final StringBuilder buffer = new StringBuilder( 128 ); |
52 | 16 | buffer.append( a.getArtifactId() ); |
53 | 16 | if ( addVersion ) |
54 | { | |
55 | 10 | buffer.append( '-' ).append( a.getBaseVersion() ); |
56 | } | |
57 | 16 | if ( a.hasClassifier() ) |
58 | { | |
59 | 6 | buffer.append( '-' ).append( a.getClassifier() ); |
60 | } | |
61 | 16 | if ( extension != null && extension.length() > 0 ) |
62 | { | |
63 | 16 | buffer.append( '.' ).append( extension ); |
64 | } | |
65 | ||
66 | 16 | return buffer.toString(); |
67 | } | |
68 | } |