Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
UnpackFileMarkerHandler |
|
| 1.8;1.8 |
1 | package org.apache.maven.plugin.dependency.utils.markers; | |
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 this work for additional information | |
7 | * regarding copyright ownership. The ASF licenses this file | |
8 | * to you under the Apache License, Version 2.0 (the | |
9 | * "License"); you may not use this 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 java.io.File; | |
23 | ||
24 | import org.apache.maven.plugin.dependency.fromConfiguration.ArtifactItem; | |
25 | import org.codehaus.plexus.util.StringUtils; | |
26 | ||
27 | /** | |
28 | * @author <a href="mailto:dbradicich@comcast.net">Damian Bradicich</a> | |
29 | * @version $Id: UnpackFileMarkerHandler.java 728546 2008-12-21 22:56:51Z bentmann $ | |
30 | */ | |
31 | public class UnpackFileMarkerHandler extends DefaultFileMarkerHandler | |
32 | { | |
33 | protected ArtifactItem artifactItem; | |
34 | ||
35 | public UnpackFileMarkerHandler( File markerFilesDirectory ) | |
36 | { | |
37 | 97 | super( markerFilesDirectory ); |
38 | 97 | } |
39 | ||
40 | public UnpackFileMarkerHandler( ArtifactItem artifactItem, File markerFilesDirectory ) | |
41 | { | |
42 | 97 | this( markerFilesDirectory ); |
43 | 97 | setArtifactItem( artifactItem ); |
44 | 97 | } |
45 | ||
46 | protected File getMarkerFile() | |
47 | { | |
48 | /** | |
49 | * Build a hash of all include/exclude strings, to determine | |
50 | * if an artifactItem has been unpacked using the include/exclude | |
51 | * parameters, this will allow an artifact to be included multiple | |
52 | * times with different include/exclude parameters | |
53 | */ | |
54 | 137 | File markerFile = null; |
55 | 137 | if ( this.artifactItem == null |
56 | || ( StringUtils.isEmpty( this.artifactItem.getIncludes() ) | |
57 | && StringUtils.isEmpty( this.artifactItem.getExcludes() ) ) ) | |
58 | { | |
59 | 92 | markerFile = super.getMarkerFile(); |
60 | } | |
61 | else | |
62 | { | |
63 | 45 | int includeExcludeHash = 0; |
64 | ||
65 | 45 | if ( StringUtils.isNotEmpty( this.artifactItem.getIncludes() ) ) |
66 | { | |
67 | 33 | includeExcludeHash += this.artifactItem.getIncludes().hashCode(); |
68 | } | |
69 | ||
70 | 45 | if ( StringUtils.isNotEmpty( this.artifactItem.getExcludes() ) ) |
71 | { | |
72 | 19 | includeExcludeHash += this.artifactItem.getExcludes().hashCode(); |
73 | } | |
74 | ||
75 | 45 | markerFile = new File( this.markerFilesDirectory, this.artifact.getId().replace( ':', '-' ) + includeExcludeHash ); |
76 | } | |
77 | ||
78 | 137 | return markerFile; |
79 | } | |
80 | ||
81 | public void setArtifactItem( ArtifactItem artifactItem ) | |
82 | { | |
83 | 99 | this.artifactItem = artifactItem; |
84 | ||
85 | 99 | if (this.artifactItem != null) |
86 | { | |
87 | 97 | setArtifact( this.artifactItem.getArtifact() ); |
88 | } | |
89 | 99 | } |
90 | ||
91 | public ArtifactItem getArtifactItem( ) | |
92 | { | |
93 | 2 | return this.artifactItem; |
94 | } | |
95 | } |