Package org.codehaus.plexus.build
Interface BuildContext
-
- All Known Implementing Classes:
DefaultBuildContext
,ThreadBuildContext
public interface BuildContext
BuildContext interface.
-
-
Field Summary
Fields Modifier and Type Field Description static int
SEVERITY_ERROR
ConstantSEVERITY_ERROR=2
static int
SEVERITY_WARNING
ConstantSEVERITY_WARNING=1
-
Method Summary
All Methods Instance Methods Abstract Methods Deprecated Methods Modifier and Type Method Description void
addError(File file, int line, int column, String message, Throwable cause)
Deprecated.Use addMessage with severity=SEVERITY_WARNING insteadvoid
addMessage(File file, int line, int column, String message, int severity, Throwable cause)
Adds a message to the build context.void
addWarning(File file, int line, int column, String message, Throwable cause)
Deprecated.Use addMessage with severity=SEVERITY_ERROR insteadObject
getValue(String key)
Returns value associated withkey
during previous mojo execution.boolean
hasDelta(File file)
Returnstrue
if the file has changed since last build or is not under basedir.boolean
hasDelta(String relpath)
Returnstrue
if file or folder identified byrelpath
has changed since last build.boolean
hasDelta(List<String> relpaths)
Returnstrue
if any file or folder identified byrelpaths
has changed since last build.boolean
isIncremental()
Returnstrue
if this build context is incremental.boolean
isUptodate(File target, File source)
Returns true, if the target file exists and is uptodate compared to the source file.org.codehaus.plexus.util.Scanner
newDeleteScanner(File basedir)
Returned Scanner scansbasedir
for files and directories deleted since last build.OutputStream
newFileOutputStream(File file)
Returns new OutputStream that writes to thefile
.org.codehaus.plexus.util.Scanner
newScanner(File basedir)
Convenience method, fully equal to newScanner(basedir, false)org.codehaus.plexus.util.Scanner
newScanner(File basedir, boolean ignoreDelta)
Returned Scanner scans files and folders underbasedir
.void
refresh(File file)
Indicates that the file or folder content has been modified during the build.void
removeMessages(File file)
Removes all messages associated with a file or folder during a previous build.void
setValue(String key, Object value)
Associate specifiedkey
with specifiedvalue
in the build context.
-
-
-
Field Detail
-
SEVERITY_WARNING
static final int SEVERITY_WARNING
ConstantSEVERITY_WARNING=1
- See Also:
- Constant Field Values
-
SEVERITY_ERROR
static final int SEVERITY_ERROR
ConstantSEVERITY_ERROR=2
- See Also:
- Constant Field Values
-
-
Method Detail
-
hasDelta
boolean hasDelta(String relpath)
Returnstrue
if file or folder identified byrelpath
has changed since last build.- Parameters:
relpath
- is path relative to build context basedir- Returns:
- a boolean.
-
hasDelta
boolean hasDelta(File file)
Returnstrue
if the file has changed since last build or is not under basedir.- Parameters:
file
- aFile
object.- Returns:
- a boolean.
- Since:
- 0.0.5
-
hasDelta
boolean hasDelta(List<String> relpaths)
Returnstrue
if any file or folder identified byrelpaths
has changed since last build.- Parameters:
relpaths
- paths relative to build context basedir- Returns:
- a boolean.
-
refresh
void refresh(File file)
Indicates that the file or folder content has been modified during the build.- Parameters:
file
- aFile
object.- See Also:
newFileOutputStream(File)
-
newFileOutputStream
OutputStream newFileOutputStream(File file) throws IOException
Returns new OutputStream that writes to thefile
. Files changed using OutputStream returned by this method do not need to be explicitly refreshed usingrefresh(File)
. As an optional optimisation, OutputStreams created by incremental build context will attempt to avoid writing to the file if file content has not changed.- Parameters:
file
- aFile
object.- Returns:
- a
OutputStream
object. - Throws:
IOException
- if any.
-
newScanner
org.codehaus.plexus.util.Scanner newScanner(File basedir)
Convenience method, fully equal to newScanner(basedir, false)- Parameters:
basedir
- aFile
object.- Returns:
- a
Scanner
object.
-
newDeleteScanner
org.codehaus.plexus.util.Scanner newDeleteScanner(File basedir)
Returned Scanner scansbasedir
for files and directories deleted since last build. Returns empty Scanner ifbasedir
is not under this build context basedir.- Parameters:
basedir
- aFile
object.- Returns:
- a
Scanner
object.
-
newScanner
org.codehaus.plexus.util.Scanner newScanner(File basedir, boolean ignoreDelta)
Returned Scanner scans files and folders underbasedir
. If this is an incremental build context andignoreDelta
isfalse
, the scanner will only "see" files and folders with content changes since last build. IfignoreDelta
istrue
, the scanner will "see" all files and folders. Please beware that ignoreDelta=false does NOT work reliably for operations that copy resources from source to target locations. Returned Scanner only scans changed source resources and it does not consider changed or deleted target resources. This results in missing or stale target resources. Starting with 0.5.0, recommended way to process resources is to use #newScanner(basedir,true) to locate all source resources andisUptodate(File, File)
to optimized processing of uptodate target resources. Returns empty Scanner ifbasedir
is not under this build context basedir. https://issues.apache.org/jira/browse/MSHARED-125- Parameters:
basedir
- aFile
object.ignoreDelta
- a boolean.- Returns:
- a
Scanner
object.
-
isIncremental
boolean isIncremental()
Returnstrue
if this build context is incremental. Scanners created bynewScanner(File)
of an incremental build context will ignore files and folders that were not changed since last build. Additionally,newDeleteScanner(File)
will scan files and directories deleted since last build.- Returns:
- a boolean.
-
setValue
void setValue(String key, Object value)
Associate specifiedkey
with specifiedvalue
in the build context. Primary (and the only) purpose of this method is to allow preservation of state needed for proper incremental behaviour between consecutive executions of the same mojo needed to. For example, maven-plugin-plugin:descriptor mojo can store collection of extracted MojoDescritpor during first invocation. Then on each consecutive execution maven-plugin-plugin:descriptor will only need to extract MojoDescriptors for changed files.- Parameters:
key
- aString
object.value
- aObject
object.- See Also:
getValue(String)
-
getValue
Object getValue(String key)
Returns value associated withkey
during previous mojo execution. This method always returnsnull
for non-incremental builds (i.e.,isIncremental()
returnsfalse
) and mojos are expected to fall back to full, non-incremental behaviour.- Parameters:
key
- aString
object.- Returns:
- a
Object
object. - See Also:
setValue(String, Object)
,isIncremental()
-
addWarning
void addWarning(File file, int line, int column, String message, Throwable cause)
Deprecated.Use addMessage with severity=SEVERITY_ERROR insteadaddWarning.
-
addError
void addError(File file, int line, int column, String message, Throwable cause)
Deprecated.Use addMessage with severity=SEVERITY_WARNING insteadaddError.
-
addMessage
void addMessage(File file, int line, int column, String message, int severity, Throwable cause)
Adds a message to the build context. The message is associated with a file and a location inside that file.- Parameters:
file
- The file or folder with which the message is associated. Should not be null and it is recommended to be an absolute path.line
- The line number inside the file. Use 1 (not 0) for the first line. Use 0 for unknown/unspecified.column
- The column number inside the file. Use 1 (not 0) for the first column. Use 0 for unknown/unspecified.severity
- The severity of the message: SEVERITY_WARNING or SEVERITY_ERROR.cause
- A Throwable object associated with the message. Can be null.message
- aString
object.- Since:
- 0.0.7
-
removeMessages
void removeMessages(File file)
Removes all messages associated with a file or folder during a previous build. It does not affect the messages added during the current build.- Parameters:
file
- aFile
object.- Since:
- 0.0.7
-
isUptodate
boolean isUptodate(File target, File source)
Returns true, if the target file exists and is uptodate compared to the source file. More specifically, this method returns true when both target and source files exist, do not have changes since last incremental build and the target file was last modified later than the source file. Returns false in all other cases.
-
-