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);
}
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);
}
}
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);
}
}
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"));
}
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;
}
Aggregations