Browse Source

SONAR-3755 Manage errors from actions and transitions

tags/3.6
Julien Lancelot 11 years ago
parent
commit
96a2e77ad5
40 changed files with 134 additions and 1877 deletions
  1. 8
    11
      sonar-plugin-api/src/main/java/org/sonar/api/issue/condition/IsUnResolved.java
  2. 0
    45
      sonar-plugin-api/src/main/java/org/sonar/api/workflow/MutableReview.java
  3. 0
    83
      sonar-plugin-api/src/main/java/org/sonar/api/workflow/Review.java
  4. 0
    48
      sonar-plugin-api/src/main/java/org/sonar/api/workflow/WorkflowContext.java
  5. 0
    44
      sonar-plugin-api/src/main/java/org/sonar/api/workflow/condition/AdminRoleCondition.java
  6. 0
    59
      sonar-plugin-api/src/main/java/org/sonar/api/workflow/condition/Condition.java
  7. 0
    59
      sonar-plugin-api/src/main/java/org/sonar/api/workflow/condition/Conditions.java
  8. 0
    51
      sonar-plugin-api/src/main/java/org/sonar/api/workflow/condition/HasProjectPropertyCondition.java
  9. 0
    52
      sonar-plugin-api/src/main/java/org/sonar/api/workflow/condition/HasReviewPropertyCondition.java
  10. 0
    51
      sonar-plugin-api/src/main/java/org/sonar/api/workflow/condition/NotCondition.java
  11. 0
    42
      sonar-plugin-api/src/main/java/org/sonar/api/workflow/condition/ProjectPropertyCondition.java
  12. 0
    61
      sonar-plugin-api/src/main/java/org/sonar/api/workflow/condition/ResolutionCondition.java
  13. 0
    61
      sonar-plugin-api/src/main/java/org/sonar/api/workflow/condition/StatusCondition.java
  14. 0
    23
      sonar-plugin-api/src/main/java/org/sonar/api/workflow/condition/package-info.java
  15. 0
    60
      sonar-plugin-api/src/main/java/org/sonar/api/workflow/internal/DefaultComment.java
  16. 0
    215
      sonar-plugin-api/src/main/java/org/sonar/api/workflow/internal/DefaultReview.java
  17. 0
    109
      sonar-plugin-api/src/main/java/org/sonar/api/workflow/internal/DefaultWorkflowContext.java
  18. 0
    31
      sonar-plugin-api/src/main/java/org/sonar/api/workflow/internal/package-info.java
  19. 0
    24
      sonar-plugin-api/src/main/java/org/sonar/api/workflow/package-info.java
  20. 0
    38
      sonar-plugin-api/src/main/java/org/sonar/api/workflow/screen/CommentScreen.java
  21. 0
    54
      sonar-plugin-api/src/main/java/org/sonar/api/workflow/screen/Screen.java
  22. 0
    23
      sonar-plugin-api/src/main/java/org/sonar/api/workflow/screen/package-info.java
  23. 2
    3
      sonar-plugin-api/src/test/java/org/sonar/api/issue/condition/HasResolutionTest.java
  24. 11
    9
      sonar-plugin-api/src/test/java/org/sonar/api/issue/condition/IsUnResolvedTest.java
  25. 0
    44
      sonar-plugin-api/src/test/java/org/sonar/api/workflow/condition/AdminRoleConditionTest.java
  26. 0
    51
      sonar-plugin-api/src/test/java/org/sonar/api/workflow/condition/ConditionTest.java
  27. 0
    68
      sonar-plugin-api/src/test/java/org/sonar/api/workflow/condition/ConditionsTest.java
  28. 0
    63
      sonar-plugin-api/src/test/java/org/sonar/api/workflow/condition/HasProjectPropertyConditionTest.java
  29. 0
    62
      sonar-plugin-api/src/test/java/org/sonar/api/workflow/condition/HasReviewPropertyConditionTest.java
  30. 0
    53
      sonar-plugin-api/src/test/java/org/sonar/api/workflow/condition/NotConditionTest.java
  31. 0
    57
      sonar-plugin-api/src/test/java/org/sonar/api/workflow/condition/ProjectPropertyConditionTest.java
  32. 0
    61
      sonar-plugin-api/src/test/java/org/sonar/api/workflow/condition/ResolutionConditionTest.java
  33. 0
    62
      sonar-plugin-api/src/test/java/org/sonar/api/workflow/condition/StatusConditionTest.java
  34. 0
    37
      sonar-plugin-api/src/test/java/org/sonar/api/workflow/internal/DefaultReviewTest.java
  35. 54
    14
      sonar-server/src/main/java/org/sonar/server/issue/InternalRubyIssueService.java
  36. 35
    36
      sonar-server/src/main/webapp/WEB-INF/app/controllers/api/issues_controller.rb
  37. 16
    10
      sonar-server/src/main/webapp/WEB-INF/app/controllers/issue_controller.rb
  38. 6
    0
      sonar-server/src/main/webapp/WEB-INF/app/views/issue/_error.html.erb
  39. 1
    1
      sonar-server/src/main/webapp/WEB-INF/app/views/issue/_issue.html.erb
  40. 1
    2
      sonar-server/src/main/webapp/javascripts/issue.js

sonar-plugin-api/src/main/java/org/sonar/api/workflow/Comment.java → sonar-plugin-api/src/main/java/org/sonar/api/issue/condition/IsUnResolved.java View File

@@ -17,20 +17,17 @@
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.api.workflow;
package org.sonar.api.issue.condition;

import com.google.common.annotations.Beta;
import org.sonar.api.issue.Issue;

