Skip to content

Commit

Permalink
JANDEX-6 don't treat individual file errors as fatal. Cleanup error h…
Browse files Browse the repository at this point in the history
…andling a bit. Don't display usage unless there is an argument error.
  • Loading branch information
n1hility committed Aug 12, 2011
1 parent 5581d3d commit 6e98e8d
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/main/java/org/jboss/jandex/Indexer.java
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ private void verifyMagic(DataInputStream stream) throws IOException {

stream.readFully(buf);
if (buf[0] != (byte)0xCA || buf[1] != (byte)0xFE || buf[2] != (byte)0xBA || buf[3] != (byte)0xBE)
throw new RuntimeException("Invalid Magic");
throw new IOException("Invalid Magic");

}

Expand Down
12 changes: 9 additions & 3 deletions src/main/java/org/jboss/jandex/JarIndexer.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,15 @@ public static Result createJarIndex(File jarFile, Indexer indexer, boolean modif
}

if (entry.getName().endsWith(".class")) {
ClassInfo info = indexer.index(jar.getInputStream(entry));
if (verbose && info != null)
printIndexEntryInfo(info);
try {
ClassInfo info = indexer.index(jar.getInputStream(entry));
if (verbose && info != null)
printIndexEntryInfo(info);
} catch (Exception e) {
String message = e.getMessage() == null ? e.getClass().getSimpleName() : e.getMessage();
System.err.println("ERROR: Could not index " + entry.getName() + ": " + message); if (verbose)
e.printStackTrace(System.err);
}
}
}

Expand Down
22 changes: 17 additions & 5 deletions src/main/java/org/jboss/jandex/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,11 @@ public static void main(String[] args) {


private void execute(String[] args) {
boolean printUsage = true;
try {
parseOptions(args);

printUsage = false;
if (dump) {
dumpIndex(source);
return;
Expand All @@ -76,8 +78,10 @@ private void execute(String[] args) {
e.printStackTrace(System.err);
}

System.out.println();
printUsage();
if (printUsage) {
System.out.println();
printUsage();
}
}
}

Expand Down Expand Up @@ -136,9 +140,17 @@ private void scanFile(File source, Indexer indexer) throws FileNotFoundException
}

FileInputStream input = new FileInputStream(source);
ClassInfo info = indexer.index(input);
if (verbose)
printIndexEntryInfo(info);

try {
ClassInfo info = indexer.index(input);
if (verbose && info != null)
printIndexEntryInfo(info);
} catch (Exception e) {
String message = e.getMessage() == null ? e.getClass().getSimpleName() : e.getMessage();
System.err.println("ERROR: Could not index " + source.getName() + ": " + message);
if (verbose)
e.printStackTrace(System.err);
}

return;
}
Expand Down

0 comments on commit 6e98e8d

Please sign in to comment.