Search in sources :

Example 1 with AntNoFileException

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);
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) AntBuildFile(com.intellij.lang.ant.config.AntBuildFile) AntNoFileException(com.intellij.lang.ant.config.AntNoFileException) AntConfiguration(com.intellij.lang.ant.config.AntConfiguration) HashSet(java.util.HashSet)

Aggregations

AntBuildFile (com.intellij.lang.ant.config.AntBuildFile)1 AntConfiguration (com.intellij.lang.ant.config.AntConfiguration)1 AntNoFileException (com.intellij.lang.ant.config.AntNoFileException)1 Project (com.intellij.openapi.project.Project)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 HashSet (java.util.HashSet)1