Skip to content

Commit

Permalink
Merge pull request #493 from sbt/wip/appveyor-windows-tests
Browse files Browse the repository at this point in the history
Wip/appveyor windows tests
  • Loading branch information
muuki88 committed Feb 22, 2015
2 parents 6d9f82f + df25ad5 commit 7da3f21
Show file tree
Hide file tree
Showing 7 changed files with 122 additions and 60 deletions.
24 changes: 24 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
version: '{build}'
os: Windows Server 2012
install:
- ps: |
Add-Type -AssemblyName System.IO.Compression.FileSystem
if (!(Test-Path -Path "C:\sbt" )) {
(new-object System.Net.WebClient).DownloadFile(
'https://dl.bintray.com/sbt/native-packages/sbt/0.13.7/sbt-0.13.7.zip',
'C:\sbt-bin.zip'
)
[System.IO.Compression.ZipFile]::ExtractToDirectory("C:\sbt-bin.zip", "C:\sbt")
}
- cmd: SET PATH=C:\sbt\sbt\bin;%JAVA_HOME%\bin;%PATH%
- cmd: SET SBT_OPTS=-XX:MaxPermSize=2g -Xmx4g
- cmd: SET JAVA_OPTS=-XX:MaxPermSize=2g -Xmx4g
build_script:
- sbt clean compile
test_script:
- sbt "test-only * -- -n windows"
- sbt "scripted universal/dist universal/stage windows/java-app-archetype windows/test-custom-main"
cache:
- C:\sbt\
- C:\Users\appveyor\.m2
- C:\Users\appveyor\.ivy2
22 changes: 17 additions & 5 deletions src/main/scala/com/typesafe/sbt/packager/FileUtil.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.typesafe.sbt
package packager

