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