Search in sources :

Example 26 with JpsLibrary

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

the class JpsSdkTableSerializer method saveSdk.

private static <P extends JpsElement> void saveSdk(final JpsSdk<P> sdk, Element sdkTag) {
    JpsLibrary library = sdk.getParent();
    sdkTag.setAttribute("version", "2");
    setAttributeValue(sdkTag, NAME_TAG, library.getName());
    JpsSdkPropertiesSerializer<P> serializer = getSdkPropertiesSerializer(sdk.getSdkType());
    setAttributeValue(sdkTag, TYPE_TAG, serializer.getTypeId());
    String versionString = sdk.getVersionString();
    if (versionString != null) {
        setAttributeValue(sdkTag, VERSION_TAG, versionString);
    }
    setAttributeValue(sdkTag, HOME_PATH_TAG, sdk.getHomePath());
    Element rootsTag = new Element(ROOTS_TAG);
    for (JpsLibraryRootTypeSerializer rootTypeSerializer : getRootTypeSerializers()) {
        Element rootTypeTag = new Element(rootTypeSerializer.getTypeId());
        Element compositeTag = new Element(ROOT_TAG);
        compositeTag.setAttribute(TYPE_ATTRIBUTE, COMPOSITE_TYPE);
        List<JpsLibraryRoot> roots = library.getRoots(rootTypeSerializer.getType());
        for (JpsLibraryRoot root : roots) {
            compositeTag.addContent(new Element(ROOT_TAG).setAttribute(TYPE_ATTRIBUTE, SIMPLE_TYPE).setAttribute(URL_ATTRIBUTE, root.getUrl()));
        }
        rootTypeTag.addContent(compositeTag);
        rootsTag.addContent(rootTypeTag);
    }
    sdkTag.addContent(rootsTag);
    Element additionalTag = new Element(ADDITIONAL_TAG);
    serializer.saveProperties(sdk.getSdkProperties(), additionalTag);
    sdkTag.addContent(additionalTag);
}
Also used : JpsElement(org.jetbrains.jps.model.JpsElement) JpsDummyElement(org.jetbrains.jps.model.JpsDummyElement) Element(org.jdom.Element) JpsLibrary(org.jetbrains.jps.model.library.JpsLibrary) JpsLibraryRoot(org.jetbrains.jps.model.library.JpsLibraryRoot)

Example 27 with JpsLibrary

use of org.jetbrains.jps.model.library.JpsLibrary 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 28 with JpsLibrary

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

the class JpsProjectSerializationTest method testSaveProject.

public void testSaveProject() {
    loadProject(SAMPLE_PROJECT_PATH);
    List<JpsModule> modules = myProject.getModules();
    doTestSaveModule(modules.get(0), SAMPLE_PROJECT_PATH + "/main.iml");
    doTestSaveModule(modules.get(1), SAMPLE_PROJECT_PATH + "/util/util.iml");
    //tod[nik] remember that test output root wasn't specified and doesn't save it to avoid unnecessary modifications of iml files
    //doTestSaveModule(modules.get(2), "xxx/xxx.iml");
    File[] libs = getFileInSampleProject(".idea/libraries").listFiles();
    assertNotNull(libs);
    for (File libFile : libs) {
        String libName = FileUtil.getNameWithoutExtension(libFile);
        JpsLibrary library = myProject.getLibraryCollection().findLibrary(libName);
        assertNotNull(libName, library);
        doTestSaveLibrary(libFile, libName, library);
    }
}
Also used : File(java.io.File) JpsLibrary(org.jetbrains.jps.model.library.JpsLibrary)

Example 29 with JpsLibrary

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

the class JpsProjectSerializationTest method testDuplicatedModuleLibrary.

public void testDuplicatedModuleLibrary() {
    loadProject("/jps/model-serialization/testData/duplicatedModuleLibrary/duplicatedModuleLibrary.ipr");
    JpsModule module = assertOneElement(myProject.getModules());
    List<JpsDependencyElement> dependencies = module.getDependenciesList().getDependencies();
    assertEquals(4, dependencies.size());
    JpsLibrary lib1 = assertInstanceOf(dependencies.get(2), JpsLibraryDependency.class).getLibrary();
    assertNotNull(lib1);
    assertSameElements(lib1.getRootUrls(JpsOrderRootType.COMPILED), getUrl("data/lib1"));
    JpsLibrary lib2 = assertInstanceOf(dependencies.get(3), JpsLibraryDependency.class).getLibrary();
    assertNotSame(lib1, lib2);
    assertNotNull(lib2);
    assertSameElements(lib2.getRootUrls(JpsOrderRootType.COMPILED), getUrl("data/lib2"));
}
Also used : JpsLibrary(org.jetbrains.jps.model.library.JpsLibrary)

Example 30 with JpsLibrary

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

the class JpsDependenciesEnumeratorTest method createAsmLibrary.

private JpsLibrary createAsmLibrary() {
    JpsLibrary library = addLibrary("asm");
    library.addRoot(getAsmJar(), JpsOrderRootType.COMPILED);
    return library;
}
Also used : JpsLibrary(org.jetbrains.jps.model.library.JpsLibrary)

Aggregations

JpsLibrary (org.jetbrains.jps.model.library.JpsLibrary)41 JpsModule (org.jetbrains.jps.model.module.JpsModule)11 File (java.io.File)10 Element (org.jdom.Element)8 NotNull (org.jetbrains.annotations.NotNull)7 JpsSimpleElement (org.jetbrains.jps.model.JpsSimpleElement)7 JpsLibraryRoot (org.jetbrains.jps.model.library.JpsLibraryRoot)6 JpsAndroidModuleExtensionImpl (org.jetbrains.jps.android.model.impl.JpsAndroidModuleExtensionImpl)5 JpsAndroidModuleProperties (org.jetbrains.jps.android.model.impl.JpsAndroidModuleProperties)5 JpsElement (org.jetbrains.jps.model.JpsElement)5 JpsDummyElement (org.jetbrains.jps.model.JpsDummyElement)4 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 Nullable (org.jetbrains.annotations.Nullable)3 JpsDependencyElement (org.jetbrains.jps.model.module.JpsDependencyElement)3 JpsLibraryDependency (org.jetbrains.jps.model.module.JpsLibraryDependency)3 Logger (com.intellij.openapi.diagnostic.Logger)2 SystemInfo (com.intellij.openapi.util.SystemInfo)2 JpsElementFactory (org.jetbrains.jps.model.JpsElementFactory)2 JpsSdkReference (org.jetbrains.jps.model.library.sdk.JpsSdkReference)2