removed deprecated configs and refactored libraries configs [gregory, nicity]

This commit is contained in:
sergey.vasiliev
2010-12-01 17:50:40 +03:00
parent 706f14c37c
commit 51eceffe61
6 changed files with 118 additions and 120 deletions
@@ -16,7 +16,7 @@
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.frameworks.beans.Artifact;
import com.intellij.facet.ui.libraries.FacetLibrariesValidator;
import com.intellij.facet.ui.libraries.FacetLibrariesValidatorDescription;
import com.intellij.facet.ui.libraries.LibraryInfo;
@@ -51,7 +51,7 @@ public abstract class VersionsComponent {
private final Map<String, Pair<JRadioButton, JComboBox>> myButtons = new HashMap<String, Pair<JRadioButton, JComboBox>>();
private Version myCurrentVersion = null;
private Artifact myCurrentVersion = null;
public VersionsComponent(@NotNull final Module module, FacetLibrariesValidator validator) {
myModule = module;
@@ -66,7 +66,7 @@ public abstract class VersionsComponent {
}
@Nullable
public Version getCurrentVersion() {
public Artifact getCurrentVersion() {
return myCurrentVersion;
}
@@ -89,7 +89,7 @@ public abstract class VersionsComponent {
}
if (myCurrentVersion != null) {
Pair<JRadioButton, JComboBox> currentPair = myButtons.get(myCurrentVersion.getRI());
Pair<JRadioButton, JComboBox> currentPair = myButtons.get(myCurrentVersion.getName());
if (currentPair != null) {
currentPair.first.setSelected(true);
currentPair.second.setSelectedItem(myCurrentVersion);
@@ -107,20 +107,20 @@ public abstract class VersionsComponent {
}
@NotNull
protected abstract Version[] getLibraries();
protected abstract Artifact[] getLibraries();
@Nullable
private Version getCurrentVersion(@NotNull String currentRI) {
private Artifact getCurrentVersion(@NotNull String currentRI) {
String detectionClass = getFacetDetectionClass(currentRI);
if (detectionClass != null) {
final String version = JarVersionDetectionUtil.detectJarVersion(detectionClass, myModule);
if (version != null) {
Version approximatedVersion = null;
for (Version info : getLibraries()) {
if (version.equals(info.getId())) {
Artifact approximatedVersion = null;
for (Artifact info : getLibraries()) {
if (version.equals(info.getVersion())) {
return info;
}
if (version.contains(info.getId())) {
if (version.contains(info.getVersion())) {
approximatedVersion = info;
}
}
@@ -131,10 +131,10 @@ public abstract class VersionsComponent {
return null;
}
private List<Version> getSupportedVersions(@NotNull String ri) {
List<Version> versions = new ArrayList<Version>();
for (Version version : getLibraries()) {
if (ri.equals(version.getRI())) {
private List<Artifact> getSupportedVersions(@NotNull String ri) {
List<Artifact> versions = new ArrayList<Artifact>();
for (Artifact version : getLibraries()) {
if (ri.equals(version.getName())) {
versions.add(version);
}
}
@@ -145,7 +145,7 @@ public abstract class VersionsComponent {
private void addSingletonReferenceImplementationUI(@NotNull final String ri) {
JComboBox comboBox = createComboBox(ri);
addToPanel(new JLabel(ri), comboBox);
Version version = getCurrentVersion(ri);
Artifact version = getCurrentVersion(ri);
if (version != null) {
comboBox.setSelectedItem(version);
}
@@ -180,7 +180,7 @@ public abstract class VersionsComponent {
JComboBox comboBox = pair.second;
comboBox.setEnabled(true);
Version currentVersion = getCurrentVersion(ri);
Artifact currentVersion = getCurrentVersion(ri);
if (currentVersion != null) {
comboBox.setSelectedItem(currentVersion);
}
@@ -205,7 +205,7 @@ public abstract class VersionsComponent {
private JComboBox createComboBox(String ri) {
final JComboBox comboBox = new JComboBox();
List<Version> versions = getSupportedVersions(ri);
List<Artifact> versions = getSupportedVersions(ri);
comboBox.setModel(new CollectionComboBoxModel(versions, null));
comboBox.addActionListener(new ActionListener() {
@@ -218,7 +218,7 @@ public abstract class VersionsComponent {
}
private void updateCurrentVersion(JComboBox comboBox) {
final Version versionInfo = getSelectedVersion(comboBox);
final Artifact versionInfo = getSelectedVersion(comboBox);
if (versionInfo != null) {
myCurrentVersion = versionInfo;
@@ -227,13 +227,13 @@ public abstract class VersionsComponent {
}
}
protected FacetLibrariesValidatorDescription getFacetLibrariesValidatorDescription(Version version) {
return new FacetLibrariesValidatorDescription(version.getId()) {
protected FacetLibrariesValidatorDescription getFacetLibrariesValidatorDescription(Artifact version) {
return new FacetLibrariesValidatorDescription(version.getVersion()) {
@NonNls
public String getDefaultLibraryName() {
if (myCurrentVersion != null) {
String ri = myCurrentVersion.getRI();
String version = myCurrentVersion.getId();
String ri = myCurrentVersion.getName();
String version = myCurrentVersion.getVersion();
return StringUtil.isEmptyOrSpaces(ri) ? version : ri + "." + version;
}
@@ -244,20 +244,20 @@ public abstract class VersionsComponent {
}
@Nullable
private static Version getAppropriateVersion(List<Version> versions) {
private static Artifact getAppropriateVersion(List<Artifact> versions) {
return versions.size() > 0 ? versions.get(0) : null;
}
private static LibraryInfo[] getRequiredLibraries(Version version) {
private static LibraryInfo[] getRequiredLibraries(Artifact version) {
final LibraryInfo[] infos = LibrariesDownloadAssistant.getLibraryInfos(version);
return infos == null ? LibraryInfo.EMPTY_ARRAY : infos;
}
@Nullable
private static Version getSelectedVersion(@NotNull JComboBox comboBox) {
private static Artifact getSelectedVersion(@NotNull JComboBox comboBox) {
final Object version = comboBox.getModel().getSelectedItem();
return version instanceof Version ? (Version)version : null;
return version instanceof Artifact ? (Artifact)version : null;
}
@@ -272,8 +272,8 @@ public abstract class VersionsComponent {
public Set<String> getRIs() {
Set<String> ris = new HashSet<String>();
for (Version version : getLibraries()) {
String ri = version.getRI();
for (Artifact version : getLibraries()) {
String ri = version.getName();
if (!StringUtil.isEmptyOrSpaces(ri)) {
ris.add(ri);
}
@@ -1,9 +1,9 @@
package com.intellij.facet.frameworks;
import com.intellij.facet.frameworks.actions.GetVersionInfoAction;
import com.intellij.facet.frameworks.beans.DownloadJar;
import com.intellij.facet.frameworks.beans.Version;
import com.intellij.facet.frameworks.beans.Versions;
import com.intellij.facet.frameworks.beans.Artifact;
import com.intellij.facet.frameworks.beans.ArtifactItem;
import com.intellij.facet.frameworks.beans.Artifacts;
import com.intellij.facet.ui.libraries.LibraryInfo;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.util.Condition;
@@ -19,9 +19,7 @@ import org.jetbrains.annotations.Nullable;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Arrays;
import java.util.List;
import java.util.Set;
import java.util.*;
public class LibrariesDownloadAssistant {
private static final Logger LOG = Logger.getInstance("#com.intellij.LibrariesDownloadAssistant");
@@ -30,17 +28,17 @@ public class LibrariesDownloadAssistant {
}
@Nullable
public static Version[] getVersions(@NotNull String groupId, @NotNull URL... localUrls) {
final Version[] versions = getDownloadServiceVersions(groupId);
public static Artifact[] getVersions(@NotNull String groupId, @NotNull URL... localUrls) {
final Artifact[] versions = getDownloadServiceVersions(groupId);
return versions == null ? getVersions(localUrls) : versions;
}
@Nullable
public static Version[] getDownloadServiceVersions(@NotNull String id) {
public static Artifact[] getDownloadServiceVersions(@NotNull String id) {
final URL url = createVersionsUrl(id);
if (url == null) return null;
final Versions allVersions = deserialize(url);
return allVersions == null ? null : allVersions.getVersions();
final Artifacts allArtifacts = deserialize(url);
return allArtifacts == null ? null : allArtifacts.getArtifacts();
}
@Nullable
@@ -59,28 +57,28 @@ public class LibrariesDownloadAssistant {
}
@NotNull
public static Version[] getVersions(@NotNull URL... urls) {
Set<Version> versions = new HashSet<Version>();
public static Artifact[] getVersions(@NotNull URL... urls) {
Set<Artifact> versions = new HashSet<Artifact>();
for (URL url : urls) {
final Versions allVersions = deserialize(url);
if (allVersions != null) {
final Version[] vers = allVersions.getVersions();
final Artifacts allArtifacts = deserialize(url);
if (allArtifacts != null) {
final Artifact[] vers = allArtifacts.getArtifacts();
if (vers != null) {
versions.addAll(Arrays.asList(vers));
}
}
}
return versions.toArray(new Version[versions.size()]);
return versions.toArray(new Artifact[versions.size()]);
}
@Nullable
private static Versions deserialize(@Nullable URL url) {
private static Artifacts deserialize(@Nullable URL url) {
if (url == null) return null;
Versions allVersions = null;
Artifacts allArtifacts = null;
try {
allVersions = XmlSerializer.deserialize(url, Versions.class);
allArtifacts = XmlSerializer.deserialize(url, Artifacts.class);
}
catch (XmlSerializationException e) {
final Throwable cause = e.getCause();
@@ -88,19 +86,19 @@ public class LibrariesDownloadAssistant {
LOG.error(e);
}
}
return allVersions;
return allArtifacts;
}
@Nullable
public static Version getVersion(@NotNull String id, @NotNull String versionId) {
public static Artifact getVersion(@NotNull String id, @NotNull String versionId) {
final URL url = GetVersionInfoAction.create(id, versionId).getUrl();
if (url == null) return null;
final Versions allVersions = XmlSerializer.deserialize(url, Versions.class);
final Artifacts allArtifacts = XmlSerializer.deserialize(url, Artifacts.class);
if (allVersions == null) return null;
if (allArtifacts == null) return null;
final Version[] versions = allVersions.getVersions();
final Artifact[] versions = allArtifacts.getArtifacts();
assert versions.length == 1;
@@ -108,46 +106,46 @@ public class LibrariesDownloadAssistant {
}
@Nullable
public static Version findVersion(@NotNull final String versionId, @NotNull final URL... urls) {
public static Artifact findVersion(@NotNull final String versionId, @NotNull final URL... urls) {
return findVersion(getVersions(urls), versionId);
}
@Nullable
public static Version findVersion(@NotNull final String groupId, @NotNull final String versionId) {
public static Artifact findVersion(@NotNull final String groupId, @NotNull final String versionId) {
return findVersion(getVersions(groupId), versionId);
}
@Nullable
public static Version findVersion(@Nullable Version[] versions, @NotNull final String versionId) {
return versions == null ? null : ContainerUtil.find(versions, new Condition<Version>() {
public boolean value(final Version springVersion) {
return versionId.equals(springVersion.getId());
public static Artifact findVersion(@Nullable Artifact[] versions, @NotNull final String versionId) {
return versions == null ? null : ContainerUtil.find(versions, new Condition<Artifact>() {
public boolean value(final Artifact springVersion) {
return versionId.equals(springVersion.getVersion());
}
});
}
@NotNull
public static LibraryInfo[] getLibraryInfos(@NotNull final URL url, @NotNull final String versionId) {
final Version version = findVersion(getVersions(url), versionId);
final Artifact version = findVersion(getVersions(url), versionId);
return version != null ? getLibraryInfos(version) : LibraryInfo.EMPTY_ARRAY;
}
@NotNull
public static LibraryInfo[] getLibraryInfos(@Nullable Version version) {
public static LibraryInfo[] getLibraryInfos(@Nullable Artifact version) {
if (version == null) return LibraryInfo.EMPTY_ARRAY;
final List<LibraryInfo> infos = convert(version.getJars());
final List<LibraryInfo> infos = convert(version.getItems());
return infos.toArray(new LibraryInfo[infos.size()]);
}
@NotNull
public static List<LibraryInfo> convert(@NotNull DownloadJar[] jars) {
return ContainerUtil.mapNotNull(jars, new Function<DownloadJar, LibraryInfo>() {
public static List<LibraryInfo> convert(@NotNull ArtifactItem[] jars) {
return ContainerUtil.mapNotNull(jars, new Function<ArtifactItem, LibraryInfo>() {
@Override
public LibraryInfo fun(DownloadJar downloadJar) {
final String downloadUrl = downloadJar.getDownloadUrl();
return new LibraryInfo(downloadJar.getName(), downloadUrl, downloadUrl, downloadJar.getMD5(), downloadJar.getRequiredClasses());
public LibraryInfo fun(ArtifactItem artifactItem) {
final String downloadUrl = artifactItem.getUrl();
return new LibraryInfo(artifactItem.getName(), downloadUrl, downloadUrl, artifactItem.getMD5(), artifactItem.getRequiredClasses());
}
});
}
@@ -0,0 +1,45 @@
package com.intellij.facet.frameworks.beans;
import com.intellij.util.xmlb.annotations.AbstractCollection;
import com.intellij.util.xmlb.annotations.Attribute;
import com.intellij.util.xmlb.annotations.Property;
import com.intellij.util.xmlb.annotations.Tag;
@Tag("artifact")
public class Artifact {
public static final Artifact[] EMPTY_ARRAY = new Artifact[0];
@Property(surroundWithTag = false)
@AbstractCollection(surroundWithTag = false)
public ArtifactItem[] myItems;
@Attribute("version")
public String myVersion;
@Attribute("name")
public String myName;
@Attribute("group")
public String myGroup;
public String getName() {
return myName;
}
public String getGroup() {
return myGroup;
}
public ArtifactItem[] getItems() {
return myItems;
}
public String getVersion() {
return myVersion;
}
@Override
public String toString() {
return myVersion;
}
}
@@ -25,8 +25,8 @@ import com.intellij.util.xmlb.annotations.Tag;
import java.util.List;
@Tag("jar")
public class DownloadJar {
@Tag("item")
public class ArtifactItem {
@Property(surroundWithTag = false)
@AbstractCollection(surroundWithTag = false)
@@ -36,10 +36,7 @@ public class DownloadJar {
public String myName;
@Attribute("url")
public String myDownloadUrl;
@Attribute("presentation")
public String myPresentation;
public String myUrl;
@Attribute("md5")
public String myMD5;
@@ -48,12 +45,8 @@ public class DownloadJar {
return myName;
}
public String getDownloadUrl() {
return myDownloadUrl;
}
public String getPresentation() {
return myPresentation;
public String getUrl() {
return myUrl;
}
public String getMD5() {
@@ -3,13 +3,13 @@ package com.intellij.facet.frameworks.beans;
import com.intellij.util.xmlb.annotations.AbstractCollection;
import com.intellij.util.xmlb.annotations.Property;
public class Versions {
public class Artifacts {
@Property(surroundWithTag = false)
@AbstractCollection(surroundWithTag = false)
public Version[] myVersions;
public Artifact[] myVersions;
public Version[] getVersions() {
public Artifact[] getArtifacts() {
return myVersions;
}
}
@@ -1,38 +0,0 @@
package com.intellij.facet.frameworks.beans;
import com.intellij.util.xmlb.annotations.AbstractCollection;
import com.intellij.util.xmlb.annotations.Attribute;
import com.intellij.util.xmlb.annotations.Property;
import com.intellij.util.xmlb.annotations.Tag;
@Tag("version")
public class Version {
public static final Version[] EMPTY_ARRAY = new Version[0];
@Property(surroundWithTag = false)
@AbstractCollection(surroundWithTag = false)
public DownloadJar[] myJars;
@Attribute("id")
public String myId;
@Attribute("ri")
public String myRI; // optional attribute "reference implementation"
public String getRI() {
return myRI;
}
public DownloadJar[] getJars() {
return myJars;
}
public String getId() {
return myId;
}
@Override
public String toString() {
return myId;
}
}