Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,13 @@ public Transporter newTransporter(RepositorySystemSession session, RemoteReposit

List<NoTransporterException> errors = new ArrayList<>();
for (PrioritizedComponent<TransporterFactory> factory : factories.getEnabled()) {
if (!factory.getComponent().canHandle(repository.getProtocol())) {
LOGGER.debug(
"Transporter factory {} cannot deal with protocol {}",
factory.getComponent(),
repository.getProtocol());
continue;
}
try {
Transporter transporter = factory.getComponent().newInstance(session, repository);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
*/
package org.eclipse.aether.spi.connector.transport;

import java.util.Map;

import org.eclipse.aether.RepositorySystemSession;
import org.eclipse.aether.repository.RemoteRepository;
import org.eclipse.aether.transfer.NoTransporterException;
Expand All @@ -31,9 +33,39 @@
*/
public interface TransporterFactory {

/**
* A key for transporter properties.
* @see #getProperties()
*/
public interface TransporterPropertyKey {}

/**
* Indicates whether this factory can handle the specified repository protocol.
* Even if {@code true} is returned the factory may still refuse to create a transporter for the given protocol.
*
* @param repositoryProtocol The repository protocol to check, may be {@code null}.
* @return {@code true} if this factory can potentially handle the specified repository protocol, {@code false} otherwise.
* @see #newInstance(RepositorySystemSession, RemoteRepository)
*/
default boolean canHandle(String repositoryProtocol) {
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe to ease listing all transporters it would be better to expose a list of supported protocols (potentially including a wildcard). WDYT @cstamas?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't requesting an instance for RemoteRepository (and getting NoTransportEx) same?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Especially as sometimes you cannot tell ahead of time. for HTTP yes, but for file?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is different in the following aspect: This just requires a protocol not a full blown remote repository. It doesn't rely on exceptions but just returns a boolean.

return true;
}

/**
* Gets the properties exposing information about this transporter factory.
* Some are mandatory and some are transporter-specific.
*
* @return A map of transporter property keys with values, never {@code null}.
* @throws UnsupportedOperationException if the transporter factory does not implement this method.
*/
default Map<TransporterPropertyKey, Object> getProperties() {
throw new UnsupportedOperationException("getProperties not implemented");
}

/**
* Tries to create a transporter for the specified remote repository. Typically, a factory will inspect
* {@link RemoteRepository#getProtocol()} to determine whether it can handle a repository.
* This should be preceded by a call to {@link #canHandle(String)}.
*
* @param session The repository system session from which to configure the transporter, must not be {@code null}.
* In particular, a transporter should obey the timeouts configured for the session.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@
*/
public interface HttpTransporterFactory extends TransporterFactory {

@Override
default boolean canHandle(String repositoryProtocol) {
return "http".equalsIgnoreCase(repositoryProtocol) || "https".equalsIgnoreCase(repositoryProtocol);
}

/**
* Tries to create HTTP transporter for the specified remote repository.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@

import static java.util.Objects.requireNonNull;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
Expand Down Expand Up @@ -1399,7 +1400,7 @@ protected void testAuthSchemePreemptive() throws Exception {

@Test
void testInit_BadProtocol() {
assertThrows(NoTransporterException.class, () -> newTransporter("bad:/void"));
assertFalse(factory.canHandle("bad:/void"));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,7 @@ public HttpTransporter newInstance(RepositorySystemSession session, RemoteReposi
requireNonNull(session, "session cannot be null");
requireNonNull(repository, "repository cannot be null");

if (!"http".equalsIgnoreCase(repository.getProtocol()) && !"https".equalsIgnoreCase(repository.getProtocol())) {
throw new NoTransporterException(repository);
}

// repository protocol already checked in canHandle
return new ApacheTransporter(repository, session, checksumExtractor, pathProcessor);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,17 @@ public ClasspathTransporterFactory setPriority(float priority) {
return this;
}

@Override
public boolean canHandle(String repositoryProtocol) {
return "classpath".equalsIgnoreCase(repositoryProtocol);
}

@Override
public Transporter newInstance(RepositorySystemSession session, RemoteRepository repository)
throws NoTransporterException {
requireNonNull(session, "session cannot be null");
requireNonNull(repository, "repository cannot be null");

if (!"classpath".equalsIgnoreCase(repository.getProtocol())) {
throw new NoTransporterException(repository);
}

return new ClasspathTransporter(session, repository);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import org.eclipse.aether.spi.connector.transport.PutTask;
import org.eclipse.aether.spi.connector.transport.Transporter;
import org.eclipse.aether.spi.connector.transport.TransporterFactory;
import org.eclipse.aether.transfer.NoTransporterException;
import org.eclipse.aether.transfer.TransferCancelledException;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
Expand All @@ -59,7 +58,9 @@ private void newTransporter(String url) throws Exception {
transporter.close();
transporter = null;
}
transporter = factory.newInstance(session, newRepo(url));
RemoteRepository repo = newRepo(url);
assertTrue(factory.canHandle(repo.getProtocol()));
transporter = factory.newInstance(session, repo);
}

@BeforeEach
Expand Down Expand Up @@ -259,8 +260,8 @@ void testPut_Closed() throws Exception {
}

@Test
void testInit_BadProtocol() {
assertThrows(NoTransporterException.class, () -> newTransporter("bad:/void"));
void testCanHandle_BadProtocol() {
assertFalse(factory.canHandle("bad:/void"));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ public FileTransporterFactory setPriority(float priority) {
return this;
}


@Override
public boolean canHandle(String repositoryProtocol) {
return "bundle".equalsIgnoreCase(repositoryProtocol) || "file".equalsIgnoreCase(repositoryProtocol);
}

/**
* Creates new instance of {@link FileTransporter}.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,7 @@ public HttpTransporter newInstance(RepositorySystemSession session, RemoteReposi
requireNonNull(session, "session cannot be null");
requireNonNull(repository, "repository cannot be null");

if (!"http".equalsIgnoreCase(repository.getProtocol()) && !"https".equalsIgnoreCase(repository.getProtocol())) {
throw new NoTransporterException(repository);
}

// repository protocol already checked in canHandle
return new JdkTransporter(session, repository, javaVersion(), checksumExtractor, pathProcessor);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,7 @@ public HttpTransporter newInstance(RepositorySystemSession session, RemoteReposi
requireNonNull(session, "session cannot be null");
requireNonNull(repository, "repository cannot be null");

if (!"http".equalsIgnoreCase(repository.getProtocol()) && !"https".equalsIgnoreCase(repository.getProtocol())) {
throw new NoTransporterException(repository);
}

// repository protocol already checked in canHandle
return new JettyTransporter(session, repository, checksumExtractor, pathProcessor);
}
}
Loading