summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwisberg <wisberg>2006-09-07 07:04:31 +0000
committerwisberg <wisberg>2006-09-07 07:04:31 +0000
commit0409738040af0a34cd76739dfff22d8c622198b2 (patch)
treeb3f1e67ca0459db219ede36b187118911f6a26e1
parent090de7e4c5c9618f965259f93de6d490050543da (diff)
downloadaspectj-0409738040af0a34cd76739dfff22d8c622198b2.tar.gz
aspectj-0409738040af0a34cd76739dfff22d8c622198b2.zip
refix 112098 - check for correct aspectjrt.jar version re-enabled for Main (taskdef, command-line) but still disabled otherwise (for AJDT)
-rw-r--r--org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AjBuildManager.java88
1 files changed, 88 insertions, 0 deletions
diff --git a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AjBuildManager.java b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AjBuildManager.java
index 5fc00afe8..79215b62c 100644
--- a/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AjBuildManager.java
+++ b/org.aspectj.ajdt.core/src/org/aspectj/ajdt/internal/core/builder/AjBuildManager.java
@@ -29,6 +29,8 @@ import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
+import java.util.jar.Attributes;
+import java.util.jar.JarFile;
import java.util.jar.JarInputStream;
import java.util.jar.JarOutputStream;
import java.util.jar.Manifest;
@@ -59,6 +61,7 @@ import org.aspectj.bridge.IProgressListener;
import org.aspectj.bridge.Message;
import org.aspectj.bridge.MessageUtil;
import org.aspectj.bridge.SourceLocation;
+import org.aspectj.bridge.Version;
import org.aspectj.bridge.context.CompilationAndWeavingContext;
import org.aspectj.bridge.context.ContextFormatter;
import org.aspectj.bridge.context.ContextToken;
@@ -78,6 +81,7 @@ import org.aspectj.org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
import org.aspectj.org.eclipse.jdt.internal.compiler.parser.Parser;
import org.aspectj.org.eclipse.jdt.internal.compiler.problem.AbortCompilation;
import org.aspectj.org.eclipse.jdt.internal.compiler.problem.DefaultProblemFactory;
+import org.aspectj.tools.ajc.Main;
import org.aspectj.util.FileUtil;
import org.aspectj.weaver.Dump;
import org.aspectj.weaver.ResolvedType;
@@ -92,6 +96,9 @@ public class AjBuildManager implements IOutputClassFileNameProvider,IBinarySourc
private static final String CANT_WRITE_RESULT = "unable to write compilation result";
private static final String MANIFEST_NAME = "META-INF/MANIFEST.MF";
static final boolean COPY_INPATH_DIR_RESOURCES = false;
+ // AJDT doesn't want this check, so Main enables it.
+ private static boolean DO_RUNTIME_VERSION_CHECK = false;
+ // If runtime version check fails, warn or fail? (unset?)
static final boolean FAIL_IF_RUNTIME_NOT_FOUND = false;
private static final FileFilter binarySourceFilter =
@@ -135,6 +142,14 @@ public class AjBuildManager implements IOutputClassFileNameProvider,IBinarySourc
AjState state = new AjState(this);
+ /**
+ * Enable check for runtime version, used only by Ant/command-line Main.
+ * @param main Main unused except to limit to non-null clients.
+ */
+ public static void enableRuntimeVersionCheck(Main caller) {
+ DO_RUNTIME_VERSION_CHECK = null != caller;
+ }
+
public BcelWeaver getWeaver() { return state.getWeaver();}
public BcelWorld getBcelWorld() { return state.getBcelWorld();}
@@ -199,6 +214,19 @@ public class AjBuildManager implements IOutputClassFileNameProvider,IBinarySourc
this.handler =
CountingMessageHandler.makeCountingMessageHandler(baseHandler);
+ if (DO_RUNTIME_VERSION_CHECK) {
+ String check = checkRtJar(buildConfig);
+ if (check != null) {
+ if (FAIL_IF_RUNTIME_NOT_FOUND) {
+ MessageUtil.error(handler, check);
+ CompilationAndWeavingContext.leavingPhase(ct);
+ return false;
+ } else {
+ MessageUtil.warn(handler, check);
+ }
+ }
+ }
+
// if (batch) {
setBuildConfig(buildConfig);
//}
@@ -1066,6 +1094,66 @@ public class AjBuildManager implements IOutputClassFileNameProvider,IBinarySourc
}
+ /**
+ * This will return null if aspectjrt.jar is present and has the correct version.
+ * Otherwise it will return a string message indicating the problem.
+ */
+ private String checkRtJar(AjBuildConfig buildConfig) {
+ // omitting dev info
+ if (Version.text.equals(Version.DEVELOPMENT)) {
+ // in the development version we can't do this test usefully
+// MessageUtil.info(holder, "running development version of aspectj compiler");
+ return null;
+ }
+
+ if (buildConfig == null || buildConfig.getFullClasspath() == null) return "no classpath specified";
+
+ String ret = null;
+ for (Iterator it = buildConfig.getFullClasspath().iterator(); it.hasNext(); ) {
+ File p = new File( (String)it.next() );
+ // pr112830, allow variations on aspectjrt.jar of the form aspectjrtXXXXXX.jar
+ if (p.isFile() && p.getName().startsWith("aspectjrt") && p.getName().endsWith(".jar")) {
+
+ try {
+ String version = null;
+ Manifest manifest = new JarFile(p).getManifest();
+ if (manifest == null) {
+ ret = "no manifest found in " + p.getAbsolutePath() +
+ ", expected " + Version.text;
+ continue;
+ }
+ Attributes attr = manifest.getAttributes("org/aspectj/lang/");
+ if (null != attr) {
+ version = attr.getValue(Attributes.Name.IMPLEMENTATION_VERSION);
+ if (null != version) {
+ version = version.trim();
+ }
+ }
+ // assume that users of development aspectjrt.jar know what they're doing
+ if (Version.DEVELOPMENT.equals(version)) {
+// MessageUtil.info(holder,
+// "running with development version of aspectjrt.jar in " +
+// p.getAbsolutePath());
+ return null;
+ } else if (!Version.text.equals(version)) {
+ ret = "bad version number found in " + p.getAbsolutePath() +
+ " expected " + Version.text + " found " + version;
+ continue;
+ }
+ } catch (IOException ioe) {
+ ret = "bad jar file found in " + p.getAbsolutePath() + " error: " + ioe;
+ }
+ return null; // this is the "OK" return value!
+ } else {
+ // might want to catch other classpath errors
+ }
+ }
+
+ if (ret != null) return ret; // last error found in potentially matching jars...
+
+ return "couldn't find aspectjrt.jar on classpath, checked: " + makeClasspathString(buildConfig);
+ }
+
public String toString() {
StringBuffer buf = new StringBuffer();