Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/manual/creating-a-checker.tex
Original file line number Diff line number Diff line change
Expand Up @@ -1987,6 +1987,11 @@
While creating a stub file, you may find the debugging options described in
Section~\ref{stub-troubleshooting} useful.

\item
If you want to use an external annotated JDK .jar file, you can specify it when you run the checker:
\begin{Verbatim}
javac -J-Dchecker.annotated.jdk.jar=/path/to/annotated-jdk.jar -processor <YourChecker> ...
\end{Verbatim}
\end{itemize}


Expand Down
31 changes: 28 additions & 3 deletions framework/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ task copyAndMinimizeAnnotatedJdkFiles(type: JavaExec, dependsOn: cloneAnnotatedJ
dependsOn ':javacutil:jar'
dependsOn ':dataflow:jar'
def inputDir = "${annotatedJdkHome}/src"
def outputDir = "${buildDir}/generated/resources/annotated-jdk/"
def outputDir = "${buildDir}/generated/annotated-jdk/"

description = "Copy annotated JDK files to ${outputDir}. Removes private and package-private methods, method bodies, comments, etc. from the annotated JDK"

Expand All @@ -119,6 +119,22 @@ task copyAndMinimizeAnnotatedJdkFiles(type: JavaExec, dependsOn: cloneAnnotatedJ
args outputDir

doFirst {
if (project.hasProperty('annotatedJdkBranch')) {
def repoDir = file(annotatedJdkHome)
exec {
workingDir repoDir
commandLine 'git', 'fetch', '--all', '--tags'
}
exec {
workingDir repoDir
commandLine 'git', 'checkout', project.property('annotatedJdkBranch')
}
exec {
workingDir repoDir
commandLine 'git', 'pull', '--ff-only'
}
}

FileTree tree = fileTree(dir: inputDir)
NavigableSet<String> annotatedForFiles = new TreeSet<>();
// Populate `annotatedForFiles`.
Expand All @@ -145,8 +161,17 @@ task copyAndMinimizeAnnotatedJdkFiles(type: JavaExec, dependsOn: cloneAnnotatedJ
}
}

sourcesJar.dependsOn(copyAndMinimizeAnnotatedJdkFiles)
processResources.dependsOn(copyAndMinimizeAnnotatedJdkFiles)

task annotatedJdkJar(type: Jar, dependsOn: copyAndMinimizeAnnotatedJdkFiles, group: 'Build') {
description = 'Packages the generated annotated JDK stubs into annotated-jdk.jar at the repository root'
destinationDirectory = rootProject.layout.projectDirectory.dir("checker/dist");
archiveFileName = 'annotated-jdk.jar'
from("${buildDir}/generated/annotated-jdk") {
into 'annotated-jdk'
}
}

processResources.dependsOn(annotatedJdkJar)

task allSourcesJar(type: Jar, group: 'Build') {
description = 'Creates a sources jar that includes sources for all Checker Framework classes in framework.jar'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -857,13 +857,50 @@ private void parseJdkJarEntry(String jarEntryName) {
}
}

private final URL getAnnotatedJDKResourceURL(String resourcePath) {
try {
URL resourceURL = null;
File externalJdkFile = new File(resourcePath);
if (externalJdkFile.exists()) {
resourceURL =
new URL(
"jar:file:"
+ externalJdkFile.getAbsolutePath()
+ "!/annotated-jdk");
}
return resourceURL;
} catch (Exception e) {
if (stubDebug) {
System.out.printf(
"Failed to load external annotated JDK from %s: %s%n",
resourcePath, e.getMessage());
}
return null;
}
}

/**
* Returns a JarURLConnection to "/jdk*".
*
* @return a JarURLConnection to "/jdk*"
*/
private JarURLConnection getJarURLConnectionToJdk() {
URL resourceURL = atypeFactory.getClass().getResource("/annotated-jdk");
// First, try to use the external annotated-jdk.jar file if specified
String pathFromProperty = System.getProperty("checker.annotated.jdk.jar");
URL resourceURL = getAnnotatedJDKResourceURL(pathFromProperty);
if (resourceURL == null) {
// Get the location of checker.jar
URL location =
atypeFactory.getClass().getProtectionDomain().getCodeSource().getLocation();
try {
Path checkerDir = Paths.get(location.toURI()).getParent();
String annotatedJarPath = checkerDir.resolve("annotated-jdk.jar").toString();
resourceURL = getAnnotatedJDKResourceURL(annotatedJarPath);
} catch (URISyntaxException e) {
throw new BugInCF("Cannot parse URL: " + location.toString(), e);
}
}

JarURLConnection connection;
try {
connection = (JarURLConnection) resourceURL.openConnection();
Expand Down
Loading