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