import scala.util.Try
import java.io.{ File, IOException }
import java.nio.file.{ Paths, Files }
import java.nio.file.attribute.{ PosixFilePermission, PosixFilePermissions }
Expand All @@ -16,13 +17,24 @@ object chmod {
* @param file
* @param perms in octal format
*/
def apply(file: File, perms: String): Unit =
try {
Files.setPosixFilePermissions(file.toPath, permissions(perms))
} catch {
case e: IOException => sys.error("Error setting permissions " + perms + " on " + file.getAbsolutePath + ": " + e.getMessage)
def apply(file: File, perms: String): Unit = {
val posix = permissions(perms)
val result = Try {
Files.setPosixFilePermissions(file.toPath, posix)
} recoverWith {
// in case of windows
case e: UnsupportedOperationException => Try {
file.setExecutable(perms contains PosixFilePermission.OWNER_EXECUTE)
file.setWritable(perms contains PosixFilePermission.OWNER_WRITE)
}
}

// propagate error
if (result.isFailure) {
val e = result.failed.get
sys.error("Error setting permissions " + perms + " on " + file.getAbsolutePath + ": " + e.getMessage)
}
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,12 @@ object ZipHelper {
*
* @param zipFile
* @param f: FileSystem => Unit, logic working in the filesystem
* @see http://stackoverflow.com/questions/9873845/java-7-zip-file-system-provider-doesnt-seem-to-accept-spaces-in-uri
*/
def withZipFilesystem(zipFile: File, overwrite: Boolean = true)(f: FileSystem => Unit) {
if (overwrite) Files deleteIfExists zipFile.toPath
val env = Map("create" -> "true").asJava
val uri = URI.create("jar:file:" + zipFile.getAbsolutePath)
val uri = new URI("jar", zipFile.toPath.toUri().toString(), null)

val system = FileSystems.newFileSystem(uri, env)
try {
Expand Down
1 change: 1 addition & 0 deletions src/sbt-test/jar/classpath-jar/test
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Run the staging and check the script.
> stage
$ exists target/universal/stage/lib/classpath-jar-test.classpath-jar-test-0.1.0-classpath.jar
$ exists target/universal/stage/bin/classpath-jar-test.bat
> check-classspath
> run-check
4 changes: 2 additions & 2 deletions src/test/scala/com/typesafe/sbt/packager/FileUtilSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import java.nio.file.attribute.PosixFilePermission._

class FileUtilSpec extends FlatSpec with Matchers {

"permissions" should "convert octal to symbolic correctly" in {
"permissions" should "convert octal to symbolic correctly" taggedAs (LinuxTag, WindowsTag) in {
permissions convert "0000" should be("---------")
permissions convert "0600" should be("rw-------")
permissions convert "0755" should be("rwxr-xr-x")
permissions convert "0777" should be("rwxrwxrwx")
}

it should "generate valid java PosixFilePermission" in {
it should "generate valid java PosixFilePermission" taggedAs (LinuxTag, WindowsTag) in {
permissions("0000") should be(empty)

val perm1 = permissions("0600")
Expand Down
10 changes: 10 additions & 0 deletions src/test/scala/com/typesafe/sbt/packager/package.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.typesafe.sbt

import org.scalatest._

package object packager {

object UniversalTag extends Tag("universal")
object LinuxTag extends Tag("linux")
object WindowsTag extends Tag("windows")
}
118 changes: 66 additions & 52 deletions src/test/scala/com/typesafe/sbt/packager/universal/ZipHelperSpec.scala
Original file line number Diff line number Diff line change
@@ -1,87 +1,101 @@
package com.typesafe.sbt.packager.universal

import com.typesafe.sbt.packager.DeleteDirectoryVisitor
import com.typesafe.sbt.packager._
import com.typesafe.sbt.packager.permissions
import org.scalatest._
import java.io.File
import java.nio.file.{ Path, Paths, Files }
import java.nio.file.attribute.PosixFilePermission._
import scala.collection.JavaConversions._

class ZipHelperSpec extends FlatSpec with Matchers with BeforeAndAfterEach {
class ZipHelperSpec extends WordSpec with Matchers with BeforeAndAfterEach with BeforeAndAfterAll {

var tmp: Path = _
val toDelete = scala.collection.mutable.ListBuffer[Path]()

override def beforeEach {
tmp = Files createTempDirectory "_sbt-native-packager"
toDelete += tmp
}

override def afterEach {
Files.walkFileTree(tmp, new DeleteDirectoryVisitor)
override def afterAll {
toDelete foreach { dir =>
scala.util.Try {
Files.walkFileTree(dir, new DeleteDirectoryVisitor)
}
}
}

"The ZipHelper.zip" should "create a zip with a single file" in {
zipSingleFile(ZipHelper.zip)
}
"The ZipHelper.zip" should {

// ignores empty directories
it should "create a zip with nested directories" ignore {
zipNestedFile(ZipHelper.zip)
}
"create a zip with a single file" taggedAs (LinuxTag, WindowsTag) in {
zipSingleFile(ZipHelper.zip)
}

it should "create a zip with nested directories containing file" in {
zipNestedDirsWithFiles(ZipHelper.zip)
}
// ignores empty directories
"create a zip with nested directories" taggedAs (LinuxTag, WindowsTag) ignore {
zipNestedFile(ZipHelper.zip)
}

it should "create directories if necessary" in {
createNecessaryDirectories(ZipHelper.zip)
}
"create a zip with nested directories containing file" taggedAs (LinuxTag, WindowsTag) in {
zipNestedDirsWithFiles(ZipHelper.zip)
}

// works only on some systems
it should "preserve the executable bit" ignore {
preserveExecutableBit(ZipHelper.zip)
}
"create directories if necessary" taggedAs (LinuxTag, WindowsTag) in {
createNecessaryDirectories(ZipHelper.zip)
}

"The ZipHelper.zipNIO" should "create a zip with a single file" in {
zipSingleFile(ZipHelper.zipNIO)
// works only on some systems
"preserve the executable bit" taggedAs (LinuxTag, WindowsTag) ignore {
preserveExecutableBit(ZipHelper.zip)
}
}

it should "create a zip with nested directories" in {
zipNestedFile(ZipHelper.zipNIO)
}
"The ZipHelper.zipNIO" should {

it should "create a zip with nested directories containing file" in {
zipNestedDirsWithFiles(ZipHelper.zipNIO)
}
"create a zip with a single file" taggedAs (LinuxTag, WindowsTag) in {
zipSingleFile(ZipHelper.zipNIO)
}

it should "create directories if necessary" in {
createNecessaryDirectories(ZipHelper.zipNIO)
}
"create a zip with nested directories" taggedAs (LinuxTag, WindowsTag) in {
zipNestedFile(ZipHelper.zipNIO)
}

// never works
it should "preserve the executable bit" ignore {
preserveExecutableBit(ZipHelper.zipNIO)
}
"create a zip with nested directories containing file" taggedAs (LinuxTag, WindowsTag) in {
zipNestedDirsWithFiles(ZipHelper.zipNIO)
}

"The ZipHelper.zipNative" should "create a zip with a single file" in {
zipSingleFile(ZipHelper.zipNative)
}
"create directories if necessary" taggedAs (LinuxTag, WindowsTag) in {
createNecessaryDirectories(ZipHelper.zipNIO)
}

it should "create a zip with nested directories" in {
zipNestedFile(ZipHelper.zipNative)
// never works
"preserve the executable bit" taggedAs (LinuxTag, WindowsTag) ignore {
preserveExecutableBit(ZipHelper.zipNIO)
}
}

it should "create a zip with nested directories containing file" in {
zipNestedDirsWithFiles(ZipHelper.zipNative)
}
"The ZipHelper.zipNative" should {
"create a zip with a single file" taggedAs (LinuxTag) in {
zipSingleFile(ZipHelper.zipNative)
}

it should "create directories if necessary" in {
createNecessaryDirectories(ZipHelper.zipNative)
}
"create a zip with nested directories" taggedAs (LinuxTag) in {
zipNestedFile(ZipHelper.zipNative)
}

"create a zip with nested directories containing file" taggedAs (LinuxTag) in {
zipNestedDirsWithFiles(ZipHelper.zipNative)
}

"create directories if necessary" taggedAs (LinuxTag) in {
createNecessaryDirectories(ZipHelper.zipNative)
}

// never works
it should "preserve the executable bit" ignore {
preserveExecutableBit(ZipHelper.zipNative)
// never works
"preserve the executable bit" taggedAs (LinuxTag) ignore {
preserveExecutableBit(ZipHelper.zipNative)
}
}

/* ========================================================== */
Expand All @@ -92,15 +106,15 @@ class ZipHelperSpec extends FlatSpec with Matchers with BeforeAndAfterEach {

private def zipSingleFile(zipper: Zipper) {
val out = tmp resolve "single.zip"
val file = tmp resolve "single.txt"
Files createFile file
val file = Files createFile (tmp resolve "single.txt")

zipper(List(file.toFile -> "single.txt"), out.toFile)

ZipHelper.withZipFilesystem(out.toFile, false) { system =>
val zippedFile = system getPath "single.txt"
Files exists zippedFile should be(true)
}

}

private def zipNestedFile(zipper: Zipper) {
Expand Down

0 comments on commit 7da3f21

Please sign in to comment.