public inbox for [email protected]  
help / color / mirror / Atom feed
From: Kartik Ohri <[email protected]>
To: Chapman Flack <[email protected]>
Cc: [email protected]
Subject: Re: PL/Java new build plugin
Date: Sun, 19 Jul 2020 01:19:42 +0530
Message-ID: <CAASLQ4OR8ZD4GRNHVGuTzJp_UP-PAcADxcz=uymiSFPpg8EEHQ@mail.gmail.com> (raw)
In-Reply-To: <[email protected]>
References: <CAASLQ4Mva7dAXiS_c9OLhV4VzNHF=XNKJosuS5gtZTB6b4TW1Q@mail.gmail.com>
	<[email protected]>
	<CAASLQ4PDcaAJ8fEwXXFW6XPakc7GCNVgPNGCxA8KYMzPDZw4+w@mail.gmail.com>
	<[email protected]>
	<CAASLQ4OuFQCiSMeypQtfRaAvj-4H-EAgszLwdAo6Tc1zS9B66g@mail.gmail.com>
	<[email protected]>
	<CAASLQ4PSizkzBKyyfkp9ccJ1qDPLRLu6g2bo9cN-XuTzGQFGfQ@mail.gmail.com>
	<CAASLQ4P9zGxHda=HAGJ2eAa-oMmJtnPm=4a14mj4P-QpfFsYxg@mail.gmail.com>
	<[email protected]>
	<CAASLQ4NmornyOW8n-qyneLpDVPgV0Js=+=Eys6bw3Y-ZiVbVjA@mail.gmail.com>
	<CAASLQ4OYvTQL7ssG4=QyEqhaB71=AM-svBUYj3uRdWXWoQgBPw@mail.gmail.com>
	<[email protected]>
	<[email protected]>
	<CAASLQ4N40xn-0S4Nsy0Ld75=Ny719MPUE7_aRP_5nAcAqkAqoQ@mail.gmail.com>
	<CAASLQ4OiWCQQwYFnxAQBe2dC6Ms803RjCMX-9AC2=1m0ZzeDhA@mail.gmail.com>
	<[email protected]>
	<[email protected]>
	<CAASLQ4MqSVnhK_GMgq03HcmOKk7a-v7b4L0yfPbtRO=mpqoQtA@mail.gmail.com>
	<[email protected]>

>
> But I would really like to know what ends up happening when a Maven
> classpathref is passed to Ant, and ends up solving the problem.
> What is a Maven classpathref? Is it just a list of URLs, or some
> other object?
>

I went through the relevant codebase again going through the files a
Project or a Script Task call. As the manual mentions here, [1]
<https://ant.apache.org/manual/Tasks/script.html; a classpathref is just a
reference to paths stored elsewhere, I also realized that I had it all
inside out. maven.plugin.classpath is not something that maven declares. It
is declared by the maven antrun plugin for use by ant tasks [2]
<https://github.com/apache/maven-antrun-plugin/blob/8e5b3c613e96c20881347ec16813864a2d8ef0bb/src/main...;.
I had completely understood the opposite of it. This maven-antrun docs
verify this [3]
<https://maven.apache.org/plugins/maven-antrun-plugin/examples/classpaths.html;.
This means that adding  classpathref="maven.plugin.classpath" to our
scripts will not be useful. The maven plugin classpath is essentially the
reference to artifact paths. In our case, the maven.plugin.classpath would
be referring to,
/home/amcap1712/pljava/pljava-pgxs/target/pljava-pgxs-0.0.1-SNAPSHOT.jar
/home/amcap1712/.m2/repository/org/codehaus/plexus/plexus-utils/1.1/plexus-utils-1.1.jar
joined into using a file separator. I used the code from maven-antrun to
generate this [4]
<https://github.com/apache/maven-antrun-plugin/blob/8e5b3c613e96c20881347ec16813864a2d8ef0bb/src/main...;
.

I wonder if it ends up working sort of by accident, maybe Ant uses
> the classpathref to make a more usual classloader structure that has
> the same URLs as the ClassRealm loader, but delegates from there to
> the AppClassLoader instead of the ClassRealm. That could be plausible,
> as Ant came first and wouldn't know about a ClassRealm. It would be
> good to see it in the code though.
>

Ant uses a custom AntLoader which extends the ClassLoader [5]
<https://github.com/apache/ant/blob/master/src/main/org/apache/tools/ant/AntClassLoader.java;.
It is heavily customized and over 1600 lines. I am still going through it
and trying to understand what it does but it is definitely more than a
URLClassLoader. But I am sure, we might be able to chomp down a lot from
this class loader even if we have to implement one of our own. To
supplement the AntLoaderClass, Ant also has a ClasspathUtils class [6]
<https://github.com/apache/ant/blob/master/src/main/org/apache/tools/ant/util/ClasspathUtils.java;
which
also provides an instance of an AntLoader. I think this class only serves
as a convenience class and to implement good software design patterns.

------------------------

The actual script evaluation happens here [6]
<https://github.com/apache/ant/blob/1ce1cc2317cb2b2773ab6b765f1a79ccd4806926/src/main/org/apache/tool...;,
assuming Apache BSF is not present. (Since, the scripts do not specify the
manager to use, BSF is preferred if present according to [1] above. If BSF
is absent,  then javax.script is used.) Most of the code in the function is
uninteresting and generic (in my opinion) , however one interesting thing
does happen. Before executing the script, Ant changes the ClassLoader and
stores the ClassLoader which it replaces. After the script has been
evaluated, it again switches the ClassLoader to the one which was before it
was replaced in the first place. I do not understand why it is done.

Some other interesting or mysterious things I found in the code related to
the Script task. Here [7]
<https://github.com/apache/ant/blob/master/src/main/org/apache/tools/ant/util/ScriptRunnerCreator.jav...;,
Ant loads the javax.script (or BSF) manager class manually into the
classpath which I don't understand why (to be fair, I don't know what
Class.forName even does, my best guess is load the class into classpath).
Then Here [8]
<https://github.com/apache/ant/blob/1ce1cc2317cb2b2773ab6b765f1a79ccd4806926/src/main/org/apache/tool...;,
Ant chooses between three methods to create a classloader. Again, I don't
have the slightest idea why so.

This is all I could gather from the source. I think our answer may lie
inside this most probably inside AntLoader. I'll try to study the AntLoader
class to grasp it and find out the cause.

Regards,
Kartik


view thread (132+ messages)  latest in thread

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected], [email protected], [email protected]
  Subject: Re: PL/Java new build plugin
  In-Reply-To: <CAASLQ4OR8ZD4GRNHVGuTzJp_UP-PAcADxcz=uymiSFPpg8EEHQ@mail.gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox