Skip to content

Commit af0ec54

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@1829 5751e0cb-dcb7-432f-92e2-260806df54be
1 parent 45acb4a commit af0ec54

File tree

4 files changed

+63
-33
lines changed

4 files changed

+63
-33
lines changed

src/main/java/org/sonatype/plexus/build/incremental/BuildContext.java

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,14 @@ public interface BuildContext {
3333
*/
3434
boolean hasDelta(String relpath);
3535

36+
/**
37+
* Returns <code>true</code> if the file has changed since last build or is not
38+
* under basedir.
39+
*
40+
* @since 0.5.0
41+
*/
42+
boolean hasDelta(File file);
43+
3644
/**
3745
* Returns <code>true</code> if any file or folder identified by <code>relpaths</code> has
3846
* changed since last build.
@@ -82,7 +90,17 @@ public interface BuildContext {
8290
* If <code>ignoreDelta</code> is <code>true</code>, the scanner will "see" all
8391
* files and folders.
8492
*
93+
* Please beware that ignoreDelta=false does NOT work reliably for operations
94+
* that copy resources from source to target locations. Returned Scanner
95+
* only scans changed source resources and it does not consider changed or deleted
96+
* target resources. This results in missing or stale target resources.
97+
* Starting with 0.5.0, recommended way to process resources is to use
98+
* #newScanner(basedir,true) to locate all source resources and {@link #isUptodate(File, File)}
99+
* to optimized processing of uptodate target resources.
100+
*
85101
* Returns empty Scanner if <code>basedir</code> is not under this build context basedir.
102+
*
103+
* @see http://jira.codehaus.org/browse/MSHARED-125
86104
*/
87105
Scanner newScanner(File basedir, boolean ignoreDelta);
88106

@@ -111,7 +129,7 @@ public interface BuildContext {
111129
*
112130
* @see #getValue(String)
113131
*/
114-
public void setValue(String key, Object value);
132+
void setValue(String key, Object value);
115133

116134
/**
117135
* Returns value associated with <code>key</code> during previous mojo execution.
@@ -123,6 +141,29 @@ public interface BuildContext {
123141
* @see #setValue(String, Object)
124142
* @see #isIncremental()
125143
*/
126-
public Object getValue(String key);
144+
Object getValue(String key);
145+
146+
/**
147+
*
148+
* @since 0.5.0
149+
*/
150+
void addWarning(File file, int line, int column, String message, Throwable cause);
151+
152+
/**
153+
*
154+
* @since 0.5.0
155+
*/
156+
void addError(File file, int line, int column, String message, Throwable cause);
157+
158+
/**
159+
* Returns true, if the target file exists and is uptodate compared to the source file.
160+
*
161+
* More specifically, this method returns true when both target and source files exist,
162+
* do not have changes since last incremental build and the target file was last modified
163+
* later than the source file. Returns false in all other cases.
164+
*
165+
* @since 0.5.0
166+
*/
167+
boolean isUptodate(File target, File source);
127168

128169
}

src/main/java/org/sonatype/plexus/build/incremental/BuildContext2.java

Lines changed: 0 additions & 21 deletions
This file was deleted.

src/main/java/org/sonatype/plexus/build/incremental/DefaultBuildContext.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
* were just created. More specifically,
2828
*
2929
* hasDelta returns <code>true</code> for all paths
30-
* newScanner returns Scanner that scanns all files under provided basedir
30+
* newScanner returns Scanner that scans all files under provided basedir
3131
* newDeletedScanner always returns empty scanner.
3232
* isIncremental returns <code>false</code<
3333
* getValue always returns <code>null</code>
@@ -41,6 +41,10 @@ public boolean hasDelta(String relpath) {
4141
return true;
4242
}
4343

44+
public boolean hasDelta(File file) {
45+
return true;
46+
}
47+
4448
public boolean hasDelta(List relpaths) {
4549
return true;
4650
}
@@ -83,4 +87,9 @@ public void addWarning(File file, int line, int column, String message, Throwabl
8387

8488
public void addError(File file, int line, int column, String message, Throwable cause) {
8589
}
90+
91+
public boolean isUptodate(File target, File source) {
92+
return target != null && target.exists() && source != null && source.exists()
93+
&& target.lastModified() > source.lastModified();
94+
}
8695
}

src/main/java/org/sonatype/plexus/build/incremental/ThreadBuildContext.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
* Apparently, older version of plexus used by maven-filtering and likely
3030
* other projects, does not honour "default" role-hint.
3131
*/
32-
public class ThreadBuildContext implements BuildContext, BuildContext2 {
32+
public class ThreadBuildContext implements BuildContext {
3333

3434
private static final ThreadLocal threadContext = new ThreadLocal();
3535

@@ -51,6 +51,10 @@ public boolean hasDelta(String relPath) {
5151
return getContext().hasDelta(relPath);
5252
}
5353

54+
public boolean hasDelta(File file) {
55+
return getContext().hasDelta(file);
56+
}
57+
5458
public boolean hasDelta(List relPaths) {
5559
return getContext().hasDelta(relPaths);
5660
}
@@ -88,17 +92,14 @@ public void setValue(String key, Object value) {
8892
}
8993

9094
public void addWarning(File file, int line, int column, String message, Throwable cause) {
91-
BuildContext context = getContext();
92-
if (context instanceof BuildContext2) {
93-
((BuildContext2) context).addWarning(file, line, column, message, cause);
94-
}
95+
getContext().addWarning(file, line, column, message, cause);
9596
}
9697

9798
public void addError(File file, int line, int column, String message, Throwable cause) {
98-
BuildContext context = getContext();
99-
if (context instanceof BuildContext2) {
100-
((BuildContext2) context).addError(file, line, column, message, cause);
101-
}
99+
getContext().addError(file, line, column, message, cause);
102100
}
103101

102+
public boolean isUptodate(File target, File source) {
103+
return getContext().isUptodate(target, source);
104+
}
104105
}

0 commit comments

Comments
 (0)