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