Package org.codehaus.plexus.build
Class DefaultBuildContext
java.lang.Object
org.codehaus.plexus.build.DefaultBuildContext
- All Implemented Interfaces:
BuildContext
@Named("default")
@Singleton
public class DefaultBuildContext
extends Object
implements BuildContext
Filesystem based non-incremental build context implementation which behaves
as if all files were just created. More specifically,
- hasDelta returns
true
for all paths - newScanner returns Scanner that scans all files under provided basedir
- newDeletedScanner always returns empty scanner
- isIncremental returns
false
- getValue always returns the last set value in this session and only stores to memory
-
Field Summary
Fields inherited from interface org.codehaus.plexus.build.BuildContext
SEVERITY_ERROR, SEVERITY_WARNING
-
Constructor Summary
ConstructorsConstructorDescriptionDefaultBuildContext
(org.sonatype.plexus.build.incremental.BuildContext legacy) -
Method Summary
Modifier and TypeMethodDescriptionvoid
addError.void
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) addWarning.Returns value associated withkey
during previous mojo execution.boolean
hasDelta.boolean
Returnstrue
if file or folder identified byrelpath
has changed since last build.boolean
hasDelta.boolean
isIncremental.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.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
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
Associate specifiedkey
with specifiedvalue
in the build context.
-
Constructor Details
-
DefaultBuildContext
@Inject public DefaultBuildContext(org.sonatype.plexus.build.incremental.BuildContext legacy) - Parameters:
legacy
- the legacy API we delegate to by default, this allow us to support "older" plugins and implementors of the API while still having a way to move forward!
-
-
Method Details
-
hasDelta
Returnstrue
if file or folder identified byrelpath
has changed since last build.- Specified by:
hasDelta
in interfaceBuildContext
- Parameters:
relpath
- is path relative to build context basedir- Returns:
- a boolean.
-
hasDelta
hasDelta.
- Specified by:
hasDelta
in interfaceBuildContext
- Parameters:
file
- aFile
object.- Returns:
- a boolean.
-
hasDelta
hasDelta.
- Specified by:
hasDelta
in interfaceBuildContext
- Parameters:
relpaths
- aList
object.- Returns:
- a boolean.
-
newFileOutputStream
Returns new OutputStream that writes to thefile
. Files changed using OutputStream returned by this method do not need to be explicitly refreshed usingBuildContext.refresh(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.- Specified by:
newFileOutputStream
in interfaceBuildContext
- Parameters:
file
- aFile
object.- Returns:
- a
OutputStream
object. - Throws:
IOException
- if any.
-
newScanner
Convenience method, fully equal to newScanner(basedir, false)- Specified by:
newScanner
in interfaceBuildContext
- Parameters:
basedir
- aFile
object.- Returns:
- a
Scanner
object.
-
refresh
Indicates that the file or folder content has been modified during the build.- Specified by:
refresh
in interfaceBuildContext
- Parameters:
file
- aFile
object.- See Also:
-
newDeleteScanner
Returned Scanner scansbasedir
for files and directories deleted since last build. Returns empty Scanner ifbasedir
is not under this build context basedir.- Specified by:
newDeleteScanner
in interfaceBuildContext
- Parameters:
basedir
- aFile
object.- Returns:
- a
Scanner
object.
-
newScanner
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 andBuildContext.isUptodate(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- Specified by:
newScanner
in interfaceBuildContext
- Parameters:
basedir
- aFile
object.ignoreDelta
- a boolean.- Returns:
- a
Scanner
object.
-
isIncremental
public boolean isIncremental()isIncremental.
- Specified by:
isIncremental
in interfaceBuildContext
- Returns:
- a boolean.
-
getValue
Returns value associated withkey
during previous mojo execution. This method always returnsnull
for non-incremental builds (i.e.,BuildContext.isIncremental()
returnsfalse
) and mojos are expected to fall back to full, non-incremental behaviour.- Specified by:
getValue
in interfaceBuildContext
- Parameters:
key
- aString
object.- Returns:
- a
Object
object. - See Also:
-
setValue
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.- Specified by:
setValue
in interfaceBuildContext
- Parameters:
key
- aString
object.value
- aObject
object.- See Also:
-
addError
addError.
- Specified by:
addError
in interfaceBuildContext
- Parameters:
file
- aFile
object.line
- a int.column
- a int.message
- aString
object.cause
- aThrowable
object.
-
addWarning
addWarning.
- Specified by:
addWarning
in interfaceBuildContext
- Parameters:
file
- aFile
object.line
- a int.column
- a int.message
- aString
object.cause
- aThrowable
object.
-
addMessage
public 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.- Specified by:
addMessage
in interfaceBuildContext
- 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.message
- aString
object.severity
- The severity of the message: SEVERITY_WARNING or SEVERITY_ERROR.cause
- A Throwable object associated with the message. Can be null.
-
removeMessages
Removes all messages associated with a file or folder during a previous build. It does not affect the messages added during the current build.- Specified by:
removeMessages
in interfaceBuildContext
- Parameters:
file
- aFile
object.
-
isUptodate
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.- Specified by:
isUptodate
in interfaceBuildContext
- Parameters:
target
- aFile
object.source
- aFile
object.- Returns:
- a boolean.
-