use of com.intellij.conversion.CannotConvertException in project intellij-community by JetBrains.
the class ConvertProjectDialog method doOKAction.
@Override
protected void doOKAction() {
final List<File> nonexistentFiles = myContext.getNonExistingModuleFiles();
if (!nonexistentFiles.isEmpty() && !myNonExistingFilesMessageShown) {
final String filesString = getFilesString(nonexistentFiles);
final String message = IdeBundle.message("message.text.files.do.not.exist", filesString);
final int res = Messages.showYesNoDialog(getContentPane(), message, IdeBundle.message("dialog.title.convert.project"), Messages.getQuestionIcon());
if (res != Messages.YES) {
super.doOKAction();
return;
}
myNonExistingFilesMessageShown = false;
}
try {
if (!checkReadOnlyFiles()) {
return;
}
ProjectConversionUtil.backupFiles(myAffectedFiles, myContext.getProjectBaseDir(), myBackupDir);
List<ConversionRunner> usedRunners = new ArrayList<>();
for (ConversionRunner runner : myConversionRunners) {
if (runner.isConversionNeeded()) {
runner.preProcess();
runner.process();
runner.postProcess();
usedRunners.add(runner);
}
}
myContext.saveFiles(myAffectedFiles, usedRunners);
myConverted = true;
super.doOKAction();
} catch (CannotConvertException | IOException e) {
LOG.info(e);
showErrorMessage(IdeBundle.message("error.cannot.convert.project", e.getMessage()));
}
}
use of com.intellij.conversion.CannotConvertException 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