Ejemplo n.º 1
0
 public void testDeleteRootTask() {
   AbstractTask task = new LocalTask("1", "label");
   taskList.addTask(task);
   taskList.deleteTask(task);
   assertEquals(0, taskList.getAllTasks().size());
   assertEquals(0, taskList.getDefaultCategory().getChildren().size());
 }
Ejemplo n.º 2
0
  @Override
  public void setUp() throws Exception {
    taskList = TasksUiPlugin.getTaskList();

    TaskTestUtil.resetTaskListAndRepositories();
    TasksUiPlugin.getDefault().getLocalTaskRepository();

    cat1 = new TaskCategory("First Category");
    taskList.addCategory(cat1);

    cat1task1 = TasksUiInternal.createNewLocalTask("task 1");
    cat1task1.setPriority(PriorityLevel.P1.toString());
    cat1task1.setCompletionDate(new Date());
    taskList.addTask(cat1task1, cat1);

    cat1task2 = TasksUiInternal.createNewLocalTask("task 2");
    cat1task2.setPriority(PriorityLevel.P2.toString());
    taskList.addTask(cat1task2, cat1);

    assertEquals(cat1.getChildren().size(), 2);

    activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
    assertTrue(activePage.closeAllEditors(false));
    assertEquals(0, activePage.getEditorReferences().length);
  }
Ejemplo n.º 3
0
  public void testgetQueriesAndHitsForHandle() {
    MockTask hit1 = new MockTask("1");
    MockTask hit2 = new MockTask("2");
    MockTask hit3 = new MockTask("3");

    MockTask hit1twin = new MockTask("1");
    MockTask hit2twin = new MockTask("2");
    MockTask hit3twin = new MockTask("3");

    MockRepositoryQuery query1 = new MockRepositoryQuery("query1");
    MockRepositoryQuery query2 = new MockRepositoryQuery("query2");

    taskList.addQuery(query1);
    taskList.addQuery(query2);
    taskList.addTask(hit1, query1);
    taskList.addTask(hit2, query1);
    taskList.addTask(hit3, query1);

    assertEquals(3, query1.getChildren().size());

    taskList.addTask(hit1twin, query2);
    taskList.addTask(hit2twin, query2);
    taskList.addTask(hit3twin, query2);

    assertEquals(3, query2.getChildren().size());

    Set<AbstractTaskContainer> queriesReturned = hit1.getParentContainers();
    assertNotNull(queriesReturned);
    assertEquals(2, queriesReturned.size());
    assertTrue(queriesReturned.contains(query1));
    assertTrue(queriesReturned.contains(query2));
  }
Ejemplo n.º 4
0
 public void testDeleteCategory() {
   assertEquals(1, taskList.getCategories().size());
   TaskCategory category = new TaskCategory("cat");
   taskList.addCategory(category);
   assertEquals(2, taskList.getCategories().size());
   taskList.deleteCategory(category);
   assertEquals(1, taskList.getCategories().size());
 }
Ejemplo n.º 5
0
  public void testLocalTaskAddToSelf() {
    LocalTask task = new LocalTask("1", "summary");

    taskList.addTask(task);
    assertFalse(taskList.addTask(task, task));
    assertEquals(0, task.getChildren().size());
    assertEquals(1, task.getParentContainers().size());
  }
Ejemplo n.º 6
0
 public void testDeleteCategoryMovesTasksToRoot() {
   AbstractTask task = new MockTask("delete");
   TaskCategory category = new TaskCategory("cat");
   taskList.addCategory(category);
   taskList.addTask(task, category);
   assertEquals(0, taskList.getDefaultCategory().getChildren().size());
   taskList.deleteCategory(category);
   taskList.getUnmatchedContainer(MockRepositoryConnector.REPOSITORY_URL);
 }
Ejemplo n.º 7
0
  public void testLocalSubTaskAdd() {
    LocalTask task = new LocalTask("1", "summary");
    LocalTask subTask = new LocalTask("2", "subTask");

    taskList.addTask(task);
    taskList.addTask(subTask, task);

    assertEquals(1, task.getChildren().size());
    assertEquals(subTask, task.getChildren().iterator().next());
  }
