Temporary copy beans with reflection while there's no library method in TeamCity JPS
Original commit: e70098a2d4
This commit is contained in:
@@ -31,8 +31,10 @@ import org.jetbrains.kotlin.cli.common.arguments.K2JVMCompilerArguments;
|
||||
import org.jetbrains.kotlin.cli.common.messages.MessageCollector;
|
||||
import org.jetbrains.kotlin.cli.common.messages.MessageCollectorUtil;
|
||||
import org.jetbrains.kotlin.config.CompilerSettings;
|
||||
import org.jetbrains.kotlin.utils.UtilsPackage;
|
||||
|
||||
import java.io.*;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
@@ -143,13 +145,32 @@ public class KotlinCompilerRunner {
|
||||
private static <F, T extends F> T mergeBeans(F from, T to) {
|
||||
T copy = XmlSerializerUtil.createCopy(to);
|
||||
|
||||
// TODO: Rewrite with XmlSerializerUtil.copyBean() after method is in Teamcity JPS (9.1 expected)
|
||||
for (Accessor accessor : XmlSerializerUtil.getAccessors(from.getClass())) {
|
||||
accessor.set(copy, accessor.read(from));
|
||||
if (!setValue("set", false, accessor, copy, accessor.read(from))) {
|
||||
setValue("write", true, accessor, copy, accessor.read(from));
|
||||
}
|
||||
}
|
||||
|
||||
return copy;
|
||||
}
|
||||
|
||||
private static boolean setValue(String methodName, boolean failOnReflection, Accessor accessor, Object from, Object copy) {
|
||||
try {
|
||||
Method method = Accessor.class.getMethod(methodName, Object.class, Object.class);
|
||||
method.invoke(accessor, from, copy);
|
||||
|
||||
return true;
|
||||
}
|
||||
catch (Throwable e) {
|
||||
if (failOnReflection) {
|
||||
throw UtilsPackage.rethrow(e);
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private static void setupK2JvmArguments(File moduleFile, K2JVMCompilerArguments settings) {
|
||||
settings.module = moduleFile.getAbsolutePath();
|
||||
settings.noStdlib = true;
|
||||
|
||||
Reference in New Issue
Block a user