Search in sources :

Example 1 with Task

use of com.intellij.tasks.Task in project intellij-community by JetBrains.

the class RegExResponseHandler method parseIssues.

@NotNull
@Override
public Task[] parseIssues(@NotNull String response, int max) throws Exception {
    final List<String> placeholders = getPlaceholders(myTaskRegex);
    if (!placeholders.contains(ID_PLACEHOLDER) || !placeholders.contains(SUMMARY_PLACEHOLDER)) {
        throw new Exception("Incorrect Task Pattern");
    }
    final String taskPatternWithoutPlaceholders = myTaskRegex.replaceAll("\\{.+?\\}", "");
    Matcher matcher = Pattern.compile(taskPatternWithoutPlaceholders, Pattern.CASE_INSENSITIVE | Pattern.MULTILINE | Pattern.DOTALL | Pattern.UNICODE_CASE | Pattern.CANON_EQ).matcher(response);
    List<Task> tasks = new ArrayList<>();
    for (int i = 0; i < max && matcher.find(); i++) {
        String id = matcher.group(placeholders.indexOf(ID_PLACEHOLDER) + 1);
        String summary = matcher.group(placeholders.indexOf(SUMMARY_PLACEHOLDER) + 1);
        // temporary workaround to make AssemblaIntegrationTestPass
        final String finalSummary = summary;
        summary = ApplicationManager.getApplication().runReadAction(new Computable<String>() {

            @Override
            public String compute() {
                XmlElementFactory factory = XmlElementFactory.getInstance(ProjectManager.getInstance().getDefaultProject());
                XmlTag text = factory.createTagFromText("<a>" + finalSummary + "</a>");
                String trimmedText = text.getValue().getTrimmedText();
                return XmlUtil.decode(trimmedText);
            }
        });
        tasks.add(new GenericTask(id, summary, myRepository));
    }
    return tasks.toArray(new Task[tasks.size()]);
}
Also used : Task(com.intellij.tasks.Task) Matcher(java.util.regex.Matcher) XmlElementFactory(com.intellij.psi.XmlElementFactory) ArrayList(java.util.ArrayList) Computable(com.intellij.openapi.util.Computable) XmlTag(com.intellij.psi.xml.XmlTag) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with Task

use of com.intellij.tasks.Task in project intellij-community by JetBrains.

the class TaskCheckinHandlerFactory method createHandler.

@NotNull
@Override
public CheckinHandler createHandler(@NotNull final CheckinProjectPanel panel, @NotNull final CommitContext commitContext) {
    return new CheckinHandler() {

        @Override
        public void checkinSuccessful() {
            final String message = panel.getCommitMessage();
            final Project project = panel.getProject();
            final TaskManagerImpl manager = (TaskManagerImpl) TaskManager.getManager(project);
            if (manager.getState().saveContextOnCommit) {
                Task task = findTaskInRepositories(message, manager);
                if (task == null) {
                    task = manager.createLocalTask(message);
                }
                final LocalTask localTask = manager.addTask(task);
                localTask.setUpdated(new Date());
                ApplicationManager.getApplication().invokeLater(() -> WorkingContextManager.getInstance(project).saveContext(localTask), project.getDisposed());
            }
        }
    };
}
Also used : Project(com.intellij.openapi.project.Project) Task(com.intellij.tasks.Task) LocalTask(com.intellij.tasks.LocalTask) CheckinHandler(com.intellij.openapi.vcs.checkin.CheckinHandler) LocalTask(com.intellij.tasks.LocalTask) Date(java.util.Date) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with Task

use of com.intellij.tasks.Task in project intellij-community by JetBrains.

the class TaskCheckinHandlerFactory method findTaskInRepositories.

@Nullable
private static Task findTaskInRepositories(String message, TaskManager manager) {
    TaskRepository[] repositories = manager.getAllRepositories();
    for (TaskRepository repository : repositories) {
        String id = repository.extractId(message);
        if (id == null)
            continue;
        LocalTask localTask = manager.findTask(id);
        if (localTask != null)
            return localTask;
        try {
            Task task = repository.findTask(id);
            if (task != null) {
                return task;
            }
        } catch (Exception ignore) {
        }
    }
    return null;
}
Also used : Task(com.intellij.tasks.Task) LocalTask(com.intellij.tasks.LocalTask) TaskRepository(com.intellij.tasks.TaskRepository) LocalTask(com.intellij.tasks.LocalTask) Nullable(org.jetbrains.annotations.Nullable)

Example 4 with Task

use of com.intellij.tasks.Task in project intellij-community by JetBrains.

the class GotoTaskAction method perform.

