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