Skip to content

Commit

Permalink
Add ResolutionParams#defaultConfiguration (#405)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexarchambault authored Dec 5, 2024
1 parent 3d50d14 commit d78a31b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
21 changes: 18 additions & 3 deletions interface/src/main/java/coursierapi/ResolutionParams.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class ResolutionParams implements Serializable {
private Boolean keepProvidedDependencies;
private Boolean forceDepMgmtVersions;
private Boolean enableDependencyOverrides;
private String defaultConfiguration;

private ResolutionParams() {
maxIterations = null;
Expand All @@ -29,6 +30,7 @@ private ResolutionParams() {
keepProvidedDependencies = null;
forceDepMgmtVersions = null;
enableDependencyOverrides = null;
defaultConfiguration = null;
}

@Override
Expand All @@ -46,7 +48,8 @@ public boolean equals(Object o) {
Objects.equals(scalaVersion, that.scalaVersion) &&
Objects.equals(keepProvidedDependencies, that.keepProvidedDependencies) &&
Objects.equals(forceDepMgmtVersions, that.forceDepMgmtVersions) &&
Objects.equals(enableDependencyOverrides, that.enableDependencyOverrides);
Objects.equals(enableDependencyOverrides, that.enableDependencyOverrides) &&
Objects.equals(defaultConfiguration, that.defaultConfiguration);
}

@Override
Expand All @@ -62,7 +65,8 @@ public int hashCode() {
scalaVersion,
keepProvidedDependencies,
forceDepMgmtVersions,
enableDependencyOverrides);
enableDependencyOverrides,
defaultConfiguration);
}

@Override
Expand All @@ -79,6 +83,7 @@ public String toString() {
", keepProvidedDependencies=" + keepProvidedDependencies +
", forceDepMgmtVersions=" + forceDepMgmtVersions +
", enableDependencyOverrides=" + enableDependencyOverrides +
", defaultConfiguration=" + defaultConfiguration +
'}';
}

Expand All @@ -98,7 +103,8 @@ public static ResolutionParams of(ResolutionParams params) {
.withScalaVersion(params.scalaVersion)
.withKeepProvidedDependencies(params.keepProvidedDependencies)
.withForceDepMgmtVersions(params.forceDepMgmtVersions)
.withEnableDependencyOverrides(params.enableDependencyOverrides);
.withEnableDependencyOverrides(params.enableDependencyOverrides)
.withDefaultConfiguration(params.defaultConfiguration);
}

public ResolutionParams withMaxIterations(Integer maxIterations) {
Expand Down Expand Up @@ -197,6 +203,11 @@ public ResolutionParams withEnableDependencyOverrides(Boolean enableDependencyOv
return this;
}

public ResolutionParams withDefaultConfiguration(String defaultConfiguration) {
this.defaultConfiguration = defaultConfiguration;
return this;
}

public Integer getMaxIterations() {
return maxIterations;
}
Expand Down Expand Up @@ -240,4 +251,8 @@ public Boolean getForceDepMgmtVersions() {
public Boolean getEnableDependencyOverrides() {
return enableDependencyOverrides;
}

public String getDefaultConfiguration() {
return defaultConfiguration;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ object ApiHelper {
.withKeepProvidedDependencies(params.keepProvidedDependencies.map(b => b: JBoolean).orNull)
.withForceDepMgmtVersions(params.forceDepMgmtVersions.map(b => b: JBoolean).orNull)
.withEnableDependencyOverrides(params.enableDependencyOverrides.map(b => b: JBoolean).orNull)
.withDefaultConfiguration(if (params.defaultConfiguration == ResolutionParams().defaultConfiguration) null else params.defaultConfiguration.value)
}

def resolutionParams(params: coursierapi.ResolutionParams): ResolutionParams = {
Expand All @@ -277,6 +278,7 @@ object ApiHelper {
.withKeepProvidedDependencies(Option(params.getKeepProvidedDependencies).map(b => b: Boolean))
.withForceDepMgmtVersions(Option(params.getForceDepMgmtVersions).map(b => b: Boolean))
.withEnableDependencyOverrides(Option(params.getEnableDependencyOverrides).map(b => b: Boolean))
.withDefaultConfiguration(Option(params.getDefaultConfiguration).map(Configuration(_)).getOrElse(params0.defaultConfiguration))
}

def cache(cache: coursierapi.Cache): FileCache[Task] = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ object ResolutionParamsTests extends TestSuite {
.addExclusion("org.scala-lang.modules", "*")
.withUseSystemOsInfo(false)
.withUseSystemJdkVersion(false)
.withDefaultConfiguration("foo")
val params0 = ApiHelper.resolutionParams(ApiHelper.resolutionParams(params))

assert(params != ResolutionParams.create())
Expand All @@ -49,6 +50,7 @@ object ResolutionParamsTests extends TestSuite {
.withUseSystemOsInfo(true)
.withUseSystemJdkVersion(true)
.withScalaVersion("2.14.3")
.withDefaultConfiguration("thing")
val params0 = ApiHelper.resolutionParams(ApiHelper.resolutionParams(params))

assert(params != ResolutionParams.create())
Expand Down

0 comments on commit d78a31b

Please sign in to comment.