/**
* @since 3.1
* @since 3.6
*/
@Beta
public interface Comment {
String getMarkdownText();
public class IsUnResolved implements Condition {

Long getUserId();

Comment setMarkdownText(String s);

Comment setUserId(Long l);
@Override
public boolean matches(Issue issue) {
return issue.resolution() == null;
}
}

+ 0
- 45
sonar-plugin-api/src/main/java/org/sonar/api/workflow/MutableReview.java View File

@@ -1,45 +0,0 @@
/*
* SonarQube, open source software quality management tool.
* Copyright (C) 2008-2013 SonarSource
* mailto:contact AT sonarsource DOT com
*
* SonarQube is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* SonarQube is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.api.workflow;

import com.google.common.annotations.Beta;

import javax.annotation.Nullable;
import java.util.List;

/**
* Review that can be changed by functions. It does not support (yet) changes
* on creation date, author, severity, existing comments or switched-off attribute.
*
* @since 3.1
*/
@Beta
public interface MutableReview extends Review {

MutableReview setStatus(String s);

MutableReview setResolution(@Nullable String resolution);

MutableReview setProperty(String key, @Nullable String value);

Comment createComment();

List<Comment> getNewComments();
}

+ 0
- 83
sonar-plugin-api/src/main/java/org/sonar/api/workflow/Review.java View File

@@ -1,83 +0,0 @@
/*
* SonarQube, open source software quality management tool.
* Copyright (C) 2008-2013 SonarSource
* mailto:contact AT sonarsource DOT com
*
* SonarQube is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* SonarQube is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.api.workflow;

import com.google.common.annotations.Beta;

import java.util.Map;

/**
* @since 3.1
*/
@Beta
public interface Review {

/**
* This method will probably be removed in order to decrease
* coupling with database.
*
* @return not-null review id (primary key of the table REVIEWS).
*/
Long getReviewId();

/**
* @return not-null rule repository, for example "checkstyle"
*/
String getRuleRepositoryKey();

/**
* @return not-null rule key
*/
String getRuleKey();

/**
* @return not-null rule name, in English.
*/
String getRuleName();

boolean isSwitchedOff();

String getMessage();

/**
* @return not-null properties
*/
Map<String, String> getProperties();

String getStatus();

String getResolution();

/**
* @return not-null severity, from INFO to BLOCKER
*/
String getSeverity();

/**
* @return optional line, starting from 1
*/
Long getLine();

/**
* @return true if the violation has been created by an automated rule engine,
* false if created by an end-user.
*/
boolean isManual();
}

+ 0
- 48
sonar-plugin-api/src/main/java/org/sonar/api/workflow/WorkflowContext.java View File

@@ -1,48 +0,0 @@
/*
* SonarQube, open source software quality management tool.
* Copyright (C) 2008-2013 SonarSource
* mailto:contact AT sonarsource DOT com
*
* SonarQube is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* SonarQube is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.api.workflow;

import com.google.common.annotations.Beta;
import org.sonar.api.config.Settings;

/**
* @since 3.1
*/
@Beta
public interface WorkflowContext {

/**
* TODO : to be replaced by getProjectKey()
*/
Long getProjectId();

Long getUserId();

String getUserLogin();

String getUserName();

String getUserEmail();

boolean isAdmin();

Settings getProjectSettings();

}

+ 0
- 44
sonar-plugin-api/src/main/java/org/sonar/api/workflow/condition/AdminRoleCondition.java View File

@@ -1,44 +0,0 @@
/*
* SonarQube, open source software quality management tool.
* Copyright (C) 2008-2013 SonarSource
* mailto:contact AT sonarsource DOT com
*
* SonarQube is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* SonarQube is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.api.workflow.condition;

import com.google.common.annotations.Beta;
import org.sonar.api.workflow.Review;
import org.sonar.api.workflow.WorkflowContext;

import javax.annotation.Nullable;

/**
* Checks that user has admin rights on project.
*
* @since 3.1
*/
@Beta
public final class AdminRoleCondition extends Condition {

public AdminRoleCondition() {
super(true);
}

@Override
public boolean doVerify(@Nullable Review review, WorkflowContext context) {
return context.isAdmin();
}
}

+ 0
- 59
sonar-plugin-api/src/main/java/org/sonar/api/workflow/condition/Condition.java View File

@@ -1,59 +0,0 @@
/*
* SonarQube, open source software quality management tool.
* Copyright (C) 2008-2013 SonarSource
* mailto:contact AT sonarsource DOT com
*
* SonarQube is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* SonarQube is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.api.workflow.condition;

import com.google.common.annotations.Beta;
import org.sonar.api.workflow.Review;
import org.sonar.api.workflow.WorkflowContext;

import javax.annotation.Nullable;

/**
* Conditions control who can perform a command (i.e. who can see the screen
* associated to the command).
*
* @since 3.1
*/
@Beta
public abstract class Condition {

private final boolean onContext;

protected Condition(boolean onContext) {
this.onContext = onContext;
}

/**
* @return true if the condition relates to a review, false if it relates to the resource
* context (selected file, end-user, ...)
*/
public final boolean isOnContext() {
return onContext;
}

/**
* @param review the review on "review conditions" like StatusCondition, null on "context conditions"
* like AdminRoleCondition or ProjectPropertyCondition
* @param context
* @return is the condition verified ?
*/
public abstract boolean doVerify(@Nullable Review review, WorkflowContext context);

}

+ 0
- 59
sonar-plugin-api/src/main/java/org/sonar/api/workflow/condition/Conditions.java View File

@@ -1,59 +0,0 @@
/*
* SonarQube, open source software quality management tool.
* Copyright (C) 2008-2013 SonarSource
* mailto:contact AT sonarsource DOT com
*
* SonarQube is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* SonarQube is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.api.workflow.condition;

import com.google.common.annotations.Beta;

/**
* Static utility methods pertaining to {@link Condition} instances.
*
* @since 3.1
*/
@Beta
public final class Conditions {

private Conditions() {
}

public static Condition not(Condition c) {
return new NotCondition(c);
}

public static Condition hasReviewProperty(String propertyKey) {
return new HasReviewPropertyCondition(propertyKey);
}

public static Condition hasProjectProperty(String propertyKey) {
return new HasProjectPropertyCondition(propertyKey);
}

public static Condition hasAdminRole() {
return new AdminRoleCondition();
}

public static Condition statuses(String... statuses) {
return new StatusCondition(statuses);
}

public static Condition resolutions(String... resolutions) {
return new ResolutionCondition(resolutions);
}

}

+ 0
- 51
sonar-plugin-api/src/main/java/org/sonar/api/workflow/condition/HasProjectPropertyCondition.java View File

@@ -1,51 +0,0 @@
/*
* SonarQube, open source software quality management tool.
* Copyright (C) 2008-2013 SonarSource
* mailto:contact AT sonarsource DOT com
*
* SonarQube is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* SonarQube is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.api.workflow.condition;

import com.google.common.annotations.Beta;
import org.sonar.api.config.Settings;
import org.sonar.api.workflow.Review;
import org.sonar.api.workflow.WorkflowContext;

import javax.annotation.Nullable;

/**
* Checks that a project property is set, whatever its value.
*
* @since 3.1
*/
@Beta
public final class HasProjectPropertyCondition extends ProjectPropertyCondition {

public HasProjectPropertyCondition(String propertyKey) {
super(propertyKey);
}

@Override
public boolean doVerify(@Nullable Review review, WorkflowContext context) {
Settings settings = context.getProjectSettings();
return settings.hasKey(getPropertyKey()) || settings.getDefaultValue(getPropertyKey()) != null;
}

@Override
public String toString() {
return "Property " + getPropertyKey() + " must be set";
}
}

+ 0
- 52
sonar-plugin-api/src/main/java/org/sonar/api/workflow/condition/HasReviewPropertyCondition.java View File

@@ -1,52 +0,0 @@
/*
* SonarQube, open source software quality management tool.
* Copyright (C) 2008-2013 SonarSource
* mailto:contact AT sonarsource DOT com
*
* SonarQube is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* SonarQube is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.api.workflow.condition;

import com.google.common.annotations.Beta;
import com.google.common.base.Preconditions;
import com.google.common.base.Strings;
import org.sonar.api.workflow.Review;
import org.sonar.api.workflow.WorkflowContext;

import javax.annotation.Nullable;

/**
* @since 3.1
*/
@Beta
public final class HasReviewPropertyCondition extends Condition {

private final String propertyKey;

public HasReviewPropertyCondition(String propertyKey) {
super(false);
Preconditions.checkArgument(!Strings.isNullOrEmpty(propertyKey));
this.propertyKey = propertyKey;
}

public String getPropertyKey() {
return propertyKey;
}

@Override
public boolean doVerify(@Nullable Review review, WorkflowContext context) {
return review != null && !Strings.isNullOrEmpty(review.getProperties().get(propertyKey));
}
}

+ 0
- 51
sonar-plugin-api/src/main/java/org/sonar/api/workflow/condition/NotCondition.java View File

@@ -1,51 +0,0 @@
/*
* SonarQube, open source software quality management tool.
* Copyright (C) 2008-2013 SonarSource
* mailto:contact AT sonarsource DOT com
*
* SonarQube is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* SonarQube is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.api.workflow.condition;

import com.google.common.annotations.Beta;
import com.google.common.annotations.VisibleForTesting;
import org.sonar.api.workflow.Review;
import org.sonar.api.workflow.WorkflowContext;

import javax.annotation.Nullable;

/**
* @since 3.1
*/
@Beta
public final class NotCondition extends Condition {

private Condition condition;

public NotCondition(Condition c) {
super(c.isOnContext());
this.condition = c;
}

@Override
public boolean doVerify(@Nullable Review review, WorkflowContext context) {
return !condition.doVerify(review, context);
}

@VisibleForTesting
Condition getCondition() {
return condition;
}
}

+ 0
- 42
sonar-plugin-api/src/main/java/org/sonar/api/workflow/condition/ProjectPropertyCondition.java View File

@@ -1,42 +0,0 @@
/*
* SonarQube, open source software quality management tool.
* Copyright (C) 2008-2013 SonarSource
* mailto:contact AT sonarsource DOT com
*
* SonarQube is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* SonarQube is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.api.workflow.condition;

import com.google.common.annotations.Beta;
import com.google.common.base.Preconditions;
import com.google.common.base.Strings;

/**
* @since 3.1
*/
@Beta
public abstract class ProjectPropertyCondition extends Condition {
private final String propertyKey;

protected ProjectPropertyCondition(String propertyKey) {
super(true);
Preconditions.checkArgument(!Strings.isNullOrEmpty(propertyKey));
this.propertyKey = propertyKey;
}

public final String getPropertyKey() {
return propertyKey;
}
}

+ 0
- 61
sonar-plugin-api/src/main/java/org/sonar/api/workflow/condition/ResolutionCondition.java View File

@@ -1,61 +0,0 @@
/*
* SonarQube, open source software quality management tool.
* Copyright (C) 2008-2013 SonarSource
* mailto:contact AT sonarsource DOT com
*
* SonarQube is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* SonarQube is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.api.workflow.condition;

import com.google.common.annotations.Beta;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets;
import org.sonar.api.workflow.Review;
import org.sonar.api.workflow.WorkflowContext;

import javax.annotation.Nullable;
import java.util.Arrays;
import java.util.Set;

/**
* @since 3.1
*/
@Beta
public final class ResolutionCondition extends Condition {
private final Set<String> resolutions;

public ResolutionCondition(Set<String> resolutions) {
super(false);
Preconditions.checkNotNull(resolutions);
Preconditions.checkArgument(!resolutions.isEmpty(), "No resolutions defined");
this.resolutions = resolutions;
}

public ResolutionCondition(String... resolutions) {
this(Sets.newLinkedHashSet(Arrays.asList(resolutions)));
}

@Override
public boolean doVerify(@Nullable Review review, WorkflowContext context) {
return review != null && resolutions.contains(review.getResolution());
}

@VisibleForTesting
Set<String> getResolutions() {
return ImmutableSet.copyOf(resolutions);
}
}

+ 0
- 61
sonar-plugin-api/src/main/java/org/sonar/api/workflow/condition/StatusCondition.java View File

@@ -1,61 +0,0 @@
/*
* SonarQube, open source software quality management tool.
* Copyright (C) 2008-2013 SonarSource
* mailto:contact AT sonarsource DOT com
*
* SonarQube is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* SonarQube is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.api.workflow.condition;

import com.google.common.annotations.Beta;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets;
import org.sonar.api.workflow.Review;
import org.sonar.api.workflow.WorkflowContext;

import javax.annotation.Nullable;
import java.util.Arrays;
import java.util.Set;

/**
* @since 3.1
*/
@Beta
public final class StatusCondition extends Condition {
private final Set<String> statuses;

public StatusCondition(Set<String> statuses) {
super(false);
Preconditions.checkNotNull(statuses);
Preconditions.checkArgument(!statuses.isEmpty(), "No statuses defined");
this.statuses = statuses;
}

public StatusCondition(String... statuses) {
this(Sets.newLinkedHashSet(Arrays.asList(statuses)));
}

@Override
public boolean doVerify(@Nullable Review review, WorkflowContext context) {
return review != null && statuses.contains(review.getStatus());
}

@VisibleForTesting
Set<String> getStatuses() {
return ImmutableSet.copyOf(statuses);
}
}

+ 0
- 23
sonar-plugin-api/src/main/java/org/sonar/api/workflow/condition/package-info.java View File

@@ -1,23 +0,0 @@
/*
* SonarQube, open source software quality management tool.
* Copyright (C) 2008-2013 SonarSource
* mailto:contact AT sonarsource DOT com
*
* SonarQube is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* SonarQube is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
@ParametersAreNonnullByDefault
package org.sonar.api.workflow.condition;

import javax.annotation.ParametersAreNonnullByDefault;

+ 0
- 60
sonar-plugin-api/src/main/java/org/sonar/api/workflow/internal/DefaultComment.java View File

@@ -1,60 +0,0 @@
/*
* SonarQube, open source software quality management tool.
* Copyright (C) 2008-2013 SonarSource
* mailto:contact AT sonarsource DOT com
*
* SonarQube is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* SonarQube is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.api.workflow.internal;

import com.google.common.annotations.Beta;
import org.apache.commons.lang.builder.ReflectionToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
import org.sonar.api.workflow.Comment;

/**
* @since 3.1
*/
@Beta
public final class DefaultComment implements Comment {
private String markdownText;
private Long userId;

DefaultComment() {
}

public String getMarkdownText() {
return markdownText;
}

public DefaultComment setMarkdownText(String s) {
this.markdownText = s;
return this;
}

public Long getUserId() {
return userId;
}

public DefaultComment setUserId(Long l) {
this.userId = l;
return this;
}

@Override
public String toString() {
return new ReflectionToStringBuilder(this, ToStringStyle.SIMPLE_STYLE).toString();
}
}

+ 0
- 215
sonar-plugin-api/src/main/java/org/sonar/api/workflow/internal/DefaultReview.java View File

@@ -1,215 +0,0 @@
/*
* SonarQube, open source software quality management tool.
* Copyright (C) 2008-2013 SonarSource
* mailto:contact AT sonarsource DOT com
*
* SonarQube is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* SonarQube is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.api.workflow.internal;

import com.google.common.annotations.Beta;
import com.google.common.base.Preconditions;
import com.google.common.base.Strings;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import org.apache.commons.lang.builder.ReflectionToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
import org.sonar.api.workflow.Comment;
import org.sonar.api.workflow.MutableReview;
import org.sonar.api.utils.KeyValueFormat;

import javax.annotation.Nullable;
import java.util.Collections;
import java.util.List;
import java.util.Map;

/**
* @since 3.1
*/
@Beta
public final class DefaultReview implements MutableReview {

private Long violationId;
private Long reviewId;
private String ruleRepositoryKey;
private String ruleKey;
private String ruleName;
private Long line;
private boolean switchedOff = false;
private boolean manual = false;
private String message;
private String status;
private String resolution;
private String severity;
private Map<String, String> properties;
private List<Comment> newComments;

public Long getViolationId() {
return violationId;
}

public DefaultReview setViolationId(Long violationId) {
this.violationId = violationId;
return this;
}

public Long getReviewId() {
return reviewId;
}

public DefaultReview setReviewId(Long reviewId) {
this.reviewId = reviewId;
return this;
}

public String getRuleRepositoryKey() {
return ruleRepositoryKey;
}

public DefaultReview setRuleRepositoryKey(String s) {
this.ruleRepositoryKey = s;
return this;
}

public String getRuleKey() {
return ruleKey;
}

public DefaultReview setRuleKey(String s) {
this.ruleKey = s;
return this;
}

public String getRuleName() {
return ruleName;
}

public DefaultReview setRuleName(String s) {
this.ruleName = s;
return this;
}

public Long getLine() {
return line;
}

public DefaultReview setLine(Long line) {
this.line = line;
return this;
}

public boolean isSwitchedOff() {
return switchedOff;
}

public DefaultReview setSwitchedOff(boolean b) {
this.switchedOff = b;
return this;
}

public boolean isManual() {
return manual;
}

public DefaultReview setManual(boolean manual) {
this.manual = manual;
return this;
}

public String getMessage() {
return message;
}

public DefaultReview setMessage(String message) {
this.message = message;
return this;
}

public String getStatus() {
return status;
}

public DefaultReview setStatus(String s) {
Preconditions.checkArgument(!Strings.isNullOrEmpty(s));
this.status = s;
return this;
}

public String getResolution() {
return resolution;
}

public DefaultReview setResolution(@Nullable String s) {
this.resolution = s;
return this;
}

public String getSeverity() {
return severity;
}

public DefaultReview setSeverity(String s) {
Preconditions.checkArgument(!Strings.isNullOrEmpty(s));
this.severity = s;
return this;
}

public Map<String, String> getProperties() {
if (properties == null) {
return Collections.emptyMap();
}
return properties;
}

public DefaultReview setProperties(Map<String, String> properties) {
this.properties = properties;
return this;
}

public DefaultReview setPropertiesAsString(@Nullable String s) {
this.properties = (s == null ? null : KeyValueFormat.parse(s));
return this;
}

public Comment createComment() {
if (newComments == null) {
newComments = Lists.newArrayList();
}
Comment comment = new DefaultComment();
newComments.add(comment);
return comment;
}

public List<Comment> getNewComments() {
if (newComments == null) {
return Collections.emptyList();
}
return newComments;
}

public DefaultReview setProperty(String key, @Nullable String value) {
if (properties == null) {
// keeping entries ordered by key allows to have consistent behavior in unit tests
properties = Maps.newLinkedHashMap();
}
properties.put(key, value);
return this;
}

@Override
public String toString() {
return new ReflectionToStringBuilder(this, ToStringStyle.SIMPLE_STYLE).toString();
}
}

+ 0
- 109
sonar-plugin-api/src/main/java/org/sonar/api/workflow/internal/DefaultWorkflowContext.java View File

@@ -1,109 +0,0 @@
/*
* SonarQube, open source software quality management tool.
* Copyright (C) 2008-2013 SonarSource
* mailto:contact AT sonarsource DOT com
*
* SonarQube is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* SonarQube is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.api.workflow.internal;

import com.google.common.annotations.Beta;
import org.apache.commons.lang.builder.ReflectionToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
import org.sonar.api.config.Settings;
import org.sonar.api.workflow.WorkflowContext;

/**
* @since 3.1
*/
@Beta
public final class DefaultWorkflowContext implements WorkflowContext {

private Long userId;
private String userLogin;
private String userName;
private String userEmail;
private boolean isAdmin = false;
private Long projectId;
private Settings settings;

public Long getUserId() {
return userId;
}

public DefaultWorkflowContext setUserId(Long l) {
this.userId = l;
return this;
}

public String getUserLogin() {
return userLogin;
}

public DefaultWorkflowContext setUserLogin(String s) {
this.userLogin = s;
return this;
}

public String getUserName() {
return userName;
}

public DefaultWorkflowContext setUserName(String s) {
this.userName = s;
return this;
}

public String getUserEmail() {
return userEmail;
}

public DefaultWorkflowContext setUserEmail(String userEmail) {
this.userEmail = userEmail;
return this;
}

public boolean isAdmin() {
return isAdmin;
}

public DefaultWorkflowContext setIsAdmin(boolean b) {
isAdmin = b;
return this;
}

public Long getProjectId() {
return projectId;
}

public DefaultWorkflowContext setProjectId(Long l) {
this.projectId = l;
return this;
}

public Settings getProjectSettings() {
return settings;
}

public DefaultWorkflowContext setSettings(Settings s) {
this.settings = s;
return this;
}

@Override
public String toString() {
return new ReflectionToStringBuilder(this, ToStringStyle.SIMPLE_STYLE).toString();
}
}

+ 0
- 31
sonar-plugin-api/src/main/java/org/sonar/api/workflow/internal/package-info.java View File

@@ -1,31 +0,0 @@
/*
* SonarQube, open source software quality management tool.
* Copyright (C) 2008-2013 SonarSource
* mailto:contact AT sonarsource DOT com
*
* SonarQube is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* SonarQube is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/

/**
This package is not considered as API and future versions can break backward-compatibility.
<p>
It provides some classes that can be helpful for unit tests but must
<b>ABSOLUTELY NOT</b> be used by plugins production code.
</p>
*/
@ParametersAreNonnullByDefault
package org.sonar.api.workflow.internal;

import javax.annotation.ParametersAreNonnullByDefault;

+ 0
- 24
sonar-plugin-api/src/main/java/org/sonar/api/workflow/package-info.java View File

@@ -1,24 +0,0 @@
/*
* SonarQube, open source software quality management tool.
* Copyright (C) 2008-2013 SonarSource
* mailto:contact AT sonarsource DOT com
*
* SonarQube is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* SonarQube is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/

@ParametersAreNonnullByDefault
package org.sonar.api.workflow;

import javax.annotation.ParametersAreNonnullByDefault;

+ 0
- 38
sonar-plugin-api/src/main/java/org/sonar/api/workflow/screen/CommentScreen.java View File

@@ -1,38 +0,0 @@
/*
* SonarQube, open source software quality management tool.
* Copyright (C) 2008-2013 SonarSource
* mailto:contact AT sonarsource DOT com
*
* SonarQube is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* SonarQube is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.api.workflow.screen;

/**
* Form with only a textarea field to type a comment.
*/

import com.google.common.annotations.Beta;

/**
* @since 3.1
*/
@Beta
public final class CommentScreen extends Screen {

public CommentScreen() {
super("comment");
}

}

+ 0
- 54
sonar-plugin-api/src/main/java/org/sonar/api/workflow/screen/Screen.java View File

@@ -1,54 +0,0 @@
/*
* SonarQube, open source software quality management tool.
* Copyright (C) 2008-2013 SonarSource
* mailto:contact AT sonarsource DOT com
*
* SonarQube is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* SonarQube is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.api.workflow.screen;

import com.google.common.annotations.Beta;

/**
* <h2>Localization</h2>
* <p>At least two buttons must have labels :</p>
* <ul>
* <li>the button in the violation toolbar that displays the form screen. Key is 'reviews.command.<command_key>.button'.</li>
* <li>the button in the form screen that submits the command. Key is 'reviews.command.<command_key>.submit'.</li>
* </ul>
* @since 3.1
*/
@Beta
public abstract class Screen {
private final String key;
private String commandKey;

protected Screen(String key) {
this.key = key;
}

public final String getKey() {
return key;
}

public final String getCommandKey() {
return commandKey;
}

public final Screen setCommandKey(String commandKey) {
this.commandKey = commandKey;
return this;
}
}

+ 0
- 23
sonar-plugin-api/src/main/java/org/sonar/api/workflow/screen/package-info.java View File

@@ -1,23 +0,0 @@
/*
* SonarQube, open source software quality management tool.
* Copyright (C) 2008-2013 SonarSource
* mailto:contact AT sonarsource DOT com
*
* SonarQube is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* SonarQube is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
@ParametersAreNonnullByDefault
package org.sonar.api.workflow.screen;

import javax.annotation.ParametersAreNonnullByDefault;

+ 2
- 3
sonar-plugin-api/src/test/java/org/sonar/api/issue/condition/HasResolutionTest.java View File

@@ -20,6 +20,7 @@
package org.sonar.api.issue.condition;

import org.junit.Test;
import org.sonar.api.issue.Issue;
import org.sonar.api.issue.internal.DefaultIssue;

import static org.fest.assertions.Assertions.assertThat;
@@ -30,13 +31,11 @@ public class HasResolutionTest {

@Test
public void should_match() throws Exception {
HasResolution condition = new HasResolution("OPEN", "FIXED", "FALSE-POSITIVE");
HasResolution condition = new HasResolution(Issue.RESOLUTION_FIXED, Issue.RESOLUTION_FALSE_POSITIVE);

assertThat(condition.matches(issue.setResolution("OPEN"))).isTrue();
assertThat(condition.matches(issue.setResolution("FIXED"))).isTrue();
assertThat(condition.matches(issue.setResolution("FALSE-POSITIVE"))).isTrue();

assertThat(condition.matches(issue.setResolution("open"))).isFalse();
assertThat(condition.matches(issue.setResolution("Fixed"))).isFalse();
}
}

sonar-plugin-api/src/test/java/org/sonar/api/workflow/screen/CommentScreenTest.java → sonar-plugin-api/src/test/java/org/sonar/api/issue/condition/IsUnResolvedTest.java View File

@@ -17,21 +17,23 @@
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.api.workflow.screen;

package org.sonar.api.issue.condition;

import org.junit.Test;
import org.sonar.api.issue.internal.DefaultIssue;

import static org.fest.assertions.Assertions.assertThat;

public class CommentScreenTest {
@Test
public void testCommentScreen() {
CommentScreen screen = new CommentScreen();
public class IsUnResolvedTest {

assertThat(screen.getKey()).isEqualTo("comment");
DefaultIssue issue = new DefaultIssue();

@Test
public void should_match() throws Exception {
IsUnResolved condition = new IsUnResolved();

assertThat(screen.getCommandKey()).isNull();
assertThat(screen.setCommandKey("create-jira-issue"));
assertThat(screen.getCommandKey()).isEqualTo("create-jira-issue");
assertThat(condition.matches(issue)).isTrue();
assertThat(condition.matches(issue.setResolution("FIXED"))).isFalse();
}
}

+ 0
- 44
sonar-plugin-api/src/test/java/org/sonar/api/workflow/condition/AdminRoleConditionTest.java View File

@@ -1,44 +0,0 @@
/*
* SonarQube, open source software quality management tool.
* Copyright (C) 2008-2013 SonarSource
* mailto:contact AT sonarsource DOT com
*
* SonarQube is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* SonarQube is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.api.workflow.condition;

import org.junit.Test;
import org.sonar.api.workflow.internal.DefaultReview;
import org.sonar.api.workflow.internal.DefaultWorkflowContext;

import static org.fest.assertions.Assertions.assertThat;

public class AdminRoleConditionTest {
@Test
public void verifiedIfAdminRole() {
AdminRoleCondition condition = new AdminRoleCondition();
DefaultWorkflowContext context = new DefaultWorkflowContext();
context.setIsAdmin(true);
assertThat(condition.doVerify(new DefaultReview(), context)).isTrue();
}

@Test
public void failIfNotAdminRole() {
AdminRoleCondition condition = new AdminRoleCondition();
DefaultWorkflowContext context = new DefaultWorkflowContext();
context.setIsAdmin(false);
assertThat(condition.doVerify(new DefaultReview(), context)).isFalse();
}
}

+ 0
- 51
sonar-plugin-api/src/test/java/org/sonar/api/workflow/condition/ConditionTest.java View File

@@ -1,51 +0,0 @@
/*
* SonarQube, open source software quality management tool.
* Copyright (C) 2008-2013 SonarSource
* mailto:contact AT sonarsource DOT com
*
* SonarQube is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* SonarQube is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.api.workflow.condition;

import org.junit.Test;
import org.sonar.api.workflow.Review;
import org.sonar.api.workflow.WorkflowContext;

import static org.fest.assertions.Assertions.assertThat;

public class ConditionTest {
@Test
public void checkedOncePerGroupOfReviews() {
Condition condition = new Condition(true) {
@Override
public boolean doVerify(Review review, WorkflowContext context) {
return false;
}
};
assertThat(condition.isOnContext()).isTrue();
}

@Test
public void checkedForEveryReview() {
Condition condition = new Condition(false) {
@Override
public boolean doVerify(Review review, WorkflowContext context) {
return false;
}
};
assertThat(condition.isOnContext()).isFalse();
}

}

+ 0
- 68
sonar-plugin-api/src/test/java/org/sonar/api/workflow/condition/ConditionsTest.java View File

@@ -1,68 +0,0 @@
/*
* SonarQube, open source software quality management tool.
* Copyright (C) 2008-2013 SonarSource
* mailto:contact AT sonarsource DOT com
*
* SonarQube is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* SonarQube is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.api.workflow.condition;

import org.junit.Test;

import static org.fest.assertions.Assertions.assertThat;

public class ConditionsTest {
@Test
public void not() {
StatusCondition target = new StatusCondition("OPEN");
Condition not = Conditions.not(target);
assertThat(not).isInstanceOf(NotCondition.class);
assertThat(((NotCondition) not).getCondition()).isSameAs(target);
}

@Test
public void hasReviewProperty() {
Condition condition = Conditions.hasReviewProperty("foo");
assertThat(condition).isInstanceOf(HasReviewPropertyCondition.class);
assertThat(((HasReviewPropertyCondition) condition).getPropertyKey()).isEqualTo("foo");
}

@Test
public void hasProjectProperty() {
Condition condition = Conditions.hasProjectProperty("foo");
assertThat(condition).isInstanceOf(HasProjectPropertyCondition.class);
assertThat(((HasProjectPropertyCondition) condition).getPropertyKey()).isEqualTo("foo");
}

@Test
public void hasAdminRole() {
Condition condition = Conditions.hasAdminRole();
assertThat(condition).isInstanceOf(AdminRoleCondition.class);
}

@Test
public void statuses() {
Condition condition = Conditions.statuses("OPEN", "CLOSED");
assertThat(condition).isInstanceOf(StatusCondition.class);
assertThat(((StatusCondition) condition).getStatuses()).containsOnly("OPEN", "CLOSED");
}

@Test
public void resolutions() {
Condition condition = Conditions.resolutions("", "RESOLVED");
assertThat(condition).isInstanceOf(ResolutionCondition.class);
assertThat(((ResolutionCondition) condition).getResolutions()).containsOnly("", "RESOLVED");
}
}

+ 0
- 63
sonar-plugin-api/src/test/java/org/sonar/api/workflow/condition/HasProjectPropertyConditionTest.java View File

@@ -1,63 +0,0 @@
/*
* SonarQube, open source software quality management tool.
* Copyright (C) 2008-2013 SonarSource
* mailto:contact AT sonarsource DOT com
*
* SonarQube is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* SonarQube is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.api.workflow.condition;

import org.junit.Test;
import org.sonar.api.Properties;
import org.sonar.api.Property;
import org.sonar.api.config.PropertyDefinitions;
import org.sonar.api.config.Settings;
import org.sonar.api.workflow.internal.DefaultReview;
import org.sonar.api.workflow.internal.DefaultWorkflowContext;

import static org.fest.assertions.Assertions.assertThat;

public class HasProjectPropertyConditionTest {
@Test
public void doVerify() {
HasProjectPropertyCondition condition = new HasProjectPropertyCondition("jira.url");
DefaultWorkflowContext context = new DefaultWorkflowContext();
context.setSettings(new Settings().setProperty("jira.url", "http://jira"));
assertThat(condition.doVerify(new DefaultReview(), context)).isTrue();
}

@Test
public void missingProperty() {
HasProjectPropertyCondition condition = new HasProjectPropertyCondition("jira.url");
DefaultWorkflowContext context = new DefaultWorkflowContext();
context.setSettings(new Settings());
assertThat(condition.doVerify(new DefaultReview(), context)).isFalse();
}

@Test
public void returnTrueIfDefaultValue() {
HasProjectPropertyCondition condition = new HasProjectPropertyCondition("jira.url");
DefaultWorkflowContext context = new DefaultWorkflowContext();
context.setSettings(new Settings(new PropertyDefinitions().addComponent(WithDefaultValue.class)));
assertThat(condition.doVerify(new DefaultReview(), context)).isTrue();
}

@Properties({
@Property(key = "jira.url", name = "JIRA URL", defaultValue = "http://jira.com")
})
private static class WithDefaultValue {

}
}

+ 0
- 62
sonar-plugin-api/src/test/java/org/sonar/api/workflow/condition/HasReviewPropertyConditionTest.java View File

@@ -1,62 +0,0 @@
/*
* SonarQube, open source software quality management tool.
* Copyright (C) 2008-2013 SonarSource
* mailto:contact AT sonarsource DOT com
*
* SonarQube is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* SonarQube is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.api.workflow.condition;

import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.sonar.api.workflow.internal.DefaultReview;
import org.sonar.api.workflow.internal.DefaultWorkflowContext;

import static org.fest.assertions.Assertions.assertThat;

public class HasReviewPropertyConditionTest {

@Rule
public ExpectedException thrown = ExpectedException.none();

@Test
public void doVerify() {
HasReviewPropertyCondition condition = new HasReviewPropertyCondition("foo");

DefaultWorkflowContext context = new DefaultWorkflowContext();
assertThat(condition.doVerify(new DefaultReview(), context)).isFalse();
assertThat(condition.doVerify(new DefaultReview().setProperty("foo", ""), context)).isFalse();
assertThat(condition.doVerify(new DefaultReview().setProperty("foo", "bar"), context)).isTrue();
}

@Test
public void getPropertyKey() {
HasReviewPropertyCondition condition = new HasReviewPropertyCondition("foo");
assertThat(condition.getPropertyKey()).isEqualTo("foo");
}

@Test
public void failIfNullProperty() {
thrown.expect(IllegalArgumentException.class);
new HasReviewPropertyCondition(null);
}

@Test
public void failIfEmptyProperty() {
thrown.expect(IllegalArgumentException.class);
new HasReviewPropertyCondition("");
}
}

+ 0
- 53
sonar-plugin-api/src/test/java/org/sonar/api/workflow/condition/NotConditionTest.java View File

@@ -1,53 +0,0 @@
/*
* SonarQube, open source software quality management tool.
* Copyright (C) 2008-2013 SonarSource
* mailto:contact AT sonarsource DOT com
*
* SonarQube is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* SonarQube is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.api.workflow.condition;

import org.junit.Test;
import org.sonar.api.workflow.internal.DefaultReview;
import org.sonar.api.workflow.internal.DefaultWorkflowContext;
import org.sonar.api.workflow.Review;
import org.sonar.api.workflow.WorkflowContext;

import static org.fest.assertions.Assertions.assertThat;

public class NotConditionTest {
@Test
public void doVerifyInverse() {
Condition target = new TargetCondition(true);
assertThat(new NotCondition(target).doVerify(new DefaultReview(), new DefaultWorkflowContext())).isFalse();

target = new TargetCondition(false);
assertThat(new NotCondition(target).doVerify(new DefaultReview(), new DefaultWorkflowContext())).isTrue();
}

private static class TargetCondition extends Condition {
private boolean returns;

private TargetCondition(boolean returns) {
super(false);
this.returns = returns;
}

@Override
public boolean doVerify(Review review, WorkflowContext context) {
return returns;
}
}
}

+ 0
- 57
sonar-plugin-api/src/test/java/org/sonar/api/workflow/condition/ProjectPropertyConditionTest.java View File

@@ -1,57 +0,0 @@
/*
* SonarQube, open source software quality management tool.
* Copyright (C) 2008-2013 SonarSource
* mailto:contact AT sonarsource DOT com
*
* SonarQube is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* SonarQube is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.api.workflow.condition;

import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.sonar.api.workflow.Review;
import org.sonar.api.workflow.WorkflowContext;

import javax.annotation.Nullable;

import static org.fest.assertions.Assertions.assertThat;

public class ProjectPropertyConditionTest {
@Rule
public ExpectedException thrown = ExpectedException.none();

@Test
public void getPropertyKey() {
ProjectPropertyCondition condition = new ProjectPropertyCondition("foo") {
@Override
public boolean doVerify(Review review, WorkflowContext context) {
return false;
}
};
assertThat(condition.getPropertyKey()).isEqualTo("foo");
}

@Test
public void keyIsMandatory() {
thrown.expect(IllegalArgumentException.class);
new ProjectPropertyCondition(""){
@Override
public boolean doVerify(@Nullable Review review, WorkflowContext context) {
return false;
}
};
}
}

+ 0
- 61
sonar-plugin-api/src/test/java/org/sonar/api/workflow/condition/ResolutionConditionTest.java View File

@@ -1,61 +0,0 @@
/*
* SonarQube, open source software quality management tool.
* Copyright (C) 2008-2013 SonarSource
* mailto:contact AT sonarsource DOT com
*
* SonarQube is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* SonarQube is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.api.workflow.condition;

import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.sonar.api.workflow.Review;
import org.sonar.api.workflow.internal.DefaultReview;
import org.sonar.api.workflow.internal.DefaultWorkflowContext;

import static org.fest.assertions.Assertions.assertThat;

public class ResolutionConditionTest {

@Rule
public ExpectedException thrown = ExpectedException.none();

@Test
public void failIfNoResolution() {
thrown.expect(IllegalArgumentException.class);
new ResolutionCondition();
}

@Test
public void getResolutions() {
ResolutionCondition condition = new ResolutionCondition("", "RESOLVED");
assertThat(condition.getResolutions()).containsOnly("", "RESOLVED");
}

@Test
public void doVerify_review_has_resolution() {
Condition condition = new ResolutionCondition("", "RESOLVED");
Review review = new DefaultReview().setResolution("");
assertThat(condition.doVerify(review, new DefaultWorkflowContext())).isTrue();
}

@Test
public void doVerify_review_does_not_have_resolution() {
Condition condition = new ResolutionCondition("", "RESOLVED");
Review review = new DefaultReview().setResolution("OTHER");
assertThat(condition.doVerify(review, new DefaultWorkflowContext())).isFalse();
}
}

+ 0
- 62
sonar-plugin-api/src/test/java/org/sonar/api/workflow/condition/StatusConditionTest.java View File

@@ -1,62 +0,0 @@
/*
* SonarQube, open source software quality management tool.
* Copyright (C) 2008-2013 SonarSource
* mailto:contact AT sonarsource DOT com
*
* SonarQube is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* SonarQube is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.api.workflow.condition;

import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.sonar.api.workflow.Review;
import org.sonar.api.workflow.internal.DefaultReview;
import org.sonar.api.workflow.internal.DefaultWorkflowContext;

import static org.fest.assertions.Assertions.assertThat;

public class StatusConditionTest {

@Rule
public ExpectedException thrown = ExpectedException.none();

@Test
public void failIfNoStatus() {
thrown.expect(IllegalArgumentException.class);
new StatusCondition();
}


@Test
public void getStatuses() {
StatusCondition condition = new StatusCondition("OPEN", "CLOSED");
assertThat(condition.getStatuses()).containsOnly("OPEN", "CLOSED");
}

@Test
public void doVerify_review_has_status() {
Condition condition = new StatusCondition("OPEN", "CLOSED");
Review review = new DefaultReview().setStatus("CLOSED");
assertThat(condition.doVerify(review, new DefaultWorkflowContext())).isTrue();
}

@Test
public void doVerify_review_does_not_have_status() {
Condition condition = new StatusCondition("OPEN", "CLOSED");
Review review = new DefaultReview().setStatus("OTHER");
assertThat(condition.doVerify(review, new DefaultWorkflowContext())).isFalse();
}
}

+ 0
- 37
sonar-plugin-api/src/test/java/org/sonar/api/workflow/internal/DefaultReviewTest.java View File

@@ -1,37 +0,0 @@
/*
* SonarQube, open source software quality management tool.
* Copyright (C) 2008-2013 SonarSource
* mailto:contact AT sonarsource DOT com
*
* SonarQube is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* SonarQube is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package org.sonar.api.workflow.internal;

import org.junit.Test;
import org.sonar.api.workflow.MutableReview;

import static org.fest.assertions.Assertions.assertThat;

public class DefaultReviewTest {
@Test
public void createComment_keep_order() {
MutableReview review = new DefaultReview();
review.createComment().setMarkdownText("first");
review.createComment().setMarkdownText("second");
assertThat(review.getNewComments()).hasSize(2);
assertThat(review.getNewComments().get(0).getMarkdownText()).isEqualTo("first");
assertThat(review.getNewComments().get(1).getMarkdownText()).isEqualTo("second");
}
}

+ 54
- 14
sonar-server/src/main/java/org/sonar/server/issue/InternalRubyIssueService.java View File

@@ -75,7 +75,7 @@ public class InternalRubyIssueService implements ServerComponent {
this.actionService = actionService;
}

public IssueStatsFinder.IssueStatsResult findIssueAssignees(Map<String, Object> params){
public IssueStatsFinder.IssueStatsResult findIssueAssignees(Map<String, Object> params) {
return issueStatsFinder.findIssueAssignees(PublicRubyIssueService.toQuery(params));
}

@@ -100,24 +100,54 @@ public class InternalRubyIssueService implements ServerComponent {
return changeService.changelog(issueKey);
}

public Issue doTransition(String issueKey, String transitionKey) {
return issueService.doTransition(issueKey, transitionKey, UserSession.get());
public Result<Issue> doTransition(String issueKey, String transitionKey) {
Result<Issue> result = Result.of();
try {
result.set(issueService.doTransition(issueKey, transitionKey, UserSession.get()));
} catch (Exception e) {
result.addError(e.getMessage());
}
return result;
}

public Issue assign(String issueKey, @Nullable String assignee) {
return issueService.assign(issueKey, StringUtils.defaultIfBlank(assignee, null), UserSession.get());
public Result<Issue> assign(String issueKey, @Nullable String assignee) {
Result<Issue> result = Result.of();
try {
result.set(issueService.assign(issueKey, StringUtils.defaultIfBlank(assignee, null), UserSession.get()));
} catch (Exception e) {
result.addError(e.getMessage());
}
return result;
}

public Issue setSeverity(String issueKey, String severity) {
return issueService.setSeverity(issueKey, severity, UserSession.get());
public Result<Issue> setSeverity(String issueKey, String severity) {
Result<Issue> result = Result.of();
try {
result.set(issueService.setSeverity(issueKey, severity, UserSession.get()));
} catch (Exception e) {
result.addError(e.getMessage());
}
return result;
}

public Issue plan(String issueKey, @Nullable String actionPlanKey) {
return issueService.plan(issueKey, actionPlanKey, UserSession.get());
public Result<Issue> plan(String issueKey, @Nullable String actionPlanKey) {
Result<Issue> result = Result.of();
try {
result.set(issueService.plan(issueKey, actionPlanKey, UserSession.get()));
} catch (Exception e) {
result.addError(e.getMessage());
}
return result;
}

public IssueComment addComment(String issueKey, String text) {
return changeService.addComment(issueKey, text, UserSession.get());
public Result<IssueComment> addComment(String issueKey, String text) {
Result<IssueComment> result = Result.of();
try {
result.set(changeService.addComment(issueKey, text, UserSession.get()));
} catch (Exception e) {
result.addError(e.getMessage());
}
return result;
}

public IssueComment deleteComment(String commentKey) {
@@ -312,15 +342,25 @@ public class InternalRubyIssueService implements ServerComponent {
return result;
}

public Issue executeAction(String issueKey, String actionKey) {
return actionService.execute(issueKey, actionKey, UserSession.get());
public Result<Issue> executeAction(String issueKey, String actionKey) {
// TODO verify authorization

Result<Issue> result = Result.of();
try {
result.set(actionService.execute(issueKey, actionKey, UserSession.get()));
} catch (Exception e) {
result.addError(e.getMessage());
result.addError(e.getMessage());
}
return result;
}

public List<Action> listActions(String issueKey){
public List<Action> listActions(String issueKey) {
return actionService.listAvailableActions(issueKey);
}

public List<Action> listActions(Issue issue) {
return actionService.listAvailableActions(issue);
}

}

+ 35
- 36
sonar-server/src/main/webapp/WEB-INF/app/controllers/api/issues_controller.rb View File

@@ -73,14 +73,8 @@ class Api::IssuesController < Api::ApiController
verify_post_request
require_parameters :issue, :transition

issue = Internal.issues.doTransition(params[:issue], params[:transition])
if issue
render :json => jsonp({
:issue => Issue.to_hash(issue)
})
else
render :status => 400
end
result = Internal.issues.doTransition(params[:issue], params[:transition])
render_result_issue(result)
end

#
@@ -98,8 +92,17 @@ class Api::IssuesController < Api::ApiController
require_parameters :issue, :text

text = Api::Utils.read_post_request_param(params[:text])
comment = Internal.issues.addComment(params[:issue], text)
render :json => jsonp({:comment => Issue.comment_to_hash(comment)})
result = Internal.issues.addComment(params[:issue], text)

http_status = (result.ok ? 200 : 400)
hash = result_to_hash(result)
hash[:comment] = Issue.comment_to_hash(result.get) if result.get

respond_to do |format|
# if the request header "Accept" is "*/*", then the default format is the first one (json)
format.json { render :json => jsonp(hash), :status => result.httpStatus }
format.xml { render :xml => hash.to_xml(:skip_types => true, :root => 'sonar', :status => http_status) }
end
end

#
@@ -151,8 +154,8 @@ class Api::IssuesController < Api::ApiController
verify_post_request
require_parameters :issue

issue = Internal.issues.assign(params[:issue], params[:assignee])
render :json => jsonp({:issue => Issue.to_hash(issue)})
result = Internal.issues.assign(params[:issue], params[:assignee])
render_result_issue(result)
end


@@ -168,9 +171,8 @@ class Api::IssuesController < Api::ApiController
verify_post_request
require_parameters :issue, :severity

issue = Internal.issues.setSeverity(params[:issue], params[:severity])

render :json => jsonp({:issue => Issue.to_hash(issue)})
result = Internal.issues.setSeverity(params[:issue], params[:severity])
render_result_issue(result)
end

#
@@ -188,9 +190,8 @@ class Api::IssuesController < Api::ApiController

plan = nil
plan = params[:plan] if params[:plan] && !params[:plan].blank?
issue = Internal.issues.plan(params[:issue], plan)

render :json => jsonp({:issue => Issue.to_hash(issue)})
result = Internal.issues.plan(params[:issue], plan)
render_result_issue(result)
end

#
@@ -214,16 +215,7 @@ class Api::IssuesController < Api::ApiController
verify_post_request

issue_result = Internal.issues.create(params)

http_status = (issue_result.ok ? 200 : 400)
hash = result_to_hash(issue_result)
hash[:issue] = Issue.to_hash(issue_result.get) if issue_result.get

respond_to do |format|
# if the request header "Accept" is "*/*", then the default format is the first one (json)
format.json { render :json => jsonp(hash), :status => issue_result.httpStatus }
format.xml { render :xml => hash.to_xml(:skip_types => true, :root => 'sonar', :status => http_status) }
end
render_result_issue(issue_result)
end

#
@@ -254,18 +246,25 @@ class Api::IssuesController < Api::ApiController
verify_post_request
require_parameters :issue, :actionKey

issue = Internal.issues.executeAction(params[:issue], params[:actionKey])
if issue
render :json => jsonp({
:issue => Issue.to_hash(issue)
})
else
render :status => 400
end
result = Internal.issues.executeAction(params[:issue], params[:actionKey])
render_result_issue(result)
end


protected

def render_result_issue(result)
http_status = (result.ok ? 200 : 400)
hash = result_to_hash(result)
hash[:issue] = Issue.to_hash(result.get) if result.get

respond_to do |format|
# if the request header "Accept" is "*/*", then the default format is the first one (json)
format.json { render :json => jsonp(hash), :status => result.httpStatus }
format.xml { render :xml => hash.to_xml(:skip_types => true, :root => 'sonar', :status => http_status) }
end
end

def component_to_hash(component)
hash = {
:key => component.key,

+ 16
- 10
sonar-server/src/main/webapp/WEB-INF/app/controllers/issue_controller.rb View File

@@ -52,7 +52,7 @@ class IssueController < ApplicationController
require_parameters :id, :issue

@issue_result = Api.issues.find(params[:issue])
@issue = @issue_result.issues().get(0)
@issue = @issue_result.first

bad_request('Unknown issue') unless @issue

@@ -69,25 +69,31 @@ class IssueController < ApplicationController
issue_key = params[:issue]

if action_type=='comment'
Internal.issues.addComment(issue_key, params[:text])
issue_result = Internal.issues.addComment(issue_key, params[:text])
elsif action_type=='assign'
assignee = (params[:me]=='true' ? current_user.login : params[:assignee])
Internal.issues.assign(issue_key, assignee)
issue_result = Internal.issues.assign(issue_key, assignee)
elsif action_type=='transition'
Internal.issues.doTransition(issue_key, params[:transition])
issue_result = Internal.issues.doTransition(issue_key, params[:transition])
elsif action_type=='severity'
Internal.issues.setSeverity(issue_key, params[:severity])
issue_result = Internal.issues.setSeverity(issue_key, params[:severity])
elsif action_type=='plan'
Internal.issues.plan(issue_key, params[:plan])
issue_result = Internal.issues.plan(issue_key, params[:plan])
elsif action_type=='unplan'
Internal.issues.plan(issue_key, nil)
issue_result = Internal.issues.plan(issue_key, nil)
else
# Execute action defined by plugin
Internal.issues.executeAction(issue_key, action_type)
issue_result = Internal.issues.executeAction(issue_key, action_type)
end

if issue_result.ok
@issue_results = Api.issues.find(issue_key)
render :partial => 'issue/issue', :locals => {:issue => @issue_results.first}
else
@errors = issue_result.errors
render :partial => 'issue/error', :status => issue_result.httpStatus
end

@issue_results = Api.issues.find(issue_key)
render :partial => 'issue/issue', :locals => {:issue => @issue_results.issues.get(0)}
end

# Form used to edit comment

+ 6
- 0
sonar-server/src/main/webapp/WEB-INF/app/views/issue/_error.html.erb View File

@@ -0,0 +1,6 @@
<div class="error">
<% @errors.each do |msg| %>
<div><%= h (msg.text ? msg.text : Api::Utils.message(msg.l10nKey, :params => msg.l10nParams)) -%></div>
<% end %>
<%= link_to_function message('close'), 'refreshIssue(this)' -%>
</div>

+ 1
- 1
sonar-server/src/main/webapp/WEB-INF/app/views/issue/_issue.html.erb View File

@@ -61,6 +61,7 @@
<% end %>

<% if current_user %>

<div class="code-issue-actions">
<a href='#' onclick="return issueForm('comment', this)" class="link-action spacer-right"><%= message('issue.comment.formlink') -%></a>
<% unless issue.resolution %>
@@ -104,7 +105,6 @@

<%
plugin_actions = Internal.issues.listActions(issue)
puts "### "
shouldDisplayDropDown = transitions.size > 1 || !issue.resolution || !plugin_actions.empty?
if shouldDisplayDropDown
transitions.remove(0)

+ 1
- 2
sonar-server/src/main/webapp/javascripts/issue.js View File

@@ -87,8 +87,7 @@ function doIssueAction(elt, action, parameters) {
notifyIssueChange(issueKey);
}
).fail(function (jqXHR, textStatus) {
closeIssueForm(elt);
alert(textStatus);
issueElt.find('.code-issue-actions').replaceWith(jqXHR.responseText);
});
return false;
}

Loading…
Cancel
Save