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
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 @Override
55 public File getMarkerFile()
56 {
57 return getMarkerFile( this.resolved );
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 @Override
91 public boolean isMarkerSet()
92 throws MojoExecutionException
93 {
94 File marker = getMarkerFile();
95
96 File marker2 = getMarkerFile( !this.resolved );
97
98 return marker.exists() || marker2.exists();
99 }
100
101 @Override
102 public boolean isMarkerOlder( Artifact theArtifact )
103 throws MojoExecutionException
104 {
105 File marker = getMarkerFile();
106 if ( marker.exists() )
107 {
108 return theArtifact.getFile().lastModified() > marker.lastModified();
109 }
110 else
111 {
112 marker = getMarkerFile( !this.resolved );
113 if ( marker.exists() )
114 {
115 return theArtifact.getFile().lastModified() > marker.lastModified();
116 }
117 else
118 {
119
120
121 return true;
122 }
123 }
124 }
125
126 @Override
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 if ( !clearMarker.delete() )
151 {
152 clearMarker.deleteOnExit();
153 }
154 }
155 }
156 catch ( IOException e )
157 {
158 throw new MojoExecutionException( "Unable to create Marker: " + marker.getAbsolutePath(), e );
159 }
160 }
161
162
163
164
165
166
167
168
169
170
171 @Override
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 public void setResolved( boolean isResolved )
194 {
195 this.resolved = isResolved;
196 }
197 }