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