-
Notifications
You must be signed in to change notification settings - Fork 128
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use external binary to extract class name from stdin Java sources
- Loading branch information
1 parent
5ab04a5
commit 80a6ecf
Showing
15 changed files
with
166 additions
and
120 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
12 changes: 12 additions & 0 deletions
12
modules/build/src/main/java/scala/build/internal/JavaParserProxyMakerSubst.java
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,12 @@ | ||
package scala.build.internal; | ||
|
||
import com.oracle.svm.core.annotate.Substitute; | ||
import com.oracle.svm.core.annotate.TargetClass; | ||
|
||
@TargetClass(className = "scala.build.internal.JavaParserProxyMaker") | ||
public final class JavaParserProxyMakerSubst { | ||
@Substitute | ||
public JavaParserProxy get() { | ||
return new JavaParserProxy(); | ||
} | ||
} |
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
17 changes: 17 additions & 0 deletions
17
modules/build/src/main/scala/scala/build/internal/JavaParseProxyJvm.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,17 @@ | ||
package scala.build.internal | ||
|
||
import coursier.cache.ArchiveCache | ||
import coursier.util.Task | ||
|
||
import scala.build.Logger | ||
import scala.build.errors.BuildException | ||
import scala.cli.javaclassname.JavaParser | ||
|
||
class JavaParserProxyJvm extends JavaParserProxy { | ||
override def className( | ||
archiveCache: ArchiveCache[Task], | ||
content: Array[Byte], | ||
logger: Logger | ||
): Either[BuildException, Option[String]] = | ||
Right(JavaParser.parseRootPublicClassName(content)) | ||
} |
42 changes: 42 additions & 0 deletions
42
modules/build/src/main/scala/scala/build/internal/JavaParserProxy.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,42 @@ | ||
package scala.build.internal | ||
|
||
import coursier.cache.ArchiveCache | ||
import coursier.util.Task | ||
|
||
import scala.build.EitherCps.{either, value} | ||
import scala.build.Logger | ||
import scala.build.errors.BuildException | ||
import scala.util.Properties | ||
|
||
class JavaParserProxy { | ||
def className( | ||
archiveCache: ArchiveCache[Task], | ||
content: Array[Byte], | ||
logger: Logger | ||
): Either[BuildException, Option[String]] = either { | ||
|
||
val versionOpt = Some("0.1.0") | ||
|
||
val platformSuffix = FetchExternalBinary.platformSuffix() | ||
val version = versionOpt | ||
.getOrElse(Constants.javaClassNameVersion) | ||
val (tag, changing) = | ||
if (version == "latest") ("launchers", true) | ||
else ("v" + version, false) | ||
val ext = if (Properties.isWin) ".zip" else ".gz" | ||
val url = | ||
s"https://github.com/scala-cli/java-class-name/releases/download/$tag/java-class-name-$platformSuffix$ext" | ||
|
||
val binary = | ||
value(FetchExternalBinary.fetch(url, changing, archiveCache, logger, "java-class-name")) | ||
|
||
val source = | ||
os.temp(content, suffix = ".java", perms = if (Properties.isWin) null else "rw-------") | ||
logger.log(s"Running $binary $source") | ||
val res = os.proc(binary, source).call() | ||
val output = res.out.text().trim | ||
|
||
if (output.isEmpty) None | ||
else Some(output) | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
modules/build/src/main/scala/scala/build/internal/JavaParserProxyMaker.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,6 @@ | ||
package scala.build.internal | ||
|
||
class JavaParserProxyMaker { | ||
def get(): JavaParserProxy = | ||
new JavaParserProxyJvm | ||
} |
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.