diff --git a/java/idea-ui/src/com/intellij/framework/library/DownloadableLibraryTypeBase.java b/java/idea-ui/src/com/intellij/framework/library/DownloadableLibraryTypeBase.java new file mode 100644 index 000000000000..eb36fde1fa14 --- /dev/null +++ b/java/idea-ui/src/com/intellij/framework/library/DownloadableLibraryTypeBase.java @@ -0,0 +1,50 @@ +package com.intellij.framework.library; + +import com.intellij.openapi.roots.libraries.JarVersionDetectionUtil; +import com.intellij.openapi.roots.libraries.LibraryKind; +import com.intellij.openapi.roots.libraries.LibraryUtil; +import com.intellij.openapi.vfs.VirtualFile; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import javax.swing.*; +import java.net.URL; +import java.util.List; + +public abstract class DownloadableLibraryTypeBase extends DownloadableLibraryType { + private Icon myIcon; + + public DownloadableLibraryTypeBase(@NotNull String libraryCategoryName, + @NotNull String groupId, + @NotNull Icon icon, + @NotNull URL... localUrls) { + super(new LibraryKind(libraryCategoryName), libraryCategoryName, + DownloadableLibraryService.getInstance().createLibraryDescription(groupId, localUrls)); + myIcon = icon; + } + + public Icon getIcon() { + return myIcon; + } + + public abstract String[] getDetectionClassNames(); + + @Override + public LibraryVersionProperties detect(@NotNull List classesRoots) { + for (String className : getDetectionClassNames()) { + + final LibraryVersionProperties versionProperties = detectJsfVersion(classesRoots, className); + if (versionProperties != null) return versionProperties; + } + return null; + } + + @Nullable + private LibraryVersionProperties detectJsfVersion(List classesRoots, String detectionClass) { + if (!LibraryUtil.isClassAvailableInLibrary(classesRoots, detectionClass)) { + return null; + } + final String version = JarVersionDetectionUtil.detectJarVersion(detectionClass, classesRoots); + return new LibraryVersionProperties(version); + } +} diff --git a/java/idea-ui/src/com/intellij/framework/library/UnderlyingFrameworkSupportProviderBase.java b/java/idea-ui/src/com/intellij/framework/library/UnderlyingFrameworkSupportProviderBase.java new file mode 100644 index 000000000000..8a19d9f8d5e1 --- /dev/null +++ b/java/idea-ui/src/com/intellij/framework/library/UnderlyingFrameworkSupportProviderBase.java @@ -0,0 +1,58 @@ +package com.intellij.framework.library; + +import com.intellij.ide.util.frameworkSupport.FrameworkSupportConfigurableBase; +import com.intellij.ide.util.frameworkSupport.FrameworkSupportModel; +import com.intellij.ide.util.frameworkSupport.FrameworkSupportProviderBase; +import com.intellij.ide.util.frameworkSupport.FrameworkVersion; +import com.intellij.openapi.module.Module; +import com.intellij.openapi.module.ModuleType; +import com.intellij.openapi.roots.ModifiableRootModel; +import com.intellij.openapi.roots.libraries.Library; +import com.intellij.openapi.roots.ui.configuration.libraries.CustomLibraryDescription; +import org.jetbrains.annotations.NonNls; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +public abstract class UnderlyingFrameworkSupportProviderBase extends FrameworkSupportProviderBase { + + public UnderlyingFrameworkSupportProviderBase(final @NonNls @NotNull String id, final @NotNull String title) { + super(id, title); + } + + @Override + protected void addSupport(@NotNull Module module, + @NotNull ModifiableRootModel rootModel, + FrameworkVersion version, + @Nullable Library library) { + } + + @NotNull + @Override + public FrameworkSupportConfigurableBase createConfigurable(@NotNull final FrameworkSupportModel model) { + return new LibrarySupportConfigurable(this, model); + } + + public boolean isEnabledForModuleType(@NotNull ModuleType moduleType) { + return true; + } + + protected abstract Class getLibraryClass() ; + + private class LibrarySupportConfigurable extends FrameworkSupportConfigurableBase implements FrameworkSupportWithLibrary { + private LibrarySupportConfigurable(UnderlyingFrameworkSupportProviderBase provider, + FrameworkSupportModel model) { + super(provider, model); + } + + @NotNull + @Override + public CustomLibraryDescription createLibraryDescription() { + return DownloadableLibraryService.getInstance().createDescriptionForType(getLibraryClass()); + } + + @Override + public boolean isLibraryOnly() { + return false; + } + } +}