Search in sources :

Example 1 with EclipseModuleManager

use of org.jetbrains.idea.eclipse.EclipseModuleManager in project intellij-community by JetBrains.

the class EclipseClasspathWriter method writeClasspath.

@NotNull
public Element writeClasspath(@Nullable Element oldRoot, @NotNull ModuleRootModel model) {
    Element classpathElement = new Element(EclipseXml.CLASSPATH_TAG);
    if (oldRoot != null) {
        for (Element oldChild : oldRoot.getChildren(EclipseXml.CLASSPATHENTRY_TAG)) {
            String oldKind = oldChild.getAttributeValue(EclipseXml.KIND_ATTR);
            String oldPath = oldChild.getAttributeValue(EclipseXml.PATH_ATTR);
            myOldEntries.put(oldKind + getJREKey(oldPath), oldChild);
        }
    }
    for (OrderEntry orderEntry : model.getOrderEntries()) {
        createClasspathEntry(orderEntry, classpathElement, model);
    }
    String outputPath = "bin";
    final String compilerOutputUrl = model.getModuleExtension(CompilerModuleExtension.class).getCompilerOutputUrl();
    final EclipseModuleManager eclipseModuleManager = EclipseModuleManagerImpl.getInstance(model.getModule());
    final String linkedPath = eclipseModuleManager.getEclipseLinkedVarPath(compilerOutputUrl);
    if (linkedPath != null) {
        outputPath = linkedPath;
    } else {
        VirtualFile contentRoot = EPathUtil.getContentRoot(model);
        VirtualFile output = model.getModuleExtension(CompilerModuleExtension.class).getCompilerOutputPath();
        if (contentRoot != null && output != null && VfsUtilCore.isAncestor(contentRoot, output, false)) {
            outputPath = EPathUtil.collapse2EclipsePath(output.getUrl(), model);
        } else if (output == null && compilerOutputUrl != null) {
            outputPath = EPathUtil.collapse2EclipsePath(compilerOutputUrl, model);
        }
    }
    for (String support : eclipseModuleManager.getUsedCons()) {
        addOrderEntry(EclipseXml.CON_KIND, support, classpathElement, eclipseModuleManager.getSrcPlace(support));
    }
    setAttributeIfAbsent(addOrderEntry(EclipseXml.OUTPUT_KIND, outputPath, classpathElement), EclipseXml.PATH_ATTR, EclipseXml.BIN_DIR);
    return classpathElement;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) EclipseModuleManager(org.jetbrains.idea.eclipse.EclipseModuleManager) Element(org.jdom.Element) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with EclipseModuleManager

use of org.jetbrains.idea.eclipse.EclipseModuleManager in project intellij-community by JetBrains.

the class EclipseClasspathWriter method createClasspathEntry.

