correct fix for resource bundle search in tests

GitOrigin-RevId: 9f9174a419bce38e5d54628bf85cd63691cd7359
This commit is contained in:
Eugene Zhuravlev
2019-07-29 19:59:51 +02:00
committed by intellij-monorepo-bot
parent 124c3ffe0c
commit 83ffefe020
6 changed files with 26 additions and 30 deletions

View File

@@ -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();

View File

@@ -15,7 +15,7 @@
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0"/>
</constraints>
<properties>
<text resource-bundle="TestProperties" key="mnemonic"/>
<text resource-bundle="com/intellij/uiDesigner/core/TestProperties" key="mnemonic"/>
</properties>
</component>
</children>

View File

@@ -20,7 +20,7 @@
</component>
<component id="980c7" class="javax.swing.JButton">
<constraints>
<tabbedpane title-resource-bundle="TestProperties" title-key="test"/>
<tabbedpane title-resource-bundle="com/intellij/uiDesigner/core/TestProperties" title-key="test"/>
</constraints>
<properties>
<enabled value="true"/>

View File

@@ -13,7 +13,7 @@
<component id="f484d" class="javax.swing.JButton" default-binding="true">
<constraints border-constraint="North"/>
<properties>
<text resource-bundle="TestProperties" key="test"/>
<text resource-bundle="com/intellij/uiDesigner/core/TestProperties" key="test"/>
</properties>
</component>
</children>

View File

@@ -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<String, byte[]> 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);
}

View File

@@ -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));
}
}