001/*
002 * SonarQube, open source software quality management tool.
003 * Copyright (C) 2008-2014 SonarSource
004 * mailto:contact AT sonarsource DOT com
005 *
006 * SonarQube is free software; you can redistribute it and/or
007 * modify it under the terms of the GNU Lesser General Public
008 * License as published by the Free Software Foundation; either
009 * version 3 of the License, or (at your option) any later version.
010 *
011 * SonarQube is distributed in the hope that it will be useful,
012 * but WITHOUT ANY WARRANTY; without even the implied warranty of
013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014 * Lesser General Public License for more details.
015 *
016 * You should have received a copy of the GNU Lesser General Public License
017 * along with this program; if not, write to the Free Software Foundation,
018 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
019 */
020package org.sonar.api.batch;
021
022import org.sonar.api.batch.fs.InputFile;
023import org.sonar.api.design.Dependency;
024import org.sonar.api.measures.Measure;
025import org.sonar.api.measures.MeasuresFilter;
026import org.sonar.api.resources.Project;
027import org.sonar.api.resources.ProjectLink;
028import org.sonar.api.resources.Resource;
029import org.sonar.api.rules.Violation;
030import org.sonar.graph.DirectedGraphAccessor;
031
032import javax.annotation.CheckForNull;
033import javax.annotation.Nullable;
034
035import java.util.Collection;
036import java.util.Date;
037import java.util.List;
038import java.util.Set;
039
040/**
041 * @deprecated since 4.5.2 should not be used by plugins. Everything should be accessed using {@link SensorContext}.
042 */
043@Deprecated
044public abstract class SonarIndex implements DirectedGraphAccessor<Resource, Dependency> {
045
046  /**
047   * Indexes a resource as a direct child of project. This method does nothing and returns true if the resource already indexed.
048   * If the method resource.getParent() does not return null, then this parent will be indexed too.
049   *
050   * @return false if the resource is excluded
051   * @since 2.6
052   */
053  public abstract boolean index(Resource resource);
054
055  /**
056   * Indexes a resource. This method does nothing if the resource is already indexed.
057   *
058   * @param resource        the resource to index. Not nullable
059   * @param parentReference a reference to the indexed parent. If null, the resource is indexed as a direct child of project.
060   * @return false if the parent is not indexed or if the resource is excluded
061   * @since 2.6
062   */
063  public abstract boolean index(Resource resource, Resource parentReference);
064
065  /**
066   * Returns true if the referenced resource is excluded. An excluded resource is not indexed.
067   * @since 2.6
068   */
069  public abstract boolean isExcluded(Resource reference);
070
071  /**
072   * @since 2.6
073   */
074  public abstract boolean isIndexed(Resource reference, boolean acceptExcluded);
075
076  /**
077   * Search for an indexed resource.
078   *
079   * @param reference the resource reference
080   * @return the indexed resource, null if it's not indexed
081   * @since 1.10. Generic types since 2.6.
082   */
083  public abstract <R extends Resource> R getResource(R reference);
084
085  /**
086   * @since 2.6
087   */
088  public abstract Resource getParent(Resource reference);
089
090  /**
091   * @since 2.6
092   */
093
094  public abstract Collection<Resource> getChildren(Resource reference);
095
096  /**
097   * @return source code associated with a specified resource, <code>null</code> if not available 
098   * (for example if resource is not a file)
099   * @since 2.9
100   * @deprecated since 5.0 sources are no more stored in SQ as a single blob. Use {@link InputFile#file()} to read file content from disk.
101   */
102  @Deprecated
103  @CheckForNull
104  public abstract String getSource(Resource resource);
105
106  public abstract Project getProject();
107
108  public final Collection<Resource> getResources() {
109    return getVertices();
110  }
111
112  /**
113   * Indexes the resource.
114   * @return the indexed resource, even if it's excluded
115   * @deprecated since 2.6. Use methods index()
116   */
117  @Deprecated
118  public abstract Resource addResource(Resource resource);
119
120  @CheckForNull
121  public abstract Measure getMeasure(Resource resource, org.sonar.api.batch.measure.Metric<?> metric);
122
123  @CheckForNull
124  public abstract <M> M getMeasures(Resource resource, MeasuresFilter<M> filter);
125
126  /**
127   * @since 2.5
128   * @deprecated in 3.6
129   */
130  @Deprecated
131  public abstract void addViolation(Violation violation, boolean force);
132
133  /**
134   * @deprecated in 3.6
135   */
136  @Deprecated
137  public final void addViolation(Violation violation) {
138    addViolation(violation, false);
139  }
140
141  /**
142   * Warning: the resource is automatically indexed for backward-compatibility, but it should be explictly
143   * indexed before. Next versions will deactivate this automatic indexation.
144   */
145  public abstract Measure addMeasure(Resource resource, Measure measure);
146
147  public abstract Dependency addDependency(Dependency dependency);
148
149  public abstract Set<Dependency> getDependencies();
150
151  public abstract void addLink(ProjectLink link);
152
153  public abstract void deleteLink(String key);
154
155  public abstract List<Event> getEvents(Resource resource);
156
157  public abstract void deleteEvent(Event event);
158
159  public abstract Event addEvent(Resource resource, String name, String description, String category, @Nullable Date date);
160
161  public final Collection<Dependency> getOutgoingDependencies(Resource from) {
162    return getOutgoingEdges(from);
163  }
164
165  public final Collection<Dependency> getIncomingDependencies(Resource to) {
166    return getIncomingEdges(to);
167  }
168}