Cleanup; explicitly handle checksum creation failure

This commit is contained in:
Marco Hunsicker 2016-11-14 17:11:48 +01:00
parent 11daaf9333
commit 068ff9d3d6
3 changed files with 12 additions and 10 deletions

View File

@ -268,9 +268,9 @@ public class Antlr4Mojo extends AbstractMojo {
grammarFiles = getGrammarFiles(sourceDirectory);
importGrammarFiles = getImportFiles(sourceDirectory);
argumentSets = processGrammarFiles(args, grammarFiles, dependencies, sourceDirectory);
} catch (InclusionScanException ie) {
log.error(ie);
throw new MojoExecutionException("Fatal error occured while evaluating the names of the grammar files to analyze", ie);
} catch (Exception e) {
log.error(e);
throw new MojoExecutionException("Fatal error occured while evaluating the names of the grammar files to analyze", e);
}
log.debug("Output directory base will be " + outputDirectory.getAbsolutePath());
@ -385,7 +385,7 @@ public class Antlr4Mojo extends AbstractMojo {
List<String> args,
Set<File> grammarFiles,
GrammarDependencies dependencies,
File sourceDirectory) throws InclusionScanException {
File sourceDirectory) throws InclusionScanException, IOException {
// We don't want the plugin to run for every grammar, regardless of whether
// it's changed since the last compilation. Check the mtime of the tokens vs

View File

@ -56,7 +56,7 @@ class GrammarDependencies {
*
* @return self-reference.
*/
public String getPackage(List<String> arguments) {
private String getPackage(List<String> arguments) {
int index = (arguments != null) ? arguments.indexOf("-package") : -1;
return (index > -1)
@ -90,7 +90,7 @@ class GrammarDependencies {
* @return self-reference.
*/
public GrammarDependencies analyze(Set<File> grammarFiles,
Set<File> importGrammarFiles, Tool tool) {
Set<File> importGrammarFiles, Tool tool) throws IOException {
log.debug("Analysing grammar dependencies " + sourceDirectory);
// for dependency analysis we require all grammars
@ -141,7 +141,7 @@ class GrammarDependencies {
*
* @return {@code true} if a grammar used by the given grammar has been modified.
*/
public boolean isDependencyChanged(File grammarFile) {
public boolean isDependencyChanged(File grammarFile) throws IOException {
String grammarPath = getRelativePath(grammarFile);
for (Map.Entry<File, Map.Entry<byte[], Collection<String>>> e : grammars.entrySet()) {

View File

@ -3,8 +3,10 @@ package org.antlr.mojo.antlr4;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.IOException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
class MojoUtils {
@ -15,7 +17,7 @@ class MojoUtils {
*
* @return the checksum.
*/
public static byte[] checksum(File file) {
public static byte[] checksum(File file) throws IOException {
try {
InputStream in = new FileInputStream(file);
byte[] buffer = new byte[2048];
@ -36,8 +38,8 @@ class MojoUtils {
}
return complete.digest();
} catch (Exception ex) {
throw new RuntimeException("Could not create checksum " + file, ex);
} catch (NoSuchAlgorithmException ex) {
throw new IOException("Could not create checksum " + file, ex);
}
}