Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jwsqQ-0001Ma-UY for pljava-dev@arkaria.postgresql.org; Sat, 18 Jul 2020 19:50:03 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jwsqP-0004aT-S0 for pljava-dev@arkaria.postgresql.org; Sat, 18 Jul 2020 19:50:01 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jwsqP-0004aB-Gy for pljava-dev@lists.postgresql.org; Sat, 18 Jul 2020 19:50:01 +0000 Received: from mail-ej1-x635.google.com ([2a00:1450:4864:20::635]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1jwsqJ-0002Xw-Jw for pljava-dev@lists.postgresql.org; Sat, 18 Jul 2020 19:50:00 +0000 Received: by mail-ej1-x635.google.com with SMTP id rk21so14283141ejb.2 for ; Sat, 18 Jul 2020 12:49:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=DdsR8k4gTxm0r8yBrDVbm2L4j6GcXnxzW1CsgJ1ziWA=; b=HYyeQz6Wkbd374nudnQV+JDa3X3D1CcAN/QDkNGjdfbUuvDroHeVjx9aznRGMYs7CD ZpmZ5NUXX9WhNF8T4yKGxBpym8ly1vBRyiTIut1BuooXHrVKzl0trBPNTQHVBfPp35j1 4ixixHcfGouNx418a8rz9SE8BYMJJbUU67PVEAEmLaz91hWPbl3X7aqWmlQ6gby9rcej FTvS17hvkof6pXICMwjRhpZVLwc3iv6E4fy6tCpGRg/QA37pua3L1Y3vwIPqxf4a0xLK ItOm6+kUnFIV3e3qTAQAxSBnNaQuSTm+qQj+IbiarKSH4thCEoOlu7k5Rs2HZ1/vao5R IQ4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=DdsR8k4gTxm0r8yBrDVbm2L4j6GcXnxzW1CsgJ1ziWA=; b=sZtqrHqcHsMPvpO1X5PTQIc6Iy7XJGWelmRJvHG7oll0A1xcDXZyhmXA7tMPCNIiOy 1pESgPSJeRvmsywTnIzTW+zQcChdn+d3ZQt4dUJsphDyGlljRIk1PCqrPZl0dLb6Xw20 zYUvHguoPBMmNENWMSpAQfVFiMTAQQ0bCELEOnSQPqQF+3E8ZbTIn2ZNdmEyk2Prv/qs 7oQTsFc/m5LldmUXUTfT/NNyAqdKckvFQGMcDJo7o3LnlYQmwBV1RZKUOGUgVls+2DEv QFE8rS2Z6T6kV05pGY//6W8MiolKJBlXfmEvks2PYK+JRfkMsCGA8jQ8BA8wS01c3Sk1 GUnw== X-Gm-Message-State: AOAM533kceDQBLcqKcqfTPp90SZRYY8JanvcQEkNL82UNDU24Jlb92Dq lwDSE+tXg5dw5ZxzS7ZA7RmP5Pqy691c+pQ+SrA= X-Google-Smtp-Source: ABdhPJwBpjZicuJNeTOBpRuBsNHOJgu4jZlr2MiwWTXA6krSyVXOOhDbW/gfmSY3IBWFNRP807kpLhCPXIzylLq+Guc= X-Received: by 2002:a17:906:594c:: with SMTP id g12mr14083533ejr.255.1595101793724; Sat, 18 Jul 2020 12:49:53 -0700 (PDT) MIME-Version: 1.0 References: <5F0734AD.7060001@anastigmatix.net> <5F077926.2050806@anastigmatix.net> <5F07C2D5.5050904@anastigmatix.net> <5F0D35BA.30904@anastigmatix.net> <5F0E3972.5070609@anastigmatix.net> <5F0F2DA2.5090603@anastigmatix.net> <5F12FF49.6090906@anastigmatix.net> <5F12FF80.5020208@anastigmatix.net> <5F1338F8.6030506@anastigmatix.net> In-Reply-To: <5F1338F8.6030506@anastigmatix.net> From: Kartik Ohri Date: Sun, 19 Jul 2020 01:19:42 +0530 Message-ID: Subject: Re: PL/Java new build plugin To: Chapman Flack Cc: pljava-dev@lists.postgresql.org Content-Type: multipart/alternative; boundary="000000000000cbac0c05aabc93c8" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --000000000000cbac0c05aabc93c8 Content-Type: text/plain; charset="UTF-8" > > 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] 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] . I had completely understood the opposite of it. This maven-antrun docs verify this [3] . 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] . 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] . 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] 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] , 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] , 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] , 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 --000000000000cbac0c05aabc93c8 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
But I would really like to know what ends up happening w= hen 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 releva= nt codebase again going through the files a Project or a Script Task call. = As the manual mentions here,=C2=A0[1]=C2=A0a classpathref is just a reference to paths= stored elsewhere, I also realized that I had it all inside out. maven.plug= in.classpath is not something that maven declares. It is declared by the ma= ven antrun plugin for use by ant tasks=C2=A0[2]. I= had completely=C2=A0understood the opposite of it. This maven-antrun docs = verify this=C2=A0[3]. This means that adding=C2=A0=C2=A0= classpathref=3D"maven.plugin.classpath" to our scripts will not b= e useful. The maven plugin classpath is essentially the reference to artifa= ct paths. In our case, the maven.plugin.classpath would be referring to,
/home/amcap1712/pljava/pljava-pgxs/target/pljava-pgxs-0.0.1-SNAPSHO= T.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=C2=A0= [4].

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.
=C2=A0
An= t uses a custom AntLoader which extends the ClassLoader [5]. It is heavily customized and over 1600 lines. I am still= going through it and trying to understand what it does but it is definitel= y 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]=C2=A0which also provides an instance o= f an AntLoader. I think this class only serves as a convenience class and t= o implement good software design patterns.

-------= -----------------

The actual script evaluation hap= pens here=C2=A0[6], assuming Apache BSF is not present. (Since= , the scripts do not specify the manager to use, BSF is preferred if presen= t according to [1] above. If BSF is absent,=C2=A0 then javax.script is used= .) Most of the code in the function is uninteresting and generic (in my opi= nion) , however one interesting thing does happen. Before executing the scr= ipt, Ant changes the ClassLoader and stores the ClassLoader which it replac= es. 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 un= derstand=C2=A0why it is done.

Some other interesti= ng or mysterious things I found in the code related to the Script task. Her= e=C2=A0[7], Ant loads the j= avax.script (or BSF) manager class manually into the classpath which I don&= #39;t understand why (to be fair, I don't know what Class.forName=C2=A0= even does, my best guess is load the class into classpath). Then Here=C2=A0=