Ejemplo n.º 8
0
  @Override
  public void run() {
    if (selectedTask == null) {
      return;
    }

    if (selectedTask instanceof LocalTask) {
      // XXX code copied from NewLocalTaskWizard.performFinish() and
      // TaskListManager.createNewLocalTask()
      TaskList taskList = TasksUiPlugin.getTaskList();
      LocalTask newTask =
          new LocalTask(
              "" + taskList.getNextLocalTaskId(), // $NON-NLS-1$
              LocalRepositoryConnector.DEFAULT_SUMMARY);
      newTask.setPriority(PriorityLevel.P3.toString());
      TasksUiInternal.scheduleNewTask(newTask);
      taskList.addTask(newTask, selectedTask);
      TasksUiUtil.openTask(newTask);
      return;
    }

    AbstractRepositoryConnector connector =
        TasksUi.getRepositoryManager().getRepositoryConnector(selectedTask.getConnectorKind());
    IWizard wizard = getNewSubTaskWizard();
    if (wizard != null) {
      WizardDialog dialog = new WizardDialog(WorkbenchUtil.getShell(), wizard);
      dialog.setBlockOnOpen(true);
      dialog.open();
      return;
    }
    TaskData taskData = createTaskData(connector);
    if (taskData != null) {
      try {
        TasksUiInternal.createAndOpenNewTask(taskData);
      } catch (CoreException e) {
        StatusHandler.log(
            new Status(
                IStatus.ERROR,
                TasksUiPlugin.ID_PLUGIN,
                "Failed to open new sub task",
                e)); //$NON-NLS-1$
        TasksUiInternal.displayStatus(
            Messages.NewSubTaskAction_Unable_to_create_subtask,
            new Status(
                IStatus.ERROR,
                TasksUiPlugin.ID_PLUGIN,
                Messages.NewSubTaskAction_Failed_to_create_new_sub_task_ + e.getMessage()));
      }
    }
  }
Ejemplo n.º 9
0
  public void testGetRepositoryTasks() {
    String repositoryUrl = "https://bugs.eclipse.org/bugs";
    String bugNumber = "106939";
    MockTask task1 = new MockTask(repositoryUrl, bugNumber);
    taskList.addTask(task1);
    MockTask task2 = new MockTask("https://unresolved", bugNumber);
    taskList.addTask(task2);

    assertEquals(2, taskList.getAllTasks().size());
    Set<ITask> tasksReturned = taskList.getTasks(repositoryUrl);
    assertNotNull(tasksReturned);
    assertEquals(1, tasksReturned.size());
    assertTrue(tasksReturned.contains(task1));
  }
Ejemplo n.º 10
0
 public void testDeleteRepositoryTask() {
   String repositoryUrl = "http://somewhere.com";
   MockTask task = new MockTask(repositoryUrl, "1");
   taskList.addTask(task, taskList.getDefaultCategory());
   MockRepositoryQuery query = new MockRepositoryQuery("query");
   taskList.addQuery(query);
   taskList.addTask(task, query);
   assertEquals(1, taskList.getAllTasks().size());
   assertEquals(1, taskList.getDefaultCategory().getChildren().size());
   taskList.deleteTask(task);
   assertEquals(0, taskList.getAllTasks().size());
   assertEquals(0, taskList.getDefaultCategory().getChildren().size());
 }
Ejemplo n.º 11
0
  public void testUpdateQueryHits() {
    MockTask hit1 = new MockTask("1");
    MockTask hit2 = new MockTask("2");
    MockTask hit3 = new MockTask("3");

    MockTask hit1twin = new MockTask("1");
    MockTask hit2twin = new MockTask("2");
    MockTask hit3twin = new MockTask("3");

    MockRepositoryQuery query1 = new MockRepositoryQuery("query1");
    taskList.addQuery(query1);

    taskList.addTask(hit1, query1);
    taskList.addTask(hit2, query1);
    taskList.addTask(hit3, query1);

    taskList.addTask(hit1twin, query1);
    taskList.addTask(hit2twin, query1);
    taskList.addTask(hit3twin, query1);

    assertEquals(3, query1.getChildren().size());
    for (ITask child : query1.getChildren()) {
      taskList.removeFromContainer(query1, child);
    }
    assertEquals(0, query1.getChildren().size());
    taskList.addTask(hit1, query1);
    taskList.addTask(hit2, query1);
    assertEquals(2, query1.getChildren().size());
    hit1.setNotified(true);

    taskList.addTask(hit1twin, query1);
    taskList.addTask(hit2twin, query1);
    taskList.addTask(hit3twin, query1);
    assertEquals(3, query1.getChildren().size());
    assertTrue(query1.getChildren().contains(hit1twin));
    assertTrue(query1.getChildren().contains(hit2twin));
    assertTrue(query1.getChildren().contains(hit3twin));
    for (ITask hit : query1.getChildren()) {
      if (hit.equals(hit1twin)) {
        assertTrue(((AbstractTask) hit).isNotified());
      } else {
        assertFalse(((AbstractTask) hit).isNotified());
      }
    }
  }
