refactored framework libraries support

This commit is contained in:
sergey.vasiliev
2010-09-14 16:11:04 +04:00
parent 1e6cf1a001
commit 82b5f8971f
16 changed files with 316 additions and 382 deletions
@@ -52,7 +52,7 @@ public class DownloadingOptionsDialog extends DialogWrapper {
myFilesList.setModel(new CollectionListModel(ContainerUtil.map2Array(settings.getLibraryInfos(), new Function<LibraryInfo, Object>() {
@Override
public Object fun(LibraryInfo libraryInfo) {
return new JCheckBox(libraryInfo.getPresentableName(), libraryInfo.isSelected());
return new JCheckBox(libraryInfo.getName(), libraryInfo.isSelected());
}
})));
myFilesToDownloadLabel.setLabelFor(myFilesList);
@@ -73,7 +73,7 @@ public class RequiredLibrariesInfo {
missedJarsText.append(", ");
}
missedJarsText.append(libraryInfos[i].getPresentableName());
missedJarsText.append(libraryInfos[i].getName());
}
return missedJarsText.toString();
}
@@ -1,59 +0,0 @@
/*
* Copyright 2000-2009 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 com.intellij.facet.impl.ui.libraries.versions;
import com.intellij.util.xmlb.annotations.AbstractCollection;
import com.intellij.util.xmlb.annotations.Attribute;
import com.intellij.util.xmlb.annotations.Property;
public class LibrariesConfigurationInfo {
@Property(surroundWithTag = false)
@AbstractCollection(surroundWithTag = false)
public LibraryConfigurationInfo[] myInfos;
@Attribute("default-version")
public String myDefaultVersion;
@Attribute("default-ri")
public String myDefaultRI;
@Attribute("default-download-url")
public String myDefaultDownloadUrl;
@Attribute("default-presentation-url")
public String myDefaultPresentationUrl;
public LibraryConfigurationInfo[] getLibraryConfigurationInfos() {
return myInfos;
}
public String getDefaultVersion() {
return myDefaultVersion;
}
public String getDefaultDownloadUrl() {
return myDefaultDownloadUrl;
}
public String getDefaultPresentationUrl() {
return myDefaultPresentationUrl;
}
public String getDefaultRI() {
return myDefaultRI;
}
}
@@ -1,123 +0,0 @@
/*
* Copyright 2000-2009 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 com.intellij.facet.impl.ui.libraries.versions;
import com.intellij.facet.ui.libraries.LibraryInfo;
import com.intellij.openapi.Disposable;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.util.ArrayUtil;
import com.intellij.util.containers.HashMap;
import com.intellij.util.xmlb.XmlSerializer;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
public class LibrariesConfigurationManager implements Disposable {
private static final String STRING_DELIMITER = ",";
private static final String RI_TEMPLATE = "$RI$";
private static final String VERSION_TEMPLATE = "$VERSION$";
@NotNull
public static Map<LibraryVersionInfo, List<LibraryInfo>> getLibraries(final URL... urls) {
final Map<LibraryVersionInfo, List<LibraryInfo>> versionLibs = new HashMap<LibraryVersionInfo, List<LibraryInfo>>();
for (URL url : urls) {
final LibrariesConfigurationInfo libs = XmlSerializer.deserialize(url, LibrariesConfigurationInfo.class);
assert libs != null;
assert libs.getLibraryConfigurationInfos() != null;
final String defaultVersion = libs.getDefaultVersion();
final String defaultRI = libs.getDefaultRI();
final String defaultDownloadUrl = libs.getDefaultDownloadUrl();
final String defaultPresentationUrl = libs.getDefaultPresentationUrl();
for (LibraryConfigurationInfo libInfo : libs.getLibraryConfigurationInfos()) {
String[] libInfoVersions = getSplitted(libInfo.getVersion());
if (libInfoVersions.length == 0) {
addVersionLibrary(null, versionLibs, defaultVersion, defaultRI, defaultDownloadUrl, defaultPresentationUrl, libInfo);
} else {
for (String infoVersion : libInfoVersions) {
addVersionLibrary(infoVersion.trim(), versionLibs, defaultVersion, defaultRI, defaultDownloadUrl, defaultPresentationUrl, libInfo);
}
}
}
}
return versionLibs;
}
private static void addVersionLibrary(@Nullable String infoVersion,
Map<LibraryVersionInfo, List<LibraryInfo>> versionLibs,
String defaultVersion,
String defaultRI,
String defaultDownloadUrl,
String defaultPresentationUrl,
LibraryConfigurationInfo libInfo) {
final String version = choose(infoVersion, defaultVersion);
assert !StringUtil.isEmptyOrSpaces(version);
final String ri = choose(libInfo.getRI(), defaultRI);
final String downloadUrl = choose(libInfo.getDownloadUrl(), defaultDownloadUrl);
final String presentationdUrl = choose(libInfo.getPresentationdUrl(), defaultPresentationUrl);
final LibraryVersionInfo versionInfo = new LibraryVersionInfo(version, ri);
final LibraryInfo info = createLibraryInfo(downloadUrl, presentationdUrl, version, ri, libInfo);
if (versionLibs.get(versionInfo) == null) versionLibs.put(versionInfo, new ArrayList<LibraryInfo>());
versionLibs.get(versionInfo).add(info);
}
@Nullable
private static String choose(@Nullable String str, @Nullable String defaultStr) {
return StringUtil.isEmptyOrSpaces(str) ? defaultStr : str;
}
private static LibraryInfo createLibraryInfo(String downloadUrl,
String presentationdUrl,
String version,
String ri,
LibraryConfigurationInfo libInfo) {
downloadUrl = downloadUrl.replace(VERSION_TEMPLATE, version);
if (ri != null) {
downloadUrl = downloadUrl.replace(RI_TEMPLATE, ri);
}
String jarName = libInfo.getJarName();
String jarVersion = libInfo.getJarVersion();
return new LibraryInfo(jarName, jarVersion == null ? version : jarVersion, downloadUrl + jarName, presentationdUrl, getSplitted(libInfo.getRequiredClasses()));
}
private static String[] getSplitted(@Nullable final String s) {
if (StringUtil.isEmptyOrSpaces(s)) return ArrayUtil.EMPTY_STRING_ARRAY;
return ArrayUtil.toStringArray(StringUtil.split(s, STRING_DELIMITER));
}
public void dispose() {
}
}
@@ -1,73 +0,0 @@
/*
* Copyright 2000-2009 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 com.intellij.facet.impl.ui.libraries.versions;
import com.intellij.util.xmlb.annotations.Attribute;
import com.intellij.util.xmlb.annotations.Tag;
@Tag("lib")
public class LibraryConfigurationInfo {
@Attribute("ri")
public String myRI;
@Attribute("jar-name")
public String myJarName;
@Attribute("version")
public String myVersion;
@Attribute("download-url")
public String myDownloadUrl;
@Attribute("presentation-url")
public String myPresentationdUrl;
@Attribute("required-classes")
public String myRequiredClasses;
@Attribute("jar-version")
public String myJarVersion;
public String getRI() {
return myRI;
}
public String getJarName() {
return myJarName;
}
public String getVersion() {
return myVersion;
}
public String getDownloadUrl() {
return myDownloadUrl;
}
public String getPresentationdUrl() {
return myPresentationdUrl;
}
public String getRequiredClasses() {
return myRequiredClasses;
}
public String getJarVersion() {
return myJarVersion;
}
}
@@ -1,77 +0,0 @@
/*
* Copyright 2000-2009 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 com.intellij.facet.impl.ui.libraries.versions;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.NotNull;
public class LibraryVersionInfo {
@NotNull private String myVersion;
@Nullable private String myRI;
public LibraryVersionInfo(@NotNull String version) {
myVersion = version;
}
public LibraryVersionInfo(@NotNull String version, @Nullable String RI) {
myVersion = version;
myRI = RI;
}
@NotNull
public String getVersion() {
return myVersion;
}
public void setVersion(@NotNull String version) {
myVersion = version;
}
@Nullable
public String getRI() {
return myRI;
}
public void setRI(@Nullable String RI) {
myRI = RI;
}
@Override
public String toString() {
return myVersion;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
LibraryVersionInfo that = (LibraryVersionInfo)o;
if (myRI != null ? !myRI.equals(that.myRI) : that.myRI != null) return false;
if (!myVersion.equals(that.myVersion)) return false;
return true;
}
@Override
public int hashCode() {
int result = myVersion.hashCode();
result = 31 * result + (myRI != null ? myRI.hashCode() : 0);
return result;
}
}
@@ -15,6 +15,8 @@
*/
package com.intellij.facet.impl.ui.libraries.versions;
import com.intellij.facet.frameworks.LibrariesDownloadAssistant;
import com.intellij.facet.frameworks.beans.Version;
import com.intellij.facet.ui.libraries.FacetLibrariesValidator;
import com.intellij.facet.ui.libraries.FacetLibrariesValidatorDescription;
import com.intellij.facet.ui.libraries.LibraryInfo;
@@ -49,7 +51,7 @@ public abstract class VersionsComponent {
private final Map<String, Pair<JRadioButton, JComboBox>> myButtons = new HashMap<String, Pair<JRadioButton, JComboBox>>();
private LibraryVersionInfo myCurrentVersion = null;
private Version myCurrentVersion = null;
public VersionsComponent(@NotNull final Module module, FacetLibrariesValidator validator) {
myModule = module;
@@ -64,7 +66,7 @@ public abstract class VersionsComponent {
}
@Nullable
public LibraryVersionInfo getCurrentLibraryVersionInfo() {
public Version getCurrentVersion() {
return myCurrentVersion;
}
@@ -105,20 +107,20 @@ public abstract class VersionsComponent {
}
@NotNull
protected abstract Map<LibraryVersionInfo, List<LibraryInfo>> getLibraries();
protected abstract Version[] getLibraries();
@Nullable
private LibraryVersionInfo getCurrentVersion(@NotNull String currentRI) {
private Version getCurrentVersion(@NotNull String currentRI) {
String detectionClass = getFacetDetectionClass(currentRI);
if (detectionClass != null) {
final String version = JarVersionDetectionUtil.detectJarVersion(detectionClass, myModule);
if (version != null) {
LibraryVersionInfo approximatedVersion = null;
for (LibraryVersionInfo info : getLibraries().keySet()) {
if (version.equals(info.getVersion())) {
Version approximatedVersion = null;
for (Version info : getLibraries()) {
if (version.equals(info.getId())) {
return info;
}
if (version.contains(info.getVersion())) {
if (version.contains(info.getId())) {
approximatedVersion = info;
}
}
@@ -129,11 +131,11 @@ public abstract class VersionsComponent {
return null;
}
private List<LibraryVersionInfo> getSupportedVersions(@NotNull String ri) {
List<LibraryVersionInfo> versions = new ArrayList<LibraryVersionInfo>();
for (Map.Entry<LibraryVersionInfo, List<LibraryInfo>> entry : getLibraries().entrySet()) {
if (ri.equals(entry.getKey().getRI())) {
versions.add(entry.getKey());
private List<Version> getSupportedVersions(@NotNull String ri) {
List<Version> versions = new ArrayList<Version>();
for (Version version : getLibraries()) {
if (ri.equals(version.getRI())) {
versions.add(version);
}
}
@@ -143,7 +145,7 @@ public abstract class VersionsComponent {
private void addSingletonReferenceImplementationUI(@NotNull final String ri) {
JComboBox comboBox = createComboBox(ri);
addToPanel(new JLabel(ri), comboBox);
LibraryVersionInfo version = getCurrentVersion(ri);
Version version = getCurrentVersion(ri);
if (version != null) {
comboBox.setSelectedItem(version);
}
@@ -178,7 +180,7 @@ public abstract class VersionsComponent {
JComboBox comboBox = pair.second;
comboBox.setEnabled(true);
LibraryVersionInfo currentVersion = getCurrentVersion(ri);
Version currentVersion = getCurrentVersion(ri);
if (currentVersion != null) {
comboBox.setSelectedItem(currentVersion);
}
@@ -203,7 +205,7 @@ public abstract class VersionsComponent {
private JComboBox createComboBox(String ri) {
final JComboBox comboBox = new JComboBox();
List<LibraryVersionInfo> versions = getSupportedVersions(ri);
List<Version> versions = getSupportedVersions(ri);
comboBox.setModel(new CollectionComboBoxModel(versions, null));
comboBox.addActionListener(new ActionListener() {
@@ -216,7 +218,7 @@ public abstract class VersionsComponent {
}
private void updateCurrentVersion(JComboBox comboBox) {
final LibraryVersionInfo versionInfo = getSelectedVersion(comboBox);
final Version versionInfo = getSelectedVersion(comboBox);
if (versionInfo != null) {
myCurrentVersion = versionInfo;
@@ -225,13 +227,13 @@ public abstract class VersionsComponent {
}
}
protected FacetLibrariesValidatorDescription getFacetLibrariesValidatorDescription(LibraryVersionInfo versionInfo) {
return new FacetLibrariesValidatorDescription(versionInfo.getVersion()) {
protected FacetLibrariesValidatorDescription getFacetLibrariesValidatorDescription(Version version) {
return new FacetLibrariesValidatorDescription(version.getId()) {
@NonNls
public String getDefaultLibraryName() {
if (myCurrentVersion != null) {
String ri = myCurrentVersion.getRI();
String version = myCurrentVersion.getVersion();
String version = myCurrentVersion.getId();
return StringUtil.isEmptyOrSpaces(ri) ? version : ri + "." + version;
}
@@ -242,19 +244,20 @@ public abstract class VersionsComponent {
}
@Nullable
private static LibraryVersionInfo getAppropriateVersion(List<LibraryVersionInfo> versions) {
private static Version getAppropriateVersion(List<Version> versions) {
return versions.size() > 0 ? versions.get(0) : null;
}
private LibraryInfo[] getRequiredLibraries(LibraryVersionInfo versionInfo) {
List<LibraryInfo> libraryInfos = getLibraries().get(versionInfo);
return libraryInfos.toArray(new LibraryInfo[libraryInfos.size()]);
private static LibraryInfo[] getRequiredLibraries(Version version) {
final LibraryInfo[] infos = LibrariesDownloadAssistant.getLibraryInfos(version);
return infos == null ? LibraryInfo.EMPTY_ARRAY : infos;
}
@Nullable
private static LibraryVersionInfo getSelectedVersion(@NotNull JComboBox comboBox) {
private static Version getSelectedVersion(@NotNull JComboBox comboBox) {
final Object version = comboBox.getModel().getSelectedItem();
return version instanceof LibraryVersionInfo ? (LibraryVersionInfo)version : null;
return version instanceof Version ? (Version)version : null;
}
@@ -269,8 +272,8 @@ public abstract class VersionsComponent {
public Set<String> getRIs() {
Set<String> ris = new HashSet<String>();
for (LibraryVersionInfo info : getLibraries().keySet()) {
String ri = info.getRI();
for (Version version : getLibraries()) {
String ri = version.getRI();
if (!StringUtil.isEmptyOrSpaces(ri)) {
ris.add(ri);
}
@@ -60,10 +60,10 @@ public class ModuleProjectStructureElement extends ProjectStructureElement {
// final LibraryEx library = (LibraryEx)((LibraryOrderEntry)entry).getLibrary();
// if (library != null) {
// if (!library.allPathsValid(OrderRootType.CLASSES)) {
// problemsHolder.registerError(ProjectBundle.message("project.roots.tooltip.library.misconfigured", entry.getPresentableName()));
// problemsHolder.registerError(ProjectBundle.message("project.roots.tooltip.library.misconfigured", entry.getName()));
// }
// else if (!library.allPathsValid(OrderRootType.SOURCES)) {
// problemsHolder.registerWarning(ProjectBundle.message("project.roots.tooltip.library.misconfigured", entry.getPresentableName()));
// problemsHolder.registerWarning(ProjectBundle.message("project.roots.tooltip.library.misconfigured", entry.getName()));
// }
// }
//}