icyphy / kepler-build

Build Kepler - the scientific workflow system
BSD 2-Clause "Simplified" License
4 stars 2 forks source link

Problem compling diva because of missing batik jar #2

Closed cxbrooks closed 2 years ago

cxbrooks commented 2 years ago

When running ant compile under JDK 8, batik was missing:

bash-3.2$ ant compile Buildfile: /Users/cxh/src/kepler-build/build-area/build.xml

compile: [echo] Note that you may need to run "ant force-ptolemy compile" to compile ptolemy. [compile] Compiling ptolemy... [compile] Compiling 1905 source files to /Users/cxh/src/kepler-build/ptolemy/target/classes [compile] /Users/cxh/src/kepler-build/ptolemy/src/diva/util/java2d/svg/SVGPaintedObject.java:46: error: package org.apache.batik.gvt does not exist [compile] import org.apache.batik.gvt.GraphicsNode; [compile] ^ [compile] /Users/cxh/src/kepler-build/ptolemy/src/diva/util/java2d/svg/SVGPaintedObject.java:47: error: package org.apache.batik.swing.svg does not exist [compile] import org.apache.batik.swing.svg.GVTTreeBuilderAdapter; [compile] ^

Running ant -d compile

adding /Users/cxh/src/kepler-build/ptolemy/lib/jar/ which contains wildcards and may not do what you intend it to do depending on your OS or version of Java adding /Users/cxh/src/kepler-build/ptolemy/src/lib/ which contains wildcards and may not do what you intend it to do depending on your OS or version of Java adding /Users/cxh/src/kepler-build/ptolemy/lib/jar/ which contains wildcards and may not do what you intend it to do depending on y or version of Java adding /Users/cxh/src/kepler-build/ptolemy/src/lib/ which contains wildcards and may not do what you intend it to do depending on your OS or version of Java

It turns out to be a problem with ant.

Ant 1.10.7 fails with the above message

bash-3.2$ ant -version
Apache Ant(TM) version 1.10.7 compiled on September 1 2019

The version of ant included in Ptolemy II works:

bash-3.2$ $PTII/bin/ant -version
/Users/cxh/src/ptII/bin/ant: Running /Users/cxh/src/ptII/ant/bin/ant -version
Apache Ant(TM) version 1.10.1 compiled on February 2 2017

See also

cxbrooks commented 2 years ago

The reason this did not show up in the build is that Travis Xenial (Ubuntu 16.x) uses ant:

Apache Ant(TM) version 1.9.6 compiled on July 20 2018

cxbrooks commented 2 years ago

This issue prevents upgrading to Ubuntu 20.x because under 20.x we are running

Apache Ant(TM) version 1.10.7 compiled on October 24 2019

cxbrooks commented 2 years ago

So, it is possible to edit kepler-build/build-area/src/org/kepler/build/project/CompileClasspath.java and add code like


                        FileSet fileSet = new FileSet();                                                                                                                                 
                        String[] includes = {"*.jar"};                                                                                                                                   
                        fileSet.setDir(file);                                                                                                                                            
                        fileSet.appendIncludes(includes);                                                                                                                                
                        jarPath.addFileset(fileSet);  

in two places and for the build to work with

bash-3.2$ ant -version
Apache Ant(TM) version 1.10.7 compiled on September 1 2019
bash-3.2$ java -version
openjdk version "11.0.2" 2019-01-15
OpenJDK Runtime Environment 18.9 (build 11.0.2+9)
OpenJDK 64-Bit Server VM 18.9 (build 11.0.2+9, mixed mode)
bash-3.2$ 

However, CompileClasspath.java says:

            // use wildcards to reduce the size of the classpath.                                                                                                                           
            // this gets around the maximum path length on windows.   

So, adding each jar file will probably break the build under Windows.

See junit: pathelement with wildcard fails running on java 11 - InvalidPathException: Illegal char <*> which discusses a possible fix in Java 12

However, compiling with

