@Override public void setSource(Resource reference, String source) { Bucket bucket = checkIndexed(reference); if (bucket != null && !bucket.isExcluded()) { persistence.setSource(reference, source); } }
void doStart(Project rootProject) { Bucket bucket = new Bucket(rootProject); buckets.put(rootProject, bucket); persistence.saveProject(rootProject, null); currentProject = rootProject; for (Project project : rootProject.getModules()) { addProject(project); } }
@Override public Event addEvent( Resource resource, String name, String description, String category, Date date) { Event event = new Event(name, description, category); event.setDate(date); event.setCreatedAt(new Date()); persistence.saveEvent(resource, event); return null; }
@Override public Measure getMeasure(Resource resource, Metric metric) { Bucket bucket = buckets.get(resource); if (bucket != null) { Measure measure = bucket.getMeasures(MeasuresFilters.metric(metric)); if (measure != null) { return persistence.reloadMeasure(measure); } } return null; }
@Override public Dependency addDependency(Dependency dependency) { Dependency existingDep = getEdge(dependency.getFrom(), dependency.getTo()); if (existingDep != null) { return existingDep; } Dependency parentDependency = dependency.getParent(); if (parentDependency != null) { addDependency(parentDependency); } if (registerDependency(dependency)) { persistence.saveDependency(currentProject, dependency, parentDependency); } return dependency; }
/** the measure is updated if it's already registered. */ @Override public Measure addMeasure(Resource resource, Measure measure) { Bucket bucket = checkIndexed(resource); if (bucket != null && !bucket.isExcluded()) { Metric metric = metricFinder.findByKey(measure.getMetricKey()); if (metric == null) { throw new SonarException("Unknown metric: " + measure.getMetricKey()); } measure.setMetric(metric); bucket.addMeasure(measure); if (measure.getPersistenceMode().useDatabase()) { persistence.saveMeasure(resource, measure); } } return measure; }
private Bucket doIndex(Resource resource, Resource parentReference) { Bucket bucket = buckets.get(resource); if (bucket != null) { return bucket; } checkLock(resource); Resource parent = null; if (!ResourceUtils.isLibrary(resource)) { // a library has no parent parent = (Resource) ObjectUtils.defaultIfNull(parentReference, currentProject); } Bucket parentBucket = getBucket(parent, true); if (parentBucket == null && parent != null) { LOG.warn("Resource ignored, parent is not indexed: " + resource); return null; } resource.setEffectiveKey(createUID(currentProject, resource)); bucket = new Bucket(resource).setParent(parentBucket); buckets.put(resource, bucket); boolean excluded = checkExclusion(resource, parentBucket); if (!excluded) { Snapshot snapshot = persistence.saveResource( currentProject, resource, (parentBucket != null ? parentBucket.getResource() : null)); if (ResourceUtils.isPersistable(resource) && !Qualifiers.LIBRARY.equals(resource.getQualifier())) { graph.addComponent(resource, snapshot); } } return bucket; }
@Override public String getSource(Resource resource) { return persistence.getSource(resource); }
@Override public void deleteEvent(Event event) { persistence.deleteEvent(event); }
@Override public List<Event> getEvents(Resource resource) { // currently events are not cached in memory return persistence.getEvents(resource); }
@Override public void deleteLink(String key) { persistence.deleteLink(currentProject, key); }
@Override public void addLink(ProjectLink link) { persistence.saveLink(currentProject, link); }