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;
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;
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;
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 =
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();}
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);
//}
}
+ /**
+ * 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();