org.sonatype.plexus.build.incremental
Class ThreadBuildContext

java.lang.Object
  extended by org.sonatype.plexus.build.incremental.ThreadBuildContext
All Implemented Interfaces:
BuildContext

public class ThreadBuildContext
extends Object
implements BuildContext

BuildContext implementation that delegates actual work to thread-local build context set using setThreadBuildContext(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.


Constructor Summary
ThreadBuildContext()
           
 
Method Summary
 void addError(File file, int line, int column, String message, Throwable cause)
           
 void addWarning(File file, int line, int column, String message, Throwable cause)
           
static BuildContext getContext()
           
 Object getValue(String key)
          Returns value associated with key during previous mojo execution.
 boolean hasDelta(File file)
          Returns true if the file has changed since last build or is not under basedir.
 boolean hasDelta(List relPaths)
          Returns true if any file or folder identified by relpaths has changed since last build.
 boolean hasDelta(String relPath)
          Returns true if file or folder identified by relpath has changed since last build.
 boolean isIncremental()
          Returns true 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 scans basedir for files and directories deleted since last build.
 OutputStream newFileOutputStream(File file)
          Returns new OutputStream that writes to the file.
 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 under basedir.
 void refresh(File file)
          Indicates that the file or folder content has been modified during the build.
static void setThreadBuildContext(BuildContext context)
           
 void setValue(String key, Object value)
          Associate specified key with specified value in the build context.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ThreadBuildContext

public ThreadBuildContext()
Method Detail

getContext

public static BuildContext getContext()

setThreadBuildContext

public static void setThreadBuildContext(BuildContext context)

hasDelta

public boolean hasDelta(String relPath)
Description copied from interface: BuildContext
Returns true if file or folder identified by relpath has changed since last build.

Specified by:
hasDelta in interface BuildContext
Parameters:
relPath - is path relative to build context basedir

hasDelta

public boolean hasDelta(File file)
Description copied from interface: BuildContext
Returns true if the file has changed since last build or is not under basedir.

Specified by:
hasDelta in interface BuildContext

hasDelta

public boolean hasDelta(List relPaths)
Description copied from interface: BuildContext
Returns true if any file or folder identified by relpaths has changed since last build.

Specified by:
hasDelta in interface BuildContext
Parameters:
relPaths - List are paths relative to build context basedir

newDeleteScanner

public org.codehaus.plexus.util.Scanner newDeleteScanner(File basedir)
Description copied from interface: BuildContext
Returned Scanner scans basedir for files and directories deleted since last build. Returns empty Scanner if basedir is not under this build context basedir.

Specified by:
newDeleteScanner in interface BuildContext

newFileOutputStream

public OutputStream newFileOutputStream(File file)
                                 throws IOException
Description copied from interface: BuildContext
Returns new OutputStream that writes to the file. Files changed using OutputStream returned by this method do not need to be explicitly refreshed using BuildContext.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 interface BuildContext
Throws:
IOException

newScanner

public org.codehaus.plexus.util.Scanner newScanner(File basedir)
Description copied from interface: BuildContext
Convenience method, fully equal to newScanner(basedir, false)

Specified by:
newScanner in interface BuildContext

newScanner

public org.codehaus.plexus.util.Scanner newScanner(File basedir,
                                                   boolean ignoreDelta)
Description copied from interface: BuildContext
Returned Scanner scans files and folders under basedir. If this is an incremental build context and ignoreDelta is false, the scanner will only "see" files and folders with content changes since last build. If ignoreDelta is true, 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 and BuildContext.isUptodate(File, File) to optimized processing of uptodate target resources. Returns empty Scanner if basedir is not under this build context basedir.

Specified by:
newScanner in interface BuildContext
See Also:
http://jira.codehaus.org/browse/MSHARED-125

refresh

public void refresh(File file)
Description copied from interface: BuildContext
Indicates that the file or folder content has been modified during the build.

Specified by:
refresh in interface BuildContext
See Also:
BuildContext.newFileOutputStream(File)

getValue

public Object getValue(String key)
Description copied from interface: BuildContext
Returns value associated with key during previous mojo execution. This method always returns null for non-incremental builds (i.e., BuildContext.isIncremental() returns false) and mojos are expected to fall back to full, non-incremental behaviour.

Specified by:
getValue in interface BuildContext
See Also:
BuildContext.setValue(String, Object), BuildContext.isIncremental()

isIncremental

public boolean isIncremental()
Description copied from interface: BuildContext
Returns true if this build context is incremental. Scanners created by BuildContext.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 interface BuildContext

setValue

public void setValue(String key,
                     Object value)
Description copied from interface: BuildContext
Associate specified key with specified value 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 interface BuildContext
See Also:
BuildContext.getValue(String)

addWarning

public void addWarning(File file,
                       int line,
                       int column,
                       String message,
                       Throwable cause)
Specified by:
addWarning in interface BuildContext

addError

public void addError(File file,
                     int line,
                     int column,
                     String message,
                     Throwable cause)
Specified by:
addError in interface BuildContext

isUptodate

public boolean isUptodate(File target,
                          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 interface BuildContext


Copyright © 2008-2011. All Rights Reserved.