*/
package org.sonar.core.dryrun;
-import org.sonar.api.ServerExtension;
-
import org.apache.commons.io.FileUtils;
+import org.sonar.api.ServerExtension;
import org.sonar.api.platform.ServerFileSystem;
import org.sonar.core.properties.PropertiesDao;
import org.sonar.core.properties.PropertyDto;
propertiesDao.setProperty(new PropertyDto().setKey(SONAR_DRY_RUN_CACHE_LAST_UPDATE_KEY).setValue(String.valueOf(System.nanoTime())));
}
- public void reportResourceModification(long projectId) {
- // Delete folder where dryRun DB are stored
- FileUtils.deleteQuietly(getCacheLocation(projectId));
-
- ResourceDto rootProject = resourceDao.getRootProjectByComponentId(projectId);
+ public void reportResourceModification(String resourceKey) {
+ ResourceDto rootProject = resourceDao.getRootProjectByComponentKey(resourceKey);
propertiesDao.setProperty(new PropertyDto().setKey(SONAR_DRY_RUN_CACHE_LAST_UPDATE_KEY).setResourceId(rootProject.getId())
.setValue(String.valueOf(System.nanoTime())));
}
import org.sonar.api.issue.internal.DefaultIssue;
import org.sonar.api.issue.internal.IssueChangeContext;
import org.sonar.api.web.UserRole;
+import org.sonar.core.dryrun.DryRunCache;
import org.sonar.core.issue.IssueNotifications;
import org.sonar.core.issue.db.IssueStorage;
import org.sonar.server.exceptions.BadRequestException;
import org.sonar.server.user.UserSession;
import java.util.Date;
+import java.util.HashSet;
import java.util.List;
+import java.util.Set;
import static com.google.common.collect.Lists.newArrayList;
private final DefaultIssueFinder issueFinder;
private final IssueStorage issueStorage;
private final IssueNotifications issueNotifications;
+ private final DryRunCache dryRunCache;
private final List<Action> actions;
- public IssueBulkChangeService(DefaultIssueFinder issueFinder, IssueStorage issueStorage, IssueNotifications issueNotifications, List<Action> actions) {
+ public IssueBulkChangeService(DefaultIssueFinder issueFinder, IssueStorage issueStorage, IssueNotifications issueNotifications, List<Action> actions, DryRunCache dryRunCache) {
this.issueFinder = issueFinder;
this.issueStorage = issueStorage;
this.issueNotifications = issueNotifications;
this.actions = actions;
+ this.dryRunCache = dryRunCache;
}
public IssueBulkChangeResult execute(IssueBulkChangeQuery issueBulkChangeQuery, UserSession userSession) {
List<Action> bulkActions = getActionsToApply(issueBulkChangeQuery, issues, userSession);
IssueChangeContext issueChangeContext = IssueChangeContext.createUser(new Date(), userSession.login());
+ Set<String> concernedProjects = new HashSet<String>();
for (Issue issue : issues) {
ActionContext actionContext = new ActionContext(issue, issueChangeContext);
for (Action action : bulkActions) {
}
issueStorage.save((DefaultIssue) issue);
issueNotifications.sendChanges((DefaultIssue) issue, issueChangeContext, issueQueryResult);
+ concernedProjects.add(((DefaultIssue) issue).projectKey());
}
}
+ // Purge dryRun cache
+ for (String projectKey : concernedProjects) {
+ dryRunCache.reportResourceModification(projectKey);
+ }
LOG.debug("BulkChange execution time : {} ms", System.currentTimeMillis() - start);
return result;
}
}
}, null);
if (action == null) {
- throw new BadRequestException("The action : '"+ actionKey + "' is unknown");
+ throw new BadRequestException("The action : '" + actionKey + "' is unknown");
}
return action;
}
import org.sonar.api.user.User;
import org.sonar.api.user.UserFinder;
import org.sonar.api.web.UserRole;
+import org.sonar.core.dryrun.DryRunCache;
import org.sonar.core.issue.IssueNotifications;
import org.sonar.core.issue.IssueUpdater;
import org.sonar.core.issue.db.IssueStorage;
import org.sonar.server.user.UserSession;
import javax.annotation.Nullable;
+
import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
private final ResourceDao resourceDao;
private final AuthorizationDao authorizationDao;
private final UserFinder userFinder;
+ private final DryRunCache dryRunCache;
public IssueService(DefaultIssueFinder finder,
- IssueWorkflow workflow,
- IssueStorage issueStorage,
- IssueUpdater issueUpdater,
- IssueNotifications issueNotifications,
- ActionPlanService actionPlanService,
- RuleFinder ruleFinder,
- ResourceDao resourceDao,
- AuthorizationDao authorizationDao,
- UserFinder userFinder) {
+ IssueWorkflow workflow,
+ IssueStorage issueStorage,
+ IssueUpdater issueUpdater,
+ IssueNotifications issueNotifications,
+ ActionPlanService actionPlanService,
+ RuleFinder ruleFinder,
+ ResourceDao resourceDao,
+ AuthorizationDao authorizationDao,
+ UserFinder userFinder,
+ DryRunCache dryRunCache) {
this.finder = finder;
this.workflow = workflow;
this.issueStorage = issueStorage;
this.resourceDao = resourceDao;
this.authorizationDao = authorizationDao;
this.userFinder = userFinder;
+ this.dryRunCache = dryRunCache;
}
/**
if (workflow.doTransition(issue, transition, context)) {
issueStorage.save(issue);
issueNotifications.sendChanges(issue, context, queryResult);
+ dryRunCache.reportResourceModification(issue.componentKey());
}
return issue;
}
User user = null;
if (!Strings.isNullOrEmpty(assignee)) {
user = userFinder.findByLogin(assignee);
- if(user == null) {
+ if (user == null) {
throw new IllegalArgumentException("Unknown user: " + assignee);
}
}
if (issueUpdater.assign(issue, user, context)) {
issueStorage.save(issue);
issueNotifications.sendChanges(issue, context, queryResult);
+ dryRunCache.reportResourceModification(issue.componentKey());
}
return issue;
}
ActionPlan actionPlan = null;
if (!Strings.isNullOrEmpty(actionPlanKey)) {
actionPlan = actionPlanService.findByKey(actionPlanKey, userSession);
- if(actionPlan == null) {
+ if (actionPlan == null) {
throw new IllegalArgumentException("Unknown action plan: " + actionPlanKey);
}
}
if (issueUpdater.plan(issue, actionPlan, context)) {
issueStorage.save(issue);
issueNotifications.sendChanges(issue, context, queryResult);
+ dryRunCache.reportResourceModification(issue.componentKey());
}
return issue;
}
if (issueUpdater.setManualSeverity(issue, severity, context)) {
issueStorage.save(issue);
issueNotifications.sendChanges(issue, context, queryResult);
+ dryRunCache.reportResourceModification(issue.componentKey());
}
return issue;
}
issue.setCreationDate(now);
issue.setUpdateDate(now);
issueStorage.save(issue);
+ dryRunCache.reportResourceModification(issue.componentKey());
return issue;
}
import org.sonar.api.issue.internal.DefaultIssue;
import org.sonar.api.issue.internal.IssueChangeContext;
import org.sonar.api.web.UserRole;
+import org.sonar.core.dryrun.DryRunCache;
import org.sonar.core.issue.IssueNotifications;
import org.sonar.core.issue.db.IssueStorage;
import org.sonar.server.exceptions.BadRequestException;
import static org.fest.assertions.Assertions.assertThat;
import static org.fest.assertions.Fail.fail;
import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.anyListOf;
+import static org.mockito.Matchers.anyMap;
import static org.mockito.Matchers.eq;
-import static org.mockito.Mockito.*;
+import static org.mockito.Mockito.doThrow;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyNoMoreInteractions;
+import static org.mockito.Mockito.verifyZeroInteractions;
+import static org.mockito.Mockito.when;
public class IssueBulkChangeServiceTest {
actions = newArrayList();
- service = new IssueBulkChangeService(finder, issueStorage, issueNotifications, actions);
+ service = new IssueBulkChangeService(finder, issueStorage, issueNotifications, actions, mock(DryRunCache.class));
}
@Test
verifyZeroInteractions(issueNotifications);
}
-
class MockAction extends Action {
private boolean verify;
import org.sonar.api.user.User;
import org.sonar.api.user.UserFinder;
import org.sonar.api.web.UserRole;
+import org.sonar.core.dryrun.DryRunCache;
import org.sonar.core.issue.DefaultActionPlan;
import org.sonar.core.issue.IssueNotifications;
import org.sonar.core.issue.IssueUpdater;
import static org.mockito.Matchers.anyLong;
import static org.mockito.Matchers.anyString;
import static org.mockito.Matchers.eq;
-import static org.mockito.Mockito.*;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyZeroInteractions;
+import static org.mockito.Mockito.when;
public class IssueServiceTest {
when(issueQueryResult.issues()).thenReturn(newArrayList((Issue) issue));
when(issueQueryResult.first()).thenReturn(issue);
- issueService = new IssueService(finder, workflow, issueStorage, issueUpdater, issueNotifications, actionPlanService, ruleFinder, resourceDao, authorizationDao, userFinder);
+ issueService = new IssueService(finder, workflow, issueStorage, issueUpdater, issueNotifications, actionPlanService, ruleFinder, resourceDao, authorizationDao, userFinder,
+ mock(DryRunCache.class));
}
@Test
@Test
public void should_fail_to_load_issue() {
- when(issueQueryResult.issues()).thenReturn(Collections.<Issue>emptyList());
+ when(issueQueryResult.issues()).thenReturn(Collections.<Issue> emptyList());
when(finder.find(any(IssueQuery.class))).thenReturn(issueQueryResult);
try {
verifyZeroInteractions(issueNotifications);
}
-
@Test
public void should_fail_do_transition_if_not_logged() {
when(userSession.isLoggedIn()).thenReturn(false);
verify(issueNotifications).sendChanges(eq(issue), eq(issueChangeContext), eq(issueQueryResult));
}
-
@Test
public void should_unassign() {
when(issueUpdater.assign(eq(issue), eq((User) null), any(IssueChangeContext.class))).thenReturn(true);
verifyZeroInteractions(issueStorage);
}
-
}