Skip to content

Commit c7da71e

Browse files
author
Igor Fedorenko
committed
Merged BuildContext2 back into BuildContext
Introduced convenience hasDelta(File) method Introduced new isUpdate(File target, File source) method git-svn-id: file:///opt/svn/repositories/sonatype.org/spice/trunk/plexus-build-api@1830 5751e0cb-dcb7-432f-92e2-260806df54be
1 parent af0ec54 commit c7da71e

File tree

1 file changed

+28
-4
lines changed

1 file changed

+28
-4
lines changed

src/test/java/org/sonatype/plexus/build/incremental/test/TestIncrementalBuildContext.java

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,8 @@
2727
import org.codehaus.plexus.util.DirectoryScanner;
2828
import org.codehaus.plexus.util.Scanner;
2929
import org.sonatype.plexus.build.incremental.BuildContext;
30-
import org.sonatype.plexus.build.incremental.BuildContext2;
3130

32-
33-
public class TestIncrementalBuildContext implements BuildContext, BuildContext2 {
31+
public class TestIncrementalBuildContext implements BuildContext {
3432

3533
private final File basedir;
3634

@@ -117,7 +115,27 @@ public boolean hasDelta(List relpaths) {
117115
return false;
118116
}
119117

120-
public boolean isIncremental() {
118+
public boolean hasDelta(File file) {
119+
String relpath = getRelpath(file);
120+
return relpath == null || hasDelta(relpath);
121+
}
122+
123+
private String getRelpath(File file) {
124+
try {
125+
String path = file.getCanonicalPath();
126+
String basepath = basedir.getCanonicalPath();
127+
if (path.startsWith(basepath) && !path.equals(basepath)) {
128+
return path.substring(basepath.length());
129+
} else {
130+
return null;
131+
}
132+
} catch (IOException e) {
133+
// this is a test implementation, we can be little loose here
134+
throw new IllegalArgumentException(e);
135+
}
136+
}
137+
138+
public boolean isIncremental() {
121139
return true;
122140
}
123141

@@ -165,4 +183,10 @@ public void addError(File file, int line, int column, String message, Throwable
165183

166184
public void addWarning(File file, int line, int column, String message, Throwable cause) {
167185
}
186+
187+
public boolean isUptodate(File target, File source) {
188+
return target != null && target.exists() && !hasDelta(target)
189+
&& source != null && source.exists() && !hasDelta(source)
190+
&& target.lastModified() > source.lastModified();
191+
}
168192
}

0 commit comments

Comments
 (0)