Refactor providers
This commit is contained in:
@@ -42,11 +42,12 @@ public class JSLibraryDescription extends CustomLibraryDescription {
|
|||||||
public static final String LIBRARY_NAME = "KotlinJavaScript";
|
public static final String LIBRARY_NAME = "KotlinJavaScript";
|
||||||
|
|
||||||
private static final String JAVA_SCRIPT_LIBRARY_CREATION = "JavaScript Library Creation";
|
private static final String JAVA_SCRIPT_LIBRARY_CREATION = "JavaScript Library Creation";
|
||||||
|
private static final Set<LibraryKind> libraryKinds = Sets.newHashSet(KOTLIN_JAVASCRIPT_KIND);
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public Set<? extends LibraryKind> getSuitableLibraryKinds() {
|
public Set<? extends LibraryKind> getSuitableLibraryKinds() {
|
||||||
return Sets.newHashSet(KOTLIN_JAVASCRIPT_KIND);
|
return libraryKinds;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@@ -55,53 +56,51 @@ public class JSLibraryDescription extends CustomLibraryDescription {
|
|||||||
CreateJavaScriptLibraryDialog dialog = new CreateJavaScriptLibraryDialog(null, "Create Kotlin JavaScript Library", contextDirectory);
|
CreateJavaScriptLibraryDialog dialog = new CreateJavaScriptLibraryDialog(null, "Create Kotlin JavaScript Library", contextDirectory);
|
||||||
dialog.show();
|
dialog.show();
|
||||||
|
|
||||||
if (dialog.isOK()) {
|
if (!dialog.isOK()) return null;
|
||||||
KotlinPaths paths = PathUtil.getKotlinPathsForIdeaPlugin();
|
|
||||||
|
|
||||||
File libraryFile = paths.getJsLibJarPath();
|
KotlinPaths paths = PathUtil.getKotlinPathsForIdeaPlugin();
|
||||||
if (!libraryFile.exists()) {
|
|
||||||
Messages.showErrorDialog(String.format("JavaScript standard library was not found in %s", paths.getLibPath()),
|
File libraryFile = paths.getJsLibJarPath();
|
||||||
JAVA_SCRIPT_LIBRARY_CREATION);
|
if (!libraryFile.exists()) {
|
||||||
|
Messages.showErrorDialog(String.format("JavaScript standard library was not found in %s", paths.getLibPath()),
|
||||||
|
JAVA_SCRIPT_LIBRARY_CREATION);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<File, String> copyToPaths = new HashMap<File, String>();
|
||||||
|
if (dialog.isCopyLibraryFiles()) {
|
||||||
|
String copyIntoPath = dialog.getCopyLibraryIntoPath();
|
||||||
|
assert copyIntoPath != null;
|
||||||
|
|
||||||
|
copyToPaths.put(libraryFile, copyIntoPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dialog.isCopyJS()) {
|
||||||
|
String copyIntoPath = dialog.getCopyJsIntoPath();
|
||||||
|
assert copyIntoPath != null;
|
||||||
|
|
||||||
|
copyToPaths.put(paths.getJsLibJsPath(), copyIntoPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!copyToPaths.isEmpty()) {
|
||||||
|
Map<File,File> copiedFiles =
|
||||||
|
FileUIUtils.copyWithOverwriteDialog(parentComponent, JAVA_SCRIPT_LIBRARY_CREATION, copyToPaths);
|
||||||
|
if (copiedFiles == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<File, String> copyToPaths = new HashMap<File, String>();
|
|
||||||
if (dialog.isCopyLibraryFiles()) {
|
if (dialog.isCopyLibraryFiles()) {
|
||||||
String copyIntoPath = dialog.getCopyLibraryIntoPath();
|
libraryFile = copiedFiles.get(libraryFile);
|
||||||
assert copyIntoPath != null;
|
|
||||||
|
|
||||||
copyToPaths.put(libraryFile, copyIntoPath);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dialog.isCopyJS()) {
|
|
||||||
String copyIntoPath = dialog.getCopyJsIntoPath();
|
|
||||||
assert copyIntoPath != null;
|
|
||||||
|
|
||||||
copyToPaths.put(paths.getJsLibJsPath(), copyIntoPath);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!copyToPaths.isEmpty()) {
|
|
||||||
Map<File,File> copiedFiles =
|
|
||||||
FileUIUtils.copyWithOverwriteDialog(parentComponent, JAVA_SCRIPT_LIBRARY_CREATION, copyToPaths);
|
|
||||||
if (copiedFiles == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (dialog.isCopyLibraryFiles()) {
|
|
||||||
libraryFile = copiedFiles.get(libraryFile);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
final String libraryFileUrl = VfsUtil.getUrlForLibraryRoot(libraryFile);
|
|
||||||
return new NewLibraryConfiguration(LIBRARY_NAME, getDownloadableLibraryType(), new LibraryVersionProperties()) {
|
|
||||||
@Override
|
|
||||||
public void addRoots(@NotNull LibraryEditor editor) {
|
|
||||||
editor.addRoot(libraryFileUrl, OrderRootType.CLASSES);
|
|
||||||
editor.addRoot(libraryFileUrl, OrderRootType.SOURCES);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
final String libraryFileUrl = VfsUtil.getUrlForLibraryRoot(libraryFile);
|
||||||
|
return new NewLibraryConfiguration(LIBRARY_NAME, getDownloadableLibraryType(), new LibraryVersionProperties()) {
|
||||||
|
@Override
|
||||||
|
public void addRoots(@NotNull LibraryEditor editor) {
|
||||||
|
editor.addRoot(libraryFileUrl, OrderRootType.CLASSES);
|
||||||
|
editor.addRoot(libraryFileUrl, OrderRootType.SOURCES);
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,7 +28,6 @@ import com.intellij.openapi.vfs.VfsUtil;
|
|||||||
import com.intellij.openapi.vfs.VirtualFile;
|
import com.intellij.openapi.vfs.VirtualFile;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.jet.plugin.JetPluginUtil;
|
|
||||||
import org.jetbrains.jet.plugin.framework.ui.CreateJavaLibraryDialog;
|
import org.jetbrains.jet.plugin.framework.ui.CreateJavaLibraryDialog;
|
||||||
import org.jetbrains.jet.plugin.framework.ui.FileUIUtils;
|
import org.jetbrains.jet.plugin.framework.ui.FileUIUtils;
|
||||||
import org.jetbrains.jet.utils.KotlinPaths;
|
import org.jetbrains.jet.utils.KotlinPaths;
|
||||||
@@ -43,11 +42,12 @@ public class JavaRuntimeLibraryDescription extends CustomLibraryDescription {
|
|||||||
public static final String LIBRARY_NAME = "KotlinJavaRuntime";
|
public static final String LIBRARY_NAME = "KotlinJavaRuntime";
|
||||||
|
|
||||||
private static final String JAVA_RUNTIME_LIBRARY_CREATION = "Java Runtime Library Creation";
|
private static final String JAVA_RUNTIME_LIBRARY_CREATION = "Java Runtime Library Creation";
|
||||||
|
private static final Set<LibraryKind> libraryKinds = Sets.newHashSet(KOTLIN_JAVA_RUNTIME_KIND);
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public Set<? extends LibraryKind> getSuitableLibraryKinds() {
|
public Set<? extends LibraryKind> getSuitableLibraryKinds() {
|
||||||
return Sets.newHashSet(KOTLIN_JAVA_RUNTIME_KIND);
|
return libraryKinds;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@@ -56,36 +56,34 @@ public class JavaRuntimeLibraryDescription extends CustomLibraryDescription {
|
|||||||
CreateJavaLibraryDialog dialog = new CreateJavaLibraryDialog(null, "Create Kotlin Java Runtime Library", contextDirectory);
|
CreateJavaLibraryDialog dialog = new CreateJavaLibraryDialog(null, "Create Kotlin Java Runtime Library", contextDirectory);
|
||||||
dialog.show();
|
dialog.show();
|
||||||
|
|
||||||
if (dialog.isOK()) {
|
if (!dialog.isOK()) return null;
|
||||||
KotlinPaths paths = PathUtil.getKotlinPathsForIdeaPlugin();
|
|
||||||
|
|
||||||
File libraryFile = paths.getRuntimePath();
|
KotlinPaths paths = PathUtil.getKotlinPathsForIdeaPlugin();
|
||||||
if (!libraryFile.exists()) {
|
|
||||||
Messages.showErrorDialog(
|
|
||||||
parentComponent,
|
|
||||||
String.format("Java Runtime library was not found in '%s'." , paths.getLibPath()),
|
|
||||||
JAVA_RUNTIME_LIBRARY_CREATION);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
String copyIntoPath = dialog.getCopyIntoPath();
|
File libraryFile = paths.getRuntimePath();
|
||||||
if (copyIntoPath != null) {
|
if (!libraryFile.exists()) {
|
||||||
libraryFile = FileUIUtils.copyWithOverwriteDialog(parentComponent, JAVA_RUNTIME_LIBRARY_CREATION, copyIntoPath, libraryFile);
|
Messages.showErrorDialog(
|
||||||
if (libraryFile == null) {
|
parentComponent,
|
||||||
return null;
|
String.format("Java Runtime library was not found in '%s'." , paths.getLibPath()),
|
||||||
}
|
JAVA_RUNTIME_LIBRARY_CREATION);
|
||||||
}
|
return null;
|
||||||
|
|
||||||
final String libraryFileUrl = VfsUtil.getUrlForLibraryRoot(libraryFile);
|
|
||||||
return new NewLibraryConfiguration(LIBRARY_NAME, getDownloadableLibraryType(), new LibraryVersionProperties()) {
|
|
||||||
@Override
|
|
||||||
public void addRoots(@NotNull LibraryEditor editor) {
|
|
||||||
editor.addRoot(libraryFileUrl, OrderRootType.CLASSES);
|
|
||||||
editor.addRoot(libraryFileUrl + "src", OrderRootType.SOURCES);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
String copyIntoPath = dialog.getCopyIntoPath();
|
||||||
|
if (copyIntoPath != null) {
|
||||||
|
libraryFile = FileUIUtils.copyWithOverwriteDialog(parentComponent, JAVA_RUNTIME_LIBRARY_CREATION, copyIntoPath, libraryFile);
|
||||||
|
if (libraryFile == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
final String libraryFileUrl = VfsUtil.getUrlForLibraryRoot(libraryFile);
|
||||||
|
return new NewLibraryConfiguration(LIBRARY_NAME, getDownloadableLibraryType(), new LibraryVersionProperties()) {
|
||||||
|
@Override
|
||||||
|
public void addRoots(@NotNull LibraryEditor editor) {
|
||||||
|
editor.addRoot(libraryFileUrl, OrderRootType.CLASSES);
|
||||||
|
editor.addRoot(libraryFileUrl + "src", OrderRootType.SOURCES);
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user