New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JycompileAntTask of Jython 2.7.1, cannot find org.python.apache.tools.ant.taskdefs.MatchingTask #109

Open
lee-csu opened this Issue Sep 7, 2018 · 5 comments

Comments

Projects
None yet
3 participants
@lee-csu

lee-csu commented Sep 7, 2018

when i use the JycompileAntTask of Jython 2.7.1 to compile the py to py.class, an error happend.

my usage is:
<plugin> <dependencies> <dependency> <groupId>org.python</groupId> <artifactId>jython-standalone</artifactId> <version>2.7.1</version> </dependency> </dependencies> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-antrun-plugin</artifactId> <version>1.6</version> <executions> <execution> <id>compile</id> <phase>compile</phase> <goals> <goal>run</goal> </goals> <configuration> <target name="pycompile" > <taskdef name="JycompileAntTask" classname="org.python.util.JycompileAntTask" /> <mkdir dir="src/main/release/etc/common" /> <JycompileAntTask srcdir="src/main/common" destdir="src/main/release/etc/common" /> </target> </configuration> </execution>

the error is:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-antrun-plugin:1.6:run (compile) on project : An Ant BuildException has occured: taskdef A class needed by class org.python.util.JycompileAntTask cannot be found: org/python/apache/tools/ant/taskdefs/MatchingTask
[ERROR] using the classloader AntClassLoader[]: org.python.apache.tools.ant.taskdefs.MatchingTask
[ERROR] -> [Help 1]
@tobias @groves @bzimmer @pjenvey @tlecomte

@jeff5

This comment has been minimized.

Member

jeff5 commented Sep 7, 2018

I haven't used the Jython Ant build from Maven, so this is untested functionality. However, let us assume it is possible and ought to work.

I recognise the missing class as one that would normally have been compiled earlier in the build.

The work I have done that is most similar to this is to develop a Gradle build. Here I am defining then calling the task you are having problems with. In my earlier failures I got messages of this general type. I had to take special care to add previously-compiled files to the path. I don't know the Maven idiom for that, but I don't see anything like it in your snippet.

In the Ant build proper, it looks like we build the dev jar first, and put that on the path of the newly-defined task, so this may be your answer.

@lee-csu

This comment has been minimized.

lee-csu commented Sep 8, 2018

@jeff5 , thanks for your answer, I studied it and this is my point of view. Add that, my project is a java maven project. And I use the jython-xxx.jar directly. we do not use the source code of jython.

Earlier, I used the Jython of version 2.5.3, and usage is the same, it worked fine.
<plugin> <dependencies> <dependency> <groupId>org.python</groupId> <artifactId>jython</artifactId> <version>2.5.3</version> </dependency> </dependencies> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-antrun-plugin</artifactId> <version>1.6</version> <executions> <execution> <id>compile</id> <phase>compile</phase> <goals> <goal>run</goal> </goals> <configuration> <target name="pycompile" > <taskdef name="JycompileAntTask" classname="org.python.util.JycompileAntTask"/> <mkdir dir="src/main/release/etc/collectscript/common" /> <JycompileAntTask srcdir="src/main/collectscript/common" destdir="src/main/release/etc/collectscript/common" /> </target> </configuration> </execution> <execution> <id>clean</id> <phase>clean</phase> <goals> <goal>run</goal> </goals> <configuration> <target> <delete dir="src/main/release/etc/collectscript" /> <delete dir="target" /> </target> </configuration> </execution> </executions> </plugin>

it can compile the .py files under 'src/main/collectscript/common' directory to .class files correctly. When I upgraded to the 2.7.1 version , the error happened.

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-antrun-plugin:1.6:run (compile) on project : An Ant BuildException has occured: taskdef A class needed by class org.python.util.JycompileAntTask cannot be found: org/python/apache/tools/ant/taskdefs/MatchingTask
[ERROR] using the classloader AntClassLoader[]: org.python.apache.tools.ant.taskdefs.MatchingTask
[ERROR] -> [Help 1]

