import java.io.File;
import java.io.IOException;
import java.io.InputStream;
+import java.net.URI;
import java.nio.file.Path;
import javax.annotation.CheckForNull;
* <code>/path/to/module/src/main/java/com/Foo.java</code>.
* <br>
* Relative path is not null and is normalized ('foo/../foo' is replaced by 'foo').
+ * @deprecated since 6.6 use {@link #inputStream()}, {@link #filename()} or {@link #uri()}
*/
+ @Deprecated
@Override
String relativePath();
* This is not canonical path. Symbolic links are not resolved. For example if /project/src links
* to /tmp/src and basedir is /project, then this method returns /project/src/index.php. Use
* {@code file().getCanonicalPath()} to resolve symbolic link.
+ * @deprecated since 6.6 use {@link #inputStream()}, {@link #filename()} or {@link #uri()}
*/
+ @Deprecated
@Override
String absolutePath();
* The underlying absolute {@link java.io.File}. It should not be used to read the file in the filesystem.
* @see #contents()
* @see #inputStream()
+ * @deprecated since 6.6 use {@link #inputStream()}, {@link #filename()} or {@link #uri()}
*/
+ @Deprecated
@Override
File file();
* @see #contents()
* @see #inputStream()
* @since 5.1
+ * @deprecated since 6.6 use {@link #inputStream()}, {@link #filename()} or {@link #uri()}
*/
+ @Deprecated
@Override
Path path();
+ /**
+ * Identifier of the file. The only guarantee is that it is unique in the project.
+ * You should not assume it is a file:// URI.
+ * @since 6.6
+ */
+ URI uri();
+
+ /**
+ * Filename for this file (inclusing extension). For example: MyClass.java.
+ * @since 6.6
+ */
+ String filename();
+
/**
* Language, for example "java" or "php". Can be null if indexation of all files is enabled and no language claims to support the file.
*/
public interface InputComponent {
/**
- * Component key shared by all part of SonarQube (batch, server, WS...).
+ * Component key shared by all part of SonarQube (scanner, server, WS...).
* It doesn't include the branch.
*/
String key();
* <code>/path/to/module/src/main/java/com/Foo.java</code>.
* <br>
* Relative path is not null and is normalized ('foo/../foo' is replaced by 'foo').
+ * @deprecated since 6.6 use {@link #inputStream()}, {@link #filename()} or {@link #uri()}
*/
+ @Deprecated
@Override
String relativePath();
* This is not canonical path. Symbolic links are not resolved. For example if /project/src links
* to /tmp/src and basedir is /project, then this method returns /project/src/index.php. Use
* {@code file().getCanonicalPath()} to resolve symbolic link.
+ * @deprecated since 6.6 use {@link #inputStream()}, {@link #filename()} or {@link #uri()}
*/
+ @Deprecated
@Override
String absolutePath();
* The underlying absolute {@link java.io.File}. It should not be used to read the file in the filesystem.
* @see #contents()
* @see #inputStream()
+ * @deprecated since 6.6 use {@link #inputStream()}, {@link #filename()} or {@link #uri()}
*/
+ @Deprecated
@Override
File file();
* @see #contents()
* @see #inputStream()
* @since 5.1
+ * @deprecated since 6.6 use {@link #inputStream()}, {@link #filename()} or {@link #uri()}
*/
+ @Deprecated
@Override
Path path();
package org.sonar.api.batch.fs;
import java.io.File;
+import java.net.URI;
import java.nio.file.Path;
/**
/**
* @see InputFile#relativePath()
* @see InputDir#relativePath()
+ * @deprecated since 6.5 use {@link #uri()}
*/
+ @Deprecated
String relativePath();
/**
* @see InputFile#absolutePath()
* @see InputDir#absolutePath()
+ * @deprecated since 6.5 use {@link #uri()}
*/
+ @Deprecated
String absolutePath();
/**
* @see InputFile#file()
* @see InputDir#file()
+ * @deprecated since 6.5 use {@link #uri()}
*/
+ @Deprecated
File file();
/**
* @see InputFile#path()
* @see InputDir#path()
* @since 5.1
+ * @deprecated since 6.5 use {@link #uri()}
*/
+ @Deprecated
Path path();
+ /**
+ * Identifier of the component. The only guarantee is that it is unique in the project.
+ * You should not assume it is a file:// URI.
+ * @since 6.5
+ */
+ URI uri();
+
}
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
+import java.net.URI;
import java.nio.file.Files;
import java.nio.file.Path;
-
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
import javax.annotation.concurrent.Immutable;
-
import org.sonar.api.batch.fs.IndexedFile;
import org.sonar.api.batch.fs.InputFile.Type;
import org.sonar.api.utils.PathUtils;
public boolean isFile() {
return true;
}
+
+ @Override
+ public String filename() {
+ return path().getFileName().toString();
+ }
+
+ @Override
+ public URI uri() {
+ return path().toUri();
+ }
}
package org.sonar.api.batch.fs.internal;
import java.io.File;
+import java.net.URI;
import java.nio.file.Path;
import org.apache.commons.lang.StringUtils;
import org.sonar.api.batch.fs.InputDir;
public String toString() {
return "[moduleKey=" + moduleKey + ", relative=" + relativePath + ", basedir=" + moduleBaseDir + "]";
}
+
+ @Override
+ public URI uri() {
+ return path().toUri();
+ }
}
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
+import java.net.URI;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Path;
@Override
public InputStream inputStream() throws IOException {
- return contents != null ? new ByteArrayInputStream(contents.getBytes(charset())) : new BOMInputStream(Files.newInputStream(path()),
- ByteOrderMark.UTF_8, ByteOrderMark.UTF_16LE, ByteOrderMark.UTF_16BE, ByteOrderMark.UTF_32LE, ByteOrderMark.UTF_32BE);
+ return contents != null ? new ByteArrayInputStream(contents.getBytes(charset()))
+ : new BOMInputStream(Files.newInputStream(path()),
+ ByteOrderMark.UTF_8, ByteOrderMark.UTF_16LE, ByteOrderMark.UTF_16BE, ByteOrderMark.UTF_32LE, ByteOrderMark.UTF_32BE);
}
@Override
return true;
}
+ @Override
+ public String filename() {
+ return indexedFile.filename();
+ }
+
+ @Override
+ public URI uri() {
+ return indexedFile.uri();
+ }
+
}
assertThat(inputFile.relativePath()).isEqualTo("src/Foo.php");
assertThat(new File(inputFile.relativePath())).isRelative();
assertThat(inputFile.absolutePath()).endsWith("Foo.php");
+ assertThat(inputFile.filename()).isEqualTo("Foo.php");
+ assertThat(inputFile.uri()).hasPath(baseDir.resolve("src/Foo.php").toUri().getPath());
assertThat(new File(inputFile.absolutePath())).isAbsolute();
assertThat(inputFile.language()).isEqualTo("php");
assertThat(inputFile.status()).isEqualTo(InputFile.Status.ADDED);