Skip to content

Commit 2ceef09

Browse files
author
Igor Fedorenko
committed
MECLIPSE-147 context can be used to retain state between builds now
git-svn-id: file:///opt/svn/repositories/sonatype.org/spice/trunk/plexus-build-api@857 5751e0cb-dcb7-432f-92e2-260806df54be
1 parent a269378 commit 2ceef09

File tree

3 files changed

+82
-12
lines changed

3 files changed

+82
-12
lines changed

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

Lines changed: 54 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public interface BuildContext {
3131
boolean hasDelta(List relpaths);
3232

3333
/**
34-
* Indicates that the file content has been modified during the build.
34+
* Indicates that the file or folder content has been modified during the build.
3535
*
3636
* @see #newFileOutputStream(File)
3737
*/
@@ -42,6 +42,10 @@ public interface BuildContext {
4242
*
4343
* Files changed using OutputStream returned by this method do not need to be
4444
* explicitly refreshed using {@link #refresh(File)}.
45+
*
46+
* As an optional optimisation, OutputStreams created by incremental build
47+
* context will attempt to avoid writing to the file if file content
48+
* has not changed.
4549
*/
4650
OutputStream newFileOutputStream(File file) throws IOException;
4751

@@ -59,11 +63,55 @@ public interface BuildContext {
5963

6064
/**
6165
* Returned Scanner scans files and folders under <code>basedir</code>.
62-
* If <code>ignoreDelta</code> is <code>false</code>, the scanner will only
63-
* "see" files and folders with content changes since last build. If
64-
* <code>ignoreDelta</code> is <code>true</code>, the scanner will "see" all
65-
* files and folders. Returns empty Scanner if <code>basedir</code>
66-
* is not under this build context basedir.
66+
*
67+
* If this is an incremental build context and <code>ignoreDelta</code>
68+
* is <code>false</code>, the scanner will only "see" files and folders with
69+
* content changes since last build.
70+
*
71+
* If <code>ignoreDelta</code> is <code>true</code>, the scanner will "see" all
72+
* files and folders.
73+
*
74+
* Returns empty Scanner if <code>basedir</code> is not under this build context basedir.
6775
*/
6876
Scanner newScanner(File basedir, boolean ignoreDelta);
77+
78+
/**
79+
* Returns <code>true</code> if this build context is incremental.
80+
*
81+
* Scanners created by {@link #newScanner(File)} of an incremental build context
82+
* will ignore files and folders that were not changed since last build.
83+
* Additionally, {@link #newDeleteScanner(File)} will scan files and directories
84+
* deleted since last build.
85+
*/
86+
boolean isIncremental();
87+
88+
/**
89+
* Associate specified <code>key</code> with specified <code>value</code>
90+
* in the build context.
91+
*
92+
* Primary (and the only) purpose of this method is to allow preservation of
93+
* state needed for proper incremental behaviour between consecutive executions
94+
* of the same mojo needed to.
95+
*
96+
* For example, maven-plugin-plugin:descriptor mojo
97+
* can store collection of extracted MojoDescritpor during first invocation. Then
98+
* on each consecutive execution maven-plugin-plugin:descriptor will only need
99+
* to extract MojoDescriptors for changed files.
100+
*
101+
* @see #getValue(String)
102+
*/
103+
public void setValue(String key, Object value);
104+
105+
/**
106+
* Returns value associated with <code>key</code> during previous mojo execution.
107+
*
108+
* This method always returns <code>null</code> for non-incremental builds
109+
* (i.e., {@link #isIncremental()} returns <code>false</code>) and mojos are
110+
* expected to fall back to full, non-incremental behaviour.
111+
*
112+
* @see #setValue(String, Object)
113+
* @see #isIncremental()
114+
*/
115+
public Object getValue(String key);
116+
69117
}

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

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,25 @@
1111
import org.codehaus.plexus.util.Scanner;
1212

1313
/**
14-
* Filesystem based build context implementation which behaves as if all files
14+
* Filesystem based non-incremental build context implementation which behaves as if all files
1515
* were just created. More specifically,
1616
*
1717
* hasDelta returns <code>true</code> for all paths
1818
* newScanner returns Scanner that scanns all files under provided basedir
1919
* newDeletedScanner always returns empty scanner.
20+
* isIncremental returns <code>false</code<
21+
* getValue always returns <code>null</code>
2022
*
2123
* @plexus.component role="org.codehaus.plexus.build.incremental.BuildContext"
2224
* role-hint="default"
2325
*/
2426
public class DefaultBuildContext implements BuildContext {
2527

26-
public boolean hasDelta(String relPath) {
28+
public boolean hasDelta(String relpath) {
2729
return true;
2830
}
2931

30-
public boolean hasDelta(List relPaths) {
32+
public boolean hasDelta(List relpaths) {
3133
return true;
3234
}
3335

@@ -46,11 +48,21 @@ public void refresh(File file) {
4648
}
4749

4850
public Scanner newDeleteScanner(File basedir) {
49-
return EmptyScanner.INSTANCE;
51+
return new EmptyScanner(basedir);
5052
}
5153

5254
public Scanner newScanner(File basedir, boolean ignoreDelta) {
5355
return newScanner(basedir);
5456
}
5557

58+
public boolean isIncremental() {
59+
return false;
60+
}
61+
62+
public Object getValue(String key) {
63+
return null;
64+
}
65+
66+
public void setValue(String key, Object value) {
67+
}
5668
}

src/main/java/org/codehaus/plexus/build/incremental/EmptyScanner.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,22 @@
11

22
package org.codehaus.plexus.build.incremental;
33

4+
import java.io.File;
5+
46
import org.codehaus.plexus.util.Scanner;
57

68
/**
79
* Scanner implementation never finds any files/directories.
810
*/
911
public class EmptyScanner implements Scanner {
1012

11-
public static final Scanner INSTANCE = new EmptyScanner();
12-
1313
private static final String[] EMPTY_STRING_ARRAY = new String[0];
14+
15+
private final File basedir;
16+
17+
public EmptyScanner(File basedir) {
18+
this.basedir = basedir;
19+
}
1420

1521
public void addDefaultExcludes() {
1622
}
@@ -32,4 +38,8 @@ public void setExcludes(String[] excludes) {
3238
public void setIncludes(String[] includes) {
3339
}
3440

41+
public File getBasedir() {
42+
return basedir;
43+
}
44+
3545
}

0 commit comments

Comments
 (0)