I compared the decompilation files of two jar packages. The GlobMatchingTask.class in the 2.5.3 version of Jython is,
`package org.python.util;

import java.io.File;
import java.util.Set;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.DirectoryScanner;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.taskdefs.MatchingTask;
import org.apache.tools.ant.types.Path;
import org.apache.tools.ant.util.GlobPatternMapper;
import org.apache.tools.ant.util.SourceFileScanner;

public abstract class GlobMatchingTask extends MatchingTask
{
private Path src;
protected File destDir;
private Set toExpose;
`
and the GlobMatchingTask.class in the 2.7.1 version of Jython is,

`
package org.python.util;

import java.io.File;
import java.util.Set;
import org.python.apache.tools.ant.BuildException;
import org.python.apache.tools.ant.DirectoryScanner;
import org.python.apache.tools.ant.Project;
import org.python.apache.tools.ant.taskdefs.MatchingTask;
import org.python.apache.tools.ant.types.Path;
import org.python.apache.tools.ant.util.GlobPatternMapper;
import org.python.apache.tools.ant.util.SourceFileScanner;

public abstract class GlobMatchingTask extends MatchingTask
{
private Path src;
protected File destDir;
private Set toExpose;
`

"org.apache.tools.ant.taskdefs.MatchingTask" becomes to "org.python.apache.tools.ant.taskdefs.MatchingTask". However, I can not find the MatchingTask class int the package of org.python.apache in the Jython-2.7.1.jar.

When I read the GlobMatchingTask.java in the source code of Jython 2.7.1, I found that,
`package org.python.util;

import java.io.File;
import java.util.Set;

import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.taskdefs.MatchingTask;
import org.apache.tools.ant.types.Path;
import org.apache.tools.ant.util.GlobPatternMapper;
import org.apache.tools.ant.util.SourceFileScanner;
`
it is "org.apache.tools.ant.taskdefs.MatchingTask" in the source code, but it is "org.python.apache.tools.ant.taskdefs.MatchingTask" int the class file. I notice the build.xml in the source code of 2.7.1. the snippet code is,

<zipfileset src="extlibs/commons-compress-1.14.jar"/> <rule pattern="org.apache.**" result="org.python.apache.@1"/>
Therefore, I doubt that it didn't pack the needed ant.jar to the jython-standalone-2.7.1.jar, and this is the reason of the error happened. In the jython-2.5.3.jar, it didn't change the package of ant.jar, and it works fine.

@jeff5

This comment has been minimized.

Member

jeff5 commented Sep 8, 2018

Ok, I was wrong about that class! (I was in fact thinking of the GlobMatchingTask.)

I agree you are seeing the effect of the jarjar task which renames packages. And that does seem to be the offending line. Thank-you.

You must be picking up the renamed GlobMatchingTask from the Jython JAR, but it doesn't contain the renamed dependency. In our Ant version of what you're doing, I see we have jython-dev.jar in the path, where everything has its proper name, but also all the JARs on which this tool might depend as main.classpath. So when we use this tool it looks like we're using the un-transformed versions of everything.

As we do not bundle a transformed copy of ant, we ought not to have transformed references to its classes. Although this task is structured as if the rules applied only to the preceding file set, I think they are global in effect.

I have raised issue 2703 linked to this. (That's still our main bug-tracker.)

@duzuoqian

This comment has been minimized.

duzuoqian commented Sep 10, 2018

So, May I ask, when will the bug be fixed? As I have encountered the same problem, I hope it will be fixed as soon as possible, thank you! @jeff5

@jeff5

This comment has been minimized.

Member

jeff5 commented Sep 19, 2018

@duzuoqian : I started answering that in the earlier post, but deleted that when realised I was saying nothing. It looks fairly simple. On the other hand, we're busy with other issues. Knowing at least 2 people want it makes it more likely it will be in 2.7.2, but then you'll want to know then that is ... .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment