Skip to content

Commit

Permalink
handle empty string launcher
Browse files Browse the repository at this point in the history
  • Loading branch information
mliarakos committed Jan 7, 2024
1 parent d04bf77 commit 8a0d854
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 19 deletions.
7 changes: 0 additions & 7 deletions src/main/java/scala_maven/AppLauncher.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,6 @@ public AppLauncher() {
this.args = new String[0];
}

public AppLauncher(String id, String mainClass, String[] jvmArgs, String[] args) {
this.id = id;
this.mainClass = mainClass;
this.jvmArgs = jvmArgs;
this.args = args;
}

public String getId() {
return id;
}
Expand Down
19 changes: 7 additions & 12 deletions src/main/scala/bloop/integrations/maven/MojoImplementation.scala
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,6 @@ object MojoImplementation {
}
}

private val emptyLauncher = new AppLauncher("", "", Array(), Array())

def writeCompileAndTestConfiguration(mojo: BloopMojo, session: MavenSession, log: Log): Unit = {
import scala.collection.JavaConverters._
def abs(file: File): Path = {
Expand Down Expand Up @@ -163,19 +161,15 @@ object MojoImplementation {
val configDir = mojo.getBloopConfigDir.toPath()
if (!Files.exists(configDir)) Files.createDirectory(configDir)

val launcherId = mojo.getLauncher()
val launcherId = Option(mojo.getLauncher()).filter(_.nonEmpty)
val launchers = mojo.getLaunchers()
val launcher = launchers
.find(_.getId == launcherId)
val launcher = launcherId
.flatMap(id => launchers.find(_.getId == id))
.orElse {
if (launcherId.nonEmpty)
log.warn(s"Falling back to first launcher: Launcher ID '${launcherId}' does not exist")
launchers.headOption
}
.getOrElse {
log.info(s"Using empty launcher: no run setup for ${project.getName}.")
emptyLauncher
}

// check if Scala is contained in this project
// findScalaContext throws an exception if it can't find Scala
Expand Down Expand Up @@ -203,7 +197,7 @@ object MojoImplementation {
// needs to be lazy, since we resolve artifacts later on
classpath0: () => java.util.List[_],
resources0: java.util.List[_],
launcher: AppLauncher,
launcher: Option[AppLauncher],
configuration: String
): Unit = {
val suffix = if (configuration == "compile") "" else s"-$configuration"
Expand Down Expand Up @@ -282,8 +276,9 @@ object MojoImplementation {
Config.Scala(scalaOrganization, mojo.getScalaArtifactID(), context.version().toString(), scalacArgs, allScalaJars, analysisOut, Some(compileSetup))
}
val javaHome = Some(abs(mojo.getJavaHome().getParentFile.getParentFile))
val mainClass = if (launcher.getMainClass().isEmpty) None else Some(launcher.getMainClass())
val platform = Some(Config.Platform.Jvm(Config.JvmConfig(javaHome, launcher.getJvmArgs().toList), mainClass, None, None, None))
val jvmArgs = launcher.map(_.getJvmArgs.toList).getOrElse(List.empty)
val mainClass = launcher.map(_.getMainClass).filter(_.nonEmpty)
val platform = Some(Config.Platform.Jvm(Config.JvmConfig(javaHome, jvmArgs), mainClass, None, None, None))
val resources = Some(resources0.asScala.toList.flatMap{
case a: Resource => Option(Paths.get(a.getDirectory()))
case _ => None
Expand Down

0 comments on commit 8a0d854

Please sign in to comment.