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.nio.file.Path; 026import javax.annotation.CheckForNull; 027 028/** 029 * Represents the indexed view of an {@link InputFile}. Accessing any of data exposed here won't trigger the expensive generation of 030 * metadata for the {@link InputFile}. 031 * 032 * @since 6.3 033 */ 034public interface IndexedFile extends InputPath { 035 /** 036 * Path relative to module base directory. Path is unique and identifies file 037 * within given <code>{@link FileSystem}</code>. File separator is the forward 038 * slash ('/'), even on Microsoft Windows. 039 * <br> 040 * Returns <code>src/main/java/com/Foo.java</code> if module base dir is 041 * <code>/path/to/module</code> and if file is 042 * <code>/path/to/module/src/main/java/com/Foo.java</code>. 043 * <br> 044 * Relative path is not null and is normalized ('foo/../foo' is replaced by 'foo'). 045 */ 046 @Override 047 String relativePath(); 048 049 /** 050 * Normalized absolute path. File separator is forward slash ('/'), even on Microsoft Windows. 051 * <br> 052 * This is not canonical path. Symbolic links are not resolved. For example if /project/src links 053 * to /tmp/src and basedir is /project, then this method returns /project/src/index.php. Use 054 * {@code file().getCanonicalPath()} to resolve symbolic link. 055 */ 056 @Override 057 String absolutePath(); 058 059 /** 060 * The underlying absolute {@link java.io.File}. It should not be used to read the file in the filesystem. 061 * @see #contents() 062 * @see #inputStream() 063 */ 064 @Override 065 File file(); 066 067 /** 068 * The underlying absolute {@link Path}. 069 * It should not be used to read the file in the filesystem. 070 * @see #contents() 071 * @see #inputStream() 072 * @since 5.1 073 */ 074 @Override 075 Path path(); 076 077 /** 078 * Language, for example "java" or "php". Can be null if indexation of all files is enabled and no language claims to support the file. 079 */ 080 @CheckForNull 081 String language(); 082 083 /** 084 * Does it contain main or test code ? 085 */ 086 InputFile.Type type(); 087 088 /** 089 * 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. 090 * Typically, it won't be buffered. <b>The stream must be closed by the caller</b>. 091 * @since 6.2 092 */ 093 InputStream inputStream() throws IOException; 094}