From d92319c43f5723d57887e09f2a839ee5b595fcfd Mon Sep 17 00:00:00 2001 From: Andy Clement Date: Thu, 9 Nov 2017 13:14:02 -0800 Subject: [PATCH] Updates to better cope with future JDKs The version handling in LangUtil has been overhauled to cope better with post 1.8 releases (JDK9 and JDK10 or 18.3 or whatever they call it). As part of this moved to treating JDK9 as '9' rather than '1.9'. Also removed duplicate version processing logic and had that defer to the one place in LangUtil where we now deal with it. Includes some generics tidyup in ajdoc. More ajdoc work is necessary for Java10 because it removes the standard doclet (old style). However trying to invoke the internal Javadoc handler in Java10 is failing due to module visibility rules. --- .../aspectj/tools/ajdoc/HtmlDecorator.java | 30 ++++++------ .../aspectj/tools/ajdoc/JavadocRunner.java | 10 +++- ajdoc/src/org/aspectj/tools/ajdoc/Main.java | 46 +++++++++---------- .../aspectj/tools/ajdoc/StructureUtil.java | 41 ++++++++--------- .../aspectj/tools/ajdoc/AjdocTestCase.java | 6 ++- .../aspectj/tools/ajdoc/CoverageTestCase.java | 2 +- .../src/org/aspectj/weaver/World.java | 3 ++ .../newsrc/org/aspectj/testing/AjcTest.java | 33 +++---------- .../org/aspectj/testing/OutputSpec.java | 22 ++++++++- .../org/aspectj/systemtest/ajc150/ajc150.xml | 38 +++++++-------- .../org/aspectj/systemtest/ajc154/ajc154.xml | 12 ++--- .../systemtest/ajc1611/newfeatures-tests.xml | 2 +- .../aspectj/systemtest/ajc1612/ajc1612.xml | 4 +- .../aspectj/systemtest/ajc169/intertype.xml | 14 +++--- .../org/aspectj/systemtest/ajc170/ajc170.xml | 14 +++--- .../org/aspectj/systemtest/ajc173/ajc173.xml | 2 +- .../systemtest/ajc190/Ajc190Tests.java | 4 -- .../systemtest/ajc190/ajc190_from150.xml | 2 +- util/src/org/aspectj/util/LangUtil.java | 45 +++++++++++++----- ....txt => StaticTjpBeforeHelloWorld.9.0.txt} | 0 ...d.1.9.txt => TjpAround2HelloWorld.9.0.txt} | 0 ...ld.1.9.txt => TjpAroundHelloWorld.9.0.txt} | 0 ...ld.1.9.txt => TjpBeforeHelloWorld.9.0.txt} | 0 23 files changed, 180 insertions(+), 150 deletions(-) rename weaver/testdata/{StaticTjpBeforeHelloWorld.1.9.txt => StaticTjpBeforeHelloWorld.9.0.txt} (100%) rename weaver/testdata/{TjpAround2HelloWorld.1.9.txt => TjpAround2HelloWorld.9.0.txt} (100%) rename weaver/testdata/{TjpAroundHelloWorld.1.9.txt => TjpAroundHelloWorld.9.0.txt} (100%) rename weaver/testdata/{TjpBeforeHelloWorld.1.9.txt => TjpBeforeHelloWorld.9.0.txt} (100%) diff --git a/ajdoc/src/org/aspectj/tools/ajdoc/HtmlDecorator.java b/ajdoc/src/org/aspectj/tools/ajdoc/HtmlDecorator.java index f873c3e55..ec492fce9 100644 --- a/ajdoc/src/org/aspectj/tools/ajdoc/HtmlDecorator.java +++ b/ajdoc/src/org/aspectj/tools/ajdoc/HtmlDecorator.java @@ -48,7 +48,7 @@ class HtmlDecorator { private static final String ITD_FIELD_SUMMARY = "Inter-Type Field Summary"; private static final String ITD_CONSTRUCTOR_SUMMARY = "Inter-Type Constructor Summary"; - static List visibleFileList = new ArrayList(); + static List visibleFileList = new ArrayList(); static Hashtable declIDTable = null; static File rootDir = null; static String docVisibilityModifier; @@ -291,22 +291,22 @@ class HtmlDecorator { } static void addAspectDocumentation(IProgramElement node, StringBuffer fileBuffer, int index) { - List pointcuts = new ArrayList(); - List advice = new ArrayList(); - List declares = new ArrayList(); - List methodsDeclaredOn = StructureUtil.getDeclareInterTypeTargets(node, IProgramElement.Kind.INTER_TYPE_METHOD); + List pointcuts = new ArrayList(); + List advice = new ArrayList(); + List declares = new ArrayList(); + List methodsDeclaredOn = StructureUtil.getDeclareInterTypeTargets(node, IProgramElement.Kind.INTER_TYPE_METHOD); if (methodsDeclaredOn != null && !methodsDeclaredOn.isEmpty()) { insertDeclarationsSummary(fileBuffer, methodsDeclaredOn, ITD_METHOD_SUMMARY, index); } - List fieldsDeclaredOn = StructureUtil.getDeclareInterTypeTargets(node, IProgramElement.Kind.INTER_TYPE_FIELD); + List fieldsDeclaredOn = StructureUtil.getDeclareInterTypeTargets(node, IProgramElement.Kind.INTER_TYPE_FIELD); if (fieldsDeclaredOn != null && !fieldsDeclaredOn.isEmpty()) { insertDeclarationsSummary(fileBuffer, fieldsDeclaredOn, ITD_FIELD_SUMMARY, index); } - List constDeclaredOn = StructureUtil.getDeclareInterTypeTargets(node, IProgramElement.Kind.INTER_TYPE_CONSTRUCTOR); + List constDeclaredOn = StructureUtil.getDeclareInterTypeTargets(node, IProgramElement.Kind.INTER_TYPE_CONSTRUCTOR); if (fieldsDeclaredOn != null && !constDeclaredOn.isEmpty()) { insertDeclarationsSummary(fileBuffer, constDeclaredOn, ITD_CONSTRUCTOR_SUMMARY, index); } - for (Iterator it = node.getChildren().iterator(); it.hasNext();) { + for (Iterator it = node.getChildren().iterator(); it.hasNext();) { IProgramElement member = (IProgramElement) it.next(); if (member.getKind().equals(IProgramElement.Kind.POINTCUT)) { pointcuts.add(member); @@ -329,17 +329,17 @@ class HtmlDecorator { insertDeclarationsDetails(fileBuffer, advice, ADVICE_DETAIL, index); } // add the 'aspect declarations' information against the type - List parentsDeclaredOn = StructureUtil.getDeclareInterTypeTargets(node, IProgramElement.Kind.DECLARE_PARENTS); + List parentsDeclaredOn = StructureUtil.getDeclareInterTypeTargets(node, IProgramElement.Kind.DECLARE_PARENTS); if (parentsDeclaredOn != null && parentsDeclaredOn.size() > 0) { decorateDocWithRel(node, fileBuffer, index, parentsDeclaredOn, HtmlRelationshipKind.ASPECT_DECLARATIONS); } // add the 'annotated by' information against the type - List annotatedBy = StructureUtil.getTargets(node, IRelationship.Kind.DECLARE_INTER_TYPE, "annotated by"); + List annotatedBy = StructureUtil.getTargets(node, IRelationship.Kind.DECLARE_INTER_TYPE, "annotated by"); if (annotatedBy != null && annotatedBy.size() > 0) { decorateDocWithRel(node, fileBuffer, index, annotatedBy, HtmlRelationshipKind.ANNOTATED_BY); } // add the 'advised by' information against the type - List advisedBy = StructureUtil.getTargets(node, IRelationship.Kind.ADVICE); + List advisedBy = StructureUtil.getTargets(node, IRelationship.Kind.ADVICE); if (advisedBy != null && advisedBy.size() > 0) { decorateDocWithRel(node, fileBuffer, index, advisedBy, HtmlRelationshipKind.ADVISED_BY); } @@ -621,16 +621,16 @@ class HtmlDecorator { } static void decorateMemberDocumentation(IProgramElement node, StringBuffer fileContentsBuffer, int index) { - List targets = StructureUtil.getTargets(node, IRelationship.Kind.ADVICE); + List targets = StructureUtil.getTargets(node, IRelationship.Kind.ADVICE); decorateDocWithRel(node, fileContentsBuffer, index, targets, HtmlRelationshipKind.ADVISED_BY); - List warnings = StructureUtil.getTargets(node, IRelationship.Kind.DECLARE, "matches declare"); + List warnings = StructureUtil.getTargets(node, IRelationship.Kind.DECLARE, "matches declare"); decorateDocWithRel(node, fileContentsBuffer, index, warnings, HtmlRelationshipKind.MATCHES_DECLARE); - List softenedBy = StructureUtil.getTargets(node, IRelationship.Kind.DECLARE, "softened by"); + List softenedBy = StructureUtil.getTargets(node, IRelationship.Kind.DECLARE, "softened by"); decorateDocWithRel(node, fileContentsBuffer, index, softenedBy, HtmlRelationshipKind.SOFTENED_BY); - List annotatedBy = StructureUtil.getTargets(node, IRelationship.Kind.DECLARE_INTER_TYPE, "annotated by"); + List annotatedBy = StructureUtil.getTargets(node, IRelationship.Kind.DECLARE_INTER_TYPE, "annotated by"); decorateDocWithRel(node, fileContentsBuffer, index, annotatedBy, HtmlRelationshipKind.ANNOTATED_BY); } diff --git a/ajdoc/src/org/aspectj/tools/ajdoc/JavadocRunner.java b/ajdoc/src/org/aspectj/tools/ajdoc/JavadocRunner.java index b0ab3cd21..37b727175 100644 --- a/ajdoc/src/org/aspectj/tools/ajdoc/JavadocRunner.java +++ b/ajdoc/src/org/aspectj/tools/ajdoc/JavadocRunner.java @@ -14,9 +14,12 @@ package org.aspectj.tools.ajdoc; +import java.io.IOException; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; +import org.aspectj.util.LangUtil; + /** * @author Mik Kersten */ @@ -62,7 +65,12 @@ class JavadocRunner { // defaultSecurityManager.checkPermission( permission, context ); // } // } ); - + + // Need to do something different on Java > 9 due to removal of standard doclet I think +// if (LangUtil.is19VMOrGreater()) { +// // Not visible according to module rules... +// clazz = Class.forName("jdk.javadoc.internal.tool.Main"); +// } try { // for JDK 1.4 and above call the execute method... Class jdMainClass = com.sun.tools.javadoc.Main.class; diff --git a/ajdoc/src/org/aspectj/tools/ajdoc/Main.java b/ajdoc/src/org/aspectj/tools/ajdoc/Main.java index 5c9047dcb..e8f1472b5 100644 --- a/ajdoc/src/org/aspectj/tools/ajdoc/Main.java +++ b/ajdoc/src/org/aspectj/tools/ajdoc/Main.java @@ -47,24 +47,24 @@ public class Main implements Config { private static final String FAIL_MESSAGE = "> compile failed, exiting ajdoc"; /** Command line options. */ - static Vector options; + static Vector options; /** Options to pass to ajc. */ - static Vector ajcOptions; + static Vector ajcOptions; /** All of the files to be processed by ajdoc. */ - static Vector filenames; + static Vector filenames; /** List of files to pass to javadoc. */ - static Vector fileList; + static Vector fileList; /** List of packages to pass to javadoc. */ - static Vector packageList; + static Vector packageList; /** Default to package visiblity. */ static String docModifier = "package"; - static Vector sourcepath; + static Vector sourcepath; static boolean verboseMode = false; static boolean packageMode = false; @@ -85,13 +85,13 @@ public class Main implements Config { private static String outputWorkingDir = Config.WORKING_DIR; public static void clearState() { - options = new Vector(); - ajcOptions = new Vector(); - filenames = new Vector(); - fileList = new Vector(); - packageList = new Vector(); + options = new Vector(); + ajcOptions = new Vector(); + filenames = new Vector(); + fileList = new Vector(); + packageList = new Vector(); docModifier = "package"; - sourcepath = new Vector(); + sourcepath = new Vector(); verboseMode = false; packageMode = false; rootDir = null; @@ -169,7 +169,7 @@ public class Main implements Config { * package-summary properly. */ private static void packageHTML(AsmManager model, File[] inputFiles) throws IOException { - ArrayList dirList = new ArrayList(); + ArrayList dirList = new ArrayList(); for (int i = 0; i < inputFiles.length; i++) { String packageName = StructureUtil.getPackageDeclarationFromFile(model, inputFiles[i]); // Only copy the package.html file once. @@ -192,7 +192,7 @@ public class Main implements Config { String pathName = outputWorkingDir + File.separator + packageName.replace('.', File.separatorChar); File packageDir = new File(pathName); if (!packageDir.exists()) { - dirList.add(packageDir); + dirList.add(packageName); continue; } packageName = packageName.replace('.', '/'); // !!! @@ -273,7 +273,6 @@ public class Main implements Config { javadocargs[options.size() + k] = StructureUtil.translateAjPathName(signatureFiles[k].getCanonicalPath()); } } - JavadocRunner.callJavadoc(javadocargs); } @@ -345,8 +344,8 @@ public class Main implements Config { } } - static Vector getSourcePath() { - Vector sourcePath = new Vector(); + static Vector getSourcePath() { + Vector sourcePath = new Vector(); boolean found = false; for (int i = 0; i < options.size(); i++) { String currOption = (String) options.elementAt(i); @@ -455,14 +454,14 @@ public class Main implements Config { String line = ""; line = br.readLine(); StringTokenizer st = new StringTokenizer(line, " "); - List argList = new ArrayList(); + List argList = new ArrayList(); while (st.hasMoreElements()) { - argList.add(st.nextElement()); + argList.add(st.nextToken()); } // System.err.println(argList); args = new String[argList.size()]; int counter = 0; - for (Iterator it = argList.iterator(); it.hasNext();) { + for (Iterator it = argList.iterator(); it.hasNext();) { args[counter] = (String) it.next(); counter++; } @@ -474,7 +473,7 @@ public class Main implements Config { ioe.printStackTrace(); } } - List vargs = new LinkedList(Arrays.asList(args)); + List vargs = new LinkedList(Arrays.asList(args)); vargs.add("-Xset:minimalModel=false"); parseArgs(vargs, new File(".")); // !!! @@ -488,7 +487,7 @@ public class Main implements Config { arg = arg + File.pathSeparator; // makes things easier for ourselves StringTokenizer tokenizer = new StringTokenizer(arg, File.pathSeparator); while (tokenizer.hasMoreElements()) { - sourcepath.addElement(tokenizer.nextElement()); + sourcepath.addElement(tokenizer.nextToken()); } } @@ -705,7 +704,7 @@ public class Main implements Config { } static void expandAtSignFile(String filename, File currentWorkingDir) { - List result = new LinkedList(); + List result = new LinkedList(); File atFile = qualifiedFile(filename, currentWorkingDir); String atFileParent = atFile.getParent(); @@ -730,6 +729,7 @@ public class Main implements Config { continue; result.add(line); } + stream.close(); } catch (IOException e) { System.err.println("Error while reading the @ file " + atFile.getPath() + ".\n" + e); System.exit(-1); diff --git a/ajdoc/src/org/aspectj/tools/ajdoc/StructureUtil.java b/ajdoc/src/org/aspectj/tools/ajdoc/StructureUtil.java index 6f9ad7790..3d866b625 100644 --- a/ajdoc/src/org/aspectj/tools/ajdoc/StructureUtil.java +++ b/ajdoc/src/org/aspectj/tools/ajdoc/StructureUtil.java @@ -31,7 +31,7 @@ public class StructureUtil { * * @return null if a relationship of that kind is not found */ - public static List /* String */getTargets(IProgramElement node, IRelationship.Kind kind) { + public static List getTargets(IProgramElement node, IRelationship.Kind kind) { return getTargets(node, kind, null); } @@ -41,21 +41,21 @@ public class StructureUtil { * * @return null if a relationship of that kind is not found */ - public static List /* String */getTargets(IProgramElement node, IRelationship.Kind kind, String relName) { - List relations = new ArrayList(); - List rels = node.getModel().getRelationshipMap().get(node); + public static List getTargets(IProgramElement node, IRelationship.Kind kind, String relName) { + List relations = new ArrayList(); + List rels = node.getModel().getRelationshipMap().get(node); if (rels != null) { relations.addAll(rels); } - for (Iterator iter = node.getChildren().iterator(); iter.hasNext();) { + for (Iterator iter = node.getChildren().iterator(); iter.hasNext();) { IProgramElement child = (IProgramElement) iter.next(); // if we're not a type, or if we are and the child is code, then // we want to get the relationships for this child - this means that the // correct relationships appear against the type in the ajdoc if (!node.getKind().isType() || child.getKind().equals(IProgramElement.Kind.CODE)) { - List childRelations = node.getModel().getRelationshipMap().get(child); + List childRelations = node.getModel().getRelationshipMap().get(child); if (childRelations != null) { - for (Iterator iterator = childRelations.iterator(); iterator.hasNext();) { + for (Iterator iterator = childRelations.iterator(); iterator.hasNext();) { IRelationship rel = (IRelationship) iterator.next(); if (!relations.contains(rel)) { relations.add(rel); @@ -66,13 +66,12 @@ public class StructureUtil { } if (relations == null || relations.isEmpty()) return null; - List targets = new ArrayList(); - for (Iterator it = relations.iterator(); it.hasNext();) { + List targets = new ArrayList(); + for (Iterator it = relations.iterator(); it.hasNext();) { IRelationship rtn = (IRelationship) it.next(); if (rtn.getKind().equals(kind) && ((relName != null && relName.equals(rtn.getName())) || relName == null)) { - List targs = rtn.getTargets(); - for (Iterator iter = targs.iterator(); iter.hasNext();) { - String element = (String) iter.next(); + List targs = rtn.getTargets(); + for (String element: targs) { if (!targets.contains(element)) { targets.add(element); } @@ -82,14 +81,13 @@ public class StructureUtil { return targets; } - static List /* IProgramElement */getDeclareInterTypeTargets(IProgramElement node, IProgramElement.Kind kind) { - List targets = new ArrayList(); - List stringTargets = StructureUtil.getTargets(node, IRelationship.Kind.DECLARE_INTER_TYPE); + static List getDeclareInterTypeTargets(IProgramElement node, IProgramElement.Kind kind) { + List targets = new ArrayList(); + List stringTargets = StructureUtil.getTargets(node, IRelationship.Kind.DECLARE_INTER_TYPE); if (stringTargets == null) { return null; } - for (Iterator iter = stringTargets.iterator(); iter.hasNext();) { - String element = (String) iter.next(); + for (String element: stringTargets) { IProgramElement ipe = node.getModel().getHierarchy().findElementForHandle(element); if (ipe != null && ipe.getKind().equals(kind)) { targets.add(ipe); @@ -98,13 +96,12 @@ public class StructureUtil { return targets; } - public static List/* String */getDeclareTargets(IProgramElement node) { - List relations = node.getModel().getRelationshipMap().get(node); - List targets = null; + public static List getDeclareTargets(IProgramElement node) { + List relations = node.getModel().getRelationshipMap().get(node); + List targets = null; if (relations == null) return null; - for (Iterator it = relations.iterator(); it.hasNext();) { - IRelationship rtn = (IRelationship) it.next(); + for (IRelationship rtn: relations) { if (rtn.getKind().isDeclareKind()) { targets = rtn.getTargets(); } diff --git a/ajdoc/testsrc/org/aspectj/tools/ajdoc/AjdocTestCase.java b/ajdoc/testsrc/org/aspectj/tools/ajdoc/AjdocTestCase.java index afe288a3b..ea9a81875 100644 --- a/ajdoc/testsrc/org/aspectj/tools/ajdoc/AjdocTestCase.java +++ b/ajdoc/testsrc/org/aspectj/tools/ajdoc/AjdocTestCase.java @@ -198,8 +198,10 @@ public class AjdocTestCase extends TestCase { !sourceLevel.equals("1.6") && !sourceLevel.equals("1.7") && !sourceLevel.equals("1.8") && - !sourceLevel.equals("1.9")) { - fail("need to pass ajdoc '1.3' > '1.9' as the source level"); + !sourceLevel.equals("1.9") && + !sourceLevel.startsWith("9") && + !sourceLevel.startsWith("10")) { + fail("need to pass suitable version to ajdoc as the source level"); } if (inputFiles.length == 0) { fail("need to pass some files into ajdoc"); diff --git a/ajdoc/testsrc/org/aspectj/tools/ajdoc/CoverageTestCase.java b/ajdoc/testsrc/org/aspectj/tools/ajdoc/CoverageTestCase.java index 70aa02b22..af9ab0ed9 100644 --- a/ajdoc/testsrc/org/aspectj/tools/ajdoc/CoverageTestCase.java +++ b/ajdoc/testsrc/org/aspectj/tools/ajdoc/CoverageTestCase.java @@ -55,7 +55,7 @@ public class CoverageTestCase extends AjdocTestCase { */ public void testCoveragePublicMode() throws Exception { File[] files = {file3,file9}; - runAjdoc("public","1.6",files); + runAjdoc("public","9",files); // have passed the "public" modifier as well as // one public and one package visible class. There diff --git a/org.aspectj.matcher/src/org/aspectj/weaver/World.java b/org.aspectj.matcher/src/org/aspectj/weaver/World.java index 8af6cc528..99f1e5e11 100644 --- a/org.aspectj.matcher/src/org/aspectj/weaver/World.java +++ b/org.aspectj.matcher/src/org/aspectj/weaver/World.java @@ -462,6 +462,9 @@ public abstract class World implements Dump.INode { } else if (ty.isGenericType()) { // ======= generic types ====================== ResolvedType rt = resolveGenericTypeFor(ty, false); + if (rt.isMissing()) { + return rt; + } ReferenceType genericType = (ReferenceType) rt; return genericType; diff --git a/testing/newsrc/org/aspectj/testing/AjcTest.java b/testing/newsrc/org/aspectj/testing/AjcTest.java index 29d3d1786..2cc450636 100644 --- a/testing/newsrc/org/aspectj/testing/AjcTest.java +++ b/testing/newsrc/org/aspectj/testing/AjcTest.java @@ -12,6 +12,7 @@ import java.util.ArrayList; import java.util.List; import org.aspectj.tools.ajc.AjcTestCase; +import org.aspectj.util.LangUtil; /** * @author Adrian Colyer @@ -28,32 +29,12 @@ public class AjcTest { private static boolean is19VMOrGreater = false; static { // matching logic is also in org.aspectj.util.LangUtil - String vm = System.getProperty("java.version"); // JLS 20.18.7 - if (vm==null) vm = System.getProperty("java.runtime.version"); - if (vm==null) vm = System.getProperty("java.vm.version"); - if (vm.startsWith("1.3")) { - is14VMOrGreater = false; - } else if (vm.startsWith("1.5")) { - is15VMOrGreater = true; - } else if (vm.startsWith("1.6")) { - is15VMOrGreater = true; - is16VMOrGreater = true; - } else if (vm.startsWith("1.7")) { - is15VMOrGreater = true; - is16VMOrGreater = true; - is17VMOrGreater = true; - } else if (vm.startsWith("1.8")) { - is15VMOrGreater = true; - is16VMOrGreater = true; - is17VMOrGreater = true; - is18VMOrGreater = true; - } else if (vm.startsWith("1.9") || vm.startsWith("9")) { - is15VMOrGreater = true; - is16VMOrGreater = true; - is17VMOrGreater = true; - is18VMOrGreater = true; - is19VMOrGreater = true; - } + is14VMOrGreater = LangUtil.is14VMOrGreater(); + is15VMOrGreater = LangUtil.is15VMOrGreater(); + is16VMOrGreater = LangUtil.is16VMOrGreater(); + is17VMOrGreater = LangUtil.is17VMOrGreater(); + is18VMOrGreater = LangUtil.is18VMOrGreater(); + is19VMOrGreater = LangUtil.is19VMOrGreater(); } private List testSteps = new ArrayList(); diff --git a/testing/newsrc/org/aspectj/testing/OutputSpec.java b/testing/newsrc/org/aspectj/testing/OutputSpec.java index 4f978f6b6..9eab46098 100644 --- a/testing/newsrc/org/aspectj/testing/OutputSpec.java +++ b/testing/newsrc/org/aspectj/testing/OutputSpec.java @@ -23,11 +23,31 @@ public class OutputSpec { private List expectedOutputLines = new ArrayList(); public void addLine(OutputLine line) { - if (line.getVm() == null || line.getVm().contains(LangUtil.getVmVersionString())) { + if (line.getVm() == null || matchesThisVm(line.getVm())) { expectedOutputLines.add(line.getText()); } } + /** + * For a test output line that has specified a vm version, check if it matches the vm we are running on. + * vm might be "1.2,1.3,1.4,1.5" or simply "9" or it may be a version with a '+' suffix indicating that + * level or later, e.g. "9+" should be ok on Java 10 + * @return true if the current vm version matches the spec + */ + private boolean matchesThisVm(String vm) { + // vm might be 1.2, 1.3, 1.4, 1.5 or 1.9 possibly with a '+' in there + // For now assume + is attached to there only being one version, like "9+" + if (vm.contains(LangUtil.getVmVersionString())) { + return true; + } + if (vm.endsWith("+")) { + double vmVersion = LangUtil.getVmVersion(); + double vmSpecified = Double.parseDouble(vm.substring(0,vm.length()-1)); + return vmVersion >= vmSpecified; + } + return false; + } + public void matchAgainst(String output) { matchAgainst(output, "yes"); } diff --git a/tests/src/org/aspectj/systemtest/ajc150/ajc150.xml b/tests/src/org/aspectj/systemtest/ajc150/ajc150.xml index cf75f7426..d0da94ec9 100644 --- a/tests/src/org/aspectj/systemtest/ajc150/ajc150.xml +++ b/tests/src/org/aspectj/systemtest/ajc150/ajc150.xml @@ -2809,7 +2809,7 @@ - + @@ -3813,46 +3813,46 @@ - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + diff --git a/tests/src/org/aspectj/systemtest/ajc154/ajc154.xml b/tests/src/org/aspectj/systemtest/ajc154/ajc154.xml index a3297e68c..9cb0eae87 100644 --- a/tests/src/org/aspectj/systemtest/ajc154/ajc154.xml +++ b/tests/src/org/aspectj/systemtest/ajc154/ajc154.xml @@ -28,7 +28,7 @@ - + @@ -41,7 +41,7 @@ - + @@ -54,7 +54,7 @@ - + @@ -67,7 +67,7 @@ - + @@ -81,7 +81,7 @@ - + @@ -96,7 +96,7 @@ - + diff --git a/tests/src/org/aspectj/systemtest/ajc1611/newfeatures-tests.xml b/tests/src/org/aspectj/systemtest/ajc1611/newfeatures-tests.xml index 0a8105df7..914042633 100644 --- a/tests/src/org/aspectj/systemtest/ajc1611/newfeatures-tests.xml +++ b/tests/src/org/aspectj/systemtest/ajc1611/newfeatures-tests.xml @@ -110,7 +110,7 @@ - + diff --git a/tests/src/org/aspectj/systemtest/ajc1612/ajc1612.xml b/tests/src/org/aspectj/systemtest/ajc1612/ajc1612.xml index 8011cd68f..38f46c7d6 100644 --- a/tests/src/org/aspectj/systemtest/ajc1612/ajc1612.xml +++ b/tests/src/org/aspectj/systemtest/ajc1612/ajc1612.xml @@ -258,9 +258,9 @@ - + - + diff --git a/tests/src/org/aspectj/systemtest/ajc169/intertype.xml b/tests/src/org/aspectj/systemtest/ajc169/intertype.xml index f9c788b0c..75846b05c 100644 --- a/tests/src/org/aspectj/systemtest/ajc169/intertype.xml +++ b/tests/src/org/aspectj/systemtest/ajc169/intertype.xml @@ -71,7 +71,7 @@ - + @@ -82,7 +82,7 @@ - + @@ -93,7 +93,7 @@ - + @@ -104,7 +104,7 @@ - + @@ -115,7 +115,7 @@ - + @@ -126,7 +126,7 @@ - + @@ -137,7 +137,7 @@ - + diff --git a/tests/src/org/aspectj/systemtest/ajc170/ajc170.xml b/tests/src/org/aspectj/systemtest/ajc170/ajc170.xml index 241ad3867..e379d6cab 100644 --- a/tests/src/org/aspectj/systemtest/ajc170/ajc170.xml +++ b/tests/src/org/aspectj/systemtest/ajc170/ajc170.xml @@ -183,14 +183,14 @@ - + - + - + @@ -202,10 +202,10 @@ - + - + @@ -222,7 +222,7 @@ - + @@ -234,7 +234,7 @@ - + diff --git a/tests/src/org/aspectj/systemtest/ajc173/ajc173.xml b/tests/src/org/aspectj/systemtest/ajc173/ajc173.xml index 4a784fff8..398fae62f 100644 --- a/tests/src/org/aspectj/systemtest/ajc173/ajc173.xml +++ b/tests/src/org/aspectj/systemtest/ajc173/ajc173.xml @@ -10,7 +10,7 @@ - + diff --git a/tests/src/org/aspectj/systemtest/ajc190/Ajc190Tests.java b/tests/src/org/aspectj/systemtest/ajc190/Ajc190Tests.java index 26d0905e8..607f723fc 100644 --- a/tests/src/org/aspectj/systemtest/ajc190/Ajc190Tests.java +++ b/tests/src/org/aspectj/systemtest/ajc190/Ajc190Tests.java @@ -21,10 +21,6 @@ import junit.framework.Test; */ public class Ajc190Tests extends org.aspectj.testing.XMLBasedAjcTestCase { - public void testVarious_SettingFinalStatic() { - runTest("setting static final outside clinit"); - } - public void testAnnotMethodHasMember_pr156962_1() { // From similar in Ajc153Tests runTest("Test Annot Method Has Member 1"); } diff --git a/tests/src/org/aspectj/systemtest/ajc190/ajc190_from150.xml b/tests/src/org/aspectj/systemtest/ajc190/ajc190_from150.xml index 41a75c0ae..24d683928 100644 --- a/tests/src/org/aspectj/systemtest/ajc190/ajc190_from150.xml +++ b/tests/src/org/aspectj/systemtest/ajc190/ajc190_from150.xml @@ -2809,7 +2809,7 @@ - + diff --git a/util/src/org/aspectj/util/LangUtil.java b/util/src/org/aspectj/util/LangUtil.java index 08c2da43a..ff6c7246c 100644 --- a/util/src/org/aspectj/util/LangUtil.java +++ b/util/src/org/aspectj/util/LangUtil.java @@ -49,6 +49,10 @@ public class LangUtil { return Double.toString(vmVersion); } + public static double getVmVersion() { + return vmVersion; + } + static { StringWriter buf = new StringWriter(); PrintWriter writer = new PrintWriter(buf); @@ -66,6 +70,8 @@ public class LangUtil { } static { + // http://www.oracle.com/technetwork/java/javase/versioning-naming-139433.html + // http://openjdk.java.net/jeps/223 "New Version-String Scheme" try { String vm = System.getProperty("java.version"); // JLS 20.18.7 if (vm == null) { @@ -80,17 +86,21 @@ public class LangUtil { .printStackTrace(System.err); vmVersion = 1.5; } else { - if (vm.startsWith("9")) { - // JDK 9 beta 99 starts using 9-ea as the version string. - vmVersion = 1.9; - } else { - try { - String versionString = vm.substring(0, 3); - Double temp = new Double(Double.parseDouble(versionString)); - vmVersion = temp.doubleValue(); - } catch (Exception e) { - vmVersion = 1.4; + // Version: [1-9][0-9]*((\.0)*\.[1-9][0-9]*)* + // Care about the first set of digits and second set if first digit is 1 + try { + List numbers = getFirstNumbers(vm); + if (numbers.get(0) == 1) { + // Old school for 1.0 > 1.8 + vmVersion = numbers.get(0)+(numbers.get(1)/10d); + } else { + // numbers.get(0) is the major version (9 and above) + // Note here the number will be 9 (or 10), *not* 1.9 or 1.10 + vmVersion = numbers.get(0); } + } catch (Throwable t) { + // Give up + vmVersion = 1.5; } } } catch (Throwable t) { @@ -100,6 +110,19 @@ public class LangUtil { vmVersion = 1.5; } } + + private static List getFirstNumbers(String vm) { + List result = new ArrayList(); + StringTokenizer st = new StringTokenizer(vm,".-_"); + try { + result.add(Integer.parseInt(st.nextToken())); + result.add(Integer.parseInt(st.nextToken())); + } catch (Exception e) { + // NoSuchElementException if no more tokens + // NumberFormatException if not a number + } + return result; + } public static boolean is13VMOrGreater() { return 1.3 <= vmVersion; @@ -126,7 +149,7 @@ public class LangUtil { } public static boolean is19VMOrGreater() { - return 1.9 <= vmVersion; + return 9 <= vmVersion; } /** diff --git a/weaver/testdata/StaticTjpBeforeHelloWorld.1.9.txt b/weaver/testdata/StaticTjpBeforeHelloWorld.9.0.txt similarity index 100% rename from weaver/testdata/StaticTjpBeforeHelloWorld.1.9.txt rename to weaver/testdata/StaticTjpBeforeHelloWorld.9.0.txt diff --git a/weaver/testdata/TjpAround2HelloWorld.1.9.txt b/weaver/testdata/TjpAround2HelloWorld.9.0.txt similarity index 100% rename from weaver/testdata/TjpAround2HelloWorld.1.9.txt rename to weaver/testdata/TjpAround2HelloWorld.9.0.txt diff --git a/weaver/testdata/TjpAroundHelloWorld.1.9.txt b/weaver/testdata/TjpAroundHelloWorld.9.0.txt similarity index 100% rename from weaver/testdata/TjpAroundHelloWorld.1.9.txt rename to weaver/testdata/TjpAroundHelloWorld.9.0.txt diff --git a/weaver/testdata/TjpBeforeHelloWorld.1.9.txt b/weaver/testdata/TjpBeforeHelloWorld.9.0.txt similarity index 100% rename from weaver/testdata/TjpBeforeHelloWorld.1.9.txt rename to weaver/testdata/TjpBeforeHelloWorld.9.0.txt -- 2.39.5