Feature - Implemented Request: refactor build.xml to support IntelliJ IDEA (please review)

MCroft

Developer
IntelliJ IDEA is mostly compatible with the build system for KoLMafia out of this box with one big exception.
  1. If you use the default application-type run action, there's no revision number in the version string
  2. If you use ANT target daily, it can't set the working directory properly
  3. If you use a JAR application Run task, it can't handle changing jar file names.

The first is caused by the code that looks at the compiled KoLConstants.class file for the Constants "RELEASED" and "REVISION". If RELEASED is false, then the version is appended. Since the default value in the code is "true", it isn't there unless we make the configuration change it.

So, the patch refactors the build target "compile", adding antcalls to the new targets "set.version" and "set.released.false". Everywhere we made those replaces, I switched it to antcall, to make it more consistent. Additionally, I added those two antcall targets to my IntelliJ build. And now it works like I want...

I only tested the things I could test, and since it's the build system, hopefully it can be well tested, but it looks like it should be correct: it should be transparent to anyone doing anything except my IDE-related refactoring.
Screen Shot 2020-10-09 at 7.24.05 PM.png
View attachment build.refactor.patch
 
Last edited:

fronobulax

Developer
The few things I tried worked for me. My only concern is whether something breaks with Jenkins which is not something I can test. We can wait a bit until I can monitor Jenkins after a checking so I can revert if something did break.
 

MCroft

Developer
Sure, I definitely don't want to be the guy who broke the build. :)

Anyone who needs it can apply the patch and it should be transparent to everyone else.
 

Veracity

Developer
I'm missing something.

I imported my SVN project into a new IntelliJ project
I set my SDK to Java 14
I have your changes to build.xml - hence the required ant tasks.
I set build.xml to be the "ant build file" for the project
I set up the Run/Debug task as shown on your image
Warning: Class 'net.sourceforge.kolmafia.KoLmafia' not found in module 'kolmafia'

When I Build from the menu, it does this:

Clearing build system data...
Executing pre-compile tasks...
Loading Ant Configuration...
Running Ant Tasks...
Cleaning output directories...
Running 'before' tasks
Checking sources
Running 'after' tasks
Finished, saving caches...
Executing post-compile tasks...
Loading Ant Configuration...
Running Ant Tasks...

No class files anywhere.

I removed build.xml as the "build file" to use.
I told IntelliJ to use project output files for classes
I invalidated caches and restarted
I told it to rebuild the project. No output files anywhere.
Try to Run. It can't find the class to run.
 

MCroft

Developer
This doesn't seem to have gotten as far as you got before, when you got it to run without the version number.

let me try it with a clean project.

I created a new directory and did svn co from it.

I imported project from existing sources. I accepted the defaults on the import.

I added build.xml to the ant tab.

I set up my run configuration as shown.
+ to add configuration, select "Application"
main class: net.sourceforge.kolmafia.KoLmafia
Working directory:/Users/mcroft/Library/Application Support/KoLmafia
(or wherever, this is important after launch...)
Use classpath of module: kolmafia
JRE: Default (or whatever)
Before Launch:
Run Ant target 'set.released.false'
Run Ant target 'set.version'
Build (not Build Project, just vanilla Build)
Edit: Run Ant target 'unset.properties' Don't skip this step. It needs to undo the props to follow the ant build process correctly

Apply the config.

It does a lot less when I run it. Build window says:
Executing pre-compile tasks...
Loading Ant Configuration...
Running Ant Tasks...
Executing post-compile tasks...
Loading Ant Configuration...
Running Ant Tasks...

Run window says (once I expand that command to see the ugly command line with classpath):
/Library/Java/JavaVirtualMachines/adoptopenjdk-13-openj9.jdk/Contents/Home/bin/java -javaagent:/Applications/IntelliJ IDEA CE.app/Contents/lib/idea_rt.jar=57919:/Applications/IntelliJ IDEA CE.app/Contents/bin -Dfile.encoding=UTF-8 -classpath /Users/mcroft/projects/kolmafia/out/production/kolmafia:/Users/mcroft/projects/kolmafia/lib/jar/jna-4.1.0.jar:/Users/mcroft/projects/kolmafia/lib/jar/jdom-2.0.6.jar:/Users/mcroft/projects/kolmafia/lib/jar/sqljet-1.1.12.jar:/Users/mcroft/projects/kolmafia/lib/jar/lz4-java-1.4.1.jar:/Users/mcroft/projects/kolmafia/lib/jar/antlr-runtime-3.4.jar:/Users/mcroft/projects/kolmafia/lib/jar/svnkit-cli-1.10.1.jar:/Users/mcroft/projects/kolmafia/lib/jar/jna-platform-4.1.0.jar:/Users/mcroft/projects/kolmafia/lib/jar/sequence-library-1.0.4.jar:/Users/mcroft/projects/kolmafia/lib/jar/svnkit-javahl16-1.10.1.jar:/Users/mcroft/projects/kolmafia/lib/jar/jsch.agentproxy.core-0.0.7.jar:/Users/mcroft/projects/kolmafia/lib/jar/trilead-ssh2-1.0.0-build222.jar:/Users/mcroft/projects/kolmafia/lib/jar/jsch.agentproxy.pageant-0.0.7.jar:/Users/mcroft/projects/kolmafia/lib/jar/jsch.agentproxy.sshagent-0.0.7.jar:/Users/mcroft/projects/kolmafia/lib/jar/jsch.agentproxy.usocket-nc-0.0.7.jar:/Users/mcroft/projects/kolmafia/lib/jar/jsch.agentproxy.usocket-jna-0.0.7.jar:/Users/mcroft/projects/kolmafia/lib/jar/jsch.agentproxy.connector-factory-0.0.7.jar:/Users/mcroft/projects/kolmafia/lib/jar/jsch.agentproxy.svnkit-trilead-ssh2-0.0.7.jar:/Users/mcroft/projects/kolmafia/lib/testjar/junit-4.12.jar net.sourceforge.kolmafia.KoLmafia

