Browse Source

Merge pull request #677 in DESIGN/design from ~PLOUGH/10-design:release/10.0 to release/10.0

* commit '40f367e1d2b3fff16568dd4cdaa18dffb7edc9a8':
  REPORT-13402 【阻塞】【10.0.2回归】公式面板点不开=>调整代码
  REPORT-13402 【阻塞】【10.0.2回归】公式面板点不开=>调整代码
  REPORT-13402 【阻塞】【10.0.2回归】公式面板点不开
bugfix/10.0
plough 6 years ago
parent
commit
f9d541e63f
  1. 26
      designer-base/src/main/java/com/fr/design/formula/FunctionConstants.java
  2. 36
      designer-base/src/test/java/com/fr/design/formula/FunctionConstantsTest.java

26
designer-base/src/main/java/com/fr/design/formula/FunctionConstants.java

@ -13,6 +13,7 @@ import com.fr.function.SUM;
import com.fr.function.TIME;
import com.fr.general.ComparatorUtils;
import com.fr.general.GeneralUtils;
import com.fr.log.FineLoggerFactory;
import com.fr.plugin.ExtraClassManager;
import com.fr.stable.EncodeConstants;
@ -66,7 +67,6 @@ public final class FunctionConstants {
while (urlEnumeration.hasMoreElements()) {
URL url = urlEnumeration.nextElement();
String classFilePath = url.getFile();
/*
* alex:url.getFile获取的地址中,如果有空格或中文会被URLEncoder.encode处理
* 会变成%20这种%打头的东西,但是new File的时候%20是无法解析成空格,所以在此需要做URLDecoder.decode处理
@ -77,10 +77,9 @@ public final class FunctionConstants {
FRContext.getLogger().error(e1.getMessage(), e1);
}
FRContext.getLogger().info("ClassFilePath:" + classFilePath);
/*
* alex:如果是jar包中的class文件
* file:/D:/opt/FineReport6.5/WebReport/WEB-INF/lib/fr-server-6.5.jar!/com/fr/rpt/script/function
*/
if (isCustomFormulaPath(classFilePath)) {
continue;
}
for (String fileName : findClassNamesUnderFilePath(classFilePath)) {
try {
Class<?> cls = Class.forName(pkgName + "." + fileName.substring(0, fileName.length() - 6));
@ -94,9 +93,24 @@ public final class FunctionConstants {
}
}
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException ignore) {
} catch (Throwable e) {
// 不要因为个别公式加载失败,而导致整个函数面板无法启动
FineLoggerFactory.getLogger().error(e.getMessage());
}
}
}
}
private static boolean isCustomFormulaPath(String classFilePath) {
return !isJarPath(classFilePath) && isNotDebugMode();
}
private static boolean isNotDebugMode() {
return GeneralUtils.readBuildNO().contains("-");
}
private static boolean isJarPath(String classFilePath) {
return classFilePath.contains("!/");
}
/**
@ -145,7 +159,7 @@ public final class FunctionConstants {
* alex:如果是jar包中的class文件
* file:/D:/opt/FineReport6.5/WebReport/WEB-INF/lib/fr-server-6.5.jar!/com/fr/rpt/script/function
*/
if (filePath.contains("!/")) {
if (isJarPath(filePath)) {
String[] arr = filePath.split("!/");
String jarPath = arr[0].substring(6); // alex:substring(6)去掉前面的file:/这六个字符
String classPath = arr[1];

36
designer-base/src/test/java/com/fr/design/formula/FunctionConstantsTest.java

@ -1,14 +1,24 @@
package com.fr.design.formula;
import com.fr.general.GeneralUtils;
import com.fr.invoke.Reflect;
import org.easymock.EasyMock;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.api.easymock.PowerMock;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import static junit.framework.Assert.fail;
import static junit.framework.TestCase.assertEquals;
import static junit.framework.TestCase.assertTrue;
import static org.junit.Assert.assertFalse;
/**
* Created by plough on 2018/12/7.
*/
@RunWith(PowerMockRunner.class)
@PrepareForTest(GeneralUtils.class)
public class FunctionConstantsTest {
@Test
public void testNewInstanceFail() throws Exception {
@ -37,4 +47,30 @@ public class FunctionConstantsTest {
NameAndFunctionList commonFunctionList = FunctionConstants.COMMON;
assertEquals(9, commonFunctionList.getDescriptions().length);
}
@Test
public void testIsCustomFormulaPathRunWithCode() {
PowerMock.mockStatic(GeneralUtils.class);
EasyMock.expect(GeneralUtils.readBuildNO()).andReturn("不是安装版本").anyTimes();
PowerMock.replayAll();
String classFilePath = "/Users/plough/.m2/repository/com/fr/core/fine-core/10.0-RELEASE-SNAPSHOT/fine-core-10.0-RELEASE-20181211.024527-499.jar!/com/fr/function";
assertFalse(Reflect.on(FunctionConstants.class).call("isCustomFormulaPath", classFilePath).<Boolean>get());
classFilePath = "/Users/plough/work/new_10_release_finereport/engine-settings/env/webroot/WEB-INF/classes/com/fr/function";
assertFalse(Reflect.on(FunctionConstants.class).call("isCustomFormulaPath", classFilePath).<Boolean>get());
}
@Test
public void testIsCustomFormulaPathRunWithJar() {
PowerMock.mockStatic(GeneralUtils.class);
EasyMock.expect(GeneralUtils.readBuildNO()).andReturn("Build#release-2018.12.10.12.11.09.95").anyTimes();
PowerMock.replayAll();
String classFilePath = "file:/Applications/FineReport_10.0_12_10/webapps/webroot/WEB-INF/lib/fine-report-engine-10.0.jar!/com/fr/function";
assertFalse(Reflect.on(FunctionConstants.class).call("isCustomFormulaPath", classFilePath).<Boolean>get());
classFilePath = "/Applications/FineReport_10.0_12_10/webapps/webroot/WEB-INF/classes/com/fr/function";
assertTrue(Reflect.on(FunctionConstants.class).call("isCustomFormulaPath", classFilePath).<Boolean>get());
}
}

Loading…
Cancel
Save