Skip to content
This repository was archived by the owner on Feb 17, 2025. It is now read-only.
Open
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

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,27 @@ public final class CacheConfiguration
private final boolean cacheParsedPoms;
private final boolean cacheOtherData;

public CacheConfiguration(boolean cachePoms, boolean cacheJars, boolean cacheParsedPoms, boolean cacheOtherData)
private CacheConfiguration(final boolean cachePoms, final boolean cacheJars,
final boolean cacheParsedPoms, final boolean cacheOtherData)
{
this.cachePoms = cachePoms;
this.cacheJars = cacheJars;
this.cacheParsedPoms = cacheParsedPoms;
this.cacheOtherData = cacheOtherData;
}

public static @NotNull Builder builder()
@NotNull
public static Builder builder()
{
return new Builder();
}

@NotNull
public static CacheConfiguration of(final boolean cachePoms, final boolean cacheJars,
final boolean cacheParsedPoms, final boolean cacheOtherData) {
return new CacheConfiguration(cachePoms, cacheJars, cacheParsedPoms, cacheOtherData);
}

public boolean cachePoms()
{
return cachePoms;
Expand Down Expand Up @@ -51,31 +59,36 @@ public static class Builder
private boolean cacheParsedPoms = true;
private boolean cacheOtherData = true;

public @NotNull Builder disablePomCaching()
@NotNull
public Builder disablePomCaching()
{
cachePoms = false;
return this;
}

public @NotNull Builder disableJarCaching()
@NotNull
public Builder disableJarCaching()
{
cacheJars = false;
return this;
}

public @NotNull Builder disableParsedPomCaching()
@NotNull
public Builder disableParsedPomCaching()
{
cacheParsedPoms = false;
return this;
}

public @NotNull Builder disableOtherDataCaching()
@NotNull
public Builder disableOtherDataCaching()
{
cacheOtherData = false;
return this;
}

public @NotNull CacheConfiguration build()
@NotNull
public CacheConfiguration build()
{
return new CacheConfiguration(cachePoms, cacheJars, cacheParsedPoms, cacheOtherData);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package me.bristermitten.pdmlibs.artifact;
package me.bristermitten.pdmlibs.dependency;

import me.bristermitten.pdmlibs.http.HTTPService;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.net.URL;
import java.util.Map;
import java.util.Set;

public abstract class Artifact
public abstract class Dependency
{

private static final String JAR_NAME_FORMAT = "%s-%s.jar";
Expand All @@ -21,15 +22,20 @@ public abstract class Artifact
@Nullable
private final String repoAlias;
@Nullable
private Set<Artifact> transitiveDependencies;
private Set<Dependency> transitiveDependencies;
@Nullable
private Map<String, String> relocations;

protected Artifact(@NotNull String groupId, @NotNull String artifactId, @NotNull String version, @Nullable Set<Artifact> transitiveDependencies, @Nullable String repoAlias)
protected Dependency(@NotNull final String groupId, @NotNull final String artifactId,
@NotNull final String version, @Nullable final Set<Dependency> transitiveDependencies,
@Nullable final String repoAlias, @Nullable final Map<String, String> relocations)
{
this.groupId = groupId;
this.artifactId = artifactId;
this.version = version;
this.transitiveDependencies = transitiveDependencies;
this.repoAlias = repoAlias;
this.relocations = relocations;
}

@Nullable
Expand Down Expand Up @@ -63,28 +69,34 @@ public String getVersion()
}

/**
* Get the transitive dependencies of this artifact.
* Get the transitive dependencies of this dependency.
* <p>
* There are semantics attached to the returned value:
* {@code null} implies that the transitive dependencies have not been looked up, and so should be located by the runtime.
* An empty set implies that the transitive dependencies <i>have</i> been looked up and are empty. That is, the artifact has no transitive dependencies.
* An empty set implies that the transitive dependencies <i>have</i> been looked up and are empty. That is, the dependency has no transitive dependencies.
* A set with elements will have those elements downloaded, without querying the transitive dependencies again.
*
* @return the transitive dependencies of this artifact.
* @return the transitive dependencies of this dependency.
*/
@Nullable
public Set<Artifact> getTransitiveDependencies()
public Set<Dependency> getTransitiveDependencies()
{
return transitiveDependencies;
}

public void setTransitiveDependencies(@Nullable Set<Artifact> transitiveDependencies)
@Nullable
public Map<String, String> getRelocations() {
return relocations;
}

public void setTransitiveDependencies(@Nullable final Set<Dependency> transitiveDependencies)
{
this.transitiveDependencies = transitiveDependencies;
}

@NotNull
@Override
public @NotNull String toString()
public String toString()
{
return "Artifact{" +
"groupId='" + groupId + '\'' +
Expand All @@ -101,7 +113,7 @@ protected final String createBaseURL(@NotNull final String repoURL)
}

@NotNull
private String addSlashIfNecessary(@NotNull final String concatTo)
private static String addSlashIfNecessary(@NotNull final String concatTo)
{
if (concatTo.endsWith("/"))
{
Expand All @@ -120,6 +132,7 @@ public final String toArtifactURL()
);
}

@NotNull
public String getJarName()
{
return String.format(JAR_NAME_FORMAT, artifactId, version);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package me.bristermitten.pdmlibs.artifact;
package me.bristermitten.pdmlibs.dependency;

import com.google.gson.annotations.SerializedName;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.Map;
import java.util.Set;

public class ArtifactDTO
public class DependencyDTO
{

@NotNull
Expand All @@ -21,15 +22,21 @@ public class ArtifactDTO
private final String repositoryAlias;

@Nullable
private final Set<ArtifactDTO> transitive;
private final Set<DependencyDTO> transitive;

public ArtifactDTO(@NotNull String groupId, @NotNull String artifactId, @NotNull String version, @Nullable String sourceRepository, @Nullable Set<ArtifactDTO> transitive)
@Nullable
private final Map<String, String> relocations;

public DependencyDTO(@NotNull final String groupId, @NotNull final String artifactId,
@NotNull final String version, @Nullable final String sourceRepository,
@Nullable final Set<DependencyDTO> transitive, @Nullable final Map<String, String> relocations)
{
this.groupId = groupId;
this.artifactId = artifactId;
this.version = version;
this.repositoryAlias = sourceRepository;
this.transitive = transitive;
this.relocations = relocations;
}

@NotNull
Expand Down Expand Up @@ -57,8 +64,13 @@ public String getRepositoryAlias()
}

@Nullable
public Set<ArtifactDTO> getTransitive()
public Set<DependencyDTO> getTransitive()
{
return transitive;
}

@Nullable
public Map<String, String> getRelocations() {
return relocations;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package me.bristermitten.pdmlibs.dependency;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.Map;
import java.util.Set;
import java.util.regex.Pattern;

import static java.util.stream.Collectors.toSet;

public class DependencyFactory
{

private static final String SNAPSHOT_SUFFIX = "-SNAPSHOT";
private static final Pattern DESCRIPTOR_SEPARATOR = Pattern.compile(":");

@NotNull
public Dependency toArtifact(@NotNull final String artifactDescriptor)
{
final String[] parts = DESCRIPTOR_SEPARATOR.split(artifactDescriptor);
final String group = parts[0];
final String artifact = parts[1];
final String version = parts[2];

return toArtifact(group, artifact, version, null, null, null);
}

@NotNull
public Dependency toArtifact(@NotNull final DependencyDTO dto)
{
Set<Dependency> transitive = null;
if (dto.getTransitive() != null)
{
transitive = dto.getTransitive().stream().map(this::toArtifact).collect(toSet());
}

return toArtifact(dto.getGroupId(), dto.getArtifactId(), dto.getVersion(), dto.getRepositoryAlias(), transitive, dto.getRelocations());
}

@NotNull
public Dependency toArtifact(@NotNull final String group, @NotNull final String artifact,
@NotNull final String version, @Nullable final String repoAlias,
@Nullable final Set<Dependency> transitive, @Nullable final Map<String, String> relocations)
{
if (version.endsWith(SNAPSHOT_SUFFIX))
{
return new SnapshotDependency(group, artifact, version, repoAlias, transitive, relocations);
}

return new ReleaseDependency(group, artifact, version, repoAlias, transitive, relocations);
}
}
Loading