public class PluginUtil extends Object
CheckerMain
.Modifier and Type | Class and Description |
---|---|
static class |
PluginUtil.CheckerProp |
Modifier and Type | Field and Description |
---|---|
static String |
CHECKER_QUAL_PATH_OPT
Option name for specifying an alternative checker-qual.jar location.
|
static String |
JAVAC_PATH_OPT
Option name for specifying an alternative javac.jar location.
|
static String |
JDK_PATH_OPT
Option name for specifying an alternative jdk.jar location.
|
Constructor and Description |
---|
PluginUtil() |
Modifier and Type | Method and Description |
---|---|
static String |
escapeQuotesAndSlashes(String toEscape) |
static String |
fileArgToStr(File fileArg) |
static List<String> |
getBooleanProp(Map<PluginUtil.CheckerProp,Object> props,
PluginUtil.CheckerProp prop,
String cmdLineArg)
If prop is in props, return a 1-element list containing
cmdLineArg . |
static boolean |
getBooleanSystemProperty(String key)
Return true if the system property is set to "true".
|
static boolean |
getBooleanSystemProperty(String key,
boolean defaultValue)
Return its boolean value if the system property is set.
|
static List<String> |
getCmd(@Nullable String executable,
@Nullable File javacPath,
@Nullable File jdkPath,
File srcFofn,
String processors,
String checkerHome,
String javaHome,
File classPathFofn,
String bootClassPath,
Map<PluginUtil.CheckerProp,Object> props,
PrintStream out,
boolean procOnly,
String outputDirectory)
Build a javac command.
|
static List<String> |
getCmdArgsOnly(File javacPath,
File jdkPath,
File srcFofn,
String processors,
String checkerHome,
String javaHome,
File classpathFofn,
String bootClassPath,
Map<PluginUtil.CheckerProp,Object> props,
PrintStream out,
boolean procOnly,
String outputDirectory) |
static List<String> |
getCmdArgsOnly(File srcFofn,
String processors,
String checkerHome,
String javaHome,
File classpathFofn,
String bootClassPath,
Map<PluginUtil.CheckerProp,Object> props,
PrintStream out,
boolean procOnly,
String outputDirectory) |
static String |
getJavaCommand(String javaHome,
PrintStream out) |
static String |
getJdkJarName()
Determine the version of the JRE that we are currently running and select a jdkX.jar where X
is the version of Java that is being run (e.g.
|
static String |
getJdkJarPrefix()
Determine the version of the JRE that we are currently running and select a jdkX where X is
the version of Java that is being run (e.g.
|
static int |
getJreVersion()
Returns the major JRE version.
|
static @Nullable String |
getReleaseValue(ProcessingEnvironment env)
Returns the release value passed to the compiler or null if release was not passed.
|
static List<String> |
getStringProp(Map<PluginUtil.CheckerProp,Object> props,
PluginUtil.CheckerProp prop,
String cmdLineArgStart,
String... extras)
Returns a list of command-line arguments: one that sets the given property, plus everything
in extras.
|
static boolean |
isWindows() |
static String |
join(String delimiter,
Iterable<?> values) |
static <T> String |
join(String delimiter,
T[] objs) |
static List<String> |
readFile(File argFile)
Return a list of Strings, one per line of the file.
|
static List<File> |
toFiles(List<String> fileNames) |
static List<String> |
toJavaOpts(List<String> opts) |
static String |
wrapArg(String classpath) |
static void |
writeFile(File destination,
List<String> contents)
Write the strings to the file, one per line.
|
static void |
writeFofn(File destination,
File... files)
Takes a list of files and writes it as a "File of file names" (i.e.
|
static void |
writeFofn(File destination,
List<File> files)
Takes a list of files and writes it as a "File of file names" (i.e.
|
static File |
writeTmpCpFile(String prefix,
boolean deleteOnExit,
String classpath) |
static File |
writeTmpFile(String prefix,
String suffix,
boolean deleteOnExit,
List<String> args)
Write the strings to a temporary file.
|
static File |
writeTmpFofn(String prefix,
String suffix,
boolean deleteOnExit,
List<File> files) |
static File |
writeTmpSrcFofn(String prefix,
boolean deleteOnExit,
List<File> files) |
public static final String CHECKER_QUAL_PATH_OPT
public static final String JAVAC_PATH_OPT
public static final String JDK_PATH_OPT
public static void writeFofn(File destination, List<File> files) throws IOException
destination
- the fofn file we are writing. This file will contain newline separated
list of absolute file paths.files
- the files to write to the destination fileIOException
public static void writeFofn(File destination, File... files) throws IOException
destination
- the fofn file we are writing. This file will contain newline separated
list of absolute file paths.files
- the files to write to the destination fileIOException
public static File writeTmpFofn(String prefix, String suffix, boolean deleteOnExit, List<File> files) throws IOException
IOException
public static File writeTmpFile(String prefix, String suffix, boolean deleteOnExit, List<String> args) throws IOException
deleteOnExit
- if true, delete the file on program exitIOException
public static void writeFile(File destination, List<String> contents) throws IOException
IOException
public static List<String> readFile(File argFile) throws IOException
IOException
public static List<String> getStringProp(Map<PluginUtil.CheckerProp,Object> props, PluginUtil.CheckerProp prop, String cmdLineArgStart, String... extras)
prop
- the property to look up in propscmdLineArgStart
- the command-line argument that introduces proppublic static List<String> getBooleanProp(Map<PluginUtil.CheckerProp,Object> props, PluginUtil.CheckerProp prop, String cmdLineArg)
cmdLineArg
. Otherwise, return
a 0-element list.public static boolean getBooleanSystemProperty(String key)
public static boolean getBooleanSystemProperty(String key, boolean defaultValue)
public static File writeTmpSrcFofn(String prefix, boolean deleteOnExit, List<File> files) throws IOException
IOException
public static File writeTmpCpFile(String prefix, boolean deleteOnExit, String classpath) throws IOException
IOException
public static boolean isWindows()
public static String getJavaCommand(String javaHome, PrintStream out)
public static List<String> getCmd(@Nullable String executable, @Nullable File javacPath, @Nullable File jdkPath, File srcFofn, String processors, String checkerHome, String javaHome, File classPathFofn, String bootClassPath, Map<PluginUtil.CheckerProp,Object> props, PrintStream out, boolean procOnly, String outputDirectory)
public static List<String> getCmdArgsOnly(File srcFofn, String processors, String checkerHome, String javaHome, File classpathFofn, String bootClassPath, Map<PluginUtil.CheckerProp,Object> props, PrintStream out, boolean procOnly, String outputDirectory)
public static List<String> getCmdArgsOnly(File javacPath, File jdkPath, File srcFofn, String processors, String checkerHome, String javaHome, File classpathFofn, String bootClassPath, Map<PluginUtil.CheckerProp,Object> props, PrintStream out, boolean procOnly, String outputDirectory)
public static int getJreVersion()
This is different from the version passed to the compiler via --release; use getReleaseValue(ProcessingEnvironment)
to get that version.
Extract the major version number from the "java.version" system property. Two possible formats are considered. Up to Java 8, from a version string like `1.8.whatever`, this method extracts 8. Since Java 9, from a version string like `11.0.1`, this method extracts 11.
public static String getJdkJarPrefix()
public static String getJdkJarName()
public static @Nullable String getReleaseValue(ProcessingEnvironment env)
env
- the ProcessingEnvironment