Skip to content

Commit

Permalink
SONAR-6014 Isolate persistence of resources to ease its removal in pr…
Browse files Browse the repository at this point in the history
…eview mode
  • Loading branch information
henryju committed Jan 7, 2015
1 parent 5e0ae3e commit bde5316
Show file tree
Hide file tree
Showing 29 changed files with 397 additions and 405 deletions.
Expand Up @@ -49,7 +49,7 @@ public void shouldSaveConfigurationInSnapshotsTable() {


ResourceCache resourceCache = new ResourceCache(); ResourceCache resourceCache = new ResourceCache();
Project project = new Project("foo"); Project project = new Project("foo");
resourceCache.add(project, null, projectSnapshot); resourceCache.add(project, null).setSnapshot(projectSnapshot);


TimeMachineConfigurationPersister persister = new TimeMachineConfigurationPersister(timeMachineConfiguration, resourceCache, getSession()); TimeMachineConfigurationPersister persister = new TimeMachineConfigurationPersister(timeMachineConfiguration, resourceCache, getSession());


Expand Down
Expand Up @@ -32,14 +32,13 @@ public class BatchResource {


private final long batchId; private final long batchId;
private final Resource r; private final Resource r;
private final Snapshot s; private Snapshot s;
private final BatchResource parent; private final BatchResource parent;
private final Collection<BatchResource> children = new ArrayList<BatchResource>(); private final Collection<BatchResource> children = new ArrayList<BatchResource>();


public BatchResource(long batchId, Resource r, Snapshot s, @Nullable BatchResource parent) { public BatchResource(long batchId, Resource r, @Nullable BatchResource parent) {
this.batchId = batchId; this.batchId = batchId;
this.r = r; this.r = r;
this.s = s;
this.parent = parent; this.parent = parent;
if (parent != null) { if (parent != null) {
parent.children.add(this); parent.children.add(this);
Expand All @@ -54,6 +53,11 @@ public Resource resource() {
return r; return r;
} }


public BatchResource setSnapshot(Snapshot snapshot) {
this.s = snapshot;
return this;
}

public int snapshotId() { public int snapshotId() {
return s.getId(); return s.getId();
} }
Expand Down
20 changes: 7 additions & 13 deletions sonar-batch/src/main/java/org/sonar/batch/index/DefaultIndex.java
Expand Up @@ -55,7 +55,6 @@
import org.sonar.batch.scan.measure.MeasureCache; import org.sonar.batch.scan.measure.MeasureCache;
import org.sonar.batch.scan2.DefaultSensorContext; import org.sonar.batch.scan2.DefaultSensorContext;
import org.sonar.core.component.ComponentKeys; import org.sonar.core.component.ComponentKeys;
import org.sonar.core.component.ScanGraph;


import javax.annotation.CheckForNull; import javax.annotation.CheckForNull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
Expand All @@ -75,9 +74,8 @@ public class DefaultIndex extends SonarIndex {


private static final Logger LOG = LoggerFactory.getLogger(DefaultIndex.class); private static final Logger LOG = LoggerFactory.getLogger(DefaultIndex.class);


private ResourcePersister resourcePersister; private final ResourceCache resourceCache;
private MetricFinder metricFinder; private final MetricFinder metricFinder;
private final ScanGraph graph;


// caches // caches
private Project currentProject; private Project currentProject;
Expand All @@ -95,16 +93,15 @@ public class DefaultIndex extends SonarIndex {
private final LinkPersister linkPersister; private final LinkPersister linkPersister;
private final EventPersister eventPersister; private final EventPersister eventPersister;


public DefaultIndex(ResourcePersister resourcePersister, DependencyPersister dependencyPersister, public DefaultIndex(ResourceCache resourceCache, DependencyPersister dependencyPersister,
LinkPersister linkPersister, EventPersister eventPersister, ProjectTree projectTree, MetricFinder metricFinder, LinkPersister linkPersister, EventPersister eventPersister, ProjectTree projectTree, MetricFinder metricFinder,
ScanGraph graph, DeprecatedViolations deprecatedViolations, ResourceKeyMigration migration, MeasureCache measureCache) { DeprecatedViolations deprecatedViolations, ResourceKeyMigration migration, MeasureCache measureCache) {
this.resourcePersister = resourcePersister; this.resourceCache = resourceCache;
this.dependencyPersister = dependencyPersister; this.dependencyPersister = dependencyPersister;
this.linkPersister = linkPersister; this.linkPersister = linkPersister;
this.eventPersister = eventPersister; this.eventPersister = eventPersister;
this.projectTree = projectTree; this.projectTree = projectTree;
this.metricFinder = metricFinder; this.metricFinder = metricFinder;
this.graph = graph;
this.deprecatedViolations = deprecatedViolations; this.deprecatedViolations = deprecatedViolations;
this.migration = migration; this.migration = migration;
this.measureCache = measureCache; this.measureCache = measureCache;
Expand All @@ -121,7 +118,7 @@ void doStart(Project rootProject) {
Bucket bucket = new Bucket(rootProject); Bucket bucket = new Bucket(rootProject);
addBucket(rootProject, bucket); addBucket(rootProject, bucket);
migration.checkIfMigrationNeeded(rootProject); migration.checkIfMigrationNeeded(rootProject);
resourcePersister.saveProject(rootProject, null); resourceCache.add(rootProject, null);
currentProject = rootProject; currentProject = rootProject;


for (Project module : rootProject.getModules()) { for (Project module : rootProject.getModules()) {
Expand Down Expand Up @@ -593,10 +590,7 @@ private Bucket doIndex(Resource resource, @Nullable Resource parentReference) {
addBucket(resource, bucket); addBucket(resource, bucket);


Resource parentResource = parentBucket != null ? parentBucket.getResource() : null; Resource parentResource = parentBucket != null ? parentBucket.getResource() : null;
BatchResource batchResource = resourcePersister.saveResource(currentProject, resource, parentResource); resourceCache.add(resource, parentResource);
if (ResourceUtils.isPersistable(resource) && !Qualifiers.LIBRARY.equals(resource.getQualifier())) {
graph.addComponent(resource, batchResource.snapshotId());
}


return bucket; return bucket;
} }
Expand Down

0 comments on commit bde5316

Please sign in to comment.