Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-dev] AspectJ 1.8 and modularized JARs

OK, patch is attached. It's based off the V1_8_13 tag. ​

diff --git a/ajde.core/testdata/IgnoreJava9JarElements/.gitignore b/ajde.core/testdata/IgnoreJava9JarElements/.gitignore
new file mode 100644
index 000000000..f8b92c3aa
--- /dev/null
+++ b/ajde.core/testdata/IgnoreJava9JarElements/.gitignore
@@ -0,0 +1,2 @@
+.gradle
+build
diff --git a/ajde.core/testdata/IgnoreJava9JarElements/README b/ajde.core/testdata/IgnoreJava9JarElements/README
new file mode 100644
index 000000000..2993093bd
--- /dev/null
+++ b/ajde.core/testdata/IgnoreJava9JarElements/README
@@ -0,0 +1,2 @@
+Generates a modular, multi-release JAR. To regenerate, run `gradle jar`. The output
+is `build/libs/IgnoreJava9JarElements.jar`.
diff --git a/ajde.core/testdata/IgnoreJava9JarElements/build.gradle b/ajde.core/testdata/IgnoreJava9JarElements/build.gradle
new file mode 100644
index 000000000..70ee66060
--- /dev/null
+++ b/ajde.core/testdata/IgnoreJava9JarElements/build.gradle
@@ -0,0 +1,54 @@
+/*******************************************************************************
+ * Copyright (c) 2019 Contributors
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+
+apply plugin: 'java-library'
+
+if (!JavaVersion.current().isJava11Compatible()) {
+   throw new GradleException("Run with with JDK 11 or newer.")
+}
+
+sourceSets {
+   java11 {
+      java {
+       srcDirs = ['src/main/java11']
+      }
+   }
+   moduleInfo {
+      java {
+         srcDirs = ['src/main/module-info']
+      }
+   }
+}
+
+compileJava {
+   sourceCompatibility = 8
+   targetCompatibility = 8
+}
+
+compileJava11Java {
+   sourceCompatibility = 11
+   targetCompatibility = 11
+}
+
+compileModuleInfoJava {
+   sourceCompatibility = 11
+   targetCompatibility = 11
+}
+
+jar {
+   into('META-INF/versions/11') {
+      from sourceSets.java11.output
+   }
+   into('') {
+      from sourceSets.moduleInfo.output
+   }
+   manifest.attributes(
+      'Multi-Release': 'true',
+      'Main-Class': 'org.aspectj.JdkSpecific'
+   )
+}
diff --git a/ajde.core/testdata/IgnoreJava9JarElements/src/main/java/org/aspectj/JdkSpecific.java b/ajde.core/testdata/IgnoreJava9JarElements/src/main/java/org/aspectj/JdkSpecific.java
new file mode 100644
index 000000000..eb4a5fe6c
--- /dev/null
+++ b/ajde.core/testdata/IgnoreJava9JarElements/src/main/java/org/aspectj/JdkSpecific.java
@@ -0,0 +1,15 @@
+/*******************************************************************************
+ * Copyright (c) 2019 Contributors
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+
+package org.aspectj;
+
+public class JdkSpecific {
+     public static void main(String... args) {
+         System.out.println("This is the Java 8 version of the class.");
+     }
+}
diff --git a/ajde.core/testdata/IgnoreJava9JarElements/src/main/java11/org/aspectj/JdkSpecific.java b/ajde.core/testdata/IgnoreJava9JarElements/src/main/java11/org/aspectj/JdkSpecific.java
new file mode 100644
index 000000000..c560eea91
--- /dev/null
+++ b/ajde.core/testdata/IgnoreJava9JarElements/src/main/java11/org/aspectj/JdkSpecific.java
@@ -0,0 +1,15 @@
+/*******************************************************************************
+ * Copyright (c) 2019 Contributors
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+
+package org.aspectj;
+
+public class JdkSpecific {
+     public static void main(String... args) {
+         System.out.println("This is the Java 11 version of the class.");
+     }
+}
diff --git a/ajde.core/testdata/IgnoreJava9JarElements/src/main/module-info/module-info.java b/ajde.core/testdata/IgnoreJava9JarElements/src/main/module-info/module-info.java
new file mode 100644
index 000000000..8bee12d57
--- /dev/null
+++ b/ajde.core/testdata/IgnoreJava9JarElements/src/main/module-info/module-info.java
@@ -0,0 +1,11 @@
+/*******************************************************************************
+ * Copyright (c) 2019 Contributors
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+
+module org.aspectj.java9plusjar {
+
+}
diff --git a/ajde.core/testsrc/org/aspectj/ajde/core/tests/IgnoreJava9JarElements.java b/ajde.core/testsrc/org/aspectj/ajde/core/tests/IgnoreJava9JarElements.java
new file mode 100644
index 000000000..0de4b811c
--- /dev/null
+++ b/ajde.core/testsrc/org/aspectj/ajde/core/tests/IgnoreJava9JarElements.java
@@ -0,0 +1,76 @@
+/*******************************************************************************
+ * Copyright (c) 2019 Contributors
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+package org.aspectj.ajde.core.tests;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Enumeration;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.jar.JarEntry;
+import java.util.jar.JarFile;
+import java.util.jar.Manifest;
+
+import org.aspectj.ajde.core.AjdeCoreTestCase;
+import org.aspectj.ajde.core.TestCompilerConfiguration;
+import org.aspectj.ajde.core.TestMessageHandler;
+
+public class IgnoreJava9JarElements extends AjdeCoreTestCase {
+
+    public static final String injarName = "build/libs/IgnoreJava9JarElements.jar";
+    public static final String outjarName = "outjar.jar";
+
+    private TestMessageHandler handler;
+    private TestCompilerConfiguration compilerConfig;
+
+    protected void setUp() throws Exception {
+        super.setUp();
+        initialiseProject("IgnoreJava9JarElements");
+        handler = (TestMessageHandler) getCompiler().getMessageHandler();
+        compilerConfig = (TestCompilerConfiguration) getCompiler()
+                .getCompilerConfiguration();
+    }
+
+    protected void tearDown() throws Exception {
+        super.tearDown();
+        handler = null;
+        compilerConfig = null;
+    }
+
+    public void testWeave() {
+        Set<File> injars = new HashSet<File>();
+        injars.add(openFile(injarName));
+        compilerConfig.setInpath(injars);
+        Set<File> aspectpath = new HashSet<File>();
+        compilerConfig.setAspectPath(aspectpath);
+        File outjar = openFile(outjarName);
+        compilerConfig.setOutjar(outjar.getAbsolutePath());
+        doBuild(true);
+        assertTrue("Expected no compiler errors or warnings but found "
+                + handler.getMessages(), handler.getMessages().isEmpty());
+        compareManifests(openFile(injarName), openFile(outjarName));
+    }
+
+    private void compareManifests(File inFile, File outFile) {
+
+        try {
+            JarFile inJar = new JarFile(inFile);
+            Manifest inManifest = inJar.getManifest();
+            inJar.close();
+            JarFile outJar = new JarFile(outFile);
+            Manifest outManifest = outJar.getManifest();
+            outJar.close();
+            assertTrue("The manifests in '" + inFile.getCanonicalPath()
+                    + "' and '" + outFile.getCanonicalPath()
+                    + "' sould be the same", inManifest.equals(outManifest));
+        } catch (IOException ex) {
+            fail(ex.toString());
+        }
+    }
+
+}
diff --git a/weaver/src/org/aspectj/weaver/bcel/BcelWeaver.java b/weaver/src/org/aspectj/weaver/bcel/BcelWeaver.java
index 1a66c72b3..8766abe10 100644
--- a/weaver/src/org/aspectj/weaver/bcel/BcelWeaver.java
+++ b/weaver/src/org/aspectj/weaver/bcel/BcelWeaver.java
@@ -391,15 +391,23 @@ public class BcelWeaver {
 
 					while (entries.hasMoreElements()) {
 						JarEntry entry = (JarEntry) entries.nextElement();
+						String filename = entry.getName();
+						String filenameLowercase = filename.toLowerCase();
+
+						// Ignore class files that Java 8 won't understand (multi-release and module-info)
+						if (filenameLowercase.startsWith("meta-inf")
+								|| filenameLowercase.endsWith("module-info.class")) {
+							continue;
+						}
+
 						InputStream inStream = inJar.getInputStream(entry);
 
 						byte[] bytes = FileUtil.readAsByteArray(inStream);
-						String filename = entry.getName();
 						// System.out.println("? addJarFile() filename='" + filename
 						// + "'");
 						UnwovenClassFile classFile = new UnwovenClassFile(new File(outDir, filename).getAbsolutePath(), bytes);
 
-						if (filename.endsWith(".class")) {
+						if (filenameLowercase.endsWith(".class")) {
 							ReferenceType type = this.addClassFile(classFile, false);
 							StringBuffer sb = new StringBuffer();
 							sb.append(inFile.getAbsolutePath());

Back to the top