Skip to content

Commit

Permalink
Fix JANDEX-16 -o not working
Browse files Browse the repository at this point in the history
Conflicts:
	src/main/java/org/jboss/jandex/Main.java
  • Loading branch information
n1hility committed Apr 20, 2015
1 parent b3781f0 commit 7c92b8d
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 5 deletions.
44 changes: 42 additions & 2 deletions src/main/java/org/jboss/jandex/JarIndexer.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,24 @@ public static Result createJarIndex(File jarFile, Indexer indexer, boolean modif
return createJarIndex(jarFile, indexer, modify, newJar, verbose, System.out, System.err);
}

/**
* Indexes a jar file and saves the result. If the modify flag is set, index is saved to META-INF/jandex.idx.
* Otherwise an external file is created with a similar name to the original file,
* concatenating <code>.idx</code> suffix.
*
* @param jarFile The file to index
* @param indexer The indexer to use
* @param outputFile The index file to write to
* @param modify If the original jar should be modified
* @param newJar If the new jar should be created
* @param verbose If we should print what we are doing to standard out
* @return indexing result
* @throws IOException for any I/o error
*/
public static Result createJarIndex(File jarFile, Indexer indexer, File outputFile, boolean modify, boolean newJar, boolean verbose) throws IOException {
return createJarIndex(jarFile, indexer, outputFile, modify, newJar, verbose, System.out, System.err);
}

/**
* Indexes a jar file and saves the result. If the modify flag is set, index is saved to META-INF/jandex.idx.
* Otherwise an external file is created with a similar name to the original file,
Expand All @@ -85,10 +103,30 @@ public static Result createJarIndex(File jarFile, Indexer indexer, boolean modif
* @throws IOException for any I/o error
*/
public static Result createJarIndex(File jarFile, Indexer indexer, boolean modify, boolean newJar, boolean verbose, PrintStream infoStream, PrintStream errStream) throws IOException {
return createJarIndex(jarFile, indexer, null, modify, newJar, verbose, infoStream, errStream);
}

/**
* Indexes a jar file and saves the result. If the modify flag is set, index is saved to META-INF/jandex.idx.
* Otherwise an external file is created with a similar name to the original file,
* concatenating <code>.idx</code> suffix.
*
* @param jarFile The file to index
* @param indexer The indexer to use
* @param outputFile The index file to write to
* @param modify If the original jar should be modified
* @param newJar If the new jar should be created
* @param verbose If we should print what we are doing to the specified info stream
* @param infoStream A print stream which will record verbose info, may be null 1
* @param errStream A print stream to print errors, must not be null
*
* @return indexing result
* @throws IOException for any I/o error
*/
public static Result createJarIndex(File jarFile, Indexer indexer, File outputFile, boolean modify, boolean newJar, boolean verbose, PrintStream infoStream, PrintStream errStream) throws IOException {
File tmpCopy = null;
ZipOutputStream zo = null;
OutputStream out;
File outputFile = null;

JarFile jar = new JarFile(jarFile);

Expand All @@ -100,7 +138,9 @@ public static Result createJarIndex(File jarFile, Indexer indexer, boolean modif
outputFile = getIndexFile(jarFile, newJar);
out = zo = new ZipOutputStream(new FileOutputStream(outputFile));
} else {
outputFile = getIndexFile(jarFile, newJar);
if (outputFile == null) {
outputFile = getIndexFile(jarFile, newJar);
}
out = new FileOutputStream(outputFile);
}

Expand Down
7 changes: 4 additions & 3 deletions src/main/java/org/jboss/jandex/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ private void execute(String[] args) {

private Index getIndex(long start) throws IOException {
Indexer indexer = new Indexer();
Result result = (source.isDirectory()) ? indexDirectory(source, indexer) : JarIndexer.createJarIndex(source, indexer, modify, jarFile, verbose);
Result result = (source.isDirectory()) ? indexDirectory(source, indexer) : JarIndexer.createJarIndex(source, indexer, outputFile, modify, jarFile, verbose);

double time = (System.currentTimeMillis() - start) / 1000.00;
System.out.printf("Wrote %s in %.4f seconds (%d classes, %d annotations, %d instances, %d bytes)\n", result.getName(), time, result.getClasses(), result.getAnnotations(), result.getInstances(), result.getBytes());
return result.getIndex();
Expand Down Expand Up @@ -222,11 +223,11 @@ private void parseOptions(String[] args) {
break;
case 'o':
if (i >= args.length)
throw new IllegalArgumentException("-o reuires an output file name");
throw new IllegalArgumentException("-o requires an output file name");

String name = args[++i];
if (name.length() < 1)
throw new IllegalArgumentException("-o reuires an output file name");
throw new IllegalArgumentException("-o requires an output file name");

outputFile = new File(name);
optionCount++;
Expand Down

0 comments on commit 7c92b8d

Please sign in to comment.