From 77f5f5f94ace6e4162446d7665b3afa470db695c Mon Sep 17 00:00:00 2001 From: Alexander Lobas Date: Mon, 3 Jun 2019 22:18:51 +0300 Subject: [PATCH] Fix tests for jdk 11 GitOrigin-RevId: 4fe5d82f3562312c199aa24cefc4dc14e8305653 --- .../InstrumentationClassFinder.java | 8 ++++ .../uiDesigner/core/AsmCodeGeneratorTest.java | 37 +++++++++++++++---- 2 files changed, 38 insertions(+), 7 deletions(-) diff --git a/java/compiler/instrumentation-util/src/com/intellij/compiler/instrumentation/InstrumentationClassFinder.java b/java/compiler/instrumentation-util/src/com/intellij/compiler/instrumentation/InstrumentationClassFinder.java index a97a2da47e16..85bbaebec7ab 100644 --- a/java/compiler/instrumentation-util/src/com/intellij/compiler/instrumentation/InstrumentationClassFinder.java +++ b/java/compiler/instrumentation-util/src/com/intellij/compiler/instrumentation/InstrumentationClassFinder.java @@ -85,6 +85,10 @@ public class InstrumentationClassFinder { @Override protected Class findClass(String name) throws ClassNotFoundException { + Class aClass = InstrumentationClassFinder.this.findClass(name); + if (aClass != null) { + return aClass; + } final InputStream is = lookupClassBeforeClasspath(name.replace('.', '/')); if (is == null) { throw new ClassNotFoundException("Class not found: " + name.replace('/', '.')); // ensure presentable class name in error message @@ -106,6 +110,10 @@ public class InstrumentationClassFinder { return loader; } + protected Class findClass(String name) { + return null; + } + public void releaseResources() { myPlatformClasspath.releaseResources(); myClasspath.releaseResources(); diff --git a/plugins/ui-designer/testSrc/com/intellij/uiDesigner/core/AsmCodeGeneratorTest.java b/plugins/ui-designer/testSrc/com/intellij/uiDesigner/core/AsmCodeGeneratorTest.java index 4bd659ec7653..ebb9b4086ac9 100644 --- a/plugins/ui-designer/testSrc/com/intellij/uiDesigner/core/AsmCodeGeneratorTest.java +++ b/plugins/ui-designer/testSrc/com/intellij/uiDesigner/core/AsmCodeGeneratorTest.java @@ -25,8 +25,11 @@ import com.intellij.util.ui.UIUtil; import com.intellij.util.ui.UIUtilities; import com.sun.tools.javac.Main; import gnu.trove.TIntObjectHashMap; -import junit.framework.TestCase; import kotlin.reflect.KDeclarationContainer; +import org.jetbrains.jps.builders.JpsBuildTestCase; +import org.jetbrains.jps.model.JpsDummyElement; +import org.jetbrains.jps.model.java.JpsJavaSdkType; +import org.jetbrains.jps.model.library.sdk.JpsSdk; import org.jetbrains.org.objectweb.asm.ClassWriter; import javax.swing.*; @@ -48,7 +51,7 @@ import static org.assertj.core.api.Assertions.assertThat; /** * @author yole */ -public class AsmCodeGeneratorTest extends TestCase { +public class AsmCodeGeneratorTest extends JpsBuildTestCase { private MyNestedFormLoader myNestedFormLoader; private MyClassFinder myClassFinder; @@ -57,7 +60,15 @@ public class AsmCodeGeneratorTest extends TestCase { super.setUp(); myNestedFormLoader = new MyNestedFormLoader(); - final String swingPath = PathUtil.getJarPathForClass(AbstractButton.class); + URL url; + JpsSdk jdk = getJdk(); + if (JpsJavaSdkType.getJavaVersion(jdk) >= 9) { + url = InstrumentationClassFinder.createJDKPlatformUrl(jdk.getHomePath()); + } + else { + String swingPath = PathUtil.getJarPathForClass(AbstractButton.class); + url = new File(swingPath).toURI().toURL(); + } List cp = new ArrayList<>(); appendPath(cp, JBTabbedPane.class); @@ -74,10 +85,7 @@ public class AsmCodeGeneratorTest extends TestCase { appendPath(cp, KDeclarationContainer.class); appendPath(cp, NotNullProducer.class); appendPath(cp, SimpleTextAttributes.class); - myClassFinder = new MyClassFinder( - new URL[] {new File(swingPath).toURI().toURL()}, - cp.toArray(new URL[0]) - ); + myClassFinder = new MyClassFinder(new URL[]{url}, cp.toArray(new URL[0])); } private static void appendPath(Collection container, Class cls) throws MalformedURLException { @@ -442,6 +450,13 @@ public class AsmCodeGeneratorTest extends TestCase { assert instance != null : mainClass; } + // For JDK 11 `TestProperties` bundle try load over class + public static class MyTestProperties extends PropertyResourceBundle { + public MyTestProperties() throws IOException { + super(new StringReader(MyClassFinder.TEST_PROPERTY_CONTENT)); + } + } + private static class MyClassFinder extends InstrumentationClassFinder { private static final String TEST_PROPERTY_CONTENT = "test=Test Value\nmnemonic=Mne&monic"; private final byte[] myTestProperties = Charset.defaultCharset().encode(TEST_PROPERTY_CONTENT).array(); @@ -464,6 +479,14 @@ public class AsmCodeGeneratorTest extends TestCase { return null; } + @Override + protected Class findClass(String name) { + if ("TestProperties".equals(name)) { + return MyTestProperties.class; + } + return null; + } + @Override public InputStream getResourceAsStream(String name) throws IOException { if (name.equals("TestProperties.properties")) {