typetools / checker-framework

Pluggable type-checking for Java
http://checkerframework.org/
Other
1.03k stars 356 forks source link

-classpath argument only works on command line, not in an argfile #193

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1.  Run:
java -jar checkers.jar -classpath path/to/customChecker.jar -processor 
path.to.CustomChecker <src files>
Everything should work via this invocation

2. Write classpath to a file like @myclasspaths.txt The file should have a 
single line like:
-classpath path/to/customChecker.jar

3. Run:
java -jar checkers.jar @myclasspaths.txt -processor path.to.CustomChecker <src 
files>
This invocation leads to an error message that indicates BaseTypeChecker is 
missing.  Putting checkers.jar in @myclasspaths.txt fixes this (which is 
currently what the Eclipse/Maven plugins do).

We should never have to put checkers.jar on the classpath manually when running 
checkers.jar.

Original issue reported on code.google.com by Jonathan...@gmail.com on 7 Jan 2013 at 3:36

GoogleCodeExporter commented 9 years ago
From Jonathan:

There are a few issues at play:

1.  Unlike bootclasspaths, classpath arguments don't have an option to 
prepend/append.
2.  The last -classpath argument read takes precedence over all previous ones.
3.  Users can specify any number of @arg.files.  
4.  Options in arg files are escaped like Java strings, not like shell
commands, i.e., they are not expanded by the shell.
5.  One of the reasons people read arg files is that the resulting options
might be too long for the command line, especially under Windows.

Probably, the best way to handle this is:

1.  Read the arg files in reverse order.  
2.  Find the first instance of a classpath argument.
3.  Prepend to that classpath argument our checker.jar
4.  Copy the original arg-file into a new arg-file in tmp but replace the
classpath with the one determined in step 3.
5.  Pass the new arg file in place of the old.

Original comment by michael.ernst@gmail.com on 28 Aug 2014 at 8:13