001/*
002 * SonarQube
003 * Copyright (C) 2009-2016 SonarSource SA
004 * mailto:contact AT sonarsource DOT com
005 *
006 * This program 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 * This program 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 java.util.Collection;
023import javax.annotation.CheckForNull;
024import org.sonar.api.batch.fs.InputFile;
025import org.sonar.api.batch.sensor.SensorContext;
026import org.sonar.api.design.Dependency;
027import org.sonar.api.measures.Measure;
028import org.sonar.api.measures.MeasuresFilter;
029import org.sonar.api.resources.Project;
030import org.sonar.api.resources.Resource;
031
032/**
033 * @deprecated since 4.5.2 should not be used by plugins. Everything should be accessed using {@link SensorContext}.
034 */
035@Deprecated
036public abstract class SonarIndex {
037
038  /**
039   * Indexes a resource as a direct child of project. This method does nothing and returns true if the resource already indexed.
040   * If the method resource.getParent() does not return null, then this parent will be indexed too.
041   *
042   * @return false if the resource is excluded
043   * @since 2.6
044   */
045  public abstract boolean index(Resource resource);
046
047  /**
048   * Indexes a resource. This method does nothing if the resource is already indexed.
049   *
050   * @param resource        the resource to index. Not nullable
051   * @param parentReference a reference to the indexed parent. If null, the resource is indexed as a direct child of project.
052   * @return false if the parent is not indexed or if the resource is excluded
053   * @since 2.6
054   */
055  public abstract boolean index(Resource resource, Resource parentReference);
056
057  /**
058   * Returns true if the referenced resource is excluded. An excluded resource is not indexed.
059   * @since 2.6
060   */
061  public abstract boolean isExcluded(Resource reference);
062
063  /**
064   * @since 2.6
065   */
066  public abstract boolean isIndexed(Resource reference, boolean acceptExcluded);
067
068  /**
069   * Search for an indexed resource.
070   *
071   * @param reference the resource reference
072   * @return the indexed resource, null if it's not indexed
073   * @since 1.10. Generic types since 2.6.
074   */
075  public abstract <R extends Resource> R getResource(R reference);
076
077  /**
078   * @since 2.6
079   */
080  public abstract Resource getParent(Resource reference);
081
082  /**
083   * @since 2.6
084   */
085
086  public abstract Collection<Resource> getChildren(Resource reference);
087
088  /**
089   * @return source code associated with a specified resource, <code>null</code> if not available 
090   * (for example if resource is not a file)
091   * @since 2.9
092   * @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.
093   */
094  @Deprecated
095  @CheckForNull
096  public abstract String getSource(Resource resource);
097
098  public abstract Project getProject();
099
100  public abstract Collection<Resource> getResources();
101
102  /**
103   * Indexes the resource.
104   * @return the indexed resource, even if it's excluded
105   * @deprecated since 2.6. Use methods index()
106   */
107  @Deprecated
108  public abstract Resource addResource(Resource resource);
109
110  @CheckForNull
111  public abstract Measure getMeasure(Resource resource, org.sonar.api.batch.measure.Metric<?> metric);
112
113  @CheckForNull
114  public abstract <M> M getMeasures(Resource resource, MeasuresFilter<M> filter);
115
116  /**
117   * Warning: the resource is automatically indexed for backward-compatibility, but it should be explictly
118   * indexed before. Next versions will deactivate this automatic indexation.
119   */
120  public abstract Measure addMeasure(Resource resource, Measure measure);
121
122  /**
123   * @deprecated since 5.2 No more design features. No op.
124   */
125  @Deprecated
126  public abstract Dependency addDependency(Dependency dependency);
127}