relpaths) {
- return true;
+ return legacy.hasDelta(relpaths);
}
/** {@inheritDoc} */
public OutputStream newFileOutputStream(File file) throws IOException {
- return new CachingOutputStream(file.toPath());
+ if (isDefaultImplementation()) {
+ return new CachingOutputStream(file.toPath());
+ }
+ return legacy.newFileOutputStream(file);
+ }
+
+ /**
+ * @return true
if the legacy is the default implementation and we
+ * can safely override/change behavior here, or false
if a
+ * custom implementation is used and full delegation is required.
+ */
+ private boolean isDefaultImplementation() {
+ return legacy.getClass().equals(org.sonatype.plexus.build.incremental.DefaultBuildContext.class);
}
/** {@inheritDoc} */
public Scanner newScanner(File basedir) {
- DirectoryScanner ds = new DirectoryScanner();
- ds.setBasedir(basedir);
- return ds;
+ return legacy.newScanner(basedir);
}
/** {@inheritDoc} */
public void refresh(File file) {
- // do nothing
+ legacy.refresh(file);
}
/** {@inheritDoc} */
public Scanner newDeleteScanner(File basedir) {
- return new EmptyScanner(basedir);
+ return legacy.newDeleteScanner(basedir);
}
/** {@inheritDoc} */
public Scanner newScanner(File basedir, boolean ignoreDelta) {
- return newScanner(basedir);
+ return legacy.newScanner(basedir, ignoreDelta);
}
/**
@@ -107,7 +135,7 @@ public Scanner newScanner(File basedir, boolean ignoreDelta) {
* @return a boolean.
*/
public boolean isIncremental() {
- return false;
+ return legacy.isIncremental();
}
/** {@inheritDoc} */
@@ -120,10 +148,6 @@ 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);
@@ -134,28 +158,38 @@ public void addWarning(File file, int line, int column, String message, Throwabl
addMessage(file, line, column, message, SEVERITY_WARNING, cause);
}
+ private String getMessage(File file, int line, int column, String message) {
+ return file.getAbsolutePath() + " [" + line + ':' + column + "]: " + message;
+ }
+
/** {@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;
+ if (isDefaultImplementation()) {
+ 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;
+ default:
+ logger.debug(getMessage(file, line, column, message), cause);
+ return;
+ }
}
- throw new IllegalArgumentException("severity=" + severity);
+ legacy.addMessage(file, line, column, message, severity, cause);
}
/** {@inheritDoc} */
- public void removeMessages(File file) {}
+ public void removeMessages(File file) {
+ if (isDefaultImplementation()) {
+ return;
+ }
+ legacy.removeMessages(file);
+ }
/** {@inheritDoc} */
public boolean isUptodate(File target, File source) {
- return target != null
- && target.exists()
- && source != null
- && source.exists()
- && target.lastModified() > source.lastModified();
+ return legacy.isUptodate(target, source);
}
}
diff --git a/src/main/java/org/codehaus/plexus/build/EmptyScanner.java b/src/main/java/org/codehaus/plexus/build/EmptyScanner.java
deleted file mode 100644
index 99cd8a6..0000000
--- a/src/main/java/org/codehaus/plexus/build/EmptyScanner.java
+++ /dev/null
@@ -1,93 +0,0 @@
-/*
-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.
-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.
-See the Apache License Version 2.0 for the specific language governing permissions and limitations there under.
-*/
-
-package org.codehaus.plexus.build;
-
-import java.io.File;
-import java.util.Comparator;
-
-import org.codehaus.plexus.util.Scanner;
-
-/**
- * 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) {}
-}
diff --git a/src/test/java/org/codehaus/plexus/build/test/TestFullBuildContext.java b/src/test/java/org/codehaus/plexus/build/test/TestFullBuildContext.java
deleted file mode 100644
index 2533138..0000000
--- a/src/test/java/org/codehaus/plexus/build/test/TestFullBuildContext.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
-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.
-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.
-See the Apache License Version 2.0 for the specific language governing permissions and limitations there under.
-*/
-
-package org.codehaus.plexus.build.test;
-
-import java.util.Map;
-
-import org.codehaus.plexus.build.DefaultBuildContext;
-
-public class TestFullBuildContext extends DefaultBuildContext {
-
- private final Map context;
-
- 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
deleted file mode 100644
index 3dedd24..0000000
--- a/src/test/java/org/codehaus/plexus/build/test/TestIncrementalBuildContext.java
+++ /dev/null
@@ -1,199 +0,0 @@
-/*
-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.
-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.
-See the Apache License Version 2.0 for the specific language governing permissions and limitations there under.
-*/
-
-package org.codehaus.plexus.build.test;
-
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.OutputStream;
-import java.util.ArrayList;
-import java.util.Comparator;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import org.codehaus.plexus.build.BuildContext;
-import org.codehaus.plexus.util.DirectoryScanner;
-import org.codehaus.plexus.util.Scanner;
-
-public class TestIncrementalBuildContext implements BuildContext {
-
- private final File basedir;
-
- private final Set refresh = new HashSet<>();
-
- 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;
- }
-
- 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 setIncludes(String[] includes) {}
-
- public File getBasedir() {
- return basedir;
- }
-
- @Override
- public void setFilenameComparator(Comparator filenameComparator) {}
- }
-
- 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 TestIncrementalBuildContext(File basedir, Set changedFiles, Set deletedFiles, Map context) {
- this(basedir, changedFiles, deletedFiles, context, new ArrayList(), new ArrayList());
- }
-
- 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 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 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();
- }
-}