diff options
Diffstat (limited to 'sonar-batch/src/main/java/org/sonar')
33 files changed, 30 insertions, 1074 deletions
diff --git a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchComponents.java b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchComponents.java index d40e1c223f7..879ae9afb82 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchComponents.java +++ b/sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchComponents.java @@ -40,10 +40,7 @@ import org.sonar.batch.cpd.CpdComponents; import org.sonar.batch.debt.DebtDecorator; import org.sonar.batch.debt.IssueChangelogDebtCalculator; import org.sonar.batch.debt.NewDebtDecorator; -import org.sonar.batch.issue.tracking.InitialOpenIssuesSensor; -import org.sonar.batch.issue.tracking.IssueHandlers; import org.sonar.batch.issue.tracking.IssueTracking; -import org.sonar.batch.issue.tracking.IssueTrackingDecorator; import org.sonar.batch.language.LanguageDistributionDecorator; import org.sonar.batch.scan.report.ConsoleReport; import org.sonar.batch.scan.report.HtmlReport; @@ -92,11 +89,6 @@ public class BatchComponents { DebtDecorator.class, NewDebtDecorator.class, - // Issue tracking - IssueTrackingDecorator.class, - IssueHandlers.class, - InitialOpenIssuesSensor.class, - // to be moved to compute engine UnitTestDecorator.class, LineCoverageDecorator.class, diff --git a/sonar-batch/src/main/java/org/sonar/batch/debt/DebtDecorator.java b/sonar-batch/src/main/java/org/sonar/batch/debt/DebtDecorator.java index 5ddb7e45949..b339ead086a 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/debt/DebtDecorator.java +++ b/sonar-batch/src/main/java/org/sonar/batch/debt/DebtDecorator.java @@ -38,7 +38,7 @@ import org.sonar.api.batch.rule.Rules; import org.sonar.api.component.ResourcePerspectives; import org.sonar.api.issue.Issuable; import org.sonar.api.issue.Issue; -import org.sonar.api.issue.internal.DefaultIssue; +import org.sonar.core.issue.DefaultIssue; import org.sonar.api.measures.CoreMetrics; import org.sonar.api.measures.Measure; import org.sonar.api.measures.MeasuresFilters; diff --git a/sonar-batch/src/main/java/org/sonar/batch/debt/IssueChangelogDebtCalculator.java b/sonar-batch/src/main/java/org/sonar/batch/debt/IssueChangelogDebtCalculator.java index fb882a7a0eb..5d34e8f89de 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/debt/IssueChangelogDebtCalculator.java +++ b/sonar-batch/src/main/java/org/sonar/batch/debt/IssueChangelogDebtCalculator.java @@ -34,8 +34,8 @@ import javax.annotation.Nullable; import org.apache.commons.lang.time.DateUtils; import org.sonar.api.batch.BatchSide; import org.sonar.api.issue.Issue; -import org.sonar.api.issue.internal.DefaultIssue; -import org.sonar.api.issue.internal.FieldDiffs; +import org.sonar.core.issue.DefaultIssue; +import org.sonar.core.issue.FieldDiffs; import org.sonar.core.issue.IssueUpdater; import static com.google.common.collect.Lists.newArrayList; diff --git a/sonar-batch/src/main/java/org/sonar/batch/index/ScanPersister.java b/sonar-batch/src/main/java/org/sonar/batch/index/ScanPersister.java deleted file mode 100644 index 88b749ecb18..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/index/ScanPersister.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * SonarQube, open source software quality management tool. - * Copyright (C) 2008-2014 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.batch.index; - -import org.sonar.api.batch.BatchSide; - -@BatchSide -public interface ScanPersister { - - void persist(); - -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/issue/DefaultIssuable.java b/sonar-batch/src/main/java/org/sonar/batch/issue/DefaultIssuable.java index 89561865d63..9dd268a8d22 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/issue/DefaultIssuable.java +++ b/sonar-batch/src/main/java/org/sonar/batch/issue/DefaultIssuable.java @@ -23,7 +23,7 @@ import com.google.common.collect.Lists; import java.util.List; import org.sonar.api.issue.Issuable; import org.sonar.api.issue.Issue; -import org.sonar.api.issue.internal.DefaultIssue; +import org.sonar.core.issue.DefaultIssue; import org.sonar.api.resources.Project; import org.sonar.batch.index.BatchComponent; import org.sonar.core.issue.DefaultIssueBuilder; diff --git a/sonar-batch/src/main/java/org/sonar/batch/issue/DefaultProjectIssues.java b/sonar-batch/src/main/java/org/sonar/batch/issue/DefaultProjectIssues.java index 1cc682c0e34..ed9de9a5def 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/issue/DefaultProjectIssues.java +++ b/sonar-batch/src/main/java/org/sonar/batch/issue/DefaultProjectIssues.java @@ -23,7 +23,7 @@ import com.google.common.base.Predicate; import com.google.common.collect.Iterables; import org.sonar.api.issue.Issue; import org.sonar.api.issue.ProjectIssues; -import org.sonar.api.issue.internal.DefaultIssue; +import org.sonar.core.issue.DefaultIssue; import javax.annotation.Nullable; diff --git a/sonar-batch/src/main/java/org/sonar/batch/issue/IssueCache.java b/sonar-batch/src/main/java/org/sonar/batch/issue/IssueCache.java index dc5daaaafb4..52a29fb7483 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/issue/IssueCache.java +++ b/sonar-batch/src/main/java/org/sonar/batch/issue/IssueCache.java @@ -20,7 +20,7 @@ package org.sonar.batch.issue; import org.sonar.api.batch.BatchSide; -import org.sonar.api.issue.internal.DefaultIssue; +import org.sonar.core.issue.DefaultIssue; import org.sonar.batch.index.Cache; import org.sonar.batch.index.Caches; diff --git a/sonar-batch/src/main/java/org/sonar/batch/issue/IssueFilters.java b/sonar-batch/src/main/java/org/sonar/batch/issue/IssueFilters.java index 0e623246b50..70bd4d54d5b 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/issue/IssueFilters.java +++ b/sonar-batch/src/main/java/org/sonar/batch/issue/IssueFilters.java @@ -21,7 +21,7 @@ package org.sonar.batch.issue; import org.sonar.api.batch.BatchSide; import org.sonar.api.issue.batch.IssueFilter; -import org.sonar.api.issue.internal.DefaultIssue; +import org.sonar.core.issue.DefaultIssue; @BatchSide public class IssueFilters { diff --git a/sonar-batch/src/main/java/org/sonar/batch/issue/ModuleIssues.java b/sonar-batch/src/main/java/org/sonar/batch/issue/ModuleIssues.java index 2586d4f898a..23fa523df44 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/issue/ModuleIssues.java +++ b/sonar-batch/src/main/java/org/sonar/batch/issue/ModuleIssues.java @@ -28,7 +28,7 @@ import org.sonar.api.batch.rule.ActiveRules; import org.sonar.api.batch.rule.Rule; import org.sonar.api.batch.rule.Rules; import org.sonar.api.batch.rule.internal.DefaultActiveRule; -import org.sonar.api.issue.internal.DefaultIssue; +import org.sonar.core.issue.DefaultIssue; import org.sonar.api.resources.Project; import org.sonar.api.rule.RuleKey; import org.sonar.api.rules.Violation; diff --git a/sonar-batch/src/main/java/org/sonar/batch/issue/tracking/InitialOpenIssuesSensor.java b/sonar-batch/src/main/java/org/sonar/batch/issue/tracking/InitialOpenIssuesSensor.java deleted file mode 100644 index ef39e6b77e9..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/issue/tracking/InitialOpenIssuesSensor.java +++ /dev/null @@ -1,93 +0,0 @@ -/* - * SonarQube, open source software quality management tool. - * Copyright (C) 2008-2014 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.batch.issue.tracking; - -import java.util.Calendar; -import java.util.Date; -import org.apache.commons.lang.time.DateUtils; -import org.apache.ibatis.session.ResultContext; -import org.apache.ibatis.session.ResultHandler; -import org.sonar.api.batch.RequiresDB; -import org.sonar.api.batch.Sensor; -import org.sonar.api.batch.SensorContext; -import org.sonar.api.resources.Project; -import org.sonar.core.issue.db.IssueChangeDao; -import org.sonar.core.issue.db.IssueChangeDto; -import org.sonar.core.issue.db.IssueDao; -import org.sonar.core.issue.db.IssueDto; -import org.sonar.core.resource.ResourceDao; -import org.sonar.core.resource.ResourceDto; -import org.sonar.core.resource.ResourceQuery; - -/** - * Load all the issues referenced during the previous scan. - */ -@RequiresDB -public class InitialOpenIssuesSensor implements Sensor { - - private final InitialOpenIssuesStack initialOpenIssuesStack; - private final IssueDao issueDao; - private final IssueChangeDao issueChangeDao; - private final ResourceDao resourceDao; - - public InitialOpenIssuesSensor(InitialOpenIssuesStack initialOpenIssuesStack, IssueDao issueDao, IssueChangeDao issueChangeDao, ResourceDao resourceDao) { - this.initialOpenIssuesStack = initialOpenIssuesStack; - this.issueDao = issueDao; - this.issueChangeDao = issueChangeDao; - this.resourceDao = resourceDao; - } - - @Override - public boolean shouldExecuteOnProject(Project project) { - return true; - } - - @Override - public void analyse(Project project, SensorContext context) { - ResourceDto module = resourceDao.getResource(ResourceQuery.create().setKey(project.getEffectiveKey())); - if (module != null) { - long moduleId = module.getId(); - // Adding one second is a hack for resolving conflicts with concurrent user - // changes during issue persistence - final Date now = DateUtils.addSeconds(DateUtils.truncate(new Date(), Calendar.MILLISECOND), 1); - issueDao.selectNonClosedIssuesByModule(moduleId, new ResultHandler() { - @Override - public void handleResult(ResultContext rc) { - IssueDto dto = (IssueDto) rc.getResultObject(); - dto.setSelectedAt(now.getTime()); - initialOpenIssuesStack.addIssue(dto); - } - }); - - issueChangeDao.selectChangelogOnNonClosedIssuesByModuleAndType(moduleId, new ResultHandler() { - @Override - public void handleResult(ResultContext rc) { - IssueChangeDto dto = (IssueChangeDto) rc.getResultObject(); - initialOpenIssuesStack.addChangelog(dto); - } - }); - } - } - - @Override - public String toString() { - return getClass().getSimpleName(); - } -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/issue/tracking/InitialOpenIssuesStack.java b/sonar-batch/src/main/java/org/sonar/batch/issue/tracking/InitialOpenIssuesStack.java deleted file mode 100644 index ea7b9fb6e95..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/issue/tracking/InitialOpenIssuesStack.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * SonarQube, open source software quality management tool. - * Copyright (C) 2008-2014 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.batch.issue.tracking; - -import org.sonar.api.batch.BatchSide; -import org.sonar.api.batch.InstantiationStrategy; -import org.sonar.batch.index.Cache; -import org.sonar.batch.index.Caches; -import org.sonar.core.issue.db.IssueChangeDto; -import org.sonar.core.issue.db.IssueDto; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -import static com.google.common.collect.Lists.newArrayList; - -@BatchSide -@InstantiationStrategy(InstantiationStrategy.PER_BATCH) -public class InitialOpenIssuesStack { - - private final Cache<IssueDto> issuesCache; - private final Cache<ArrayList<IssueChangeDto>> issuesChangelogCache; - - public InitialOpenIssuesStack(Caches caches) { - issuesCache = caches.createCache("last-open-issues"); - issuesChangelogCache = caches.createCache("issues-changelog"); - } - - public InitialOpenIssuesStack addIssue(IssueDto issueDto) { - issuesCache.put(issueDto.getComponentKey(), issueDto.getKee(), issueDto); - return this; - } - - public List<ServerIssue> selectAndRemoveIssues(String componentKey) { - Iterable<IssueDto> issues = issuesCache.values(componentKey); - List<ServerIssue> result = newArrayList(); - for (IssueDto issue : issues) { - result.add(new ServerIssueFromDb(issue)); - } - issuesCache.clear(componentKey); - return result; - } - - public Iterable<IssueDto> selectAllIssues() { - return issuesCache.values(); - } - - public InitialOpenIssuesStack addChangelog(IssueChangeDto issueChangeDto) { - List<IssueChangeDto> changeDtos = issuesChangelogCache.get(issueChangeDto.getIssueKey()); - if (changeDtos == null) { - changeDtos = newArrayList(); - } - changeDtos.add(issueChangeDto); - issuesChangelogCache.put(issueChangeDto.getIssueKey(), newArrayList(changeDtos)); - return this; - } - - public List<IssueChangeDto> selectChangelog(String issueKey) { - List<IssueChangeDto> changeDtos = issuesChangelogCache.get(issueKey); - return changeDtos != null ? changeDtos : Collections.<IssueChangeDto>emptyList(); - } - - public void clear() { - issuesCache.clear(); - issuesChangelogCache.clear(); - } -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/issue/tracking/IssueHandlers.java b/sonar-batch/src/main/java/org/sonar/batch/issue/tracking/IssueHandlers.java deleted file mode 100644 index c7ef0dd53c4..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/issue/tracking/IssueHandlers.java +++ /dev/null @@ -1,141 +0,0 @@ -/* - * SonarQube, open source software quality management tool. - * Copyright (C) 2008-2014 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.batch.issue.tracking; - -import org.sonar.api.batch.BatchSide; -import org.sonar.api.issue.Issue; -import org.sonar.api.issue.IssueHandler; -import org.sonar.api.issue.internal.DefaultIssue; -import org.sonar.api.issue.internal.IssueChangeContext; -import org.sonar.api.user.User; -import org.sonar.core.issue.IssueUpdater; -import org.sonar.core.user.DefaultUser; - -import javax.annotation.Nullable; - -@BatchSide -public class IssueHandlers { - private final IssueHandler[] handlers; - private final DefaultContext context; - - public IssueHandlers(IssueUpdater updater, IssueHandler[] handlers) { - this.handlers = handlers; - this.context = new DefaultContext(updater); - } - - public IssueHandlers(IssueUpdater updater) { - this(updater, new IssueHandler[0]); - } - - public void execute(DefaultIssue issue, IssueChangeContext changeContext) { - context.reset(issue, changeContext); - for (IssueHandler handler : handlers) { - handler.onIssue(context); - } - } - - static class DefaultContext implements IssueHandler.Context { - private final IssueUpdater updater; - private DefaultIssue issue; - private IssueChangeContext changeContext; - - private DefaultContext(IssueUpdater updater) { - this.updater = updater; - } - - private void reset(DefaultIssue i, IssueChangeContext changeContext) { - this.issue = i; - this.changeContext = changeContext; - } - - @Override - public Issue issue() { - return issue; - } - - @Override - public boolean isNew() { - return issue.isNew(); - } - - @Override - public boolean isEndOfLife() { - return issue.isEndOfLife(); - } - - @Override - public IssueHandler.Context setLine(@Nullable Integer line) { - updater.setLine(issue, line); - return this; - } - - @Override - public IssueHandler.Context setMessage(@Nullable String s) { - updater.setMessage(issue, s, changeContext); - return this; - } - - @Override - public IssueHandler.Context setSeverity(String severity) { - updater.setSeverity(issue, severity, changeContext); - return this; - } - - @Override - public IssueHandler.Context setAuthorLogin(@Nullable String login) { - updater.setAuthorLogin(issue, login, changeContext); - return this; - } - - @Override - public IssueHandler.Context setEffortToFix(@Nullable Double d) { - updater.setEffortToFix(issue, d, changeContext); - return this; - } - - @Override - public IssueHandler.Context setAttribute(String key, @Nullable String value) { - throw new UnsupportedOperationException("TODO"); - } - - @Override - public IssueHandler.Context assign(@Nullable String assignee) { - User user = null; - if (assignee != null) { - user = new DefaultUser().setLogin(assignee).setName(assignee); - } - updater.assign(issue, user, changeContext); - return this; - } - - @Override - public IssueHandler.Context assign(@Nullable User user) { - updater.assign(issue, user, changeContext); - return this; - } - - @Override - public IssueHandler.Context addComment(String text) { - updater.addComment(issue, text, changeContext); - return this; - } - } - -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/issue/tracking/IssueTracking.java b/sonar-batch/src/main/java/org/sonar/batch/issue/tracking/IssueTracking.java index bd339571e51..ee089357320 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/issue/tracking/IssueTracking.java +++ b/sonar-batch/src/main/java/org/sonar/batch/issue/tracking/IssueTracking.java @@ -29,7 +29,7 @@ import com.google.common.collect.Maps; import com.google.common.collect.Multimap; import org.sonar.api.batch.BatchSide; import org.sonar.api.batch.InstantiationStrategy; -import org.sonar.api.issue.internal.DefaultIssue; +import org.sonar.core.issue.DefaultIssue; import javax.annotation.Nullable; diff --git a/sonar-batch/src/main/java/org/sonar/batch/issue/tracking/IssueTrackingDecorator.java b/sonar-batch/src/main/java/org/sonar/batch/issue/tracking/IssueTrackingDecorator.java deleted file mode 100644 index 7c05341ffe1..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/issue/tracking/IssueTrackingDecorator.java +++ /dev/null @@ -1,279 +0,0 @@ -/* - * SonarQube, open source software quality management tool. - * Copyright (C) 2008-2014 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.batch.issue.tracking; - -import com.google.common.annotations.VisibleForTesting; -import com.google.common.base.Strings; -import com.google.common.collect.Lists; -import org.apache.commons.lang.StringUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.sonar.api.batch.Decorator; -import org.sonar.api.batch.DecoratorBarriers; -import org.sonar.api.batch.DecoratorContext; -import org.sonar.api.batch.DependedUpon; -import org.sonar.api.batch.DependsUpon; -import org.sonar.api.batch.RequiresDB; -import org.sonar.api.batch.fs.InputFile; -import org.sonar.api.batch.fs.internal.DefaultInputFile; -import org.sonar.api.component.ResourcePerspectives; -import org.sonar.api.issue.Issuable; -import org.sonar.api.issue.Issue; -import org.sonar.api.issue.internal.DefaultIssue; -import org.sonar.api.issue.internal.IssueChangeContext; -import org.sonar.api.profiles.RulesProfile; -import org.sonar.api.resources.File; -import org.sonar.api.resources.Project; -import org.sonar.api.resources.Resource; -import org.sonar.api.resources.ResourceUtils; -import org.sonar.api.rules.ActiveRule; -import org.sonar.api.rules.Rule; -import org.sonar.api.rules.RuleFinder; -import org.sonar.api.utils.Duration; -import org.sonar.api.utils.KeyValueFormat; -import org.sonar.batch.issue.IssueCache; -import org.sonar.batch.scan.filesystem.InputPathCache; -import org.sonar.core.issue.IssueUpdater; -import org.sonar.core.issue.db.IssueChangeDto; -import org.sonar.core.issue.db.IssueDto; -import org.sonar.core.issue.workflow.IssueWorkflow; - -import java.util.Collection; - -@DependsUpon(DecoratorBarriers.ISSUES_ADDED) -@DependedUpon(DecoratorBarriers.ISSUES_TRACKED) -@RequiresDB -public class IssueTrackingDecorator implements Decorator { - - private static final Logger LOG = LoggerFactory.getLogger(IssueTrackingDecorator.class); - - private final IssueCache issueCache; - private final InitialOpenIssuesStack initialOpenIssues; - private final IssueTracking tracking; - private final ServerLineHashesLoader lastLineHashes; - private final IssueHandlers handlers; - private final IssueWorkflow workflow; - private final IssueUpdater updater; - private final IssueChangeContext changeContext; - private final ResourcePerspectives perspectives; - private final RulesProfile rulesProfile; - private final RuleFinder ruleFinder; - private final InputPathCache inputPathCache; - private final Project project; - - public IssueTrackingDecorator(IssueCache issueCache, InitialOpenIssuesStack initialOpenIssues, IssueTracking tracking, - ServerLineHashesLoader lastLineHashes, - IssueHandlers handlers, IssueWorkflow workflow, - IssueUpdater updater, - Project project, - ResourcePerspectives perspectives, - RulesProfile rulesProfile, - RuleFinder ruleFinder, InputPathCache inputPathCache) { - this.issueCache = issueCache; - this.initialOpenIssues = initialOpenIssues; - this.tracking = tracking; - this.lastLineHashes = lastLineHashes; - this.handlers = handlers; - this.workflow = workflow; - this.updater = updater; - this.project = project; - this.inputPathCache = inputPathCache; - this.changeContext = IssueChangeContext.createScan(project.getAnalysisDate()); - this.perspectives = perspectives; - this.rulesProfile = rulesProfile; - this.ruleFinder = ruleFinder; - } - - @Override - public boolean shouldExecuteOnProject(Project project) { - return true; - } - - @Override - public void decorate(Resource resource, DecoratorContext context) { - Issuable issuable = perspectives.as(Issuable.class, resource); - if (issuable != null) { - doDecorate(resource); - } - } - - @VisibleForTesting - void doDecorate(Resource resource) { - Collection<DefaultIssue> issues = Lists.newArrayList(); - for (Issue issue : issueCache.byComponent(resource.getEffectiveKey())) { - issues.add((DefaultIssue) issue); - } - issueCache.clear(resource.getEffectiveKey()); - // issues = all the issues created by rule engines during this module scan and not excluded by filters - - // all the issues that are not closed in db before starting this module scan, including manual issues - Collection<ServerIssue> dbOpenIssues = initialOpenIssues.selectAndRemoveIssues(resource.getEffectiveKey()); - - SourceHashHolder sourceHashHolder = null; - if (ResourceUtils.isFile(resource)) { - File sonarFile = (File) resource; - InputFile file = inputPathCache.getFile(project.getEffectiveKey(), sonarFile.getPath()); - if (file == null) { - throw new IllegalStateException("File " + resource + " was not found in InputPath cache"); - } - sourceHashHolder = new SourceHashHolder((DefaultInputFile) file, lastLineHashes); - } - - IssueTrackingResult trackingResult = tracking.track(sourceHashHolder, dbOpenIssues, issues); - - // unmatched = issues that have been resolved + issues on disabled/removed rules + manual issues - addUnmatched(trackingResult.unmatched(), sourceHashHolder, issues); - - mergeMatched(trackingResult); - - if (ResourceUtils.isProject(resource)) { - // issues that relate to deleted components - addIssuesOnDeletedComponents(issues); - } - - for (DefaultIssue issue : issues) { - workflow.doAutomaticTransition(issue, changeContext); - handlers.execute(issue, changeContext); - issueCache.put(issue); - } - } - - @VisibleForTesting - protected void mergeMatched(IssueTrackingResult result) { - for (DefaultIssue issue : result.matched()) { - IssueDto ref = ((ServerIssueFromDb) result.matching(issue)).getDto(); - - // invariant fields - issue.setKey(ref.getKee()); - issue.setCreationDate(ref.getIssueCreationDate()); - issue.setUpdateDate(ref.getIssueUpdateDate()); - issue.setCloseDate(ref.getIssueCloseDate()); - - // non-persisted fields - issue.setNew(false); - issue.setEndOfLife(false); - issue.setOnDisabledRule(false); - issue.setSelectedAt(ref.getSelectedAt()); - - // fields to update with old values - issue.setActionPlanKey(ref.getActionPlanKey()); - issue.setResolution(ref.getResolution()); - issue.setStatus(ref.getStatus()); - issue.setAssignee(ref.getAssignee()); - issue.setAuthorLogin(ref.getAuthorLogin()); - issue.setTags(ref.getTags()); - - if (ref.getIssueAttributes() != null) { - issue.setAttributes(KeyValueFormat.parse(ref.getIssueAttributes())); - } - - // populate existing changelog - Collection<IssueChangeDto> issueChangeDtos = initialOpenIssues.selectChangelog(issue.key()); - for (IssueChangeDto issueChangeDto : issueChangeDtos) { - issue.addChange(issueChangeDto.toFieldDiffs()); - } - - // fields to update with current values - if (ref.isManualSeverity()) { - issue.setManualSeverity(true); - issue.setSeverity(ref.getSeverity()); - } else { - updater.setPastSeverity(issue, ref.getSeverity(), changeContext); - } - updater.setPastLine(issue, ref.getLine()); - updater.setPastMessage(issue, ref.getMessage(), changeContext); - updater.setPastEffortToFix(issue, ref.getEffortToFix(), changeContext); - Long debtInMinutes = ref.getDebt(); - Duration previousTechnicalDebt = debtInMinutes != null ? Duration.create(debtInMinutes) : null; - updater.setPastTechnicalDebt(issue, previousTechnicalDebt, changeContext); - updater.setPastProject(issue, ref.getProjectKey(), changeContext); - } - } - - private void addUnmatched(Collection<ServerIssue> unmatchedIssues, SourceHashHolder sourceHashHolder, Collection<DefaultIssue> issues) { - for (ServerIssue unmatchedIssue : unmatchedIssues) { - IssueDto unmatchedDto = ((ServerIssueFromDb) unmatchedIssue).getDto(); - DefaultIssue unmatched = unmatchedDto.toDefaultIssue(); - if (StringUtils.isNotBlank(unmatchedDto.getReporter()) && !Issue.STATUS_CLOSED.equals(unmatchedDto.getStatus())) { - relocateManualIssue(unmatched, unmatchedDto, sourceHashHolder); - } - updateUnmatchedIssue(unmatched, false /* manual issues can be kept open */); - issues.add(unmatched); - } - } - - private void addIssuesOnDeletedComponents(Collection<DefaultIssue> issues) { - for (IssueDto deadDto : initialOpenIssues.selectAllIssues()) { - DefaultIssue dead = deadDto.toDefaultIssue(); - updateUnmatchedIssue(dead, true); - issues.add(dead); - } - initialOpenIssues.clear(); - } - - private void updateUnmatchedIssue(DefaultIssue issue, boolean forceEndOfLife) { - issue.setNew(false); - - boolean manualIssue = !Strings.isNullOrEmpty(issue.reporter()); - Rule rule = ruleFinder.findByKey(issue.ruleKey()); - if (manualIssue) { - // Manual rules are not declared in Quality profiles, so no need to check ActiveRule - boolean isRemovedRule = rule == null || Rule.STATUS_REMOVED.equals(rule.getStatus()); - issue.setEndOfLife(forceEndOfLife || isRemovedRule); - issue.setOnDisabledRule(isRemovedRule); - } else { - ActiveRule activeRule = rulesProfile.getActiveRule(issue.ruleKey().repository(), issue.ruleKey().rule()); - issue.setEndOfLife(true); - issue.setOnDisabledRule(activeRule == null || rule == null || Rule.STATUS_REMOVED.equals(rule.getStatus())); - } - } - - private void relocateManualIssue(DefaultIssue newIssue, IssueDto oldIssue, SourceHashHolder sourceHashHolder) { - LOG.debug("Trying to relocate manual issue {}", oldIssue.getKee()); - - Integer previousLine = oldIssue.getLine(); - if (previousLine == null) { - LOG.debug("Cannot relocate issue at resource level"); - return; - } - - Collection<Integer> newLinesWithSameHash = sourceHashHolder.getNewLinesMatching(previousLine); - LOG.debug("Found the following lines with same hash: {}", newLinesWithSameHash); - if (newLinesWithSameHash.isEmpty()) { - if (previousLine > sourceHashHolder.getHashedSource().length()) { - LOG.debug("Old issue line {} is out of new source, closing and removing line number", previousLine); - newIssue.setLine(null); - updater.setStatus(newIssue, Issue.STATUS_CLOSED, changeContext); - updater.setResolution(newIssue, Issue.RESOLUTION_REMOVED, changeContext); - updater.setPastLine(newIssue, previousLine); - updater.setPastMessage(newIssue, oldIssue.getMessage(), changeContext); - updater.setPastEffortToFix(newIssue, oldIssue.getEffortToFix(), changeContext); - } - } else if (newLinesWithSameHash.size() == 1) { - Integer newLine = newLinesWithSameHash.iterator().next(); - LOG.debug("Relocating issue to line {}", newLine); - - newIssue.setLine(newLine); - updater.setPastLine(newIssue, previousLine); - updater.setPastMessage(newIssue, oldIssue.getMessage(), changeContext); - updater.setPastEffortToFix(newIssue, oldIssue.getEffortToFix(), changeContext); - } - } -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/issue/tracking/IssueTrackingResult.java b/sonar-batch/src/main/java/org/sonar/batch/issue/tracking/IssueTrackingResult.java index 8fe3549e66b..e04cdc240b4 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/issue/tracking/IssueTrackingResult.java +++ b/sonar-batch/src/main/java/org/sonar/batch/issue/tracking/IssueTrackingResult.java @@ -23,7 +23,7 @@ import com.google.common.collect.HashMultimap; import com.google.common.collect.Maps; import com.google.common.collect.Multimap; import org.apache.commons.lang.StringUtils; -import org.sonar.api.issue.internal.DefaultIssue; +import org.sonar.core.issue.DefaultIssue; import org.sonar.api.rule.RuleKey; import javax.annotation.Nullable; diff --git a/sonar-batch/src/main/java/org/sonar/batch/issue/tracking/LocalIssueTracking.java b/sonar-batch/src/main/java/org/sonar/batch/issue/tracking/LocalIssueTracking.java index a946c9f7dea..733e41d26a1 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/issue/tracking/LocalIssueTracking.java +++ b/sonar-batch/src/main/java/org/sonar/batch/issue/tracking/LocalIssueTracking.java @@ -29,8 +29,8 @@ import org.sonar.api.batch.fs.internal.DefaultInputFile; import org.sonar.api.batch.rule.ActiveRule; import org.sonar.api.batch.rule.ActiveRules; import org.sonar.api.issue.Issue; -import org.sonar.api.issue.internal.DefaultIssue; -import org.sonar.api.issue.internal.IssueChangeContext; +import org.sonar.core.issue.DefaultIssue; +import org.sonar.core.issue.IssueChangeContext; import org.sonar.api.resources.Project; import org.sonar.api.resources.ResourceUtils; import org.sonar.api.rule.RuleKey; @@ -166,7 +166,7 @@ public class LocalIssueTracking { // non-persisted fields issue.setNew(false); - issue.setEndOfLife(false); + issue.setBeingClosed(false); issue.setOnDisabledRule(false); // fields to update with old values @@ -226,9 +226,9 @@ public class LocalIssueTracking { boolean manualIssue = issue.ruleKey().isManual(); boolean isRemovedRule = activeRule == null; if (manualIssue) { - issue.setEndOfLife(forceEndOfLife || isRemovedRule); + issue.setBeingClosed(forceEndOfLife || isRemovedRule); } else { - issue.setEndOfLife(true); + issue.setBeingClosed(true); } issue.setOnDisabledRule(isRemovedRule); } diff --git a/sonar-batch/src/main/java/org/sonar/batch/mediumtest/TaskResult.java b/sonar-batch/src/main/java/org/sonar/batch/mediumtest/TaskResult.java index 55502e9ba78..9b6ece676b1 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/mediumtest/TaskResult.java +++ b/sonar-batch/src/main/java/org/sonar/batch/mediumtest/TaskResult.java @@ -37,7 +37,7 @@ import org.sonar.api.batch.sensor.duplication.Duplication; import org.sonar.api.batch.sensor.highlighting.TypeOfText; import org.sonar.api.batch.sensor.measure.internal.DefaultMeasure; import org.sonar.api.issue.Issue; -import org.sonar.api.issue.internal.DefaultIssue; +import org.sonar.core.issue.DefaultIssue; import org.sonar.api.measures.Measure; import org.sonar.batch.duplication.DuplicationCache; import org.sonar.batch.index.Cache.Entry; diff --git a/sonar-batch/src/main/java/org/sonar/batch/phases/PersisterExecutionEvent.java b/sonar-batch/src/main/java/org/sonar/batch/phases/PersisterExecutionEvent.java deleted file mode 100644 index cb6574591c7..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/phases/PersisterExecutionEvent.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * SonarQube, open source software quality management tool. - * Copyright (C) 2008-2014 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.batch.phases; - -import org.sonar.batch.index.ScanPersister; -import org.sonar.batch.phases.event.PersisterExecutionHandler; - -class PersisterExecutionEvent extends AbstractPhaseEvent<PersisterExecutionHandler> - implements PersisterExecutionHandler.PersisterExecutionEvent { - - private final ScanPersister persister; - - PersisterExecutionEvent(ScanPersister persister, boolean start) { - super(start); - this.persister = persister; - } - - @Override - public ScanPersister getPersister() { - return persister; - } - - @Override - public void dispatch(PersisterExecutionHandler handler) { - handler.onPersisterExecution(this); - } - - @Override - public Class getType() { - return PersisterExecutionHandler.class; - } - -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/phases/PersistersExecutor.java b/sonar-batch/src/main/java/org/sonar/batch/phases/PersistersExecutor.java deleted file mode 100644 index 8e114b6ec31..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/phases/PersistersExecutor.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * SonarQube, open source software quality management tool. - * Copyright (C) 2008-2014 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.batch.phases; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.sonar.api.batch.BatchSide; -import org.sonar.batch.bootstrap.DefaultAnalysisMode; -import org.sonar.batch.events.EventBus; -import org.sonar.batch.index.ScanPersister; - -import java.util.Arrays; - -@BatchSide -public class PersistersExecutor { - - private static final Logger LOG = LoggerFactory.getLogger(PersistersExecutor.class); - - private final ScanPersister[] persisters; - private final DefaultAnalysisMode analysisMode; - private final EventBus eventBus; - - public PersistersExecutor(DefaultAnalysisMode analysisMode, EventBus eventBus, ScanPersister[] persisters) { - this.analysisMode = analysisMode; - this.eventBus = eventBus; - this.persisters = persisters; - } - - public PersistersExecutor(DefaultAnalysisMode analysisMode, EventBus eventBus) { - this(analysisMode, eventBus, new ScanPersister[0]); - } - - public void execute() { - if (analysisMode.isDb()) { - LOG.info("Store results in database"); - eventBus.fireEvent(new PersistersPhaseEvent(Arrays.asList(persisters), true)); - for (ScanPersister persister : persisters) { - LOG.debug("Execute {}", persister.getClass().getName()); - eventBus.fireEvent(new PersisterExecutionEvent(persister, true)); - persister.persist(); - eventBus.fireEvent(new PersisterExecutionEvent(persister, false)); - } - - eventBus.fireEvent(new PersistersPhaseEvent(Arrays.asList(persisters), false)); - } - } - -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/phases/PersistersPhaseEvent.java b/sonar-batch/src/main/java/org/sonar/batch/phases/PersistersPhaseEvent.java deleted file mode 100644 index ad43c00ab36..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/phases/PersistersPhaseEvent.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * SonarQube, open source software quality management tool. - * Copyright (C) 2008-2014 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.batch.phases; - -import org.sonar.batch.index.ScanPersister; -import org.sonar.batch.phases.event.PersistersPhaseHandler; - -import java.util.List; - -class PersistersPhaseEvent extends AbstractPhaseEvent<PersistersPhaseHandler> - implements PersistersPhaseHandler.PersistersPhaseEvent { - - private final List<ScanPersister> persisters; - - PersistersPhaseEvent(List<ScanPersister> persisters, boolean start) { - super(start); - this.persisters = persisters; - } - - @Override - public List<ScanPersister> getPersisters() { - return persisters; - } - - @Override - protected void dispatch(PersistersPhaseHandler handler) { - handler.onPersistersPhase(this); - } - - @Override - protected Class getType() { - return PersistersPhaseHandler.class; - } - -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/phases/PhaseExecutor.java b/sonar-batch/src/main/java/org/sonar/batch/phases/PhaseExecutor.java index af07cf80cb0..3a616e62465 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/phases/PhaseExecutor.java +++ b/sonar-batch/src/main/java/org/sonar/batch/phases/PhaseExecutor.java @@ -44,7 +44,6 @@ public final class PhaseExecutor { private final SensorContext sensorContext; private final DefaultIndex index; private final ProjectInitializer pi; - private final PersistersExecutor persistersExecutor; private final FileSystemLogger fsLogger; private final DefaultModuleFileSystem fs; private final QProfileVerifier profileVerifier; @@ -57,7 +56,7 @@ public final class PhaseExecutor { InitializersExecutor initializersExecutor, PostJobsExecutor postJobsExecutor, SensorsExecutor sensorsExecutor, SensorContext sensorContext, DefaultIndex index, EventBus eventBus, ReportPublisher reportPublisher, ProjectInitializer pi, - PersistersExecutor persistersExecutor, FileSystemLogger fsLogger, IssuesReports jsonReport, DefaultModuleFileSystem fs, QProfileVerifier profileVerifier, + FileSystemLogger fsLogger, IssuesReports jsonReport, DefaultModuleFileSystem fs, QProfileVerifier profileVerifier, IssueExclusionsLoader issueExclusionsLoader, DefaultAnalysisMode analysisMode, LocalIssueTracking localIssueTracking) { this.decoratorsExecutor = decoratorsExecutor; this.postJobsExecutor = postJobsExecutor; @@ -68,7 +67,6 @@ public final class PhaseExecutor { this.eventBus = eventBus; this.reportPublisher = reportPublisher; this.pi = pi; - this.persistersExecutor = persistersExecutor; this.fsLogger = fsLogger; this.issuesReport = jsonReport; this.fs = fs; @@ -106,16 +104,11 @@ public final class PhaseExecutor { localIssueTracking(); } issuesReport(); - - if (!analysisMode.isPreview()) { - persistersExecutor.execute(); - } - publishReportJob(); postJobsExecutor.execute(sensorContext); } cleanMemory(); - eventBus.fireEvent(new ProjectAnalysisEvent(module, false)); + eventBus.fireEvent(new ProjectAnalysisEvent(module, false)); } private void publishReportJob() { diff --git a/sonar-batch/src/main/java/org/sonar/batch/phases/event/PersisterExecutionHandler.java b/sonar-batch/src/main/java/org/sonar/batch/phases/event/PersisterExecutionHandler.java deleted file mode 100644 index 7df8dae4ade..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/phases/event/PersisterExecutionHandler.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * SonarQube, open source software quality management tool. - * Copyright (C) 2008-2014 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.batch.phases.event; - -import org.sonar.api.batch.events.EventHandler; -import org.sonar.batch.index.ScanPersister; - -public interface PersisterExecutionHandler extends EventHandler { - - /** - * This interface is not intended to be implemented by clients. - */ - interface PersisterExecutionEvent { - - ScanPersister getPersister(); - - boolean isStart(); - - boolean isEnd(); - - } - - /** - * Called before and after execution of {@link ScanPersister}. - */ - void onPersisterExecution(PersisterExecutionEvent event); - -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/phases/event/PersistersPhaseHandler.java b/sonar-batch/src/main/java/org/sonar/batch/phases/event/PersistersPhaseHandler.java deleted file mode 100644 index 087755bacab..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/phases/event/PersistersPhaseHandler.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * SonarQube, open source software quality management tool. - * Copyright (C) 2008-2014 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.batch.phases.event; - -import org.sonar.api.batch.events.EventHandler; -import org.sonar.batch.index.ScanPersister; - -import java.util.List; - -public interface PersistersPhaseHandler extends EventHandler { - - /** - * This interface is not intended to be implemented by clients. - */ - interface PersistersPhaseEvent { - - /** - * @return list of Persisters in the order of execution - */ - List<ScanPersister> getPersisters(); - - boolean isStart(); - - boolean isEnd(); - - } - - /** - * Called before and after execution of all {@link ScanPersister}s. - */ - void onPersistersPhase(PersistersPhaseEvent event); - -} diff --git a/sonar-batch/src/main/java/org/sonar/batch/phases/event/package-info.java b/sonar-batch/src/main/java/org/sonar/batch/phases/event/package-info.java deleted file mode 100644 index 6aefbe5b6bb..00000000000 --- a/sonar-batch/src/main/java/org/sonar/batch/phases/event/package-info.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * SonarQube, open source software quality management tool. - * Copyright (C) 2008-2014 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.batch.phases.event; - -import javax.annotation.ParametersAreNonnullByDefault; diff --git a/sonar-batch/src/main/java/org/sonar/batch/postjob/DefaultPostJobContext.java b/sonar-batch/src/main/java/org/sonar/batch/postjob/DefaultPostJobContext.java index 6f46c012ce9..7b1edddabec 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/postjob/DefaultPostJobContext.java +++ b/sonar-batch/src/main/java/org/sonar/batch/postjob/DefaultPostJobContext.java @@ -28,7 +28,7 @@ import org.sonar.api.batch.postjob.PostJobContext; import org.sonar.api.batch.postjob.issue.Issue; import org.sonar.api.batch.rule.Severity; import org.sonar.api.config.Settings; -import org.sonar.api.issue.internal.DefaultIssue; +import org.sonar.core.issue.DefaultIssue; import org.sonar.api.rule.RuleKey; import org.sonar.batch.index.BatchComponent; import org.sonar.batch.index.BatchComponentCache; diff --git a/sonar-batch/src/main/java/org/sonar/batch/profiling/PhasesSumUpTimeProfiler.java b/sonar-batch/src/main/java/org/sonar/batch/profiling/PhasesSumUpTimeProfiler.java index 97e5c09dcdb..1da5585e762 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/profiling/PhasesSumUpTimeProfiler.java +++ b/sonar-batch/src/main/java/org/sonar/batch/profiling/PhasesSumUpTimeProfiler.java @@ -48,16 +48,13 @@ import org.sonar.api.utils.System2; import org.sonar.api.utils.TimeUtils; import org.sonar.batch.bootstrap.BootstrapProperties; import org.sonar.batch.events.BatchStepHandler; -import org.sonar.batch.phases.event.PersisterExecutionHandler; -import org.sonar.batch.phases.event.PersistersPhaseHandler; import org.sonar.batch.util.BatchUtils; import static org.sonar.batch.profiling.AbstractTimeProfiling.sortByDescendingTotalTime; import static org.sonar.batch.profiling.AbstractTimeProfiling.truncate; public class PhasesSumUpTimeProfiler implements ProjectAnalysisHandler, SensorExecutionHandler, DecoratorExecutionHandler, PostJobExecutionHandler, DecoratorsPhaseHandler, - SensorsPhaseHandler, PostJobsPhaseHandler, InitializersPhaseHandler, InitializerExecutionHandler, BatchStepHandler, PersistersPhaseHandler, - PersisterExecutionHandler { + SensorsPhaseHandler, PostJobsPhaseHandler, InitializersPhaseHandler, InitializerExecutionHandler, BatchStepHandler { static final Logger LOG = LoggerFactory.getLogger(PhasesSumUpTimeProfiler.class); private static final int TEXT_RIGHT_PAD = 60; @@ -175,25 +172,6 @@ public class PhasesSumUpTimeProfiler implements ProjectAnalysisHandler, SensorEx } @Override - public void onPersistersPhase(PersistersPhaseEvent event) { - if (event.isStart()) { - currentModuleProfiling.addPhaseProfiling(Phase.PERSISTER); - } else { - currentModuleProfiling.getProfilingPerPhase(Phase.PERSISTER).stop(); - } - } - - @Override - public void onPersisterExecution(PersisterExecutionEvent event) { - PhaseProfiling profiling = currentModuleProfiling.getProfilingPerPhase(Phase.PERSISTER); - if (event.isStart()) { - profiling.newItemProfiling(event.getPersister()); - } else { - profiling.getProfilingPerItem(event.getPersister()).stop(); - } - } - - @Override public void onDecoratorExecution(DecoratorExecutionEvent event) { PhaseProfiling profiling = currentModuleProfiling.getProfilingPerPhase(Phase.DECORATOR); if (event.isStart()) { diff --git a/sonar-batch/src/main/java/org/sonar/batch/report/IssuesPublisher.java b/sonar-batch/src/main/java/org/sonar/batch/report/IssuesPublisher.java index 08be39df953..0377b3e0889 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/report/IssuesPublisher.java +++ b/sonar-batch/src/main/java/org/sonar/batch/report/IssuesPublisher.java @@ -21,14 +21,8 @@ package org.sonar.batch.report; import com.google.common.base.Function; import com.google.common.collect.Iterables; -import java.util.Collection; -import java.util.Date; -import java.util.Iterator; -import javax.annotation.Nullable; import org.sonar.api.CoreProperties; import org.sonar.api.batch.bootstrap.ProjectDefinition; -import org.sonar.api.issue.internal.DefaultIssue; -import org.sonar.api.issue.internal.FieldDiffs; import org.sonar.api.resources.Project; import org.sonar.api.utils.KeyValueFormat; import org.sonar.batch.index.BatchComponent; @@ -38,6 +32,7 @@ import org.sonar.batch.protocol.Constants; import org.sonar.batch.protocol.output.BatchReport; import org.sonar.batch.protocol.output.BatchReportWriter; import org.sonar.batch.scan.ImmutableProjectReactor; +import org.sonar.core.issue.DefaultIssue; public class IssuesPublisher implements ReportPublisherStep { @@ -53,7 +48,6 @@ public class IssuesPublisher implements ReportPublisherStep { @Override public void publish(BatchReportWriter writer) { - Collection<Object> deletedComponentKeys = issueCache.componentKeys(); for (BatchComponent resource : componentCache.all()) { String componentKey = resource.resource().getEffectiveKey(); Iterable<DefaultIssue> issues = issueCache.byComponent(componentKey); @@ -65,23 +59,19 @@ public class IssuesPublisher implements ReportPublisherStep { return toReportIssue(builder, input); } })); - deletedComponentKeys.remove(componentKey); } - int count = exportIssuesOfDeletedComponents(deletedComponentKeys, writer); - - exportMetadata(writer, count); + exportMetadata(writer); } - private void exportMetadata(BatchReportWriter writer, int count) { + private void exportMetadata(BatchReportWriter writer) { ProjectDefinition root = reactor.getRoot(); BatchComponent rootProject = componentCache.getRoot(); BatchReport.Metadata.Builder builder = BatchReport.Metadata.newBuilder() .setAnalysisDate(((Project) rootProject.resource()).getAnalysisDate().getTime()) // Here we want key without branch .setProjectKey(root.getKey()) - .setRootComponentRef(rootProject.batchId()) - .setDeletedComponentsCount(count); + .setRootComponentRef(rootProject.batchId()); String branch = root.properties().get(CoreProperties.PROJECT_BRANCH_PROPERTY); if (branch != null) { builder.setBranch(branch); @@ -89,39 +79,14 @@ public class IssuesPublisher implements ReportPublisherStep { writer.writeMetadata(builder.build()); } - private int exportIssuesOfDeletedComponents(Collection<Object> deletedComponentKeys, BatchReportWriter writer) { - int deletedComponentCount = 0; - for (Object componentKey : deletedComponentKeys) { - deletedComponentCount++; - Iterable<DefaultIssue> issues = issueCache.byComponent(componentKey.toString()); - Iterator<DefaultIssue> iterator = issues.iterator(); - if (iterator.hasNext()) { - String componentUuid = iterator.next().componentUuid(); - writer.writeDeletedComponentIssues(deletedComponentCount, componentUuid, Iterables.transform(issues, new Function<DefaultIssue, BatchReport.Issue>() { - private BatchReport.Issue.Builder builder = BatchReport.Issue.newBuilder(); - - @Override - public BatchReport.Issue apply(DefaultIssue input) { - return toReportIssue(builder, input); - } - })); - } - } - return deletedComponentCount; - } - private BatchReport.Issue toReportIssue(BatchReport.Issue.Builder builder, DefaultIssue issue) { builder.clear(); // non-null fields - builder.setUuid(issue.key()); - builder.setIsNew(issue.isNew()); builder.setSeverity(Constants.Severity.valueOf(issue.severity())); builder.setRuleRepository(issue.ruleKey().repository()); builder.setRuleKey(issue.ruleKey().rule()); builder.setAttributes(KeyValueFormat.format(issue.attributes())); builder.addAllTag(issue.tags()); - builder.setMustSendNotification(issue.mustSendNotifications()); - builder.setIsChanged(issue.isChanged()); // nullable fields Integer line = issue.line(); @@ -136,65 +101,12 @@ public class IssuesPublisher implements ReportPublisherStep { if (effortToFix != null) { builder.setEffortToFix(effortToFix); } - Long debtInMinutes = issue.debtInMinutes(); if (debtInMinutes != null) { builder.setDebtInMinutes(debtInMinutes); } - String resolution = issue.resolution(); - if (resolution != null) { - builder.setResolution(resolution); - } - String status = issue.status(); - if (status != null) { - builder.setStatus(status); - } - String checksum = issue.checksum(); - if (checksum != null) { - builder.setChecksum(checksum); - } - builder.setManualSeverity(issue.manualSeverity()); - String reporter = issue.reporter(); - if (reporter != null) { - builder.setReporter(reporter); - } - String assignee = issue.assignee(); - if (assignee != null) { - builder.setAssignee(assignee); - } - String actionPlanKey = issue.actionPlanKey(); - if (actionPlanKey != null) { - builder.setActionPlanKey(actionPlanKey); - } - String authorLogin = issue.authorLogin(); - if (authorLogin != null) { - builder.setAuthorLogin(authorLogin); - } - String diff = diffsToString(issue.currentChange()); - if (diff != null) { - builder.setDiffFields(diff); - } - Date creationDate = issue.creationDate(); - if (creationDate != null) { - builder.setCreationDate(creationDate.getTime()); - } - Long selectedAt = issue.selectedAt(); - if (selectedAt != null) { - builder.setSelectedAt(selectedAt); - } - Date closeDate = issue.closeDate(); - if (closeDate != null) { - builder.setCloseDate(closeDate.getTime()); - } - Date updateDate = issue.updateDate(); - if (updateDate != null) { - builder.setUpdateDate(updateDate.getTime()); - } - return builder.build(); - } - private String diffsToString(@Nullable FieldDiffs diffs) { - return diffs != null ? diffs.toString() : null; + return builder.build(); } } diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/ModuleScanContainer.java b/sonar-batch/src/main/java/org/sonar/batch/scan/ModuleScanContainer.java index 4d4fb03fff9..c4524dca799 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/scan/ModuleScanContainer.java +++ b/sonar-batch/src/main/java/org/sonar/batch/scan/ModuleScanContainer.java @@ -50,7 +50,6 @@ import org.sonar.batch.issue.ignore.scanner.IssueExclusionsLoader; import org.sonar.batch.issue.ignore.scanner.IssueExclusionsRegexpScanner; import org.sonar.batch.phases.DecoratorsExecutor; import org.sonar.batch.phases.InitializersExecutor; -import org.sonar.batch.phases.PersistersExecutor; import org.sonar.batch.phases.PhaseExecutor; import org.sonar.batch.phases.PostJobsExecutor; import org.sonar.batch.phases.ProjectInitializer; @@ -120,7 +119,6 @@ public class ModuleScanContainer extends ComponentContainer { PostJobsExecutor.class, DecoratorsExecutor.class, SensorsExecutor.class, - PersistersExecutor.class, InitializersExecutor.class, ProjectInitializer.class, moduleDefinition.getContainerExtensions(), diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectScanContainer.java b/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectScanContainer.java index 1c3e864170d..83f24753ef4 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectScanContainer.java +++ b/sonar-batch/src/main/java/org/sonar/batch/scan/ProjectScanContainer.java @@ -53,7 +53,6 @@ import org.sonar.batch.index.Caches; import org.sonar.batch.index.DefaultIndex; import org.sonar.batch.issue.DefaultProjectIssues; import org.sonar.batch.issue.IssueCache; -import org.sonar.batch.issue.tracking.InitialOpenIssuesStack; import org.sonar.batch.issue.tracking.LocalIssueTracking; import org.sonar.batch.issue.tracking.ServerIssueRepository; import org.sonar.batch.mediumtest.ScanTaskObservers; @@ -217,10 +216,7 @@ public class ProjectScanContainer extends ComponentContainer { new DebtModelProvider(), // technical debt - DefaultTechnicalDebtModel.class, - - // Issue tracking - InitialOpenIssuesStack.class); + DefaultTechnicalDebtModel.class); } private void addBatchExtensions() { diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/report/ConsoleReport.java b/sonar-batch/src/main/java/org/sonar/batch/scan/report/ConsoleReport.java index e23e8a816e3..2634fdd9af9 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/scan/report/ConsoleReport.java +++ b/sonar-batch/src/main/java/org/sonar/batch/scan/report/ConsoleReport.java @@ -25,7 +25,7 @@ import org.sonar.api.Properties; import org.sonar.api.Property; import org.sonar.api.PropertyType; import org.sonar.api.config.Settings; -import org.sonar.api.issue.internal.DefaultIssue; +import org.sonar.core.issue.DefaultIssue; import org.sonar.api.rule.Severity; import org.sonar.api.utils.log.Logger; import org.sonar.api.utils.log.Loggers; diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/report/IssuesReportBuilder.java b/sonar-batch/src/main/java/org/sonar/batch/scan/report/IssuesReportBuilder.java index 72c48f9bb7a..43e423e7fa7 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/scan/report/IssuesReportBuilder.java +++ b/sonar-batch/src/main/java/org/sonar/batch/scan/report/IssuesReportBuilder.java @@ -23,7 +23,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.sonar.api.batch.BatchSide; import org.sonar.api.issue.Issue; -import org.sonar.api.issue.internal.DefaultIssue; +import org.sonar.core.issue.DefaultIssue; import org.sonar.api.resources.Project; import org.sonar.api.rule.RuleKey; import org.sonar.api.rules.Rule; diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/report/JSONReport.java b/sonar-batch/src/main/java/org/sonar/batch/scan/report/JSONReport.java index e2959d9352d..b13b5468d67 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/scan/report/JSONReport.java +++ b/sonar-batch/src/main/java/org/sonar/batch/scan/report/JSONReport.java @@ -34,7 +34,7 @@ import org.sonar.api.batch.fs.internal.DefaultInputFile; import org.sonar.api.batch.rule.ActiveRules; import org.sonar.api.batch.rule.internal.DefaultActiveRule; import org.sonar.api.config.Settings; -import org.sonar.api.issue.internal.DefaultIssue; +import org.sonar.core.issue.DefaultIssue; import org.sonar.api.platform.Server; import org.sonar.api.resources.Project; import org.sonar.api.rule.RuleKey; diff --git a/sonar-batch/src/main/java/org/sonar/batch/sensor/DefaultSensorStorage.java b/sonar-batch/src/main/java/org/sonar/batch/sensor/DefaultSensorStorage.java index 0277408cbe4..4ddfe03452e 100644 --- a/sonar-batch/src/main/java/org/sonar/batch/sensor/DefaultSensorStorage.java +++ b/sonar-batch/src/main/java/org/sonar/batch/sensor/DefaultSensorStorage.java @@ -42,7 +42,7 @@ import org.sonar.api.batch.sensor.issue.Issue; import org.sonar.api.batch.sensor.measure.Measure; import org.sonar.api.batch.sensor.measure.internal.DefaultMeasure; import org.sonar.api.config.Settings; -import org.sonar.api.issue.internal.DefaultIssue; +import org.sonar.core.issue.DefaultIssue; import org.sonar.api.measures.Formula; import org.sonar.api.measures.Metric; import org.sonar.api.measures.PersistenceMode; |