Skip to content

Commit

Permalink
Paths
Browse files Browse the repository at this point in the history
WIP
  • Loading branch information
cstamas committed Feb 18, 2024
1 parent 0bfb9aa commit d8bd3c6
Show file tree
Hide file tree
Showing 112 changed files with 2,441 additions and 793 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package org.eclipse.aether;

import java.io.File;
import java.nio.file.Path;
import java.util.Collections;
import java.util.List;

Expand Down Expand Up @@ -149,7 +150,7 @@ public enum EventType {

private final ArtifactRepository repository;

private final File file;
private final Path path;

private final List<Exception> exceptions;

Expand All @@ -161,7 +162,7 @@ public enum EventType {
artifact = builder.artifact;
metadata = builder.metadata;
repository = builder.repository;
file = builder.file;
path = builder.path;
exceptions = builder.exceptions;
trace = builder.trace;
}
Expand Down Expand Up @@ -206,9 +207,21 @@ public Metadata getMetadata() {
* Gets the file involved in the event (if any).
*
* @return The involved file or {@code null} if none.
* @deprecated Use {@link #getPath()} instead.
*/
@Deprecated
public File getFile() {
return file;
return path != null ? path.toFile() : null;
}

/**
* Gets the file involved in the event (if any).
*
* @return The involved file or {@code null} if none.
* @since 2.0.0
*/
public Path getPath() {
return path;
}

/**
Expand Down Expand Up @@ -260,8 +273,8 @@ public String toString() {
if (getMetadata() != null) {
buffer.append(" ").append(getMetadata());
}
if (getFile() != null) {
buffer.append(" (").append(getFile()).append(")");
if (getPath() != null) {
buffer.append(" (").append(getPath()).append(")");
}
if (getRepository() != null) {
buffer.append(" @ ").append(getRepository());
Expand All @@ -284,7 +297,7 @@ public static final class Builder {

ArtifactRepository repository;

File file;
Path path;

List<Exception> exceptions = Collections.emptyList();

Expand Down Expand Up @@ -339,9 +352,22 @@ public Builder setRepository(ArtifactRepository repository) {
*
* @param file The involved file, may be {@code null}.
* @return This event builder for chaining, never {@code null}.
* @deprecated Use {@link #setPath(Path)} instead.
*/
@Deprecated
public Builder setFile(File file) {
this.file = file;
return setPath(file != null ? file.toPath() : null);
}

/**
* Sets the file involved in the event.
*
* @param path The involved file, may be {@code null}.
* @return This event builder for chaining, never {@code null}.
* @since 2.0.0
*/
public Builder setPath(Path path) {
this.path = path;
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
package org.eclipse.aether;

import java.io.Closeable;
import java.io.File;
import java.util.List;
import java.nio.file.Path;
import java.util.Collection;
import java.util.Map;
import java.util.function.Supplier;

Expand Down Expand Up @@ -397,6 +397,14 @@ interface SessionBuilder {
*/
SessionBuilder setSystemScopeHandler(SystemScopeHandler systemScopeHandler);

/**
* Adds on session ended handler to be immediately registered when this builder creates session.
*
* @param handler The on session ended handler, may not be {@code null}.
* @return The session for chaining, never {@code null}.
*/
SessionBuilder addOnSessionEndedHandler(Runnable handler);

/**
* Sets the custom session data supplier associated with this session.
* Note: The supplier will be used for every built session out of this builder instance, so if supplier supplies
Expand All @@ -419,25 +427,25 @@ interface SessionBuilder {

/**
* Shortcut method to set up local repository manager directly onto builder. There must be at least one non-null
* {@link File} passed in this method. In case multiple files, session builder will use chained local repository
* {@link Path} passed in this method. In case multiple files, session builder will use chained local repository
* manager.
*
* @param baseDirectories The local repository base directories.
* @return This session for chaining, never {@code null}.
* @see #withLocalRepositories(LocalRepository...)
*/
SessionBuilder withLocalRepositoryBaseDirectories(File... baseDirectories);
SessionBuilder withLocalRepositoryBaseDirectories(Path... baseDirectories);

/**
* Shortcut method to set up local repository manager directly onto builder. There must be at least one non-null
* {@link File} present in passed in list. In case multiple files, session builder will use chained local
* {@link Path} present in passed in list. In case multiple files, session builder will use chained local
* repository manager.
*
* @param baseDirectories The local repository base directories.
* @return This session for chaining, never {@code null}.
* @see #withLocalRepositories(List)
* @see #withLocalRepositories(Collection)
*/
SessionBuilder withLocalRepositoryBaseDirectories(List<File> baseDirectories);
SessionBuilder withLocalRepositoryBaseDirectories(Collection<Path> baseDirectories);

/**
* Shortcut method to set up local repository manager directly onto builder. There must be at least one non-null
Expand All @@ -457,7 +465,39 @@ interface SessionBuilder {
* @param localRepositories The local repositories.
* @return This session for chaining, never {@code null}.
*/
SessionBuilder withLocalRepositories(List<LocalRepository> localRepositories);
SessionBuilder withLocalRepositories(Collection<LocalRepository> localRepositories);

/**
* Adds the listeners to be notified of actions in the repository system.
*
* @param repositoryListeners The repository listeners, never {@code null}.
* @return This session for chaining, never {@code null}.
*/
SessionBuilder withRepositoryListener(RepositoryListener... repositoryListeners);

/**
* Adds the listeners to be notified of actions in the repository system.
*
* @param repositoryListeners The repository listeners, never {@code null}.
* @return This session for chaining, never {@code null}.
*/
SessionBuilder withRepositoryListener(Collection<RepositoryListener> repositoryListeners);

/**
* Adds the listener to be notified of uploads/downloads by the repository system.
*
* @param transferListeners The transfer listeners, never {@code null}.
* @return This session for chaining, never {@code null}.
*/
SessionBuilder withTransferListener(TransferListener... transferListeners);

/**
* Adds the listener to be notified of uploads/downloads by the repository system.
*
* @param transferListeners The transfer listeners, never {@code null}.
* @return This session for chaining, never {@code null}.
*/
SessionBuilder withTransferListener(Collection<TransferListener> transferListeners);

/**
* Shortcut method to shallow-copy passed in session into current builder.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package org.eclipse.aether.artifact;

import java.io.File;
import java.nio.file.Path;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
Expand All @@ -35,6 +36,7 @@ public abstract class AbstractArtifact implements Artifact {

private static final Pattern SNAPSHOT_TIMESTAMP = Pattern.compile("^(.*-)?([0-9]{8}\\.[0-9]{6}-[0-9]+)$");

@Override
public boolean isSnapshot() {
return isSnapshot(getVersion());
}
Expand All @@ -43,6 +45,7 @@ private static boolean isSnapshot(String version) {
return version.endsWith(SNAPSHOT) || SNAPSHOT_TIMESTAMP.matcher(version).matches();
}

@Override
public String getBaseVersion() {
return toBaseVersion(getVersion());
}
Expand Down Expand Up @@ -76,36 +79,44 @@ private static String toBaseVersion(String version) {
* @param version The version of the artifact, may be {@code null}.
* @param properties The properties of the artifact, may be {@code null} if none. The method may assume immutability
* of the supplied map, i.e. need not copy it.
* @param file The resolved file of the artifact, may be {@code null}.
* @param path The resolved file of the artifact, may be {@code null}.
* @return The new artifact instance, never {@code null}.
*/
private Artifact newInstance(String version, Map<String, String> properties, File file) {
private Artifact newInstance(String version, Map<String, String> properties, Path path) {
return new DefaultArtifact(
getGroupId(), getArtifactId(), getClassifier(), getExtension(), version, file, properties);
getGroupId(), getArtifactId(), getClassifier(), getExtension(), version, path, properties);
}

@Override
public Artifact setVersion(String version) {
String current = getVersion();
if (current.equals(version) || (version == null && current.isEmpty())) {
return this;
}
return newInstance(version, getProperties(), getFile());
return newInstance(version, getProperties(), getPath());
}

@Deprecated
@Override
public Artifact setFile(File file) {
File current = getFile();
if (Objects.equals(current, file)) {
return setPath(file != null ? file.toPath() : null);
}

@Override
public Artifact setPath(Path path) {
Path current = getPath();
if (Objects.equals(current, path)) {
return this;
}
return newInstance(getVersion(), getProperties(), file);
return newInstance(getVersion(), getProperties(), path);
}

public Artifact setProperties(Map<String, String> properties) {
Map<String, String> current = getProperties();
if (current.equals(properties) || (properties == null && current.isEmpty())) {
return this;
}
return newInstance(getVersion(), copyProperties(properties), getFile());
return newInstance(getVersion(), copyProperties(properties), getPath());
}

public String getProperty(String key, String defaultValue) {
Expand Down Expand Up @@ -163,7 +174,7 @@ public boolean equals(Object obj) {
&& Objects.equals(getVersion(), that.getVersion())
&& Objects.equals(getExtension(), that.getExtension())
&& Objects.equals(getClassifier(), that.getClassifier())
&& Objects.equals(getFile(), that.getFile())
&& Objects.equals(getPath(), that.getPath())
&& Objects.equals(getProperties(), that.getProperties());
}

Expand All @@ -180,7 +191,7 @@ public int hashCode() {
hash = hash * 31 + getExtension().hashCode();
hash = hash * 31 + getClassifier().hashCode();
hash = hash * 31 + getVersion().hashCode();
hash = hash * 31 + hash(getFile());
hash = hash * 31 + hash(getPath());
return hash;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package org.eclipse.aether.artifact;

import java.io.File;
import java.nio.file.Path;
import java.util.Map;

/**
Expand Down Expand Up @@ -97,17 +98,39 @@ public interface Artifact {
* callers must not assume any relationship between an artifact's filename and its coordinates.
*
* @return The file or {@code null} if the artifact isn't resolved.
* @deprecated Use {@link #getPath()} instead.
*/
@Deprecated
File getFile();

/**
* Gets the file of this artifact. Note that only resolved artifacts have a file associated with them. In general,
* callers must not assume any relationship between an artifact's filename and its coordinates.
*
* @return The file or {@code null} if the artifact isn't resolved.
* @since 2.0.0
*/
Path getPath();

/**
* Sets the file of the artifact.
*
* @param file The file of the artifact, may be {@code null}
* @return The new artifact, never {@code null}.
* @deprecated Use {@link #setPath(Path)} instead.
*/
@Deprecated
Artifact setFile(File file);

/**
* Sets the file of the artifact.
*
* @param path The file of the artifact, may be {@code null}
* @return The new artifact, never {@code null}.
* @since 2.0.0
*/
Artifact setPath(Path path);

/**
* Gets the specified property.
*
Expand Down
Loading

0 comments on commit d8bd3c6

Please sign in to comment.