ASF Bugzilla – Attachment 17386 Details for
Bug 30094
Performance enhancements using java.nio & lazy calls
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
lazy init changes against Ant 1.6.5, in unified diff format
ant-lazy-init.diff (text/plain), 22.20 KB, created by
Robin Verduijn
on 2006-01-11 18:53:10 UTC
(
hide
)
Description:
lazy init changes against Ant 1.6.5, in unified diff format
Filename:
MIME Type:
Creator:
Robin Verduijn
Created:
2006-01-11 18:53:10 UTC
Size:
22.20 KB
patch
obsolete
>diff -ur apache-ant-1.6.5.orig/src/main/org/apache/tools/ant/DirectoryScanner.java apache-ant-1.6.5/src/main/org/apache/tools/ant/DirectoryScanner.java >--- apache-ant-1.6.5.orig/src/main/org/apache/tools/ant/DirectoryScanner.java 2006-01-11 12:37:20.294347500 -0500 >+++ apache-ant-1.6.5/src/main/org/apache/tools/ant/DirectoryScanner.java 2006-01-11 11:50:19.068261900 -0500 >@@ -32,6 +32,7 @@ > import org.apache.tools.ant.taskdefs.condition.Os; > import org.apache.tools.ant.types.Resource; > import org.apache.tools.ant.types.ResourceFactory; >+import org.apache.tools.ant.types.ResourceFile; > import org.apache.tools.ant.types.selectors.FileSelector; > import org.apache.tools.ant.types.selectors.SelectorUtils; > import org.apache.tools.ant.types.selectors.SelectorScanner; >@@ -1476,8 +1477,7 @@ > */ > public synchronized Resource getResource(String name) { > File f = FILE_UTILS.resolveFile(basedir, name); >- return new Resource(name, f.exists(), f.lastModified(), >- f.isDirectory(), f.length()); >+ return new ResourceFile(name, f); > } > > /** >diff -ur apache-ant-1.6.5.orig/src/main/org/apache/tools/ant/taskdefs/Length.java apache-ant-1.6.5/src/main/org/apache/tools/ant/taskdefs/Length.java >--- apache-ant-1.6.5.orig/src/main/org/apache/tools/ant/taskdefs/Length.java 2006-01-11 12:37:20.309972700 -0500 >+++ apache-ant-1.6.5/src/main/org/apache/tools/ant/taskdefs/Length.java 2006-01-11 11:50:19.068261900 -0500 >@@ -31,6 +31,7 @@ > import org.apache.tools.ant.taskdefs.condition.Condition; > import org.apache.tools.ant.types.FileSet; > import org.apache.tools.ant.types.Resource; >+import org.apache.tools.ant.types.ResourceFile; > import org.apache.tools.ant.types.EnumeratedAttribute; > import org.apache.tools.ant.util.FileUtils; > >@@ -220,10 +221,12 @@ > } else { > //force a full path: > File basedir = ds.getBasedir(); >- String s = FileUtils.getFileUtils().resolveFile( >- basedir, r.getName()).getAbsolutePath(); >- h.handle(new Resource(s, true, >- r.getLastModified(), false, r.getSize())); >+ File file = FileUtils.getFileUtils().resolveFile(basedir, r.getName()); >+ String name = file.getAbsolutePath(); >+ ResourceFile rf = new ResourceFile(name, file); >+ rf.setExists(true); >+ rf.setDirectory(false); >+ h.handle(rf); > } > } > } >diff -ur apache-ant-1.6.5.orig/src/main/org/apache/tools/ant/types/Resource.java apache-ant-1.6.5/src/main/org/apache/tools/ant/types/Resource.java >--- apache-ant-1.6.5.orig/src/main/org/apache/tools/ant/types/Resource.java 2006-01-11 12:37:20.309972700 -0500 >+++ apache-ant-1.6.5/src/main/org/apache/tools/ant/types/Resource.java 2006-01-11 11:50:19.083885800 -0500 >@@ -25,78 +25,16 @@ > * > * @since Ant 1.5.2 > */ >-public class Resource implements Cloneable, Comparable { >+public abstract class Resource implements Cloneable, Comparable { >+ protected String name = null; >+ > /** Constant unknown size */ > public static final long UNKNOWN_SIZE = -1; > >- private String name = null; >- private boolean exists = true; >- private long lastmodified = 0; >- private boolean directory = false; >- private long size = UNKNOWN_SIZE; >- > /** > * Default constructor. > */ >- public Resource() { >- } >- >- /** >- * Only sets the name. >- * >- * <p>This is a dummy, used for not existing resources.</p> >- * >- * @param name relative path of the resource. Expects >- * "/" to be used as the directory separator. >- */ >- public Resource(String name) { >- this(name, false, 0, false); >- } >- >- /** >- * Sets the name, lastmodified flag, and exists flag. >- * >- * @param name relative path of the resource. Expects >- * "/" to be used as the directory separator. >- * @param exists if true, this resource exists. >- * @param lastmodified the last modification time of this resource. >- */ >- public Resource(String name, boolean exists, long lastmodified) { >- this(name, exists, lastmodified, false); >- } >- >- /** >- * Sets the name, lastmodified flag, exists flag, and directory flag. >- * >- * @param name relative path of the resource. Expects >- * "/" to be used as the directory separator. >- * @param exists if true the resource exists >- * @param lastmodified the last modification time of the resource >- * @param directory if true, this resource is a directory >- */ >- public Resource(String name, boolean exists, long lastmodified, >- boolean directory) { >- this(name, exists, lastmodified, directory, UNKNOWN_SIZE); >- } >- >- /** >- * Sets the name, lastmodified flag, exists flag, directory flag, and size. >- * >- * @param name relative path of the resource. Expects >- * "/" to be used as the directory separator. >- * @param exists if true the resource exists >- * @param lastmodified the last modification time of the resource >- * @param directory if true, this resource is a directory >- * @param size the size of this resource. >- */ >- public Resource(String name, boolean exists, long lastmodified, >- boolean directory, long size) { >- this.name = name; >- setName(name); >- setExists(exists); >- setLastModified(lastmodified); >- setDirectory(directory); >- setSize(size); >+ protected Resource() { > } > > /** >@@ -128,17 +66,13 @@ > * The exists attribute tells whether a file exists. > * @return true if this resource exists. > */ >- public boolean isExists() { >- return exists; >- } >+ public abstract boolean isExists(); > > /** > * Set the exists attribute. > * @param exists if true, this resource exists. > */ >- public void setExists(boolean exists) { >- this.exists = exists; >- } >+ public abstract void setExists(boolean exists); > > /** > * Tells the modification time in milliseconds since 01.01.1970 . >@@ -146,42 +80,32 @@ > * @return 0 if the resource does not exist to mirror the behavior > * of {@link java.io.File File}. > */ >- public long getLastModified() { >- return !exists || lastmodified < 0 ? 0L : lastmodified; >- } >+ public abstract long getLastModified(); > > /** > * Set the last modification attribute. > * @param lastmodified the modification time in milliseconds since 01.01.1970. > */ >- public void setLastModified(long lastmodified) { >- this.lastmodified = lastmodified; >- } >+ public abstract void setLastModified(long lastmodified); > > /** > * Tells if the resource is a directory. > * @return boolean flag indicating if the resource is a directory. > */ >- public boolean isDirectory() { >- return directory; >- } >+ public abstract boolean isDirectory(); > > /** > * Set the directory attribute. > * @param directory if true, this resource is a directory. > */ >- public void setDirectory(boolean directory) { >- this.directory = directory; >- } >+ public abstract void setDirectory(boolean directory); > > /** > * Set the size of this Resource. > * @param size the size, as a long. > * @since Ant 1.6.3 > */ >- public void setSize(long size) { >- this.size = (size > UNKNOWN_SIZE) ? size : UNKNOWN_SIZE; >- } >+ public abstract void setSize(long size); > > /** > * Get the size of this Resource. >@@ -189,9 +113,7 @@ > * compatibility with java.io.File), or UNKNOWN_SIZE if not known. > * @since Ant 1.6.3 > */ >- public long getSize() { >- return (exists) ? size : 0L; >- } >+ public abstract long getSize(); > > /** > * Clone this Resource. >diff -ur apache-ant-1.6.5.orig/src/main/org/apache/tools/ant/types/ResourceFile.java apache-ant-1.6.5/src/main/org/apache/tools/ant/types/ResourceFile.java >--- apache-ant-1.6.5.orig/src/main/org/apache/tools/ant/types/ResourceFile.java 2006-01-11 12:37:20.325597900 -0500 >+++ apache-ant-1.6.5/src/main/org/apache/tools/ant/types/ResourceFile.java 2006-01-11 11:50:19.083885800 -0500 >@@ -0,0 +1,197 @@ >+/* >+ * Created on Jul 10, 2004 >+ * >+ * TODO To change the template for this generated file go to >+ * Window - Preferences - Java - Code Style - Code Templates >+ */ >+package org.apache.tools.ant.types; >+ >+import java.io.*; >+ >+/** >+ * @author jbleijen >+ * >+ * TODO To change the template for this generated type comment go to Window - >+ * Preferences - Java - Code Style - Code Templates >+ */ >+public class ResourceFile extends Resource { >+ protected File file; >+ >+ private final static int UNKNOWN = 1; >+ >+ private final static int FILE_EXISTS = 2; >+ >+ private final static int FILE_DOES_NOT_EXISTS = 3; >+ >+ private final static int IS_DIRECTORY = 4; >+ >+ private final static int IS_NOT_DIRECTORY = 5; >+ >+ private int exists = UNKNOWN; >+ >+ private int isDir = UNKNOWN; >+ >+ private long lastModified = -1l; >+ >+ private long size = UNKNOWN_SIZE; >+ >+ /** >+ * only sets the name. >+ * >+ * <p> >+ * This is a dummy, used for not existing resources. >+ * </p> >+ * >+ * @param name >+ * relative path of the resource. Expects "/" to be >+ * used as the directory separator. >+ */ >+ public ResourceFile(String name) { >+ this(name, new File(name)); >+ } >+ >+ public ResourceFile(String name, File file) { >+ this.name = name; >+ this.file = file; >+ } >+ >+ /** >+ * the exists attribute tells whether a file exists >+ */ >+ public boolean isExists() { >+ validateFileExists(); >+ return exists == FILE_EXISTS; >+ } >+ >+ public void setExists(boolean exists) { >+ if (exists) { >+ this.exists = FILE_EXISTS; >+ } else { >+ this.exists = FILE_DOES_NOT_EXISTS; >+ } >+ } >+ >+ /** >+ * tells the modification time in milliseconds since 01.01.1970 of >+ * >+ * @return 0 if the resource does not exist to mirror the behavior of >+ * {@link java.io.File File}. >+ */ >+ public long getLastModified() { >+ if (!isExists()) >+ return 0; >+ if (lastModified == -1) { >+ lastModified = file.lastModified(); >+ } >+ return lastModified; >+ } >+ >+ public void setLastModified(long lastmodified) { >+ this.lastModified = lastmodified; >+ } >+ >+ /** >+ * tells if the resource is a directory >+ * >+ * @return boolean flag indicating if the resource is a directory >+ */ >+ public boolean isDirectory() { >+ validateFileIsDir(); >+ return isDir == IS_DIRECTORY; >+ } >+ >+ public void setDirectory(boolean directory) { >+ if (directory) { >+ this.isDir = IS_DIRECTORY; >+ } else { >+ this.isDir = IS_NOT_DIRECTORY; >+ } >+ } >+ >+ /** >+ * Get the size of this Resource. >+ * @return the size, as a long, 0 if the Resource does not exist (for >+ * compatibility with java.io.File), or UNKNOWN_SIZE if not known. >+ * @since Ant 1.6.3 >+ */ >+ public long getSize() { >+ if (!isExists()) { >+ return 0L; >+ } >+ validateFileSize(); >+ return size; >+ } >+ >+ /** >+ * Set the size of this Resource. >+ * @param size the size, as a long. >+ * @since Ant 1.6.3 >+ */ >+ public void setSize(long size) { >+ this.size = (size > UNKNOWN_SIZE) ? size : UNKNOWN_SIZE; >+ } >+ >+ /** >+ * @return copy of this >+ */ >+ public Object clone() { >+ return super.clone(); >+ } >+ >+ /** >+ * delegates to a comparison of names. >+ * >+ * @since Ant 1.6 >+ */ >+ public int compareTo(Object other) { >+ if (!(other instanceof Resource)) { >+ throw new IllegalArgumentException("Can only be compared with " >+ + "Resources"); >+ } >+ Resource r = (Resource) other; >+ return getName().compareTo(r.getName()); >+ } >+ >+ /* >+ * TODO >+ */ >+ protected void validateFileExists() { >+ if (exists == UNKNOWN) { >+ this.lastModified = file.lastModified(); >+ if (this.lastModified == 0l) { >+ this.exists = FILE_DOES_NOT_EXISTS; >+ } else { >+ this.exists = FILE_EXISTS; >+ } >+ } >+ } >+ >+ /* >+ * TODO @author jbleijen >+ * >+ */ >+ protected void validateFileIsDir() { >+ if (exists == FILE_DOES_NOT_EXISTS) { >+ isDir = IS_NOT_DIRECTORY; >+ return; >+ } >+ if (isDir == UNKNOWN) { >+ if (file.isDirectory()) { >+ isDir = IS_DIRECTORY; >+ } else { >+ isDir = IS_NOT_DIRECTORY; >+ } >+ } >+ } >+ >+ /* >+ * TODO @author rverduijn >+ * >+ */ >+ protected void validateFileSize() { >+ if (size == UNKNOWN_SIZE) { >+ this.size = file.length(); >+ } >+ } >+ >+} >diff -ur apache-ant-1.6.5.orig/src/main/org/apache/tools/ant/types/ResourceZipEntry.java apache-ant-1.6.5/src/main/org/apache/tools/ant/types/ResourceZipEntry.java >--- apache-ant-1.6.5.orig/src/main/org/apache/tools/ant/types/ResourceZipEntry.java 2006-01-11 12:37:20.325597900 -0500 >+++ apache-ant-1.6.5/src/main/org/apache/tools/ant/types/ResourceZipEntry.java 2006-01-11 11:50:19.130757500 -0500 >@@ -0,0 +1,149 @@ >+/* >+ * Created on Jul 10, 2004 >+ * >+ * TODO To change the template for this generated file go to >+ * Window - Preferences - Java - Code Style - Code Templates >+ */ >+package org.apache.tools.ant.types; >+ >+/** >+ * @author jbleijen >+ * >+ * TODO To change the template for this generated type comment go to >+ * Window - Preferences - Java - Code Style - Code Templates >+ */ >+public class ResourceZipEntry extends Resource >+{ >+ protected boolean exists = true; >+ protected long lastmodified = 0; >+ protected boolean directory = false; >+ protected long size = UNKNOWN_SIZE; >+ >+ /** >+ * only sets the name. >+ * >+ * <p>This is a dummy, used for not existing resources.</p> >+ * >+ * @param name relative path of the resource. Expects >+ * "/" to be used as the directory separator. >+ */ >+ public ResourceZipEntry(String name) { >+ this(name, false, 0, false); >+ } >+ >+ /** >+ * sets the name, lastmodified flag, and exists flag >+ * >+ * @param name relative path of the resource. Expects >+ * "/" to be used as the directory separator. >+ */ >+ public ResourceZipEntry(String name, boolean exists, long lastmodified) { >+ this(name, exists, lastmodified, false); >+ } >+ >+ /** >+ * @param name relative path of the resource. Expects >+ * "/" to be used as the directory separator. >+ */ >+ public ResourceZipEntry(String name, boolean exists, long lastmodified, >+ boolean directory) { >+ this(name, exists, lastmodified, directory, UNKNOWN_SIZE); >+ } >+ >+ /** >+ * Sets the name, lastmodified flag, exists flag, directory flag, and size. >+ * >+ * @param name relative path of the resource. Expects >+ * "/" to be used as the directory separator. >+ * @param exists if true the resource exists >+ * @param lastmodified the last modification time of the resource >+ * @param directory if true, this resource is a directory >+ * @param size the size of this resource. >+ */ >+ public ResourceZipEntry(String name, boolean exists, long lastmodified, >+ boolean directory, long size) { >+ this.name = name; >+ setName(name); >+ setExists(exists); >+ setLastModified(lastmodified); >+ setDirectory(directory); >+ setSize(size); >+ } >+ >+ /** >+ * the exists attribute tells whether a file exists >+ */ >+ public boolean isExists() { >+ return exists; >+ } >+ >+ public void setExists(boolean exists) { >+ this.exists = exists; >+ } >+ >+ /** >+ * tells the modification time in milliseconds since 01.01.1970 of >+ * >+ * @return 0 if the resource does not exist to mirror the behavior >+ * of {@link java.io.File File}. >+ */ >+ public long getLastModified() { >+ return !exists || lastmodified < 0 ? 0 : lastmodified; >+ } >+ >+ public void setLastModified(long lastmodified) { >+ this.lastmodified = lastmodified; >+ } >+ >+ /** >+ * tells if the resource is a directory >+ * @return boolean flag indicating if the resource is a directory >+ */ >+ public boolean isDirectory() { >+ return directory; >+ } >+ >+ public void setDirectory(boolean directory) { >+ this.directory = directory; >+ } >+ >+ /** >+ * Get the size of this Resource. >+ * @return the size, as a long, 0 if the Resource does not exist (for >+ * compatibility with java.io.File), or UNKNOWN_SIZE if not known. >+ * @since Ant 1.6.3 >+ */ >+ public long getSize() { >+ return (isExists()) ? size : 0L; >+ } >+ >+ /** >+ * Set the size of this Resource. >+ * @param size the size, as a long. >+ * @since Ant 1.6.3 >+ */ >+ public void setSize(long size) { >+ this.size = (size > UNKNOWN_SIZE) ? size : UNKNOWN_SIZE; >+ } >+ >+ /** >+ * @return copy of this >+ */ >+ public Object clone() { >+ return super.clone(); >+ } >+ >+ /** >+ * delegates to a comparison of names. >+ * >+ * @since Ant 1.6 >+ */ >+ public int compareTo(Object other) { >+ if (!(other instanceof ResourceZipEntry)) { >+ throw new IllegalArgumentException("Can only be compared with " >+ + "Resources"); >+ } >+ ResourceZipEntry r = (ResourceZipEntry) other; >+ return getName().compareTo(r.getName()); >+ } >+} >diff -ur apache-ant-1.6.5.orig/src/main/org/apache/tools/ant/types/ZipScanner.java apache-ant-1.6.5/src/main/org/apache/tools/ant/types/ZipScanner.java >--- apache-ant-1.6.5.orig/src/main/org/apache/tools/ant/types/ZipScanner.java 2006-01-11 12:37:20.341223100 -0500 >+++ apache-ant-1.6.5/src/main/org/apache/tools/ant/types/ZipScanner.java 2006-01-11 11:50:19.130757500 -0500 >@@ -174,7 +174,7 @@ > return super.getResource(name); > } else if (name.equals("")) { > // special case in ZIPs, we do not want this thing included >- return new Resource("", true, Long.MAX_VALUE, true); >+ return new ResourceZipEntry("", true, Long.MAX_VALUE, true); > } > > // first check if the archive needs to be scanned again >@@ -184,7 +184,7 @@ > } else if (myentries.containsKey(name + "/")) { > return (Resource) myentries.get(name + "/"); > } else { >- return new Resource(name); >+ return new ResourceZipEntry(name); > } > } > >@@ -196,7 +196,7 @@ > * type > */ > private void scanme() { >- Resource thisresource = new Resource(srcFile.getAbsolutePath(), >+ Resource thisresource = new ResourceZipEntry(srcFile.getAbsolutePath(), > srcFile.exists(), > srcFile.lastModified()); > >@@ -224,7 +224,7 @@ > while (e.hasMoreElements()) { > entry = (ZipEntry) e.nextElement(); > myentries.put(new String(entry.getName()), >- new Resource(entry.getName(), true, >+ new ResourceZipEntry(entry.getName(), true, > entry.getTime(), > entry.isDirectory(), > entry.getSize())); >diff -ur apache-ant-1.6.5.orig/src/main/org/apache/tools/ant/util/ResourceUtils.java apache-ant-1.6.5/src/main/org/apache/tools/ant/util/ResourceUtils.java >--- apache-ant-1.6.5.orig/src/main/org/apache/tools/ant/util/ResourceUtils.java 2006-01-11 12:37:20.341223100 -0500 >+++ apache-ant-1.6.5/src/main/org/apache/tools/ant/util/ResourceUtils.java 2006-01-11 11:50:19.130757500 -0500 >@@ -81,11 +81,11 @@ > > Vector vresult = new Vector(); > for (int counter = 0; counter < source.length; counter++) { >- if (source[counter].getLastModified() > now) { >- logTo.log("Warning: " + source[counter].getName() >- + " modified in the future.", >- Project.MSG_WARN); >- } >+// if (source[counter].getLastModified() > now) { >+// logTo.log("Warning: " + source[counter].getName() >+// + " modified in the future.", >+// Project.MSG_WARN); >+// } > > String[] targetnames = > mapper.mapFileName(source[counter].getName() >diff -ur apache-ant-1.6.5.orig/src/main/org/apache/tools/ant/util/SourceFileScanner.java apache-ant-1.6.5/src/main/org/apache/tools/ant/util/SourceFileScanner.java >--- apache-ant-1.6.5.orig/src/main/org/apache/tools/ant/util/SourceFileScanner.java 2006-01-11 12:37:20.356848300 -0500 >+++ apache-ant-1.6.5/src/main/org/apache/tools/ant/util/SourceFileScanner.java 2006-01-11 11:50:19.130757500 -0500 >@@ -22,6 +22,7 @@ > import org.apache.tools.ant.Task; > import org.apache.tools.ant.types.ResourceFactory; > import org.apache.tools.ant.types.Resource; >+import org.apache.tools.ant.types.ResourceFile; > > /** > * Utility class that collects the functionality of the various >@@ -86,8 +87,9 @@ > Vector v = new Vector(); > for (int i = 0; i < files.length; i++) { > File src = fileUtils.resolveFile(srcDir, files[i]); >- v.addElement(new Resource(files[i], src.exists(), >- src.lastModified(), src.isDirectory())); >+ ResourceFile rf = new ResourceFile(files[i], src); >+ rf.setExists(true); >+ v.addElement(rf); > } > Resource[] sourceresources = new Resource[v.size()]; > v.copyInto(sourceresources); >@@ -141,8 +143,7 @@ > */ > public Resource getResource(String name) { > File src = fileUtils.resolveFile(destDir, name); >- return new Resource(name, src.exists(), src.lastModified(), >- src.isDirectory()); >+ return new ResourceFile(name, src); > } > } >
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 30094
:
12110
|
17385
| 17386 |
17388
|
17389
|
21368
|
21369