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