aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-batch
diff options
context:
space:
mode:
authorJulien Lancelot <julien.lancelot@sonarsource.com>2015-06-09 17:45:52 +0200
committerJulien Lancelot <julien.lancelot@sonarsource.com>2015-06-10 14:30:41 +0200
commit55046a775d5a9fdc550745183b1f89cc5c927a78 (patch)
tree139a6dffb18e441f884f104bc3c2227033e4e045 /sonar-batch
parente00296ce0ab054cba714f1a214cf312020495d42 (diff)
downloadsonarqube-55046a775d5a9fdc550745183b1f89cc5c927a78.tar.gz
sonarqube-55046a775d5a9fdc550745183b1f89cc5c927a78.zip
SONAR-6260 Remove snapshot and project persistence form batch
Diffstat (limited to 'sonar-batch')
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/bootstrap/BatchComponents.java4
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/compute/ApplyProjectRolesDecorator.java60
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/compute/TimeMachineConfigurationPersister.java83
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/index/ResourcePersister.java255
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/issue/tracking/InitialOpenIssuesSensor.java56
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/qualitygate/QualityGateVerifier.java23
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/scan/ProjectScanContainer.java6
-rw-r--r--sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/ComponentIndexer.java21
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/compute/ApplyProjectRolesDecoratorTest.java83
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/compute/TimeMachineConfigurationPersisterTest.java59
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/index/ResourcePersisterTest.java400
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/issue/tracking/InitialOpenIssuesSensorTest.java34
-rw-r--r--sonar-batch/src/test/java/org/sonar/batch/qualitygate/QualityGateVerifierTest.java11
-rw-r--r--sonar-batch/src/test/resources/org/sonar/batch/compute/TimeMachineConfigurationPersisterTest/shared.xml42
-rw-r--r--sonar-batch/src/test/resources/org/sonar/batch/compute/TimeMachineConfigurationPersisterTest/shouldSaveConfigurationInSnapshotsTable-result.xml42
15 files changed, 79 insertions, 1100 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 34235ba135b..ec1cd10a490 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
@@ -23,7 +23,6 @@ import com.google.common.collect.Lists;
import java.util.Collection;
import java.util.List;
import org.sonar.batch.components.TimeMachineConfiguration;
-import org.sonar.batch.compute.ApplyProjectRolesDecorator;
import org.sonar.batch.compute.BranchCoverageDecorator;
import org.sonar.batch.compute.CommentDensityDecorator;
import org.sonar.batch.compute.CountFalsePositivesDecorator;
@@ -42,7 +41,6 @@ import org.sonar.batch.compute.NewOverallCoverageFileAnalyzer;
import org.sonar.batch.compute.OverallBranchCoverageDecorator;
import org.sonar.batch.compute.OverallCoverageDecorator;
import org.sonar.batch.compute.OverallLineCoverageDecorator;
-import org.sonar.batch.compute.TimeMachineConfigurationPersister;
import org.sonar.batch.compute.UnitTestDecorator;
import org.sonar.batch.compute.VariationDecorator;
import org.sonar.batch.cpd.CpdComponents;
@@ -127,12 +125,10 @@ public class BatchComponents {
OverallLineCoverageDecorator.class,
OverallCoverageDecorator.class,
OverallBranchCoverageDecorator.class,
- ApplyProjectRolesDecorator.class,
CommentDensityDecorator.class,
DirectoriesDecorator.class,
FilesDecorator.class,
VariationDecorator.class,
- TimeMachineConfigurationPersister.class,
NewCoverageFileAnalyzer.class,
NewItCoverageFileAnalyzer.class,
NewOverallCoverageFileAnalyzer.class,
diff --git a/sonar-batch/src/main/java/org/sonar/batch/compute/ApplyProjectRolesDecorator.java b/sonar-batch/src/main/java/org/sonar/batch/compute/ApplyProjectRolesDecorator.java
deleted file mode 100644
index 8861e1312f8..00000000000
--- a/sonar-batch/src/main/java/org/sonar/batch/compute/ApplyProjectRolesDecorator.java
+++ /dev/null
@@ -1,60 +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.compute;
-
-import com.google.common.collect.ImmutableSet;
-import java.util.Set;
-import org.slf4j.LoggerFactory;
-import org.sonar.api.batch.Decorator;
-import org.sonar.api.batch.DecoratorContext;
-import org.sonar.api.batch.RequiresDB;
-import org.sonar.api.resources.Project;
-import org.sonar.api.resources.Qualifiers;
-import org.sonar.api.resources.Resource;
-import org.sonar.api.security.ResourcePermissions;
-
-@RequiresDB
-public class ApplyProjectRolesDecorator implements Decorator {
-
- private static final Set<String> QUALIFIERS = ImmutableSet.of(Qualifiers.PROJECT, Qualifiers.VIEW, Qualifiers.SUBVIEW);
- private final ResourcePermissions resourcePermissions;
-
- public ApplyProjectRolesDecorator(ResourcePermissions resourcePermissions) {
- this.resourcePermissions = resourcePermissions;
- }
-
- @Override
- public boolean shouldExecuteOnProject(Project project) {
- return true;
- }
-
- @Override
- public void decorate(Resource resource, DecoratorContext context) {
- if (shouldDecorateResource(resource)) {
- LoggerFactory.getLogger(ApplyProjectRolesDecorator.class).info("Grant default permissions to {}", resource.getKey());
- resourcePermissions.grantDefaultRoles(resource);
- }
- }
-
- private boolean shouldDecorateResource(Resource resource) {
- return resource.getId() != null && QUALIFIERS.contains(resource.getQualifier()) && !resourcePermissions.hasRoles(resource);
- }
-
-}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/compute/TimeMachineConfigurationPersister.java b/sonar-batch/src/main/java/org/sonar/batch/compute/TimeMachineConfigurationPersister.java
deleted file mode 100644
index 68b5e1a8330..00000000000
--- a/sonar-batch/src/main/java/org/sonar/batch/compute/TimeMachineConfigurationPersister.java
+++ /dev/null
@@ -1,83 +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.compute;
-
-import java.util.List;
-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.RequiresDB;
-import org.sonar.api.database.DatabaseSession;
-import org.sonar.api.database.model.Snapshot;
-import org.sonar.api.resources.Project;
-import org.sonar.api.resources.Resource;
-import org.sonar.api.resources.ResourceUtils;
-import org.sonar.batch.components.PastSnapshot;
-import org.sonar.batch.components.TimeMachineConfiguration;
-import org.sonar.batch.index.BatchComponentCache;
-
-import static org.sonar.api.utils.DateUtils.dateToLong;
-
-@DependedUpon(DecoratorBarriers.END_OF_TIME_MACHINE)
-@RequiresDB
-public final class TimeMachineConfigurationPersister implements Decorator {
-
- private final TimeMachineConfiguration timeMachineConfiguration;
- private BatchComponentCache resourceCache;
- private DatabaseSession session;
-
- public TimeMachineConfigurationPersister(TimeMachineConfiguration timeMachineConfiguration, BatchComponentCache resourceCache, DatabaseSession session) {
- this.timeMachineConfiguration = timeMachineConfiguration;
- this.resourceCache = resourceCache;
- this.session = session;
- }
-
- @Override
- public void decorate(Resource resource, DecoratorContext context) {
- if (ResourceUtils.isProject(resource)) {
- persistConfiguration(resource);
- }
- }
-
- void persistConfiguration(Resource module) {
- List<PastSnapshot> pastSnapshots = timeMachineConfiguration.getProjectPastSnapshots();
- Snapshot projectSnapshot = resourceCache.get(module).snapshot();
- for (PastSnapshot pastSnapshot : pastSnapshots) {
- Snapshot snapshot = session.reattach(Snapshot.class, projectSnapshot.getId());
- updatePeriodParams(snapshot, pastSnapshot);
- updatePeriodParams(projectSnapshot, pastSnapshot);
- session.save(snapshot);
- }
- session.commit();
- }
-
- @Override
- public boolean shouldExecuteOnProject(Project project) {
- return true;
- }
-
- private static void updatePeriodParams(Snapshot snapshot, PastSnapshot pastSnapshot) {
- int periodIndex = pastSnapshot.getIndex();
- snapshot.setPeriodMode(periodIndex, pastSnapshot.getMode());
- snapshot.setPeriodModeParameter(periodIndex, pastSnapshot.getModeParameter());
- snapshot.setPeriodDateMs(periodIndex, dateToLong(pastSnapshot.getDate()));
- }
-}
diff --git a/sonar-batch/src/main/java/org/sonar/batch/index/ResourcePersister.java b/sonar-batch/src/main/java/org/sonar/batch/index/ResourcePersister.java
deleted file mode 100644
index 67dd4dca0ea..00000000000
--- a/sonar-batch/src/main/java/org/sonar/batch/index/ResourcePersister.java
+++ /dev/null
@@ -1,255 +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 com.google.common.annotations.VisibleForTesting;
-import javax.annotation.Nullable;
-import javax.persistence.NonUniqueResultException;
-import org.apache.commons.lang.ObjectUtils;
-import org.apache.commons.lang.StringUtils;
-import org.sonar.api.database.DatabaseSession;
-import org.sonar.api.database.model.ResourceModel;
-import org.sonar.api.database.model.Snapshot;
-import org.sonar.api.resources.Language;
-import org.sonar.api.resources.Project;
-import org.sonar.api.resources.Resource;
-import org.sonar.api.resources.Scopes;
-import org.sonar.api.security.ResourcePermissions;
-import org.sonar.api.utils.SonarException;
-import org.sonar.api.utils.internal.Uuids;
-
-import static org.sonar.api.utils.DateUtils.dateToLong;
-
-public class ResourcePersister implements ScanPersister {
-
- @VisibleForTesting
- static final String MODULE_UUID_PATH_SEPARATOR = ".";
-
- private final DatabaseSession session;
- private final ResourcePermissions permissions;
- private final BatchComponentCache resourceCache;
-
- public ResourcePersister(DatabaseSession session, ResourcePermissions permissions, BatchComponentCache resourceCache) {
- this.session = session;
- this.permissions = permissions;
- this.resourceCache = resourceCache;
- }
-
- @Override
- public void persist() {
- for (BatchComponent resource : resourceCache.all()) {
- persist(resource);
- }
- }
-
- private void persist(BatchComponent batchResource) {
- if (batchResource.snapshot() != null) {
- // already persisted
- return;
- }
- BatchComponent parentBatchResource = batchResource.parent();
- Snapshot s;
- if (parentBatchResource != null) {
- persist(parentBatchResource);
- s = persist(findModule(parentBatchResource), batchResource.resource(), parentBatchResource.resource());
- } else {
- // Root project
- s = persistProject((Project) batchResource.resource(), null);
- }
- batchResource.setSnapshot(s);
- }
-
- private Project findModule(BatchComponent batchResource) {
- if (batchResource.resource() instanceof Project) {
- return (Project) batchResource.resource();
- } else {
- return findModule(batchResource.parent());
- }
- }
-
- private Snapshot persistProject(Project project, @Nullable Project parent) {
- ResourceModel model = findOrCreateModel(project, parent);
- // Used by ResourceKeyMigration in order to know that a project has already being migrated
- model.setDeprecatedKey(project.getKey());
- // language is null for project since multi-language support
- model.setLanguageKey(null);
-
- // For views
- if (project instanceof ResourceCopy) {
- model.setCopyResourceId(((ResourceCopy) project).getCopyResourceId());
- }
-
- Snapshot parentSnapshot = null;
- if (parent != null) {
- // assume that the parent project has already been saved
- parentSnapshot = resourceCache.get(parent.getEffectiveKey()).snapshot();
- model.setRootId((Integer) ObjectUtils.defaultIfNull(parentSnapshot.getRootProjectId(), parentSnapshot.getResourceId()));
- } else {
- model.setRootId(null);
- }
- model = session.save(model);
- project.setId(model.getId());
- project.setUuid(model.getUuid());
-
- Snapshot snapshot = new Snapshot(model, parentSnapshot);
- snapshot.setVersion(project.getAnalysisVersion());
- snapshot.setCreatedAtMs(dateToLong(project.getAnalysisDate()));
- snapshot.setBuildDateMs(System.currentTimeMillis());
- snapshot = session.save(snapshot);
- session.commit();
-
- if (parent == null && !permissions.hasRoles(project)) {
- permissions.grantDefaultRoles(project);
- }
-
- return snapshot;
- }
-
- Snapshot persist(Project project, Resource resource, @Nullable Resource parent) {
- Snapshot snapshot;
- if (resource instanceof Project) {
- // should not occur, please use the method saveProject()
- snapshot = persistProject((Project) resource, (Project) parent);
- } else {
- snapshot = persistFileOrDirectory(project, resource, parent);
- }
-
- return snapshot;
- }
-
- /**
- * Everything except project and library
- */
- private Snapshot persistFileOrDirectory(Project project, Resource resource, @Nullable Resource parentReference) {
- BatchComponent moduleResource = resourceCache.get(project);
- Integer moduleId = moduleResource.resource().getId();
- ResourceModel model = findOrCreateModel(resource, parentReference != null ? parentReference : project);
- model.setRootId(moduleId);
- model = session.save(model);
- resource.setId(model.getId());
- resource.setUuid(model.getUuid());
-
- Snapshot parentSnapshot;
- if (parentReference != null) {
- parentSnapshot = resourceCache.get(parentReference).snapshot();
- } else {
- parentSnapshot = moduleResource.snapshot();
- }
-
- Snapshot snapshot = new Snapshot(model, parentSnapshot);
- snapshot.setBuildDateMs(System.currentTimeMillis());
- snapshot = session.save(snapshot);
- session.commit();
- return snapshot;
- }
-
- private ResourceModel findOrCreateModel(Resource resource, @Nullable Resource parentResource) {
- ResourceModel model;
- try {
- model = session.getSingleResult(ResourceModel.class, "key", resource.getEffectiveKey());
- if (model == null) {
- if (StringUtils.isBlank(resource.getEffectiveKey())) {
- throw new SonarException("Unable to persist resource " + resource.toString() + ". Resource effective key is blank. This may be caused by an outdated plugin.");
- }
- model = createModel(resource, parentResource);
-
- } else {
- mergeModel(model, resource);
- }
- updateUuids(resource, parentResource, model);
- return model;
-
- } catch (NonUniqueResultException e) {
- throw new SonarException("The resource '" + resource.getEffectiveKey() + "' is duplicated in database.", e);
- }
- }
-
- ResourceModel createModel(Resource resource, @Nullable Resource parentResource) {
- ResourceModel model = new ResourceModel();
- model.setEnabled(Boolean.TRUE);
- model.setDescription(resource.getDescription());
- model.setKey(resource.getEffectiveKey());
- model.setUuid(Uuids.create());
- model.setPath(resource.getPath());
- Language language = resource.getLanguage();
- if (language != null) {
- model.setLanguageKey(language.getKey());
- }
- if (StringUtils.isNotBlank(resource.getName())) {
- model.setName(resource.getName());
- } else {
- model.setName(resource.getKey());
- }
- model.setLongName(resource.getLongName());
- model.setScope(resource.getScope());
- model.setQualifier(resource.getQualifier());
- return model;
- }
-
- private void updateUuids(Resource resource, Resource parentResource, ResourceModel model) {
- if (parentResource == null) {
- // Root module
- model.setProjectUuid(model.getUuid());
- model.setModuleUuidPath(MODULE_UUID_PATH_SEPARATOR + model.getUuid() + MODULE_UUID_PATH_SEPARATOR);
- } else {
- ResourceModel parentModel = session.getSingleResult(ResourceModel.class, "id", parentResource.getId());
- model.setProjectUuid(parentModel.getProjectUuid());
- if (Scopes.isProject(resource)) {
- // Sub module
- model.setModuleUuid(parentResource.getUuid());
- String parentModuleUuidPath = parentModel.getModuleUuidPath();
- model.setModuleUuidPath(parentModuleUuidPath + model.getUuid() + MODULE_UUID_PATH_SEPARATOR);
- } else if (Scopes.isProject(parentResource)) {
- // Directory
- model.setModuleUuid(parentResource.getUuid());
- String parentModuleUuidPath = parentModel.getModuleUuidPath();
- model.setModuleUuidPath(parentModuleUuidPath);
- } else {
- // File
- model.setModuleUuid(parentModel.getModuleUuid());
- String parentModuleUuidPath = parentModel.getModuleUuidPath();
- model.setModuleUuidPath(parentModuleUuidPath);
- }
- }
- }
-
- static void mergeModel(ResourceModel model, Resource resource) {
- model.setEnabled(true);
- model.setKey(resource.getEffectiveKey());
- if (StringUtils.isNotBlank(resource.getName())) {
- model.setName(resource.getName());
- }
- if (StringUtils.isNotBlank(resource.getLongName())) {
- model.setLongName(resource.getLongName());
- }
- if (StringUtils.isNotBlank(resource.getDescription())) {
- model.setDescription(resource.getDescription());
- }
- if (StringUtils.isNotBlank(resource.getPath())) {
- model.setPath(resource.getPath());
- }
- model.setScope(resource.getScope());
- model.setQualifier(resource.getQualifier());
- Language language = resource.getLanguage();
- if (language != null) {
- model.setLanguageKey(language.getKey());
- }
- }
-}
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
index 507e5cbd2f0..ef39e6b77e9 100644
--- 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
@@ -19,11 +19,12 @@
*/
package org.sonar.batch.issue.tracking;
-import org.sonar.api.batch.RequiresDB;
-
+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;
@@ -31,9 +32,9 @@ 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 java.util.Calendar;
-import java.util.Date;
+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.
@@ -44,11 +45,13 @@ 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) {
+ public InitialOpenIssuesSensor(InitialOpenIssuesStack initialOpenIssuesStack, IssueDao issueDao, IssueChangeDao issueChangeDao, ResourceDao resourceDao) {
this.initialOpenIssuesStack = initialOpenIssuesStack;
this.issueDao = issueDao;
this.issueChangeDao = issueChangeDao;
+ this.resourceDao = resourceDao;
}
@Override
@@ -58,26 +61,29 @@ public class InitialOpenIssuesSensor implements Sensor {
@Override
public void analyse(Project project, SensorContext context) {
- // 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(project.getId(), new ResultHandler() {
- @Override
- public void handleResult(ResultContext rc) {
- IssueDto dto = (IssueDto) rc.getResultObject();
- dto.setSelectedAt(now.getTime());
- initialOpenIssuesStack.addIssue(dto);
- }
- });
+ 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(project.getId(), new ResultHandler() {
- @Override
- public void handleResult(ResultContext rc) {
- IssueChangeDto dto = (IssueChangeDto) rc.getResultObject();
- initialOpenIssuesStack.addChangelog(dto);
- }
- });
+ issueChangeDao.selectChangelogOnNonClosedIssuesByModuleAndType(moduleId, new ResultHandler() {
+ @Override
+ public void handleResult(ResultContext rc) {
+ IssueChangeDto dto = (IssueChangeDto) rc.getResultObject();
+ initialOpenIssuesStack.addChangelog(dto);
+ }
+ });
+ }
}
@Override
diff --git a/sonar-batch/src/main/java/org/sonar/batch/qualitygate/QualityGateVerifier.java b/sonar-batch/src/main/java/org/sonar/batch/qualitygate/QualityGateVerifier.java
index 54427072235..5e300001222 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/qualitygate/QualityGateVerifier.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/qualitygate/QualityGateVerifier.java
@@ -22,9 +22,17 @@ package org.sonar.batch.qualitygate;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
+import java.util.Collection;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+import java.util.Set;
import org.apache.commons.lang.StringUtils;
-import org.sonar.api.batch.*;
-import org.sonar.api.database.model.Snapshot;
+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.i18n.I18n;
import org.sonar.api.measures.CoreMetrics;
import org.sonar.api.measures.Measure;
@@ -38,8 +46,6 @@ import org.sonar.batch.index.BatchComponentCache;
import org.sonar.core.qualitygate.db.QualityGateConditionDto;
import org.sonar.core.timemachine.Periods;
-import java.util.*;
-
public class QualityGateVerifier implements Decorator {
private static final String VARIATION_METRIC_PREFIX = "new_";
@@ -160,10 +166,11 @@ public class QualityGateVerifier implements Decorator {
.append(" ").append(operatorLabel(condition.operator())).append(" ")
.append(alertValue(condition, level));
- if (alertPeriod != null) {
- Snapshot snapshot = resourceCache.get(project).snapshot();
- stringBuilder.append(" ").append(periods.label(snapshot, alertPeriod));
- }
+ // Disabled because snapshot is no more created by the batch
+// if (alertPeriod != null) {
+// Snapshot snapshot = resourceCache.get(project).snapshot();
+// stringBuilder.append(" ").append(periods.label(snapshot, alertPeriod));
+// }
return stringBuilder.toString();
}
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 07fca1ad1ab..b3295cb2974 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
@@ -44,10 +44,9 @@ import org.sonar.batch.deprecated.components.DefaultResourceCreationLock;
import org.sonar.batch.deprecated.components.PeriodsDefinition;
import org.sonar.batch.duplication.DuplicationCache;
import org.sonar.batch.events.EventBus;
+import org.sonar.batch.index.BatchComponentCache;
import org.sonar.batch.index.Caches;
import org.sonar.batch.index.DefaultIndex;
-import org.sonar.batch.index.BatchComponentCache;
-import org.sonar.batch.index.ResourcePersister;
import org.sonar.batch.issue.DefaultProjectIssues;
import org.sonar.batch.issue.IssueCache;
import org.sonar.batch.issue.tracking.InitialOpenIssuesStack;
@@ -81,7 +80,6 @@ import org.sonar.core.issue.workflow.FunctionExecutor;
import org.sonar.core.issue.workflow.IssueWorkflow;
import org.sonar.core.permission.PermissionFacade;
import org.sonar.core.platform.ComponentContainer;
-import org.sonar.core.resource.DefaultResourcePermissions;
import org.sonar.core.technicaldebt.DefaultTechnicalDebtModel;
import org.sonar.core.user.DefaultUserFinder;
@@ -138,7 +136,6 @@ public class ProjectScanContainer extends ComponentContainer {
PhasesTimeProfiler.class,
ResourceTypes.class,
PermissionFacade.class,
- DefaultResourcePermissions.class,
DefaultProjectTree.class,
ProjectExclusions.class,
ProjectReactorValidator.class,
@@ -210,7 +207,6 @@ public class ProjectScanContainer extends ComponentContainer {
private void addDataBaseComponents() {
add(
PastMeasuresLoader.class,
- ResourcePersister.class,
// Users
DefaultUserFinder.class,
diff --git a/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/ComponentIndexer.java b/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/ComponentIndexer.java
index f9ff2fb6511..d3caddc45a1 100644
--- a/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/ComponentIndexer.java
+++ b/sonar-batch/src/main/java/org/sonar/batch/scan/filesystem/ComponentIndexer.java
@@ -27,9 +27,6 @@ import org.sonar.api.resources.Languages;
import org.sonar.api.resources.Project;
import org.sonar.api.resources.Resource;
import org.sonar.batch.index.BatchComponentCache;
-import org.sonar.batch.index.ResourcePersister;
-
-import javax.annotation.Nullable;
/**
* Index all files/directories of the module in SQ database and importing source code.
@@ -42,29 +39,18 @@ public class ComponentIndexer {
private final Languages languages;
private final SonarIndex sonarIndex;
private final Project module;
- private final ResourcePersister resourcePersister;
private final BatchComponentCache resourceCache;
- public ComponentIndexer(Project module, Languages languages, SonarIndex sonarIndex, BatchComponentCache resourceCache, @Nullable ResourcePersister resourcePersister) {
+ public ComponentIndexer(Project module, Languages languages, SonarIndex sonarIndex, BatchComponentCache resourceCache) {
this.module = module;
this.languages = languages;
this.sonarIndex = sonarIndex;
this.resourceCache = resourceCache;
- this.resourcePersister = resourcePersister;
- }
-
- public ComponentIndexer(Project module, Languages languages, SonarIndex sonarIndex, BatchComponentCache resourceCache) {
- this(module, languages, sonarIndex, resourceCache, null);
}
public void execute(DefaultModuleFileSystem fs) {
module.setBaseDir(fs.baseDir());
- if (resourcePersister != null) {
- // Force persistence of module structure in order to know if project should be migrated
- resourcePersister.persist();
- }
-
for (InputFile inputFile : fs.inputFiles(fs.predicates().all())) {
String languageKey = inputFile.language();
boolean unitTest = InputFile.Type.TEST == inputFile.type();
@@ -72,10 +58,5 @@ public class ComponentIndexer {
sonarIndex.index(sonarFile);
resourceCache.get(sonarFile).setInputPath(inputFile);
}
-
- if (resourcePersister != null) {
- // Persist all files in order to have snapshot availables
- resourcePersister.persist();
- }
}
}
diff --git a/sonar-batch/src/test/java/org/sonar/batch/compute/ApplyProjectRolesDecoratorTest.java b/sonar-batch/src/test/java/org/sonar/batch/compute/ApplyProjectRolesDecoratorTest.java
deleted file mode 100644
index cd48e6a315f..00000000000
--- a/sonar-batch/src/test/java/org/sonar/batch/compute/ApplyProjectRolesDecoratorTest.java
+++ /dev/null
@@ -1,83 +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.compute;
-
-import org.junit.Before;
-import org.junit.Test;
-import org.sonar.api.resources.Project;
-import org.sonar.api.security.ResourcePermissions;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.never;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
-public class ApplyProjectRolesDecoratorTest {
-
- private ResourcePermissions resourcePermissions;
- private ApplyProjectRolesDecorator decorator;
-
- @Before
- public void init() {
- resourcePermissions = mock(ResourcePermissions.class);
- decorator = new ApplyProjectRolesDecorator(resourcePermissions);
- }
-
- @Test
- public void alwaysExecute() {
- assertThat(decorator.shouldExecuteOnProject(new Project("project"))).isTrue();
- }
-
- @Test
- public void doNotGrantDefaultRolesWhenExistingPermissions() {
- Project project = new Project("project");
- project.setId(10);
- when(resourcePermissions.hasRoles(project)).thenReturn(true);
-
- decorator.decorate(project, null);
-
- verify(resourcePermissions, never()).grantDefaultRoles(project);
- }
-
- @Test
- public void doNotApplySecurityOnModules() {
- Project project = new Project("project");
- Project module = new Project("module").setParent(project);
- module.setId(10);
- when(resourcePermissions.hasRoles(project)).thenReturn(false);
-
- decorator.decorate(module, null);
-
- verify(resourcePermissions, never()).grantDefaultRoles(module);
- }
-
- @Test
- public void grantDefaultRolesWhenNoPermissions() {
- Project project = new Project("project");
- project.setId(10);
- when(resourcePermissions.hasRoles(project)).thenReturn(false);
-
- decorator.decorate(project, null);
-
- verify(resourcePermissions).grantDefaultRoles(project);
- }
-
-}
diff --git a/sonar-batch/src/test/java/org/sonar/batch/compute/TimeMachineConfigurationPersisterTest.java b/sonar-batch/src/test/java/org/sonar/batch/compute/TimeMachineConfigurationPersisterTest.java
deleted file mode 100644
index 2c48e9c6614..00000000000
--- a/sonar-batch/src/test/java/org/sonar/batch/compute/TimeMachineConfigurationPersisterTest.java
+++ /dev/null
@@ -1,59 +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.compute;
-
-import java.util.Arrays;
-import org.junit.Test;
-import org.sonar.api.database.model.Snapshot;
-import org.sonar.api.resources.Project;
-import org.sonar.api.utils.DateUtils;
-import org.sonar.batch.components.PastSnapshot;
-import org.sonar.batch.components.TimeMachineConfiguration;
-import org.sonar.batch.index.BatchComponentCache;
-import org.sonar.jpa.test.AbstractDbUnitTestCase;
-
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-public class TimeMachineConfigurationPersisterTest extends AbstractDbUnitTestCase {
-
- @Test
- public void shouldSaveConfigurationInSnapshotsTable() {
- setupData("shared");
-
- TimeMachineConfiguration timeMachineConfiguration = mock(TimeMachineConfiguration.class);
- PastSnapshot vs1 = new PastSnapshot("days", DateUtils.parseDate("2009-01-25"), getSession().getSingleResult(Snapshot.class, "id", 100))
- .setModeParameter("30").setIndex(1);
- PastSnapshot vs3 = new PastSnapshot("version", DateUtils.parseDate("2008-12-13"), getSession().getSingleResult(Snapshot.class, "id", 300))
- .setModeParameter("1.2.3").setIndex(3);
- when(timeMachineConfiguration.getProjectPastSnapshots()).thenReturn(Arrays.asList(vs1, vs3));
- Snapshot projectSnapshot = getSession().getSingleResult(Snapshot.class, "id", 1000);
-
- BatchComponentCache resourceCache = new BatchComponentCache();
- Project project = new Project("foo");
- resourceCache.add(project, null).setSnapshot(projectSnapshot);
-
- TimeMachineConfigurationPersister persister = new TimeMachineConfigurationPersister(timeMachineConfiguration, resourceCache, getSession());
-
- persister.persistConfiguration(project);
-
- checkTables("shouldSaveConfigurationInSnapshotsTable", "snapshots");
- }
-}
diff --git a/sonar-batch/src/test/java/org/sonar/batch/index/ResourcePersisterTest.java b/sonar-batch/src/test/java/org/sonar/batch/index/ResourcePersisterTest.java
deleted file mode 100644
index 4c83e9da457..00000000000
--- a/sonar-batch/src/test/java/org/sonar/batch/index/ResourcePersisterTest.java
+++ /dev/null
@@ -1,400 +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 java.io.IOException;
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
-import javax.persistence.Query;
-import org.apache.ibatis.session.SqlSession;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.ExpectedException;
-import org.junit.rules.TemporaryFolder;
-import org.sonar.api.CoreProperties;
-import org.sonar.api.batch.bootstrap.ProjectDefinition;
-import org.sonar.api.batch.measure.MetricFinder;
-import org.sonar.api.config.Settings;
-import org.sonar.api.database.model.Snapshot;
-import org.sonar.api.resources.Directory;
-import org.sonar.api.resources.File;
-import org.sonar.api.resources.Project;
-import org.sonar.api.resources.Resource;
-import org.sonar.api.security.ResourcePermissions;
-import org.sonar.batch.DefaultProjectTree;
-import org.sonar.batch.scan.measure.MeasureCache;
-import org.sonar.core.component.ComponentDto;
-import org.sonar.core.component.db.ComponentMapper;
-import org.sonar.jpa.test.AbstractDbUnitTestCase;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.never;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-import static org.sonar.batch.index.ResourcePersister.MODULE_UUID_PATH_SEPARATOR;
-
-public class ResourcePersisterTest extends AbstractDbUnitTestCase {
-
- @Rule
- public ExpectedException thrown = ExpectedException.none();
-
- @Rule
- public TemporaryFolder temp = new TemporaryFolder();
-
- private Project singleProject, singleCopyProject, multiModuleProject, moduleA, moduleB, moduleB1, existingProject;
- private BatchComponentCache resourceCache;
-
- private ResourcePersister persister;
-
- private DefaultProjectTree projectTree;
-
- private ResourcePermissions permissions;
-
- @Before
- public void before() throws ParseException {
- resourceCache = new BatchComponentCache();
-
- SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy");
- singleProject = newProject("foo", "java");
- singleProject.setName("Foo").setDescription("some description").setAnalysisDate(format.parse("25/12/2010"));
-
- existingProject = newProject("my:key", "java");
- existingProject.setName("Other project").setDescription("some description").setAnalysisDate(format.parse("25/12/2010"));
-
- singleCopyProject = newCopyProject("foo", "java", 10);
- singleCopyProject.setName("Foo").setDescription("some description").setAnalysisDate(format.parse("25/12/2010"));
-
- multiModuleProject = newProject("root", "java");
- multiModuleProject.setName("Root").setAnalysisDate(format.parse("25/12/2010"));
-
- moduleA = newProject("a", "java");
- moduleA.setName("A").setAnalysisDate(format.parse("25/12/2010"));
- moduleA.setParent(multiModuleProject);
- moduleA.setPath("/moduleA");
-
- moduleB = newProject("b", "java");
- moduleB.setName("B").setAnalysisDate(format.parse("25/12/2010"));
- moduleB.setParent(multiModuleProject);
- moduleB.setPath("/moduleB");
-
- moduleB1 = newProject("b1", "java");
- moduleB1.setName("B1").setAnalysisDate(format.parse("25/12/2010"));
- moduleB1.setParent(moduleB);
- moduleB1.setPath("/moduleB1");
-
- projectTree = mock(DefaultProjectTree.class);
- permissions = mock(ResourcePermissions.class);
- persister = new ResourcePersister(getSession(), permissions, resourceCache);
- }
-
- @Test
- public void shouldSaveNewProject() {
- setupData("shared");
-
- persister.persist(null, singleProject, null);
-
- checkTables("shouldSaveNewProject", new String[] {"build_date", "created_at", "authorization_updated_at", "uuid", "project_uuid", "module_uuid", "module_uuid_path"},
- "projects", "snapshots");
-
- // Need to enable snapshot to make resource visible using ComponentMapper
- enableSnapshot(1001);
- try (SqlSession session = getMyBatis().openSession(false)) {
- ComponentDto newProject = session.getMapper(ComponentMapper.class).selectByKey("foo");
- assertThat(newProject.uuid()).isNotNull();
- assertThat(newProject.projectUuid()).isEqualTo(newProject.uuid());
- assertThat(newProject.moduleUuid()).isNull();
- assertThat(newProject.moduleUuidPath()).isEqualTo(MODULE_UUID_PATH_SEPARATOR + newProject.uuid() + MODULE_UUID_PATH_SEPARATOR);
- // SONAR-3636 : created_at must be fed when inserting a new entry in the 'projects' table
- assertThat(newProject.getCreatedAt()).isNotNull();
- }
- }
-
- @Test
- public void shouldSaveCopyProject() {
- setupData("shared");
-
- persister.persist(null, singleCopyProject, null);
-
- checkTables("shouldSaveCopyProject", new String[] {"build_date", "created_at", "authorization_updated_at", "uuid", "project_uuid", "module_uuid", "module_uuid_path"},
- "projects", "snapshots");
- // Need to enable snapshot to make resource visible using ComponentMapper
- enableSnapshot(1001);
- try (SqlSession session = getMyBatis().openSession(false)) {
- ComponentDto newProject = session.getMapper(ComponentMapper.class).selectByKey("foo");
- assertThat(newProject.uuid()).isNotNull();
- assertThat(newProject.projectUuid()).isEqualTo(newProject.uuid());
- assertThat(newProject.moduleUuid()).isNull();
- assertThat(newProject.moduleUuidPath()).isEqualTo(MODULE_UUID_PATH_SEPARATOR + newProject.uuid() + MODULE_UUID_PATH_SEPARATOR);
- }
- }
-
- @Test
- public void shouldSaveNewMultiModulesProject() {
- setupData("shared");
-
- resourceCache.add(multiModuleProject, null).setSnapshot(persister.persist(null, multiModuleProject, null));
- resourceCache.add(moduleA, multiModuleProject).setSnapshot(persister.persist(null, moduleA, multiModuleProject));
- resourceCache.add(moduleB, multiModuleProject).setSnapshot(persister.persist(null, moduleB, multiModuleProject));
- resourceCache.add(moduleB1, moduleB).setSnapshot(persister.persist(null, moduleB1, moduleB));
- Resource file = File.create("src/main/java/org/Foo.java").setEffectiveKey("b1:src/main/java/org/Foo.java");
- file.getParent().setEffectiveKey("b1:src/main/java/org");
- resourceCache.add(file.getParent(), moduleB1).setSnapshot(persister.persist(moduleB1, file.getParent(), null));
- persister.persist(moduleB1, file, file.getParent());
-
- checkTables("shouldSaveNewMultiModulesProject",
- new String[] {"build_date", "created_at", "authorization_updated_at", "uuid", "project_uuid", "module_uuid", "module_uuid_path"}, "projects", "snapshots");
-
- // Need to enable snapshot to make resource visible using ComponentMapper
- enableSnapshot(1001);
- enableSnapshot(1002);
- enableSnapshot(1003);
- enableSnapshot(1004);
- enableSnapshot(1005);
- enableSnapshot(1006);
- try (SqlSession session = getMyBatis().openSession(false)) {
- ComponentDto root = session.getMapper(ComponentMapper.class).selectByKey("root");
- assertThat(root.uuid()).isNotNull();
- assertThat(root.projectUuid()).isEqualTo(root.uuid());
- assertThat(root.moduleUuid()).isNull();
- assertThat(root.moduleUuidPath()).isEqualTo(MODULE_UUID_PATH_SEPARATOR + root.uuid() + MODULE_UUID_PATH_SEPARATOR);
- ComponentDto a = session.getMapper(ComponentMapper.class).selectByKey("a");
- assertThat(a.uuid()).isNotNull();
- assertThat(a.projectUuid()).isEqualTo(root.uuid());
- assertThat(a.moduleUuid()).isEqualTo(root.uuid());
- assertThat(a.moduleUuidPath()).isEqualTo(MODULE_UUID_PATH_SEPARATOR + root.uuid() + MODULE_UUID_PATH_SEPARATOR + a.uuid() + MODULE_UUID_PATH_SEPARATOR);
- ComponentDto b = session.getMapper(ComponentMapper.class).selectByKey("b");
- assertThat(b.uuid()).isNotNull();
- assertThat(b.projectUuid()).isEqualTo(root.uuid());
- assertThat(b.moduleUuid()).isEqualTo(root.uuid());
- assertThat(b.moduleUuidPath()).isEqualTo(MODULE_UUID_PATH_SEPARATOR + root.uuid() + MODULE_UUID_PATH_SEPARATOR + b.uuid() + MODULE_UUID_PATH_SEPARATOR);
- ComponentDto b1 = session.getMapper(ComponentMapper.class).selectByKey("b1");
- assertThat(b1.uuid()).isNotNull();
- assertThat(b1.projectUuid()).isEqualTo(root.uuid());
- assertThat(b1.moduleUuid()).isEqualTo(b.uuid());
- assertThat(b1.moduleUuidPath()).isEqualTo(
- MODULE_UUID_PATH_SEPARATOR + root.uuid() + MODULE_UUID_PATH_SEPARATOR + b.uuid() + MODULE_UUID_PATH_SEPARATOR + b1.uuid() + MODULE_UUID_PATH_SEPARATOR);
- ComponentDto dir = session.getMapper(ComponentMapper.class).selectByKey("b1:src/main/java/org");
- assertThat(dir.uuid()).isNotNull();
- assertThat(dir.projectUuid()).isEqualTo(root.uuid());
- assertThat(dir.moduleUuid()).isEqualTo(b1.uuid());
- assertThat(dir.moduleUuidPath()).isEqualTo(
- MODULE_UUID_PATH_SEPARATOR + root.uuid() + MODULE_UUID_PATH_SEPARATOR + b.uuid() + MODULE_UUID_PATH_SEPARATOR + b1.uuid() + MODULE_UUID_PATH_SEPARATOR);
- ComponentDto fileComp = session.getMapper(ComponentMapper.class).selectByKey("b1:src/main/java/org/Foo.java");
- assertThat(fileComp.uuid()).isNotNull();
- assertThat(fileComp.projectUuid()).isEqualTo(root.uuid());
- assertThat(fileComp.moduleUuid()).isEqualTo(b1.uuid());
- assertThat(fileComp.moduleUuidPath()).isEqualTo(
- MODULE_UUID_PATH_SEPARATOR + root.uuid() + MODULE_UUID_PATH_SEPARATOR + b.uuid() + MODULE_UUID_PATH_SEPARATOR + b1.uuid() + MODULE_UUID_PATH_SEPARATOR);
- }
- }
-
- // FIXME this is a kind of medium test
- @Test
- public void shouldSaveNewMultiModulesProjectUsingIndex() throws IOException {
- setupData("shared");
-
- java.io.File baseDir = temp.newFolder();
-
- when(projectTree.getRootProject()).thenReturn(multiModuleProject);
- when(projectTree.getProjectDefinition(multiModuleProject)).thenReturn(ProjectDefinition.create().setBaseDir(baseDir));
- when(projectTree.getProjectDefinition(moduleA)).thenReturn(ProjectDefinition.create().setBaseDir(new java.io.File(baseDir, "moduleA")));
- when(projectTree.getProjectDefinition(moduleB)).thenReturn(ProjectDefinition.create().setBaseDir(new java.io.File(baseDir, "moduleB")));
- when(projectTree.getProjectDefinition(moduleB1)).thenReturn(ProjectDefinition.create().setBaseDir(new java.io.File(baseDir, "moduleB/moduleB1")));
-
- DefaultIndex index = new DefaultIndex(resourceCache, projectTree, mock(MetricFinder.class), mock(MeasureCache.class));
-
- index.start();
-
- Resource file = File.create("src/main/java/org/Foo.java");
-
- index.setCurrentProject(moduleB1, null);
- index.index(file);
-
- persister.persist();
-
- checkTables("shouldSaveNewMultiModulesProjectUsingIndex",
- new String[] {"build_date", "created_at", "authorization_updated_at", "uuid", "project_uuid", "module_uuid", "module_uuid_path"}, "projects", "snapshots");
-
- // Need to enable snapshot to make resource visible using ComponentMapper
- enableSnapshot(1001);
- enableSnapshot(1002);
- enableSnapshot(1003);
- enableSnapshot(1004);
- enableSnapshot(1005);
- enableSnapshot(1006);
- try (SqlSession session = getMyBatis().openSession(false)) {
- ComponentDto root = session.getMapper(ComponentMapper.class).selectByKey("root");
- System.out.println("Root: " + root.uuid());
- assertThat(root.uuid()).isNotNull();
- assertThat(root.projectUuid()).isEqualTo(root.uuid());
- assertThat(root.moduleUuid()).isNull();
- assertThat(root.moduleUuidPath()).isEqualTo(MODULE_UUID_PATH_SEPARATOR + root.uuid() + MODULE_UUID_PATH_SEPARATOR);
- ComponentDto a = session.getMapper(ComponentMapper.class).selectByKey("a");
- System.out.println("A: " + a.uuid());
- assertThat(a.uuid()).isNotNull();
- assertThat(a.projectUuid()).isEqualTo(root.uuid());
- assertThat(a.moduleUuid()).isEqualTo(root.uuid());
- assertThat(a.moduleUuidPath()).isEqualTo(MODULE_UUID_PATH_SEPARATOR + root.uuid() + MODULE_UUID_PATH_SEPARATOR + a.uuid() + MODULE_UUID_PATH_SEPARATOR);
- ComponentDto b = session.getMapper(ComponentMapper.class).selectByKey("b");
- System.out.println("B: " + b.uuid());
- assertThat(b.uuid()).isNotNull();
- assertThat(b.projectUuid()).isEqualTo(root.uuid());
- assertThat(b.moduleUuid()).isEqualTo(root.uuid());
- assertThat(b.moduleUuidPath()).isEqualTo(MODULE_UUID_PATH_SEPARATOR + root.uuid() + MODULE_UUID_PATH_SEPARATOR + b.uuid() + MODULE_UUID_PATH_SEPARATOR);
- ComponentDto b1 = session.getMapper(ComponentMapper.class).selectByKey("b1");
- System.out.println("B1: " + b1.uuid());
- assertThat(b1.uuid()).isNotNull();
- assertThat(b1.projectUuid()).isEqualTo(root.uuid());
- assertThat(b1.moduleUuid()).isEqualTo(b.uuid());
- assertThat(b1.moduleUuidPath()).isEqualTo(
- MODULE_UUID_PATH_SEPARATOR + root.uuid() + MODULE_UUID_PATH_SEPARATOR + b.uuid() + MODULE_UUID_PATH_SEPARATOR + b1.uuid() + MODULE_UUID_PATH_SEPARATOR);
- ComponentDto dir = session.getMapper(ComponentMapper.class).selectByKey("b1:src/main/java/org");
- assertThat(dir.uuid()).isNotNull();
- assertThat(dir.projectUuid()).isEqualTo(root.uuid());
- assertThat(dir.moduleUuid()).isEqualTo(b1.uuid());
- assertThat(dir.moduleUuidPath()).isEqualTo(
- MODULE_UUID_PATH_SEPARATOR + root.uuid() + MODULE_UUID_PATH_SEPARATOR + b.uuid() + MODULE_UUID_PATH_SEPARATOR + b1.uuid() + MODULE_UUID_PATH_SEPARATOR);
- ComponentDto fileComp = session.getMapper(ComponentMapper.class).selectByKey("b1:src/main/java/org/Foo.java");
- assertThat(fileComp.uuid()).isNotNull();
- assertThat(fileComp.projectUuid()).isEqualTo(root.uuid());
- assertThat(fileComp.moduleUuid()).isEqualTo(b1.uuid());
- assertThat(fileComp.moduleUuidPath()).isEqualTo(
- MODULE_UUID_PATH_SEPARATOR + root.uuid() + MODULE_UUID_PATH_SEPARATOR + b.uuid() + MODULE_UUID_PATH_SEPARATOR + b1.uuid() + MODULE_UUID_PATH_SEPARATOR);
- }
- }
-
- @Test
- public void shouldSaveNewDirectory() {
- setupData("shared");
-
- resourceCache.add(singleProject, null).setSnapshot(persister.persist(null, singleProject, null));
- persister.persist(singleProject, Directory.create("src/main/java/org/foo").setEffectiveKey("foo:src/main/java/org/foo"), null);
- // check that the directory is attached to the project
- checkTables("shouldSaveNewDirectory", new String[] {"build_date", "created_at", "authorization_updated_at", "uuid", "project_uuid", "module_uuid", "module_uuid_path"},
- "projects", "snapshots");
-
- // Need to enable snapshot to make resource visible using ComponentMapper
- enableSnapshot(1001);
- enableSnapshot(1002);
- try (SqlSession session = getMyBatis().openSession(false)) {
- ComponentDto newProject = session.getMapper(ComponentMapper.class).selectByKey("foo");
- ComponentDto newDir = session.getMapper(ComponentMapper.class).selectByKey("foo:src/main/java/org/foo");
- assertThat(newDir.uuid()).isNotNull();
- assertThat(newDir.projectUuid()).isEqualTo(newProject.uuid());
- assertThat(newDir.moduleUuid()).isEqualTo(newProject.uuid());
- assertThat(newDir.moduleUuidPath()).isEqualTo(MODULE_UUID_PATH_SEPARATOR + newProject.uuid() + MODULE_UUID_PATH_SEPARATOR);
- }
- }
-
- private void enableSnapshot(int resourceId) {
- String hql = "UPDATE " + Snapshot.class.getSimpleName() + " SET last=true";
- hql += " WHERE project_id=:resourceId";
- Query query = getSession().createQuery(hql);
- query.setParameter("resourceId", resourceId);
- query.executeUpdate();
- getSession().commit();
- }
-
- @Test
- public void shouldUpdateExistingResource() {
- setupData("shouldUpdateExistingResource");
-
- singleProject.setName("new name");
- singleProject.setDescription("new description");
- persister.persist(null, singleProject, null);
-
- checkTables("shouldUpdateExistingResource", new String[] {"build_date", "created_at", "authorization_updated_at"}, "projects", "snapshots");
- }
-
- // SONAR-1700
- @Test
- public void shouldRemoveRootIndexIfResourceIsProject() {
- setupData("shouldRemoveRootIndexIfResourceIsProject");
-
- persister.persist(null, singleProject, null);
-
- checkTables("shouldRemoveRootIndexIfResourceIsProject", new String[] {"build_date", "created_at", "authorization_updated_at"}, "projects", "snapshots");
- }
-
- @Test
- public void shouldGrantDefaultPermissionsIfNewProject() {
- setupData("shared");
-
- when(permissions.hasRoles(singleProject)).thenReturn(false);
-
- persister.persist(null, singleProject, null);
-
- verify(permissions).grantDefaultRoles(singleProject);
- }
-
- @Test
- public void shouldNotGrantDefaultPermissionsOnModules() {
- setupData("shared");
- resourceCache.add(multiModuleProject, null).setSnapshot(persister.persist(null, multiModuleProject, null));
- resourceCache.add(moduleA, multiModuleProject).setSnapshot(persister.persist(null, moduleA, multiModuleProject));
- when(permissions.hasRoles(multiModuleProject)).thenReturn(true);
- persister.persist(null, multiModuleProject, null);
-
- persister.persist(null, moduleA, multiModuleProject);
-
- verify(permissions, never()).grantDefaultRoles(moduleA);
- }
-
- @Test
- public void shouldNotGrantDefaultPermissionsIfExistingProject() {
- setupData("shared");
-
- when(permissions.hasRoles(singleProject)).thenReturn(true);
-
- persister.persist(null, singleProject, null);
-
- verify(permissions, never()).grantDefaultRoles(singleProject);
- }
-
- private static Project newProject(String key, String language) {
- Settings settings = new Settings();
- settings.setProperty(CoreProperties.PROJECT_LANGUAGE_PROPERTY, language);
- return new Project(key).setSettings(settings).setAnalysisType(Project.AnalysisType.DYNAMIC);
- }
-
- private static Project newCopyProject(String key, String language, int copyResourceId) {
- Settings settings = new Settings();
- settings.setProperty(CoreProperties.PROJECT_LANGUAGE_PROPERTY, language);
- return new CopyProject(key, copyResourceId).setSettings(settings).setAnalysisType(Project.AnalysisType.DYNAMIC);
- }
-
- private static class CopyProject extends Project implements ResourceCopy {
-
- private int copyResourceId;
-
- public CopyProject(String key, int copyResourceId) {
- super(key);
- this.copyResourceId = copyResourceId;
- }
-
- public int getCopyResourceId() {
- return copyResourceId;
- }
-
- }
-
-}
diff --git a/sonar-batch/src/test/java/org/sonar/batch/issue/tracking/InitialOpenIssuesSensorTest.java b/sonar-batch/src/test/java/org/sonar/batch/issue/tracking/InitialOpenIssuesSensorTest.java
index 85c1e43c51a..1b4a6adf544 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/issue/tracking/InitialOpenIssuesSensorTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/issue/tracking/InitialOpenIssuesSensorTest.java
@@ -24,37 +24,53 @@ import org.junit.Test;
import org.sonar.api.resources.Project;
import org.sonar.core.issue.db.IssueChangeDao;
import org.sonar.core.issue.db.IssueDao;
+import org.sonar.core.resource.ResourceDao;
+import org.sonar.core.resource.ResourceDto;
+import org.sonar.core.resource.ResourceQuery;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyZeroInteractions;
+import static org.mockito.Mockito.when;
public class InitialOpenIssuesSensorTest {
InitialOpenIssuesStack stack = mock(InitialOpenIssuesStack.class);
IssueDao issueDao = mock(IssueDao.class);
IssueChangeDao issueChangeDao = mock(IssueChangeDao.class);
+ ResourceDao resourceDao = mock(ResourceDao.class);
- InitialOpenIssuesSensor sensor = new InitialOpenIssuesSensor(stack, issueDao, issueChangeDao);
+ InitialOpenIssuesSensor sensor = new InitialOpenIssuesSensor(stack, issueDao, issueChangeDao, resourceDao);
@Test
public void should_select_module_open_issues() {
- Project project = new Project("key");
- project.setId(1);
- sensor.analyse(project, null);
+ when(resourceDao.getResource(any(ResourceQuery.class))).thenReturn(new ResourceDto().setId(1L));
- verify(issueDao).selectNonClosedIssuesByModule(eq(1), any(ResultHandler.class));
+ sensor.analyse(new Project("key"), null);
+
+ verify(issueDao).selectNonClosedIssuesByModule(eq(1L), any(ResultHandler.class));
}
@Test
public void should_select_module_open_issues_changelog() {
- Project project = new Project("key");
- project.setId(1);
- sensor.analyse(project, null);
+ when(resourceDao.getResource(any(ResourceQuery.class))).thenReturn(new ResourceDto().setId(1L));
+
+ sensor.analyse(new Project("key"), null);
+
+ verify(issueChangeDao).selectChangelogOnNonClosedIssuesByModuleAndType(eq(1L), any(ResultHandler.class));
+ }
+
+ @Test
+ public void nothing_to_on_new_component() {
+ when(resourceDao.getResource(any(ResourceQuery.class))).thenReturn(null);
+
+ sensor.analyse(new Project("key"), null);
- verify(issueChangeDao).selectChangelogOnNonClosedIssuesByModuleAndType(eq(1), any(ResultHandler.class));
+ verifyZeroInteractions(issueDao);
+ verifyZeroInteractions(issueChangeDao);
}
@Test
diff --git a/sonar-batch/src/test/java/org/sonar/batch/qualitygate/QualityGateVerifierTest.java b/sonar-batch/src/test/java/org/sonar/batch/qualitygate/QualityGateVerifierTest.java
index 12194f753ca..1579a537074 100644
--- a/sonar-batch/src/test/java/org/sonar/batch/qualitygate/QualityGateVerifierTest.java
+++ b/sonar-batch/src/test/java/org/sonar/batch/qualitygate/QualityGateVerifierTest.java
@@ -21,8 +21,11 @@ package org.sonar.batch.qualitygate;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
+import java.util.ArrayList;
+import java.util.Locale;
import org.apache.commons.lang.NotImplementedException;
import org.junit.Before;
+import org.junit.Ignore;
import org.junit.Test;
import org.mockito.ArgumentMatcher;
import org.sonar.api.batch.DecoratorBarriers;
@@ -43,9 +46,6 @@ import org.sonar.batch.index.BatchComponentCache;
import org.sonar.core.qualitygate.db.QualityGateConditionDto;
import org.sonar.core.timemachine.Periods;
-import java.util.ArrayList;
-import java.util.Locale;
-
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.anyString;
@@ -70,7 +70,6 @@ public class QualityGateVerifierTest {
Periods periods;
I18n i18n;
Durations durations;
- private BatchComponentCache resourceCache;
@Before
public void before() {
@@ -94,7 +93,7 @@ public class QualityGateVerifierTest {
project = new Project("foo");
- resourceCache = new BatchComponentCache();
+ BatchComponentCache resourceCache = new BatchComponentCache();
resourceCache.add(project, null).setSnapshot(snapshot);
verifier = new QualityGateVerifier(qualityGate, resourceCache, periods, i18n, durations);
@@ -357,6 +356,7 @@ public class QualityGateVerifierTest {
}
@Test
+ @Ignore("Disabled because snapshot is no more created by the batch")
public void shouldLabelAlertContainsPeriod() {
measureClasses.setVariation1(40d);
@@ -376,6 +376,7 @@ public class QualityGateVerifierTest {
}
@Test
+ @Ignore("Disabled because snapshot is no more created by the batch")
public void shouldLabelAlertForNewMetricDoNotContainsVariationWord() {
Metric newMetric = new Metric.Builder("new_metric_key", "New Metric", Metric.ValueType.INT).create();
Measure measure = new Measure(newMetric, 15d);
diff --git a/sonar-batch/src/test/resources/org/sonar/batch/compute/TimeMachineConfigurationPersisterTest/shared.xml b/sonar-batch/src/test/resources/org/sonar/batch/compute/TimeMachineConfigurationPersisterTest/shared.xml
deleted file mode 100644
index 70c8178d4e8..00000000000
--- a/sonar-batch/src/test/resources/org/sonar/batch/compute/TimeMachineConfigurationPersisterTest/shared.xml
+++ /dev/null
@@ -1,42 +0,0 @@
-<dataset>
- <snapshots purge_status="[null]"
- period1_mode="[null]" period1_param="[null]" period1_date="[null]"
- period2_mode="[null]" period2_param="[null]" period2_date="[null]"
- period3_mode="[null]" period3_param="[null]" period3_date="[null]"
- period4_mode="[null]" period4_param="[null]" period4_date="[null]"
- period5_mode="[null]" period5_param="[null]" period5_date="[null]"
- id="100" project_id="1" parent_snapshot_id="[null]" root_project_id="1" root_snapshot_id="[null]"
- scope="PRJ" qualifier="TRK" created_at="1225544280000" build_date="1225544280000" version="[null]" path=""
- status="P" islast="false" depth="0" />
-
- <snapshots purge_status="[null]"
- period1_mode="[null]" period1_param="[null]" period1_date="[null]"
- period2_mode="[null]" period2_param="[null]" period2_date="[null]"
- period3_mode="[null]" period3_param="[null]" period3_date="[null]"
- period4_mode="[null]" period4_param="[null]" period4_date="[null]"
- period5_mode="[null]" period5_param="[null]" period5_date="[null]"
- id="200" project_id="1" parent_snapshot_id="[null]" root_project_id="1" root_snapshot_id="[null]"
- scope="PRJ" qualifier="TRK" created_at="1229345880000" build_date="1229345880000" version="[null]" path=""
- status="P" islast="false" depth="0" />
-
- <!-- Snapshot of previous version -->
- <snapshots purge_status="[null]"
- period1_mode="[null]" period1_param="[null]" period1_date="[null]"
- period2_mode="[null]" period2_param="[null]" period2_date="[null]"
- period3_mode="[null]" period3_param="[null]" period3_date="[null]"
- period4_mode="[null]" period4_param="[null]" period4_date="[null]"
- period5_mode="[null]" period5_param="[null]" period5_date="[null]"
- id="300" project_id="1" parent_snapshot_id="[null]" root_project_id="1" root_snapshot_id="[null]"
- scope="PRJ" qualifier="TRK" created_at="1229173080000" build_date="1229173080000" version="1.2.3" path=""
- status="P" islast="false" depth="0" />
-
- <snapshots purge_status="[null]"
- period1_mode="[null]" period1_param="[null]" period1_date="[null]"
- period2_mode="[null]" period2_param="[null]" period2_date="[null]"
- period3_mode="[null]" period3_param="[null]" period3_date="[null]"
- period4_mode="[null]" period4_param="[null]" period4_date="[null]"
- period5_mode="[null]" period5_param="[null]" period5_date="[null]"
- id="1000" project_id="1" parent_snapshot_id="[null]" root_project_id="1" root_snapshot_id="[null]"
- scope="PRJ" qualifier="TRK" created_at="1235566680000" build_date="1235566680000" version="[null]" path=""
- status="P" islast="false" depth="0" />
-</dataset>
diff --git a/sonar-batch/src/test/resources/org/sonar/batch/compute/TimeMachineConfigurationPersisterTest/shouldSaveConfigurationInSnapshotsTable-result.xml b/sonar-batch/src/test/resources/org/sonar/batch/compute/TimeMachineConfigurationPersisterTest/shouldSaveConfigurationInSnapshotsTable-result.xml
deleted file mode 100644
index 34fdf2d4d32..00000000000
--- a/sonar-batch/src/test/resources/org/sonar/batch/compute/TimeMachineConfigurationPersisterTest/shouldSaveConfigurationInSnapshotsTable-result.xml
+++ /dev/null
@@ -1,42 +0,0 @@
-<dataset>
- <snapshots purge_status="[null]"
- period1_mode="[null]" period1_param="[null]" period1_date="[null]"
- period2_mode="[null]" period2_param="[null]" period2_date="[null]"
- period3_mode="[null]" period3_param="[null]" period3_date="[null]"
- period4_mode="[null]" period4_param="[null]" period4_date="[null]"
- period5_mode="[null]" period5_param="[null]" period5_date="[null]"
- id="100" project_id="1" parent_snapshot_id="[null]" root_project_id="1" root_snapshot_id="[null]"
- scope="PRJ" qualifier="TRK" created_at="1225544280000" build_date="1225544280000" version="[null]" path=""
- status="P" islast="false" depth="0" />
-
- <snapshots purge_status="[null]"
- period1_mode="[null]" period1_param="[null]" period1_date="[null]"
- period2_mode="[null]" period2_param="[null]" period2_date="[null]"
- period3_mode="[null]" period3_param="[null]" period3_date="[null]"
- period4_mode="[null]" period4_param="[null]" period4_date="[null]"
- period5_mode="[null]" period5_param="[null]" period5_date="[null]"
- id="200" project_id="1" parent_snapshot_id="[null]" root_project_id="1" root_snapshot_id="[null]"
- scope="PRJ" qualifier="TRK" created_at="1229345880000" build_date="1229345880000" version="[null]" path=""
- status="P" islast="false" depth="0" />
-
- <!-- Snapshot of previous version -->
- <snapshots purge_status="[null]"
- period1_mode="[null]" period1_param="[null]" period1_date="[null]"
- period2_mode="[null]" period2_param="[null]" period2_date="[null]"
- period3_mode="[null]" period3_param="[null]" period3_date="[null]"
- period4_mode="[null]" period4_param="[null]" period4_date="[null]"
- period5_mode="[null]" period5_param="[null]" period5_date="[null]"
- id="300" project_id="1" parent_snapshot_id="[null]" root_project_id="1" root_snapshot_id="[null]"
- scope="PRJ" qualifier="TRK" created_at="1229173080000" build_date="1229173080000" version="1.2.3" path=""
- status="P" islast="false" depth="0" />
-
- <snapshots purge_status="[null]"
- period1_mode="days" period1_param="30" period1_date="1225544280000"
- period2_mode="[null]" period2_param="[null]" period2_date="[null]"
- period3_mode="version" period3_param="1.2.3" period3_date="1229173080000"
- period4_mode="[null]" period4_param="[null]" period4_date="[null]"
- period5_mode="[null]" period5_param="[null]" period5_date="[null]"
- id="1000" project_id="1" parent_snapshot_id="[null]" root_project_id="1" root_snapshot_id="[null]"
- scope="PRJ" qualifier="TRK" created_at="1235566680000" build_date="1235566680000" version="[null]" path=""
- status="P" islast="false" depth="0" />
-</dataset>