Patch was [jsword-devel] Feature found
DM Smith
dmsmith555 at yahoo.com
Fri May 21 12:58:49 MST 2004
Here is a patch that does option 3.
I have also made a change to core.xml to allow for junit to work.
I didn't zip it. I think that this e-mail does not modify the attachment
(like hotmail.com does)
DM Smith wrote:
> I found a "feature" which I am working on fixing.
>
> When the xsl is compiled for reuse, it works very well to check each
> time it is used to see if there is a change and recompile it when it
> does. The compilation is expensive so it is best for the user to compile
> it. And recompiling it when it changes allows a developer to bring up
> the application and test iterative changes to the xsl. It serves no
> advantage to a non-developer.
>
> The problem is when the xsl is in a jar the NetUtil.getLastModified
> returns the current time and the net result is that the xsl is compiled
> every time it is used.
>
> I see three possible solutions:
> 1) return 0 when the resource is in a jar. This is the simplest
> solution. The problem with this is that if there is any persistence of a
> n artifact based upon that timestamp, then it will not see any changes.
> 2) return the timestamp of the jar. So if there is persistence and the
> jar changes then it would force a recompile even if the xsl did not
> change. The basic thought is that the changes to the jar are going to be
> relatively infrequent and even recompiling the xsl once for each run of
> the application is not that big a deal.
> 3) return the timestamp on the file in the jar. This is a complete
> solution and matches the expectation of the method's contract.
>
> The form of the url that I am trying to work with is:
> jar:file:/a/b/c/jarname.jar!/x/y/filename.ext
>
> In this case I can pick off the file:.../jarname.jar and the
> .../filename.ext and use JarFile to get the JarEntry to interrogate.
>
> The problem is that the solution is still not completely generalized.
> What if the jar's file is served up via ftp or http. I don't know what
> that url would look like. Would it be something like:
> http:jar:file:.../jarname.jar!.../filename.ext.
>
> I am inclined to do nothing for this situation.
>
> On another note, I think Eclipse M9 is coming out later today. I have
> been using an integration build for the last week and it is better than M8.
-------------- next part --------------
Index: core.xml
===================================================================
RCS file: /cvs/jsword/common/core.xml,v
retrieving revision 1.5
diff -u -r1.5 core.xml
--- core.xml 16 May 2004 21:48:21 -0000 1.5
+++ core.xml 21 May 2004 20:00:38 -0000
@@ -16,7 +16,6 @@
<property name="source.java" value="java"/>
<property name="source.res" value="resource"/>
<property name="target.root" value="target/ant"/>
- <property name="target.output" value="${target.root}"/>
<property name="target.classes" value="${target.root}/classes"/>
<property name="target.jar" value="${target.root}/jar"/>
<property name="target.signed" value="${target.root}/signed"/>
@@ -56,23 +55,7 @@
=========================================================================-->
<path id="test.jarpath">
<fileset dir="${target.jar}" includes="*.jar"/>
- <fileset dir="${source.jar}" includes="**/junit*.jar"/>
- </path>
-
- <!--=======================================================================
- == This is a path to all of the jars in the project
- =========================================================================-->
- <path id="all.jarpath">
- <fileset dir="${target.jar}" includes="*.jar"/>
- <fileset dir="${source.jar}" includes="**/*.jar"/>
- </path>
-
- <!--=======================================================================
- == This is a path to all of the jars in the project
- =========================================================================-->
- <path id="testsource.jarpath">
- <fileset dir="${target.jar}" includes="*.jar"/>
- <fileset dir="${source.jar}" includes="**/*.jar"/>
+ <fileset dir="../common/jar" includes="**/junit*.jar"/>
</path>
<!--=======================================================================
@@ -90,23 +73,6 @@
<path id="testsource.path">
<dirset dir="${source.java}" includes="*test*"/>
</path>
-
- <!--=======================================================================
- == These are the non-test java files.
- == A test file is any file that has Test in its name.
- =========================================================================-->
- <patternset id="non.test.sources">
- <include name="**/*.java"/>
- <exclude name="**/*Test*"/>
- </patternset>
-
- <!--=======================================================================
- == These are the test java files.
- == A test file is any file that has Test in its name.
- =========================================================================-->
- <patternset id="test.sources">
- <include name="**/*Test*.java"/>
- </patternset>
<!--=======================================================================
== These are the non-java resource files
Index: java/core/org/crosswire/common/util/NetUtil.java
===================================================================
RCS file: /cvs/jsword/common/java/core/org/crosswire/common/util/NetUtil.java,v
retrieving revision 1.1
diff -u -r1.1 NetUtil.java
--- java/core/org/crosswire/common/util/NetUtil.java 20 Apr 2004 21:16:06 -0000 1.1
+++ java/core/org/crosswire/common/util/NetUtil.java 21 May 2004 20:00:45 -0000
@@ -13,6 +13,8 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
+import java.util.jar.JarEntry;
+import java.util.jar.JarFile;
import org.apache.commons.lang.StringUtils;
@@ -56,6 +58,11 @@
public static final String PROTOCOL_FILE = "file"; //$NON-NLS-1$
/**
+ * Constant for the jar: protocol
+ */
+ public static final String PROTOCOL_JAR = "jar"; //$NON-NLS-1$
+
+ /**
* For directory listings
*/
public static final String INDEX_FILE = "index.txt"; //$NON-NLS-1$
@@ -560,15 +567,35 @@
*/
public static long getLastModified(URL url)
{
+ if (url.getProtocol().equals(PROTOCOL_JAR))
+ {
+ // form is jar:file:.../xxx.jar!.../filename.ext
+ try {
+ String spec = url.getFile();
+ int bang = spec.indexOf('!');
+ String jar = spec.substring(0, bang);
+ url = new URL(jar); // Note: replacing input argument!!!
+ JarFile jarfile = new JarFile(url.getFile());
+ // Skip the ! and the leading /
+ String file = spec.substring(bang+2);
+ JarEntry jarEntry = jarfile.getJarEntry(file);
+ long time = jarEntry.getTime();
+ if (time != -1)
+ {
+ return time;
+ }
+ } catch (IOException e) {
+ log.debug("Could not get the file from the jar." + e);
+ }
+ // If we got here we did not get the timestamp of the file in the jar
+ // So now get the timestamp of the jar itself.
+ }
if (url.getProtocol().equals(PROTOCOL_FILE))
{
File file = new File(url.getFile());
return file.lastModified();
}
- else
- {
- return System.currentTimeMillis();
- }
+ return System.currentTimeMillis();
}
/**
More information about the jsword-devel
mailing list