Search in sources :

Example 1 with SimpleArtifactRepository

use of org.eclipse.equinox.internal.p2.artifact.repository.simple.SimpleArtifactRepository in project tycho by eclipse.

the class SimpleArtifactRepositoryIO method write.

/**
 * Writes the given artifact repository to the stream. This method performs buffering, and
 * closes the stream when finished.
 */
public void write(SimpleArtifactRepository repository, OutputStream output) {
    OutputStream bufferedOutput = null;
    try {
        try {
            bufferedOutput = new BufferedOutputStream(output);
            Writer repositoryWriter = new Writer(bufferedOutput);
            repositoryWriter.write(repository);
        } finally {
            if (bufferedOutput != null) {
                bufferedOutput.close();
            }
        }
    } catch (IOException ioe) {
        // TODO shouldn't this throw a core exception?
        ioe.printStackTrace();
    }
}
Also used : BufferedOutputStream(java.io.BufferedOutputStream) OutputStream(java.io.OutputStream) IOException(java.io.IOException) BufferedOutputStream(java.io.BufferedOutputStream) XMLWriter(org.eclipse.equinox.internal.p2.persistence.XMLWriter)

Example 2 with SimpleArtifactRepository

use of org.eclipse.equinox.internal.p2.artifact.repository.simple.SimpleArtifactRepository in project tycho by eclipse.

the class SimpleArtifactRepositoryIO method read.

/**
 * Reads the artifact repository from the given stream, and returns the contained array of
 * abstract artifact repositories.
 *
 * This method performs buffering, and closes the stream when finished.
 */
public IArtifactRepository read(URL location, InputStream input, IProgressMonitor monitor) throws ProvisionException {
    BufferedInputStream bufferedInput = null;
    try {
        try {
            bufferedInput = new BufferedInputStream(input);
            Parser repositoryParser = new Parser(Activator.getContext(), Activator.ID);
            repositoryParser.parse(input);
            IStatus result = repositoryParser.getStatus();
            switch(result.getSeverity()) {
                case IStatus.CANCEL:
                    throw new OperationCanceledException();
                case IStatus.ERROR:
                    throw new ProvisionException(result);
                case IStatus.WARNING:
                case IStatus.INFO:
                    LogHelper.log(result);
                    break;
                case IStatus.OK:
                    break;
                default:
                    // $NON-NLS-1$
                    throw new IllegalStateException("Unknown serverity value: " + result.getSeverity());
            }
            SimpleArtifactRepository repository = repositoryParser.getRepository();
            if (repository == null)
                throw new ProvisionException(new Status(IStatus.ERROR, Activator.ID, ProvisionException.REPOSITORY_FAILED_READ, Messages.io_parseError, null));
            return repository;
        } finally {
            if (bufferedInput != null)
                bufferedInput.close();
        }
    } catch (IOException ioe) {
        String msg = NLS.bind(Messages.io_failedRead, location);
        throw new ProvisionException(new Status(IStatus.ERROR, Activator.ID, ProvisionException.REPOSITORY_FAILED_READ, msg, ioe));
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) ProvisionException(org.eclipse.equinox.p2.core.ProvisionException) SimpleArtifactRepository(org.eclipse.equinox.internal.p2.artifact.repository.simple.SimpleArtifactRepository) BufferedInputStream(java.io.BufferedInputStream) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) IOException(java.io.IOException) XMLParser(org.eclipse.equinox.internal.p2.persistence.XMLParser)

Aggregations

IOException (java.io.IOException)2 BufferedInputStream (java.io.BufferedInputStream)1 BufferedOutputStream (java.io.BufferedOutputStream)1 OutputStream (java.io.OutputStream)1 IStatus (org.eclipse.core.runtime.IStatus)1 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)1 Status (org.eclipse.core.runtime.Status)1 SimpleArtifactRepository (org.eclipse.equinox.internal.p2.artifact.repository.simple.SimpleArtifactRepository)1 XMLParser (org.eclipse.equinox.internal.p2.persistence.XMLParser)1 XMLWriter (org.eclipse.equinox.internal.p2.persistence.XMLWriter)1 ProvisionException (org.eclipse.equinox.p2.core.ProvisionException)1