diff --git a/pom.xml b/pom.xml index 2dbb706..a589c79 100644 --- a/pom.xml +++ b/pom.xml @@ -1,3 +1,4 @@ + - 4.0.0 org.codehaus.plexus plexus - 10 + 13 plexus-build-api @@ -26,10 +26,10 @@ See the Apache License Version 2.0 for the specific language governing permissio scm:git:https://github.com/codehaus-plexus/plexus-build-api.git scm:git:https://github.com/codehaus-plexus/plexus-build-api.git - https://github.com/codehaus-plexus/plexus-build-api HEAD + https://github.com/codehaus-plexus/plexus-build-api - + org.codehaus.plexus @@ -51,8 +51,8 @@ See the Apache License Version 2.0 for the specific language governing permissio - src/main/resources true + src/main/resources @@ -61,14 +61,14 @@ See the Apache License Version 2.0 for the specific language governing permissio sisu-maven-plugin 0.3.5 - - index-project - - main-index - test-index - - - + + index-project + + main-index + test-index + + + org.apache.maven.plugins diff --git a/src/main/java/org/codehaus/plexus/build/BuildContext.java b/src/main/java/org/codehaus/plexus/build/BuildContext.java index 48fee34..e13b37d 100644 --- a/src/main/java/org/codehaus/plexus/build/BuildContext.java +++ b/src/main/java/org/codehaus/plexus/build/BuildContext.java @@ -1,13 +1,13 @@ /* Copyright (c) 2008 Sonatype, Inc. All rights reserved. -This program is licensed to you under the Apache License Version 2.0, -and you may not use this file except in compliance with the Apache License Version 2.0. +This program is licensed to you under the Apache License Version 2.0, +and you may not use this file except in compliance with the Apache License Version 2.0. You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0. -Unless required by applicable law or agreed to in writing, -software distributed under the Apache License Version 2.0 is distributed on an -"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +Unless required by applicable law or agreed to in writing, +software distributed under the Apache License Version 2.0 is distributed on an +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. */ package org.codehaus.plexus.build; @@ -19,223 +19,222 @@ import org.codehaus.plexus.util.Scanner; - // TODO should it be BuildWorkspace or something like that? /** *

BuildContext interface.

