Skip to content

Commit

Permalink
Merge pull request #392 from alexarchambault/coursier-2.1.17
Browse files Browse the repository at this point in the history
Update coursier to 2.1.17
  • Loading branch information
alexarchambault authored Nov 11, 2024
2 parents aa9a2fc + 0ee56d9 commit 01b2c1a
Show file tree
Hide file tree
Showing 8 changed files with 367 additions and 118 deletions.
5 changes: 3 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ lazy val interface = project
rename("org.fusesource.**", "coursierapi.shaded.org.fusesource.@1"),
rename("io.github.alexarchambault.windowsansi.**", "coursierapi.shaded.windowsansi.@1"),
rename("concurrentrefhashmap.**", "coursierapi.shaded.concurrentrefhashmap.@1"),
rename("org.apache.commons.codec.**", "coursierapi.shaded.commonscodec.@1"),
rename("org.apache.commons.compress.**", "coursierapi.shaded.commonscompress.@1"),
rename("org.apache.commons.io.**", "coursierapi.shaded.commonsio.@1"),
rename("org.codehaus.plexus.**", "coursierapi.shaded.plexus.@1"),
Expand Down Expand Up @@ -187,8 +188,8 @@ lazy val interface = project
Settings.shared,
Settings.mima(),
libraryDependencies ++= Seq(
"io.get-coursier" %% "coursier" % "2.1.14",
"io.get-coursier" %% "coursier-jvm" % "2.1.14",
"io.get-coursier" %% "coursier" % "2.1.17",
"io.get-coursier" %% "coursier-jvm" % "2.1.17",
"io.get-coursier.jniutils" % "windows-jni-utils-coursierapi" % "0.3.3",
"org.slf4j" % "slf4j-api" % "1.7.36" // no need to shade that one…
),
Expand Down
93 changes: 53 additions & 40 deletions interface/src/main/java/coursierapi/Dependency.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public final class Dependency implements Serializable {
private String configuration;
private Publication publication;
private boolean transitive;
private final HashMap<DependencyManagement.Key, DependencyManagement.Values> overrides;


private Dependency(Module module, String version) {
Expand All @@ -22,6 +23,7 @@ private Dependency(Module module, String version) {
this.configuration = "";
this.publication = null;
this.transitive = true;
this.overrides = new HashMap<>();
}

public static Dependency of(Module module, String version) {
Expand All @@ -37,7 +39,8 @@ public static Dependency of(Dependency dependency) {
.withType(dependency.getType())
.withClassifier(dependency.getClassifier())
.withPublication(dependency.getPublication())
.withTransitive(dependency.isTransitive());
.withTransitive(dependency.isTransitive())
.withOverrides(dependency.getOverrides());
}

public static Dependency parse(String dep, ScalaVersion scalaVersion) {
Expand Down Expand Up @@ -101,54 +104,60 @@ public Dependency withTransitive(boolean transitive) {
return this;
}

public Dependency addOverride(DependencyManagement.Key key, DependencyManagement.Values values) {
this.overrides.put(key, values);
return this;
}
public Dependency addOverride(String organization, String name, String version) {
this.overrides.put(
new DependencyManagement.Key(organization, name, "", ""),
new DependencyManagement.Values("", version, false));
return this;
}

public Dependency withOverrides(Map<DependencyManagement.Key, DependencyManagement.Values> overrides) {
this.overrides.clear();
this.overrides.putAll(overrides);
return this;
}

@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj instanceof Dependency) {
Dependency other = (Dependency) obj;
return this.module.equals(other.module) &&
this.version.equals(other.version) &&
this.exclusions.equals(other.exclusions) &&
this.configuration.equals(other.configuration) &&
Objects.equals(this.publication, other.publication) &&
this.transitive == other.transitive;
}
return false;
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof Dependency)) return false;
Dependency that = (Dependency) o;
return transitive == that.transitive &&
Objects.equals(module, that.module) &&
Objects.equals(version, that.version) &&
Objects.equals(exclusions, that.exclusions) &&
Objects.equals(configuration, that.configuration) &&
Objects.equals(publication, that.publication) &&
Objects.equals(overrides, that.overrides);
}

@Override
public int hashCode() {
return 37 * (37 * (37 * (37 * (37 * (17 + module.hashCode()) + version.hashCode()) + exclusions.hashCode()) + configuration.hashCode()) + Objects.hashCode(publication)) + Boolean.hashCode(transitive);
return Objects.hash(
module,
version,
exclusions,
configuration,
publication,
transitive,
overrides);
}