private void createClasspathEntry(@NotNull OrderEntry entry, @NotNull Element classpathRoot, @NotNull final ModuleRootModel model) throws ConversionException {
    EclipseModuleManager eclipseModuleManager = EclipseModuleManagerImpl.getInstance(entry.getOwnerModule());
    if (entry instanceof ModuleSourceOrderEntry) {
        boolean shouldPlaceSeparately = eclipseModuleManager.isExpectedModuleSourcePlace(ArrayUtil.find(model.getOrderEntries(), entry));
        for (ContentEntry contentEntry : model.getContentEntries()) {
            VirtualFile contentRoot = contentEntry.getFile();
            for (SourceFolder sourceFolder : contentEntry.getSourceFolders()) {
                String srcUrl = sourceFolder.getUrl();
                String relativePath = EPathUtil.collapse2EclipsePath(srcUrl, model);
                if (!Comparing.equal(contentRoot, EPathUtil.getContentRoot(model))) {
                    String linkedPath = EclipseModuleManagerImpl.getInstance(entry.getOwnerModule()).getEclipseLinkedSrcVariablePath(srcUrl);
                    if (linkedPath != null) {
                        relativePath = linkedPath;
                    }
                }
                int index = eclipseModuleManager.getSrcPlace(srcUrl);
                addOrderEntry(EclipseXml.SRC_KIND, relativePath, classpathRoot, shouldPlaceSeparately && index != -1 ? index : -1);
            }
        }
    } else if (entry instanceof ModuleOrderEntry) {
        final String path = '/' + ((ModuleOrderEntry) entry).getModuleName();
        final Element oldElement = getOldElement(EclipseXml.SRC_KIND, path);
        Element orderEntry = addOrderEntry(EclipseXml.SRC_KIND, path, classpathRoot);
        if (oldElement == null) {
            setAttributeIfAbsent(orderEntry, EclipseXml.COMBINEACCESSRULES_ATTR, EclipseXml.FALSE_VALUE);
        }
        setExported(orderEntry, ((ExportableOrderEntry) entry));
    } else if (entry instanceof LibraryOrderEntry) {
        final LibraryOrderEntry libraryOrderEntry = (LibraryOrderEntry) entry;
        final String libraryName = libraryOrderEntry.getLibraryName();
        if (libraryOrderEntry.isModuleLevel()) {
            final String[] files = libraryOrderEntry.getRootUrls(OrderRootType.CLASSES);
            if (files.length > 0) {
                if (libraryName != null && libraryName.contains(IdeaXml.JUNIT) && Comparing.strEqual(files[0], EclipseClasspathReader.getJunitClsUrl(libraryName.contains("4")))) {
                    final Element orderEntry = addOrderEntry(EclipseXml.CON_KIND, EclipseXml.JUNIT_CONTAINER + "/" + libraryName.substring(IdeaXml.JUNIT.length()), classpathRoot);
                    setExported(orderEntry, libraryOrderEntry);
                } else {
                    boolean newVarLibrary = false;
                    boolean link = false;
                    String eclipseVariablePath = eclipseModuleManager.getEclipseVariablePath(files[0]);
                    if (eclipseVariablePath == null) {
                        eclipseVariablePath = eclipseModuleManager.getEclipseLinkedVarPath(files[0]);
                        link = eclipseVariablePath != null;
                    }
                    if (eclipseVariablePath == null && !eclipseModuleManager.isEclipseLibUrl(files[0])) {
                        //new library was added
                        newVarLibrary = true;
                        eclipseVariablePath = EPathUtil.collapse2EclipseVariabledPath(libraryOrderEntry, OrderRootType.CLASSES);
                    }
                    Element orderEntry;
                    if (eclipseVariablePath != null) {
                        orderEntry = addOrderEntry(link ? EclipseXml.LIB_KIND : EclipseXml.VAR_KIND, eclipseVariablePath, classpathRoot);
                    } else {
                        LOG.assertTrue(!StringUtil.isEmptyOrSpaces(files[0]), "Library: " + libraryName);
                        orderEntry = addOrderEntry(EclipseXml.LIB_KIND, EPathUtil.collapse2EclipsePath(files[0], model), classpathRoot);
                    }
                    final String srcRelativePath;
                    String eclipseSrcVariablePath = null;
                    boolean addSrcRoots = true;
                    String[] srcFiles = libraryOrderEntry.getRootUrls(OrderRootType.SOURCES);
                    if (srcFiles.length == 0) {
                        srcRelativePath = null;
                    } else {
                        final String srcFile = srcFiles[0];
                        srcRelativePath = EPathUtil.collapse2EclipsePath(srcFile, model);
                        if (eclipseVariablePath != null) {
                            eclipseSrcVariablePath = eclipseModuleManager.getEclipseSrcVariablePath(srcFile);
                            if (eclipseSrcVariablePath == null) {
                                eclipseSrcVariablePath = eclipseModuleManager.getEclipseLinkedSrcVariablePath(srcFile);
                            }
                            if (eclipseSrcVariablePath == null) {
                                eclipseSrcVariablePath = EPathUtil.collapse2EclipseVariabledPath(libraryOrderEntry, OrderRootType.SOURCES);
                                if (eclipseSrcVariablePath != null) {
                                    eclipseSrcVariablePath = "/" + eclipseSrcVariablePath;
                                } else {
                                    if (newVarLibrary) {
                                        //new library which cannot be replaced with vars
                                        orderEntry.detach();
                                        orderEntry = addOrderEntry(EclipseXml.LIB_KIND, EPathUtil.collapse2EclipsePath(files[0], model), classpathRoot);
                                    } else {
                                        LOG.info("Added root " + srcRelativePath + " (in existing var library) can't be replaced with any variable; src roots placed in .eml only");
                                        addSrcRoots = false;
                                    }
                                }
                            }
                        }
                    }
                    setOrRemoveAttribute(orderEntry, EclipseXml.SOURCEPATH_ATTR, addSrcRoots ? (eclipseSrcVariablePath != null ? eclipseSrcVariablePath : srcRelativePath) : null);
                    EJavadocUtil.setupJavadocAttributes(orderEntry, libraryOrderEntry, model);
                    final String[] nativeRoots = libraryOrderEntry.getUrls(NativeLibraryOrderRootType.getInstance());
                    if (nativeRoots.length > 0) {
                        EJavadocUtil.setupAttributes(orderEntry, nativeRoot -> EPathUtil.collapse2EclipsePath(nativeRoot, model), EclipseXml.DLL_LINK, nativeRoots);
                    }
                    setExported(orderEntry, libraryOrderEntry);
                }
            }
        } else {
            Element orderEntry;
            if (eclipseModuleManager.getUnknownCons().contains(libraryName)) {
                orderEntry = addOrderEntry(EclipseXml.CON_KIND, libraryName, classpathRoot);
            } else if (Comparing.strEqual(libraryName, IdeaXml.ECLIPSE_LIBRARY)) {
                orderEntry = addOrderEntry(EclipseXml.CON_KIND, EclipseXml.ECLIPSE_PLATFORM, classpathRoot);
            } else {
                orderEntry = addOrderEntry(EclipseXml.CON_KIND, EclipseXml.USER_LIBRARY + '/' + libraryName, classpathRoot);
            }
            setExported(orderEntry, libraryOrderEntry);
        }
    } else if (entry instanceof JdkOrderEntry) {
        if (entry instanceof InheritedJdkOrderEntry) {
            if (!EclipseModuleManagerImpl.getInstance(entry.getOwnerModule()).isForceConfigureJDK()) {
                addOrderEntry(EclipseXml.CON_KIND, EclipseXml.JRE_CONTAINER, classpathRoot);
            }
        } else {
            final Sdk jdk = ((JdkOrderEntry) entry).getJdk();
            String jdkLink;
            if (jdk == null) {
                jdkLink = EclipseXml.JRE_CONTAINER;
            } else {
                jdkLink = EclipseXml.JRE_CONTAINER;
                if (jdk.getSdkType() instanceof JavaSdkType) {
                    jdkLink += EclipseXml.JAVA_SDK_TYPE;
                }
                jdkLink += '/' + jdk.getName();
            }
            addOrderEntry(EclipseXml.CON_KIND, jdkLink, classpathRoot);
        }
    } else {
        throw new ConversionException("Unknown EclipseProjectModel.ClasspathEntry: " + entry.getClass());
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ConversionException(org.jetbrains.idea.eclipse.ConversionException) Element(org.jdom.Element) JavaSdkType(com.intellij.openapi.projectRoots.JavaSdkType) EclipseModuleManager(org.jetbrains.idea.eclipse.EclipseModuleManager) Sdk(com.intellij.openapi.projectRoots.Sdk)

Aggregations

VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 Element (org.jdom.Element)2 EclipseModuleManager (org.jetbrains.idea.eclipse.EclipseModuleManager)2 JavaSdkType (com.intellij.openapi.projectRoots.JavaSdkType)1 Sdk (com.intellij.openapi.projectRoots.Sdk)1 NotNull (org.jetbrains.annotations.NotNull)1 ConversionException (org.jetbrains.idea.eclipse.ConversionException)1