use of com.intellij.lang.javascript.flex.library.FlexLibraryProperties in project intellij-plugins by JetBrains.
the class FlexTestUtils method doAddFlexLibrary.
private static void doAddFlexLibrary(boolean isProjectLibrary, Module module, String libraryName, boolean overwrite, String libraryRoot, @Nullable String classesPath, @Nullable String sourcesPath, @Nullable String asdocPath, LinkageType linkageType) {
ModifiableRootModel moduleModifiableModel = ModuleRootManager.getInstance(module).getModifiableModel();
WriteAction.run(() -> {
try {
// first let's create Flex library
final LibraryTable libraryTable;
if (isProjectLibrary) {
libraryTable = ProjectLibraryTable.getInstance(module.getProject());
} else {
libraryTable = moduleModifiableModel.getModuleLibraryTable();
}
Library library = libraryTable.getLibraryByName(libraryName);
if (library != null && overwrite) {
libraryTable.removeLibrary(library);
library = null;
}
if (library == null) {
LibraryTable.ModifiableModel libraryTableModifiableModel = libraryTable.getModifiableModel();
library = libraryTableModifiableModel.createLibrary(libraryName, FlexLibraryType.FLEX_LIBRARY);
LibraryEx.ModifiableModelEx libraryModel = (LibraryEx.ModifiableModelEx) library.getModifiableModel();
libraryModel.setProperties(new FlexLibraryProperties(FlexLibraryIdGenerator.generateId()));
addRootIfNotNull(libraryRoot, classesPath, libraryModel, OrderRootType.CLASSES, ".swc", ".zip");
addRootIfNotNull(libraryRoot, sourcesPath, libraryModel, OrderRootType.SOURCES, ".zip");
addRootIfNotNull(libraryRoot, asdocPath, libraryModel, JavadocOrderRootType.getInstance(), ".zip");
libraryModel.commit();
libraryTableModifiableModel.commit();
}
moduleModifiableModel.commit();
// then add Flex library to build configuration dependency
final String committedLibraryId;
if (isProjectLibrary) {
committedLibraryId = FlexProjectRootsUtil.getLibraryId(ProjectLibraryTable.getInstance(module.getProject()).getLibraryByName(libraryName));
} else {
final OrderEntry entry = ContainerUtil.find(ModuleRootManager.getInstance(module).getOrderEntries(), orderEntry -> orderEntry instanceof LibraryOrderEntry && ((LibraryOrderEntry) orderEntry).getLibraryName().equals(libraryName));
committedLibraryId = FlexProjectRootsUtil.getLibraryId(((LibraryOrderEntry) entry).getLibrary());
}
if (ModuleType.get(module) == FlexModuleType.getInstance()) {
modifyConfigs(module.getProject(), e -> {
final ModifiableFlexBuildConfiguration[] bcs = e.getConfigurations(module);
final ModifiableDependencyEntry dependencyEntry;
if (isProjectLibrary) {
dependencyEntry = e.createSharedLibraryEntry(bcs[0].getDependencies(), libraryName, LibraryTablesRegistrar.PROJECT_LEVEL);
} else {
dependencyEntry = e.createModuleLibraryEntry(bcs[0].getDependencies(), committedLibraryId);
}
dependencyEntry.getDependencyType().setLinkageType(linkageType);
bcs[0].getDependencies().getModifiableEntries().add(dependencyEntry);
});
}
} finally {
if (!moduleModifiableModel.isDisposed()) {
moduleModifiableModel.dispose();
}
}
});
}
use of com.intellij.lang.javascript.flex.library.FlexLibraryProperties in project intellij-plugins by JetBrains.
the class FlexProjectConfigTest method createModuleLibrary.
private String createModuleLibrary() {
final ModifiableRootModel modifiableModel = ModuleRootManager.getInstance(myModule).getModifiableModel();
final LibraryTable.ModifiableModel libraryTable = modifiableModel.getModuleLibraryTable().getModifiableModel();
LibraryEx library = (LibraryEx) libraryTable.createLibrary("test", FlexLibraryType.FLEX_LIBRARY);
String libraryId = UUID.randomUUID().toString();
((FlexLibraryProperties) library.getProperties()).setId(libraryId);
ApplicationManager.getApplication().runWriteAction(() -> {
libraryTable.commit();
modifiableModel.commit();
});
return libraryId;
}
use of com.intellij.lang.javascript.flex.library.FlexLibraryProperties in project intellij-plugins by JetBrains.
the class AddAsSwcLibDialog method addLib.
private static void addLib(final FlexProjectConfigurationEditor flexConfigEditor, final Collection<Pair<Module, FlexBuildConfiguration>> modulesAndBCs, final List<VirtualFile> roots) {
for (Pair<Module, FlexBuildConfiguration> moduleAndBc : modulesAndBCs) {
final Module module = moduleAndBc.first;
ModifiableFlexBuildConfiguration bc = null;
final ModifiableFlexBuildConfiguration[] bcs = flexConfigEditor.getConfigurations(module);
for (ModifiableFlexBuildConfiguration each : bcs) {
if (each.getName().equals(moduleAndBc.second.getName())) {
bc = each;
break;
}
}
if (bc == null)
continue;
final Collection<VirtualFile> filteredRoots = filterAlreadyExistingRoots(roots, flexConfigEditor, module, bc);
final LibraryTable.ModifiableModel libraryModel = flexConfigEditor.getLibraryModel(bc.getDependencies());
for (VirtualFile file : filteredRoots) {
final Library library = libraryModel.createLibrary(null, FlexLibraryType.FLEX_LIBRARY);
final LibraryEx.ModifiableModelEx libraryModifiableModel = ((LibraryEx.ModifiableModelEx) library.getModifiableModel());
final String libraryId = UUID.randomUUID().toString();
libraryModifiableModel.setProperties(new FlexLibraryProperties(libraryId));
if (file.isInLocalFileSystem() && file.isDirectory()) {
libraryModifiableModel.addJarDirectory(file, false);
} else {
libraryModifiableModel.addRoot(file, OrderRootType.CLASSES);
}
ApplicationManager.getApplication().runWriteAction(() -> libraryModifiableModel.commit());
final ModifiableModuleLibraryEntry libraryEntry = flexConfigEditor.createModuleLibraryEntry(bc.getDependencies(), libraryId);
libraryEntry.getDependencyType().setLinkageType(LinkageType.Merged);
bc.getDependencies().getModifiableEntries().add(libraryEntry);
}
}
}
use of com.intellij.lang.javascript.flex.library.FlexLibraryProperties in project intellij-plugins by JetBrains.
the class FlexProjectConfigurationEditor method copyModuleLibrary.
private static LibraryEx copyModuleLibrary(final ModifiableRootModel modifiableModel, final LibraryEx library) {
LibraryTable.ModifiableModel librariesModifiableModel = getTableModifiableModel(modifiableModel);
LibraryEx libraryCopy = (LibraryEx) librariesModifiableModel.createLibrary(library.getName(), library.getKind());
LibraryEx.ModifiableModelEx libraryCopyModel = libraryCopy.getModifiableModel();
// will overwrite library id
LibraryEditingUtil.copyLibrary(library, Collections.emptyMap(), libraryCopyModel);
// do assign unique library id
libraryCopyModel.setProperties(new FlexLibraryProperties(FlexLibraryIdGenerator.generateId()));
libraryCopyModel.commit();
return libraryCopy;
}
use of com.intellij.lang.javascript.flex.library.FlexLibraryProperties in project intellij-plugins by JetBrains.
the class FlexModuleConverter method processConfiguration.
private void processConfiguration(@Nullable FlexBuildConfiguration oldConfiguration, ModifiableFlexBuildConfiguration newBuildConfiguration, final ModuleSettings module, boolean facet, @Nullable String facetSdkName, Set<String> usedSdksNames, Collection<Element> orderEntriesToAdd, Set<Element> usedModuleLibrariesEntries) throws CannotConvertException {
if (oldConfiguration == null) {
newBuildConfiguration.setOutputType(OutputType.Application);
} else {
if (FlexBuildConfiguration.LIBRARY.equals(oldConfiguration.OUTPUT_TYPE)) {
newBuildConfiguration.setOutputType(OutputType.Library);
} else {
newBuildConfiguration.setOutputType(OutputType.Application);
}
if (newBuildConfiguration.getOutputType() == OutputType.Application) {
newBuildConfiguration.setMainClass(oldConfiguration.MAIN_CLASS);
myParams.addAppModuleAndBCName(module.getModuleName(), newBuildConfiguration.getName());
}
newBuildConfiguration.setOutputFileName(oldConfiguration.OUTPUT_FILE_NAME);
newBuildConfiguration.setSkipCompile(!oldConfiguration.DO_BUILD);
final ModifiableCompilerOptions newCompilerOptions = newBuildConfiguration.getCompilerOptions();
newCompilerOptions.setAllOptions(convertCompilerOptions(oldConfiguration, module, newCompilerOptions));
}
String outputFolder;
if (facet && oldConfiguration != null && oldConfiguration.USE_FACET_COMPILE_OUTPUT_PATH) {
outputFolder = PathUtil.getCanonicalPath(module.expandPath(oldConfiguration.FACET_COMPILE_OUTPUT_PATH));
} else {
outputFolder = getOutputFolder(module);
}
newBuildConfiguration.setOutputFolder(outputFolder);
Collection<Element> orderEntriesToRemove = new ArrayList<>();
// TODO filter out java libraries and remove their order entries
for (Element orderEntry : module.getOrderEntries()) {
String orderEntryType = orderEntry.getAttributeValue(OrderEntryFactory.ORDER_ENTRY_TYPE_ATTR);
if (ModuleLibraryOrderEntryImpl.ENTRY_TYPE.equals(orderEntryType)) {
Element library = orderEntry.getChild(LibraryImpl.ELEMENT);
if (!isApplicableLibrary(library, s -> module.expandPath(s))) {
// ignore non-flex module library
orderEntriesToRemove.add(orderEntry);
continue;
}
if (facet && isAutogeneratedLibrary(library)) {
orderEntriesToRemove.add(orderEntry);
continue;
}
Element libraryProperties;
if (!usedModuleLibrariesEntries.add(orderEntry)) {
// this library is already used by another build configuration, create new entry with new library
Element newEntry = orderEntry.clone();
orderEntriesToAdd.add(newEntry);
library = orderEntry.getChild(LibraryImpl.ELEMENT);
libraryProperties = library.getChild(LibraryImpl.PROPERTIES_ELEMENT);
} else {
library.setAttribute(LibraryImpl.LIBRARY_TYPE_ATTR, FlexLibraryType.FLEX_LIBRARY.getKindId());
libraryProperties = new Element(LibraryImpl.PROPERTIES_ELEMENT);
//noinspection unchecked
library.getChildren().add(0, libraryProperties);
}
String libraryId = FlexLibraryIdGenerator.generateId();
XmlSerializer.serializeInto(new FlexLibraryProperties(libraryId), libraryProperties);
ModifiableModuleLibraryEntry moduleLibraryEntry = ConversionHelper.createModuleLibraryEntry(libraryId);
convertDependencyType(orderEntry, moduleLibraryEntry.getDependencyType());
newBuildConfiguration.getDependencies().getModifiableEntries().add(moduleLibraryEntry);
} else if ("library".equals(orderEntryType)) {
String libraryName = orderEntry.getAttributeValue("name");
String libraryLevel = orderEntry.getAttributeValue("level");
if (myParams.libraryExists(libraryName, libraryLevel)) {
myParams.changeLibraryTypeToFlex(libraryName, libraryLevel);
ModifiableSharedLibraryEntry sharedLibraryEntry = ConversionHelper.createSharedLibraryEntry(libraryName, libraryLevel);
convertDependencyType(orderEntry, sharedLibraryEntry.getDependencyType());
newBuildConfiguration.getDependencies().getModifiableEntries().add(sharedLibraryEntry);
} else {
orderEntriesToRemove.add(orderEntry);
}
} else if (ModuleOrderEntryImpl.ENTRY_TYPE.equals(orderEntryType)) {
String moduleName = orderEntry.getAttributeValue(ModuleOrderEntryImpl.MODULE_NAME_ATTR);
Collection<String> bcNames = myParams.getBcNamesForDependency(moduleName, newBuildConfiguration.getNature());
for (String bcName : bcNames) {
ModifiableBuildConfigurationEntry bcEntry = ConversionHelper.createBuildConfigurationEntry(moduleName, bcName);
convertDependencyType(orderEntry, bcEntry.getDependencyType());
newBuildConfiguration.getDependencies().getModifiableEntries().add(bcEntry);
}
if (bcNames.isEmpty()) {
orderEntriesToRemove.add(orderEntry);
}
} else if (ModuleJdkOrderEntryImpl.ENTRY_TYPE.equals(orderEntryType)) {
if (!facet) {
String sdkName = orderEntry.getAttributeValue(ModuleJdkOrderEntryImpl.JDK_NAME_ATTR);
String newSdkName = processSdkEntry(newBuildConfiguration, oldConfiguration, sdkName);
ContainerUtil.addIfNotNull(usedSdksNames, newSdkName);
}
orderEntriesToRemove.add(orderEntry);
} else if (InheritedJdkOrderEntryImpl.ENTRY_TYPE.equals(orderEntryType)) {
if (!facet) {
String newSdkName = processSdkEntry(newBuildConfiguration, oldConfiguration, myParams.projectSdkName);
ContainerUtil.addIfNotNull(usedSdksNames, newSdkName);
}
orderEntriesToRemove.add(orderEntry);
}
}
if (facetSdkName != null) {
String newSdkName = processSdkEntry(newBuildConfiguration, oldConfiguration, facetSdkName);
ContainerUtil.addIfNotNull(usedSdksNames, newSdkName);
}
if (!orderEntriesToRemove.isEmpty()) {
module.getOrderEntries().removeAll(orderEntriesToRemove);
}
if (BCUtils.canHaveRLMsAndRuntimeStylesheets(newBuildConfiguration) && oldConfiguration != null && !oldConfiguration.CSS_FILES_LIST.isEmpty()) {
final Collection<String> cssFilesToCompile = new ArrayList<>();
for (String cssPath : oldConfiguration.CSS_FILES_LIST) {
cssFilesToCompile.add(PathUtil.getCanonicalPath(module.expandPath(cssPath)));
}
newBuildConfiguration.setCssFilesToCompile(cssFilesToCompile);
}
}
Aggregations