-
Notifications
You must be signed in to change notification settings - Fork 337
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
improvement: add debug adapter for running main class to metals (#6383)
* improvement: add debug adapter for running main class to metals * add tests * wee cleanup * clean up * fix: use javacOptions classpath if scalacOptions are empty connected to: com-lihaoyi/mill#3086 * add more informative errors
- Loading branch information
1 parent
13f7ed7
commit f116e13
Showing
20 changed files
with
612 additions
and
103 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
metals/src/main/scala/scala/meta/internal/metals/ManifestJar.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package scala.meta.internal.metals | ||
|
||
import java.nio.file.Files | ||
import java.nio.file.Path | ||
import java.util.jar.Attributes | ||
import java.util.jar.JarOutputStream | ||
import java.util.jar.Manifest | ||
|
||
import scala.concurrent.ExecutionContext | ||
import scala.util.Using | ||
|
||
import scala.meta.internal.metals.MetalsEnrichments._ | ||
import scala.meta.internal.mtags.URIEncoderDecoder | ||
import scala.meta.internal.process.SystemProcess | ||
import scala.meta.io.AbsolutePath | ||
|
||
object ManifestJar { | ||
def withTempManifestJar( | ||
classpath: Seq[Path] | ||
)( | ||
op: AbsolutePath => SystemProcess | ||
)(implicit ec: ExecutionContext): SystemProcess = { | ||
val manifestJar = | ||
createManifestJar( | ||
AbsolutePath( | ||
Files.createTempFile("jvm-forker-manifest", ".jar").toAbsolutePath | ||
), | ||
classpath, | ||
) | ||
|
||
val process = op(manifestJar) | ||
process.complete.onComplete { case _ => | ||
manifestJar.delete() | ||
} | ||
process | ||
} | ||
|
||
def createManifestJar( | ||
manifestJar: AbsolutePath, | ||
classpath: Seq[Path], | ||
): AbsolutePath = { | ||
if (!manifestJar.exists) { | ||
manifestJar.touch() | ||
manifestJar.toNIO.toFile().deleteOnExit() | ||
} | ||
|
||
val classpathStr = | ||
classpath | ||
.map(path => URIEncoderDecoder.encode(path.toUri().toString())) | ||
.mkString(" ") | ||
|
||
val manifest = new Manifest() | ||
manifest.getMainAttributes.put(Attributes.Name.MANIFEST_VERSION, "1.0") | ||
manifest.getMainAttributes.put(Attributes.Name.CLASS_PATH, classpathStr) | ||
|
||
val out = Files.newOutputStream(manifestJar.toNIO) | ||
Using.resource(new JarOutputStream(out, manifest))(identity) | ||
manifestJar | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.