Skip to content

Commit

Permalink
Get it to work on Windows (and work faster (maybe)) by keeping track of
Browse files Browse the repository at this point in the history
open FDs and closing them at opportune times
  • Loading branch information
jwells131313 committed May 15, 2015
1 parent e0af5f5 commit dc33a5f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,10 @@ public void go() throws AssertionError, IOException {
}
else {
allDescriptors = findAllServicesFromJar(toInspect);

// Do this here to close all FDs so that on Windows we can rewrite the file
utilities.close();

if (noSwap && outJarIsInJar) {
writeToJarNoSwap(toInspect, allDescriptors);
}
Expand All @@ -158,6 +162,7 @@ public void go() throws AssertionError, IOException {
}
}

utilities.close();
}

private void writeToDirectory(List<DescriptorImpl> allDescriptors) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ public class Utilities {

private final boolean verbose;
private final List<File> searchPath = new LinkedList<File>();
private final Map<File, JarFile> openedJarFiles = new HashMap<File, JarFile>();

private final static String CONFIGURED_CONTRACT = "org.jvnet.hk2.config.Configured";

Expand Down Expand Up @@ -368,7 +369,11 @@ private InputStream findClass(List<File> searchHeres, String dotDelimitedName, b
}
}
else {
JarFile jar = new JarFile(searchHere);
JarFile jar = openedJarFiles.get(searchHere);
if (jar == null) {
jar = new JarFile(searchHere);
openedJarFiles.put(searchHere, jar);
}

String entryName = dotDelimitedName.replace('.', '/') + DOT_CLASS;
ZipEntry entry = jar.getEntry(entryName);
Expand Down Expand Up @@ -1173,4 +1178,17 @@ public boolean accept(File dir, String name) {

return new LinkedList<DescriptorImpl>(retVal);
}

public void close() {
for (JarFile closeMe : openedJarFiles.values()) {
try {
closeMe.close();
}
catch (IOException ioe) {
// keep on truckin
}
}

openedJarFiles.clear();
}
}

0 comments on commit dc33a5f

Please sign in to comment.