001/*
002 * SonarQube
003 * Copyright (C) 2009-2017 SonarSource SA
004 * mailto:info 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.fs;
021
022import java.io.File;
023import java.io.IOException;
024import java.io.InputStream;
025import java.net.URI;
026import java.nio.file.Path;
027import javax.annotation.CheckForNull;
028
029/**
030 * Represents the indexed view of an {@link InputFile}. Accessing any of data exposed here won't trigger the expensive generation of 
031 * metadata for the {@link InputFile}.
032 * 
033 * @since 6.3 
034 */
035public interface IndexedFile extends InputPath {
036  /**
037   * Path relative to module base directory. Path is unique and identifies file
038   * within given <code>{@link FileSystem}</code>. File separator is the forward
039   * slash ('/'), even on Microsoft Windows.
040   * <br>
041   * Returns <code>src/main/java/com/Foo.java</code> if module base dir is
042   * <code>/path/to/module</code> and if file is
043   * <code>/path/to/module/src/main/java/com/Foo.java</code>.
044   * <br>
045   * Relative path is not null and is normalized ('foo/../foo' is replaced by 'foo').
046   * @deprecated since 6.6 use {@link #inputStream()}, {@link #filename()} or {@link #uri()}
047   */
048  @Deprecated
049  @Override
050  String relativePath();
051
052  /**
053   * Normalized absolute path. File separator is forward slash ('/'), even on Microsoft Windows.
054   * <br>
055   * This is not canonical path. Symbolic links are not resolved. For example if /project/src links
056   * to /tmp/src and basedir is /project, then this method returns /project/src/index.php. Use
057   * {@code file().getCanonicalPath()} to resolve symbolic link.
058   * @deprecated since 6.6 use {@link #inputStream()}, {@link #filename()} or {@link #uri()}
059   */
060  @Deprecated
061  @Override
062  String absolutePath();
063
064  /**
065   * The underlying absolute {@link java.io.File}. It should not be used to read the file in the filesystem.
066   * @see #contents()
067   * @see #inputStream()
068   * @deprecated since 6.6 use {@link #inputStream()}, {@link #filename()} or {@link #uri()}
069   */
070  @Deprecated
071  @Override
072  File file();
073
074  /**
075   * The underlying absolute {@link Path}.
076   * It should not be used to read the file in the filesystem.
077   * @see #contents()
078   * @see #inputStream()
079   * @since 5.1
080   * @deprecated since 6.6 use {@link #inputStream()}, {@link #filename()} or {@link #uri()}
081   */
082  @Deprecated
083  @Override
084  Path path();
085
086  /**
087   * Identifier of the file. The only guarantee is that it is unique in the project.
088   * You should not assume it is a file:// URI.
089   * @since 6.6
090   */
091  URI uri();
092
093  /**
094   * Filename for this file (inclusing extension). For example: MyClass.java.
095   * @since 6.6
096   */
097  String filename();
098
099  /**
100   * Language, for example "java" or "php". Can be null if indexation of all files is enabled and no language claims to support the file.
101   */
102  @CheckForNull
103  String language();
104
105  /**
106   * Does it contain main or test code ?
107   */
108  InputFile.Type type();
109
110  /**
111   * Creates a stream of the file's contents. Depending on the runtime context, the source might be a file in a physical or virtual filesystem.
112   * Typically, it won't be buffered. <b>The stream must be closed by the caller</b>.
113   * @since 6.2
114   */
115  InputStream inputStream() throws IOException;
116}