1 package org.apache.maven.plugins.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 org.apache.maven.plugins.dependency.fromConfiguration.ArtifactItem;
23 import org.codehaus.plexus.util.StringUtils;
24
25 import java.io.File;
26
27 /**
28 * @author <a href="mailto:dbradicich@comcast.net">Damian Bradicich</a>
29 */
30 public class UnpackFileMarkerHandler
31 extends DefaultFileMarkerHandler
32 {
33 /**
34 * The ArtifactItem.
35 */
36 protected ArtifactItem artifactItem;
37
38 /**
39 * @param markerFilesDirectory The marker files directory.
40 */
41 public UnpackFileMarkerHandler( File markerFilesDirectory )
42 {
43 super( markerFilesDirectory );
44 }
45
46 /**
47 * @param artifactItem {@link ArtifactItem}
48 * @param markerFilesDirectory the marker files directory.
49 */
50 public UnpackFileMarkerHandler( ArtifactItem artifactItem, File markerFilesDirectory )
51 {
52 this( markerFilesDirectory );
53 setArtifactItem( artifactItem );
54 }
55
56 @Override
57 protected File getMarkerFile()
58 {
59 /**
60 * Build a hash of all include/exclude strings, to determine if an artifactItem has been unpacked using the
61 * include/exclude parameters, this will allow an artifact to be included multiple times with different
62 * include/exclude parameters
63 */
64 File markerFile;
65 if ( this.artifactItem == null || ( StringUtils.isEmpty( this.artifactItem.getIncludes() )
66 && StringUtils.isEmpty( this.artifactItem.getExcludes() ) ) )
67 {
68 markerFile = super.getMarkerFile();
69 }
70 else
71 {
72 int includeExcludeHash = 0;
73
74 if ( StringUtils.isNotEmpty( this.artifactItem.getIncludes() ) )
75 {
76 includeExcludeHash += this.artifactItem.getIncludes().hashCode();
77 }
78
79 if ( StringUtils.isNotEmpty( this.artifactItem.getExcludes() ) )
80 {
81 includeExcludeHash += this.artifactItem.getExcludes().hashCode();
82 }
83
84 markerFile =
85 new File( this.markerFilesDirectory, this.artifact.getId().replace( ':', '-' ) + includeExcludeHash );
86 }
87
88 return markerFile;
89 }
90
91 /**
92 * @param artifactItem {@link #artifactItem}
93 */
94 public void setArtifactItem( ArtifactItem artifactItem )
95 {
96 this.artifactItem = artifactItem;
97
98 if ( this.artifactItem != null )
99 {
100 setArtifact( this.artifactItem.getArtifact() );
101 }
102 }
103
104 /**
105 * @return {@link #artifactItem}
106 */
107 public ArtifactItem getArtifactItem()
108 {
109 return this.artifactItem;
110 }
111 }