openjdk version "12.0.2" 2019-07-16

does not seem to have this fix, nor does

java 14.0.2 2020-07-14

It looks like the issue is that ant needs to fork the javac process?

cxbrooks commented 2 years ago

The summary is that it appears that javac does not properly handle wildcards in the classpath if the arguments are specified in a @argfile

If I have a BatikTest.java file that contains:

import org.apache.batik.swing.svg.JSVGComponent;

public class BatikTest {
    public static void main(String[] args) {
        System.out.print(System.getProperty("java.version"));
    }
}

and a batik-all-1.6.jar file that defines org.apache.batik.swing.svg.JSVGComponent:

bash-3.2$ ls lib/jar/
batik-all-1.6.jar
bash-3.2$

Then running from the command line works:

bash-3.2$ rm *.class; javac -verbose -classpath 'lib/jar/*:.' BatikTest.java
rm: *.class: No such file or directory
[parsing started SimpleFileObject[/Users/cxh/src/kepler-build/ptolemy/test/BatikTest.java]]
[parsing completed 22ms]
[loading /modules/jdk.crypto.cryptoki/module-info.class]
[loading /modules/jdk.localedata/module-info.class]
[loading /modules/jdk.jdi/module-info.class]
[loading /modules/jdk.internal.ed/module-info.class]
...
[search path for source files: lib/jar/batik-all-1.6.jar,.]
[search path for class files: /Library/Java/JavaVirtualMachines/openjdk/jdk-11.0.11+9/Contents/Home/lib/modules,lib/jar/batik-all-1.6.jar,.]
[loading /Users/cxh/src/kepler-build/ptolemy/test/lib/jar/batik-all-1.6.jar(/org/apache/batik/swing/svg/JSVGComponent.class)]
...
[wrote BatikTest.class]
[total 395ms]
bash-3.2$

However, using a @argfile to pass arguments does not work, note that the verbose output of javac does not include lib/jar/batik-all-1.6.jar:

bash-3.2$ cat argfile.txt
-verbose
-classpath
lib/jar/*:.
BatikTest.java
bash-3.2$ rm *.class; javac @argfile.txt
rm: *.class: No such file or directory
[parsing started SimpleFileObject[/Users/cxh/src/kepler-build/ptolemy/test/BatikTest.java]]
[parsing completed 20ms]
[loading /modules/jdk.jlink/module-info.class]
[loading /modules/jdk.jartool/module-info.class]
[loading /modules/java.net.http/module-info.class]
[loading /modules/jdk.scripting.nashorn.shell/module-info.class]
[loading /modules/java.naming/module-info.class]
...
[search path for source files: lib/jar/*,.]
[search path for class files: /Library/Java/JavaVirtualMachines/openjdk/jdk-11.0.11+9/Contents/Home/lib/modules,lib/jar/*,.]
BatikTest.java:3: error: package org.apache.batik.swing.svg does not exist
import org.apache.batik.swing.svg.JSVGComponent;
                                 ^
[loading /modules/java.base/java/lang/Object.class]
[total 279ms]
1 error
bash-3.2$ 

So, the fix is to modify build-area/src/org/kepler/build/project/CompileClasspath.java to expand the *. This might cause problems with Windows, but as ant presumably uses @argfile, then perhaps this won't be a problem.

https://ant.apache.org/manual/Tasks/javac.html says:

tempdir | Where Ant should place temporary files. This is only used if the task is forked and the command line args length exceeds 4 kB. Since Ant 1.6.

cxbrooks commented 2 years ago

Fixed! I needed to recompile kepler-tasks.jar with JDK 1.8 so that the JDK 9 build would work. The commands were:

cd kepler-build/build-area/
ant -f kepler-tasks.xml rejar
svn commit -m "Recompiled kepler-tasks.jar under JDK 1.8." ../kepler-tasks/lib/jar/kepler-tasks.jar target/kepler-tasks.jar

Kepler now compiles with Ubuntu 20.x (focal).