use of com.intellij.lang.ant.config.AntNoFileException in project intellij-community by JetBrains.
the class AddAntBuildFile method actionPerformed.
public void actionPerformed(@NotNull AnActionEvent e) {
final Project project = e.getProject();
if (project == null) {
return;
}
final VirtualFile[] contextFiles = e.getData(CommonDataKeys.VIRTUAL_FILE_ARRAY);
if (contextFiles == null || contextFiles.length == 0) {
return;
}
final AntConfiguration antConfiguration = AntConfiguration.getInstance(project);
final Set<VirtualFile> files = new HashSet<>();
files.addAll(Arrays.asList(contextFiles));
for (AntBuildFile buildFile : antConfiguration.getBuildFileList()) {
files.remove(buildFile.getVirtualFile());
}
int filesAdded = 0;
final StringBuilder errors = new StringBuilder();
for (VirtualFile file : files) {
try {
antConfiguration.addBuildFile(file);
filesAdded++;
} catch (AntNoFileException ex) {
String message = ex.getMessage();
if (message == null || message.length() == 0) {
message = AntBundle.message("cannot.add.build.files.from.excluded.directories.error.message", ex.getFile().getPresentableUrl());
}
if (errors.length() > 0) {
errors.append("\n");
}
errors.append(message);
}
}
if (errors.length() > 0) {
Messages.showWarningDialog(project, errors.toString(), AntBundle.message("cannot.add.build.file.dialog.title"));
}
if (filesAdded > 0) {
ToolWindowManager.getInstance(project).getToolWindow(ToolWindowId.ANT_BUILD).activate(null);
}
}
Aggregations