Skip to content

Commit

Permalink
[MRESOLVER-459] Rework session to be usable in tests (#400)
Browse files Browse the repository at this point in the history
Without touching deprecated code. Also, remove the
redundancy by duplicating this class in test utils.

---

https://issues.apache.org/jira/browse/MRESOLVER-459
  • Loading branch information
cstamas committed Dec 19, 2023
1 parent 1bde99d commit df32411
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 825 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,20 @@ public final class DefaultRepositorySystemSession implements RepositorySystemSes
*/
@Deprecated
public DefaultRepositorySystemSession() {
this(h -> false);
}

/**
* Creates an uninitialized session. <em>Note:</em> The new session is not ready to use, as a bare minimum,
* {@link #setLocalRepositoryManager(LocalRepositoryManager)} needs to be called but usually other settings also
* need to be customized to achieve meaningful behavior.
* <p>
* Note: preferred way to create sessions is {@link RepositorySystem#createSessionBuilder()}, as then client code
* does not have to fiddle with session close callbacks. This constructor is meant more for testing purposes.
*
* @since 2.0.0
*/
public DefaultRepositorySystemSession(Function<Runnable, Boolean> onSessionEndedRegistrar) {
systemProperties = new HashMap<>();
systemPropertiesView = Collections.unmodifiableMap(systemProperties);
userProperties = new HashMap<>();
Expand All @@ -148,7 +162,7 @@ public DefaultRepositorySystemSession() {
authenticationSelector = NullAuthenticationSelector.INSTANCE;
artifactTypeRegistry = NullArtifactTypeRegistry.INSTANCE;
data = new DefaultSessionData();
onSessionEndedRegistrar = h -> false;
this.onSessionEndedRegistrar = requireNonNull(onSessionEndedRegistrar, "onSessionEndedRegistrar");
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
public class DefaultRepositorySystemSessionTest {

private DefaultRepositorySystemSession newSession() {
return new DefaultRepositorySystemSession();
return new DefaultRepositorySystemSession(h -> false);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@

import org.eclipse.aether.ConfigurationProperties;
import org.eclipse.aether.DefaultRepositoryCache;
import org.eclipse.aether.DefaultRepositorySystemSession;
import org.eclipse.aether.DefaultSessionData;
import org.eclipse.aether.internal.test.util.TestFileUtils;
import org.eclipse.aether.internal.test.util.TestLocalRepositoryManager;
import org.eclipse.aether.internal.test.util.TestRepositorySystemSession;
import org.eclipse.aether.repository.Authentication;
import org.eclipse.aether.repository.Proxy;
import org.eclipse.aether.repository.RemoteRepository;
Expand Down Expand Up @@ -84,7 +84,7 @@ public class HttpTransporterTest {

private final Supplier<HttpTransporterFactory> transporterFactorySupplier;

protected TestRepositorySystemSession session;
protected DefaultRepositorySystemSession session;

protected HttpTransporterFactory factory;

Expand Down Expand Up @@ -140,7 +140,7 @@ protected void newTransporter(String url) throws Exception {
closer.run();
closer = null;
}
session = new TestRepositorySystemSession(session);
session = new DefaultRepositorySystemSession(session);
session.setData(new DefaultSessionData());
transporter = factory.newInstance(session, newRepo(url));
}
Expand All @@ -150,7 +150,10 @@ protected void newTransporter(String url) throws Exception {
@BeforeEach
protected void setUp(TestInfo testInfo) throws Exception {
System.out.println("=== " + testInfo.getDisplayName() + " ===");
session = new TestRepositorySystemSession(h -> this.closer = h);
session = new DefaultRepositorySystemSession(h -> {
this.closer = h;
return true;
});
session.setLocalRepositoryManager(new TestLocalRepositoryManager());
factory = transporterFactorySupplier.get();
repoDir = TestFileUtils.createTempDir();
Expand Down
Loading

0 comments on commit df32411

Please sign in to comment.