1 package org.apache.maven.plugins.dependency.utils.markers;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.io.File;
23 import java.io.IOException;
24
25 import org.apache.maven.artifact.Artifact;
26 import org.apache.maven.plugin.MojoExecutionException;
27
28
29
30
31 public class SourcesFileMarkerHandler
32 extends DefaultFileMarkerHandler
33 {
34
35 boolean resolved;
36
37
38
39
40 public SourcesFileMarkerHandler( File markerFilesDirectory )
41 {
42 super( markerFilesDirectory );
43 }
44
45
46
47
48
49
50 public SourcesFileMarkerHandler( Artifact artifact, File markerFilesDirectory, boolean isResolved )
51 {
52 super( artifact, markerFilesDirectory );
53 this.resolved = isResolved;
54 }
55
56
57
58
59
60
61 @Override
62 public File getMarkerFile()
63 {
64 return getMarkerFile( this.resolved );
65 }
66
67
68
69
70
71
72
73 protected File getMarkerFile( boolean res )
74 {
75 String suffix;
76 if ( res )
77 {
78 suffix = ".resolved";
79 }
80 else
81 {
82 suffix = ".unresolved";
83 }
84
85 return new File( this.markerFilesDirectory, this.artifact.getId().replace( ':', '-' ) + suffix );
86 }
87
88
89
90
91
92
93
94
95
96
97 @Override
98 public boolean isMarkerSet()
99 throws MojoExecutionException
100 {
101 File marker = getMarkerFile();
102
103 File marker2 = getMarkerFile( !this.resolved );
104
105 return marker.exists() || marker2.exists();
106 }
107
108 @Override
109 public boolean isMarkerOlder( Artifact theArtifact )
110 throws MojoExecutionException
111 {
112 File marker = getMarkerFile();
113 if ( marker.exists() )
114 {
115 return theArtifact.getFile().lastModified() > marker.lastModified();
116 }
117 else
118 {
119 marker = getMarkerFile( !this.resolved );
120 if ( marker.exists() )
121 {
122 return theArtifact.getFile().lastModified() > marker.lastModified();
123 }
124 else
125 {
126
127
128 return true;
129 }
130 }
131 }
132
133 @Override
134 public void setMarker()
135 throws MojoExecutionException
136 {
137 File marker = getMarkerFile();
138
139
140 File clearMarker = getMarkerFile( !this.resolved );
141
142 try
143 {
144 marker.getParentFile().mkdirs();
145 }
146 catch ( NullPointerException e )
147 {
148
149 }
150
151 try
152 {
153 marker.createNewFile();
154
155 if ( clearMarker.exists() )
156 {
157 if ( !clearMarker.delete() )
158 {
159 clearMarker.deleteOnExit();
160 }
161 }
162 }
163 catch ( IOException e )
164 {
165 throw new MojoExecutionException( "Unable to create Marker: " + marker.getAbsolutePath(), e );
166 }
167 }
168
169
170
171
172
173
174
175
176
177
178 @Override
179 public boolean clearMarker()
180 throws MojoExecutionException
181 {
182 File marker = getMarkerFile();
183 File marker2 = getMarkerFile( !this.resolved );
184 boolean markResult = marker.delete();
185 boolean mark2Result = marker2.delete();
186 return markResult || mark2Result;
187 }
188
189
190
191
192 public boolean isResolved()
193 {
194 return this.resolved;
195 }
196
197
198
199
200 public void setResolved( boolean isResolved )
201 {
202 this.resolved = isResolved;
203 }
204 }