public Collection<Dependency> getIncomingEdges(Resource to) { Map<Resource, Dependency> deps = incomingDependenciesByResource.get(to); if (deps != null) { return deps.values(); } return Collections.emptyList(); }
public Collection<Dependency> getOutgoingEdges(Resource from) { Map<Resource, Dependency> deps = outgoingDependenciesByResource.get(from); if (deps != null) { return deps.values(); } return Collections.emptyList(); }
public Dependency getEdge(Resource from, Resource to) { Map<Resource, Dependency> map = outgoingDependenciesByResource.get(from); if (map != null) { return map.get(to); } return null; }
private void registerIncomingDependency(Dependency dependency) { Map<Resource, Dependency> incomingDeps = incomingDependenciesByResource.get(dependency.getTo()); if (incomingDeps == null) { incomingDeps = new HashMap<Resource, Dependency>(); incomingDependenciesByResource.put(dependency.getTo(), incomingDeps); } incomingDeps.put(dependency.getFrom(), dependency); }
private void registerOutgoingDependency(Dependency dependency) { Map<Resource, Dependency> outgoingDeps = outgoingDependenciesByResource.get(dependency.getFrom()); if (outgoingDeps == null) { outgoingDeps = new HashMap<Resource, Dependency>(); outgoingDependenciesByResource.put(dependency.getFrom(), outgoingDeps); } outgoingDeps.put(dependency.getTo(), dependency); }
/** Keep only project stuff */ public void clear() { Iterator<Map.Entry<Resource, Bucket>> it = buckets.entrySet().iterator(); while (it.hasNext()) { Map.Entry<Resource, Bucket> entry = it.next(); Resource resource = entry.getKey(); if (!ResourceUtils.isSet(resource)) { entry.getValue().clear(); it.remove(); } } // store dependencies for (Dependency dep : dependencies) { dependencyPersister.saveDependency(currentProject, dep); } // Keep only inter module dependencies Set<Dependency> projectDependencies = getDependenciesBetweenProjects(); dependencies.clear(); incomingDependenciesByResource.clear(); outgoingDependenciesByResource.clear(); for (Dependency projectDependency : projectDependencies) { projectDependency.setId(null); registerDependency(projectDependency); } }
/** {@inheritDoc} */ @Override public List<Violation> getViolations(ViolationQuery violationQuery) { Resource resource = violationQuery.getResource(); if (resource == null) { throw new IllegalArgumentException( "A resource must be set on the ViolationQuery in order to search for violations."); } if (!Scopes.isHigherThanOrEquals(resource, Scopes.FILE)) { return Collections.emptyList(); } Bucket bucket = buckets.get(resource); if (bucket == null) { return Collections.emptyList(); } List<Violation> violations = deprecatedViolations.get(bucket.getResource().getEffectiveKey()); if (violationQuery.getSwitchMode() == ViolationQuery.SwitchMode.BOTH) { return violations; } List<Violation> filteredViolations = Lists.newArrayList(); for (Violation violation : violations) { if (isFiltered(violation, violationQuery.getSwitchMode())) { filteredViolations.add(violation); } } return filteredViolations; }
@Override public <R extends Resource> R getResource(R reference) { Bucket bucket = buckets.get(reference); if (bucket != null) { return (R) bucket.getResource(); } return null; }
@Override public <M> M getMeasures(Resource resource, MeasuresFilter<M> filter) { Bucket bucket = buckets.get(resource); if (bucket != null) { // TODO the data measures which are not kept in memory are not reloaded yet. Use getMeasure(). return bucket.getMeasures(filter); } return null; }
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); } }
private Bucket getBucket(Resource resource, boolean acceptExcluded) { Bucket bucket = null; if (resource != null) { bucket = buckets.get(resource); if (!acceptExcluded && bucket != null && bucket.isExcluded()) { bucket = null; } } return bucket; }
@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; }
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; }
private Bucket getBucket(@Nullable Resource reference) { if (reference == null) { return null; } if (StringUtils.isNotBlank(reference.getKey())) { return buckets.get(reference); } String relativePathFromSourceDir = null; boolean isTest = false; boolean isDir = false; if (reference instanceof File) { File referenceFile = (File) reference; isTest = Qualifiers.UNIT_TEST_FILE.equals(referenceFile.getQualifier()); relativePathFromSourceDir = referenceFile.relativePathFromSourceDir(); } else if (reference instanceof Directory) { isDir = true; Directory referenceDir = (Directory) reference; relativePathFromSourceDir = referenceDir.relativePathFromSourceDir(); if (Directory.ROOT.equals(relativePathFromSourceDir)) { relativePathFromSourceDir = ""; } } if (relativePathFromSourceDir != null) { // Resolve using deprecated key List<java.io.File> dirs; if (isTest) { dirs = getProject().getFileSystem().getTestDirs(); } else { dirs = getProject().getFileSystem().getSourceDirs(); } for (java.io.File src : dirs) { java.io.File abs = new java.io.File(src, relativePathFromSourceDir); Bucket b = getBucket( isDir ? Directory.fromIOFile(abs, getProject()) : File.fromIOFile(abs, getProject())); if (b != null) { return b; } } } return null; }
/** Keep only project stuff */ public void clear() { Iterator<Map.Entry<Resource, Bucket>> it = buckets.entrySet().iterator(); while (it.hasNext()) { Map.Entry<Resource, Bucket> entry = it.next(); Resource resource = entry.getKey(); if (!ResourceUtils.isSet(resource)) { entry.getValue().clear(); it.remove(); } } Set<Dependency> projectDependencies = getDependenciesBetweenProjects(); dependencies.clear(); incomingDependenciesByResource.clear(); outgoingDependenciesByResource.clear(); for (Dependency projectDependency : projectDependencies) { projectDependency.setId(null); registerDependency(projectDependency); } lock.unlock(); }
@Override public Set<Resource> getVertices() { return buckets.keySet(); }
private void addBucket(Resource resource, Bucket bucket) { buckets.put(resource, bucket); }