void perform(final Project project) {
    final Ref<Boolean> shiftPressed = Ref.create(false);
    final ChooseByNamePopup popup = createPopup(project, new GotoTaskPopupModel(project), new TaskItemProvider(project));
    popup.setShowListForEmptyPattern(true);
    popup.setSearchInAnyPlace(true);
    popup.setAlwaysHasMore(true);
    popup.setAdText("<html>Press SHIFT to merge with current context<br/>" + "Pressing " + KeymapUtil.getFirstKeyboardShortcutText(ActionManager.getInstance().getAction(IdeActions.ACTION_QUICK_JAVADOC)) + " would show task description and comments</html>");
    popup.registerAction("shiftPressed", KeyStroke.getKeyStroke("shift pressed SHIFT"), new AbstractAction() {

        public void actionPerformed(ActionEvent e) {
            shiftPressed.set(true);
        }
    });
    popup.registerAction("shiftReleased", KeyStroke.getKeyStroke("released SHIFT"), new AbstractAction() {

        public void actionPerformed(ActionEvent e) {
            shiftPressed.set(false);
        }
    });
    final DefaultActionGroup group = new DefaultActionGroup(new ConfigureServersAction() {

        @Override
        protected void serversChanged() {
            popup.rebuildList(true);
        }
    });
    final ActionToolbar actionToolbar = ActionManager.getInstance().createActionToolbar(ActionPlaces.UNKNOWN, group, true);
    actionToolbar.setLayoutPolicy(ActionToolbar.NOWRAP_LAYOUT_POLICY);
    actionToolbar.updateActionsImmediately();
    actionToolbar.getComponent().setFocusable(false);
    actionToolbar.getComponent().setBorder(null);
    popup.setToolArea(actionToolbar.getComponent());
    popup.setMaximumListSizeLimit(PAGE_SIZE);
    popup.setListSizeIncreasing(PAGE_SIZE);
    showNavigationPopup(new GotoActionCallback<Object>() {

        @Override
        public void elementChosen(ChooseByNamePopup popup, Object element) {
            TaskManager taskManager = TaskManager.getManager(project);
            if (element instanceof TaskPsiElement) {
                Task task = ((TaskPsiElement) element).getTask();
                LocalTask localTask = taskManager.findTask(task.getId());
                if (localTask != null) {
                    taskManager.activateTask(localTask, !shiftPressed.get());
                } else {
                    showOpenTaskDialog(project, task);
                }
            } else if (element == CREATE_NEW_TASK_ACTION) {
                LocalTask localTask = taskManager.createLocalTask(CREATE_NEW_TASK_ACTION.getTaskName());
                showOpenTaskDialog(project, localTask);
            }
        }
    }, null, popup);
}
Also used : Task(com.intellij.tasks.Task) LocalTask(com.intellij.tasks.LocalTask) ActionEvent(java.awt.event.ActionEvent) LocalTask(com.intellij.tasks.LocalTask) TaskPsiElement(com.intellij.tasks.doc.TaskPsiElement) TaskManager(com.intellij.tasks.TaskManager)

Example 5 with Task

use of com.intellij.tasks.Task in project intellij-community by JetBrains.

the class TracRepository method getIssues.

private Task[] getIssues(@Nullable String query, int max, final Transport transport) throws Exception {
    final XmlRpcClient client = getRpcClient();
    Vector<Object> result = null;
    String search = myDefaultSearch + "&max=" + max;
    if (myMaxSupported == null) {
        try {
            myMaxSupported = true;
            result = runQuery(query, transport, client, search);
        } catch (XmlRpcException e) {
            if (e.getMessage().contains("t.max")) {
                myMaxSupported = false;
            } else
                throw e;
        }
    }
    if (!myMaxSupported) {
        search = myDefaultSearch;
    }
    if (result == null) {
        result = runQuery(query, transport, client, search);
    }
    if (result == null)
        throw new Exception("Cannot connect to " + getUrl());
    ArrayList<Task> tasks = new ArrayList<>(max);
    int min = Math.min(max, result.size());
    for (int i = 0; i < min; i++) {
        Task task = getTask((Integer) result.get(i), client, transport);
        ContainerUtil.addIfNotNull(tasks, task);
    }
    return tasks.toArray(new Task[tasks.size()]);
}
Also used : Task(com.intellij.tasks.Task) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException)

Aggregations

Task (com.intellij.tasks.Task)28 LocalTask (com.intellij.tasks.LocalTask)6 NotNull (org.jetbrains.annotations.NotNull)4 TaskManager (com.intellij.tasks.TaskManager)3 TaskBuilder (com.intellij.tasks.TaskTestUtil.TaskBuilder)3 Comment (com.intellij.tasks.Comment)2 CustomTaskState (com.intellij.tasks.CustomTaskState)2 TaskManagerTestCase (com.intellij.tasks.TaskManagerTestCase)2 TaskPsiElement (com.intellij.tasks.doc.TaskPsiElement)2 GenericTask (com.intellij.tasks.generic.GenericTask)2 LocalTaskImpl (com.intellij.tasks.impl.LocalTaskImpl)2 ContainerUtil (com.intellij.util.containers.ContainerUtil)2 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 List (java.util.List)2 Nullable (org.jetbrains.annotations.Nullable)2 Gson (com.google.gson.Gson)1 EmptyProgressIndicator (com.intellij.openapi.progress.EmptyProgressIndicator)1 ProcessCanceledException (com.intellij.openapi.progress.ProcessCanceledException)1 Project (com.intellij.openapi.project.Project)1