Package org.codehaus.plexus.build
Class ThreadBuildContext
- java.lang.Object
-
- org.codehaus.plexus.build.ThreadBuildContext
-
- All Implemented Interfaces:
BuildContext
public class ThreadBuildContext extends Object implements BuildContext
BuildContext implementation that delegates actual work to thread-local build context set usingsetThreadBuildContext(BuildContext).DefaultBuildContextis 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.- Since:
- 0.0.8
- Version:
- $Id: $Id
- Author:
- slachiewicz
-
-
Field Summary
-
Fields inherited from interface org.codehaus.plexus.build.BuildContext
SEVERITY_ERROR, SEVERITY_WARNING
-
-
Constructor Summary
Constructors Constructor Description ThreadBuildContext()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddError(File file, int line, int column, String message, Throwable cause)addError.voidaddMessage(File file, int line, int column, String message, int severity, Throwable cause)Adds a message to the build context.voidaddWarning(File file, int line, int column, String message, Throwable cause)addWarning.static BuildContextgetContext()getContext.ObjectgetValue(String key)Returns value associated withkeyduring previous mojo execution.booleanhasDelta(File file)hasDelta.booleanhasDelta(String relPath)Returnstrueif file or folder identified byrelpathhas changed since last build.booleanhasDelta(List<String> relPaths)hasDelta.booleanisIncremental()isIncremental.booleanisUptodate(File target, File source)Returns true, if the target file exists and is uptodate compared to the source file.org.codehaus.plexus.util.ScannernewDeleteScanner(File basedir)Returned Scanner scansbasedirfor files and directories deleted since last build.OutputStreamnewFileOutputStream(File file)Returns new OutputStream that writes to thefile.org.codehaus.plexus.util.ScannernewScanner(File basedir)Convenience method, fully equal to newScanner(basedir, false)org.codehaus.plexus.util.ScannernewScanner(File basedir, boolean ignoreDelta)Returned Scanner scans files and folders underbasedir.voidrefresh(File file)Indicates that the file or folder content has been modified during the build.voidremoveMessages(File file)Removes all messages associated with a file or folder during a previous build.static voidsetThreadBuildContext(BuildContext context)setThreadBuildContext.voidsetValue(String key, Object value)Associate specifiedkeywith specifiedvaluein the build context.
-
-
-
Method Detail
-
getContext
public static BuildContext getContext()
getContext.
- Returns:
- a
BuildContextobject.
-
setThreadBuildContext
public static void setThreadBuildContext(BuildContext context)
setThreadBuildContext.
- Parameters:
context- aBuildContextobject.
-
hasDelta
public boolean hasDelta(String relPath)
Returnstrueif file or folder identified byrelpathhas changed since last build.- Specified by:
hasDeltain interfaceBuildContext- Parameters:
relPath- is path relative to build context basedir- Returns:
- a boolean.
-
hasDelta
public boolean hasDelta(File file)
hasDelta.
- Specified by:
hasDeltain interfaceBuildContext- Parameters:
file- aFileobject.- Returns:
- a boolean.
-
hasDelta
public boolean hasDelta(List<String> relPaths)
hasDelta.
- Specified by:
hasDeltain interfaceBuildContext- Parameters:
relPaths- aListobject.- Returns:
- a boolean.
-
newDeleteScanner
public org.codehaus.plexus.util.Scanner newDeleteScanner(File basedir)
Returned Scanner scansbasedirfor files and directories deleted since last build. Returns empty Scanner ifbasediris not under this build context basedir.- Specified by:
newDeleteScannerin interfaceBuildContext- Parameters:
basedir- aFileobject.- Returns:
- a
Scannerobject.
-
newFileOutputStream
public 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 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:
newFileOutputStreamin interfaceBuildContext- Parameters:
file- aFileobject.- Returns:
- a
OutputStreamobject. - Throws:
IOException- if any.
-
newScanner
public org.codehaus.plexus.util.Scanner newScanner(File basedir)
Convenience method, fully equal to newScanner(basedir, false)- Specified by:
newScannerin interfaceBuildContext- Parameters:
basedir- aFileobject.- Returns:
- a
Scannerobject.
-
newScanner
public org.codehaus.plexus.util.Scanner newScanner(File basedir, boolean ignoreDelta)
Returned Scanner scans files and folders underbasedir. If this is an incremental build context andignoreDeltaisfalse, the scanner will only "see" files and folders with content changes since last build. IfignoreDeltaistrue, 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 ifbasediris not under this build context basedir. https://issues.apache.org/jira/browse/MSHARED-125- Specified by:
newScannerin interfaceBuildContext- Parameters:
basedir- aFileobject.ignoreDelta- a boolean.- Returns:
- a
Scannerobject.
-
refresh
public void refresh(File file)
Indicates that the file or folder content has been modified during the build.- Specified by:
refreshin interfaceBuildContext- Parameters:
file- aFileobject.- See Also:
BuildContext.newFileOutputStream(File)
-
getValue
public Object getValue(String key)
Returns value associated withkeyduring previous mojo execution. This method always returnsnullfor non-incremental builds (i.e.,BuildContext.isIncremental()returnsfalse) and mojos are expected to fall back to full, non-incremental behaviour.- Specified by:
getValuein interfaceBuildContext- Parameters:
key- aStringobject.- Returns:
- a
Objectobject. - See Also:
BuildContext.setValue(String, Object),BuildContext.isIncremental()
-
isIncremental
public boolean isIncremental()
isIncremental.
- Specified by:
isIncrementalin interfaceBuildContext- Returns:
- a boolean.
-
setValue
public void setValue(String key, Object value)
Associate specifiedkeywith specifiedvaluein 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:
setValuein interfaceBuildContext- Parameters:
key- aStringobject.value- aObjectobject.- See Also:
BuildContext.getValue(String)
-
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:
addMessagein 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- aStringobject.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(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.- Specified by:
removeMessagesin interfaceBuildContext- Parameters:
file- aFileobject.
-
addWarning
public void addWarning(File file, int line, int column, String message, Throwable cause)
addWarning.
- Specified by:
addWarningin interfaceBuildContext- Parameters:
file- aFileobject.line- a int.column- a int.message- aStringobject.cause- aThrowableobject.
-
addError
public void addError(File file, int line, int column, String message, Throwable cause)
addError.
- Specified by:
addErrorin interfaceBuildContext- Parameters:
file- aFileobject.line- a int.column- a int.message- aStringobject.cause- aThrowableobject.
-
isUptodate
public 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.- Specified by:
isUptodatein interfaceBuildContext- Parameters:
target- aFileobject.source- aFileobject.- Returns:
- a boolean.
-
-