diff options
author | Andy Clement <aclement@gopivotal.com> | 2015-03-04 16:05:27 -0800 |
---|---|---|
committer | Andy Clement <aclement@gopivotal.com> | 2015-03-04 16:05:27 -0800 |
commit | c4d7b61ef3f9e5b54f3216b049a106f2523a60a4 (patch) | |
tree | c1602049db800a33b25ac873bd04c3c0a6383ea8 /weaver | |
parent | 3869f363bc6e473f4063faf2c296825283a21f1a (diff) | |
download | aspectj-c4d7b61ef3f9e5b54f3216b049a106f2523a60a4.tar.gz aspectj-c4d7b61ef3f9e5b54f3216b049a106f2523a60a4.zip |
very early java9 support - can resolve classes in jimages
Diffstat (limited to 'weaver')
-rw-r--r-- | weaver/.classpath | 2 | ||||
-rw-r--r-- | weaver/.settings/org.eclipse.jdt.core.prefs | 11 | ||||
-rw-r--r-- | weaver/src/org/aspectj/weaver/bcel/ClassPathManager.java | 128 |
3 files changed, 138 insertions, 3 deletions
diff --git a/weaver/.classpath b/weaver/.classpath index 179779f13..1930f369b 100644 --- a/weaver/.classpath +++ b/weaver/.classpath @@ -11,7 +11,7 @@ <classpathentry combineaccessrules="false" kind="src" path="/aspectj5rt"/> <classpathentry kind="lib" path="/lib/commons/commons.jar" sourcepath="/lib/commons/commons-src.zip"/> <classpathentry kind="lib" path="/lib/bcel/bcel.jar" sourcepath="/lib/bcel/bcel-src.zip"/> - <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"/> <classpathentry combineaccessrules="false" kind="src" path="/org.aspectj.matcher"/> <classpathentry kind="lib" path="/lib/asm/asm-5.0.1.renamed.jar"/> <classpathentry kind="output" path="bin"/> diff --git a/weaver/.settings/org.eclipse.jdt.core.prefs b/weaver/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 000000000..7341ab168 --- /dev/null +++ b/weaver/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,11 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 +org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve +org.eclipse.jdt.core.compiler.compliance=1.7 +org.eclipse.jdt.core.compiler.debug.lineNumber=generate +org.eclipse.jdt.core.compiler.debug.localVariable=generate +org.eclipse.jdt.core.compiler.debug.sourceFile=generate +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.7 diff --git a/weaver/src/org/aspectj/weaver/bcel/ClassPathManager.java b/weaver/src/org/aspectj/weaver/bcel/ClassPathManager.java index 83b7efdac..8d9bed883 100644 --- a/weaver/src/org/aspectj/weaver/bcel/ClassPathManager.java +++ b/weaver/src/org/aspectj/weaver/bcel/ClassPathManager.java @@ -12,11 +12,19 @@ package org.aspectj.weaver.bcel; +import java.io.ByteArrayInputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; +import java.net.URI; +import java.nio.file.DirectoryStream; +import java.nio.file.FileSystem; +import java.nio.file.FileSystems; +import java.nio.file.Files; +import java.nio.file.NoSuchFileException; +import java.nio.file.Path; import java.util.ArrayList; import java.util.Enumeration; import java.util.Iterator; @@ -59,7 +67,7 @@ public class ClassPathManager { trace.enter("<init>", this, new Object[] { classpath, handler }); entries = new ArrayList<Entry>(); for (Iterator<String> i = classpath.iterator(); i.hasNext();) { - String name = (String) i.next(); + String name = i.next(); addPath(name, handler); } if (trace.isTraceEnabled()) @@ -69,6 +77,10 @@ public class ClassPathManager { protected ClassPathManager() { } + private static URI JRT_URI = URI.create("jrt:/"); //$NON-NLS-1$ + + private static String JAVA_BASE_PATH = "java.base"; //$NON-NLS-1$ + public void addPath(String name, IMessageHandler handler) { File f = new File(name); String lc = name.toLowerCase(); @@ -83,7 +95,12 @@ public class ClassPathManager { return; } try { - entries.add(new ZipFileEntry(f)); + if (lc.endsWith(".jimage")) { + // Java9 + entries.add(new JImageEntry(f)); + } else { + entries.add(new ZipFileEntry(f)); + } } catch (IOException ioe) { MessageUtil.warn(handler, WeaverMessages.format(WeaverMessages.ZIPFILE_ENTRY_INVALID, name, ioe.getMessage())); return; @@ -103,6 +120,7 @@ public class ClassPathManager { return ret; } catch (IOException ioe) { // this is NOT an error: it's valid to have missing classpath entries + ioe.printStackTrace(); i.remove(); } @@ -154,6 +172,41 @@ public class ClassPathManager { // public abstract List getAllClassFiles() throws IOException; } + + private static class ByteBasedClassFile extends ClassFile { + + private byte[] bytes; + private ByteArrayInputStream bais; + private String path; + + public ByteBasedClassFile(byte[] bytes, String path) { + this.bytes = bytes; + this.path = path; + } + + @Override + public InputStream getInputStream() throws IOException { + this.bais = new ByteArrayInputStream(bytes); + return this.bais; + } + + @Override + public String getPath() { + return this.path; + } + + @Override + public void close() { + if (this.bais!=null) { + try { + this.bais.close(); + } catch (IOException e) { + } + this.bais = null; + } + } + + } private static class FileClassFile extends ClassFile { private File file; @@ -243,6 +296,77 @@ public class ClassPathManager { } } + + public class JImageEntry extends Entry { + private FileSystem fs; + + public JImageEntry(File file) { + fs = FileSystems.getFileSystem(JRT_URI); +// Iterable<java.nio.file.Path> roots = fs.getRootDirectories(); +// java.nio.file.Path basePath = null; +// try { +// System.err.println("Find on javax.naming.Context: "+find("javax.naming.Context")); +// } catch (IOException e) { +// // TODO Auto-generated catch block +// e.printStackTrace(); +// } +// roots: for (java.nio.file.Path path : roots) { +// System.err.println(">>"+path); +// try (DirectoryStream<java.nio.file.Path> stream = Files.newDirectoryStream(path)) { +// for (java.nio.file.Path subdir: stream) { +// System.err.println(">>>"+subdir); +//// if (subdir.toString().indexOf(JAVA_BASE_PATH) != -1) { +//// basePath = subdir; +//// break roots; +//// } +// } +// } catch (Exception e) { +// e.printStackTrace(); +// } +// } + } + + @Override + public ClassFile find(String name) throws IOException { + String fileName = name.replace('.', '/') + ".class"; + try { + Path p = fs.getPath(JAVA_BASE_PATH,fileName); + byte[] bs = Files.readAllBytes(p); + return new ByteBasedClassFile(bs, fileName); + } catch (NoSuchFileException nsfe) { + // try other modules! + Iterable<java.nio.file.Path> roots = fs.getRootDirectories(); + for (java.nio.file.Path path : roots) { + DirectoryStream<java.nio.file.Path> stream = Files.newDirectoryStream(path); + try { + for (java.nio.file.Path module: stream) { + try { + Path p = fs.getPath(module.toString(),fileName); + byte[] bs = Files.readAllBytes(p); + return new ByteBasedClassFile(bs, fileName); + } catch (NoSuchFileException nsfe2) { + } + } + } finally { + stream.close(); + } + } + return null; + } + } + + public ClassFile find(String module, String name) throws IOException { + String fileName = name.replace('.', '/') + ".class"; + try { + Path p = fs.getPath(module,fileName); + byte[] bs = Files.readAllBytes(p); + return new ByteBasedClassFile(bs, fileName); + } catch (NoSuchFileException nsfe) { + return null; + } + } + + } public class ZipFileEntry extends Entry { private File file; |