Search in sources :

Example 1 with JarDirectories

use of com.intellij.openapi.roots.impl.libraries.JarDirectories in project intellij-plugins by JetBrains.

the class FlexModuleConverter method isApplicableLibrary.

static boolean isApplicableLibrary(final Element library, Function<String, String> pathExpander) {
    String libraryType = library.getAttributeValue(LibraryImpl.LIBRARY_TYPE_ATTR);
    if (FlexLibraryType.FLEX_LIBRARY.getKindId().equals(libraryType)) {
        return true;
    }
    if (libraryType != null) {
        // ignore explicit non-Flex libraries
        return false;
    }
    final Element rootChild = library.getChild(OrderRootType.CLASSES.name());
    if (rootChild == null) {
        // corrupted element
        return false;
    }
    JarDirectories jarDirectories = new JarDirectories();
    try {
        jarDirectories.readExternal(library);
    } catch (InvalidDataException ignored) {
        jarDirectories.clear();
    }
    List<Element> classesRoots = rootChild.getChildren(LibraryImpl.ROOT_PATH_ELEMENT);
    if (classesRoots.isEmpty()) {
        // no classes root
        return false;
    }
    for (Element root : classesRoots) {
        final String url = root.getAttributeValue("url");
        if (url == null) {
            // corrupted element
            continue;
        }
        final String path = getPathFromUrl(url);
        if (path == null) {
            continue;
        }
        if (path.toLowerCase().endsWith(".swc")) {
            return true;
        } else {
            if (jarDirectories.contains(OrderRootType.CLASSES, url)) {
                String expanded = pathExpander.fun(path);
                File file = new File(expanded);
                if (!file.isDirectory()) {
                    return true;
                }
                String[] allChildren = file.list();
                if (allChildren == null || allChildren.length == 0) {
                    return true;
                }
                File[] swcs = file.listFiles(FileFilters.filesWithExtension("swc"));
                if (swcs != null && swcs.length > 0) {
                    return true;
                }
                File[] jars = file.listFiles(FileFilters.filesWithExtension("jar"));
                if (jars != null && jars.length > 0) {
                    continue;
                }
                return true;
            } else if (!path.toLowerCase().endsWith(".jar")) {
                return true;
            }
        }
    }
    return false;
}
Also used : Element(org.jdom.Element) InvalidDataException(com.intellij.openapi.util.InvalidDataException) JarDirectories(com.intellij.openapi.roots.impl.libraries.JarDirectories) File(java.io.File)

Aggregations

JarDirectories (com.intellij.openapi.roots.impl.libraries.JarDirectories)1 InvalidDataException (com.intellij.openapi.util.InvalidDataException)1 File (java.io.File)1 Element (org.jdom.Element)1