http://git-wip-us.apache.org/repos/asf/maven-resolver/blob/3a1b8ae0/aether-spi/src/main/java/org/eclipse/aether/spi/connector/MetadataTransfer.java ---------------------------------------------------------------------- diff --git a/aether-spi/src/main/java/org/eclipse/aether/spi/connector/MetadataTransfer.java b/aether-spi/src/main/java/org/eclipse/aether/spi/connector/MetadataTransfer.java deleted file mode 100644 index 94eb46e..0000000 --- a/aether-spi/src/main/java/org/eclipse/aether/spi/connector/MetadataTransfer.java +++ /dev/null @@ -1,115 +0,0 @@ -package org.eclipse.aether.spi.connector; - -/* - * 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 org.eclipse.aether.metadata.Metadata; -import org.eclipse.aether.transfer.MetadataTransferException; - -/** - * A download/upload of metadata. - * - * @noextend This class is not intended to be extended by clients. - */ -public abstract class MetadataTransfer - extends Transfer -{ - - private Metadata metadata; - - private File file; - - private MetadataTransferException exception; - - MetadataTransfer() - { - // hide - } - - /** - * Gets the metadata being transferred. - * - * @return The metadata being transferred or {@code null} if not set. - */ - public Metadata getMetadata() - { - return metadata; - } - - /** - * Sets the metadata to transfer. - * - * @param metadata The metadata, may be {@code null}. - * @return This transfer for chaining, never {@code null}. - */ - public MetadataTransfer setMetadata( Metadata metadata ) - { - this.metadata = metadata; - return this; - } - - /** - * Gets the local file the metadata is downloaded to or uploaded from. In case of a download, a connector should - * first transfer the bytes to a temporary file and only overwrite the target file once the entire download is - * completed such that an interrupted/failed download does not corrupt the current file contents. - * - * @return The local file or {@code null} if not set. - */ - public File getFile() - { - return file; - } - - /** - * Sets the local file the metadata is downloaded to or uploaded from. - * - * @param file The local file, may be {@code null}. - * @return This transfer for chaining, never {@code null}. - */ - public MetadataTransfer setFile( File file ) - { - this.file = file; - return this; - } - - /** - * Gets the exception that occurred during the transfer (if any). - * - * @return The exception or {@code null} if the transfer was successful. - */ - public MetadataTransferException getException() - { - return exception; - } - - /** - * Sets the exception that occurred during the transfer. - * - * @param exception The exception, may be {@code null} to denote a successful transfer. - * @return This transfer for chaining, never {@code null}. - */ - public MetadataTransfer setException( MetadataTransferException exception ) - { - this.exception = exception; - return this; - } - -}
http://git-wip-us.apache.org/repos/asf/maven-resolver/blob/3a1b8ae0/aether-spi/src/main/java/org/eclipse/aether/spi/connector/MetadataUpload.java ---------------------------------------------------------------------- diff --git a/aether-spi/src/main/java/org/eclipse/aether/spi/connector/MetadataUpload.java b/aether-spi/src/main/java/org/eclipse/aether/spi/connector/MetadataUpload.java deleted file mode 100644 index d992757..0000000 --- a/aether-spi/src/main/java/org/eclipse/aether/spi/connector/MetadataUpload.java +++ /dev/null @@ -1,98 +0,0 @@ -package org.eclipse.aether.spi.connector; - -/* - * 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 org.eclipse.aether.RequestTrace; -import org.eclipse.aether.metadata.Metadata; -import org.eclipse.aether.transfer.MetadataTransferException; -import org.eclipse.aether.transfer.TransferListener; - -/** - * An upload of metadata to a remote repository. A repository connector processing this upload has to use - * {@link #setException(MetadataTransferException)} to report the results of the transfer. - */ -public final class MetadataUpload - extends MetadataTransfer -{ - - /** - * Creates a new uninitialized upload. - */ - public MetadataUpload() - { - // enables default constructor - } - - /** - * Creates a new upload with the specified properties. - * - * @param metadata The metadata to upload, may be {@code null}. - * @param file The local file to upload the metadata from, may be {@code null}. - */ - public MetadataUpload( Metadata metadata, File file ) - { - setMetadata( metadata ); - setFile( file ); - } - - @Override - public MetadataUpload setMetadata( Metadata metadata ) - { - super.setMetadata( metadata ); - return this; - } - - @Override - public MetadataUpload setFile( File file ) - { - super.setFile( file ); - return this; - } - - @Override - public MetadataUpload setException( MetadataTransferException exception ) - { - super.setException( exception ); - return this; - } - - @Override - public MetadataUpload setListener( TransferListener listener ) - { - super.setListener( listener ); - return this; - } - - @Override - public MetadataUpload setTrace( RequestTrace trace ) - { - super.setTrace( trace ); - return this; - } - - @Override - public String toString() - { - return getMetadata() + " - " + getFile(); - } - -} http://git-wip-us.apache.org/repos/asf/maven-resolver/blob/3a1b8ae0/aether-spi/src/main/java/org/eclipse/aether/spi/connector/RepositoryConnector.java ---------------------------------------------------------------------- diff --git a/aether-spi/src/main/java/org/eclipse/aether/spi/connector/RepositoryConnector.java b/aether-spi/src/main/java/org/eclipse/aether/spi/connector/RepositoryConnector.java deleted file mode 100644 index 51e0627..0000000 --- a/aether-spi/src/main/java/org/eclipse/aether/spi/connector/RepositoryConnector.java +++ /dev/null @@ -1,77 +0,0 @@ -package org.eclipse.aether.spi.connector; - -/* - * 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.Closeable; -import java.util.Collection; - -/** - * A connector for a remote repository. The connector is responsible for downloading/uploading of artifacts and metadata - * from/to a remote repository. - * <p> - * If applicable, a connector should obey connect/request timeouts and other relevant settings from the - * {@link org.eclipse.aether.RepositorySystemSession#getConfigProperties() configuration properties} of the repository - * session it has been obtained for. However, a connector must not emit any events to the transfer listener configured - * for the session. Instead, transfer events must be emitted only to the listener (if any) specified for a given - * download/upload request. - * <p> - * <strong>Note:</strong> While a connector itself can use multiple threads internally to performs the transfers, - * clients must not call a connector concurrently, i.e. connectors are generally not thread-safe. - * - * @see org.eclipse.aether.spi.connector.transport.TransporterProvider - * @see org.eclipse.aether.spi.connector.layout.RepositoryLayoutProvider - * @see org.eclipse.aether.spi.connector.checksum.ChecksumPolicyProvider - */ -public interface RepositoryConnector - extends Closeable -{ - - /** - * Performs the specified downloads. If a download fails, the connector stores the underlying exception in the - * download object such that callers can inspect the result via {@link ArtifactDownload#getException()} and - * {@link MetadataDownload#getException()}, respectively. If reasonable, a connector should continue to process the - * remaining downloads after an error to retrieve as many items as possible. The connector may perform the transfers - * concurrently and in any order. - * - * @param artifactDownloads The artifact downloads to perform, may be {@code null} or empty. - * @param metadataDownloads The metadata downloads to perform, may be {@code null} or empty. - */ - void get( Collection<? extends ArtifactDownload> artifactDownloads, - Collection<? extends MetadataDownload> metadataDownloads ); - - /** - * Performs the specified uploads. If an upload fails, the connector stores the underlying exception in the upload - * object such that callers can inspect the result via {@link ArtifactUpload#getException()} and - * {@link MetadataUpload#getException()}, respectively. The connector may perform the transfers concurrently and in - * any order. - * - * @param artifactUploads The artifact uploads to perform, may be {@code null} or empty. - * @param metadataUploads The metadata uploads to perform, may be {@code null} or empty. - */ - void put( Collection<? extends ArtifactUpload> artifactUploads, Collection<? extends MetadataUpload> metadataUploads ); - - /** - * Closes this connector and frees any network resources associated with it. Once closed, a connector must not be - * used for further transfers, any attempt to do so would yield a {@link IllegalStateException} or similar. Closing - * an already closed connector is harmless and has no effect. - */ - void close(); - -} http://git-wip-us.apache.org/repos/asf/maven-resolver/blob/3a1b8ae0/aether-spi/src/main/java/org/eclipse/aether/spi/connector/RepositoryConnectorFactory.java ---------------------------------------------------------------------- diff --git a/aether-spi/src/main/java/org/eclipse/aether/spi/connector/RepositoryConnectorFactory.java b/aether-spi/src/main/java/org/eclipse/aether/spi/connector/RepositoryConnectorFactory.java deleted file mode 100644 index 0d401c4..0000000 --- a/aether-spi/src/main/java/org/eclipse/aether/spi/connector/RepositoryConnectorFactory.java +++ /dev/null @@ -1,60 +0,0 @@ -package org.eclipse.aether.spi.connector; - -/* - * 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 org.eclipse.aether.RepositorySystemSession; -import org.eclipse.aether.repository.RemoteRepository; -import org.eclipse.aether.transfer.NoRepositoryConnectorException; - -/** - * A factory to create repository connectors. A repository connector is responsible for uploads/downloads to/from a - * certain kind of remote repository. When the repository system needs a repository connector for a given remote - * repository, it iterates the registered factories in descending order of their priority and calls - * {@link #newInstance(RepositorySystemSession, RemoteRepository)} on them. The first connector returned by a factory - * will then be used for the transfer. - */ -public interface RepositoryConnectorFactory -{ - - /** - * Tries to create a repository connector for the specified remote repository. Typically, a factory will inspect - * {@link RemoteRepository#getProtocol()} and {@link RemoteRepository#getContentType()} to determine whether it can - * handle a repository. - * - * @param session The repository system session from which to configure the connector, must not be {@code null}. In - * particular, a connector must notify any {@link RepositorySystemSession#getTransferListener()} set for - * the session and should obey the timeouts configured for the session. - * @param repository The remote repository to create a connector for, must not be {@code null}. - * @return The connector for the given repository, never {@code null}. - * @throws NoRepositoryConnectorException If the factory cannot create a connector for the specified remote - * repository. - */ - RepositoryConnector newInstance( RepositorySystemSession session, RemoteRepository repository ) - throws NoRepositoryConnectorException; - - /** - * The priority of this factory. When multiple factories can handle a given repository, factories with higher - * priority are preferred over those with lower priority. - * - * @return The priority of this factory. - */ - float getPriority(); - -} http://git-wip-us.apache.org/repos/asf/maven-resolver/blob/3a1b8ae0/aether-spi/src/main/java/org/eclipse/aether/spi/connector/Transfer.java ---------------------------------------------------------------------- diff --git a/aether-spi/src/main/java/org/eclipse/aether/spi/connector/Transfer.java b/aether-spi/src/main/java/org/eclipse/aether/spi/connector/Transfer.java deleted file mode 100644 index fc77011..0000000 --- a/aether-spi/src/main/java/org/eclipse/aether/spi/connector/Transfer.java +++ /dev/null @@ -1,93 +0,0 @@ -package org.eclipse.aether.spi.connector; - -/* - * 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 org.eclipse.aether.RequestTrace; -import org.eclipse.aether.transfer.TransferListener; - -/** - * An artifact/metadata transfer. - * - * @noextend This class is not intended to be extended by clients. - */ -public abstract class Transfer -{ - - private TransferListener listener; - - private RequestTrace trace; - - Transfer() - { - // hide from public - } - - /** - * Gets the exception that occurred during the transfer (if any). - * - * @return The exception or {@code null} if the transfer was successful. - */ - public abstract Exception getException(); - - /** - * Gets the listener that is to be notified during the transfer. - * - * @return The transfer listener or {@code null} if none. - */ - public TransferListener getListener() - { - return listener; - } - - /** - * Sets the listener that is to be notified during the transfer. - * - * @param listener The transfer listener to notify, may be {@code null} if none. - * @return This transfer for chaining, never {@code null}. - */ - Transfer setListener( TransferListener listener ) - { - this.listener = listener; - return this; - } - - /** - * Gets the trace information that describes the higher level request/operation in which this transfer is issued. - * - * @return The trace information about the higher level operation or {@code null} if none. - */ - public RequestTrace getTrace() - { - return trace; - } - - /** - * Sets the trace information that describes the higher level request/operation in which this transfer is issued. - * - * @param trace The trace information about the higher level operation, may be {@code null}. - * @return This transfer for chaining, never {@code null}. - */ - Transfer setTrace( RequestTrace trace ) - { - this.trace = trace; - return this; - } - -} http://git-wip-us.apache.org/repos/asf/maven-resolver/blob/3a1b8ae0/aether-spi/src/main/java/org/eclipse/aether/spi/connector/checksum/ChecksumPolicy.java ---------------------------------------------------------------------- diff --git a/aether-spi/src/main/java/org/eclipse/aether/spi/connector/checksum/ChecksumPolicy.java b/aether-spi/src/main/java/org/eclipse/aether/spi/connector/checksum/ChecksumPolicy.java deleted file mode 100644 index eb1716d..0000000 --- a/aether-spi/src/main/java/org/eclipse/aether/spi/connector/checksum/ChecksumPolicy.java +++ /dev/null @@ -1,142 +0,0 @@ -package org.eclipse.aether.spi.connector.checksum; - -/* - * 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 org.eclipse.aether.transfer.ChecksumFailureException; - -/** - * A checksum policy gets employed by repository connectors to validate the integrity of a downloaded file. For each - * downloaded file, a checksum policy instance is obtained and presented with the available checksums to conclude - * whether the download is valid or not. The following pseudo-code illustrates the usage of a checksum policy by a - * repository connector in some more detail (the retry logic has been omitted for the sake of brevity): - * - * <pre> - * void validateChecksums() throws ChecksumFailureException { - * for (checksum : checksums) { - * switch (checksum.state) { - * case MATCH: - * if (policy.onChecksumMatch(...)) { - * return; - * } - * break; - * case MISMATCH: - * policy.onChecksumMismatch(...); - * break; - * case ERROR: - * policy.onChecksumError(...); - * break; - * } - * } - * policy.onNoMoreChecksums(); - * } - * - * void downloadFile() throws Exception { - * ... - * policy = newChecksumPolicy(); - * try { - * validateChecksums(); - * } catch (ChecksumFailureException e) { - * if (!policy.onTransferChecksumFailure(...)) { - * throw e; - * } - * } - * } - * </pre> - * - * Checksum policies might be stateful and are generally not thread-safe. - */ -public interface ChecksumPolicy -{ - - /** - * Bit flag indicating a checksum which is not part of the official repository layout/structure. - */ - int KIND_UNOFFICIAL = 0x01; - - /** - * Signals a match between the locally computed checksum value and the checksum value declared by the remote - * repository. - * - * @param algorithm The name of the checksum algorithm being used, must not be {@code null}. - * @param kind A bit field providing further details about the checksum. See the {@code KIND_*} constants in this - * interface for possible bit flags. - * @return {@code true} to accept the download as valid and stop further validation, {@code false} to continue - * validation with the next checksum. - */ - boolean onChecksumMatch( String algorithm, int kind ); - - /** - * Signals a mismatch between the locally computed checksum value and the checksum value declared by the remote - * repository. A simple policy would just rethrow the provided exception. More sophisticated policies could update - * their internal state and defer a conclusion until all available checksums have been processed. - * - * @param algorithm The name of the checksum algorithm being used, must not be {@code null}. - * @param kind A bit field providing further details about the checksum. See the {@code KIND_*} constants in this - * interface for possible bit flags. - * @param exception The exception describing the checksum mismatch, must not be {@code null}. - * @throws ChecksumFailureException If the checksum validation is to be failed. If the method returns normally, - * validation continues with the next checksum. - */ - void onChecksumMismatch( String algorithm, int kind, ChecksumFailureException exception ) - throws ChecksumFailureException; - - /** - * Signals an error while computing the local checksum value or retrieving the checksum value from the remote - * repository. - * - * @param algorithm The name of the checksum algorithm being used, must not be {@code null}. - * @param kind A bit field providing further details about the checksum. See the {@code KIND_*} constants in this - * interface for possible bit flags. - * @param exception The exception describing the checksum error, must not be {@code null}. - * @throws ChecksumFailureException If the checksum validation is to be failed. If the method returns normally, - * validation continues with the next checksum. - */ - void onChecksumError( String algorithm, int kind, ChecksumFailureException exception ) - throws ChecksumFailureException; - - /** - * Signals that all available checksums have been processed. - * - * @throws ChecksumFailureException If the checksum validation is to be failed. If the method returns normally, the - * download is assumed to be valid. - */ - void onNoMoreChecksums() - throws ChecksumFailureException; - - /** - * Signals that the download is being retried after a previously thrown {@link ChecksumFailureException} that is - * {@link ChecksumFailureException#isRetryWorthy() retry-worthy}. Policies that maintain internal state will usually - * have to reset some of this state at this point to prepare for a new round of validation. - */ - void onTransferRetry(); - - /** - * Signals that (even after a potential retry) checksum validation has failed. A policy could opt to merely log this - * issue or insist on rejecting the downloaded file as unusable. - * - * @param exception The exception that was thrown from a prior call to - * {@link #onChecksumMismatch(String, int, ChecksumFailureException)}, - * {@link #onChecksumError(String, int, ChecksumFailureException)} or {@link #onNoMoreChecksums()}. - * @return {@code true} to accept the download nevertheless and let artifact resolution succeed, {@code false} to - * reject the transferred file as unusable. - */ - boolean onTransferChecksumFailure( ChecksumFailureException exception ); - -} http://git-wip-us.apache.org/repos/asf/maven-resolver/blob/3a1b8ae0/aether-spi/src/main/java/org/eclipse/aether/spi/connector/checksum/ChecksumPolicyProvider.java ---------------------------------------------------------------------- diff --git a/aether-spi/src/main/java/org/eclipse/aether/spi/connector/checksum/ChecksumPolicyProvider.java b/aether-spi/src/main/java/org/eclipse/aether/spi/connector/checksum/ChecksumPolicyProvider.java deleted file mode 100644 index f502300..0000000 --- a/aether-spi/src/main/java/org/eclipse/aether/spi/connector/checksum/ChecksumPolicyProvider.java +++ /dev/null @@ -1,58 +0,0 @@ -package org.eclipse.aether.spi.connector.checksum; - -/* - * 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 org.eclipse.aether.RepositorySystemSession; -import org.eclipse.aether.repository.RemoteRepository; -import org.eclipse.aether.transfer.TransferResource; - -/** - * Assists repository connectors in applying checksum policies to downloaded resources. - * - * @noimplement This interface is not intended to be implemented by clients. - * @noextend This interface is not intended to be extended by clients. - */ -public interface ChecksumPolicyProvider -{ - - /** - * Retrieves the checksum policy with the specified identifier for use on the given remote resource. - * - * @param session The repository system session during which the request is made, must not be {@code null}. - * @param repository The repository hosting the resource being transferred, must not be {@code null}. - * @param resource The transfer resource on which the policy will be applied, must not be {@code null}. - * @param policy The identifier of the policy to apply, must not be {@code null}. - * @return The policy to apply or {@code null} if checksums should be ignored. - */ - ChecksumPolicy newChecksumPolicy( RepositorySystemSession session, RemoteRepository repository, - TransferResource resource, String policy ); - - /** - * Returns the least strict policy. A checksum policy is said to be less strict than another policy if it would - * accept a downloaded resource in all cases where the other policy would reject the resource. - * - * @param session The repository system session during which the request is made, must not be {@code null}. - * @param policy1 A policy to compare, must not be {@code null}. - * @param policy2 A policy to compare, must not be {@code null}. - * @return The least strict policy among the two input policies. - */ - String getEffectiveChecksumPolicy( RepositorySystemSession session, String policy1, String policy2 ); - -} http://git-wip-us.apache.org/repos/asf/maven-resolver/blob/3a1b8ae0/aether-spi/src/main/java/org/eclipse/aether/spi/connector/checksum/package-info.java ---------------------------------------------------------------------- diff --git a/aether-spi/src/main/java/org/eclipse/aether/spi/connector/checksum/package-info.java b/aether-spi/src/main/java/org/eclipse/aether/spi/connector/checksum/package-info.java deleted file mode 100644 index 94d0653..0000000 --- a/aether-spi/src/main/java/org/eclipse/aether/spi/connector/checksum/package-info.java +++ /dev/null @@ -1,25 +0,0 @@ -// CHECKSTYLE_OFF: RegexpHeader -/* - * 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. - */ -/** - * The support infrastructure for repository connectors to apply checksum policies when validating the integrity of - * downloaded files. - */ -package org.eclipse.aether.spi.connector.checksum; - http://git-wip-us.apache.org/repos/asf/maven-resolver/blob/3a1b8ae0/aether-spi/src/main/java/org/eclipse/aether/spi/connector/layout/RepositoryLayout.java ---------------------------------------------------------------------- diff --git a/aether-spi/src/main/java/org/eclipse/aether/spi/connector/layout/RepositoryLayout.java b/aether-spi/src/main/java/org/eclipse/aether/spi/connector/layout/RepositoryLayout.java deleted file mode 100644 index 7ae69ac..0000000 --- a/aether-spi/src/main/java/org/eclipse/aether/spi/connector/layout/RepositoryLayout.java +++ /dev/null @@ -1,181 +0,0 @@ -package org.eclipse.aether.spi.connector.layout; - -/* - * 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.net.URI; -import java.util.List; -import java.util.Locale; - -import org.eclipse.aether.artifact.Artifact; -import org.eclipse.aether.metadata.Metadata; - -/** - * The layout for a remote repository whose artifacts/metadata can be addressed via URIs. - * <p> - * <strong>Note:</strong> Implementations must be stateless. - */ -public interface RepositoryLayout -{ - - /** - * A descriptor for a checksum file. This descriptor simply associates the location of a checksum file with the - * underlying algorithm used to calculate/verify it. Checksum algorithms are denoted by names as used with - * {@link java.security.MessageDigest#getInstance(String)}, e.g. {@code "SHA-1"} or {@code "MD5"}. - */ - static final class Checksum - { - - private final String algorithm; - - private final URI location; - - /** - * Creates a new checksum file descriptor with the specified algorithm and location. The method - * {@link #forLocation(URI, String)} is usually more convenient though. - * - * @param algorithm The algorithm used to calculate the checksum, must not be {@code null}. - * @param location The relative URI to the checksum file within a repository, must not be {@code null}. - */ - public Checksum( String algorithm, URI location ) - { - verify( algorithm, location ); - this.algorithm = algorithm; - this.location = location; - } - - /** - * Creates a checksum file descriptor for the specified artifact/metadata location and algorithm. The location - * of the checksum file itself is derived from the supplied resource URI by appending the file extension - * corresponding to the algorithm. The file extension in turn is derived from the algorithm name by stripping - * out any hyphen ('-') characters and lower-casing the name, e.g. "SHA-1" is mapped to ".sha1". - * - * @param location The relative URI to the artifact/metadata whose checksum file is being obtained, must not be - * {@code null} and must not have a query or fragment part. - * @param algorithm The algorithm used to calculate the checksum, must not be {@code null}. - * @return The checksum file descriptor, never {@code null}. - */ - public static Checksum forLocation( URI location, String algorithm ) - { - verify( algorithm, location ); - if ( location.getRawQuery() != null ) - { - throw new IllegalArgumentException( "resource location must not have query parameters: " + location ); - } - if ( location.getRawFragment() != null ) - { - throw new IllegalArgumentException( "resource location must not have a fragment: " + location ); - } - String extension = '.' + algorithm.replace( "-", "" ).toLowerCase( Locale.ENGLISH ); - return new Checksum( algorithm, URI.create( location.toString() + extension ) ); - } - - private static void verify( String algorithm, URI location ) - { - if ( algorithm == null || algorithm.length() <= 0 ) - { - throw new IllegalArgumentException( "checksum algorithm has not been specified" ); - } - if ( location == null ) - { - throw new IllegalArgumentException( "checksum location has not been specified" ); - } - if ( location.isAbsolute() ) - { - throw new IllegalArgumentException( "checksum location must be relative" ); - } - } - - /** - * Gets the name of the algorithm that is used to calculate the checksum. - * - * @return The algorithm name, never {@code null}. - * @see java.security.MessageDigest#getInstance(String) - */ - public String getAlgorithm() - { - return algorithm; - } - - /** - * Gets the location of the checksum file with a remote repository. The URI is relative to the root directory of - * the repository. - * - * @return The relative URI to the checksum file, never {@code null}. - */ - public URI getLocation() - { - return location; - } - - @Override - public String toString() - { - return location + " (" + algorithm + ")"; - } - - } - - /** - * Gets the location within a remote repository where the specified artifact resides. The URI is relative to the - * root directory of the repository. - * - * @param artifact The artifact to get the URI for, must not be {@code null}. - * @param upload {@code false} if the artifact is being downloaded, {@code true} if the artifact is being uploaded. - * @return The relative URI to the artifact, never {@code null}. - */ - URI getLocation( Artifact artifact, boolean upload ); - - /** - * Gets the location within a remote repository where the specified metadata resides. The URI is relative to the - * root directory of the repository. - * - * @param metadata The metadata to get the URI for, must not be {@code null}. - * @param upload {@code false} if the metadata is being downloaded, {@code true} if the metadata is being uploaded. - * @return The relative URI to the metadata, never {@code null}. - */ - URI getLocation( Metadata metadata, boolean upload ); - - /** - * Gets the checksums files that a remote repository keeps to help detect data corruption during transfers of the - * specified artifact. - * - * @param artifact The artifact to get the checksum files for, must not be {@code null}. - * @param upload {@code false} if the checksums are being downloaded/verified, {@code true} if the checksums are - * being uploaded/created. - * @param location The relative URI to the artifact within the repository as previously obtained from - * {@link #getLocation(Artifact, boolean)}, must not be {@code null}. - * @return The checksum files for the given artifact, possibly empty but never {@code null}. - */ - List<Checksum> getChecksums( Artifact artifact, boolean upload, URI location ); - - /** - * Gets the checksums files that a remote repository keeps to help detect data corruption during transfers of the - * specified metadata. - * - * @param metadata The metadata to get the checksum files for, must not be {@code null}. - * @param upload {@code false} if the checksums are being downloaded/verified, {@code true} if the checksums are - * being uploaded/created. - * @param location The relative URI to the metadata within the repository as previously obtained from - * {@link #getLocation(Metadata, boolean)}, must not be {@code null}. - * @return The checksum files for the given metadata, possibly empty but never {@code null}. - */ - List<Checksum> getChecksums( Metadata metadata, boolean upload, URI location ); - -} http://git-wip-us.apache.org/repos/asf/maven-resolver/blob/3a1b8ae0/aether-spi/src/main/java/org/eclipse/aether/spi/connector/layout/RepositoryLayoutFactory.java ---------------------------------------------------------------------- diff --git a/aether-spi/src/main/java/org/eclipse/aether/spi/connector/layout/RepositoryLayoutFactory.java b/aether-spi/src/main/java/org/eclipse/aether/spi/connector/layout/RepositoryLayoutFactory.java deleted file mode 100644 index 8aa71d7..0000000 --- a/aether-spi/src/main/java/org/eclipse/aether/spi/connector/layout/RepositoryLayoutFactory.java +++ /dev/null @@ -1,57 +0,0 @@ -package org.eclipse.aether.spi.connector.layout; - -/* - * 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 org.eclipse.aether.RepositorySystemSession; -import org.eclipse.aether.repository.RemoteRepository; -import org.eclipse.aether.transfer.NoRepositoryLayoutException; - -/** - * A factory to obtain repository layouts. A repository layout is responsible to map an artifact or some metadata to a - * URI relative to the repository root where the resource resides. When the repository system needs to access a given - * remote repository, it iterates the registered factories in descending order of their priority and calls - * {@link #newInstance(RepositorySystemSession, RemoteRepository)} on them. The first layout returned by a factory will - * then be used for transferring artifacts/metadata. - */ -public interface RepositoryLayoutFactory -{ - - /** - * Tries to create a repository layout for the specified remote repository. Typically, a factory will inspect - * {@link RemoteRepository#getContentType()} to determine whether it can handle a repository. - * - * @param session The repository system session from which to configure the layout, must not be {@code null}. - * @param repository The remote repository to create a layout for, must not be {@code null}. - * @return The layout for the given repository, never {@code null}. - * @throws NoRepositoryLayoutException If the factory cannot create a repository layout for the specified remote - * repository. - */ - RepositoryLayout newInstance( RepositorySystemSession session, RemoteRepository repository ) - throws NoRepositoryLayoutException; - - /** - * The priority of this factory. When multiple factories can handle a given repository, factories with higher - * priority are preferred over those with lower priority. - * - * @return The priority of this factory. - */ - float getPriority(); - -} http://git-wip-us.apache.org/repos/asf/maven-resolver/blob/3a1b8ae0/aether-spi/src/main/java/org/eclipse/aether/spi/connector/layout/RepositoryLayoutProvider.java ---------------------------------------------------------------------- diff --git a/aether-spi/src/main/java/org/eclipse/aether/spi/connector/layout/RepositoryLayoutProvider.java b/aether-spi/src/main/java/org/eclipse/aether/spi/connector/layout/RepositoryLayoutProvider.java deleted file mode 100644 index 5cdf53b..0000000 --- a/aether-spi/src/main/java/org/eclipse/aether/spi/connector/layout/RepositoryLayoutProvider.java +++ /dev/null @@ -1,47 +0,0 @@ -package org.eclipse.aether.spi.connector.layout; - -/* - * 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 org.eclipse.aether.RepositorySystemSession; -import org.eclipse.aether.repository.RemoteRepository; -import org.eclipse.aether.transfer.NoRepositoryLayoutException; - -/** - * Retrieves a repository layout from the installed layout factories. - * - * @noimplement This interface is not intended to be implemented by clients. - * @noextend This interface is not intended to be extended by clients. - */ -public interface RepositoryLayoutProvider -{ - - /** - * Tries to retrieve a repository layout for the specified remote repository. - * - * @param session The repository system session from which to configure the layout, must not be {@code null}. - * @param repository The remote repository to create a layout for, must not be {@code null}. - * @return The layout for the given repository, never {@code null}. - * @throws NoRepositoryLayoutException If none of the installed layout factories can provide a repository layout for - * the specified remote repository. - */ - RepositoryLayout newRepositoryLayout( RepositorySystemSession session, RemoteRepository repository ) - throws NoRepositoryLayoutException; - -} http://git-wip-us.apache.org/repos/asf/maven-resolver/blob/3a1b8ae0/aether-spi/src/main/java/org/eclipse/aether/spi/connector/layout/package-info.java ---------------------------------------------------------------------- diff --git a/aether-spi/src/main/java/org/eclipse/aether/spi/connector/layout/package-info.java b/aether-spi/src/main/java/org/eclipse/aether/spi/connector/layout/package-info.java deleted file mode 100644 index 2b36f7c..0000000 --- a/aether-spi/src/main/java/org/eclipse/aether/spi/connector/layout/package-info.java +++ /dev/null @@ -1,26 +0,0 @@ -// CHECKSTYLE_OFF: RegexpHeader -/* - * 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. - */ -/** - * The contract to locate URI-based resources using custom repository layouts. By implementing a - * {@link org.eclipse.aether.spi.connector.layout.RepositoryLayoutFactory} and registering it with the repository - * system, an application enables access to remote repositories that use new content types/layouts. - */ -package org.eclipse.aether.spi.connector.layout; - http://git-wip-us.apache.org/repos/asf/maven-resolver/blob/3a1b8ae0/aether-spi/src/main/java/org/eclipse/aether/spi/connector/package-info.java ---------------------------------------------------------------------- diff --git a/aether-spi/src/main/java/org/eclipse/aether/spi/connector/package-info.java b/aether-spi/src/main/java/org/eclipse/aether/spi/connector/package-info.java deleted file mode 100644 index f31a2a8..0000000 --- a/aether-spi/src/main/java/org/eclipse/aether/spi/connector/package-info.java +++ /dev/null @@ -1,30 +0,0 @@ -// CHECKSTYLE_OFF: RegexpHeader -/* - * 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. - */ -/** - * The contract to access artifacts/metadata in remote repositories. By implementing a - * {@link org.eclipse.aether.spi.connector.RepositoryConnectorFactory} and registering it with the repository system, - * an application can enable access to arbitrary remote repositories. It should be noted that a repository connector is - * powerful yet burdensome to implement. In many cases, implementing a - * {@link org.eclipse.aether.spi.connector.transport.TransporterFactory} or - * {@link org.eclipse.aether.spi.connector.layout.RepositoryLayoutFactory} will be sufficient and easier to access a - * custom remote repository. - */ -package org.eclipse.aether.spi.connector; - http://git-wip-us.apache.org/repos/asf/maven-resolver/blob/3a1b8ae0/aether-spi/src/main/java/org/eclipse/aether/spi/connector/transport/AbstractTransporter.java ---------------------------------------------------------------------- diff --git a/aether-spi/src/main/java/org/eclipse/aether/spi/connector/transport/AbstractTransporter.java b/aether-spi/src/main/java/org/eclipse/aether/spi/connector/transport/AbstractTransporter.java deleted file mode 100644 index 21e54c9..0000000 --- a/aether-spi/src/main/java/org/eclipse/aether/spi/connector/transport/AbstractTransporter.java +++ /dev/null @@ -1,233 +0,0 @@ -package org.eclipse.aether.spi.connector.transport; - -/* - * 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.Closeable; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.nio.ByteBuffer; -import java.util.concurrent.atomic.AtomicBoolean; - -import org.eclipse.aether.transfer.TransferCancelledException; - -/** - * A skeleton implementation for custom transporters. - */ -public abstract class AbstractTransporter - implements Transporter -{ - - private final AtomicBoolean closed; - - /** - * Enables subclassing. - */ - protected AbstractTransporter() - { - closed = new AtomicBoolean(); - } - - public void peek( PeekTask task ) - throws Exception - { - failIfClosed( task ); - implPeek( task ); - } - - /** - * Implements {@link #peek(PeekTask)}, gets only called if the transporter has not been closed. - * - * @param task The existence check to perform, must not be {@code null}. - * @throws Exception If the existence of the specified resource could not be confirmed. - */ - protected abstract void implPeek( PeekTask task ) - throws Exception; - - public void get( GetTask task ) - throws Exception - { - failIfClosed( task ); - implGet( task ); - } - - /** - * Implements {@link #get(GetTask)}, gets only called if the transporter has not been closed. - * - * @param task The download to perform, must not be {@code null}. - * @throws Exception If the transfer failed. - */ - protected abstract void implGet( GetTask task ) - throws Exception; - - /** - * Performs stream-based I/O for the specified download task and notifies the configured transport listener. - * Subclasses might want to invoke this utility method from within their {@link #implGet(GetTask)} to avoid - * boilerplate I/O code. - * - * @param task The download to perform, must not be {@code null}. - * @param is The input stream to download the data from, must not be {@code null}. - * @param close {@code true} if the supplied input stream should be automatically closed, {@code false} to leave the - * stream open. - * @param length The size in bytes of the downloaded resource or {@code -1} if unknown, not to be confused with the - * length of the supplied input stream which might be smaller if the download is resumed. - * @param resume {@code true} if the download resumes from {@link GetTask#getResumeOffset()}, {@code false} if the - * download starts at the first byte of the resource. - * @throws IOException If the transfer encountered an I/O error. - * @throws TransferCancelledException If the transfer was cancelled. - */ - protected void utilGet( GetTask task, InputStream is, boolean close, long length, boolean resume ) - throws IOException, TransferCancelledException - { - try - { - task.getListener().transportStarted( resume ? task.getResumeOffset() : 0, length ); - OutputStream os = task.newOutputStream( resume ); - try - { - copy( os, is, task.getListener() ); - os.close(); - } - finally - { - close( os ); - } - } - finally - { - if ( close ) - { - close( is ); - } - } - } - - public void put( PutTask task ) - throws Exception - { - failIfClosed( task ); - implPut( task ); - } - - /** - * Implements {@link #put(PutTask)}, gets only called if the transporter has not been closed. - * - * @param task The upload to perform, must not be {@code null}. - * @throws Exception If the transfer failed. - */ - protected abstract void implPut( PutTask task ) - throws Exception; - - /** - * Performs stream-based I/O for the specified upload task and notifies the configured transport listener. - * Subclasses might want to invoke this utility method from within their {@link #implPut(PutTask)} to avoid - * boilerplate I/O code. - * - * @param task The upload to perform, must not be {@code null}. - * @param os The output stream to upload the data to, must not be {@code null}. - * @param close {@code true} if the supplied output stream should be automatically closed, {@code false} to leave - * the stream open. - * @throws IOException If the transfer encountered an I/O error. - * @throws TransferCancelledException If the transfer was cancelled. - */ - protected void utilPut( PutTask task, OutputStream os, boolean close ) - throws IOException, TransferCancelledException - { - try - { - task.getListener().transportStarted( 0, task.getDataLength() ); - InputStream is = task.newInputStream(); - try - { - copy( os, is, task.getListener() ); - } - finally - { - close( is ); - } - if ( close ) - { - os.close(); - } - else - { - os.flush(); - } - } - finally - { - if ( close ) - { - close( os ); - } - } - } - - public void close() - { - if ( closed.compareAndSet( false, true ) ) - { - implClose(); - } - } - - /** - * Implements {@link #close()}, gets only called if the transporter has not already been closed. - */ - protected abstract void implClose(); - - private void failIfClosed( TransportTask task ) - { - if ( closed.get() ) - { - throw new IllegalStateException( "transporter closed, cannot execute task " + task ); - } - } - - private static void copy( OutputStream os, InputStream is, TransportListener listener ) - throws IOException, TransferCancelledException - { - ByteBuffer buffer = ByteBuffer.allocate( 1024 * 32 ); - byte[] array = buffer.array(); - for ( int read = is.read( array ); read >= 0; read = is.read( array ) ) - { - os.write( array, 0, read ); - buffer.rewind(); - buffer.limit( read ); - listener.transportProgressed( buffer ); - } - } - - private static void close( Closeable file ) - { - if ( file != null ) - { - try - { - file.close(); - } - catch ( IOException e ) - { - // irrelevant - } - } - } - -} http://git-wip-us.apache.org/repos/asf/maven-resolver/blob/3a1b8ae0/aether-spi/src/main/java/org/eclipse/aether/spi/connector/transport/GetTask.java ---------------------------------------------------------------------- diff --git a/aether-spi/src/main/java/org/eclipse/aether/spi/connector/transport/GetTask.java b/aether-spi/src/main/java/org/eclipse/aether/spi/connector/transport/GetTask.java deleted file mode 100644 index e77de77..0000000 --- a/aether-spi/src/main/java/org/eclipse/aether/spi/connector/transport/GetTask.java +++ /dev/null @@ -1,266 +0,0 @@ -package org.eclipse.aether.spi.connector.transport; - -/* - * 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.ByteArrayOutputStream; -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.OutputStream; -import java.io.UnsupportedEncodingException; -import java.net.URI; -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; - -/** - * A task to download a resource from the remote repository. - * - * @see Transporter#get(GetTask) - */ -public final class GetTask - extends TransportTask -{ - - private File dataFile; - - private boolean resume; - - private ByteArrayOutputStream dataBytes; - - private Map<String, String> checksums; - - /** - * Creates a new task for the specified remote resource. - * - * @param location The relative location of the resource in the remote repository, must not be {@code null}. - */ - public GetTask( URI location ) - { - checksums = Collections.emptyMap(); - setLocation( location ); - } - - /** - * Opens an output stream to store the downloaded data. Depending on {@link #getDataFile()}, this stream writes - * either to a file on disk or a growable buffer in memory. It's the responsibility of the caller to close the - * provided stream. - * - * @return The output stream for the data, never {@code null}. The stream is unbuffered. - * @throws IOException If the stream could not be opened. - */ - public OutputStream newOutputStream() - throws IOException - { - return newOutputStream( false ); - } - - /** - * Opens an output stream to store the downloaded data. Depending on {@link #getDataFile()}, this stream writes - * either to a file on disk or a growable buffer in memory. It's the responsibility of the caller to close the - * provided stream. - * - * @param resume {@code true} if the download resumes from the byte offset given by {@link #getResumeOffset()}, - * {@code false} if the download starts at the first byte of the resource. - * @return The output stream for the data, never {@code null}. The stream is unbuffered. - * @throws IOException If the stream could not be opened. - */ - public OutputStream newOutputStream( boolean resume ) - throws IOException - { - if ( dataFile != null ) - { - return new FileOutputStream( dataFile, this.resume && resume ); - } - if ( dataBytes == null ) - { - dataBytes = new ByteArrayOutputStream( 1024 ); - } - else if ( !resume ) - { - dataBytes.reset(); - } - return dataBytes; - } - - /** - * Gets the file (if any) where the downloaded data should be stored. If the specified file already exists, it will - * be overwritten. - * - * @return The data file or {@code null} if the data will be buffered in memory. - */ - public File getDataFile() - { - return dataFile; - } - - /** - * Sets the file where the downloaded data should be stored. If the specified file already exists, it will be - * overwritten. Unless the caller can reasonably expect the resource to be small, use of a data file is strongly - * recommended to avoid exhausting heap memory during the download. - * - * @param dataFile The file to store the downloaded data, may be {@code null} to store the data in memory. - * @return This task for chaining, never {@code null}. - */ - public GetTask setDataFile( File dataFile ) - { - return setDataFile( dataFile, false ); - } - - /** - * Sets the file where the downloaded data should be stored. If the specified file already exists, it will be - * overwritten or appended to, depending on the {@code resume} argument and the capabilities of the transporter. - * Unless the caller can reasonably expect the resource to be small, use of a data file is strongly recommended to - * avoid exhausting heap memory during the download. - * - * @param dataFile The file to store the downloaded data, may be {@code null} to store the data in memory. - * @param resume {@code true} to request resuming a previous download attempt, starting from the current length of - * the data file, {@code false} to download the resource from its beginning. - * @return This task for chaining, never {@code null}. - */ - public GetTask setDataFile( File dataFile, boolean resume ) - { - this.dataFile = dataFile; - this.resume = resume; - return this; - } - - /** - * Gets the byte offset within the resource from which the download should resume if supported. - * - * @return The zero-based index of the first byte to download or {@code 0} for a full download from the start of the - * resource, never negative. - */ - public long getResumeOffset() - { - if ( resume ) - { - if ( dataFile != null ) - { - return dataFile.length(); - } - if ( dataBytes != null ) - { - return dataBytes.size(); - } - } - return 0; - } - - /** - * Gets the data that was downloaded into memory. <strong>Note:</strong> This method may only be called if - * {@link #getDataFile()} is {@code null} as otherwise the downloaded data has been written directly to disk. - * - * @return The possibly empty data bytes, never {@code null}. - */ - public byte[] getDataBytes() - { - if ( dataFile != null || dataBytes == null ) - { - return EMPTY; - } - return dataBytes.toByteArray(); - } - - /** - * Gets the data that was downloaded into memory as a string. The downloaded data is assumed to be encoded using - * UTF-8. <strong>Note:</strong> This method may only be called if {@link #getDataFile()} is {@code null} as - * otherwise the downloaded data has been written directly to disk. - * - * @return The possibly empty data string, never {@code null}. - */ - public String getDataString() - { - if ( dataFile != null || dataBytes == null ) - { - return ""; - } - try - { - return dataBytes.toString( "UTF-8" ); - } - catch ( UnsupportedEncodingException e ) - { - throw new IllegalStateException( e ); - } - } - - /** - * Sets the listener that is to be notified during the transfer. - * - * @param listener The listener to notify of progress, may be {@code null}. - * @return This task for chaining, never {@code null}. - */ - public GetTask setListener( TransportListener listener ) - { - super.setListener( listener ); - return this; - } - - /** - * Gets the checksums which the remote repository advertises for the resource. The map is keyed by algorithm name - * (cf. {@link java.security.MessageDigest#getInstance(String)}) and the values are hexadecimal representations of - * the corresponding value. <em>Note:</em> This is optional data that a transporter may return if the underlying - * transport protocol provides metadata (e.g. HTTP headers) along with the actual resource data. - * - * @return The (read-only) checksums advertised for the downloaded resource, possibly empty but never {@code null}. - */ - public Map<String, String> getChecksums() - { - return checksums; - } - - /** - * Sets a checksum which the remote repository advertises for the resource. <em>Note:</em> Transporters should only - * use this method to record checksum information which is readily available while performing the actual download, - * they should not perform additional transfers to gather this data. - * - * @param algorithm The name of the checksum algorithm (e.g. {@code "SHA-1"}, cf. - * {@link java.security.MessageDigest#getInstance(String)} ), may be {@code null}. - * @param value The hexadecimal representation of the checksum, may be {@code null}. - * @return This task for chaining, never {@code null}. - */ - public GetTask setChecksum( String algorithm, String value ) - { - if ( algorithm != null ) - { - if ( checksums.isEmpty() ) - { - checksums = new HashMap<String, String>(); - } - if ( value != null && value.length() > 0 ) - { - checksums.put( algorithm, value ); - } - else - { - checksums.remove( algorithm ); - } - } - return this; - } - - @Override - public String toString() - { - return "<< " + getLocation(); - } - -} http://git-wip-us.apache.org/repos/asf/maven-resolver/blob/3a1b8ae0/aether-spi/src/main/java/org/eclipse/aether/spi/connector/transport/PeekTask.java ---------------------------------------------------------------------- diff --git a/aether-spi/src/main/java/org/eclipse/aether/spi/connector/transport/PeekTask.java b/aether-spi/src/main/java/org/eclipse/aether/spi/connector/transport/PeekTask.java deleted file mode 100644 index d1fb905..0000000 --- a/aether-spi/src/main/java/org/eclipse/aether/spi/connector/transport/PeekTask.java +++ /dev/null @@ -1,50 +0,0 @@ -package org.eclipse.aether.spi.connector.transport; - -/* - * 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.net.URI; - -/** - * A task to check the existence of a resource in the remote repository. <em>Note:</em> The listener returned from - * {@link #getListener()} is always a noop given that none of its event methods are relevant in context of this task. - * - * @see Transporter#peek(PeekTask) - */ -public final class PeekTask - extends TransportTask -{ - - /** - * Creates a new task for the specified remote resource. - * - * @param location The relative location of the resource in the remote repository, must not be {@code null}. - */ - public PeekTask( URI location ) - { - setLocation( location ); - } - - @Override - public String toString() - { - return "?? " + getLocation(); - } - -} http://git-wip-us.apache.org/repos/asf/maven-resolver/blob/3a1b8ae0/aether-spi/src/main/java/org/eclipse/aether/spi/connector/transport/PutTask.java ---------------------------------------------------------------------- diff --git a/aether-spi/src/main/java/org/eclipse/aether/spi/connector/transport/PutTask.java b/aether-spi/src/main/java/org/eclipse/aether/spi/connector/transport/PutTask.java deleted file mode 100644 index 1208a64..0000000 --- a/aether-spi/src/main/java/org/eclipse/aether/spi/connector/transport/PutTask.java +++ /dev/null @@ -1,157 +0,0 @@ -package org.eclipse.aether.spi.connector.transport; - -/* - * 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.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.UnsupportedEncodingException; -import java.net.URI; - -/** - * A task to upload a resource to the remote repository. - * - * @see Transporter#put(PutTask) - */ -public final class PutTask - extends TransportTask -{ - - private File dataFile; - - private byte[] dataBytes = EMPTY; - - /** - * Creates a new task for the specified remote resource. - * - * @param location The relative location of the resource in the remote repository, must not be {@code null}. - */ - public PutTask( URI location ) - { - setLocation( location ); - } - - /** - * Opens an input stream for the data to be uploaded. The length of the stream can be queried via - * {@link #getDataLength()}. It's the responsibility of the caller to close the provided stream. - * - * @return The input stream for the data, never {@code null}. The stream is unbuffered. - * @throws IOException If the stream could not be opened. - */ - public InputStream newInputStream() - throws IOException - { - if ( dataFile != null ) - { - return new FileInputStream( dataFile ); - } - return new ByteArrayInputStream( dataBytes ); - } - - /** - * Gets the total number of bytes to be uploaded. - * - * @return The total number of bytes to be uploaded. - */ - public long getDataLength() - { - if ( dataFile != null ) - { - return dataFile.length(); - } - return dataBytes.length; - } - - /** - * Gets the file (if any) with the data to be uploaded. - * - * @return The data file or {@code null} if the data resides in memory. - */ - public File getDataFile() - { - return dataFile; - } - - /** - * Sets the file with the data to be uploaded. To upload some data residing already in memory, use - * {@link #setDataString(String)} or {@link #setDataBytes(byte[])}. - * - * @param dataFile The data file, may be {@code null} if the resource data is provided directly from memory. - * @return This task for chaining, never {@code null}. - */ - public PutTask setDataFile( File dataFile ) - { - this.dataFile = dataFile; - dataBytes = EMPTY; - return this; - } - - /** - * Sets the binary data to be uploaded. - * - * @param bytes The binary data, may be {@code null}. - * @return This task for chaining, never {@code null}. - */ - public PutTask setDataBytes( byte[] bytes ) - { - this.dataBytes = ( bytes != null ) ? bytes : EMPTY; - dataFile = null; - return this; - } - - /** - * Sets the textual data to be uploaded. The text is encoded using UTF-8 before transmission. - * - * @param str The textual data, may be {@code null}. - * @return This task for chaining, never {@code null}. - */ - public PutTask setDataString( String str ) - { - try - { - return setDataBytes( ( str != null ) ? str.getBytes( "UTF-8" ) : null ); - } - catch ( UnsupportedEncodingException e ) - { - throw new IllegalStateException( e ); - } - } - - /** - * Sets the listener that is to be notified during the transfer. - * - * @param listener The listener to notify of progress, may be {@code null}. - * @return This task for chaining, never {@code null}. - */ - public PutTask setListener( TransportListener listener ) - { - super.setListener( listener ); - return this; - } - - @Override - public String toString() - { - return ">> " + getLocation(); - } - -} http://git-wip-us.apache.org/repos/asf/maven-resolver/blob/3a1b8ae0/aether-spi/src/main/java/org/eclipse/aether/spi/connector/transport/TransportListener.java ---------------------------------------------------------------------- diff --git a/aether-spi/src/main/java/org/eclipse/aether/spi/connector/transport/TransportListener.java b/aether-spi/src/main/java/org/eclipse/aether/spi/connector/transport/TransportListener.java deleted file mode 100644 index 473036b..0000000 --- a/aether-spi/src/main/java/org/eclipse/aether/spi/connector/transport/TransportListener.java +++ /dev/null @@ -1,71 +0,0 @@ -package org.eclipse.aether.spi.connector.transport; - -/* - * 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.nio.ByteBuffer; - -import org.eclipse.aether.transfer.TransferCancelledException; - -/** - * A skeleton class for listeners used to monitor transport operations. Reusing common regular expression syntax, the - * sequence of events is generally as follows: - * - * <pre> - * ( STARTED PROGRESSED* )* - * </pre> - * - * The methods in this class do nothing. - */ -public abstract class TransportListener -{ - - /** - * Enables subclassing. - */ - protected TransportListener() - { - } - - /** - * Notifies the listener about the start of the data transfer. This event may arise more than once if the transfer - * needs to be restarted (e.g. after an authentication failure). - * - * @param dataOffset The byte offset in the resource at which the transfer starts, must not be negative. - * @param dataLength The total number of bytes in the resource or {@code -1} if the length is unknown. - * @throws TransferCancelledException If the transfer should be aborted. - */ - public void transportStarted( long dataOffset, long dataLength ) - throws TransferCancelledException - { - } - - /** - * Notifies the listener about some progress in the data transfer. This event may even be fired if actually zero - * bytes have been transferred since the last event, for instance to enable cancellation. - * - * @param data The (read-only) buffer holding the bytes that have just been tranferred, must not be {@code null}. - * @throws TransferCancelledException If the transfer should be aborted. - */ - public void transportProgressed( ByteBuffer data ) - throws TransferCancelledException - { - } - -} http://git-wip-us.apache.org/repos/asf/maven-resolver/blob/3a1b8ae0/aether-spi/src/main/java/org/eclipse/aether/spi/connector/transport/TransportTask.java ---------------------------------------------------------------------- diff --git a/aether-spi/src/main/java/org/eclipse/aether/spi/connector/transport/TransportTask.java b/aether-spi/src/main/java/org/eclipse/aether/spi/connector/transport/TransportTask.java deleted file mode 100644 index f74b301..0000000 --- a/aether-spi/src/main/java/org/eclipse/aether/spi/connector/transport/TransportTask.java +++ /dev/null @@ -1,89 +0,0 @@ -package org.eclipse.aether.spi.connector.transport; - -/* - * 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.net.URI; - -/** - * A transport task. - * - * @noextend This class is not intended to be extended by clients. - */ -public abstract class TransportTask -{ - - static final TransportListener NOOP = new TransportListener() - { - }; - - static final byte[] EMPTY = {}; - - private URI location; - - private TransportListener listener = NOOP; - - TransportTask() - { - // hide - } - - /** - * Gets the relative location of the affected resource in the remote repository. - * - * @return The relative location of the resource, never {@code null}. - */ - public URI getLocation() - { - return location; - } - - TransportTask setLocation( URI location ) - { - if ( location == null ) - { - throw new IllegalArgumentException( "resource location has not been specified" ); - } - this.location = location; - return this; - } - - /** - * Gets the listener that is to be notified during the transfer. - * - * @return The listener to notify of progress, never {@code null}. - */ - public TransportListener getListener() - { - return listener; - } - - /** - * Sets the listener that is to be notified during the transfer. - * - * @param listener The listener to notify of progress, may be {@code null}. - * @return This task for chaining, never {@code null}. - */ - TransportTask setListener( TransportListener listener ) - { - this.listener = ( listener != null ) ? listener : NOOP; - return this; - } - -} http://git-wip-us.apache.org/repos/asf/maven-resolver/blob/3a1b8ae0/aether-spi/src/main/java/org/eclipse/aether/spi/connector/transport/Transporter.java ---------------------------------------------------------------------- diff --git a/aether-spi/src/main/java/org/eclipse/aether/spi/connector/transport/Transporter.java b/aether-spi/src/main/java/org/eclipse/aether/spi/connector/transport/Transporter.java deleted file mode 100644 index b8d221c..0000000 --- a/aether-spi/src/main/java/org/eclipse/aether/spi/connector/transport/Transporter.java +++ /dev/null @@ -1,104 +0,0 @@ -package org.eclipse.aether.spi.connector.transport; - -/* - * 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.Closeable; - -/** - * A transporter for a remote repository. A transporter is responsible for transferring resources between the remote - * repository and the local system. During its operation, the transporter must provide progress feedback via the - * {@link TransportListener} configured on the underlying task. - * <p> - * If applicable, a transporter should obey connect/request timeouts and other relevant settings from the - * {@link org.eclipse.aether.RepositorySystemSession#getConfigProperties() configuration properties} of the repository - * system session. - * <p> - * <strong>Note:</strong> Implementations must be thread-safe such that a given transporter instance can safely be used - * for concurrent requests. - */ -public interface Transporter - extends Closeable -{ - - /** - * Classification for exceptions that denote connectivity or authentication issues and any other kind of error that - * is not mapped to another classification code. - * - * @see #classify(Throwable) - */ - int ERROR_OTHER = 0; - - /** - * Classification for exceptions that denote a requested resource does not exist in the remote repository. Note that - * cases where a remote repository is completely inaccessible should be classified as {@link #ERROR_OTHER}. - * - * @see #classify(Throwable) - */ - int ERROR_NOT_FOUND = 1; - - /** - * Classifies the type of exception that has been thrown from a previous request to the transporter. The exception - * types employed by a transporter are generally unknown to its caller. Where a caller needs to distinguish between - * certain error cases, it employs this method to detect which error case corresponds to the exception. - * - * @param error The exception to classify, must not be {@code null}. - * @return The classification of the error, either {@link #ERROR_NOT_FOUND} or {@link #ERROR_OTHER}. - */ - int classify( Throwable error ); - - /** - * Checks the existence of a resource in the repository. If the remote repository can be contacted successfully but - * indicates the resource specified in the request does not exist, an exception is thrown such that invoking - * {@link #classify(Throwable)} with that exception yields {@link #ERROR_NOT_FOUND}. - * - * @param task The existence check to perform, must not be {@code null}. - * @throws Exception If the existence of the specified resource could not be confirmed. - */ - void peek( PeekTask task ) - throws Exception; - - /** - * Downloads a resource from the repository. If the resource is downloaded to a file as given by - * {@link GetTask#getDataFile()} and the operation fails midway, the transporter should not delete the partial file - * but leave its management to the caller. - * - * @param task The download to perform, must not be {@code null}. - * @throws Exception If the transfer failed. - */ - void get( GetTask task ) - throws Exception; - - /** - * Uploads a resource to the repository. - * - * @param task The upload to perform, must not be {@code null}. - * @throws Exception If the transfer failed. - */ - void put( PutTask task ) - throws Exception; - - /** - * Closes this transporter and frees any network resources associated with it. Once closed, a transporter must not - * be used for further transfers, any attempt to do so would yield a {@link IllegalStateException} or similar. - * Closing an already closed transporter is harmless and has no effect. - */ - void close(); - -}