On 06/03/2012, at 4:02 AM, Rene Groeschke wrote:
> Hi there,
> I took a look into the problems on our "unknown OS" CI build
> (http://builds.gradle.org/viewLog.html?buildId=10451&tab=buildResultsDiv&buildTypeId=bt17)
> today. Currently, two tests are failing on the CI:
>
> - "CustomPluginIntegrationTest.can reference plugin in external jar by id"
> - "CustomPluginIntegrationTest.loads plugin in correct environment"
>
> The problem we run into here is, that the POSIX library we use to set file
> permissions (org.jruby.ext.posix:jna-posix:1.0.3) does not respect the
> correct file permissions of copied flies (e.g. executable permissions for
> directories are ignored). If Posix cannot identify the current os (using
> System.getProperty('os.name') it uses a fallback implementation to the lowest
> common denominator (called JavaPOSIX) which does not support setting
> executable permissions.
> Without correct executable permissions on directories, we fail to create
> subdirectories and files within this directory.
>
> I am not sure how we should handle these issues. Updating to the latest
> jna-posix implementation (1.1.9) doesn't solve it.
>
> The options that I see at the moment:
> 1. Don't manipulate directory permissions on an unknown OS (unknown in the
> sense of unknown to posix)
> 2. Don't support other OS than Posix does and get rid of the unknown-os
> build. Currently jna-posix supports:
> - macosx
> - linux
> - freebsd
> - openbsd
> - windows
> - solaris
>
> I would like to know your point of view / feedback on this issue. Personally,
> I tend to the first option.
Option 2 is not really an option. We should work everywhere there is java 5 jvm
available. So, degrading nicely is a better approach.
I would split the problem into 2 parts: 1) determining the unix mode of a file,
and 2) setting the unix mode of a file.
To determine the permissions, we have a few options:
* If running on a non-windows platform:
* If running under java 7, use PosixFileAttributes to calculate the mode.
* If running on a platform that jna-posix supports, use POSIX.stat() to
calculate the mode.
* If running under java 6, use File.canRead(), canWrite() and canExecute()
to calculate the mode. Assume these apply to user + group, but not others.
* If running under java 5, use File.canRead and canWrite() as above. Assume
canExecute() is true for directories.
* Use 'ls -l' to calculate the mode.
* If running on a windows platform:
* If running under java 7, use DosFileAttributes.isReadOnly() to calculate
the mode.
* Use kernel32 GetFileAttributes() via jna to calculate the mode.
* If no match, fall back to 664 for files and 775 for directories.
To set the permissions:
* If running on a non-windows platform:
* If running under java 7, use PosixFileAttributes to set the mode.
* If running on a platform that jna supports, use libc chmod() via jna
(that is, jna, not jna-posix).
* If running under java 6, use setReadable(), setWriteable() and
setExecutable() to set the mode.
* Use 'chmod' to set the mode.
* If running on a windows platform:
* If running under java 7, use DosFileAttributes to set the read-only flag.
* Use kernel32 SetFileAttributes() via jna to set the read-only flag.
* If no match, ignore.
Note: jna-posix is not used to set the permissions.
To fix this for milestone 9, I would do the following:
To determine the permissions:
* If running on a non-windows platform:
* Use POSIX.stat() if supported on the current platform. i.e. !(POSIX
instance of JavaPosix)
* Otherwise, fall back to 664 for files and 775 for directories.
To set the permissions:
* If running on a non-windows platform:
* If running on a platform that jna supports, use chmod() via jna.
* If no match, ignore.
So, there are 2 changes: don't use JavaPosix (ever), and use libc chmod() to
set the mode.
For rc-1, I think we should add in the java 7 and java 6 stuff for non-windows
platforms.
--
Adam Murdoch
Gradle Co-founder
http://www.gradle.org
VP of Engineering, Gradleware Inc. - Gradle Training, Support, Consulting
http://www.gradleware.com