Add ability to configure jdk with two backup properties
This commit is contained in:
+32
-19
@@ -35,8 +35,9 @@ import java.util.regex.Pattern;
|
|||||||
|
|
||||||
import static org.jetbrains.kotlin.test.InTextDirectivesUtils.isCompatibleTarget;
|
import static org.jetbrains.kotlin.test.InTextDirectivesUtils.isCompatibleTarget;
|
||||||
|
|
||||||
|
@SuppressWarnings({"WeakerAccess", "unused"})
|
||||||
public class KtTestUtil {
|
public class KtTestUtil {
|
||||||
private static String homeDir = computeHomeDirectory();
|
private static final String homeDir = computeHomeDirectory();
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static File tmpDirForTest(@NotNull String testClassName, @NotNull String testName) throws IOException {
|
public static File tmpDirForTest(@NotNull String testClassName, @NotNull String testName) throws IOException {
|
||||||
@@ -61,7 +62,7 @@ public class KtTestUtil {
|
|||||||
private static File normalizeFile(File file) throws IOException {
|
private static File normalizeFile(File file) throws IOException {
|
||||||
// Get canonical file to be sure that it's the same as inside the compiler,
|
// Get canonical file to be sure that it's the same as inside the compiler,
|
||||||
// for example, on Windows, if a canonical path contains any space from FileUtil.createTempDirectory we will get
|
// for example, on Windows, if a canonical path contains any space from FileUtil.createTempDirectory we will get
|
||||||
// a File with short names (8.3) in its path and it will break some normalization passes in tests.
|
// a File with short names (8.3) in its path, and it will break some normalization passes in tests.
|
||||||
return file.getCanonicalFile();
|
return file.getCanonicalFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -88,7 +89,7 @@ public class KtTestUtil {
|
|||||||
}
|
}
|
||||||
catch (FileNotFoundException fileNotFoundException) {
|
catch (FileNotFoundException fileNotFoundException) {
|
||||||
/*
|
/*
|
||||||
* Unfortunately, the FileNotFoundException will only show the relative path in it's exception message.
|
* Unfortunately, the FileNotFoundException will only show the relative path in its exception message.
|
||||||
* This clarifies the exception by showing the full path.
|
* This clarifies the exception by showing the full path.
|
||||||
*/
|
*/
|
||||||
String messageWithFullPath = file.getAbsolutePath() + " (No such file or directory)";
|
String messageWithFullPath = file.getAbsolutePath() + " (No such file or directory)";
|
||||||
@@ -105,29 +106,41 @@ public class KtTestUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private static File getJdkHome(@NotNull String prop) {
|
private static File getJdkHome(@NotNull String mainProperty) {
|
||||||
return getJdkHome(prop, null, prop);
|
return getJdkHome(mainProperty, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private static File getJdkHome(@NotNull String prop, @Nullable String otherProp) {
|
private static File getJdkHome(@NotNull String mainProperty, @Nullable String propertyVariant) {
|
||||||
return getJdkHome(prop, otherProp, prop);
|
return getJdkHome(mainProperty, propertyVariant, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private static File getJdkHome(@NotNull String prop, @Nullable String otherProp, @NotNull String propToReport) {
|
private static File getJdkHome(
|
||||||
String jdk = System.getProperty(prop);
|
@NotNull String mainProperty,
|
||||||
if (jdk == null) {
|
@Nullable String propertyVariant1,
|
||||||
jdk = System.getenv(prop);
|
@Nullable String propertyVariant2
|
||||||
|
) {
|
||||||
|
String jdkPath = getStringProperty(mainProperty);
|
||||||
|
if (jdkPath == null && propertyVariant1 != null) {
|
||||||
|
jdkPath = getStringProperty(propertyVariant1);
|
||||||
}
|
}
|
||||||
if (jdk == null) {
|
if (jdkPath == null && propertyVariant2 != null) {
|
||||||
if (otherProp != null) {
|
jdkPath = getStringProperty(propertyVariant2);
|
||||||
return getJdkHome(otherProp, null, prop);
|
|
||||||
} else {
|
|
||||||
throw new AssertionError("Environment variable " + propToReport + " is not set!");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return new File(jdk);
|
if (jdkPath == null) {
|
||||||
|
throw new AssertionError("Environment variable " + mainProperty + " is not set!");
|
||||||
|
}
|
||||||
|
|
||||||
|
return new File(jdkPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String getStringProperty(@NotNull String propertyName) {
|
||||||
|
String value = System.getProperty(propertyName);
|
||||||
|
if (value != null) {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
return System.getenv(propertyName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@@ -397,7 +410,7 @@ public class KtTestUtil {
|
|||||||
private static void assertTestClassPresentByMetadata(@NotNull Class<?> outerClass, @NotNull File testDataDir) {
|
private static void assertTestClassPresentByMetadata(@NotNull Class<?> outerClass, @NotNull File testDataDir) {
|
||||||
for (Class<?> nestedClass : outerClass.getDeclaredClasses()) {
|
for (Class<?> nestedClass : outerClass.getDeclaredClasses()) {
|
||||||
TestMetadata testMetadata = nestedClass.getAnnotation(TestMetadata.class);
|
TestMetadata testMetadata = nestedClass.getAnnotation(TestMetadata.class);
|
||||||
if (testMetadata != null && testMetadata.value().equals(KtTestUtil.getFilePath(testDataDir))) {
|
if (testMetadata != null && testMetadata.value().equals(getFilePath(testDataDir))) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user