'Configure as Kotlin (java) modules' doesn't work properly if several modules depends on KotlinJavaRuntime

#KT-5595 Fixed
This commit is contained in:
Nikolay Krasko
2014-08-08 22:27:41 +04:00
parent 2dbc328693
commit 51aa70eba8
11 changed files with 147 additions and 8 deletions
@@ -147,7 +147,7 @@ public class KotlinJsModuleConfigurator extends KotlinWithLibraryConfigurator {
} }
@NotNull @NotNull
private static String getDefaultPathToJsFile(@NotNull Project project) { protected String getDefaultPathToJsFile(@NotNull Project project) {
return FileUIUtils.createRelativePath(project, project.getBaseDir(), "script"); return FileUIUtils.createRelativePath(project, project.getBaseDir(), "script");
} }
@@ -41,6 +41,7 @@ import java.io.File;
import static org.jetbrains.jet.plugin.configuration.ConfigureKotlinInProjectUtils.showInfoNotification; import static org.jetbrains.jet.plugin.configuration.ConfigureKotlinInProjectUtils.showInfoNotification;
public abstract class KotlinWithLibraryConfigurator implements KotlinProjectConfigurator { public abstract class KotlinWithLibraryConfigurator implements KotlinProjectConfigurator {
public static final String DEFAULT_LIBRARY_DIR = "lib";
@NotNull @NotNull
protected abstract String getLibraryName(); protected abstract String getLibraryName();
@@ -376,8 +377,8 @@ public abstract class KotlinWithLibraryConfigurator implements KotlinProjectConf
return !isProjectLibraryPresent(project) && !getFileInDir(getJarName(), defaultPath).exists(); return !isProjectLibraryPresent(project) && !getFileInDir(getJarName(), defaultPath).exists();
} }
protected static String getDefaultPathToJarFile(@NotNull Project project) { protected String getDefaultPathToJarFile(@NotNull Project project) {
return FileUIUtils.createRelativePath(project, project.getBaseDir(), "lib"); return FileUIUtils.createRelativePath(project, project.getBaseDir(), DEFAULT_LIBRARY_DIR);
} }
protected void showError(@NotNull String message) { protected void showError(@NotNull String message) {
@@ -73,7 +73,7 @@ public abstract class CreateJavaLibraryDialogBase extends DialogWrapper {
@Nullable @Nullable
public String getCopyIntoPath() { public String getCopyIntoPath() {
return pathPanel.getPath(); return chooseLibraryPathPlace.isVisible() ? pathPanel.getPath() : null;
} }
@Nullable @Nullable
@@ -98,6 +98,7 @@ public abstract class CreateJavaScriptLibraryDialogBase extends DialogWrapper im
@Override @Override
@Nullable @Nullable
public String getCopyLibraryIntoPath() { public String getCopyLibraryIntoPath() {
if (!copyLibraryPlace.isVisible()) return null;
return copyLibraryFilePanel.getPath(); return copyLibraryFilePanel.getPath();
} }
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<orderEntry type="library" name="KotlinJavaScript" level="project" />
</component>
</module>
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<orderEntry type="library" name="KotlinJavaScript" level="project" />
</component>
</module>
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/module1.iml" filepath="$PROJECT_DIR$/module1.iml" />
<module fileurl="file://$PROJECT_DIR$/module2.iml" filepath="$PROJECT_DIR$/module2.iml" />
</modules>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_6" assert-keyword="true" jdk-15="true" project-jdk-name="1.6" project-jdk-type="JavaSDK"/>
<component name="libraryTable">
<library name="KotlinJavaScript">
<CLASSES>
<root url="jar://$TEMP_TEST_DIR$/kotlin-jslib.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES>
<root url="jar://$TEMP_TEST_DIR$/kotlin-jslib.jar!/src" />
</SOURCES>
</library>
</component>
</project>
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<orderEntry type="library" name="KotlinJavaRuntime" level="project" />
</component>
</module>
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<orderEntry type="library" name="KotlinJavaRuntime" level="project" />
</component>
</module>
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/module1.iml" filepath="$PROJECT_DIR$/module1.iml" />
<module fileurl="file://$PROJECT_DIR$/module2.iml" filepath="$PROJECT_DIR$/module2.iml" />
</modules>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_6" assert-keyword="true" jdk-15="true" project-jdk-name="1.6" project-jdk-type="JavaSDK"/>
<component name="libraryTable">
<library name="KotlinJavaRuntime">
<CLASSES>
<root url="jar://$TEMP_TEST_DIR$/kotlin-runtime.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES>
<root url="jar://$TEMP_TEST_DIR$/kotlin-runtime.jar!/src" />
</SOURCES>
</library>
</component>
</project>
@@ -21,6 +21,7 @@ import com.intellij.openapi.module.Module;
import com.intellij.openapi.module.ModuleManager; import com.intellij.openapi.module.ModuleManager;
import com.intellij.openapi.project.Project; import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.util.io.FileUtilRt;
import com.intellij.testFramework.PlatformTestCase; import com.intellij.testFramework.PlatformTestCase;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.utils.PathUtil; import org.jetbrains.jet.utils.PathUtil;
@@ -35,12 +36,32 @@ import static org.jetbrains.jet.plugin.configuration.KotlinWithLibraryConfigurat
public class ConfigureKotlinTest extends PlatformTestCase { public class ConfigureKotlinTest extends PlatformTestCase {
private static final String BASE_PATH = "idea/testData/configuration/"; private static final String BASE_PATH = "idea/testData/configuration/";
private static final KotlinJavaModuleConfigurator JAVA_CONFIGURATOR = new KotlinJavaModuleConfigurator();
private static final KotlinJsModuleConfigurator JS_CONFIGURATOR = new KotlinJsModuleConfigurator(); private static final KotlinJavaModuleConfigurator JAVA_CONFIGURATOR = new KotlinJavaModuleConfigurator() {
@Override
protected String getDefaultPathToJarFile(@NotNull Project project) {
return getPathRelativeToTemp("default_jvm_lib");
}
};
private static final String TEMP_DIR_MACRO_KEY = "TEMP_TEST_DIR";
private static final KotlinJsModuleConfigurator JS_CONFIGURATOR = new KotlinJsModuleConfigurator() {
@Override
protected String getDefaultPathToJarFile(@NotNull Project project) {
return getPathRelativeToTemp("default_js_lib");
}
@NotNull
@Override
protected String getDefaultPathToJsFile(@NotNull Project project) {
return getPathRelativeToTemp("default_script");
}
};
@Override @Override
protected void tearDown() throws Exception { protected void tearDown() throws Exception {
PathMacros.getInstance().removeMacro("TEMP_TEST_DIR"); PathMacros.getInstance().removeMacro(TEMP_DIR_MACRO_KEY);
super.tearDown(); super.tearDown();
} }
@@ -50,7 +71,7 @@ public class ConfigureKotlinTest extends PlatformTestCase {
super.initApplication(); super.initApplication();
File tempLibDir = FileUtil.createTempDirectory("temp", null); File tempLibDir = FileUtil.createTempDirectory("temp", null);
PathMacros.getInstance().setMacro("TEMP_TEST_DIR", tempLibDir.getAbsolutePath()); PathMacros.getInstance().setMacro(TEMP_DIR_MACRO_KEY, FileUtilRt.toSystemDependentName(tempLibDir.getAbsolutePath()));
} }
public void testNewLibrary_copyJar() { public void testNewLibrary_copyJar() {
@@ -106,11 +127,24 @@ public class ConfigureKotlinTest extends PlatformTestCase {
public void testLibraryNonDefault_libExistInDefault() throws IOException { public void testLibraryNonDefault_libExistInDefault() throws IOException {
Module module = getModule(); Module module = getModule();
// Move fake runtime jar to default library path to pretend library is already configured
FileUtil.copy(
new File(getProject().getBasePath() + "/lib/kotlin-runtime.jar"),
new File(JAVA_CONFIGURATOR.getDefaultPathToJarFile(getProject()) + "/kotlin-runtime.jar"));
assertNotConfigured(module, JAVA_CONFIGURATOR); assertNotConfigured(module, JAVA_CONFIGURATOR);
JAVA_CONFIGURATOR.configure(myProject); JAVA_CONFIGURATOR.configure(myProject);
assertProperlyConfigured(module, JAVA_CONFIGURATOR); assertProperlyConfigured(module, JAVA_CONFIGURATOR);
} }
public void testTwoModulesWithNonDefaultPath_doNotCopyInDefault() throws IOException {
doTestConfigureModulesWithNonDefaultSetup(JAVA_CONFIGURATOR);
}
public void testTwoModulesWithJSNonDefaultPath_doNotCopyInDefault() throws IOException {
doTestConfigureModulesWithNonDefaultSetup(JS_CONFIGURATOR);
}
public void testNewLibrary_jarExists_js() { public void testNewLibrary_jarExists_js() {
doTestOneJsModule(FileState.EXISTS, LibraryState.NEW_LIBRARY); doTestOneJsModule(FileState.EXISTS, LibraryState.NEW_LIBRARY);
} }
@@ -145,6 +179,23 @@ public class ConfigureKotlinTest extends PlatformTestCase {
doTestOneJsModule(FileState.DO_NOT_COPY, LibraryState.NON_CONFIGURED_LIBRARY); doTestOneJsModule(FileState.DO_NOT_COPY, LibraryState.NON_CONFIGURED_LIBRARY);
} }
private void doTestConfigureModulesWithNonDefaultSetup(KotlinWithLibraryConfigurator configurator) {
assertNoFilesInDefaultPaths(true);
Module[] modules = getModules();
for (Module module : modules) {
assertNotConfigured(module, configurator);
}
configurator.configure(myProject);
assertNoFilesInDefaultPaths(false);
for (Module module : modules) {
assertProperlyConfigured(module, configurator);
}
}
private void doTestOneJavaModule(@NotNull FileState jarState, @NotNull LibraryState libraryState) { private void doTestOneJavaModule(@NotNull FileState jarState, @NotNull LibraryState libraryState) {
doTestOneModule(jarState, libraryState, JAVA_CONFIGURATOR); doTestOneModule(jarState, libraryState, JAVA_CONFIGURATOR);
} }
@@ -259,6 +310,15 @@ public class ConfigureKotlinTest extends PlatformTestCase {
protected void setUpModule() { protected void setUpModule() {
} }
private void assertNoFilesInDefaultPaths(boolean checkJsFiles) {
assertDoesntExist(new File(JAVA_CONFIGURATOR.getDefaultPathToJarFile(getProject())));
assertDoesntExist(new File(JS_CONFIGURATOR.getDefaultPathToJarFile(getProject())));
if (checkJsFiles) {
assertDoesntExist(new File(JS_CONFIGURATOR.getDefaultPathToJsFile(getProject())));
}
}
private static void assertNotConfigured(Module module, KotlinWithLibraryConfigurator configurator) { private static void assertNotConfigured(Module module, KotlinWithLibraryConfigurator configurator) {
assertFalse( assertFalse(
String.format("Module %s should not be configured as %s Module", module.getName(), configurator.getPresentableText()), String.format("Module %s should not be configured as %s Module", module.getName(), configurator.getPresentableText()),
@@ -282,4 +342,9 @@ public class ConfigureKotlinTest extends PlatformTestCase {
throw new IllegalArgumentException("Only JS_CONFIGURATOR and JAVA_CONFIGURATOR are supported"); throw new IllegalArgumentException("Only JS_CONFIGURATOR and JAVA_CONFIGURATOR are supported");
} }
private static String getPathRelativeToTemp(String relativePath) {
String tempPath = PathMacros.getInstance().getValue(TEMP_DIR_MACRO_KEY);
return tempPath + '/' + relativePath;
}
} }