-
Notifications
You must be signed in to change notification settings - Fork 436
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #487 from sbt/wip/java-7
Upgrading to java 7 and using posix nio API
- Loading branch information
Showing
16 changed files
with
489 additions
and
51 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,61 @@ | ||
package com.typesafe.sbt | ||
package packager | ||
|
||
import java.io.File | ||
import sbt.Process | ||
import java.io.{ File, IOException } | ||
import java.nio.file.{ Paths, Files } | ||
import java.nio.file.attribute.{ PosixFilePermission, PosixFilePermissions } | ||
|
||
/** | ||
* Setting the file permissions | ||
*/ | ||
object chmod { | ||
|
||
/** | ||
* Using java 7 nio API to set the permissions. | ||
* | ||
* @param file | ||
* @param perms in octal format | ||
*/ | ||
def apply(file: File, perms: String): Unit = | ||
Process(Seq("chmod", perms, file.getAbsolutePath)).! match { | ||
case 0 => () | ||
case n => sys.error("Error running chmod " + perms + " " + file) | ||
} | ||
def safe(file: File, perms: String): Unit = | ||
try apply(file, perms) | ||
catch { | ||
case e: RuntimeException => () | ||
try { | ||
Files.setPosixFilePermissions(file.toPath, permissions(perms)) | ||
} catch { | ||
case e: IOException => sys.error("Error setting permissions " + perms + " on " + file.getAbsolutePath + ": " + e.getMessage) | ||
} | ||
|
||
} | ||
|
||
/** | ||
* Converts a octal unix permission representation into | ||
* a java `PosiFilePermissions` compatible string. | ||
*/ | ||
object permissions { | ||
|
||
/** | ||
* @param perms in octal format | ||
* @return java 7 posix file permissions | ||
*/ | ||
def apply(perms: String): java.util.Set[PosixFilePermission] = PosixFilePermissions fromString convert(perms) | ||
|
||
def convert(perms: String): String = { | ||
require(perms.length == 4 || perms.length == 3, s"Permissions must have 3 or 4 digits, got [$perms]") | ||
// ignore setuid/setguid/sticky bit | ||
val i = if (perms.length == 3) 0 else 1 | ||
val user = Character getNumericValue (perms charAt i) | ||
val group = Character getNumericValue (perms charAt i + 1) | ||
val other = Character getNumericValue (perms charAt i + 2) | ||
|
||
asString(user) + asString(group) + asString(other) | ||
} | ||
|
||
private def asString(perm: Int): String = perm match { | ||
case 0 => "---" | ||
case 1 => "--x" | ||
case 2 => "-w-" | ||
case 3 => "-wx" | ||
case 4 => "r--" | ||
case 5 => "r-x" | ||
case 6 => "rw-" | ||
case 7 => "rwx" | ||
} | ||
} |
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
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,7 @@ | ||
enablePlugins(JavaAppPackaging) | ||
|
||
name := "simple-test" | ||
|
||
version := "0.1.0" | ||
|
||
topLevelDirectory := None |
1 change: 1 addition & 0 deletions
1
src/sbt-test/universal/test-zips-no-top-level-dir/project/plugins.sbt
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 @@ | ||
addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % sys.props("project.version")) |
1 change: 1 addition & 0 deletions
1
src/sbt-test/universal/test-zips-no-top-level-dir/src/universal/conf/test
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 @@ | ||
# Test configuration to include in zips. |
Oops, something went wrong.