-
Notifications
You must be signed in to change notification settings - Fork 338
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f07e02b
commit 8a4e818
Showing
8 changed files
with
121 additions
and
173 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
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
Oops, something went wrong.