From: Andy Clement Date: Mon, 14 Mar 2016 21:05:00 +0000 (-0700) Subject: added logging X-Git-Tag: V1_8_9~1 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=dd331b08b39384132ea4aef15f4bc58f36086554;p=aspectj.git added logging --- diff --git a/weaver/src/org/aspectj/weaver/bcel/ClassPathManager.java b/weaver/src/org/aspectj/weaver/bcel/ClassPathManager.java index 83b7efdac..f176f8880 100644 --- a/weaver/src/org/aspectj/weaver/bcel/ClassPathManager.java +++ b/weaver/src/org/aspectj/weaver/bcel/ClassPathManager.java @@ -34,6 +34,8 @@ import org.aspectj.weaver.tools.TraceFactory; public class ClassPathManager { + private static Trace trace = TraceFactory.getTraceFactory().getTrace(ClassPathManager.class); + private List entries; // In order to control how many open files we have, we maintain a list. @@ -41,29 +43,31 @@ public class ClassPathManager { // org.aspectj.weaver.openarchives // and it defaults to 1000 private List openArchives = new ArrayList(); + private static int maxOpenArchives = -1; + private static final int MAXOPEN_DEFAULT = 1000; - private static Trace trace = TraceFactory.getTraceFactory().getTrace(ClassPathManager.class); - static { - String openzipsString = getSystemPropertyWithoutSecurityException("org.aspectj.weaver.openarchives", Integer - .toString(MAXOPEN_DEFAULT)); + String openzipsString = getSystemPropertyWithoutSecurityException("org.aspectj.weaver.openarchives", + Integer.toString(MAXOPEN_DEFAULT)); maxOpenArchives = Integer.parseInt(openzipsString); - if (maxOpenArchives < 20) + if (maxOpenArchives < 20) { maxOpenArchives = 1000; + } } public ClassPathManager(List classpath, IMessageHandler handler) { - if (trace.isTraceEnabled()) - trace.enter("", this, new Object[] { classpath, handler }); + if (trace.isTraceEnabled()) { + trace.enter("", this, new Object[] { classpath==null?"null":classpath.toString(), handler }); + } entries = new ArrayList(); - for (Iterator i = classpath.iterator(); i.hasNext();) { - String name = (String) i.next(); - addPath(name, handler); + for (String classpathEntry: classpath) { + addPath(classpathEntry,handler); } - if (trace.isTraceEnabled()) + if (trace.isTraceEnabled()) { trace.exit(""); + } } protected ClassPathManager() { @@ -75,7 +79,8 @@ public class ClassPathManager { if (!f.isDirectory()) { if (!f.isFile()) { if (!lc.endsWith(".jar") || lc.endsWith(".zip")) { - // heuristic-only: ending with .jar or .zip means probably a zip file + // heuristic-only: ending with .jar or .zip means probably a + // zip file MessageUtil.info(handler, WeaverMessages.format(WeaverMessages.ZIPFILE_ENTRY_MISSING, name)); } else { MessageUtil.info(handler, WeaverMessages.format(WeaverMessages.DIRECTORY_ENTRY_MISSING, name)); @@ -85,7 +90,8 @@ public class ClassPathManager { try { entries.add(new ZipFileEntry(f)); } catch (IOException ioe) { - MessageUtil.warn(handler, WeaverMessages.format(WeaverMessages.ZIPFILE_ENTRY_INVALID, name, ioe.getMessage())); + MessageUtil.warn(handler, + WeaverMessages.format(WeaverMessages.ZIPFILE_ENTRY_INVALID, name, ioe.getMessage())); return; } } else { @@ -94,18 +100,33 @@ public class ClassPathManager { } public ClassFile find(UnresolvedType type) { + if (trace.isTraceEnabled()) { + trace.enter("find", this, type); + } String name = type.getName(); for (Iterator i = entries.iterator(); i.hasNext();) { Entry entry = i.next(); try { ClassFile ret = entry.find(name); - if (ret != null) + if (trace.isTraceEnabled()) { + trace.event("searching for "+type+" in "+entry.toString()); + } + if (ret != null) { + if (trace.isTraceEnabled()) { + trace.exit("find", ret); + } return ret; + } } catch (IOException ioe) { // this is NOT an error: it's valid to have missing classpath entries + if (trace.isTraceEnabled()) { + trace.error("Removing classpath entry for "+entry,ioe); + } i.remove(); } - + } + if (trace.isTraceEnabled()) { + trace.exit("find", null); } return null; } @@ -124,35 +145,14 @@ public class ClassPathManager { return buf.toString(); } - // /** - // * This method is extremely expensive and should only be called rarely - // */ - // public List getAllClassFiles() { - // List ret = new ArrayList(); - // for (Iterator i = entries.iterator(); i.hasNext(); ) { - // Entry entry = (Entry)i.next(); - // try { - // ret.addAll(entry.getAllClassFiles()); - // } catch (IOException e) { - // i.remove(); - // } - // } - // return ret; - // } - // - public abstract static class ClassFile { public abstract InputStream getInputStream() throws IOException; - public abstract String getPath(); - public abstract void close(); } public abstract static class Entry { public abstract ClassFile find(String name) throws IOException; - - // public abstract List getAllClassFiles() throws IOException; } private static class FileClassFile extends ClassFile { @@ -203,10 +203,6 @@ public class ClassPathManager { return null; } - public List getAllClassFiles() { - throw new RuntimeException("unimplemented"); - } - public String toString() { return dirPath; } @@ -289,7 +285,8 @@ public class ClassPathManager { return; } if (openArchives.size() >= maxOpenArchives) { - closeSomeArchives(openArchives.size() / 10); // Close 10% of those open + closeSomeArchives(openArchives.size() / 10); // Close 10% of + // those open } zipFile = new ZipFile(file); if (!isReallyOpen()) { @@ -300,7 +297,8 @@ public class ClassPathManager { private boolean isReallyOpen() { try { - zipFile.size(); // this will fail if the file has been closed for + zipFile.size(); // this will fail if the file has been closed + // for // some reason; return true; } catch (IllegalStateException ex) { @@ -345,7 +343,7 @@ public class ClassPathManager { } public void closeArchives() { - for (Entry entry: entries) { + for (Entry entry : entries) { if (entry instanceof ZipFileEntry) { ((ZipFileEntry) entry).close(); }