Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add -Aversion command-line option; fixes #3381 #3464

Merged
merged 14 commits into from
Jul 20, 2020
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,8 @@

/// Amount of detail in messages

// Print the version of the Checker Framework
"version",
mernst marked this conversation as resolved.
Show resolved Hide resolved
// Print info about git repository from which the Checker Framework was compiled
"printGitProperties",

Expand Down Expand Up @@ -781,6 +783,9 @@ public void run() {
}
});
}
if (hasOption("version")) {
messager.printMessage(Kind.NOTE, "Checker Framework " + getCheckerVersion());
}
} catch (UserError ce) {
logUserError(ce);
} catch (TypeSystemError ce) {
Expand Down Expand Up @@ -2530,4 +2535,33 @@ private void printGitProperties() {
System.out.println("IOException while reading git.properties: " + e.getMessage());
}
}

/**
* Extract the version of the Checker Framework
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: end sentences with punctuation (in this case, a period).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you use "Extract", say from where. Even better, I would leave implementation details like that out of the specification and just use "Returns".

*
* @throws IOException if unable to read docs/developer/release/release.properties or
* docs/examples/MavenExample/pom.xml file
* @throws NullPointerException if tag present in release.properties for Checker Framework
* version is not found in docs/examples/MavenExample/pom.xml
* @return Checker Framework version {@link String}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is usually not necessary to state the type, which is already stated nearby in the source code and in the generated API documentation.

*/
private String getCheckerVersion() throws IOException {
String version = null;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this variable needed?

String RLS_FILE = "/docs/developer/release/release.properties";
Properties releaseProperties = getProperties(getClass(), RLS_FILE);
String startTag = releaseProperties.getProperty("checkers.ver.0");
String endTag = releaseProperties.getProperty("checkers.ver.1");
String XML_FILE = "/docs/examples/MavenExample/pom.xml";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this work? It crashed for me when I tried to run it, because neither of the two files is not available in checker.jar.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could use git.properties instead. See method printGitProperties.

InputStream in = getClass().getResourceAsStream(XML_FILE);
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
String line = null;
while ((line = reader.readLine()) != null) {
if (line.split(startTag).length > 1) {
version = line.split(startTag)[1].split(endTag)[0];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line can be combined with the following one.

return version;
}
}
throw new NullPointerException(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an odd choice of exception. Why not use BugInCF?

"Could not find the version tag as mentioned in release.properties");
}
}