Ejemplo n.º 12
0
  private IStatus rebuildIndexCompletely(SubMonitor monitor)
      throws CorruptIndexException, LockObtainFailedException, IOException, CoreException {

    MultiStatus multiStatus = new MultiStatus(TasksIndexCore.ID_PLUGIN, 0, null, null);

    // get indexable tasks from the task list
    final TaskListState taskListState = new TaskListState();
    taskList.run(taskListState, monitor.newChild(0));

    monitor.beginTask(
        Messages.TaskListIndex_task_rebuilding_index, taskListState.indexableTasks.size());
    try {
      IndexWriter writer;
      try {
        writer = createIndexWriter(true);
      } catch (CorruptIndexException e) {
        if (directory instanceof FSDirectory) {
          cleanDirectory(((FSDirectory) directory).getFile());
          writer = createIndexWriter(true);
        } else {
          throw e;
        }
      }
      try {

        for (ITask task : taskListState.indexableTasks) {
          if (taskIsIndexable(task, null)) {
            try {
              TaskData taskData = dataManager.getTaskData(task);
              add(writer, task, taskData);
            } catch (CoreException e) {
              // an individual task data error should not prevent the index from updating
              multiStatus.add(e.getStatus());
            }
          }
          monitor.worked(1);
        }
        synchronized (this) {
          rebuildIndex = false;
        }
      } finally {
        writer.close();
      }
    } finally {
      monitor.done();
    }
    return multiStatus;
  }
Ejemplo n.º 13
0
  public void testQueryAndCategoryNameClash() {
    TaskCategory category = new TaskCategory("TestClash");
    taskList.addCategory(category);
    assertTrue(taskList.getCategories().contains(category));
    assertEquals(2, taskList.getCategories().size());

    MockRepositoryQuery query = new MockRepositoryQuery("TestClash");
    taskList.addQuery(query);
    assertTrue(taskList.getCategories().contains(category));
    assertEquals(2, taskList.getCategories().size());
  }
Ejemplo n.º 14
0
 @SuppressWarnings("deprecation")
 public void testRenameCategory() {
   TaskCategory category = new TaskCategory("handle", "cat");
   taskList.addCategory(category);
   assertEquals(2, taskList.getCategories().size());
   taskList.renameContainer(category, "newDescription");
   AbstractTaskCategory container = taskList.getContainerForHandle("handle");
   assertNotNull(container);
   assertEquals("newDescription", container.getSummary());
   taskList.deleteCategory(container);
   assertEquals(1, taskList.getCategories().size());
 }
Ejemplo n.º 15
0
 @SuppressWarnings("deprecation")
 public void testDeleteCategoryAfterRename() {
   String newDesc = "newDescription";
   assertNotNull(taskList);
   assertEquals(1, taskList.getCategories().size());
   TaskCategory category = new TaskCategory("cat");
   taskList.addCategory(category);
   assertEquals(2, taskList.getCategories().size());
   taskList.renameContainer(category, newDesc);
   taskList.deleteCategory(category);
   assertEquals(1, taskList.getCategories().size());
 }
Ejemplo n.º 16
0
  private void initialize() {
    if (!rebuildIndex) {
      IndexReader indexReader = null;
      try {
        indexReader = getIndexReader();
      } catch (Exception e) {
        // ignore, this can happen if the index is corrupt
      }
      if (indexReader == null) {
        rebuildIndex = true;
      }
    }
    maintainIndexJob = new MaintainIndexJob();
    dataManager.addListener(this);
    taskList.addChangeListener(this);
    repositoryManager.addListener(this);

    scheduleIndexMaintenance(MaintainIndexType.STARTUP);
  }
