Permalink
Browse files

Allow to add classifier artifacts in bootstraps

Source JARs in particular
  • Loading branch information...
alexarchambault committed Oct 24, 2018
1 parent ebf4ce3 commit 345492b60c8885afe711eb6adca35da2ffe1e448
@@ -25,10 +25,10 @@ object Bootstrap extends CaseApp[BootstrapOptions] {
): Unit = {
val files = helper.fetch(
sources = false,
javadoc = false,
default = true,
artifactTypes = options.artifactOptions.artifactTypes()
sources = options.artifactOptions.sources,
javadoc = options.artifactOptions.javadoc,
default = options.artifactOptions.default0(options.options.common.classifier0),
artifactTypes = options.artifactOptions.artifactTypes(options.options.common.classifier0)
)
val log: String => Unit =
@@ -353,10 +353,10 @@ object Bootstrap extends CaseApp[BootstrapOptions] {
val (urls, files) =
helper.fetchMap(
sources = false,
javadoc = false,
default = true,
artifactTypes = options.artifactOptions.artifactTypes()
sources = options.artifactOptions.sources,
javadoc = options.artifactOptions.javadoc,
default = options.artifactOptions.default0(options.options.common.classifier0),
artifactTypes = options.artifactOptions.artifactTypes(options.options.common.classifier0)
).toList.foldLeft((List.empty[String], List.empty[File])){
case ((urls, files), (url, file)) =>
if (options.options.assembly || options.options.standalone) (urls, file :: files)
@@ -17,18 +17,37 @@ import org.scalatest.junit.JUnitRunner
@RunWith(classOf[JUnitRunner])
class CliBootstrapIntegrationTest extends FlatSpec with CliTestLib {
"bootstrap" should "not add POMs to the classpath" in withFile() {
private def zipEntryContent(zis: ZipInputStream, path: String): Array[Byte] = {
val e = zis.getNextEntry
if (e == null)
throw new NoSuchElementException(s"Entry $path in zip file")
else if (e.getName == path)
coursier.internal.FileUtil.readFully(zis)
else
zipEntryContent(zis, path)
}
private def actualContent(file: File) = {
def zipEntryContent(zis: ZipInputStream, path: String): Array[Byte] = {
val e = zis.getNextEntry
if (e == null)
throw new NoSuchElementException(s"Entry $path in zip file")
else if (e.getName == path)
coursier.internal.FileUtil.readFully(zis)
else
zipEntryContent(zis, path)
var fis: InputStream = null
val content = try {
fis = new FileInputStream(file)
coursier.internal.FileUtil.readFully(fis)
} finally {
if (fis != null) fis.close()
}
val header = Seq[Byte](0x50, 0x4b, 0x03, 0x04)
val idx = content.indexOfSlice(header)
if (idx < 0)
throw new Exception(s"ZIP header not found in ${file.getPath}")
else
content.drop(idx)
}
"bootstrap" should "not add POMs to the classpath" in withFile() {
(bootstrapFile, _) =>
val repositoryOpt = RepositoryOptions(repository = List("bintray:scalameta/maven"))
val artifactOptions = ArtifactOptions()
@@ -52,25 +71,7 @@ class CliBootstrapIntegrationTest extends FlatSpec with CliTestLib {
RemainingArgs(Seq("com.geirsson:scalafmt-cli_2.12:1.4.0"), Seq())
)
var fis: InputStream = null
val content = try {
fis = new FileInputStream(bootstrapFile)
coursier.internal.FileUtil.readFully(fis)
} finally {
if (fis != null) fis.close()
}
val actualContent = {
val header = Seq[Byte](0x50, 0x4b, 0x03, 0x04)
val idx = content.indexOfSlice(header)
if (idx < 0)
throw new Exception(s"ZIP header not found in ${bootstrapFile.getPath}")
else
content.drop(idx)
}
val zis = new ZipInputStream(new ByteArrayInputStream(actualContent))
val zis = new ZipInputStream(new ByteArrayInputStream(actualContent(bootstrapFile)))
val lines = new String(zipEntryContent(zis, "bootstrap-isolation-foo-jar-urls"), UTF_8).lines.toVector
@@ -86,4 +87,37 @@ class CliBootstrapIntegrationTest extends FlatSpec with CliTestLib {
assert(extensions == Set("jar"))
}
"bootstrap" should "add standard and source JARs to the classpath" in withFile() {
(bootstrapFile, _) =>
val repositoryOpt = RepositoryOptions(repository = List("bintray:scalameta/maven"))
val artifactOptions = ArtifactOptions(
sources = true,
default = Some(true)
)
val common = CommonOptions(
repositoryOptions = repositoryOpt
)
val bootstrapSpecificOptions = BootstrapSpecificOptions(
output = bootstrapFile.getPath,
force = true,
common = common
)
val bootstrapOptions = BootstrapOptions(artifactOptions, bootstrapSpecificOptions)
Bootstrap.run(
bootstrapOptions,
RemainingArgs(Seq("com.geirsson:scalafmt-cli_2.12:1.4.0"), Seq())
)
val zis = new ZipInputStream(new ByteArrayInputStream(actualContent(bootstrapFile)))
val lines = new String(zipEntryContent(zis, "bootstrap-jar-urls"), UTF_8)
.lines
.toVector
assert(lines.exists(_.endsWith("/scalaparse_2.12-0.4.2.jar")))
assert(lines.exists(_.endsWith("/scalaparse_2.12-0.4.2-sources.jar")))
}
}
@@ -16,6 +16,7 @@ fi
"$SBTPACK_LAUNCHER" bootstrap \
--intransitive "io.get-coursier::coursier-cli:$ACTUAL_VERSION" \
--classifier standalone \
-A jar \
-J "-noverify" \
--no-default \
-r central \

0 comments on commit 345492b

Please sign in to comment.