use of com.intellij.conversion.impl.ConversionRunner 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.impl.ConversionRunner in project intellij-community by JetBrains.
the class ConversionServiceImpl method isConversionNeeded.
public static boolean isConversionNeeded(String projectPath) {
try {
final ConversionContextImpl context = new ConversionContextImpl(projectPath);
final List<ConversionRunner> runners = getSortedConverters(context);
if (runners.isEmpty()) {
return false;
}
for (ConversionRunner runner : runners) {
if (runner.isConversionNeeded()) {
return true;
}
}
saveConversionResult(context);
} catch (CannotConvertException e) {
LOG.info("Cannot check whether conversion of project files is needed or not, conversion won't be performed", e);
}
return false;
}
use of com.intellij.conversion.impl.ConversionRunner in project intellij-community by JetBrains.
the class ConversionServiceImpl method getConversionRunners.
private static List<ConversionRunner> getConversionRunners(ConversionContextImpl context) throws CannotConvertException {
final List<ConversionRunner> converters = getSortedConverters(context);
final Iterator<ConversionRunner> iterator = converters.iterator();
Set<String> convertersToRunIds = new HashSet<>();
while (iterator.hasNext()) {
ConversionRunner runner = iterator.next();
boolean conversionNeeded = runner.isConversionNeeded();
if (!conversionNeeded) {
for (String id : runner.getProvider().getPrecedingConverterIds()) {
if (convertersToRunIds.contains(id)) {
conversionNeeded = true;
break;
}
}
}
if (conversionNeeded) {
convertersToRunIds.add(runner.getProvider().getId());
} else {
iterator.remove();
}
}
return converters;
}
use of com.intellij.conversion.impl.ConversionRunner in project intellij-community by JetBrains.
the class ConversionServiceImpl method convert.
@NotNull
@Override
public ConversionResult convert(@NotNull String projectPath) {
try {
if (!new File(projectPath).exists() || ApplicationManager.getApplication().isHeadlessEnvironment() || !isConversionNeeded(projectPath)) {
return ConversionResultImpl.CONVERSION_NOT_NEEDED;
}
final ConversionContextImpl context = new ConversionContextImpl(projectPath);
final List<ConversionRunner> converters = getConversionRunners(context);
ConvertProjectDialog dialog = new ConvertProjectDialog(context, converters);
dialog.show();
if (dialog.isConverted()) {
saveConversionResult(context);
return new ConversionResultImpl(converters);
}
return ConversionResultImpl.CONVERSION_CANCELED;
} catch (CannotConvertException e) {
LOG.info(e);
Messages.showErrorDialog(IdeBundle.message("error.cannot.convert.project", e.getMessage()), IdeBundle.message("title.cannot.convert.project"));
return ConversionResultImpl.ERROR_OCCURRED;
}
}
use of com.intellij.conversion.impl.ConversionRunner in project intellij-community by JetBrains.
the class ConversionServiceImpl method convertSilently.
@NotNull
@Override
public ConversionResult convertSilently(@NotNull String projectPath, @NotNull ConversionListener listener) {
try {
if (!isConversionNeeded(projectPath)) {
return ConversionResultImpl.CONVERSION_NOT_NEEDED;
}
listener.conversionNeeded();
ConversionContextImpl context = new ConversionContextImpl(projectPath);
final List<ConversionRunner> runners = getConversionRunners(context);
Set<File> affectedFiles = new HashSet<>();
for (ConversionRunner runner : runners) {
affectedFiles.addAll(runner.getAffectedFiles());
}
final List<File> readOnlyFiles = ConversionRunner.getReadOnlyFiles(affectedFiles);
if (!readOnlyFiles.isEmpty()) {
listener.cannotWriteToFiles(readOnlyFiles);
return ConversionResultImpl.ERROR_OCCURRED;
}
final File backupDir = ProjectConversionUtil.backupFiles(affectedFiles, context.getProjectBaseDir());
List<ConversionRunner> usedRunners = new ArrayList<>();
for (ConversionRunner runner : runners) {
if (runner.isConversionNeeded()) {
runner.preProcess();
runner.process();
runner.postProcess();
usedRunners.add(runner);
}
}
context.saveFiles(affectedFiles, usedRunners);
listener.successfullyConverted(backupDir);
saveConversionResult(context);
return new ConversionResultImpl(runners);
} catch (CannotConvertException | IOException e) {
listener.error(e.getMessage());
}
return ConversionResultImpl.ERROR_OCCURRED;
}
Aggregations