Refactor runtime library configuration in IDE
This commit is contained in:
@@ -29,10 +29,9 @@ import org.jetbrains.kotlin.idea.framework.JavaRuntimePresentationProvider;
|
|||||||
import org.jetbrains.kotlin.idea.project.ProjectStructureUtil;
|
import org.jetbrains.kotlin.idea.project.ProjectStructureUtil;
|
||||||
import org.jetbrains.kotlin.idea.project.TargetPlatform;
|
import org.jetbrains.kotlin.idea.project.TargetPlatform;
|
||||||
import org.jetbrains.kotlin.idea.versions.KotlinRuntimeLibraryCoreUtil;
|
import org.jetbrains.kotlin.idea.versions.KotlinRuntimeLibraryCoreUtil;
|
||||||
|
import org.jetbrains.kotlin.utils.KotlinPaths;
|
||||||
import org.jetbrains.kotlin.utils.PathUtil;
|
import org.jetbrains.kotlin.utils.PathUtil;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
|
|
||||||
import static org.jetbrains.kotlin.idea.configuration.ConfigureKotlinInProjectUtils.showInfoNotification;
|
import static org.jetbrains.kotlin.idea.configuration.ConfigureKotlinInProjectUtils.showInfoNotification;
|
||||||
|
|
||||||
public class KotlinJavaModuleConfigurator extends KotlinWithLibraryConfigurator {
|
public class KotlinJavaModuleConfigurator extends KotlinWithLibraryConfigurator {
|
||||||
@@ -61,18 +60,6 @@ public class KotlinJavaModuleConfigurator extends KotlinWithLibraryConfigurator
|
|||||||
return JavaRuntimeLibraryDescription.LIBRARY_CAPTION;
|
return JavaRuntimeLibraryDescription.LIBRARY_CAPTION;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@Override
|
|
||||||
public String getJarName() {
|
|
||||||
return PathUtil.KOTLIN_JAVA_RUNTIME_JAR;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@Override
|
|
||||||
public String getSourcesJarName() {
|
|
||||||
return PathUtil.KOTLIN_JAVA_RUNTIME_SRC_JAR;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
protected String getMessageForOverrideDialog() {
|
protected String getMessageForOverrideDialog() {
|
||||||
@@ -97,23 +84,21 @@ public class KotlinJavaModuleConfigurator extends KotlinWithLibraryConfigurator
|
|||||||
return TargetPlatform.JVM;
|
return TargetPlatform.JVM;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public File getExistingJarFile() {
|
|
||||||
return assertFileExists(PathUtil.getKotlinPathsForIdeaPlugin().getRuntimePath());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@NotNull
|
public RuntimeLibraryFiles getExistingJarFiles() {
|
||||||
public File getExistingSourcesJarFile() {
|
KotlinPaths paths = PathUtil.getKotlinPathsForIdeaPlugin();
|
||||||
return assertFileExists(PathUtil.getKotlinPathsForIdeaPlugin().getRuntimeSourcesPath());
|
return new RuntimeLibraryFiles(
|
||||||
|
assertFileExists(paths.getRuntimePath()),
|
||||||
|
assertFileExists(paths.getRuntimeSourcesPath())
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void copySourcesToPathFromLibrary(@NotNull Library library) {
|
public void copySourcesToPathFromLibrary(@NotNull Library library) {
|
||||||
String dirToJarFromLibrary = getPathFromLibrary(library, OrderRootType.SOURCES);
|
String dirToJarFromLibrary = getPathFromLibrary(library, OrderRootType.SOURCES);
|
||||||
assert dirToJarFromLibrary != null : "Directory to file from library should be non null";
|
assert dirToJarFromLibrary != null : "Directory to file from library should be non null";
|
||||||
|
|
||||||
copyFileToDir(getExistingSourcesJarFile(), dirToJarFromLibrary);
|
copyFileToDir(getExistingJarFiles().getRuntimeSourcesJar(), dirToJarFromLibrary);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean changeOldSourcesPathIfNeeded(@NotNull Library library) {
|
public boolean changeOldSourcesPathIfNeeded(@NotNull Library library) {
|
||||||
@@ -124,7 +109,7 @@ public class KotlinJavaModuleConfigurator extends KotlinWithLibraryConfigurator
|
|||||||
String parentDir = getPathFromLibrary(library, OrderRootType.CLASSES);
|
String parentDir = getPathFromLibrary(library, OrderRootType.CLASSES);
|
||||||
assert parentDir != null : "Parent dir for classes jar should exists for Kotlin library";
|
assert parentDir != null : "Parent dir for classes jar should exists for Kotlin library";
|
||||||
|
|
||||||
return addSourcesToLibraryIfNeeded(library, getFileInDir(getSourcesJarName(), parentDir));
|
return addSourcesToLibraryIfNeeded(library, getExistingJarFiles().getRuntimeSourcesDestination(parentDir));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean removeOldSourcesRootIfNeeded(@NotNull Library library) {
|
private static boolean removeOldSourcesRootIfNeeded(@NotNull Library library) {
|
||||||
|
|||||||
@@ -22,10 +22,9 @@ import org.jetbrains.kotlin.idea.framework.JSLibraryStdDescription;
|
|||||||
import org.jetbrains.kotlin.idea.project.ProjectStructureUtil;
|
import org.jetbrains.kotlin.idea.project.ProjectStructureUtil;
|
||||||
import org.jetbrains.kotlin.idea.project.TargetPlatform;
|
import org.jetbrains.kotlin.idea.project.TargetPlatform;
|
||||||
import org.jetbrains.kotlin.js.JavaScript;
|
import org.jetbrains.kotlin.js.JavaScript;
|
||||||
|
import org.jetbrains.kotlin.utils.KotlinPaths;
|
||||||
import org.jetbrains.kotlin.utils.PathUtil;
|
import org.jetbrains.kotlin.utils.PathUtil;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
|
|
||||||
public class KotlinJsModuleConfigurator extends KotlinWithLibraryConfigurator {
|
public class KotlinJsModuleConfigurator extends KotlinWithLibraryConfigurator {
|
||||||
public static final String NAME = JavaScript.LOWER_NAME;
|
public static final String NAME = JavaScript.LOWER_NAME;
|
||||||
|
|
||||||
@@ -70,18 +69,6 @@ public class KotlinJsModuleConfigurator extends KotlinWithLibraryConfigurator {
|
|||||||
return JSLibraryStdDescription.LIBRARY_CAPTION;
|
return JSLibraryStdDescription.LIBRARY_CAPTION;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@Override
|
|
||||||
public String getJarName() {
|
|
||||||
return PathUtil.JS_LIB_JAR_NAME;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@Override
|
|
||||||
public String getSourcesJarName() {
|
|
||||||
return PathUtil.JS_LIB_SRC_JAR_NAME;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
protected String getMessageForOverrideDialog() {
|
protected String getMessageForOverrideDialog() {
|
||||||
@@ -90,14 +77,12 @@ public class KotlinJsModuleConfigurator extends KotlinWithLibraryConfigurator {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public File getExistingJarFile() {
|
public RuntimeLibraryFiles getExistingJarFiles() {
|
||||||
return assertFileExists(PathUtil.getKotlinPathsForIdeaPlugin().getJsStdLibJarPath());
|
KotlinPaths paths = PathUtil.getKotlinPathsForIdeaPlugin();
|
||||||
}
|
return new RuntimeLibraryFiles(
|
||||||
|
paths.getJsStdLibJarPath(),
|
||||||
@NotNull
|
paths.getJsStdLibSrcJarPath()
|
||||||
@Override
|
);
|
||||||
public File getExistingSourcesJarFile() {
|
|
||||||
return assertFileExists(PathUtil.getKotlinPathsForIdeaPlugin().getJsStdLibSrcJarPath());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
KotlinJsModuleConfigurator() {
|
KotlinJsModuleConfigurator() {
|
||||||
|
|||||||
+26
-38
@@ -51,12 +51,6 @@ public abstract class KotlinWithLibraryConfigurator implements KotlinProjectConf
|
|||||||
@NotNull
|
@NotNull
|
||||||
protected abstract String getLibraryName();
|
protected abstract String getLibraryName();
|
||||||
|
|
||||||
@NotNull
|
|
||||||
public abstract String getJarName();
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
public abstract String getSourcesJarName();
|
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
protected abstract String getMessageForOverrideDialog();
|
protected abstract String getMessageForOverrideDialog();
|
||||||
|
|
||||||
@@ -67,10 +61,7 @@ public abstract class KotlinWithLibraryConfigurator implements KotlinProjectConf
|
|||||||
protected abstract String getLibraryCaption();
|
protected abstract String getLibraryCaption();
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public abstract File getExistingJarFile();
|
public abstract RuntimeLibraryFiles getExistingJarFiles();
|
||||||
|
|
||||||
@NotNull
|
|
||||||
public abstract File getExistingSourcesJarFile();
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isApplicable(@NotNull Module module) {
|
public boolean isApplicable(@NotNull Module module) {
|
||||||
@@ -119,16 +110,18 @@ public abstract class KotlinWithLibraryConfigurator implements KotlinProjectConf
|
|||||||
) {
|
) {
|
||||||
Project project = module.getProject();
|
Project project = module.getProject();
|
||||||
|
|
||||||
|
RuntimeLibraryFiles files = getExistingJarFiles();
|
||||||
LibraryState libraryState = getLibraryState(project);
|
LibraryState libraryState = getLibraryState(project);
|
||||||
String dirToCopyJar = getPathToCopyFileTo(project, OrderRootType.CLASSES, defaultPath, pathFromDialog);
|
String dirToCopyJar = getPathToCopyFileTo(project, OrderRootType.CLASSES, defaultPath, pathFromDialog);
|
||||||
FileState runtimeState = getJarState(project, getJarName(), OrderRootType.CLASSES, dirToCopyJar, pathFromDialog == null);
|
FileState runtimeState =
|
||||||
|
getJarState(project, files.getRuntimeDestination(dirToCopyJar), OrderRootType.CLASSES, pathFromDialog == null);
|
||||||
|
|
||||||
configureModuleWithLibraryClasses(module, libraryState, runtimeState, dirToCopyJar);
|
configureModuleWithLibraryClasses(module, libraryState, runtimeState, dirToCopyJar);
|
||||||
|
|
||||||
Library library = getKotlinLibrary(project);
|
Library library = getKotlinLibrary(project);
|
||||||
assert library != null : "Kotlin library should exists when adding sources root";
|
assert library != null : "Kotlin library should exists when adding sources root";
|
||||||
String dirToCopySourcesJar = getPathToCopyFileTo(project, OrderRootType.SOURCES, defaultPath, pathFromDialog);
|
String dirToCopySourcesJar = getPathToCopyFileTo(project, OrderRootType.SOURCES, defaultPath, pathFromDialog);
|
||||||
FileState sourcesState = getJarState(project, getSourcesJarName(), OrderRootType.SOURCES, dirToCopySourcesJar,
|
FileState sourcesState = getJarState(project, files.getRuntimeSourcesDestination(dirToCopySourcesJar), OrderRootType.SOURCES,
|
||||||
pathFromDialog == null);
|
pathFromDialog == null);
|
||||||
|
|
||||||
configureModuleWithLibrarySources(library, sourcesState, dirToCopySourcesJar);
|
configureModuleWithLibrarySources(library, sourcesState, dirToCopySourcesJar);
|
||||||
@@ -141,6 +134,8 @@ public abstract class KotlinWithLibraryConfigurator implements KotlinProjectConf
|
|||||||
@NotNull String dirToCopyJarTo
|
@NotNull String dirToCopyJarTo
|
||||||
) {
|
) {
|
||||||
Project project = module.getProject();
|
Project project = module.getProject();
|
||||||
|
RuntimeLibraryFiles files = getExistingJarFiles();
|
||||||
|
File runtimeJar = files.getRuntimeJar();
|
||||||
|
|
||||||
switch (libraryState) {
|
switch (libraryState) {
|
||||||
case LIBRARY:
|
case LIBRARY:
|
||||||
@@ -149,7 +144,7 @@ public abstract class KotlinWithLibraryConfigurator implements KotlinProjectConf
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case COPY: {
|
case COPY: {
|
||||||
copyJarToDir(dirToCopyJarTo);
|
copyFileToDir(runtimeJar, dirToCopyJarTo);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case DO_NOT_COPY: {
|
case DO_NOT_COPY: {
|
||||||
@@ -161,16 +156,16 @@ public abstract class KotlinWithLibraryConfigurator implements KotlinProjectConf
|
|||||||
case NON_CONFIGURED_LIBRARY:
|
case NON_CONFIGURED_LIBRARY:
|
||||||
switch (jarState) {
|
switch (jarState) {
|
||||||
case EXISTS: {
|
case EXISTS: {
|
||||||
addJarToExistingLibrary(project, getFileInDir(getJarName(), dirToCopyJarTo));
|
addJarToExistingLibrary(project, files.getRuntimeDestination(dirToCopyJarTo));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case COPY: {
|
case COPY: {
|
||||||
File file = copyJarToDir(dirToCopyJarTo);
|
File file = copyFileToDir(runtimeJar, dirToCopyJarTo);
|
||||||
addJarToExistingLibrary(project, file);
|
addJarToExistingLibrary(project, file);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case DO_NOT_COPY: {
|
case DO_NOT_COPY: {
|
||||||
addJarToExistingLibrary(project, getExistingJarFile());
|
addJarToExistingLibrary(project, runtimeJar);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -178,16 +173,16 @@ public abstract class KotlinWithLibraryConfigurator implements KotlinProjectConf
|
|||||||
case NEW_LIBRARY:
|
case NEW_LIBRARY:
|
||||||
switch (jarState) {
|
switch (jarState) {
|
||||||
case EXISTS: {
|
case EXISTS: {
|
||||||
addJarToNewLibrary(project, getFileInDir(getJarName(), dirToCopyJarTo));
|
addJarToNewLibrary(project, files.getRuntimeDestination(dirToCopyJarTo));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case COPY: {
|
case COPY: {
|
||||||
File file = copyJarToDir(dirToCopyJarTo);
|
File file = copyFileToDir(runtimeJar, dirToCopyJarTo);
|
||||||
addJarToNewLibrary(project, file);
|
addJarToNewLibrary(project, file);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case DO_NOT_COPY: {
|
case DO_NOT_COPY: {
|
||||||
addJarToNewLibrary(project, getExistingJarFile());
|
addJarToNewLibrary(project, runtimeJar);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -201,31 +196,28 @@ public abstract class KotlinWithLibraryConfigurator implements KotlinProjectConf
|
|||||||
@NotNull FileState jarState,
|
@NotNull FileState jarState,
|
||||||
@Nullable String dirToCopyJarTo
|
@Nullable String dirToCopyJarTo
|
||||||
) {
|
) {
|
||||||
|
RuntimeLibraryFiles files = getExistingJarFiles();
|
||||||
|
File runtimeSourcesJar = files.getRuntimeSourcesJar();
|
||||||
switch (jarState) {
|
switch (jarState) {
|
||||||
case EXISTS: {
|
case EXISTS: {
|
||||||
if (dirToCopyJarTo != null) {
|
if (dirToCopyJarTo != null) {
|
||||||
addSourcesToLibraryIfNeeded(library, getFileInDir(getSourcesJarName(), dirToCopyJarTo));
|
addSourcesToLibraryIfNeeded(library, files.getRuntimeSourcesDestination(dirToCopyJarTo));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case COPY: {
|
case COPY: {
|
||||||
assert dirToCopyJarTo != null : "Path to copy should be non-null";
|
assert dirToCopyJarTo != null : "Path to copy should be non-null";
|
||||||
File file = copyFileToDir(getExistingSourcesJarFile(), dirToCopyJarTo);
|
File file = copyFileToDir(runtimeSourcesJar, dirToCopyJarTo);
|
||||||
addSourcesToLibraryIfNeeded(library, file);
|
addSourcesToLibraryIfNeeded(library, file);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case DO_NOT_COPY: {
|
case DO_NOT_COPY: {
|
||||||
addSourcesToLibraryIfNeeded(library, getExistingSourcesJarFile());
|
addSourcesToLibraryIfNeeded(library, runtimeSourcesJar);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
|
||||||
public static File getFileInDir(@NotNull String fileName, @NotNull String dirToJar) {
|
|
||||||
return new File(dirToJar + "/" + fileName);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public Library getKotlinLibrary(@NotNull Project project) {
|
public Library getKotlinLibrary(@NotNull Project project) {
|
||||||
LibrariesContainer librariesContainer = LibrariesContainerFactory.createContainer(project);
|
LibrariesContainer librariesContainer = LibrariesContainerFactory.createContainer(project);
|
||||||
@@ -404,8 +396,10 @@ public abstract class KotlinWithLibraryConfigurator implements KotlinProjectConf
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String fileName = getExistingJarFiles().getRuntimeJar().getName();
|
||||||
|
|
||||||
for (VirtualFile root : library.getFiles(OrderRootType.CLASSES)) {
|
for (VirtualFile root : library.getFiles(OrderRootType.CLASSES)) {
|
||||||
if (root.getName().equals(getJarName())) {
|
if (root.getName().equals(fileName)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -413,13 +407,9 @@ public abstract class KotlinWithLibraryConfigurator implements KotlinProjectConf
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private File copyJarToDir(@NotNull String toDir) {
|
|
||||||
return copyFileToDir(getExistingJarFile(), toDir);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected boolean needToChooseJarPath(@NotNull Project project) {
|
protected boolean needToChooseJarPath(@NotNull Project project) {
|
||||||
String defaultPath = getDefaultPathToJarFile(project);
|
String defaultPath = getDefaultPathToJarFile(project);
|
||||||
return !isProjectLibraryPresent(project) && !getFileInDir(getJarName(), defaultPath).exists();
|
return !isProjectLibraryPresent(project) && !getExistingJarFiles().getRuntimeDestination(defaultPath).exists();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String getDefaultPathToJarFile(@NotNull Project project) {
|
protected String getDefaultPathToJarFile(@NotNull Project project) {
|
||||||
@@ -456,16 +446,14 @@ public abstract class KotlinWithLibraryConfigurator implements KotlinProjectConf
|
|||||||
@NotNull
|
@NotNull
|
||||||
protected FileState getJarState(
|
protected FileState getJarState(
|
||||||
@NotNull Project project,
|
@NotNull Project project,
|
||||||
@NotNull String jarName,
|
@NotNull File targetFile,
|
||||||
@NotNull OrderRootType jarType,
|
@NotNull OrderRootType jarType,
|
||||||
@NotNull String copyPath,
|
|
||||||
boolean useBundled
|
boolean useBundled
|
||||||
) {
|
) {
|
||||||
String pathFromLibrary = getPathFromLibrary(project, jarType);
|
if (targetFile.exists()) {
|
||||||
if (getFileInDir(jarName, copyPath).exists()) {
|
|
||||||
return FileState.EXISTS;
|
return FileState.EXISTS;
|
||||||
}
|
}
|
||||||
else if (pathFromLibrary != null) {
|
else if (getPathFromLibrary(project, jarType) != null) {
|
||||||
return FileState.COPY;
|
return FileState.COPY;
|
||||||
}
|
}
|
||||||
else if (useBundled) {
|
else if (useBundled) {
|
||||||
|
|||||||
@@ -0,0 +1,32 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2015 JetBrains s.r.o.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jetbrains.kotlin.idea.configuration
|
||||||
|
|
||||||
|
import java.io.File
|
||||||
|
|
||||||
|
class RuntimeLibraryFiles(
|
||||||
|
val runtimeJar: File,
|
||||||
|
val runtimeSourcesJar: File
|
||||||
|
) {
|
||||||
|
fun getAllJars(): List<File> = listOf(runtimeJar, runtimeSourcesJar)
|
||||||
|
|
||||||
|
fun getRuntimeDestination(dirToCopyJar: String): File =
|
||||||
|
File(dirToCopyJar + "/" + runtimeJar.name)
|
||||||
|
|
||||||
|
fun getRuntimeSourcesDestination(dirToCopyJar: String): File =
|
||||||
|
File(dirToCopyJar + "/" + runtimeSourcesJar.name)
|
||||||
|
}
|
||||||
+13
-13
@@ -36,6 +36,7 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.kotlin.idea.configuration.ConfigureKotlinInProjectUtils;
|
import org.jetbrains.kotlin.idea.configuration.ConfigureKotlinInProjectUtils;
|
||||||
import org.jetbrains.kotlin.idea.configuration.KotlinWithLibraryConfigurator;
|
import org.jetbrains.kotlin.idea.configuration.KotlinWithLibraryConfigurator;
|
||||||
|
import org.jetbrains.kotlin.idea.configuration.RuntimeLibraryFiles;
|
||||||
import org.jetbrains.kotlin.idea.framework.ui.CreateLibraryDialog;
|
import org.jetbrains.kotlin.idea.framework.ui.CreateLibraryDialog;
|
||||||
import org.jetbrains.kotlin.idea.framework.ui.FileUIUtils;
|
import org.jetbrains.kotlin.idea.framework.ui.FileUIUtils;
|
||||||
import org.jetbrains.kotlin.idea.util.projectStructure.ProjectStructurePackage;
|
import org.jetbrains.kotlin.idea.util.projectStructure.ProjectStructurePackage;
|
||||||
@@ -46,8 +47,6 @@ import java.util.Arrays;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import static org.jetbrains.kotlin.idea.configuration.KotlinWithLibraryConfigurator.getFileInDir;
|
|
||||||
|
|
||||||
public abstract class CustomLibraryDescriptorWithDeferredConfig extends CustomLibraryDescription {
|
public abstract class CustomLibraryDescriptorWithDeferredConfig extends CustomLibraryDescription {
|
||||||
|
|
||||||
private static final String DEFAULT_LIB_DIR_NAME = "lib";
|
private static final String DEFAULT_LIB_DIR_NAME = "lib";
|
||||||
@@ -172,44 +171,45 @@ public abstract class CustomLibraryDescriptorWithDeferredConfig extends CustomLi
|
|||||||
String defaultPathToJarFile = useRelativePaths ? DEFAULT_LIB_DIR_NAME
|
String defaultPathToJarFile = useRelativePaths ? DEFAULT_LIB_DIR_NAME
|
||||||
: FileUIUtils.createRelativePath(null, contextDirectory, DEFAULT_LIB_DIR_NAME);
|
: FileUIUtils.createRelativePath(null, contextDirectory, DEFAULT_LIB_DIR_NAME);
|
||||||
|
|
||||||
File bundledLibJarFile = configurator.getExistingJarFile();
|
RuntimeLibraryFiles files = configurator.getExistingJarFiles();
|
||||||
File bundledLibSourcesJarFile = configurator.getExistingSourcesJarFile();
|
|
||||||
|
|
||||||
File libraryFile;
|
File libraryFile;
|
||||||
File librarySrcFile;
|
File librarySrcFile;
|
||||||
|
|
||||||
File stdJarInDefaultPath = getFileInDir(configurator.getJarName(), defaultPathToJarFile);
|
File stdJarInDefaultPath = files.getRuntimeDestination(defaultPathToJarFile);
|
||||||
if (!useRelativePaths && stdJarInDefaultPath.exists()) {
|
if (!useRelativePaths && stdJarInDefaultPath.exists()) {
|
||||||
libraryFile = stdJarInDefaultPath;
|
libraryFile = stdJarInDefaultPath;
|
||||||
|
|
||||||
File sourcesJar = getFileInDir(configurator.getSourcesJarName(), defaultPathToJarFile);
|
File sourcesJar = files.getRuntimeSourcesDestination(defaultPathToJarFile);
|
||||||
if (sourcesJar.exists()) {
|
if (sourcesJar.exists()) {
|
||||||
librarySrcFile = sourcesJar;
|
librarySrcFile = sourcesJar;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
deferredCopyFileRequests.addCopyWithReplaceRequest(bundledLibSourcesJarFile, libraryFile.getParent());
|
librarySrcFile = files.getRuntimeSourcesJar();
|
||||||
librarySrcFile = bundledLibSourcesJarFile;
|
deferredCopyFileRequests.addCopyWithReplaceRequest(librarySrcFile, libraryFile.getParent());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
CreateLibraryDialog dialog =new CreateLibraryDialog(defaultPathToJarFile, dialogTitle, modulesSeparatorCaption);
|
CreateLibraryDialog dialog = new CreateLibraryDialog(defaultPathToJarFile, dialogTitle, modulesSeparatorCaption);
|
||||||
dialog.show();
|
dialog.show();
|
||||||
|
|
||||||
if (!dialog.isOK()) return null;
|
if (!dialog.isOK()) return null;
|
||||||
|
|
||||||
String copyIntoPath = dialog.getCopyIntoPath();
|
String copyIntoPath = dialog.getCopyIntoPath();
|
||||||
if (copyIntoPath != null) {
|
if (copyIntoPath != null) {
|
||||||
deferredCopyFileRequests.addCopyWithReplaceRequest(bundledLibJarFile, copyIntoPath);
|
for (File file : files.getAllJars()) {
|
||||||
deferredCopyFileRequests.addCopyWithReplaceRequest(bundledLibSourcesJarFile, copyIntoPath);
|
deferredCopyFileRequests.addCopyWithReplaceRequest(file, copyIntoPath);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
libraryFile = bundledLibJarFile;
|
libraryFile = files.getRuntimeJar();
|
||||||
librarySrcFile = bundledLibSourcesJarFile;
|
librarySrcFile = files.getRuntimeSourcesJar();
|
||||||
}
|
}
|
||||||
|
|
||||||
return createConfiguration(libraryFile, librarySrcFile);
|
return createConfiguration(libraryFile, librarySrcFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
protected NewLibraryConfiguration createConfiguration(@NotNull File libraryFile, @NotNull File librarySrcFile) {
|
protected NewLibraryConfiguration createConfiguration(@NotNull File libraryFile, @NotNull File librarySrcFile) {
|
||||||
final String libraryFileUrl = VfsUtil.getUrlForLibraryRoot(libraryFile);
|
final String libraryFileUrl = VfsUtil.getUrlForLibraryRoot(libraryFile);
|
||||||
final String libraryFileSrcUrl = VfsUtil.getUrlForLibraryRoot(librarySrcFile);
|
final String libraryFileSrcUrl = VfsUtil.getUrlForLibraryRoot(librarySrcFile);
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ import com.intellij.openapi.roots.libraries.NewLibraryConfiguration;
|
|||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.annotations.TestOnly;
|
import org.jetbrains.annotations.TestOnly;
|
||||||
import org.jetbrains.kotlin.idea.configuration.KotlinJsModuleConfigurator;
|
import org.jetbrains.kotlin.idea.configuration.KotlinJsModuleConfigurator;
|
||||||
|
import org.jetbrains.kotlin.idea.configuration.RuntimeLibraryFiles;
|
||||||
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
@@ -50,6 +51,7 @@ public class JSLibraryStdDescription extends CustomLibraryDescriptorWithDeferred
|
|||||||
KotlinJsModuleConfigurator configurator = (KotlinJsModuleConfigurator) getConfiguratorByName(NAME);
|
KotlinJsModuleConfigurator configurator = (KotlinJsModuleConfigurator) getConfiguratorByName(NAME);
|
||||||
assert configurator != null : "Cannot find configurator with name " + NAME;
|
assert configurator != null : "Cannot find configurator with name " + NAME;
|
||||||
|
|
||||||
return createConfiguration(configurator.getExistingJarFile(), configurator.getExistingSourcesJarFile());
|
RuntimeLibraryFiles files = configurator.getExistingJarFiles();
|
||||||
|
return createConfiguration(files.getRuntimeJar(), files.getRuntimeSourcesJar());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user