use of com.intellij.conversion.impl.ConversionContextImpl 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.ConversionContextImpl 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.ConversionContextImpl 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;
}
use of com.intellij.conversion.impl.ConversionContextImpl in project intellij-community by JetBrains.
the class ConversionServiceImpl method convertModule.
@Override
@NotNull
public ConversionResult convertModule(@NotNull final Project project, @NotNull final File moduleFile) {
final String url = project.getPresentableUrl();
assert url != null : project;
final String projectPath = FileUtil.toSystemDependentName(url);
if (!isConversionNeeded(projectPath, moduleFile)) {
return ConversionResultImpl.CONVERSION_NOT_NEEDED;
}
final int res = Messages.showYesNoDialog(project, IdeBundle.message("message.module.file.has.an.older.format.do.you.want.to.convert.it"), IdeBundle.message("dialog.title.convert.module"), Messages.getQuestionIcon());
if (res != Messages.YES) {
return ConversionResultImpl.CONVERSION_CANCELED;
}
if (!moduleFile.canWrite()) {
Messages.showErrorDialog(project, IdeBundle.message("error.message.cannot.modify.file.0", moduleFile.getAbsolutePath()), IdeBundle.message("dialog.title.convert.module"));
return ConversionResultImpl.ERROR_OCCURRED;
}
try {
ConversionContextImpl context = new ConversionContextImpl(projectPath);
final List<ConversionRunner> runners = createConversionRunners(context, Collections.emptySet());
final File backupFile = ProjectConversionUtil.backupFile(moduleFile);
List<ConversionRunner> usedRunners = new ArrayList<>();
for (ConversionRunner runner : runners) {
if (runner.isModuleConversionNeeded(moduleFile)) {
runner.convertModule(moduleFile);
usedRunners.add(runner);
}
}
context.saveFiles(Collections.singletonList(moduleFile), usedRunners);
Messages.showInfoMessage(project, IdeBundle.message("message.your.module.was.successfully.converted.br.old.version.was.saved.to.0", backupFile.getAbsolutePath()), IdeBundle.message("dialog.title.convert.module"));
return new ConversionResultImpl(runners);
} catch (CannotConvertException e) {
LOG.info(e);
Messages.showErrorDialog(IdeBundle.message("error.cannot.load.project", e.getMessage()), "Cannot Convert Module");
return ConversionResultImpl.ERROR_OCCURRED;
} catch (IOException e) {
LOG.info(e);
return ConversionResultImpl.ERROR_OCCURRED;
}
}
use of com.intellij.conversion.impl.ConversionContextImpl in project intellij-community by JetBrains.
the class ConversionServiceImpl method isConversionNeeded.
private static boolean isConversionNeeded(String projectPath, File moduleFile) {
try {
ConversionContextImpl context = new ConversionContextImpl(projectPath);
final List<ConversionRunner> runners = createConversionRunners(context, Collections.emptySet());
for (ConversionRunner runner : runners) {
if (runner.isModuleConversionNeeded(moduleFile)) {
return true;
}
}
return false;
} catch (CannotConvertException e) {
LOG.info(e);
return false;
}
}
Aggregations