aboutsummaryrefslogtreecommitdiffstats
path: root/framework/src/maven/apache-maven-3.3.3/maven-builder-support/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'framework/src/maven/apache-maven-3.3.3/maven-builder-support/src/main/java')
-rw-r--r--framework/src/maven/apache-maven-3.3.3/maven-builder-support/src/main/java/org/apache/maven/building/DefaultProblem.java161
-rw-r--r--framework/src/maven/apache-maven-3.3.3/maven-builder-support/src/main/java/org/apache/maven/building/DefaultProblemCollector.java64
-rw-r--r--framework/src/maven/apache-maven-3.3.3/maven-builder-support/src/main/java/org/apache/maven/building/FileSource.java79
-rw-r--r--framework/src/maven/apache-maven-3.3.3/maven-builder-support/src/main/java/org/apache/maven/building/Problem.java101
-rw-r--r--framework/src/maven/apache-maven-3.3.3/maven-builder-support/src/main/java/org/apache/maven/building/ProblemCollector.java59
-rw-r--r--framework/src/maven/apache-maven-3.3.3/maven-builder-support/src/main/java/org/apache/maven/building/ProblemCollectorFactory.java43
-rw-r--r--framework/src/maven/apache-maven-3.3.3/maven-builder-support/src/main/java/org/apache/maven/building/Source.java49
-rw-r--r--framework/src/maven/apache-maven-3.3.3/maven-builder-support/src/main/java/org/apache/maven/building/StringSource.java90
-rw-r--r--framework/src/maven/apache-maven-3.3.3/maven-builder-support/src/main/java/org/apache/maven/building/UrlSource.java80
9 files changed, 726 insertions, 0 deletions
diff --git a/framework/src/maven/apache-maven-3.3.3/maven-builder-support/src/main/java/org/apache/maven/building/DefaultProblem.java b/framework/src/maven/apache-maven-3.3.3/maven-builder-support/src/main/java/org/apache/maven/building/DefaultProblem.java
new file mode 100644
index 00000000..ad1fc40f
--- /dev/null
+++ b/framework/src/maven/apache-maven-3.3.3/maven-builder-support/src/main/java/org/apache/maven/building/DefaultProblem.java
@@ -0,0 +1,161 @@
+package org.apache.maven.building;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/**
+ * Describes a problem that was encountered during settings building. A problem can either be an exception that was
+ * thrown or a simple string message. In addition, a problem carries a hint about its source, e.g. the settings file
+ * that exhibits the problem.
+ *
+ * @author Benjamin Bentmann
+ * @author Robert Scholte
+ */
+class DefaultProblem
+ implements Problem
+{
+
+ private final String source;
+
+ private final int lineNumber;
+
+ private final int columnNumber;
+
+ private final String message;
+
+ private final Exception exception;
+
+ private final Severity severity;
+
+ /**
+ * Creates a new problem with the specified message and exception.
+ * Either {@code message} or {@code exception} is required
+ *
+ * @param message The message describing the problem, may be {@code null}.
+ * @param severity The severity level of the problem, may be {@code null} to default to
+ * {@link SettingsProblem.Severity#ERROR}.
+ * @param source A hint about the source of the problem like a file path, may be {@code null}.
+ * @param lineNumber The one-based index of the line containing the problem or {@code -1} if unknown.
+ * @param columnNumber The one-based index of the column containing the problem or {@code -1} if unknown.
+ * @param exception The exception that caused this problem, may be {@code null}.
+ */
+ public DefaultProblem( String message, Severity severity, String source, int lineNumber, int columnNumber,
+ Exception exception )
+ {
+ this.message = message;
+ this.severity = ( severity != null ) ? severity : Severity.ERROR;
+ this.source = ( source != null ) ? source : "";
+ this.lineNumber = lineNumber;
+ this.columnNumber = columnNumber;
+ this.exception = exception;
+ }
+
+ public String getSource()
+ {
+ return source;
+ }
+
+ public int getLineNumber()
+ {
+ return lineNumber;
+ }
+
+ public int getColumnNumber()
+ {
+ return columnNumber;
+ }
+
+ public String getLocation()
+ {
+ StringBuilder buffer = new StringBuilder( 256 );
+
+ if ( getSource().length() > 0 )
+ {
+ if ( buffer.length() > 0 )
+ {
+ buffer.append( ", " );
+ }
+ buffer.append( getSource() );
+ }
+
+ if ( getLineNumber() > 0 )
+ {
+ if ( buffer.length() > 0 )
+ {
+ buffer.append( ", " );
+ }
+ buffer.append( "line " ).append( getLineNumber() );
+ }
+
+ if ( getColumnNumber() > 0 )
+ {
+ if ( buffer.length() > 0 )
+ {
+ buffer.append( ", " );
+ }
+ buffer.append( "column " ).append( getColumnNumber() );
+ }
+
+ return buffer.toString();
+ }
+
+ public Exception getException()
+ {
+ return exception;
+ }
+
+ public String getMessage()
+ {
+ String msg;
+
+ if ( message != null && message.length() > 0 )
+ {
+ msg = message;
+ }
+ else
+ {
+ msg = exception.getMessage();
+
+ if ( msg == null )
+ {
+ msg = "";
+ }
+ }
+
+ return msg;
+ }
+
+ public Severity getSeverity()
+ {
+ return severity;
+ }
+
+ @Override
+ public String toString()
+ {
+ StringBuilder buffer = new StringBuilder( 128 );
+
+ buffer.append( "[" ).append( getSeverity() ).append( "] " );
+ buffer.append( getMessage() );
+ buffer.append( " @ " ).append( getLocation() );
+
+ return buffer.toString();
+ }
+
+}
diff --git a/framework/src/maven/apache-maven-3.3.3/maven-builder-support/src/main/java/org/apache/maven/building/DefaultProblemCollector.java b/framework/src/maven/apache-maven-3.3.3/maven-builder-support/src/main/java/org/apache/maven/building/DefaultProblemCollector.java
new file mode 100644
index 00000000..567f620e
--- /dev/null
+++ b/framework/src/maven/apache-maven-3.3.3/maven-builder-support/src/main/java/org/apache/maven/building/DefaultProblemCollector.java
@@ -0,0 +1,64 @@
+package org.apache.maven.building;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Collects problems that are encountered during settings building.
+ *
+ * @author Benjamin Bentmann
+ * @author Robert Scholte
+ */
+class DefaultProblemCollector
+ implements ProblemCollector
+{
+
+ private List<Problem> problems;
+
+ private String source;
+
+ public DefaultProblemCollector( List<Problem> problems )
+ {
+ this.problems = ( problems != null ) ? problems : new ArrayList<Problem>();
+ }
+
+ @Override
+ public List<Problem> getProblems()
+ {
+ return problems;
+ }
+
+ @Override
+ public void setSource( String source )
+ {
+ this.source = source;
+ }
+
+ @Override
+ public void add( Problem.Severity severity, String message, int line, int column, Exception cause )
+ {
+ Problem problem = new DefaultProblem( message, severity, source, line, column, cause );
+
+ problems.add( problem );
+ }
+
+}
diff --git a/framework/src/maven/apache-maven-3.3.3/maven-builder-support/src/main/java/org/apache/maven/building/FileSource.java b/framework/src/maven/apache-maven-3.3.3/maven-builder-support/src/main/java/org/apache/maven/building/FileSource.java
new file mode 100644
index 00000000..1a6fc2f4
--- /dev/null
+++ b/framework/src/maven/apache-maven-3.3.3/maven-builder-support/src/main/java/org/apache/maven/building/FileSource.java
@@ -0,0 +1,79 @@
+package org.apache.maven.building;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
+/**
+ * Wraps an ordinary {@link File} as a source.
+ *
+ * @author Benjamin Bentmann
+ */
+public class FileSource
+ implements Source
+{
+ private final File file;
+
+ /**
+ * Creates a new source backed by the specified file.
+ *
+ * @param file The file, must not be {@code null}.
+ */
+ public FileSource( File file )
+ {
+ if ( file == null )
+ {
+ throw new IllegalArgumentException( "no file specified" );
+ }
+ this.file = file.getAbsoluteFile();
+ }
+
+ @Override
+ public InputStream getInputStream()
+ throws IOException
+ {
+ return new FileInputStream( file );
+ }
+
+ @Override
+ public String getLocation()
+ {
+ return file.getPath();
+ }
+
+ /**
+ * Gets the file of this source.
+ *
+ * @return The underlying file, never {@code null}.
+ */
+ public File getFile()
+ {
+ return file;
+ }
+
+ @Override
+ public String toString()
+ {
+ return getLocation();
+ }
+}
diff --git a/framework/src/maven/apache-maven-3.3.3/maven-builder-support/src/main/java/org/apache/maven/building/Problem.java b/framework/src/maven/apache-maven-3.3.3/maven-builder-support/src/main/java/org/apache/maven/building/Problem.java
new file mode 100644
index 00000000..9ab9b3a8
--- /dev/null
+++ b/framework/src/maven/apache-maven-3.3.3/maven-builder-support/src/main/java/org/apache/maven/building/Problem.java
@@ -0,0 +1,101 @@
+package org.apache.maven.building;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/**
+ * Describes a problem that was encountered during settings building. A problem can either be an exception that was
+ * thrown or a simple string message. In addition, a problem carries a hint about its source, e.g. the settings file
+ * that exhibits the problem.
+ *
+ * @author Benjamin Bentmann
+ * @author Robert Scholte
+ */
+public interface Problem
+{
+
+ /**
+ * The different severity levels for a problem, in decreasing order.
+ */
+ enum Severity
+ {
+
+ FATAL, //
+ ERROR, //
+ WARNING //
+
+ }
+
+ /**
+ * Gets the hint about the source of the problem. While the syntax of this hint is unspecified and depends on the
+ * creator of the problem, the general expectation is that the hint provides sufficient information to the user to
+ * track the problem back to its origin. A concrete example for such a source hint can be the file path or URL from
+ * which the settings were read.
+ *
+ * @return The hint about the source of the problem or an empty string if unknown, never {@code null}.
+ */
+ String getSource();
+
+ /**
+ * Gets the one-based index of the line containing the problem. The line number should refer to some text file that
+ * is given by {@link #getSource()}.
+ *
+ * @return The one-based index of the line containing the problem or a non-positive value if unknown.
+ */
+ int getLineNumber();
+
+ /**
+ * Gets the one-based index of the column containing the problem. The column number should refer to some text file
+ * that is given by {@link #getSource()}.
+ *
+ * @return The one-based index of the column containing the problem or non-positive value if unknown.
+ */
+ int getColumnNumber();
+
+ /**
+ * Gets the location of the problem. The location is a user-friendly combination of the values from
+ * {@link #getSource()}, {@link #getLineNumber()} and {@link #getColumnNumber()}. The exact syntax of the returned
+ * value is undefined.
+ *
+ * @return The location of the problem, never {@code null}.
+ */
+ String getLocation();
+
+ /**
+ * Gets the exception that caused this problem (if any).
+ *
+ * @return The exception that caused this problem or {@code null} if not applicable.
+ */
+ Exception getException();
+
+ /**
+ * Gets the message that describes this problem.
+ *
+ * @return The message describing this problem, never {@code null}.
+ */
+ String getMessage();
+
+ /**
+ * Gets the severity level of this problem.
+ *
+ * @return The severity level of this problem, never {@code null}.
+ */
+ Severity getSeverity();
+
+}
diff --git a/framework/src/maven/apache-maven-3.3.3/maven-builder-support/src/main/java/org/apache/maven/building/ProblemCollector.java b/framework/src/maven/apache-maven-3.3.3/maven-builder-support/src/main/java/org/apache/maven/building/ProblemCollector.java
new file mode 100644
index 00000000..e7015676
--- /dev/null
+++ b/framework/src/maven/apache-maven-3.3.3/maven-builder-support/src/main/java/org/apache/maven/building/ProblemCollector.java
@@ -0,0 +1,59 @@
+package org.apache.maven.building;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.util.List;
+
+/**
+ * Collects problems that are encountered during settings building.
+ *
+ * @author Benjamin Bentmann
+ * @author Robert Scholte
+ */
+public interface ProblemCollector
+{
+
+ /**
+ * Adds the specified problem.
+ * Either message or exception is required
+ *
+ * @param severity The severity of the problem, must not be {@code null}.
+ * @param message The detail message of the problem, may be {@code null}.
+ * @param line The one-based index of the line containing the problem or {@code -1} if unknown.
+ * @param column The one-based index of the column containing the problem or {@code -1} if unknown.
+ * @param cause The cause of the problem, may be {@code null}.
+ */
+ void add( Problem.Severity severity, String message, int line, int column, Exception cause );
+
+ /**
+ * The next messages will be bound to this source. When calling this method again, previous messages keep
+ * their source, but the next messages will use the new source.
+ *
+ * @param source
+ */
+ void setSource( String source );
+
+ /**
+ *
+ * @return the collected Problems, never {@code null}
+ */
+ List<Problem> getProblems();
+
+}
diff --git a/framework/src/maven/apache-maven-3.3.3/maven-builder-support/src/main/java/org/apache/maven/building/ProblemCollectorFactory.java b/framework/src/maven/apache-maven-3.3.3/maven-builder-support/src/main/java/org/apache/maven/building/ProblemCollectorFactory.java
new file mode 100644
index 00000000..c1c23737
--- /dev/null
+++ b/framework/src/maven/apache-maven-3.3.3/maven-builder-support/src/main/java/org/apache/maven/building/ProblemCollectorFactory.java
@@ -0,0 +1,43 @@
+package org.apache.maven.building;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.util.List;
+
+/**
+ *
+ * @author Robert Scholte
+ * @since 3.3.0
+ */
+public class ProblemCollectorFactory
+{
+
+ /**
+ * The default implementation is not visible, create it with this factory
+ *
+ * @param problems starting set of problems, may be {@code null}
+ * @return a new instance of a ProblemCollector
+ */
+ public static ProblemCollector newInstance( List<Problem> problems )
+ {
+ return new DefaultProblemCollector( problems );
+ }
+
+}
diff --git a/framework/src/maven/apache-maven-3.3.3/maven-builder-support/src/main/java/org/apache/maven/building/Source.java b/framework/src/maven/apache-maven-3.3.3/maven-builder-support/src/main/java/org/apache/maven/building/Source.java
new file mode 100644
index 00000000..1f7510ba
--- /dev/null
+++ b/framework/src/maven/apache-maven-3.3.3/maven-builder-support/src/main/java/org/apache/maven/building/Source.java
@@ -0,0 +1,49 @@
+package org.apache.maven.building;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.io.IOException;
+import java.io.InputStream;
+
+/**
+ * Provides access to the contents of a source independently of the backing store (e.g. file system, database, memory).
+ *
+ * @author Benjamin Bentmann
+ */
+public interface Source
+{
+
+ /**
+ * Gets a 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}.
+ */
+ InputStream getInputStream()
+ 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}.
+ */
+ String getLocation();
+
+}
diff --git a/framework/src/maven/apache-maven-3.3.3/maven-builder-support/src/main/java/org/apache/maven/building/StringSource.java b/framework/src/maven/apache-maven-3.3.3/maven-builder-support/src/main/java/org/apache/maven/building/StringSource.java
new file mode 100644
index 00000000..f9d87c0b
--- /dev/null
+++ b/framework/src/maven/apache-maven-3.3.3/maven-builder-support/src/main/java/org/apache/maven/building/StringSource.java
@@ -0,0 +1,90 @@
+package org.apache.maven.building;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
+/**
+ * Wraps an ordinary {@link CharSequence} as a source.
+ *
+ * @author Benjamin Bentmann
+ */
+public class StringSource
+ implements Source
+{
+
+ private String content;
+
+ private String location;
+
+ /**
+ * Creates a new source backed by the specified string.
+ *
+ * @param content The String representation, may be empty or {@code null}.
+ */
+ public StringSource( CharSequence content )
+ {
+ this( content, null );
+ }
+
+ /**
+ * Creates a new source backed by the specified string.
+ *
+ * @param content The String representation, may be empty or {@code null}.
+ * @param location The location to report for this use, may be {@code null}.
+ */
+ public StringSource( CharSequence content, String location )
+ {
+ this.content = ( content != null ) ? content.toString() : "";
+ this.location = ( location != null ) ? location : "(memory)";
+ }
+
+ @Override
+ public InputStream getInputStream()
+ throws IOException
+ {
+ return new ByteArrayInputStream( content.getBytes( "UTF-8" ) );
+ }
+
+ @Override
+ public String getLocation()
+ {
+ return location;
+ }
+
+ /**
+ * Gets the content of this source.
+ *
+ * @return The underlying character stream, never {@code null}.
+ */
+ public String getContent()
+ {
+ return content;
+ }
+
+ @Override
+ public String toString()
+ {
+ return getLocation();
+ }
+
+}
diff --git a/framework/src/maven/apache-maven-3.3.3/maven-builder-support/src/main/java/org/apache/maven/building/UrlSource.java b/framework/src/maven/apache-maven-3.3.3/maven-builder-support/src/main/java/org/apache/maven/building/UrlSource.java
new file mode 100644
index 00000000..7bd3e3c3
--- /dev/null
+++ b/framework/src/maven/apache-maven-3.3.3/maven-builder-support/src/main/java/org/apache/maven/building/UrlSource.java
@@ -0,0 +1,80 @@
+package org.apache.maven.building;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+
+/**
+ * Wraps an ordinary {@link URL} as a source.
+ *
+ * @author Benjamin Bentmann
+ */
+public class UrlSource
+ implements Source
+{
+
+ private URL url;
+
+ /**
+ * Creates a new source backed by the specified URL.
+ *
+ * @param url The file, must not be {@code null}.
+ */
+ public UrlSource( URL url )
+ {
+ if ( url == null )
+ {
+ throw new IllegalArgumentException( "no url specified" );
+ }
+ this.url = url;
+ }
+
+ @Override
+ public InputStream getInputStream()
+ throws IOException
+ {
+ return url.openStream();
+ }
+
+ @Override
+ public String getLocation()
+ {
+ return url.toString();
+ }
+
+ /**
+ * Gets the URL of this source.
+ *
+ * @return The underlying URL, never {@code null}.
+ */
+ public URL getUrl()
+ {
+ return url;
+ }
+
+ @Override
+ public String toString()
+ {
+ return getLocation();
+ }
+
+}