*/ public interface BuildContext { - /** Constant SEVERITY_WARNING=1 */ - int SEVERITY_WARNING = 1; - - /** Constant SEVERITY_ERROR=2 */ - int SEVERITY_ERROR = 2; - - // TODO should we add File getBasedir()? - - /** - * Returns true if file or folder identified by relpath has - * changed since last build. - * - * @param relpath is path relative to build context basedir - * @return a boolean. - */ - boolean hasDelta(String relpath); - - /** - * Returns true if the file has changed since last build or is not - * under basedir. - * - * @since 0.0.5 - * @param file a {@link java.io.File} object. - * @return a boolean. - */ - boolean hasDelta(File file); - - /** - * Returns true if any file or folder identified by relpaths has - * changed since last build. - * - * @param relpaths paths relative to build context basedir - * @return a boolean. - */ - boolean hasDelta(List relpaths); - - /** - * Indicates that the file or folder content has been modified during the build. - * - * @see #newFileOutputStream(File) - * @param file a {@link java.io.File} object. - */ - void refresh(File file); - - /** - * Returns new OutputStream that writes to the file. - * - * Files changed using OutputStream returned by this method do not need to be - * explicitly refreshed using {@link #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. - * - * @param file a {@link java.io.File} object. - * @return a {@link java.io.OutputStream} object. - * @throws java.io.IOException if any. - */ - OutputStream newFileOutputStream(File file) throws IOException; - - /** - * Convenience method, fully equal to newScanner(basedir, false) - * - * @param basedir a {@link java.io.File} object. - * @return a {@link org.codehaus.plexus.util.Scanner} object. - */ - Scanner newScanner(File basedir); - - /** - * Returned Scanner scans basedir for files and directories - * deleted since last build. Returns empty Scanner if basedir - * is not under this build context basedir. - * - * @param basedir a {@link java.io.File} object. - * @return a {@link org.codehaus.plexus.util.Scanner} object. - */ - Scanner newDeleteScanner(File basedir); - - /** - * 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 {@link #isUptodate(File, File)} - * to optimized processing of uptodate target resources. - * - * Returns empty Scanner if basedir is not under this build context basedir. - * - * https://issues.apache.org/jira/browse/MSHARED-125 - * - * @param basedir a {@link java.io.File} object. - * @param ignoreDelta a boolean. - * @return a {@link org.codehaus.plexus.util.Scanner} object. - */ - Scanner newScanner(File basedir, boolean ignoreDelta); - - /** - * Returns true if this build context is incremental. - * - * Scanners created by {@link #newScanner(File)} of an incremental build context - * will ignore files and folders that were not changed since last build. - * Additionally, {@link #newDeleteScanner(File)} will scan files and directories - * deleted since last build. - * - * @return a boolean. - */ - boolean isIncremental(); - - /** - * 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. - * - * @see #getValue(String) - * @param key a {@link java.lang.String} object. - * @param value a {@link java.lang.Object} object. - */ - void setValue(String key, Object value); - - /** - * Returns value associated with key during previous mojo execution. - * - * This method always returns null for non-incremental builds - * (i.e., {@link #isIncremental()} returns false) and mojos are - * expected to fall back to full, non-incremental behaviour. - * - * @see #setValue(String, Object) - * @see #isIncremental() - * @param key a {@link java.lang.String} object. - * @return a {@link java.lang.Object} object. - */ - Object getValue(String key); - - /** - *

addWarning.

- * - * @deprecated Use addMessage with severity=SEVERITY_ERROR instead - * @since 0.0.5 - * @param file a {@link java.io.File} object. - * @param line a int. - * @param column a int. - * @param message a {@link java.lang.String} object. - * @param cause a {@link java.lang.Throwable} object. - */ - void addWarning(File file, int line, int column, String message, Throwable cause); - - /** - *

addError.

- * - * @deprecated Use addMessage with severity=SEVERITY_WARNING instead - * @since 0.0.5 - * @param file a {@link java.io.File} object. - * @param line a int. - * @param column a int. - * @param message a {@link java.lang.String} object. - * @param cause a {@link java.lang.Throwable} object. - */ - void addError(File file, int line, int column, String message, Throwable cause); - - /** - * Adds a message to the build context. The message is associated with a file and a location inside that file. - * - * @param file The file or folder with which the message is associated. Should not be null and it is recommended to be - * an absolute path. - * @param line The line number inside the file. Use 1 (not 0) for the first line. Use 0 for unknown/unspecified. - * @param column The column number inside the file. Use 1 (not 0) for the first column. Use 0 for unknown/unspecified. - * @param severity The severity of the message: SEVERITY_WARNING or SEVERITY_ERROR. - * @param cause A Throwable object associated with the message. Can be null. - * @since 0.0.7 - * @param message a {@link java.lang.String} object. - */ - void addMessage(File file, int line, int column, String message, int severity, Throwable cause); - - /** - * Removes all messages associated with a file or folder during a previous build. It does not affect the messages - * added during the current build. - * - * @since 0.0.7 - * @param file a {@link java.io.File} object. - */ - void removeMessages(File file); - - /** - * 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. - * - * @since 0.0.5 - * @param target a {@link java.io.File} object. - * @param source a {@link java.io.File} object. - * @return a boolean. - */ - boolean isUptodate(File target, File source); + /** Constant SEVERITY_WARNING=1 */ + int SEVERITY_WARNING = 1; + + /** Constant SEVERITY_ERROR=2 */ + int SEVERITY_ERROR = 2; + + // TODO should we add File getBasedir()? + + /** + * Returns true if file or folder identified by relpath has + * changed since last build. + * + * @param relpath is path relative to build context basedir + * @return a boolean. + */ + boolean hasDelta(String relpath); + + /** + * Returns true if the file has changed since last build or is not + * under basedir. + * + * @since 0.0.5 + * @param file a {@link java.io.File} object. + * @return a boolean. + */ + boolean hasDelta(File file); + + /** + * Returns true if any file or folder identified by relpaths has + * changed since last build. + * + * @param relpaths paths relative to build context basedir + * @return a boolean. + */ + boolean hasDelta(List relpaths); + + /** + * Indicates that the file or folder content has been modified during the build. + * + * @see #newFileOutputStream(File) + * @param file a {@link java.io.File} object. + */ + void refresh(File file); + + /** + * Returns new OutputStream that writes to the file. + * + * Files changed using OutputStream returned by this method do not need to be + * explicitly refreshed using {@link #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. + * + * @param file a {@link java.io.File} object. + * @return a {@link java.io.OutputStream} object. + * @throws java.io.IOException if any. + */ + OutputStream newFileOutputStream(File file) throws IOException; + + /** + * Convenience method, fully equal to newScanner(basedir, false) + * + * @param basedir a {@link java.io.File} object. + * @return a {@link org.codehaus.plexus.util.Scanner} object. + */ + Scanner newScanner(File basedir); + + /** + * Returned Scanner scans basedir for files and directories + * deleted since last build. Returns empty Scanner if basedir + * is not under this build context basedir. + * + * @param basedir a {@link java.io.File} object. + * @return a {@link org.codehaus.plexus.util.Scanner} object. + */ + Scanner newDeleteScanner(File basedir); + + /** + * 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 {@link #isUptodate(File, File)} + * to optimized processing of uptodate target resources. + * + * Returns empty Scanner if basedir is not under this build context basedir. + * + * https://issues.apache.org/jira/browse/MSHARED-125 + * + * @param basedir a {@link java.io.File} object. + * @param ignoreDelta a boolean. + * @return a {@link org.codehaus.plexus.util.Scanner} object. + */ + Scanner newScanner(File basedir, boolean ignoreDelta); + + /** + * Returns true if this build context is incremental. + * + * Scanners created by {@link #newScanner(File)} of an incremental build context + * will ignore files and folders that were not changed since last build. + * Additionally, {@link #newDeleteScanner(File)} will scan files and directories + * deleted since last build. + * + * @return a boolean. + */ + boolean isIncremental(); + + /** + * 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. + * + * @see #getValue(String) + * @param key a {@link java.lang.String} object. + * @param value a {@link java.lang.Object} object. + */ + void setValue(String key, Object value); + + /** + * Returns value associated with key during previous mojo execution. + * + * This method always returns null for non-incremental builds + * (i.e., {@link #isIncremental()} returns false) and mojos are + * expected to fall back to full, non-incremental behaviour. + * + * @see #setValue(String, Object) + * @see #isIncremental() + * @param key a {@link java.lang.String} object. + * @return a {@link java.lang.Object} object. + */ + Object getValue(String key); + + /** + *

addWarning.

+ * + * @deprecated Use addMessage with severity=SEVERITY_ERROR instead + * @since 0.0.5 + * @param file a {@link java.io.File} object. + * @param line a int. + * @param column a int. + * @param message a {@link java.lang.String} object. + * @param cause a {@link java.lang.Throwable} object. + */ + void addWarning(File file, int line, int column, String message, Throwable cause); + + /** + *

addError.

+ * + * @deprecated Use addMessage with severity=SEVERITY_WARNING instead + * @since 0.0.5 + * @param file a {@link java.io.File} object. + * @param line a int. + * @param column a int. + * @param message a {@link java.lang.String} object. + * @param cause a {@link java.lang.Throwable} object. + */ + void addError(File file, int line, int column, String message, Throwable cause); + + /** + * Adds a message to the build context. The message is associated with a file and a location inside that file. + * + * @param file The file or folder with which the message is associated. Should not be null and it is recommended to be + * an absolute path. + * @param line The line number inside the file. Use 1 (not 0) for the first line. Use 0 for unknown/unspecified. + * @param column The column number inside the file. Use 1 (not 0) for the first column. Use 0 for unknown/unspecified. + * @param severity The severity of the message: SEVERITY_WARNING or SEVERITY_ERROR. + * @param cause A Throwable object associated with the message. Can be null. + * @since 0.0.7 + * @param message a {@link java.lang.String} object. + */ + void addMessage(File file, int line, int column, String message, int severity, Throwable cause); + + /** + * Removes all messages associated with a file or folder during a previous build. It does not affect the messages + * added during the current build. + * + * @since 0.0.7 + * @param file a {@link java.io.File} object. + */ + void removeMessages(File file); + + /** + * 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. + * + * @since 0.0.5 + * @param target a {@link java.io.File} object. + * @param source a {@link java.io.File} object. + * @return a boolean. + */ + boolean isUptodate(File target, File source); } diff --git a/src/main/java/org/codehaus/plexus/build/DefaultBuildContext.java b/src/main/java/org/codehaus/plexus/build/DefaultBuildContext.java index 5b8c66c..3e02ed6 100644 --- a/src/main/java/org/codehaus/plexus/build/DefaultBuildContext.java +++ b/src/main/java/org/codehaus/plexus/build/DefaultBuildContext.java @@ -1,13 +1,13 @@ /* Copyright (c) 2008 Sonatype, Inc. All rights reserved. -This program is licensed to you under the Apache License Version 2.0, -and you may not use this file except in compliance with the Apache License Version 2.0. +This program is licensed to you under the Apache License Version 2.0, +and you may not use this file except in compliance with the Apache License Version 2.0. You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0. -Unless required by applicable law or agreed to in writing, -software distributed under the Apache License Version 2.0 is distributed on an -"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +Unless required by applicable law or agreed to in writing, +software distributed under the Apache License Version 2.0 is distributed on an +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. */ @@ -19,7 +19,6 @@ import java.io.File; import java.io.IOException; import java.io.OutputStream; -import java.nio.file.Files; import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; @@ -49,112 +48,114 @@ public class DefaultBuildContext implements BuildContext { private final Map contextMap = new ConcurrentHashMap<>(); - private final Logger logger = LoggerFactory.getLogger(DefaultBuildContext.class); - /** {@inheritDoc} */ - public boolean hasDelta(String relpath) { - return true; - } - - /** - *

hasDelta.

- * - * @param file a {@link java.io.File} object. - * @return a boolean. - */ - public boolean hasDelta(File file) { - return true; - } - - /** - *

hasDelta.

- * - * @param relpaths a {@link java.util.List} object. - * @return a boolean. - */ - public boolean hasDelta(List relpaths) { - return true; - } - - /** {@inheritDoc} */ - public OutputStream newFileOutputStream(File file) throws IOException { - return new CachingOutputStream(file.toPath()); - } - - /** {@inheritDoc} */ - public Scanner newScanner(File basedir) { - DirectoryScanner ds = new DirectoryScanner(); - ds.setBasedir(basedir); - return ds; - } - - /** {@inheritDoc} */ - public void refresh(File file) { - // do nothing - } - - /** {@inheritDoc} */ - public Scanner newDeleteScanner(File basedir) { - return new EmptyScanner(basedir); - } - - /** {@inheritDoc} */ - public Scanner newScanner(File basedir, boolean ignoreDelta) { - return newScanner(basedir); - } - - /** - *

isIncremental.

- * - * @return a boolean. - */ - public boolean isIncremental() { - return false; - } - - /** {@inheritDoc} */ - public Object getValue(String key) { - return contextMap.get(key); - } - - /** {@inheritDoc} */ - public void setValue(String key, Object value) { - contextMap.put(key, value); - } - - private String getMessage(File file, int line, int column, String message) { - return file.getAbsolutePath() + " [" + line + ':' + column + "]: " + message; - } - - /** {@inheritDoc} */ - public void addError(File file, int line, int column, String message, Throwable cause) { - addMessage(file, line, column, message, SEVERITY_ERROR, cause); - } - - /** {@inheritDoc} */ - public void addWarning(File file, int line, int column, String message, Throwable cause) { - addMessage(file, line, column, message, SEVERITY_WARNING, cause); - } - - /** {@inheritDoc} */ - public void addMessage(File file, int line, int column, String message, int severity, Throwable cause) { - switch(severity) { - case BuildContext.SEVERITY_ERROR: - logger.error(getMessage(file, line, column, message), cause); - return; - case BuildContext.SEVERITY_WARNING: - logger.warn(getMessage(file, line, column, message), cause); - return; - } - throw new IllegalArgumentException("severity=" + severity); - } - - /** {@inheritDoc} */ - public void removeMessages(File file) { - } - - /** {@inheritDoc} */ - public boolean isUptodate(File target, File source) { - return target != null && target.exists() && source != null && source.exists() - && target.lastModified() > source.lastModified(); - } + private final Logger logger = LoggerFactory.getLogger(DefaultBuildContext.class); + /** {@inheritDoc} */ + public boolean hasDelta(String relpath) { + return true; + } + + /** + *

hasDelta.

+ * + * @param file a {@link java.io.File} object. + * @return a boolean. + */ + public boolean hasDelta(File file) { + return true; + } + + /** + *

hasDelta.

+ * + * @param relpaths a {@link java.util.List} object. + * @return a boolean. + */ + public boolean hasDelta(List relpaths) { + return true; + } + + /** {@inheritDoc} */ + public OutputStream newFileOutputStream(File file) throws IOException { + return new CachingOutputStream(file.toPath()); + } + + /** {@inheritDoc} */ + public Scanner newScanner(File basedir) { + DirectoryScanner ds = new DirectoryScanner(); + ds.setBasedir(basedir); + return ds; + } + + /** {@inheritDoc} */ + public void refresh(File file) { + // do nothing + } + + /** {@inheritDoc} */ + public Scanner newDeleteScanner(File basedir) { + return new EmptyScanner(basedir); + } + + /** {@inheritDoc} */ + public Scanner newScanner(File basedir, boolean ignoreDelta) { + return newScanner(basedir); + } + + /** + *

isIncremental.

+ * + * @return a boolean. + */ + public boolean isIncremental() { + return false; + } + + /** {@inheritDoc} */ + public Object getValue(String key) { + return contextMap.get(key); + } + + /** {@inheritDoc} */ + public void setValue(String key, Object value) { + contextMap.put(key, value); + } + + private String getMessage(File file, int line, int column, String message) { + return file.getAbsolutePath() + " [" + line + ':' + column + "]: " + message; + } + + /** {@inheritDoc} */ + public void addError(File file, int line, int column, String message, Throwable cause) { + addMessage(file, line, column, message, SEVERITY_ERROR, cause); + } + + /** {@inheritDoc} */ + public void addWarning(File file, int line, int column, String message, Throwable cause) { + addMessage(file, line, column, message, SEVERITY_WARNING, cause); + } + + /** {@inheritDoc} */ + public void addMessage(File file, int line, int column, String message, int severity, Throwable cause) { + switch (severity) { + case BuildContext.SEVERITY_ERROR: + logger.error(getMessage(file, line, column, message), cause); + return; + case BuildContext.SEVERITY_WARNING: + logger.warn(getMessage(file, line, column, message), cause); + return; + } + throw new IllegalArgumentException("severity=" + severity); + } + + /** {@inheritDoc} */ + public void removeMessages(File file) {} + + /** {@inheritDoc} */ + public boolean isUptodate(File target, File source) { + return target != null + && target.exists() + && source != null + && source.exists() + && target.lastModified() > source.lastModified(); + } } diff --git a/src/main/java/org/codehaus/plexus/build/EmptyScanner.java b/src/main/java/org/codehaus/plexus/build/EmptyScanner.java index 106b9d9..99cd8a6 100644 --- a/src/main/java/org/codehaus/plexus/build/EmptyScanner.java +++ b/src/main/java/org/codehaus/plexus/build/EmptyScanner.java @@ -1,13 +1,13 @@ /* Copyright (c) 2008 Sonatype, Inc. All rights reserved. -This program is licensed to you under the Apache License Version 2.0, -and you may not use this file except in compliance with the Apache License Version 2.0. +This program is licensed to you under the Apache License Version 2.0, +and you may not use this file except in compliance with the Apache License Version 2.0. You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0. -Unless required by applicable law or agreed to in writing, -software distributed under the Apache License Version 2.0 is distributed on an -"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +Unless required by applicable law or agreed to in writing, +software distributed under the Apache License Version 2.0 is distributed on an +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. */ @@ -22,80 +22,72 @@ * Scanner implementation never finds any files/directories. */ public class EmptyScanner implements Scanner { - - private static final String[] EMPTY_STRING_ARRAY = new String[0]; - - private final File basedir; - - /** - *

Constructor for EmptyScanner.

- * - * @param basedir a {@link java.io.File} object. - */ - public EmptyScanner(File basedir) { - this.basedir = basedir; - } - - /** - *

addDefaultExcludes.

- */ - public void addDefaultExcludes() { - } - - /** - *

getIncludedDirectories.

- * - * @return an array of {@link java.lang.String} objects. - */ - public String[] getIncludedDirectories() { - return EMPTY_STRING_ARRAY; - } - - /** - *

getIncludedFiles.

- * - * @return an array of {@link java.lang.String} objects. - */ - public String[] getIncludedFiles() { - return EMPTY_STRING_ARRAY; - } - - /** - *

scan.

- */ - public void scan() { - } - - /** - *

setExcludes.

- * - * @param excludes an array of {@link java.lang.String} objects. - */ - public void setExcludes(String[] excludes) { - } - - /** - *

setIncludes.

- * - * @param includes an array of {@link java.lang.String} objects. - */ - public void setIncludes(String[] includes) { - } - - /** - *

Getter for the field basedir.

- * - * @return a {@link java.io.File} object. - */ - public File getBasedir() { - return basedir; - } - - /** {@inheritDoc} */ - @Override - public void setFilenameComparator( Comparator comparator ) - { - - } + private static final String[] EMPTY_STRING_ARRAY = new String[0]; + + private final File basedir; + + /** + *

Constructor for EmptyScanner.

+ * + * @param basedir a {@link java.io.File} object. + */ + public EmptyScanner(File basedir) { + this.basedir = basedir; + } + + /** + *

addDefaultExcludes.

+ */ + public void addDefaultExcludes() {} + + /** + *

getIncludedDirectories.

+ * + * @return an array of {@link java.lang.String} objects. + */ + public String[] getIncludedDirectories() { + return EMPTY_STRING_ARRAY; + } + + /** + *

getIncludedFiles.

+ * + * @return an array of {@link java.lang.String} objects. + */ + public String[] getIncludedFiles() { + return EMPTY_STRING_ARRAY; + } + + /** + *

scan.

+ */ + public void scan() {} + + /** + *

setExcludes.

+ * + * @param excludes an array of {@link java.lang.String} objects. + */ + public void setExcludes(String[] excludes) {} + + /** + *

setIncludes.

+ * + * @param includes an array of {@link java.lang.String} objects. + */ + public void setIncludes(String[] includes) {} + + /** + *

Getter for the field basedir.

+ * + * @return a {@link java.io.File} object. + */ + public File getBasedir() { + return basedir; + } + + /** {@inheritDoc} */ + @Override + public void setFilenameComparator(Comparator comparator) {} } diff --git a/src/test/java/org/codehaus/plexus/build/test/TestFullBuildContext.java b/src/test/java/org/codehaus/plexus/build/test/TestFullBuildContext.java index be30fe9..2533138 100644 --- a/src/test/java/org/codehaus/plexus/build/test/TestFullBuildContext.java +++ b/src/test/java/org/codehaus/plexus/build/test/TestFullBuildContext.java @@ -1,13 +1,13 @@ /* Copyright (c) 2008 Sonatype, Inc. All rights reserved. -This program is licensed to you under the Apache License Version 2.0, -and you may not use this file except in compliance with the Apache License Version 2.0. +This program is licensed to you under the Apache License Version 2.0, +and you may not use this file except in compliance with the Apache License Version 2.0. You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0. -Unless required by applicable law or agreed to in writing, -software distributed under the Apache License Version 2.0 is distributed on an -"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +Unless required by applicable law or agreed to in writing, +software distributed under the Apache License Version 2.0 is distributed on an +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. */ @@ -17,17 +17,15 @@ import org.codehaus.plexus.build.DefaultBuildContext; - public class TestFullBuildContext extends DefaultBuildContext { - private final Map context; - - public TestFullBuildContext(Map context) { - this.context = context; - } + private final Map context; - public void setValue(String key, Object value) { - context.put(key, value); - } + public TestFullBuildContext(Map context) { + this.context = context; + } + public void setValue(String key, Object value) { + context.put(key, value); + } } diff --git a/src/test/java/org/codehaus/plexus/build/test/TestIncrementalBuildContext.java b/src/test/java/org/codehaus/plexus/build/test/TestIncrementalBuildContext.java index 2779d31..3dedd24 100644 --- a/src/test/java/org/codehaus/plexus/build/test/TestIncrementalBuildContext.java +++ b/src/test/java/org/codehaus/plexus/build/test/TestIncrementalBuildContext.java @@ -1,13 +1,13 @@ /* Copyright (c) 2008 Sonatype, Inc. All rights reserved. -This program is licensed to you under the Apache License Version 2.0, -and you may not use this file except in compliance with the Apache License Version 2.0. +This program is licensed to you under the Apache License Version 2.0, +and you may not use this file except in compliance with the Apache License Version 2.0. You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0. -Unless required by applicable law or agreed to in writing, -software distributed under the Apache License Version 2.0 is distributed on an -"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +Unless required by applicable law or agreed to in writing, +software distributed under the Apache License Version 2.0 is distributed on an +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the Apache License Version 2.0 for the specific language governing permissions and limitations there under. */ @@ -31,175 +31,169 @@ public class TestIncrementalBuildContext implements BuildContext { - private final File basedir; + private final File basedir; - private final Set refresh = new HashSet<>(); + private final Set refresh = new HashSet<>(); - private static final class TestScanner implements Scanner { - private final File basedir; - private final Set files; + private static final class TestScanner implements Scanner { + private final File basedir; + private final Set files; - private TestScanner(File basedir, Set files) { - this.basedir = basedir; - this.files = files; - } + private TestScanner(File basedir, Set files) { + this.basedir = basedir; + this.files = files; + } + + public void addDefaultExcludes() {} + + public String[] getIncludedDirectories() { + return new String[0]; + } + + public String[] getIncludedFiles() { + return (String[]) files.toArray(new String[0]); + } + + public void scan() {} + + public void setExcludes(String[] excludes) {} - public void addDefaultExcludes() { + public void setIncludes(String[] includes) {} + + public File getBasedir() { + return basedir; + } + + @Override + public void setFilenameComparator(Comparator filenameComparator) {} } - public String[] getIncludedDirectories() { - return new String[0]; + private final Set changedFiles; + + private final Set deletedFiles; + + private final Map context; + + private final List warnings; + + private final List errors; + + public TestIncrementalBuildContext(File basedir, Set changedFiles, Map context) { + this(basedir, changedFiles, new HashSet(), context); } - public String[] getIncludedFiles() { - return (String[]) files.toArray(new String[0]); + public TestIncrementalBuildContext(File basedir, Set changedFiles, Set deletedFiles, Map context) { + this(basedir, changedFiles, deletedFiles, context, new ArrayList(), new ArrayList()); } - public void scan() { + public TestIncrementalBuildContext( + File basedir, Set changedFiles, Set deletedFiles, Map context, List warnings, List errors) { + this.basedir = basedir; + this.changedFiles = changedFiles; + this.deletedFiles = deletedFiles; + this.context = context; + this.warnings = warnings; + this.errors = errors; } - public void setExcludes(String[] excludes) { + public boolean hasDelta(String relpath) { + String basepath = basedir.getAbsolutePath(); + + if (relpath.startsWith(basepath)) { + relpath = relpath.substring(basepath.length() + 1); + } + + return changedFiles.contains(relpath) || deletedFiles.contains(relpath); } - public void setIncludes(String[] includes) { + public boolean hasDelta(List relpaths) { + for (Iterator i = relpaths.iterator(); i.hasNext(); ) { + String relpath = i.next(); + if (hasDelta(relpath)) { + return true; + } + } + return false; } - public File getBasedir() { - return basedir; + public boolean hasDelta(File file) { + String relpath = getRelpath(file); + return relpath == null || hasDelta(relpath); } - @Override - public void setFilenameComparator( Comparator filenameComparator ) - { + private String getRelpath(File file) { + try { + String path = file.getCanonicalPath(); + String basepath = basedir.getCanonicalPath(); + if (path.startsWith(basepath) && !path.equals(basepath)) { + return path.substring(basepath.length()); + } else { + return null; + } + } catch (IOException e) { + // this is a test implementation, we can be little loose here + throw new IllegalArgumentException(e); + } + } + public boolean isIncremental() { + return true; } - } - private final Set changedFiles; + public Scanner newDeleteScanner(File basedir) { + return new TestScanner(basedir, deletedFiles); + } - private final Set deletedFiles; + public OutputStream newFileOutputStream(File file) throws IOException { + refresh(file); + return new FileOutputStream(file); + } - private final Map context; + public Scanner newScanner(final File basedir) { + return new TestScanner(basedir, changedFiles); + } - private final List warnings; - - private final List errors; + public Scanner newScanner(File basedir, boolean ignoreDelta) { + if (ignoreDelta) { + DirectoryScanner directoryScanner = new DirectoryScanner(); + directoryScanner.setBasedir(basedir); + return directoryScanner; + } - public TestIncrementalBuildContext(File basedir, Set changedFiles, Map context) { - this(basedir, changedFiles, new HashSet(), context); - } + return newScanner(basedir); + } - public TestIncrementalBuildContext(File basedir, Set changedFiles, Set deletedFiles, Map context) { - this(basedir, changedFiles, deletedFiles, context, new ArrayList(), new ArrayList()); - } + public void refresh(File file) { + refresh.add(file.getAbsoluteFile()); + } - public TestIncrementalBuildContext(File basedir, Set changedFiles, Set deletedFiles, Map context, List warnings, List errors) { - this.basedir = basedir; - this.changedFiles = changedFiles; - this.deletedFiles = deletedFiles; - this.context = context; - this.warnings = warnings; - this.errors = errors; - } + public Object getValue(String key) { + return context.get(key); + } - public boolean hasDelta(String relpath) { - String basepath = basedir.getAbsolutePath(); + public void setValue(String key, Object value) { + context.put(key, value); + } - if (relpath.startsWith(basepath)) { - relpath = relpath.substring(basepath.length() + 1); + public Set getRefreshFiles() { + return refresh; } - return changedFiles.contains(relpath) || deletedFiles.contains(relpath); - } + public void addError(File file, int line, int column, String message, Throwable cause) {} - public boolean hasDelta(List relpaths) { - for(Iterator i = relpaths.iterator(); i.hasNext();) { - String relpath = i.next(); - if(hasDelta(relpath)) { - return true; - } - } - return false; - } - - public boolean hasDelta(File file) { - String relpath = getRelpath(file); - return relpath == null || hasDelta(relpath); - } - - private String getRelpath(File file) { - try { - String path = file.getCanonicalPath(); - String basepath = basedir.getCanonicalPath(); - if (path.startsWith(basepath) && !path.equals(basepath)) { - return path.substring(basepath.length()); - } else { - return null; - } - } catch (IOException e) { - // this is a test implementation, we can be little loose here - throw new IllegalArgumentException(e); - } - } - -public boolean isIncremental() { - return true; - } - - public Scanner newDeleteScanner(File basedir) { - return new TestScanner(basedir, deletedFiles); - } - - public OutputStream newFileOutputStream(File file) throws IOException { - refresh(file); - return new FileOutputStream(file); - } - - public Scanner newScanner(final File basedir) { - return new TestScanner(basedir, changedFiles); - } - - public Scanner newScanner(File basedir, boolean ignoreDelta) { - if(ignoreDelta) { - DirectoryScanner directoryScanner = new DirectoryScanner(); - directoryScanner.setBasedir(basedir); - return directoryScanner; - } - - return newScanner(basedir); - } - - public void refresh(File file) { - refresh.add(file.getAbsoluteFile()); - } - - public Object getValue(String key) { - return context.get(key); - } - - public void setValue(String key, Object value) { - context.put(key, value); - } - - public Set getRefreshFiles() { - return refresh; - } - - public void addError(File file, int line, int column, String message, Throwable cause) { - } - - public void addWarning(File file, int line, int column, String message, Throwable cause) { - } - - public void addMessage(File file, int line, int column, String message, int severity, Throwable cause) { - } - - public void removeMessages(File file) { - } - - public boolean isUptodate(File target, File source) { - return target != null && target.exists() && !hasDelta(target) - && source != null && source.exists() && !hasDelta(source) - && target.lastModified() > source.lastModified(); - } + public void addWarning(File file, int line, int column, String message, Throwable cause) {} + + public void addMessage(File file, int line, int column, String message, int severity, Throwable cause) {} + + public void removeMessages(File file) {} + + public boolean isUptodate(File target, File source) { + return target != null + && target.exists() + && !hasDelta(target) + && source != null + && source.exists() + && !hasDelta(source) + && target.lastModified() > source.lastModified(); + } }