Refine search
public String key() { return r.getEffectiveKey(); }
public ResourceNode(Resource sonarResource, @Nullable File path, Charset encoding) { this.path = path; this.encoding = encoding; this.key = sonarResource.getEffectiveKey(); this.name = sonarResource.getName(); this.longName = sonarResource.getLongName(); this.scope = sonarResource.getScope(); }
boolean shouldComputeVariation(Resource resource) { if (Scopes.FILE.equals(resource.getScope()) && !Qualifiers.UNIT_TEST_FILE.equals(resource.getQualifier())) { return false; } // measures on files are currently purged, so past measures are not available on files return StringUtils.equals(Scopes.PROJECT, resource.getScope()) || StringUtils.equals(Scopes.DIRECTORY, resource.getScope()); }
/** * Views plugin creates copy of technical projects and should be allowed to copy all measures even internal ones */ private boolean isViewResource(Resource resource) { boolean isTechnicalProject = Scopes.FILE.equals(resource.getScope()) && Qualifiers.PROJECT.equals(resource.getQualifier()); return isTechnicalProject || ResourceUtils.isView(resource) || ResourceUtils.isSubview(resource); }
private Violation createViolationOnResource(Resource<?> resource, Integer lineNumber) { if (StringUtils.isNotEmpty(currentSource) && resource == null) { LOG.debug("Ignoring violation on file outside current project ({})", currentSource); return null; } if (resource != null && !resourceHelper.isResourceInProject(resource, project)) { LOG.debug("Ignoring violation on file outside current project ({})", resource.getKey()); return null; } Violation violation = Violation.create(currentRule, resource); if (lineNumber != null) { violation.setLineId(lineNumber); } if (StringUtils.isEmpty(currentMessage)) { violation.setMessage(currentDefaultViolationMessage); } else { violation.setMessage(currentMessage); } violation.setSeverity(currentRule.getSeverity()); context.saveViolation(violation); return violation; }
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()); } if (!ResourceUtils.isLibrary(resource)) { model.setScope(resource.getScope()); model.setQualifier(resource.getQualifier()); } Language language = resource.getLanguage(); if (language != null) { model.setLanguageKey(language.getKey()); } } }
return null; if (StringUtils.isNotBlank(reference.getKey())) { return buckets.get(reference);
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); } }
private Bucket doIndex(Resource resource, @Nullable Resource parentReference) { Bucket bucket = getBucket(resource); if (bucket != null) { return bucket; } if (StringUtils.isBlank(resource.getKey())) { LOG.warn("Unable to index a resource without key " + resource); return null; } Resource parent = (Resource) ObjectUtils.defaultIfNull(parentReference, currentProject); Bucket parentBucket = getBucket(parent); if (parentBucket == null && parent != null) { LOG.warn("Resource ignored, parent is not indexed: " + resource); return null; } if (ResourceUtils.isProject(resource) || /* For technical projects */ResourceUtils.isRootProject(resource)) { resource.setEffectiveKey(resource.getKey()); } else { resource.setEffectiveKey(ComponentKeys.createEffectiveKey(currentProject, resource)); } bucket = new Bucket(resource).setParent(parentBucket); addBucket(resource, bucket); Resource parentResource = parentBucket != null ? parentBucket.getResource() : null; BatchComponent component = componentCache.add(resource, parentResource); if (ResourceUtils.isProject(resource)) { component.setInputComponent(new DefaultInputModule(resource.getEffectiveKey())); } return bucket; }
private Bucket doIndex(Resource resource, @Nullable Resource parentReference) { Bucket bucket = getBucket(resource); if (bucket != null) { return bucket; } if (StringUtils.isBlank(resource.getKey())) { LOG.warn("Unable to index a resource without key " + resource); return null; } Resource parent = null; if (!ResourceUtils.isLibrary(resource)) { // a library has no parent parent = (Resource) ObjectUtils.defaultIfNull(parentReference, currentProject); } Bucket parentBucket = getBucket(parent); if (parentBucket == null && parent != null) { LOG.warn("Resource ignored, parent is not indexed: " + resource); return null; } if (ResourceUtils.isProject(resource) || /* For technical projects */ResourceUtils.isRootProject(resource)) { resource.setEffectiveKey(resource.getKey()); } else { resource.setEffectiveKey(ComponentKeys.createEffectiveKey(currentProject, resource)); } bucket = new Bucket(resource).setParent(parentBucket); addBucket(resource, bucket); Resource parentResource = parentBucket != null ? parentBucket.getResource() : null; resourceCache.add(resource, parentResource); return bucket; }
public List<Object[]> getPastMeasures(Resource resource, PastSnapshot projectPastSnapshot) { if (projectPastSnapshot != null && projectPastSnapshot.getProjectSnapshot() != null) { return getPastMeasures(resource.getEffectiveKey(), resource.getPath(), projectPastSnapshot.getProjectSnapshot()); } return Collections.emptyList(); }
protected void notifyUsers(Resource resource, String alertName, String alertText, Level alertLevel, boolean isNewAlert) { Notification notification = new Notification("alerts") .setDefaultMessage("Alert on " + resource.getLongName() + ": " + alertName) .setFieldValue("projectName", resource.getLongName()) .setFieldValue("projectKey", resource.getKey()) .setFieldValue("projectId", String.valueOf(resource.getId())) .setFieldValue("alertName", alertName) .setFieldValue("alertText", alertText) .setFieldValue("alertLevel", alertLevel.toString()) .setFieldValue("isNewAlert", Boolean.toString(isNewAlert)); notificationManager.scheduleForSending(notification); }
private void serializeRow(int y) { Resource sonarResource = (Resource) dsm.getVertex(y); json.append("{"); if (sonarResource != null) { json.append("\"i\":"); json.append(sonarResource.getId()); json.append(",\"n\":\""); json.append(sonarResource.getName()); json.append("\",\"q\":\""); json.append(sonarResource.getQualifier()); json.append("\",\"v\":["); for (int x = 0; x < dsm.getDimension(); x++) { if (x > 0) { json.append(','); } serializeCell(y, x); } json.append("]"); } json.append("}"); }
private void createIssue(Resource resource, RuleKey ruleKey, double testFailuresAndErrors, ResourcePerspectives perspectives) { String fileName = resource.getName(); createIssue(resource, perspectives, ruleKey, testFailuresAndErrors, "Fix failing unit tests on file \"" + fileName + "\"."); }
/** * @return whether a resource is a set */ public static boolean isSet(Resource resource) { return resource != null && Scopes.PROJECT.equals(resource.getScope()); }
public void saveEvent(Resource resource, Event event) { BatchResource batchResource = resourceCache.get(resource.getEffectiveKey()); checkState(batchResource != null, "Unknown component: " + resource); event.setCreatedAt(new Date(system2.now())); if (event.getDate() == null) { event.setSnapshot(batchResource.snapshot()); } else { event.setResourceId(batchResource.resource().getId()); } session.save(event); session.commit(); } }
/** * @return the language of the resource. Only {@link File}s may have a non null value. */ @CheckForNull public String language() { Language l = getLanguage(); return l != null ? l.getKey() : null; }
@Override public int hashCode() { return resource.hashCode(); } }