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