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