You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ant.apache.org by bo...@apache.org on 2008/11/17 10:39:24 UTC
svn commit: r718210 - in /ant/core/trunk/src/main/org/apache/tools/ant:
taskdefs/Touch.java types/resources/MappedResource.java
util/ResourceUtils.java
Author: bodewig
Date: Mon Nov 17 01:39:23 2008
New Revision: 718210
URL: http://svn.apache.org/viewvc?rev=718210&view=rev
Log:
use adapter for Touchable instead of instanceof checks
Modified:
ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Touch.java
ant/core/trunk/src/main/org/apache/tools/ant/types/resources/MappedResource.java
ant/core/trunk/src/main/org/apache/tools/ant/util/ResourceUtils.java
Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Touch.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Touch.java?rev=718210&r1=718209&r2=718210&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Touch.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Touch.java Mon Nov 17 01:39:23 2008
@@ -299,7 +299,8 @@
Iterator iter = resources.iterator();
while (iter.hasNext()) {
Resource r = (Resource) iter.next();
- if (!(r instanceof Touchable)) {
+ Touchable t = (Touchable) r.as(Touchable.class);
+ if (t == null) {
throw new BuildException("Can't touch " + r);
}
touch(r, defaultTimestamp);
@@ -343,7 +344,7 @@
// use this to create file and deal with non-writable files
touch(((FileProvider) r).getFile(), defaultTimestamp);
} else {
- ((Touchable) r).touch(defaultTimestamp);
+ ((Touchable) r.as(Touchable.class)).touch(defaultTimestamp);
}
} else {
String[] mapped = fileNameMapper.mapFileName(r.getName());
Modified: ant/core/trunk/src/main/org/apache/tools/ant/types/resources/MappedResource.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/types/resources/MappedResource.java?rev=718210&r1=718209&r2=718210&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/types/resources/MappedResource.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/types/resources/MappedResource.java Mon Nov 17 01:39:23 2008
@@ -38,6 +38,7 @@
public class MappedResource extends Resource {
private final Resource wrapped;
private final boolean isAppendable;
+ private final boolean isTouchable;
// should only be instantiated via factory, this also means we
// don't have to think about being a reference to a different
@@ -49,6 +50,7 @@
protected MappedResource(Resource r) {
wrapped = r;
isAppendable = wrapped.as(Appendable.class) != null;
+ isTouchable = wrapped.as(Touchable.class) != null;
}
/**
@@ -162,21 +164,19 @@
}
};
}
+ if (clazz == Touchable.class && isTouchable) {
+ return new Touchable() {
+ public void touch(long modTime) {
+ ((Touchable) wrapped.as(Touchable.class)).touch(modTime);
+ }
+ };
+ }
return super.as(clazz);
}
public static MappedResource map(Resource r) {
- if (r instanceof FileProvider) {
- if (r instanceof Touchable) {
- return new TouchableFileProviderMR(r);
- }
- return new FileProviderMR(r);
- }
- if (r instanceof Touchable) {
- return new TouchableMR(r);
- }
- // no special interface
- return new MappedResource(r);
+ return r instanceof FileProvider
+ ? new FileProviderMR(r) : new MappedResource(r);
}
private static class FileProviderMR extends MappedResource
@@ -201,48 +201,4 @@
}
}
- private static class TouchableMR extends MappedResource
- implements Touchable {
- private final Touchable t;
-
- protected TouchableMR(Resource r) {
- super(r);
- if (!(r instanceof Touchable)) {
- throw new IllegalArgumentException("trying to wrap something "
- + "that is not a "
- + " Touchable");
- }
- t = (Touchable) r;
- }
-
- /**
- * delegated to the wrapped resource.
- */
- public void touch(long m) {
- t.touch(m);
- }
- }
-
- private static class TouchableFileProviderMR extends FileProviderMR
- implements Touchable {
- private final Touchable t;
-
- protected TouchableFileProviderMR(Resource r) {
- super(r);
- if (!(r instanceof Touchable)) {
- throw new IllegalArgumentException("trying to wrap something "
- + "that is not a "
- + " Touchable");
- }
- t = (Touchable) r;
- }
-
- /**
- * delegated to the wrapped resource.
- */
- public void touch(long m) {
- t.touch(m);
- }
- }
-
}
\ No newline at end of file
Modified: ant/core/trunk/src/main/org/apache/tools/ant/util/ResourceUtils.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/util/ResourceUtils.java?rev=718210&r1=718209&r2=718210&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/util/ResourceUtils.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/util/ResourceUtils.java Mon Nov 17 01:39:23 2008
@@ -421,8 +421,11 @@
FileUtils.close(in);
}
}
- if (preserveLastModified && dest instanceof Touchable) {
- setLastModified((Touchable) dest, source.getLastModified());
+ if (preserveLastModified) {
+ Touchable t = (Touchable) dest.as(Touchable.class);
+ if (t != null) {
+ setLastModified(t, source.getLastModified());
+ }
}
}
// CheckStyle:ParameterNumberCheck ON