Search in sources :

Example 1 with JpsCompositeElement

use of org.jetbrains.jps.model.JpsCompositeElement in project intellij-community by JetBrains.

the class JpsModuleRootModelSerializer method saveRootModel.

public static void saveRootModel(JpsModule module, Element rootModelElement) {
    List<JpsModuleSourceRoot> sourceRoots = module.getSourceRoots();
    List<String> excludedUrls = getSortedList(module.getExcludeRootsList().getUrls());
    for (String url : getSortedList(module.getContentRootsList().getUrls())) {
        Element contentElement = new Element(CONTENT_TAG);
        contentElement.setAttribute(URL_ATTRIBUTE, url);
        rootModelElement.addContent(contentElement);
        for (JpsModuleSourceRoot root : sourceRoots) {
            if (FileUtil.startsWith(root.getUrl(), url)) {
                saveSourceRoot(contentElement, root.asTyped().getUrl(), root.asTyped());
            }
        }
        for (String excludedUrl : excludedUrls) {
            if (FileUtil.startsWith(excludedUrl, url)) {
                Element element = new Element(EXCLUDE_FOLDER_TAG).setAttribute(URL_ATTRIBUTE, excludedUrl);
                contentElement.addContent(element);
            }
        }
    }
    for (JpsDependencyElement dependency : module.getDependenciesList().getDependencies()) {
        if (dependency instanceof JpsModuleSourceDependency) {
            rootModelElement.addContent(createDependencyElement(SOURCE_FOLDER_TYPE).setAttribute("forTests", "false"));
        } else if (dependency instanceof JpsSdkDependency) {
            JpsSdkType<?> sdkType = ((JpsSdkDependency) dependency).getSdkType();
            JpsSdkReferencesTable table = module.getSdkReferencesTable();
            JpsSdkReference<?> reference = table.getSdkReference(sdkType);
            if (reference == null) {
                rootModelElement.addContent(createDependencyElement(INHERITED_JDK_TYPE));
            } else {
                Element element = createDependencyElement(JDK_TYPE);
                element.setAttribute(JDK_NAME_ATTRIBUTE, reference.getSdkName());
                element.setAttribute(JDK_TYPE_ATTRIBUTE, JpsSdkTableSerializer.getLoader(sdkType).getTypeId());
                rootModelElement.addContent(element);
            }
        } else if (dependency instanceof JpsLibraryDependency) {
            JpsLibraryReference reference = ((JpsLibraryDependency) dependency).getLibraryReference();
            JpsElementReference<? extends JpsCompositeElement> parentReference = reference.getParentReference();
            Element element;
            if (parentReference instanceof JpsModuleReference) {
                element = createDependencyElement(MODULE_LIBRARY_TYPE);
                saveModuleDependencyProperties(dependency, element);
                Element libraryElement = new Element(LIBRARY_TAG);
                JpsLibrary library = reference.resolve();
                String libraryName = library.getName();
                JpsLibraryTableSerializer.saveLibrary(library, libraryElement, isGeneratedName(libraryName) ? null : libraryName);
                element.addContent(libraryElement);
            } else {
                element = createDependencyElement(LIBRARY_TYPE);
                saveModuleDependencyProperties(dependency, element);
                element.setAttribute(NAME_ATTRIBUTE, reference.getLibraryName());
                element.setAttribute(LEVEL_ATTRIBUTE, JpsLibraryTableSerializer.getLevelId(parentReference));
            }
            rootModelElement.addContent(element);
        } else if (dependency instanceof JpsModuleDependency) {
            Element element = createDependencyElement(MODULE_TYPE);
            element.setAttribute(MODULE_NAME_ATTRIBUTE, ((JpsModuleDependency) dependency).getModuleReference().getModuleName());
            saveModuleDependencyProperties(dependency, element);
            rootModelElement.addContent(element);
        }
    }
    for (JpsModelSerializerExtension extension : JpsModelSerializerExtension.getExtensions()) {
        extension.saveRootModel(module, rootModelElement);
    }
}
Also used : JpsSdkReference(org.jetbrains.jps.model.library.sdk.JpsSdkReference) JpsLibraryReference(org.jetbrains.jps.model.library.JpsLibraryReference) JpsElement(org.jetbrains.jps.model.JpsElement) JpsCompositeElement(org.jetbrains.jps.model.JpsCompositeElement) Element(org.jdom.Element) JpsSdkType(org.jetbrains.jps.model.library.sdk.JpsSdkType) JpsModelSerializerExtension(org.jetbrains.jps.model.serialization.JpsModelSerializerExtension) JpsLibrary(org.jetbrains.jps.model.library.JpsLibrary)

Example 2 with JpsCompositeElement

use of org.jetbrains.jps.model.JpsCompositeElement in project intellij-community by JetBrains.

the class JpsLibraryOrderEntry method getLibraryLevel.

@Override
public String getLibraryLevel() {
    final JpsElementReference<? extends JpsCompositeElement> reference = myDependencyElement.getLibraryReference().getParentReference();
    final JpsCompositeElement parent = reference.resolve();
    if (parent instanceof JpsGlobal)
        return LibraryTablesRegistrar.APPLICATION_LEVEL;
    if (parent instanceof JpsProject)
        return LibraryTablesRegistrar.PROJECT_LEVEL;
    if (parent instanceof JpsModule)
        return LibraryTableImplUtil.MODULE_LEVEL;
    return LibraryTablesRegistrar.PROJECT_LEVEL;
}
Also used : JpsModule(org.jetbrains.jps.model.module.JpsModule) JpsGlobal(org.jetbrains.jps.model.JpsGlobal) JpsProject(org.jetbrains.jps.model.JpsProject) JpsCompositeElement(org.jetbrains.jps.model.JpsCompositeElement)

Aggregations

JpsCompositeElement (org.jetbrains.jps.model.JpsCompositeElement)2 Element (org.jdom.Element)1 JpsElement (org.jetbrains.jps.model.JpsElement)1 JpsGlobal (org.jetbrains.jps.model.JpsGlobal)1 JpsProject (org.jetbrains.jps.model.JpsProject)1 JpsLibrary (org.jetbrains.jps.model.library.JpsLibrary)1 JpsLibraryReference (org.jetbrains.jps.model.library.JpsLibraryReference)1 JpsSdkReference (org.jetbrains.jps.model.library.sdk.JpsSdkReference)1 JpsSdkType (org.jetbrains.jps.model.library.sdk.JpsSdkType)1 JpsModule (org.jetbrains.jps.model.module.JpsModule)1 JpsModelSerializerExtension (org.jetbrains.jps.model.serialization.JpsModelSerializerExtension)1