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