mirror of https://github.com/apache/maven.git
Improve o.a.m.api.services.Source interface (#1236)
This commit is contained in:
parent
7d6f90e8d0
commit
e71d2d7167
|
@ -20,17 +20,56 @@ package org.apache.maven.api.services;
|
|||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.nio.file.Path;
|
||||
|
||||
import org.apache.maven.api.Session;
|
||||
import org.apache.maven.api.annotations.Experimental;
|
||||
import org.apache.maven.api.annotations.Nonnull;
|
||||
import org.apache.maven.api.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* The source for a project's XML model.
|
||||
* Provides access to the contents of a source independently of the
|
||||
* backing store (e.g. file system, database, memory).
|
||||
* <p>
|
||||
* This is mainly used to parse files into objects such as
|
||||
* {@link org.apache.maven.api.Project},
|
||||
* {@link org.apache.maven.api.model.Model},
|
||||
* {@link org.apache.maven.api.settings.Settings}, or
|
||||
* {@link org.apache.maven.api.toolchain.PersistedToolchains}.
|
||||
*
|
||||
* @since 4.0.0
|
||||
* @see org.apache.maven.api.services.ProjectBuilder#build(Session, Source)
|
||||
* @see org.apache.maven.api.services.SettingsBuilder#build(Session, Source, Source, Source)
|
||||
* @see org.apache.maven.api.services.ToolchainsBuilder#build(Session, Source, Source)
|
||||
*/
|
||||
@Experimental
|
||||
public interface Source {
|
||||
InputStream getInputStream() throws IOException;
|
||||
|
||||
/**
|
||||
* Provides access the file to be parsed, if this source is backed by a file.
|
||||
*
|
||||
* @return the underlying {@code Path}, or {@code null} if this source is not backed by a file
|
||||
*/
|
||||
@Nullable
|
||||
Path getPath();
|
||||
|
||||
/**
|
||||
* Creates a new byte stream to the source contents.
|
||||
* Closing the returned stream is the responsibility of the caller.
|
||||
*
|
||||
* @return a byte stream to the source contents, never {@code null}
|
||||
* @throws IOException in case of IO issue
|
||||
*/
|
||||
@Nonnull
|
||||
InputStream openStream() throws IOException;
|
||||
|
||||
/**
|
||||
* Provides a user-friendly hint about the location of the source.
|
||||
* This could be a local file path, a URI or just an empty string.
|
||||
* The intention is to assist users during error reporting.
|
||||
*
|
||||
* @return a user-friendly hint about the location of the source, never {@code null}
|
||||
*/
|
||||
@Nonnull
|
||||
String getLocation();
|
||||
}
|
||||
|
|
|
@ -85,7 +85,7 @@ public class DefaultProjectBuilder implements ProjectBuilder {
|
|||
ModelSource modelSource = new ModelSource() {
|
||||
@Override
|
||||
public InputStream getInputStream() throws IOException {
|
||||
return source.getInputStream();
|
||||
return source.openStream();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -108,7 +108,7 @@ public class DefaultSettingsBuilder implements SettingsBuilder {
|
|||
|
||||
@Override
|
||||
public InputStream getInputStream() throws IOException {
|
||||
return source.getInputStream();
|
||||
return source.openStream();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -95,7 +95,7 @@ public class DefaultToolchainsBuilder implements ToolchainsBuilder {
|
|||
|
||||
@Override
|
||||
public InputStream getInputStream() throws IOException {
|
||||
return source.getInputStream();
|
||||
return source.openStream();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in New Issue