Search in sources :

Example 1 with JpsModelSerializerExtension

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

the class JpsModuleRootModelSerializer method getSourceRootPropertiesSerializer.

@NotNull
private static JpsModuleSourceRootPropertiesSerializer<?> getSourceRootPropertiesSerializer(@NotNull Element sourceElement) {
    String typeAttribute = sourceElement.getAttributeValue(SOURCE_ROOT_TYPE_ATTRIBUTE);
    if (typeAttribute == null) {
        typeAttribute = Boolean.parseBoolean(sourceElement.getAttributeValue(IS_TEST_SOURCE_ATTRIBUTE)) ? JAVA_TEST_ROOT_TYPE_ID : JAVA_SOURCE_ROOT_TYPE_ID;
    }
    for (JpsModelSerializerExtension extension : JpsModelSerializerExtension.getExtensions()) {
        for (JpsModuleSourceRootPropertiesSerializer<?> serializer : extension.getModuleSourceRootPropertiesSerializers()) {
            if (serializer.getTypeId().equals(typeAttribute)) {
                return serializer;
            }
        }
    }
    LOG.warn("Unknown module source root type " + typeAttribute);
    return JpsJavaModelSerializerExtension.JAVA_SOURCE_ROOT_PROPERTIES_SERIALIZER;
}
Also used : JpsModelSerializerExtension(org.jetbrains.jps.model.serialization.JpsModelSerializerExtension) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with JpsModelSerializerExtension

use of org.jetbrains.jps.model.serialization.JpsModelSerializerExtension 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 3 with JpsModelSerializerExtension

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

the class JpsArtifactSerializer method doSaveArtifact.

private static <P extends JpsElement> void doSaveArtifact(JpsArtifact artifact, Element componentElement, ArtifactState state, JpsArtifactPropertiesSerializer<P> serializer) {
    state.setArtifactType(serializer.getTypeId());
    state.setRootElement(savePackagingElement(artifact.getRootElement()));
    List<ArtifactPropertiesState> propertiesList = state.getPropertiesList();
    //noinspection unchecked
    serializer.saveProperties((P) artifact.getProperties(), propertiesList);
    for (JpsModelSerializerExtension serializerExtension : JpsModelSerializerExtension.getExtensions()) {
        for (JpsArtifactExtensionSerializer<?> extensionSerializer : serializerExtension.getArtifactExtensionSerializers()) {
            JpsElement extension = artifact.getContainer().getChild(extensionSerializer.getRole());
            if (extension != null) {
                ArtifactPropertiesState propertiesState = new ArtifactPropertiesState();
                propertiesState.setId(extensionSerializer.getId());
                propertiesState.setOptions(saveExtension(extensionSerializer, extension));
                propertiesList.add(propertiesState);
            }
        }
    }
    componentElement.addContent(XmlSerializer.serialize(state, SERIALIZATION_FILTERS));
}
Also used : JpsModelSerializerExtension(org.jetbrains.jps.model.serialization.JpsModelSerializerExtension)

Example 4 with JpsModelSerializerExtension

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

the class JpsLibraryTableSerializer method getSortedSerializers.

private static Collection<JpsLibraryRootTypeSerializer> getSortedSerializers() {
    List<JpsLibraryRootTypeSerializer> serializers = new ArrayList<>();
    Collections.addAll(serializers, PREDEFINED_ROOT_TYPES_SERIALIZERS);
    for (JpsModelSerializerExtension extension : JpsModelSerializerExtension.getExtensions()) {
        serializers.addAll(extension.getLibraryRootTypeSerializers());
    }
    Collections.sort(serializers);
    return serializers;
}
Also used : JpsModelSerializerExtension(org.jetbrains.jps.model.serialization.JpsModelSerializerExtension)

Example 5 with JpsModelSerializerExtension

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

the class JpsSdkTableSerializer method getRootTypeSerializers.

private static List<JpsLibraryRootTypeSerializer> getRootTypeSerializers() {
    List<JpsLibraryRootTypeSerializer> serializers = new ArrayList<>(Arrays.asList(PREDEFINED_ROOT_TYPE_SERIALIZERS));
    for (JpsModelSerializerExtension extension : JpsModelSerializerExtension.getExtensions()) {
        serializers.addAll(extension.getSdkRootTypeSerializers());
    }
    Collections.sort(serializers);
    return serializers;
}
Also used : ArrayList(java.util.ArrayList) JpsModelSerializerExtension(org.jetbrains.jps.model.serialization.JpsModelSerializerExtension)

Aggregations

JpsModelSerializerExtension (org.jetbrains.jps.model.serialization.JpsModelSerializerExtension)8 Element (org.jdom.Element)3 JpsElement (org.jetbrains.jps.model.JpsElement)3 JpsCompositeElement (org.jetbrains.jps.model.JpsCompositeElement)2 JpsLibrary (org.jetbrains.jps.model.library.JpsLibrary)2 JpsSdkType (org.jetbrains.jps.model.library.sdk.JpsSdkType)2 HashMap (com.intellij.util.containers.hash.HashMap)1 UniqueNameGenerator (com.intellij.util.text.UniqueNameGenerator)1 SkipDefaultValuesSerializationFilters (com.intellij.util.xmlb.SkipDefaultValuesSerializationFilters)1 ArrayList (java.util.ArrayList)1 NotNull (org.jetbrains.annotations.NotNull)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