Search in sources :

Example 1 with JpsSdkType

use of org.jetbrains.jps.model.library.sdk.JpsSdkType 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 JpsSdkType

use of org.jetbrains.jps.model.library.sdk.JpsSdkType in project intellij-community by JetBrains.

the class JpsModuleRootModelSerializer method loadRootModel.

public static void loadRootModel(JpsModule module, @Nullable Element rootModelComponent, @Nullable JpsSdkType<?> projectSdkType) {
    if (rootModelComponent == null)
        return;
    for (Element contentElement : getChildren(rootModelComponent, CONTENT_TAG)) {
        final String url = contentElement.getAttributeValue(URL_ATTRIBUTE);
        module.getContentRootsList().addUrl(url);
        for (Element sourceElement : getChildren(contentElement, SOURCE_FOLDER_TAG)) {
            module.addSourceRoot(loadSourceRoot(sourceElement));
        }
        for (Element excludeElement : getChildren(contentElement, EXCLUDE_FOLDER_TAG)) {
            module.getExcludeRootsList().addUrl(excludeElement.getAttributeValue(URL_ATTRIBUTE));
        }
    }
    final JpsDependenciesList dependenciesList = module.getDependenciesList();
    dependenciesList.clear();
    final JpsElementFactory elementFactory = JpsElementFactory.getInstance();
    UniqueNameGenerator nameGenerator = new UniqueNameGenerator();
    boolean moduleSourceAdded = false;
    for (Element orderEntry : getChildren(rootModelComponent, ORDER_ENTRY_TAG)) {
        String type = orderEntry.getAttributeValue(TYPE_ATTRIBUTE);
        if (SOURCE_FOLDER_TYPE.equals(type)) {
            dependenciesList.addModuleSourceDependency();
            moduleSourceAdded = true;
        } else if (JDK_TYPE.equals(type)) {
            String sdkName = orderEntry.getAttributeValue(JDK_NAME_ATTRIBUTE);
            String sdkTypeId = orderEntry.getAttributeValue(JDK_TYPE_ATTRIBUTE);
            final JpsSdkType<?> sdkType = JpsSdkTableSerializer.getSdkType(sdkTypeId);
            dependenciesList.addSdkDependency(sdkType);
            JpsSdkTableSerializer.setSdkReference(module.getSdkReferencesTable(), sdkName, sdkType);
            if (sdkType instanceof JpsJavaSdkTypeWrapper) {
                dependenciesList.addSdkDependency(JpsJavaSdkType.INSTANCE);
            }
        } else if (INHERITED_JDK_TYPE.equals(type)) {
            final JpsSdkType<?> sdkType = projectSdkType != null ? projectSdkType : JpsJavaSdkType.INSTANCE;
            dependenciesList.addSdkDependency(sdkType);
            if (sdkType instanceof JpsJavaSdkTypeWrapper) {
                dependenciesList.addSdkDependency(JpsJavaSdkType.INSTANCE);
            }
        } else if (LIBRARY_TYPE.equals(type)) {
            String name = orderEntry.getAttributeValue(NAME_ATTRIBUTE);
            String level = orderEntry.getAttributeValue(LEVEL_ATTRIBUTE);
            final JpsLibraryDependency dependency = dependenciesList.addLibraryDependency(elementFactory.createLibraryReference(name, JpsLibraryTableSerializer.createLibraryTableReference(level)));
            loadModuleDependencyProperties(dependency, orderEntry);
        } else if (MODULE_LIBRARY_TYPE.equals(type)) {
            final Element moduleLibraryElement = orderEntry.getChild(LIBRARY_TAG);
            String name = moduleLibraryElement.getAttributeValue(NAME_ATTRIBUTE);
            if (name == null) {
                name = GENERATED_LIBRARY_NAME_PREFIX;
            }
            String uniqueName = nameGenerator.generateUniqueName(name);
            final JpsLibrary library = JpsLibraryTableSerializer.loadLibrary(moduleLibraryElement, uniqueName);
            module.addModuleLibrary(library);
            final JpsLibraryDependency dependency = dependenciesList.addLibraryDependency(library);
            loadModuleDependencyProperties(dependency, orderEntry);
        } else if (MODULE_TYPE.equals(type)) {
            String name = orderEntry.getAttributeValue(MODULE_NAME_ATTRIBUTE);
            final JpsModuleDependency dependency = dependenciesList.addModuleDependency(elementFactory.createModuleReference(name));
            loadModuleDependencyProperties(dependency, orderEntry);
        }
    }
    if (!moduleSourceAdded) {
        dependenciesList.addModuleSourceDependency();
    }
    for (JpsModelSerializerExtension extension : JpsModelSerializerExtension.getExtensions()) {
        extension.loadRootModel(module, rootModelComponent);
    }
}
Also used : JpsJavaSdkTypeWrapper(org.jetbrains.jps.model.java.JpsJavaSdkTypeWrapper) JpsElement(org.jetbrains.jps.model.JpsElement) JpsCompositeElement(org.jetbrains.jps.model.JpsCompositeElement) Element(org.jdom.Element) UniqueNameGenerator(com.intellij.util.text.UniqueNameGenerator) JpsSdkType(org.jetbrains.jps.model.library.sdk.JpsSdkType) JpsElementFactory(org.jetbrains.jps.model.JpsElementFactory) JpsModelSerializerExtension(org.jetbrains.jps.model.serialization.JpsModelSerializerExtension) JpsLibrary(org.jetbrains.jps.model.library.JpsLibrary)

Example 3 with JpsSdkType

use of org.jetbrains.jps.model.library.sdk.JpsSdkType in project intellij-community by JetBrains.

the class JpsLibraryTableSerializer method saveLibraries.

public static void saveLibraries(JpsLibraryCollection libraryCollection, Element libraryTableElement) {
    List<JpsLibrary> libraries = new ArrayList<>();
    for (JpsLibrary library : libraryCollection.getLibraries()) {
        if (!(library.getType() instanceof JpsSdkType<?>)) {
            libraries.add(library);
        }
    }
    libraries.sort((o1, o2) -> o1.getName().compareToIgnoreCase(o2.getName()));
    for (JpsLibrary library : libraries) {
        Element libraryTag = new Element(LIBRARY_TAG);
        saveLibrary(library, libraryTag, library.getName());
        libraryTableElement.addContent(libraryTag);
    }
}
Also used : Element(org.jdom.Element) JpsSdkType(org.jetbrains.jps.model.library.sdk.JpsSdkType)

Aggregations

Element (org.jdom.Element)3 JpsSdkType (org.jetbrains.jps.model.library.sdk.JpsSdkType)3 JpsCompositeElement (org.jetbrains.jps.model.JpsCompositeElement)2 JpsElement (org.jetbrains.jps.model.JpsElement)2 JpsLibrary (org.jetbrains.jps.model.library.JpsLibrary)2 JpsModelSerializerExtension (org.jetbrains.jps.model.serialization.JpsModelSerializerExtension)2 UniqueNameGenerator (com.intellij.util.text.UniqueNameGenerator)1 JpsElementFactory (org.jetbrains.jps.model.JpsElementFactory)1 JpsJavaSdkTypeWrapper (org.jetbrains.jps.model.java.JpsJavaSdkTypeWrapper)1 JpsLibraryReference (org.jetbrains.jps.model.library.JpsLibraryReference)1 JpsSdkReference (org.jetbrains.jps.model.library.sdk.JpsSdkReference)1