IDEA-116116 New Project Wizard: default folder for jars download is /lib

This commit is contained in:
Dmitry Avdeev
2014-01-27 13:55:28 +04:00
parent 99ec69c831
commit 0f28587094
5 changed files with 45 additions and 43 deletions
@@ -29,6 +29,7 @@ import com.intellij.openapi.roots.ui.configuration.libraryEditor.NewLibraryEdito
import com.intellij.openapi.roots.ui.configuration.projectRoot.LibrariesContainer;
import com.intellij.openapi.roots.ui.configuration.projectRoot.LibrariesContainerFactory;
import com.intellij.openapi.util.Disposer;
import com.intellij.openapi.util.NotNullComputable;
import com.intellij.util.containers.ContainerUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -43,8 +44,8 @@ import java.util.Map;
*/
public class LibraryCompositionSettings implements Disposable {
private final CustomLibraryDescription myLibraryDescription;
@NotNull private final NotNullComputable<String> myPathProvider;
private FrameworkLibraryVersionFilter myVersionFilter;
private String myBaseDirectoryPath;
private final List<? extends FrameworkLibraryVersion> myAllVersions;
private LibrariesContainer.LibraryLevel myNewLibraryLevel;
private NewLibraryEditor myNewLibraryEditor;
@@ -56,13 +57,13 @@ public class LibraryCompositionSettings implements Disposable {
private FrameworkLibraryProvider myLibraryProvider;
public LibraryCompositionSettings(final @NotNull CustomLibraryDescription libraryDescription,
final @NotNull String baseDirectoryPath,
final @NotNull NotNullComputable<String> pathProvider,
@NotNull FrameworkLibraryVersionFilter versionFilter,
final List<? extends FrameworkLibraryVersion> allVersions) {
myLibraryDescription = libraryDescription;
myPathProvider = pathProvider;
myVersionFilter = versionFilter;
myNewLibraryLevel = libraryDescription.getDefaultLevel();
myBaseDirectoryPath = baseDirectoryPath;
myAllVersions = allVersions;
final List<? extends FrameworkLibraryVersion> versions = getCompatibleVersions();
if (!versions.isEmpty()) {
@@ -72,7 +73,7 @@ public class LibraryCompositionSettings implements Disposable {
private LibraryDownloadSettings createDownloadSettings(final FrameworkLibraryVersion version) {
return new LibraryDownloadSettings(version, myLibraryDescription.getDownloadableLibraryType(),
myNewLibraryLevel, getDefaultDownloadPath(myBaseDirectoryPath));
myNewLibraryLevel, getDefaultDownloadPath(getBaseDirectoryPath()));
}
public void setVersionFilter(@NotNull FrameworkLibraryVersionFilter versionFilter) {
@@ -99,7 +100,7 @@ public class LibraryCompositionSettings implements Disposable {
}
private static String getDefaultDownloadPath(@NotNull String baseDirectoryPath) {
return baseDirectoryPath + "/lib";
return baseDirectoryPath.isEmpty() ? "./lib" : baseDirectoryPath + "/lib";
}
public void setDownloadSettings(LibraryDownloadSettings downloadSettings) {
@@ -128,17 +129,7 @@ public class LibraryCompositionSettings implements Disposable {
@NotNull
public String getBaseDirectoryPath() {
return myBaseDirectoryPath;
}
public void changeBaseDirectoryPath(@NotNull String baseDirectoryPath) {
if (!myBaseDirectoryPath.equals(baseDirectoryPath)) {
if (myDownloadSettings != null &&
myDownloadSettings.getDirectoryForDownloadedLibrariesPath().equals(getDefaultDownloadPath(myBaseDirectoryPath))) {
myDownloadSettings.setDirectoryForDownloadedLibrariesPath(getDefaultDownloadPath(baseDirectoryPath));
}
myBaseDirectoryPath = baseDirectoryPath;
}
return myPathProvider.compute();
}
public void setDownloadLibraries(final boolean downloadLibraries) {
@@ -155,7 +146,7 @@ public class LibraryCompositionSettings implements Disposable {
public boolean downloadFiles(final @NotNull JComponent parent) {
if (myDownloadLibraries && myDownloadSettings != null) {
final NewLibraryEditor libraryEditor = myDownloadSettings.download(parent);
final NewLibraryEditor libraryEditor = myDownloadSettings.download(parent, getBaseDirectoryPath());
if (libraryEditor != null) {
myNewLibraryEditor = libraryEditor;
}
@@ -44,7 +44,7 @@ import java.util.Map;
public class LibraryDownloadSettings {
private final FrameworkLibraryVersion myVersion;
private final DownloadableLibraryType myLibraryType;
private String myDirectoryForDownloadedLibrariesPath;
private String myLibrariesPath;
private final String myLibraryName;
private final boolean myDownloadSources;
private final boolean myDownloadJavaDocs;
@@ -59,13 +59,13 @@ public class LibraryDownloadSettings {
}
public LibraryDownloadSettings(@NotNull FrameworkLibraryVersion libraryVersion, @Nullable DownloadableLibraryType libraryType,
@NotNull String directoryForDownloadedLibrariesPath, @NotNull String libraryName,
@NotNull String librariesPath, @NotNull String libraryName,
@NotNull LibrariesContainer.LibraryLevel libraryLevel,
@NotNull List<? extends DownloadableLibraryFileDescription> selectedDownloads,
boolean downloadSources, boolean downloadJavaDocs) {
myVersion = libraryVersion;
myLibraryType = libraryType;
myDirectoryForDownloadedLibrariesPath = directoryForDownloadedLibrariesPath;
myLibrariesPath = librariesPath;
myLibraryName = libraryName;
myDownloadSources = downloadSources;
myDownloadJavaDocs = downloadJavaDocs;
@@ -100,7 +100,7 @@ public class LibraryDownloadSettings {
}
public String getDirectoryForDownloadedLibrariesPath() {
return myDirectoryForDownloadedLibrariesPath;
return myLibrariesPath;
}
public List<? extends DownloadableLibraryFileDescription> getSelectedDownloads() {
@@ -116,12 +116,8 @@ public class LibraryDownloadSettings {
return myLibraryType;
}
public void setDirectoryForDownloadedLibrariesPath(String directoryForDownloadedLibrariesPath) {
myDirectoryForDownloadedLibrariesPath = directoryForDownloadedLibrariesPath;
}
@Nullable
public NewLibraryEditor download(JComponent parent) {
public NewLibraryEditor download(JComponent parent, @Nullable String rootPath) {
final List<DownloadableFileDescription> toDownload = new ArrayList<DownloadableFileDescription>(mySelectedDownloads);
Map<DownloadableFileDescription, OrderRootType> rootTypes = new HashMap<DownloadableFileDescription, OrderRootType>();
for (DownloadableLibraryFileDescription description : mySelectedDownloads) {
@@ -137,10 +133,11 @@ public class LibraryDownloadSettings {
}
}
String path = rootPath != null && myLibrariesPath.startsWith("./") ? rootPath + myLibrariesPath.substring(1) : myLibrariesPath;
List<Pair<VirtualFile,DownloadableFileDescription>> downloaded =
DownloadableFileService.getInstance()
.createDownloader(toDownload, myLibraryName + " Library")
.downloadWithProgress(myDirectoryForDownloadedLibrariesPath, null, parent);
.downloadWithProgress(path, null, parent);
if (downloaded == null) {
return null;
}
@@ -41,6 +41,7 @@ import com.intellij.openapi.roots.ui.configuration.libraryEditor.NewLibraryEdito
import com.intellij.openapi.roots.ui.configuration.projectRoot.LibrariesContainer;
import com.intellij.openapi.util.Comparing;
import com.intellij.openapi.util.Disposer;
import com.intellij.openapi.util.NotNullComputable;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.vfs.LocalFileSystem;
@@ -107,7 +108,22 @@ public class LibraryOptionsPanel implements Disposable {
private RadioButtonEnumModel<Choice> myButtonEnumModel;
public LibraryOptionsPanel(@NotNull final CustomLibraryDescription libraryDescription,
@NotNull final String baseDirectoryPath,
@NotNull final String path,
@NotNull final FrameworkLibraryVersionFilter versionFilter,
@NotNull final LibrariesContainer librariesContainer,
final boolean showDoNotCreateOption) {
this(libraryDescription, new NotNullComputable<String>() {
@NotNull
@Override
public String compute() {
return path;
}
}, versionFilter, librariesContainer, showDoNotCreateOption);
}
public LibraryOptionsPanel(@NotNull final CustomLibraryDescription libraryDescription,
@NotNull final NotNullComputable<String> pathProvider,
@NotNull final FrameworkLibraryVersionFilter versionFilter,
@NotNull final LibrariesContainer librariesContainer,
final boolean showDoNotCreateOption) {
@@ -124,7 +140,7 @@ public class LibraryOptionsPanel implements Disposable {
@Override
public void run() {
if (!myDisposed) {
showSettingsPanel(libraryDescription, baseDirectoryPath, versionFilter, showDoNotCreateOption, versions);
showSettingsPanel(libraryDescription, pathProvider, versionFilter, showDoNotCreateOption, versions);
onVersionChanged(getPresentableVersion());
}
}
@@ -133,7 +149,7 @@ public class LibraryOptionsPanel implements Disposable {
});
}
else {
showSettingsPanel(libraryDescription, baseDirectoryPath, versionFilter, showDoNotCreateOption,
showSettingsPanel(libraryDescription, pathProvider, versionFilter, showDoNotCreateOption,
new ArrayList<FrameworkLibraryVersion>());
}
}
@@ -181,11 +197,11 @@ public class LibraryOptionsPanel implements Disposable {
}
private void showSettingsPanel(CustomLibraryDescription libraryDescription,
String baseDirectoryPath,
NotNullComputable<String> pathProvider,
FrameworkLibraryVersionFilter versionFilter,
boolean showDoNotCreateOption, final List<? extends FrameworkLibraryVersion> versions) {
//todo[nik] create mySettings only in apply() method
mySettings = new LibraryCompositionSettings(libraryDescription, baseDirectoryPath, versionFilter, versions);
mySettings = new LibraryCompositionSettings(libraryDescription, pathProvider, versionFilter, versions);
Disposer.register(this, mySettings);
List<Library> libraries = calculateSuitableLibraries();
@@ -351,13 +367,6 @@ public class LibraryOptionsPanel implements Disposable {
}
}
public void changeBaseDirectoryPath(@NotNull String directoryForLibrariesPath) {
if (mySettings != null) {
mySettings.changeBaseDirectoryPath(directoryForLibrariesPath);
updateState();
}
}
public void setVersionFilter(@NotNull FrameworkLibraryVersionFilter versionFilter) {
if (mySettings != null) {
mySettings.setVersionFilter(versionFilter);
@@ -75,7 +75,7 @@ public class DownloadableLibraryPropertiesEditor extends LibraryPropertiesEditor
pathForDownloaded);
final LibraryDownloadSettings settings = DownloadingOptionsDialog.showDialog(getMainPanel(), initialSettings, versions, false);
if (settings != null) {
final NewLibraryEditor editor = settings.download(getMainPanel());
final NewLibraryEditor editor = settings.download(getMainPanel(), null);
if (editor != null) {
final LibraryEditorBase target = (LibraryEditorBase)myEditorComponent.getLibraryEditor();
target.removeAllRoots();
@@ -31,6 +31,7 @@ import com.intellij.openapi.roots.ui.configuration.libraries.CustomLibraryDescri
import com.intellij.openapi.roots.ui.configuration.projectRoot.LibrariesContainer;
import com.intellij.openapi.ui.VerticalFlowLayout;
import com.intellij.openapi.util.Disposer;
import com.intellij.openapi.util.NotNullComputable;
import com.intellij.ui.IdeBorderFactory;
import com.intellij.ui.SeparatorFactory;
import org.jetbrains.annotations.NotNull;
@@ -97,8 +98,13 @@ public class FrameworkSupportOptionsComponent {
final CustomLibraryDescription description = myConfigurable.createLibraryDescription();
if (description != null) {
myLibraryOptionsPanel = new LibraryOptionsPanel(description, myModel.getBaseDirectoryForLibrariesPath(), createLibraryVersionFilter(),
container, !myConfigurable.isOnlyLibraryAdded()) {
myLibraryOptionsPanel = new LibraryOptionsPanel(description, new NotNullComputable<String>() {
@NotNull
@Override
public String compute() {
return myModel.getBaseDirectoryForLibrariesPath();
}
}, createLibraryVersionFilter(), container, !myConfigurable.isOnlyLibraryAdded()) {
@Override
protected void onVersionChanged(@Nullable String version) {
if (myFrameworkVersionComponent == null) {
@@ -120,7 +126,6 @@ public class FrameworkSupportOptionsComponent {
public void updateLibrariesPanel() {
if (myLibraryOptionsPanel != null) {
myLibraryOptionsPanel.changeBaseDirectoryPath(myModel.getBaseDirectoryForLibrariesPath());
myLibraryOptionsPanel.setVersionFilter(createLibraryVersionFilter());
myLibraryOptionsPanel.setLibraryProvider(myModel.getLibraryProvider());
myLibraryOptionsPanelWrapper.setVisible(myConfigurable.isVisible());