Class ThreadBuildContext
- java.lang.Object
-
- org.sonatype.plexus.build.incremental.ThreadBuildContext
-
- All Implemented Interfaces:
BuildContext
public class ThreadBuildContext extends java.lang.Object implements BuildContext
BuildContext implementation that delegates actual work to thread-local build context set usingsetThreadBuildContext(BuildContext)
.DefaultBuildContext
is used if no thread local build context was set. Note that plexus component metadata is not generated for this implementation. Apparently, older version of plexus used by maven-filtering and likely other projects, does not honour "default" role-hint.
-
-
Field Summary
Fields Modifier and Type Field Description private static DefaultBuildContext
defaultContext
private static java.lang.ThreadLocal
threadContext
-
Fields inherited from interface org.sonatype.plexus.build.incremental.BuildContext
SEVERITY_ERROR, SEVERITY_WARNING
-
-
Constructor Summary
Constructors Constructor Description ThreadBuildContext()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
addError(java.io.File file, int line, int column, java.lang.String message, java.lang.Throwable cause)
Deprecated.Use addMessage with severity=SEVERITY_ERROR insteadvoid
addMessage(java.io.File file, int line, int column, java.lang.String message, int severity, java.lang.Throwable cause)
Adds a message to the build context.void
addWarning(java.io.File file, int line, int column, java.lang.String message, java.lang.Throwable cause)
Deprecated.Use addMessage with severity=SEVERITY_WARNING insteadstatic BuildContext
getContext()
java.lang.Object
getValue(java.lang.String key)
Returns value associated withkey
during previous mojo execution.boolean
hasDelta(java.io.File file)
Returnstrue
if the file has changed since last build or is not under basedir.boolean
hasDelta(java.lang.String relPath)
Returnstrue
if file or folder identified byrelpath
has changed since last build.boolean
hasDelta(java.util.List 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(java.io.File target, java.io.File source)
Returns true, if the target file exists and is uptodate compared to the source file.org.codehaus.plexus.util.Scanner
newDeleteScanner(java.io.File basedir)
Returned Scanner scansbasedir
for files and directories deleted since last build.java.io.OutputStream
newFileOutputStream(java.io.File file)
Returns new OutputStream that writes to thefile
.org.codehaus.plexus.util.Scanner
newScanner(java.io.File basedir)
Convenience method, fully equal to newScanner(basedir, false)org.codehaus.plexus.util.Scanner
newScanner(java.io.File basedir, boolean ignoreDelta)
Returned Scanner scans files and folders underbasedir
.void
refresh(java.io.File file)
Indicates that the file or folder content has been modified during the build.void
removeMessages(java.io.File file)
Removes all messages associated with a file or folder during a previous build.static void
setThreadBuildContext(BuildContext context)
void
setValue(java.lang.String key, java.lang.Object value)
Associate specifiedkey
with specifiedvalue
in the build context.
-
-
-
Field Detail
-
threadContext
private static final java.lang.ThreadLocal threadContext
-
defaultContext
private static final DefaultBuildContext defaultContext
-
-
Method Detail
-
getContext
public static BuildContext getContext()
-
setThreadBuildContext
public static void setThreadBuildContext(BuildContext context)
-
hasDelta
public boolean hasDelta(java.lang.String relPath)
Description copied from interface:BuildContext
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
-
hasDelta
public boolean hasDelta(java.io.File file)
Description copied from interface:BuildContext
Returnstrue
if the file has changed since last build or is not under basedir.- Specified by:
hasDelta
in interfaceBuildContext
-
hasDelta
public boolean hasDelta(java.util.List relPaths)
Description copied from interface:BuildContext
Returnstrue
if any file or folder identified byrelpaths
has changed since last build.- Specified by:
hasDelta
in interfaceBuildContext
- Parameters:
relPaths
- Listare paths relative to build context basedir
-
newDeleteScanner
public org.codehaus.plexus.util.Scanner newDeleteScanner(java.io.File basedir)
Description copied from interface:BuildContext
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
-
newFileOutputStream
public java.io.OutputStream newFileOutputStream(java.io.File file) throws java.io.IOException
Description copied from interface:BuildContext
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
- Throws:
java.io.IOException
-
newScanner
public org.codehaus.plexus.util.Scanner newScanner(java.io.File basedir)
Description copied from interface:BuildContext
Convenience method, fully equal to newScanner(basedir, false)- Specified by:
newScanner
in interfaceBuildContext
-
newScanner
public org.codehaus.plexus.util.Scanner newScanner(java.io.File basedir, boolean ignoreDelta)
Description copied from interface:BuildContext
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.- Specified by:
newScanner
in interfaceBuildContext
-
refresh
public void refresh(java.io.File file)
Description copied from interface:BuildContext
Indicates that the file or folder content has been modified during the build.- Specified by:
refresh
in interfaceBuildContext
- See Also:
BuildContext.newFileOutputStream(File)
-
getValue
public java.lang.Object getValue(java.lang.String key)
Description copied from interface:BuildContext
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
- See Also:
BuildContext.setValue(String, Object)
,BuildContext.isIncremental()
-
isIncremental
public boolean isIncremental()
Description copied from interface:BuildContext
Returnstrue
if this build context is incremental. Scanners created byBuildContext.newScanner(File)
of an incremental build context will ignore files and folders that were not changed since last build. Additionally,BuildContext.newDeleteScanner(File)
will scan files and directories deleted since last build.- Specified by:
isIncremental
in interfaceBuildContext
-
setValue
public void setValue(java.lang.String key, java.lang.Object value)
Description copied from interface:BuildContext
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
- See Also:
BuildContext.getValue(String)
-
addMessage
public void addMessage(java.io.File file, int line, int column, java.lang.String message, int severity, java.lang.Throwable cause)
Description copied from interface:BuildContext
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.severity
- The severity of the message: SEVERITY_WARNING or SEVERITY_ERROR.cause
- A Throwable object associated with the message. Can be null.
-
removeMessages
public void removeMessages(java.io.File file)
Description copied from interface:BuildContext
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
-
addWarning
public void addWarning(java.io.File file, int line, int column, java.lang.String message, java.lang.Throwable cause)
Deprecated.Use addMessage with severity=SEVERITY_WARNING instead- Specified by:
addWarning
in interfaceBuildContext
-
addError
public void addError(java.io.File file, int line, int column, java.lang.String message, java.lang.Throwable cause)
Deprecated.Use addMessage with severity=SEVERITY_ERROR instead- Specified by:
addError
in interfaceBuildContext
-
isUptodate
public boolean isUptodate(java.io.File target, java.io.File source)
Description copied from interface:BuildContext
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
-
-