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(CharSequence delimiter,
Iterable<?> values)
Returns a new String composed of the string representations of the elements joined together
with a copy of the specified delimiter.
|
static <T> String |
join(CharSequence delimiter,
T[] objs)
Returns a new String composed of the string representations of the elements joined together
with a copy of the specified delimiter.
|
static String |
joinLines(Iterable<? extends Object> v)
Concatenate the string representations of the objects, placing the system-specific line
separator between them.
|
static <T> String |
joinLines(T... a)
Concatenate the string representations of the objects, placing the system-specific line
separator between them.
|
static List<String> |
readFile(File argFile)
Return a list of Strings, one per line of the file.
|
static List<File> |
toFiles(List<String> fileNames)
Convert a list of strings (file names) to a list of files.
|
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 List<File> toFiles(List<String> fileNames)
fileNames
- a list of file namespublic 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 <T> String join(CharSequence delimiter, T[] objs)
T
- the type of array elementsdelimiter
- the delimiter that separates each elementobjs
- the values whose string representations to join togetherpublic static String join(CharSequence delimiter, Iterable<?> values)
delimiter
- the delimiter that separates each elementvalues
- the values whose string representations to join together@SafeVarargs public static <T> String joinLines(T... a)
T
- the type of array elementsa
- array of values to concatenatepublic static String joinLines(Iterable<? extends Object> v)
v
- list of values to concatenatepublic 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