Skip to content

Commit

Permalink
Add ResolutionParams.scalaVersion (#111)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexarchambault authored Mar 19, 2020
1 parent daddc15 commit d5eb4d2
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 8 deletions.
29 changes: 21 additions & 8 deletions interface/src/main/java/coursierapi/ResolutionParams.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public class ResolutionParams implements Serializable {
private final HashSet<Map.Entry<String, String>> exclusions;
private boolean useSystemOsInfo;
private boolean useSystemJdkVersion;
private String scalaVersion;

private ResolutionParams() {
maxIterations = null;
Expand All @@ -21,6 +22,7 @@ private ResolutionParams() {
exclusions = new HashSet<>();
useSystemOsInfo = true;
useSystemJdkVersion = true;
scalaVersion = null;
}

@Override
Expand All @@ -31,14 +33,15 @@ public boolean equals(Object obj) {
this.forcedProperties.equals(other.forcedProperties) &&
this.profiles.equals(other.profiles) && this.exclusions.equals(other.exclusions) &&
Objects.equals(this.useSystemOsInfo, other.useSystemOsInfo) &&
Objects.equals(this.useSystemJdkVersion, other.useSystemJdkVersion);
Objects.equals(this.useSystemJdkVersion, other.useSystemJdkVersion) &&
Objects.equals(this.scalaVersion, other.scalaVersion);
}
return false;
}

@Override
public int hashCode() {
return 37 * (37 * (37 * (37 * (37 * (37 * (17 + Objects.hashCode(maxIterations)) + forceVersions.hashCode()) + forcedProperties.hashCode()) + profiles.hashCode()) + exclusions.hashCode()) + Boolean.hashCode(useSystemOsInfo)) + Boolean.hashCode(useSystemJdkVersion);
return 37 * (37 * (37 * (37 * (37 * (37 * (37 * (17 + Objects.hashCode(maxIterations)) + forceVersions.hashCode()) + forcedProperties.hashCode()) + profiles.hashCode()) + exclusions.hashCode()) + Boolean.hashCode(useSystemOsInfo)) + Boolean.hashCode(useSystemJdkVersion)) + Objects.hashCode(scalaVersion);
}

@Override
Expand Down Expand Up @@ -133,14 +136,14 @@ public String toString() {
b.append("useSystemOsInfo=");
b.append(useSystemOsInfo);

if (needSep)
b.append(", ");
else
needSep = true;

b.append("useSystemJdkVersion=");
b.append(useSystemJdkVersion);

if (scalaVersion != null) {
b.append(", scalaVersion=");
b.append(scalaVersion);
}

b.append(")");
return b.toString();
}
Expand All @@ -157,7 +160,8 @@ public static ResolutionParams of(ResolutionParams params) {
.withProfiles(params.profiles)
.withExclusions(params.exclusions)
.withUseSystemOsInfo(params.useSystemOsInfo)
.withUseSystemJdkVersion(params.useSystemJdkVersion);
.withUseSystemJdkVersion(params.useSystemJdkVersion)
.withScalaVersion(params.scalaVersion);
}

public ResolutionParams withMaxIterations(Integer maxIterations) {
Expand Down Expand Up @@ -236,6 +240,11 @@ public ResolutionParams withUseSystemJdkVersion(boolean useSystemJdkVersion) {
return this;
}

public ResolutionParams withScalaVersion(String scalaVersion) {
this.scalaVersion = scalaVersion;
return this;
}

public Integer getMaxIterations() {
return maxIterations;
}
Expand Down Expand Up @@ -263,4 +272,8 @@ public boolean getUseSystemOsInfo() {
public boolean getUseSystemJdkVersion() {
return useSystemJdkVersion;
}

public String getScalaVersion() {
return scalaVersion;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ object ApiHelper {
.withExclusions(params.exclusions.map { case (o, n) => new ju.AbstractMap.SimpleEntry(o.value, n.value): ju.Map.Entry[String, String] }.asJava)
.withUseSystemOsInfo(params.useSystemOsInfo)
.withUseSystemJdkVersion(params.useSystemJdkVersion)
.withScalaVersion(params.scalaVersionOpt.orNull)
}

def resolutionParams(params: coursierapi.ResolutionParams): ResolutionParams = {
Expand All @@ -200,6 +201,7 @@ object ApiHelper {
.withExclusions(params.getExclusions.asScala.map { e => (Organization(e.getKey), ModuleName(e.getValue)) }.toSet)
.withUseSystemOsInfo(params.getUseSystemOsInfo)
.withUseSystemJdkVersion(params.getUseSystemJdkVersion)
.withScalaVersionOpt(Option(params.getScalaVersion))
}

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

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

0 comments on commit d5eb4d2

Please sign in to comment.