KoLmafia v20.7 r20452
Released on July 30, 2020

Currently Running on Mac OS X
Local Directory is /Users/mcroft/Library/Application Support/KoLmafia
Using Java 13.0.2
 
Last edited:

MCroft

Developer
So my two guesses are
1: needs to be the Application Template
2: needs to use the Build command in the Before Launch section
3: needs to use classpath of module
 

MCroft

Developer
This is the only other place I can think there might be a difference.

If it matters, I'm using IntelliJ IDEA 2020.2.3 (Community Edition)
Build #IC-202.7660.26, built on October 6, 2020
Project Structures.png
 

Veracity

Developer
OK. I am having a lot more success with a brand new svn checkout.
One thing I notice is that we have in our source tree a ".classpath" file - used by Eclipse - with obsolete and incomplete info, which is imported by IntelliJ to create an obsolete and incomplete classpath for me. That caused build errors for me.

I fixed .classpath, removed .idea and kolmafia.iml, and re-created the project, build configuration, etc. - and it works like a charm.
I tested from my command line and ran ant to build the .jar and executed the .jar from the command line - and it worked fine.

I'll submit an updated .classpath and build.xml

And it is done - in revision 20453.

Thanks for all your work! :D
 

Veracity

Developer
I have If it matters, I'm using IntelliJ IDEA 2020.2.2 (Community Edition), by the way, which might explain why I had a .classpath issue and you did not.
 

MCroft

Developer
I don't know if I started with 2020.2.2 or .3. The test one I did today I definitely stated with .3, but it's recent and I've worked on this change for a few days.

I do know that at some point I added classpath="" to my build.properties because target compile, test-compile, ant test show errors if I don't. Is that part of the eclipse stuff as well?

I don't think just having that there causes the issue, but I think in my soon-to-be-less-than-hypothetical Wiki IDE guide, I'll recommend starting with a fresh checkout, which not only keeps a new user from screwing up any current manual environment they have, but also makes it a lot easier for helpers to help figure out what went wrong if something goes wrong.

The last time I submitted significant build.xml changes started with a dmg target issue in October of 2010, around revision 8728. Some of this is my own fault. :)
 

fredg1

Member
Noticed /bin was added to .gitignore... what IS /bin, by the way?
Seems like it's nothing more than a copy of your folder since the last time I-don't-know-what happened...

Also, wanted to ask this for a while, now: shouldn't /Build go in /Dist ?
 

MCroft

Developer
$build is where classifies are put, $dist is where the jarfile goes (and the app, exe, dmg, docs, etc).

My guess is it was a convenience for the team that made the ANT file in the first place, but it seems logically consistent to me, and it's the kind of thing I'd likely do if I was starting in a green field.

Can you explain how you'd see the steps of compiling, jar-ing, deploying, working? I'd like to understand if there's a better way of doing it than the way in the current build.xml
 

MCroft

Developer
At the end of the process, yes. $build is an intermediate directory. It compiles in $build and iff it succeeds, moves it to $dist. Also look at target clean, you’ll see a difference in what gets cleaned up. And target test, which doesn’t move to $dist

You can try your suggestion by pointing both at the same directory in default.properties. Might need to make some other changes. Make backups first.
 

Veracity

Developer
Took a fair amount of work, but I set the "Project" code style to agree with our coding conventions.
Looks better than what I have set for Emacs (having not spent an equivalent amount of work, since KoLmafia's style does not agree with the style I prefer for personal Java).

I'll move to IntelliJ for my next coding task in KoLmafia - especially since it is full of helpful suggestions for improving the code in a given file.
 

MCroft

Developer
woot! I would like your project code style.

I've started Wikifying the IntelliJ setup, which has a lot of "I told you that story so I could tell you this story..."
 

Veracity

Developer
./bin is where IntelliJ puts .class files for me.
./build is where ant puts .class files when I invoke it from the command line.

Looking at the module structure, under Paths, I see this:

Code:
X Use module compile output path
      Output path: /src/kolmafia/bin
I wonder if I just changed that to /src/kolmafia/build, I could compile using either method and the other would see what I have?
 

Veracity

Developer
Yes! I can build the project in IntelliJ and it puts the classes into build.
Then "ant jar" from the command line gets those classes and builds the jar in dist.

Alternatively, if I do "ant compile" from the command line, IntelliJ sees the compiled classes in build.
 

MCroft

Developer
can you check that? when I download it, it seems blank.

nvm, it's making a . file...
 
Last edited:
Top