@Override
public String toString() {
StringBuilder b = new StringBuilder("Dependency(");
b.append(module.toString());
b.append(", ");
b.append(version);
if (!exclusions.isEmpty()) {
for (Map.Entry<String, String> e : exclusions) {
b.append(", exclude=");
b.append(e.getKey());
b.append(":");
b.append(e.getValue());
}
}
if (!configuration.isEmpty()) {
b.append(", configuration=");
b.append(configuration);
}
if (publication != null) {
b.append(", publication=");
b.append(publication);
}
if (!transitive) {
b.append(", intransitive");
}
b.append(")");
return b.toString();
return "Dependency{" +
"module=" + module +
", version='" + version + '\'' +
", exclusions=" + exclusions +
", configuration='" + configuration + '\'' +
", publication=" + publication +
", transitive=" + transitive +
", overrides=" + overrides +
'}';
}


Expand Down Expand Up @@ -185,4 +194,8 @@ public Publication getPublication() {
public boolean isTransitive() {
return transitive;
}

public Map<DependencyManagement.Key, DependencyManagement.Values> getOverrides() {
return Collections.unmodifiableMap(overrides);
}
}
151 changes: 151 additions & 0 deletions interface/src/main/java/coursierapi/DependencyManagement.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
package coursierapi;

import java.util.*;

public final class DependencyManagement {

private DependencyManagement() {}

public static final class Key {
private final String organization;
private final String name;
private final String type;
private final String classifier;

public Key(String organization, String name, String type, String classifier) {
this.organization = organization;
this.name = name;
this.type = type;
this.classifier = classifier;
}

public String getOrganization() {
return organization;
}
public String getName() {
return name;
}
public String getType() {
return type;
}
public String getClassifier() {
return classifier;
}

public Key withOrganization(String newOrganization) {
return new Key(newOrganization, name, type, classifier);
}
public Key withName(String newName) {
return new Key(organization, newName, type, classifier);
}
public Key withType(String newType) {
return new Key(organization, name, newType, classifier);
}
public Key withClassifier(String newClassifier) {
return new Key(organization, name, type, newClassifier);
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof Key)) return false;
Key key = (Key) o;
return Objects.equals(organization, key.organization) && Objects.equals(name, key.name) && Objects.equals(type, key.type) && Objects.equals(classifier, key.classifier);
}

@Override
public int hashCode() {
return Objects.hash(organization, name, type, classifier);
}

@Override
public String toString() {
return "Key{" +
"organization='" + organization + '\'' +
", name='" + name + '\'' +
", type='" + type + '\'' +
", classifier='" + classifier + '\'' +
'}';
}
}

public static final class Values {
private final String configuration;
private final String version;
private final Set<Map.Entry<String, String>> exclusions = new HashSet<>();
private final boolean optional;

public Values(String configuration, String version, boolean optional) {
this.configuration = configuration;
this.version = version;
this.optional = optional;
}

public Values addExclusion(String organization, String name) {
this.exclusions.add(new AbstractMap.SimpleImmutableEntry<>(organization, name));
return this;
}
public Values addExclusions(Set<Map.Entry<String, String>> exclusions) {
this.exclusions.addAll(exclusions);
return this;
}

public String getConfiguration() {
return configuration;
}
public String getVersion() {
return version;
}
public Set<Map.Entry<String, String>> getExclusions() {
return Collections.unmodifiableSet(exclusions);
}
public boolean isOptional() {
return optional;
}

public Values withConfiguration(String newConfiguration) {
Values newValues = new Values(newConfiguration, version, optional);
newValues.addExclusions(this.exclusions);
return newValues;
}
public Values withVersion(String newVersion) {
Values newValues = new Values(configuration, newVersion, optional);
newValues.addExclusions(this.exclusions);
return newValues;
}
public Values withExclusions(Set<Map.Entry<String, String>> exclusions) {
Values newValues = new Values(configuration, version, optional);
newValues.addExclusions(exclusions);
return newValues;
}
public Values withOptional(boolean newOptional) {
Values newValues = new Values(configuration, version, newOptional);
newValues.addExclusions(this.exclusions);
return newValues;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof Values)) return false;
Values values = (Values) o;
return optional == values.optional && Objects.equals(configuration, values.configuration) && Objects.equals(version, values.version) && Objects.equals(exclusions, values.exclusions);
}

@Override
public int hashCode() {
return Objects.hash(configuration, version, exclusions, optional);
}

@Override
public String toString() {
return "Values{" +
"configuration='" + configuration + '\'' +
", version='" + version + '\'' +
", exclusions=" + exclusions +
", optional=" + optional +
'}';
}
}

}
Loading

0 comments on commit 01b2c1a

Please sign in to comment.