So I've been able to get Jackpot to do some basic things by calling
directly into the cmdline tool. I'm using the Maven artifact at:

  org.apache.netbeans.modules.jackpot30:tool

So this works:

String [] args = buildCmdLineArgs();
org.netbeans.modules.jackpot30.cmdline.Main.compile(args);


Now I want to try some more fine-grained control, so I'm trying to
reproduce some of the code within the cmdline tool.
But just something simple like:

String sourceFolder = "src/main/java";
FileObject srcRoot = FileUtil.toFileObject(new File(sourceFolder));

Fails with:

java.lang.ClassNotFoundException:
org.netbeans.modules.web.common.remote.RemoteURLMapper
at
java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
at
java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:520)
at java.base/java.lang.Class.forName0(Native Method)
at java.base/java.lang.Class.forName(Class.java:467)
at
org.openide.util.lookup.MetaInfServicesLookup.search(MetaInfServicesLookup.java:306)
at
org.openide.util.lookup.MetaInfServicesLookup.beforeLookup(MetaInfServicesLookup.java:131)
at
org.openide.util.lookup.MetaInfServicesLookup.beforeLookupResult(MetaInfServicesLookup.java:110)
at org.openide.util.lookup.AbstractLookup.lookup(AbstractLookup.java:458)
at org.openide.util.lookup.ProxyLookup$R.initResults(ProxyLookup.java:449)
at
org.openide.util.lookup.ProxyLookup$R.addLookupListener(ProxyLookup.java:548)
at org.openide.filesystems.URLMapper.reset(URLMapper.java:92)
at org.openide.filesystems.URLMapper.<clinit>(URLMapper.java:82)
at org.openide.filesystems.FileUtil.toFileObject(FileUtil.java:880)


If I call the Main.compile prior to that, it works.  But I don't see how
org.netbeans.modules.jackpot30.cmdline.Main is initializing anything to
make that work.
I suspected it is related to a few methods annotated with
org.openide.util.lookup.ServiceProvider; but that annotation is not
accessible to my code;

What's the trick to initializing things?  For now I'm hacking it by calling
Main.compile() with no args.

Other than that issue, I have been making progress with the public API.
Lots more to do though.


Thanks,

Scott

P.S.  someone should run Jackpot on the Jackpot cmdline tool - there's some
dead code in there.  It could also use some documentation, the --help
output is incomplete.

On Thu, Feb 23, 2023 at 10:42 AM Scott Palmer <swpal...@gmail.com> wrote:

> Getting back to this...
> My netbeans-13/java/modules/ext folder contained:
> nb-javac-jdk-19-api.jar
> nb-javac-jdk-19.jar
>
> So JDK 19 versions, not 17.   I must have used a later version and not
> realized it? Or maybe I misread the instructions and thought NB 13 was a
> minimum version. I don't know, but it was clearly a mistake on my part.
> I see the build.xml in netbeans-jackpot30/cmdline/tool/ does explicitly
> references the 17 version.   I re-downloaded the binary zip for NB 13,
> which does indeed have v17 of nb-javac.  After I replaced my netbeans 13
> folder the build succeeded.
>
> I recall some talk of the nb-javac being phased out.  Is that correct?
>
> Thanks!
>
> Scott
>
>
>
>
>
>
> On Fri, Jan 27, 2023 at 1:43 AM Jan Lahoda <lah...@gmail.com> wrote:
>
>> Hi Scott,
>>
>> Thanks for the interest in Jackpot.
>>
>> The Maven plugin basically only calls a standalone command line tool,
>> which
>> is also uploaded on Maven central
>> (org.apache.netbeans.modules.jackpot30:tool:13.0), although that's a bit
>> harder to use without the launchers (launchers are part of the release on
>> Apache).
>>
>> Overall, the tool re-uses what's in NetBeans as much as possible, and
>> packs
>> the relevant classes into a single jar file. The main place where the
>> hints
>> (declarative or hardcoded) are ran is around this place:
>>
>> https://github.com/apache/netbeans-jackpot30/blob/13e22c19c583f2ca687f951c64aab9f3f271c0fc/cmdline/tool/src/org/netbeans/modules/jackpot30/cmdline/Main.java#L563
>>
>> Generally calls to BatchSearch, which is an internal API. It handles
>> various searches through multiple files, and then calls:
>>
>> https://github.com/apache/netbeans/blob/master/java/spi.java.hints/src/org/netbeans/modules/java/hints/spiimpl/hints/HintsInvoker.java
>>
>> which is the class that runs some list of hints over a single file.
>>
>> It should be possible to open the "cmdline" directory as a module suite in
>> NetBeans, and the "cmdline/tool" directory as a project under it.
>>
>> For building the tool, based on the NPE, it seems nb-javac was not
>> available, possibly not prepended to classpath while the tests were run.
>> It
>> is here in the NB 13 distribution:
>> java/modules/ext/nb-javac-jdk-17-api.jar
>> java/modules/ext/nb-javac-jdk-17.jar
>>
>> And the command line that prepends it on the bootclasspath (for JDK 8), or
>> excludes standard javac (for JDK 11+) is here:
>>
>> https://github.com/apache/netbeans-jackpot30/blob/13e22c19c583f2ca687f951c64aab9f3f271c0fc/cmdline/tool/build.xml#L115
>>
>> So, probably some of that didn't work well. I tried on my Linux, and it
>> built, I, unfortunately, don't have a Mac to try right now. I'll keep
>> thinking of it.
>>
>> Thanks,
>>      Jan
>>
>>
>> On Fri, Jan 27, 2023 at 5:48 AM Scott Palmer <swpal...@gmail.com> wrote:
>>
>> > I haven't been able to get Jackpot to build... (If there is a better
>> place
>> > to ask about this, let me know)
>> >
>> > I followed the instructions in cmdline/README.md
>> >
>> > Using Ant v 1.10.12
>> > Maven v 3.8.4
>> > With JAVA_HOME set to JDK 8
>> >
>> > I ran:
>> >
>> > ant -DNETBEANS_PLATFORM=/Users/scott/dev/netbeans-13
>> > -DJDK11=/Library/Java/JavaVirtualMachines/zulu-11.jdk/Contents/Home
>> > -DJDK17=/Library/Java/JavaVirtualMachines/zulu-17.jdk/Contents/Home
>> >  build-and-test
>> >
>> > It chugged away for a bit but then failed a bunch of tests:
>> >
>> >     [junit] Testcase:
>> >
>> >
>> testConfigurationFile(org.netbeans.modules.jackpot30.cmdline.CreateToolTest):
>> > Caused an ERROR
>> >     [junit] junit.framework.AssertionFailedError: expected:<0> but
>> was:<1>
>> >     [junit] java.io.IOException: junit.framework.AssertionFailedError:
>> > expected:<0> but was:<1>
>> >     [junit] at
>> >
>> >
>> org.netbeans.modules.jackpot30.cmdline.CreateToolTest.reallyRunCompiler(CreateToolTest.java:77)
>> >     [junit] at
>> >
>> >
>> org.netbeans.modules.jackpot30.cmdline.MainTest.doRunCompiler(MainTest.java:1128)
>> >     [junit] at
>> >
>> >
>> org.netbeans.modules.jackpot30.cmdline.MainTest.doRunCompiler(MainTest.java:1072)
>> >     [junit] at
>> >
>> >
>> org.netbeans.modules.jackpot30.cmdline.MainTest.doRunCompiler(MainTest.java:1068)
>> >     [junit] at
>> >
>> >
>> org.netbeans.modules.jackpot30.cmdline.MainTest.testConfigurationFile(MainTest.java:191)
>> >     [junit] at
>> org.netbeans.junit.NbTestCase.access$200(NbTestCase.java:77)
>> >     [junit] at
>> > org.netbeans.junit.NbTestCase$2.doSomething(NbTestCase.java:476)
>> >     [junit] at
>> > org.netbeans.junit.NbTestCase$1Guard.run(NbTestCase.java:402)
>> >     [junit] at java.lang.Thread.run(Thread.java:750)
>> >     [junit] Caused by: junit.framework.AssertionFailedError:
>> expected:<0>
>> > but was:<1>
>> >     [junit] at
>> >
>> >
>> org.netbeans.modules.jackpot30.cmdline.CreateToolTest.reallyRunCompiler(CreateToolTest.java:72)
>> >     [junit]
>> >     [junit]
>> >     [junit] Testcase:
>> >
>> >
>> testWarningsAreErrors(org.netbeans.modules.jackpot30.cmdline.CreateToolTest):
>> > FAILED
>> >     [junit] expected:<[${workdir}/src/test/Test.java:4: warning:
>> > [Usage_of_Collection_Map_size_equals_0] c.size() == 0 can be replaced
>> with
>> > c.isEmpty()
>> >     [junit]         boolean b1 = c.size() == 0;
>> >     [junit]                      ^
>> >     [junit] ${workdir}/src/test/Test.java:5: warning:
>> > [Usage_of_Collection_Map_size_equals_0] c.size() == 0 can be replaced
>> with
>> > c.isEmpty()
>> >     [junit] boolean b2 = c.size() == 0;
>> >     [junit]             ^
>> >     [junit] ]> but was:<[]>
>> >
>> > Basically a few like above, and then a lot more that looked like this:
>> >
>> >     [junit] Testcase:
>> > testParameterFile(org.netbeans.modules.jackpot30.cmdline.MainTest):
>> Caused
>> > an ERROR
>> >     [junit] java.lang.NullPointerException
>> >     [junit] java.lang.IllegalStateException:
>> java.lang.NullPointerException
>> >     [junit] at
>> > org.netbeans.modules.jackpot30.cmdline.Main.compile(Main.java:357)
>> >     [junit] at
>> >
>> >
>> org.netbeans.modules.jackpot30.cmdline.MainTest.reallyRunCompiler(MainTest.java:1155)
>> >     [junit] at
>> >
>> >
>> org.netbeans.modules.jackpot30.cmdline.MainTest.doRunCompiler(MainTest.java:1128)
>> >     [junit] at
>> >
>> >
>> org.netbeans.modules.jackpot30.cmdline.MainTest.doRunCompiler(MainTest.java:1072)
>> >     [junit] at
>> >
>> >
>> org.netbeans.modules.jackpot30.cmdline.MainTest.doRunCompiler(MainTest.java:1068)
>> >     [junit] at
>> >
>> >
>> org.netbeans.modules.jackpot30.cmdline.MainTest.testParameterFile(MainTest.java:879)
>> >     [junit] at
>> org.netbeans.junit.NbTestCase.access$200(NbTestCase.java:77)
>> >     [junit] at
>> > org.netbeans.junit.NbTestCase$2.doSomething(NbTestCase.java:476)
>> >     [junit] at
>> > org.netbeans.junit.NbTestCase$1Guard.run(NbTestCase.java:402)
>> >     [junit] at java.lang.Thread.run(Thread.java:750)
>> >     [junit] Caused by: java.lang.NullPointerException
>> >     [junit] at
>> >
>> >
>> org.netbeans.modules.java.hints.spiimpl.batch.BatchSearch.findOccurrencesLocal(BatchSearch.java:92)
>> >     [junit] at
>> >
>> >
>> org.netbeans.modules.java.hints.spiimpl.batch.BatchSearch.findOccurrences(BatchSearch.java:85)
>> >     [junit] at
>> > org.netbeans.modules.jackpot30.cmdline.Main.handleGroup(Main.java:564)
>> >     [junit] at
>> > org.netbeans.modules.jackpot30.cmdline.Main.compile(Main.java:338)
>> >
>> >
>> > Any hints are appreciated.
>> >
>> > Regards,
>> >
>> > Scott
>> >
>> >
>> > On Thu, Jan 26, 2023 at 1:49 PM Ernie Rael <err...@raelity.com> wrote:
>> >
>> > > On 23/01/26 10:25 AM, Scott Palmer wrote:
>> > > > Well, yeah of course.. but is there a documented public API?
>> > > > The maven plugin doesn't actually do refactoring, right?  It just
>> > > > identifies hints?
>> > >
>> > > At: https://netbeans.apache.org/jackpot/
>> > >
>> > > > To apply the changes produced by the declarative hints, run
>> > > > jackpot30:apply:
>> > > > $ mvn -q jackpot30:apply && git diff
>> > >
>> > > Haven't tried it, but sure looks like it does the refactoring.
>> > >
>> > > -ernie
>> > >
>> > > > I was just wondering if there are notes somewhere that go a bit
>> deeper
>> > > than
>> > > > showing how to use it from the command line or NetBeans.
>> > > >
>> > > > I did find a README in the cmdline folder.  So at least that's a
>> start
>> > > for
>> > > > getting something to build.
>> > > >
>> > > > Thanks,
>> > > >
>> > > > Scott
>> > > >
>> > > > On Thu, Jan 26, 2023 at 11:22 AM Michael Bien <mbie...@gmail.com>
>> > wrote:
>> > > >
>> > > >> you check how the maven plugin is implemented and adopt it for
>> gradle?
>> > > >>
>> > > >> -mbien
>> > > >>
>> > > >> On 26.01.23 17:13, Scott Palmer wrote:
>> > > >>
>> > > >> I don't use Maven if I can help it.
>> > > >>
>> > > >> But you misunderstand, I want to call Jackpot from my code to get
>> it
>> > to
>> > > >> perform some refactoring from control of my program. Getting a
>> list of
>> > > >> possible hints may happen later.
>> > > >> Or perhaps a more general use... What would I do if I wanted to
>> write
>> > a
>> > > >> Gradle plugin to do the same as the Maven plugin? Assuming I know
>> the
>> > > >> Gradle side, how do I call the Jackpot methods?
>> > > >>
>> > > >> Regards,
>> > > >>
>> > > >> Scott
>> > > >>
>> > > >>
>> > > >> On Thu, Jan 26, 2023 at 10:50 AM Michael Bien <mbie...@gmail.com>
>> > > wrote:
>> > > >>
>> > > >>> On 26.01.23 16:01, Scott Palmer wrote:
>> > > >>>> I wanted to experiment with Jackpot for a project I'm working on.
>> > How
>> > > >>>> dependent on the NetBeans Platform is the Jackpot code at
>> > > >>>> https://github.com/apache/netbeans-jackpot30 ?
>> > > >>>> Is there such a thing as a jackpot library jar that does not
>> depend
>> > on
>> > > >>>> NetBeans classes?
>> > > >>>> If I wanted to make a standalone tool to do certain
>> transformations
>> > > on a
>> > > >>>> Java code base where would I start?
>> > > >>>>
>> > > >>>> Thanks for any help you can provide,
>> > > >>>>
>> > > >>>> Scott
>> > > >>>>
>> > > >>> you should be able to use it from maven in your build:
>> > > >>>
>> > > >>>               <plugin>
>> > > >>> <groupId>org.apache.netbeans.modules.jackpot30</groupId>
>> > > >>> <artifactId>jackpot30-maven-plugin</artifactId>
>> > > >>>                   <version>13.0</version>
>> > > >>>                   <configuration>
>> > > >>> <configurationFile>jackpot-settings.xml</configurationFile>
>> > > >>> <failOnWarnings>true</failOnWarnings>
>> > > >>>                   </configuration>
>> > > >>>                   <executions>
>> > > >>>                       <execution>
>> > > >>>                           <id>jackpot</id>
>> > > >>>                           <phase>compile</phase>
>> > > >>>                           <goals>
>> > > >>>                               <goal>analyze</goal>
>> > > >>>                           </goals>
>> > > >>>                       </execution>
>> > > >>>                   </executions>
>> > > >>>               </plugin>
>> > > >>>
>> > > >>>
>> > > >>> I use it mostly from within NetBeans itself for refactoring or
>> > > >>> inspection tasks with the help of the ".hint" files.
>> > > >>>
>> > > >>> I sometimes upload the inspections which I think are reusable or
>> more
>> > > >>> generic here:
>> > > >>>
>> > > >>> https://github.com/mbien/jackpot-inspections
>> > > >>>
>> > > >>> readme explains how to use hint files.
>> > > >>>
>> > > >>> -mbien
>> > > >>>
>> > > >>>
>> > >
>> > >
>> > > ---------------------------------------------------------------------
>> > > To unsubscribe, e-mail: dev-unsubscr...@netbeans.apache.org
>> > > For additional commands, e-mail: dev-h...@netbeans.apache.org
>> > >
>> > > For further information about the NetBeans mailing lists, visit:
>> > > https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
>> > >
>> > >
>> > >
>> > >
>> >
>>
>

Reply via email to