Ejemplo n.º 17
0
  /**
   * finds tasks that match the given pattern string
   *
   * @param patternString the pattern string, used to match tasks
   * @param collector the collector that receives tasks
   * @param resultsLimit the maximum number of tasks to find. Specifying a limit enables the index
   *     to be more efficient since it can skip over matching tasks that do not score highly enough.
   *     Specify {@link Integer#MAX_VALUE} if there should be no limit.
   */
  public void find(String patternString, TaskCollector collector, int resultsLimit) {
    Assert.isNotNull(patternString);
    Assert.isNotNull(collector);
    Assert.isTrue(resultsLimit > 0);

    Lock readLock = indexReaderLock.readLock();
    readLock.lock();
    try {
      IndexReader indexReader = getIndexReader();
      if (indexReader != null) {
        IndexSearcher indexSearcher = new IndexSearcher(indexReader);
        try {
          Query query = computeQuery(patternString);
          TopDocs results = indexSearcher.search(query, resultsLimit);
          for (ScoreDoc scoreDoc : results.scoreDocs) {
            Document document = indexReader.document(scoreDoc.doc);
            String taskIdentifier = document.get(FIELD_IDENTIFIER.getIndexKey());
            AbstractTask task = taskList.getTask(taskIdentifier);
            if (task != null) {
              collector.collect(task);
            }
          }
        } catch (IOException e) {
          StatusHandler.log(
              new Status(
                  IStatus.ERROR,
                  TasksIndexCore.ID_PLUGIN,
                  "Unexpected failure within task list index",
                  e)); //$NON-NLS-1$
        } finally {
          try {
            indexSearcher.close();
          } catch (IOException e) {
            // ignore
          }
        }
      }
    } finally {
      readLock.unlock();
    }
  }
Ejemplo n.º 18
0
  public void close() {
    dataManager.removeListener(this);
    taskList.removeChangeListener(this);
    repositoryManager.removeListener(this);

    maintainIndexJob.cancel();
    try {
      maintainIndexJob.join();
    } catch (InterruptedException e) {
      // ignore
    }

    Lock writeLock = indexReaderLock.writeLock();
    writeLock.lock();
    try {
      synchronized (this) {
        if (indexReader != null) {
          try {
            indexReader.close();
          } catch (IOException e) {
            // ignore
          }
          indexReader = null;
        }
      }
      if (directory != null) {
        try {
          directory.close();
        } catch (IOException e) {
          StatusHandler.log(
              new Status(
                  IStatus.ERROR,
                  TasksIndexCore.ID_PLUGIN,
                  "Cannot close index: " + e.getMessage(),
                  e)); //$NON-NLS-1$
        }
      }
    } finally {
      writeLock.unlock();
    }
  }
Ejemplo n.º 19
0
 public void testCreateSameCategoryName() {
   assertEquals(1, taskList.getCategories().size());
   TaskCategory category = new TaskCategory("cat");
   taskList.addCategory(category);
   assertEquals(2, taskList.getCategories().size());
   TaskCategory category2 = new TaskCategory("cat");
   try {
     taskList.addCategory(category2);
     fail("expected IllegalArgumentException");
   } catch (IllegalArgumentException e) {
   }
   assertEquals(2, taskList.getCategories().size());
   ITaskContainer container = taskList.getContainerForHandle("cat");
   assertEquals(container, category);
 }
