@Test public void should_build() { TaskDefinition def = TaskDefinition.builder().key("foo").taskClass(FooTask.class).description("Foo").build(); assertThat(def.key()).isEqualTo("foo"); assertThat(def.description()).isEqualTo("Foo"); assertThat(def.taskClass()).isEqualTo(FooTask.class); assertThat(def.toString()).isEqualTo("Task foo[class=org.sonar.api.task.TaskDefinitionTest$FooTask, desc=Foo]"); }
private void checkDuplicatedClasses() { Map<Class<? extends Task>, TaskDefinition> byClass = Maps.newHashMap(); for (TaskDefinition def : definitions()) { TaskDefinition other = byClass.get(def.taskClass()); if (other == null) { byClass.put(def.taskClass(), def); } else { throw new IllegalStateException("Task '" + def.taskClass().getName() + "' is defined twice: first by '" + other.key() + "' and then by '" + def.key() + "'"); } } } }
private void checkDuplicatedClasses() { Map<Class<? extends Task>, TaskDefinition> byClass = Maps.newHashMap(); for (TaskDefinition def : definitions()) { TaskDefinition other = byClass.get(def.taskClass()); if (other == null) { byClass.put(def.taskClass(), def); } else { throw new SonarException("Task '" + def.taskClass().getName() + "' is defined twice: first by '" + other.key() + "' and then by '" + def.key() + "'"); } } } }
@Override public void doAfterStart() { // default value is declared in CorePlugin String taskKey = StringUtils.defaultIfEmpty(taskProperties.get(CoreProperties.TASK), CoreProperties.SCAN_TASK); // Release memory taskProperties.clear(); TaskDefinition def = getComponentByType(Tasks.class).definition(taskKey); if (def == null) { throw MessageException.of("Task '" + taskKey + "' does not exist. Please use '" + ListTask.KEY + "' task to see all available tasks."); } Task task = getComponentByType(def.taskClass()); if (task != null) { task.execute(); } else { throw new IllegalStateException("Task " + taskKey + " is badly defined"); } } }
@Override public void doAfterStart() { // default value is declared in CorePlugin String taskKey = StringUtils.defaultIfEmpty(taskProperties.get(CoreProperties.TASK), CoreProperties.SCAN_TASK); // Release memory taskProperties.clear(); TaskDefinition def = getComponentByType(Tasks.class).definition(taskKey); if (def == null) { throw MessageException.of("Task " + taskKey + " does not exist"); } Task task = getComponentByType(def.taskClass()); if (task != null) { task.execute(); } else { throw new IllegalStateException("Task " + taskKey + " is badly defined"); } } }