1 | |
package org.apache.maven.plugin.dependency.utils.filters; |
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | |
import java.util.HashSet; |
23 | |
import java.util.Set; |
24 | |
|
25 | |
import org.apache.maven.artifact.Artifact; |
26 | |
import org.apache.maven.plugin.MojoExecutionException; |
27 | |
import org.apache.maven.plugin.dependency.fromConfiguration.ArtifactItem; |
28 | |
import org.apache.maven.plugin.dependency.utils.markers.MarkerHandler; |
29 | |
import org.apache.maven.shared.artifact.filter.collection.AbstractArtifactsFilter; |
30 | |
import org.apache.maven.shared.artifact.filter.collection.ArtifactFilterException; |
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
public class MarkerFileFilter |
37 | |
extends AbstractArtifactsFilter |
38 | |
implements ArtifactItemFilter |
39 | |
{ |
40 | |
|
41 | |
private boolean overWriteReleases; |
42 | |
|
43 | |
private boolean overWriteSnapshots; |
44 | |
|
45 | |
private boolean overWriteIfNewer; |
46 | |
|
47 | |
protected final MarkerHandler handler; |
48 | |
|
49 | |
public MarkerFileFilter( boolean overWriteReleases, boolean overWriteSnapshots, boolean overWriteIfNewer, |
50 | |
MarkerHandler handler ) |
51 | 190 | { |
52 | 190 | this.overWriteReleases = overWriteReleases; |
53 | 190 | this.overWriteSnapshots = overWriteSnapshots; |
54 | 190 | this.overWriteIfNewer = overWriteIfNewer; |
55 | 190 | this.handler = handler; |
56 | 190 | } |
57 | |
|
58 | |
|
59 | |
|
60 | |
|
61 | |
|
62 | |
|
63 | |
|
64 | |
public Set filter( Set artifacts ) |
65 | |
throws ArtifactFilterException |
66 | |
{ |
67 | 122 | Set<Artifact> artifacts_ = artifacts; |
68 | 122 | Set<Artifact> result = new HashSet<Artifact>(); |
69 | |
|
70 | 122 | for ( Artifact artifact : artifacts_ ) |
71 | |
{ |
72 | 392 | if ( isArtifactIncluded( new ArtifactItem( artifact ) ) ) |
73 | |
{ |
74 | 376 | result.add( artifact ); |
75 | |
} |
76 | |
} |
77 | 122 | return result; |
78 | |
} |
79 | |
|
80 | |
public boolean isArtifactIncluded( ArtifactItem item ) |
81 | |
throws ArtifactFilterException |
82 | |
{ |
83 | 448 | Artifact artifact = item.getArtifact(); |
84 | |
|
85 | 448 | boolean overWrite = ( artifact.isSnapshot() && this.overWriteSnapshots ) |
86 | |
|| ( !artifact.isSnapshot() && this.overWriteReleases ); |
87 | |
|
88 | 448 | handler.setArtifact( artifact ); |
89 | |
|
90 | |
try |
91 | |
{ |
92 | 448 | return overWrite || !handler.isMarkerSet() || ( overWriteIfNewer && handler.isMarkerOlder( artifact ) ); |
93 | |
} |
94 | 0 | catch ( MojoExecutionException e ) |
95 | |
{ |
96 | 0 | throw new ArtifactFilterException( e.getMessage(), e ); |
97 | |
} |
98 | |
} |
99 | |
|
100 | |
|
101 | |
|
102 | |
|
103 | |
public boolean isOverWriteReleases() |
104 | |
{ |
105 | 4 | return this.overWriteReleases; |
106 | |
} |
107 | |
|
108 | |
|
109 | |
|
110 | |
|
111 | |
|
112 | |
public void setOverWriteReleases( boolean overWriteReleases ) |
113 | |
{ |
114 | 6 | this.overWriteReleases = overWriteReleases; |
115 | 6 | } |
116 | |
|
117 | |
|
118 | |
|
119 | |
|
120 | |
public boolean isOverWriteSnapshots() |
121 | |
{ |
122 | 4 | return this.overWriteSnapshots; |
123 | |
} |
124 | |
|
125 | |
|
126 | |
|
127 | |
|
128 | |
|
129 | |
public void setOverWriteSnapshots( boolean overWriteSnapshots ) |
130 | |
{ |
131 | 6 | this.overWriteSnapshots = overWriteSnapshots; |
132 | 6 | } |
133 | |
|
134 | |
|
135 | |
|
136 | |
|
137 | |
public boolean isOverWriteIfNewer() |
138 | |
{ |
139 | 4 | return this.overWriteIfNewer; |
140 | |
} |
141 | |
|
142 | |
|
143 | |
|
144 | |
|
145 | |
|
146 | |
public void setOverWriteIfNewer( boolean overWriteIfNewer ) |
147 | |
{ |
148 | 2 | this.overWriteIfNewer = overWriteIfNewer; |
149 | 2 | } |
150 | |
} |