mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
refactored framework libraries support
This commit is contained in:
+1
-1
@@ -60,7 +60,7 @@ public class CompilerPerfTestAction extends AnAction {
|
||||
}
|
||||
final long finish = System.currentTimeMillis();
|
||||
//System.out.println("Compiled with " +
|
||||
// compiler.getPresentableName() +
|
||||
// compiler.getName() +
|
||||
// " in " +
|
||||
// TimeUnit.MILLISECONDS.toMinutes(finish - start) + "m" +TimeUnit.MILLISECONDS.toSeconds((finish - start)%60000) + "s" +
|
||||
// " with " +
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
-59
@@ -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;
|
||||
}
|
||||
}
|
||||
-123
@@ -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() {
|
||||
|
||||
}
|
||||
}
|
||||
-73
@@ -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;
|
||||
}
|
||||
}
|
||||
-77
@@ -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;
|
||||
}
|
||||
}
|
||||
+31
-28
@@ -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);
|
||||
}
|
||||
|
||||
+2
-2
@@ -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()));
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
|
||||
@@ -0,0 +1,96 @@
|
||||
package com.intellij.facet.frameworks;
|
||||
|
||||
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.ui.libraries.LibraryInfo;
|
||||
import com.intellij.openapi.util.Condition;
|
||||
import com.intellij.util.Function;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.util.containers.HashSet;
|
||||
import com.intellij.util.xmlb.XmlSerializer;
|
||||
import org.jdom.Element;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.net.URL;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class LibrariesDownloadAssistant {
|
||||
|
||||
private LibrariesDownloadAssistant() {
|
||||
}
|
||||
|
||||
// for local files
|
||||
@NotNull
|
||||
public static Version[] getVersions(@NotNull URL... urls) {
|
||||
Set<Version> versions = new HashSet<Version>();
|
||||
for (URL url : urls) {
|
||||
final Versions allVersions = XmlSerializer.deserialize(url, Versions.class);
|
||||
if (allVersions != null) {
|
||||
final Version[] vers = allVersions.getVersions();
|
||||
if (vers != null) {
|
||||
versions.addAll(Arrays.asList(vers));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return versions.toArray(new Version[versions.size()]);
|
||||
}
|
||||
|
||||
// todo: will be connect to server
|
||||
@Nullable
|
||||
public static Version[] getVersions(@NotNull String groupId) {
|
||||
final Versions allVersions =
|
||||
XmlSerializer.deserialize(getRoot(groupId), Versions.class);
|
||||
|
||||
return allVersions == null ? null : allVersions.getVersions();
|
||||
}
|
||||
|
||||
private static Element getRoot(@NotNull final String groupId) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@Nullable
|
||||
public static Version 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) {
|
||||
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());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static LibraryInfo[] getLibraryInfos(@NotNull final URL url, @NotNull final String versionId) {
|
||||
final Version version = findVersion(getVersions(url), versionId);
|
||||
return version != null ? getLibraryInfos(version) :LibraryInfo.EMPTY_ARRAY;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static LibraryInfo[] getLibraryInfos(@Nullable Version version) {
|
||||
if (version == null) return LibraryInfo.EMPTY_ARRAY;
|
||||
|
||||
final List<LibraryInfo> infos = ContainerUtil.mapNotNull(version.getJars(), new Function<DownloadJar, LibraryInfo>() {
|
||||
@Override
|
||||
public LibraryInfo fun(DownloadJar downloadJar) {
|
||||
final String downloadUrl = downloadJar.getDownloadUrl();
|
||||
return new LibraryInfo(downloadJar.getName(), downloadUrl, downloadUrl, downloadJar.getRequiredClasses());
|
||||
}
|
||||
});
|
||||
|
||||
return infos.toArray(new LibraryInfo[infos.size()]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
* Copyright 2000-2010 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.frameworks.beans;
|
||||
|
||||
import com.intellij.util.Function;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
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;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Tag("jar")
|
||||
public class DownloadJar {
|
||||
|
||||
@Property(surroundWithTag = false)
|
||||
@AbstractCollection(surroundWithTag = false)
|
||||
public RequiredClass[] myRequiredClasses;
|
||||
|
||||
@Attribute("name")
|
||||
public String myName;
|
||||
|
||||
@Attribute("url")
|
||||
public String myDownloadUrl;
|
||||
|
||||
@Attribute("presentation")
|
||||
public String myPresentation;
|
||||
|
||||
@Attribute("md5")
|
||||
public String myMD5;
|
||||
|
||||
public String getName() {
|
||||
return myName;
|
||||
}
|
||||
|
||||
public String getDownloadUrl() {
|
||||
return myDownloadUrl;
|
||||
}
|
||||
|
||||
public String getPresentation() {
|
||||
return myPresentation;
|
||||
}
|
||||
|
||||
public String getMD5() {
|
||||
return myMD5;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return myName;
|
||||
}
|
||||
|
||||
public String[] getRequiredClasses() {
|
||||
if (myRequiredClasses == null) return new String[0];
|
||||
|
||||
final List<String> classes = ContainerUtil.mapNotNull(myRequiredClasses, new Function<RequiredClass, String>() {
|
||||
@Override
|
||||
public String fun(RequiredClass requiredClass) {
|
||||
return requiredClass.getFqn();
|
||||
}
|
||||
});
|
||||
|
||||
return classes.toArray(new String[classes.size()]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Copyright 2000-2010 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.frameworks.beans;
|
||||
|
||||
import com.intellij.util.xmlb.annotations.Attribute;
|
||||
import com.intellij.util.xmlb.annotations.Tag;
|
||||
|
||||
@Tag("required-class")
|
||||
public class RequiredClass {
|
||||
|
||||
@Attribute("fqn")
|
||||
public String myFqn;
|
||||
|
||||
public String getFqn() {
|
||||
return myFqn;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package com.intellij.facet.frameworks.beans;
|
||||
|
||||
import com.intellij.util.xmlb.annotations.AbstractCollection;
|
||||
import com.intellij.util.xmlb.annotations.Property;
|
||||
|
||||
public class Versions {
|
||||
|
||||
@Property(surroundWithTag = false)
|
||||
@AbstractCollection(surroundWithTag = false)
|
||||
public Version[] myVersions;
|
||||
|
||||
public Version[] getVersions() {
|
||||
return myVersions;
|
||||
}
|
||||
}
|
||||
@@ -28,19 +28,19 @@ public class LibraryInfo {
|
||||
public static final LibraryInfo[] EMPTY_ARRAY = new LibraryInfo[0];
|
||||
|
||||
private @Nullable final LibraryDownloadInfo myDownloadInfo;
|
||||
private @NonNls final String myPresentableName;
|
||||
private @NonNls final String myName;
|
||||
private @NonNls final String[] myRequiredClasses;
|
||||
private boolean mySelected = true;
|
||||
|
||||
public LibraryInfo(final @NonNls String presentableName, final @Nullable @NonNls String version,
|
||||
final @Nullable @NonNls String downloadingUrl,
|
||||
public LibraryInfo(final @NonNls String name,
|
||||
final @Nullable @NonNls String downloadingUrl,
|
||||
final @Nullable String presentableUrl, final @NonNls String... requiredClasses) {
|
||||
myPresentableName = presentableName;
|
||||
myName = name;
|
||||
myRequiredClasses = requiredClasses;
|
||||
if (downloadingUrl != null) {
|
||||
int dot = presentableName.lastIndexOf('.');
|
||||
String prefix = presentableName.substring(0, dot);
|
||||
String suffix = presentableName.substring(dot);
|
||||
int dot = name.lastIndexOf('.');
|
||||
String prefix = name.substring(0, dot);
|
||||
String suffix = name.substring(dot);
|
||||
myDownloadInfo = new LibraryDownloadInfo(downloadingUrl, presentableUrl, prefix, suffix);
|
||||
}
|
||||
else {
|
||||
@@ -48,15 +48,15 @@ public class LibraryInfo {
|
||||
}
|
||||
}
|
||||
|
||||
public LibraryInfo(final @NonNls String presentableName, final @Nullable LibraryDownloadInfo downloadInfo, String... requiredClasses) {
|
||||
myPresentableName = presentableName;
|
||||
public LibraryInfo(final @NonNls String name, final @Nullable LibraryDownloadInfo downloadInfo, String... requiredClasses) {
|
||||
myName = name;
|
||||
myRequiredClasses = requiredClasses;
|
||||
myDownloadInfo = downloadInfo;
|
||||
}
|
||||
|
||||
@NonNls
|
||||
public String getPresentableName() {
|
||||
return myPresentableName;
|
||||
public String getName() {
|
||||
return myName;
|
||||
}
|
||||
|
||||
@NonNls
|
||||
@@ -76,7 +76,7 @@ public class LibraryInfo {
|
||||
final LibraryInfo that = (LibraryInfo)o;
|
||||
|
||||
if (myDownloadInfo != null ? !myDownloadInfo.equals(that.myDownloadInfo) : that.myDownloadInfo != null) return false;
|
||||
if (!myPresentableName.equals(that.myPresentableName)) return false;
|
||||
if (!myName.equals(that.myName)) return false;
|
||||
if (!Arrays.equals(myRequiredClasses, that.myRequiredClasses)) return false;
|
||||
|
||||
return true;
|
||||
@@ -85,14 +85,14 @@ public class LibraryInfo {
|
||||
public int hashCode() {
|
||||
int result;
|
||||
result = (myDownloadInfo != null ? myDownloadInfo.hashCode() : 0);
|
||||
result = 31 * result + myPresentableName.hashCode();
|
||||
result = 31 * result + myName.hashCode();
|
||||
result = 31 * result + Arrays.hashCode(myRequiredClasses);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return getPresentableName();
|
||||
return getName();
|
||||
}
|
||||
|
||||
public boolean isSelected() {
|
||||
|
||||
@@ -20,9 +20,9 @@ import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import com.intellij.ide.IdeBundle;
|
||||
|
||||
/**
|
||||
* @author nik
|
||||
*/
|
||||
|
||||
@Deprecated
|
||||
// see LibrariesDownloadAssistant
|
||||
public class MavenLibraryUtil {
|
||||
@NonNls private static final String[] MAVEN_MIRRORS = {
|
||||
"http://repo1.maven.org/maven2/",
|
||||
@@ -33,10 +33,12 @@ public class MavenLibraryUtil {
|
||||
private MavenLibraryUtil() {
|
||||
}
|
||||
|
||||
@Deprecated // see LibrariesDownloadAssistant
|
||||
public static LibraryInfo createSubMavenJarInfo(@NonNls String project, @NonNls String jarName, @NonNls String version, @NonNls String... requiredClasses) {
|
||||
return createMavenJarInfo(jarName, version, project, requiredClasses);
|
||||
}
|
||||
|
||||
@Deprecated // see LibrariesDownloadAssistant
|
||||
private static LibraryInfo createMavenJarInfo(final String jarName, final String version, final String downloadingPrefix,
|
||||
final String... requiredClasses) {
|
||||
LibraryDownloadInfo downloadInfo = new LibraryDownloadInfo(MAVEN, downloadingPrefix + "/" + jarName + "/" + version + "/" + jarName + "-" + version + ".jar",
|
||||
@@ -44,6 +46,7 @@ public class MavenLibraryUtil {
|
||||
return new LibraryInfo(jarName+ ".jar", downloadInfo, requiredClasses);
|
||||
}
|
||||
|
||||
@Deprecated // see LibrariesDownloadAssistant
|
||||
public static LibraryInfo createMavenJarInfo(@NonNls String jarName, @NonNls String version, @NotNull @NonNls String... requiredClasses) {
|
||||
return createMavenJarInfo(jarName, version, jarName, requiredClasses);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user