Skip to content

Revert scalafix-properties PRs #2240

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 8, 2025
Merged
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
30 changes: 3 additions & 27 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ def inferJavaHome() = {
Some(actualHome)
}

lazy val properties = project
.in(file("scalafix-properties"))
lazy val interfaces = project
.in(file("scalafix-interfaces"))
.settings(
Compile / resourceGenerators += Def.task {
val props = new java.util.Properties()
Expand All @@ -43,16 +43,6 @@ lazy val properties = project
IO.write(props, "Scalafix version constants", out)
List(out)
},
moduleName := "scalafix-properties",
mimaPreviousArtifacts := Set.empty,
crossPaths := false,
autoScalaLibrary := false
)
.disablePlugins(ScalafixPlugin)

lazy val interfaces = project
.in(file("scalafix-interfaces"))
.settings(
(Compile / javacOptions) ++= List(
"-Xlint:all",
"-Werror"
Expand All @@ -66,7 +56,6 @@ lazy val interfaces = project
autoScalaLibrary := false
)
.disablePlugins(ScalafixPlugin)
.dependsOn(properties)

// Scala 3 macros vendored separately (i.e. without runtime classes), to
// shadow Scala 2.13 macros in the Scala 3 compiler classpath, while producing
Expand Down Expand Up @@ -380,20 +369,7 @@ lazy val integration = projectMatrix
.collect { case p @ LocalProject(n) if n.startsWith("cli3") => p }
.map(_ / publishLocalTransitive)): _*
)
.value,
// Mimic sbt-scalafix usage of interfaces (without properties per default)
// to exercise dynamic loading of scalafix-properties artifact
Test / internalDependencyClasspath := {
val prev = (Test / internalDependencyClasspath).value
val propertiesClassDirectory =
(properties / Compile / classDirectory).value
prev.filter(_.data != propertiesClassDirectory)
},
// Since tests may depend on new values, we use a system property to ScalafixCoursier
// to whitelist a specific SNAPSHOT version from the list of available ones
Test / javaOptions += s"-Dscalafix-properties.version=${version.value}",
Test / fork := true,
Test / baseDirectory := (ThisBuild / baseDirectory).value
.value
)
.defaultAxes(VirtualAxis.jvm)
.jvmPlatform(CrossVersion.full, cliScalaVersions)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,26 +163,11 @@ static Scalafix fetchAndClassloadInstance(String requestedScalaVersion, List<Rep

Properties properties = new Properties();
String propertiesPath = "scalafix-interfaces.properties";
InputStream stream = Scalafix.class.getClassLoader().getResourceAsStream(propertiesPath);
try {
InputStream stream = Scalafix.class.getClassLoader().getResourceAsStream(propertiesPath);
properties.load(stream);
} catch (Exception e) {
System.err.println(
"Failed to load '" + propertiesPath + "' from local artifact, " +
"falling back to fetching the latest scalafix version...");

try {
List<URL> jars = ScalafixCoursier.latestScalafixPropertiesJars(repositories);
URLClassLoader classLoader =
new URLClassLoader(jars.stream().toArray(URL[]::new), null);

InputStream stream = classLoader.getResourceAsStream(propertiesPath);
properties.load(stream);
} catch (Exception ee) {
throw new ScalafixException(
"Failed to load '" + propertiesPath + "' from local & remote artifacts",
ee);
}
} catch (IOException | NullPointerException e) {
throw new ScalafixException("Failed to load '" + propertiesPath + "' to lookup versions", e);
}

String scalafixVersion = properties.getProperty("scalafixVersion");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,6 @@

public class ScalafixCoursier {

private static VersionListing versions(
List<Repository> repositories,
coursierapi.Module module
) throws ScalafixException {
try {
return Versions.create()
.withModule(module)
.withRepositories(repositories.stream().toArray(Repository[]::new))
.versions()
.getMergedListings();
} catch (CoursierError e) {
throw new ScalafixException("Failed to list versions for " + module + " from " + repositories, e);
}
}

private static FetchResult fetch(
List<Repository> repositories,
List<Dependency> dependencies,
Expand Down Expand Up @@ -59,23 +44,6 @@ private static List<URL> toURLs(FetchResult result) throws ScalafixException {
return urls;
}

public static List<URL> latestScalafixPropertiesJars(
List<Repository> repositories
) throws ScalafixException {
Module module = Module.of("ch.epfl.scala", "scalafix-properties");
String allowedVersion = System.getProperty("scalafix-properties.version");
String version = versions(repositories, module)
.getAvailable()
.stream()
// Ignore RC & SNAPSHOT versions, except if explicitly requested
.filter(v -> !v.contains("-") || v.equals(allowedVersion))
.reduce((older, newer) -> newer)
.orElseThrow(() -> new ScalafixException("Could not find any stable version for " + module));

Dependency scalafixProperties = Dependency.of(module, version);
return toURLs(fetch(repositories, Collections.singletonList(scalafixProperties), ResolutionParams.create()));
}

public static List<URL> scalafixCliJars(
List<Repository> repositories,
String scalafixVersion,
Expand Down