Ejemplo n.º 20
0
  public void testLocalSubTaskAddDeepCycle() {
    LocalTask task = new LocalTask("1", "summary");
    LocalTask subTask1 = new LocalTask("2", "subTask");
    LocalTask subTask2 = new LocalTask("3", "subTask");
    LocalTask subTask3 = new LocalTask("4", "subTask");
    LocalTask subTask4 = new LocalTask("5", "subTask");
    LocalTask subTask5 = new LocalTask("6", "subTask");
    LocalTask subTask6 = new LocalTask("7", "subTask");
    LocalTask subTask7 = new LocalTask("8", "subTask");
    LocalTask subTask8 = new LocalTask("9", "subTask");
    LocalTask subTask9 = new LocalTask("10", "subTask");
    LocalTask subTask10 = new LocalTask("11", "subTask");

    taskList.addTask(task);
    taskList.addTask(subTask1, task);
    taskList.addTask(subTask2, subTask1);
    taskList.addTask(subTask3, subTask2);
    taskList.addTask(subTask4, subTask3);
    taskList.addTask(subTask5, subTask4);
    taskList.addTask(subTask6, subTask5);
    taskList.addTask(subTask7, subTask6);
    taskList.addTask(subTask8, subTask7);
    taskList.addTask(subTask9, subTask8);
    taskList.addTask(subTask10, subTask9);

    taskList.addTask(task, subTask10);

    assertEquals(11, taskList.getAllTasks().size());
    assertEquals(1, taskList.getCategories().size());
    assertEquals(1, taskList.getCategories().iterator().next().getChildren().size());
    assertEquals(1, task.getChildren().size());
    assertEquals(subTask1, task.getChildren().iterator().next());

    assertEquals(1, subTask1.getChildren().size());
    assertEquals(subTask2, subTask1.getChildren().iterator().next());

    assertEquals(1, subTask2.getChildren().size());
    assertEquals(subTask3, subTask2.getChildren().iterator().next());

    assertEquals(1, subTask3.getChildren().size());
    assertEquals(subTask4, subTask3.getChildren().iterator().next());

    assertEquals(1, subTask4.getChildren().size());
    assertEquals(subTask5, subTask4.getChildren().iterator().next());

    assertEquals(1, subTask5.getChildren().size());
    assertEquals(subTask6, subTask5.getChildren().iterator().next());

    assertEquals(1, subTask6.getChildren().size());
    assertEquals(subTask7, subTask6.getChildren().iterator().next());

    assertEquals(1, subTask7.getChildren().size());
    assertEquals(subTask8, subTask7.getChildren().iterator().next());

    assertEquals(1, subTask8.getChildren().size());
    assertEquals(subTask9, subTask8.getChildren().iterator().next());

    assertEquals(1, subTask9.getChildren().size());
    assertEquals(subTask10, subTask9.getChildren().iterator().next());

    assertEquals(0, subTask10.getChildren().size());
  }
Ejemplo n.º 21
0
  public void testMoveToRoot() {
    AbstractTask task1 = new LocalTask("t1", "t1");
    taskList.addTask(
        task1, taskList.getUnmatchedContainer(LocalRepositoryConnector.REPOSITORY_URL));
    assertEquals(1, taskList.getDefaultCategory().getChildren().size());
    assertEquals(taskList.getDefaultCategory(), TaskCategory.getParentTaskCategory(task1));

    TaskCategory cat1 = new TaskCategory("c1");
    taskList.addCategory(cat1);

    taskList.addTask(task1, cat1);
    assertEquals(0, taskList.getDefaultCategory().getChildren().size());
    assertEquals(cat1, TaskCategory.getParentTaskCategory(task1));

    taskList.addTask(
        task1, taskList.getUnmatchedContainer(LocalRepositoryConnector.REPOSITORY_URL));
    assertEquals(1, taskList.getDefaultCategory().getChildren().size());
    assertEquals(0, cat1.getChildren().size());
    assertEquals(taskList.getDefaultCategory(), TaskCategory.getParentTaskCategory(task1));
  }
Ejemplo n.º 22
0
 public void testGetCategories() {
   taskList.addCategory(new TaskCategory("a"));
   assertEquals(2, taskList.getCategories().size());
 }
Ejemplo n.º 23
0
  public void testDeleteFromCategory() {
    assertEquals(0, taskList.getAllTasks().size());
    assertEquals(0, taskList.getDefaultCategory().getChildren().size());
    // assertEquals(0, taskList.getArchiveContainer().getChildren().size());
    assertEquals(1, taskList.getCategories().size());

    AbstractTask task = new LocalTask("1", "label");
    TaskCategory category = new TaskCategory("handleAndDescription");
    taskList.addTask(task);
    assertEquals(1, taskList.getDefaultCategory().getChildren().size());

    taskList.addCategory(category);
    taskList.addTask(task, category);
    assertEquals(2, taskList.getCategories().size());
    assertEquals(1, category.getChildren().size());
    assertEquals(0, taskList.getDefaultCategory().getChildren().size());
    assertEquals(1, taskList.getAllTasks().size());

    taskList.deleteTask(task);
    assertEquals(0, taskList.getAllTasks().size());
    assertEquals(0, taskList.getDefaultCategory().getChildren().size());
    assertEquals(0, category.getChildren().size());
  }