From 83ffefe020117ea3255a657f0eab404acbbb867a Mon Sep 17 00:00:00 2001 From: Eugene Zhuravlev Date: Mon, 29 Jul 2019 19:59:51 +0200 Subject: [PATCH] correct fix for resource bundle search in tests GitOrigin-RevId: 9f9174a419bce38e5d54628bf85cd63691cd7359 --- .../InstrumentationClassFinder.java | 10 +------- .../testData/TestMnemonicsProperty.form | 2 +- .../ui-designer/testData/TestTabbedPane.form | 2 +- .../formEmbedding/Ideadev14081/Main.form | 2 +- .../uiDesigner/core/AsmCodeGeneratorTest.java | 25 ++++++------------- .../uiDesigner/core/TestProperties.java | 15 +++++++++++ 6 files changed, 26 insertions(+), 30 deletions(-) create mode 100644 plugins/ui-designer/testSrc/com/intellij/uiDesigner/core/TestProperties.java 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 85bbaebec7ab..8651c35028fc 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,17 +85,13 @@ 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 } try { final byte[] bytes = loadBytes(is); - return defineClass(name, bytes, 0, bytes.length); + return defineClass(name.replace('/', '.'), bytes, 0, bytes.length); } finally { try { @@ -110,10 +106,6 @@ 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/testData/TestMnemonicsProperty.form b/plugins/ui-designer/testData/TestMnemonicsProperty.form index 674ba2a630bf..be9c6d8e3578 100644 --- a/plugins/ui-designer/testData/TestMnemonicsProperty.form +++ b/plugins/ui-designer/testData/TestMnemonicsProperty.form @@ -15,7 +15,7 @@ - + diff --git a/plugins/ui-designer/testData/TestTabbedPane.form b/plugins/ui-designer/testData/TestTabbedPane.form index fdc151a3f5bb..bc46b7404360 100644 --- a/plugins/ui-designer/testData/TestTabbedPane.form +++ b/plugins/ui-designer/testData/TestTabbedPane.form @@ -20,7 +20,7 @@ - + diff --git a/plugins/ui-designer/testData/formEmbedding/Ideadev14081/Main.form b/plugins/ui-designer/testData/formEmbedding/Ideadev14081/Main.form index 932b2e563846..8ef77276a151 100644 --- a/plugins/ui-designer/testData/formEmbedding/Ideadev14081/Main.form +++ b/plugins/ui-designer/testData/formEmbedding/Ideadev14081/Main.form @@ -13,7 +13,7 @@ - + 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 9f126aa0137c..4a44997c5ae4 100644 --- a/plugins/ui-designer/testSrc/com/intellij/uiDesigner/core/AsmCodeGeneratorTest.java +++ b/plugins/ui-designer/testSrc/com/intellij/uiDesigner/core/AsmCodeGeneratorTest.java @@ -448,16 +448,10 @@ public class AsmCodeGeneratorTest extends JpsBuildTestCase { 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(); + private final byte[] myTestPropertiesBytes = Charset.defaultCharset().encode(TestProperties.TEST_PROPERTY_CONTENT).array(); + private final String myTestPropertiesClassInternalName = TestProperties.class.getName().replace('.', '/'); + private final String myTestPropertiesFileInternalName = myTestPropertiesClassInternalName + ".properties"; private final Map myClassData = new HashMap<>(); private MyClassFinder(URL[] platformUrls, URL[] classpathUrls) { @@ -474,21 +468,16 @@ public class AsmCodeGeneratorTest extends JpsBuildTestCase { if (bytes != null) { return new ByteArrayInputStream(bytes); } - return null; - } - - @Override - protected Class findClass(String name) { - if ("TestProperties".equals(name)) { - return MyTestProperties.class; + if (myTestPropertiesClassInternalName.equals(internalClassName)) { + return TestProperties.class.getClassLoader().getResourceAsStream(myTestPropertiesClassInternalName + ".class"); } return null; } @Override public InputStream getResourceAsStream(String name) throws IOException { - if (name.equals("TestProperties.properties")) { - return new ByteArrayInputStream(myTestProperties, 0, TEST_PROPERTY_CONTENT.length()); + if (myTestPropertiesFileInternalName.equals(name)) { + return new ByteArrayInputStream(myTestPropertiesBytes, 0, TestProperties.TEST_PROPERTY_CONTENT.length()); } return super.getResourceAsStream(name); } diff --git a/plugins/ui-designer/testSrc/com/intellij/uiDesigner/core/TestProperties.java b/plugins/ui-designer/testSrc/com/intellij/uiDesigner/core/TestProperties.java new file mode 100644 index 000000000000..106f4bf9a6b1 --- /dev/null +++ b/plugins/ui-designer/testSrc/com/intellij/uiDesigner/core/TestProperties.java @@ -0,0 +1,15 @@ +// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +package com.intellij.uiDesigner.core;// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. + +import java.io.IOException; +import java.io.StringReader; +import java.util.PropertyResourceBundle; + +// For JDK 11 `com.intellij.uiDesigner.core.TestProperties` bundle try load over class +public class TestProperties extends PropertyResourceBundle { + public static final String TEST_PROPERTY_CONTENT = "test=Test Value\nmnemonic=Mne&monic"; + + public TestProperties() throws IOException { + super(new StringReader(TEST_PROPERTY_CONTENT)); + } +}