Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

GRADLE-2149: Replace PosixWrapper usage by FallbackPOSIX & FallbackFi…

…leStat

- FallbackPOSIX used on Windows- and unknown- platform
- FallbackPOSIX#chmod() returns 0.
- FallbackPOSIX#symlink() returns 0.
- FallbackPOSIX#stat() returns FallbackFileStat
- Other FallbackPOSIX methods return UnsupportedOperationException
- FallbackFileStat#mode() returns FileSystem.DEFAULT_DIR_MODE for directories
- FallbackFileStat#mode() returns FileSystem.DEFAULT_FILE_MODE for files
- Other FallbackFileStat methods return UnsupportedOperationException
  • Loading branch information...
commit ec41b8b472016dba3c3ff6196fecf1c779cf376b 1 parent e2e0d10
@breskeby breskeby authored
View
441 subprojects/native/src/main/java/org/gradle/internal/nativeplatform/PosixWrapper.java
@@ -1,441 +0,0 @@
-/*
- * Copyright 2012 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.gradle.internal.nativeplatform;
-
-import org.gradle.internal.nativeplatform.filesystem.FileSystem;
-import org.jruby.ext.posix.*;
-
-import java.io.FileDescriptor;
-import java.io.IOException;
-
-/**
- * Util class to wrap / modify results of calls to the {@link org.jruby.ext.posix.POSIXFactory#getPOSIX(org.jruby.ext.posix.POSIXHandler, boolean)}
- * */
-public class PosixWrapper {
-
- public static POSIX wrap(POSIX posix) {
- if (posix instanceof JavaPOSIX) {
- return new ChmodDisabledFallbackPOSIX(posix);
- } else if (posix instanceof WindowsPOSIX) {
- return new FilePermissionFallbackPOSIX(posix);
- } else {
- return posix;
- }
- }
-
- private static class ChmodDisabledFallbackPOSIX extends FilePermissionFallbackPOSIX {
-
- public ChmodDisabledFallbackPOSIX(POSIX posix) {
- super(posix);
- }
-
- public int chmod(String filename, int mode) {
- // short circuit this call to return incoming mode
- return mode;
- }
- }
-
- private static class FilePermissionFallbackPOSIX extends DelegatePOSIX{
- public FilePermissionFallbackPOSIX(POSIX posix) {
- super(posix);
- }
-
- public FileStat stat(String path) {
- return new FallbackFileStat(super.stat(path));
- }
- }
-
- /**
- * a Plain DelegatePosix to keep own posix implementations "clean"
- * */
- private abstract static class DelegatePOSIX implements POSIX {
- private POSIX delegate;
-
- public DelegatePOSIX(POSIX posix) {
- this.delegate = posix;
- }
-
- public int chmod(String filename, int mode) {
- return delegate.chmod(filename, mode);
- }
-
- public int chown(String filename, int user, int group) {
- return delegate.chown(filename, user, group);
- }
-
- public int fork() {
- return delegate.fork();
- }
-
- public FileStat fstat(FileDescriptor descriptor) {
- return delegate.fstat(descriptor);
- }
-
- public int getegid() {
- return delegate.getegid();
- }
-
- public int geteuid() {
- return delegate.geteuid();
- }
-
- public int seteuid(int euid) {
- return delegate.seteuid(euid);
- }
-
- public int getgid() {
- return delegate.getgid();
- }
-
- public String getlogin() {
- return delegate.getlogin();
- }
-
- public int getpgid() {
- return delegate.getpgid();
- }
-
- public int getpgid(int pid) {
- return delegate.getpgid(pid);
- }
-
- public int getpgrp() {
- return delegate.getpgrp();
- }
-
- public int getpid() {
- return delegate.getpid();
- }
-
- public int getppid() {
- return delegate.getppid();
- }
-
- public int getpriority(int which, int who) {
- return delegate.getpriority(which, who);
- }
-
- public Passwd getpwent() {
- return delegate.getpwent();
- }
-
- public Passwd getpwuid(int which) {
- return delegate.getpwuid(which);
- }
-
- public Passwd getpwnam(String which) {
- return delegate.getpwnam(which);
- }
-
- public Group getgrgid(int which) {
- return delegate.getgrgid(which);
- }
-
- public Group getgrnam(String which) {
- return delegate.getgrnam(which);
- }
-
- public Group getgrent() {
- return delegate.getgrent();
- }
-
- public int endgrent() {
- return delegate.endgrent();
- }
-
- public int setgrent() {
- return delegate.setgrent();
- }
-
- public int endpwent() {
- return delegate.endpwent();
- }
-
- public int setpwent() {
- return delegate.setpwent();
- }
-
- public int getuid() {
- return delegate.getuid();
- }
-
- public boolean isatty(FileDescriptor descriptor) {
- return delegate.isatty(descriptor);
- }
-
- public int kill(int pid, int signal) {
- return delegate.kill(pid, signal);
- }
-
- public int lchmod(String filename, int mode) {
- return delegate.lchmod(filename, mode);
- }
-
- public int lchown(String filename, int user, int group) {
- return delegate.lchown(filename, user, group);
- }
-
- public int link(String oldpath, String newpath) {
- return delegate.link(oldpath, newpath);
- }
-
- public FileStat lstat(String path) {
- return delegate.lstat(path);
- }
-
- public int mkdir(String path, int mode) {
- return delegate.mkdir(path, mode);
- }
-
- public String readlink(String path) throws IOException {
- return delegate.readlink(path);
- }
-
- public int setsid() {
- return delegate.setsid();
- }
-
- public int setgid(int gid) {
- return delegate.setgid(gid);
- }
-
- public int setegid(int egid) {
- return delegate.setegid(egid);
- }
-
- public int setpgid(int pid, int pgid) {
- return delegate.setpgid(pid, pgid);
- }
-
- public int setpgrp(int pid, int pgrp) {
- return delegate.setpgrp(pid, pgrp);
- }
-
- public int setpriority(int which, int who, int prio) {
- return delegate.setpriority(which, who, prio);
- }
-
- public int setuid(int uid) {
- return delegate.setuid(uid);
- }
-
- public FileStat stat(String path) {
- return new FallbackFileStat(delegate.stat(path));
- }
-
- public int symlink(String oldpath, String newpath) {
- return delegate.symlink(oldpath, newpath);
- }
-
- public int umask(int mask) {
- return delegate.umask(mask);
- }
-
- public int utimes(String path, long[] atimeval, long[] mtimeval) {
- return delegate.utimes(path, atimeval, mtimeval);
- }
-
- public int waitpid(int pid, int[] status, int flags) {
- return delegate.waitpid(pid, status, flags);
- }
-
- public int wait(int[] status) {
- return delegate.wait(status);
- }
-
- public int errno() {
- return delegate.errno();
- }
-
- public void errno(int value) {
- delegate.errno(value);
- }
- }
-
- /**
- * Calls to {@link #mode()} return 664 for files and 755 for directories.
- * Other method calls are delegated to delegate FileStat.
- * */
- private static class FallbackFileStat implements FileStat {
-
- private FileStat delegate;
-
- public FallbackFileStat(FileStat stat) {
- this.delegate = stat;
- }
-
- public long atime() {
- return delegate.atime();
- }
-
- public long blocks() {
- return delegate.blocks();
- }
-
- public long blockSize() {
- return delegate.blockSize();
- }
-
- public long ctime() {
- return delegate.ctime();
- }
-
- public long dev() {
- return delegate.dev();
- }
-
- public String ftype() {
- return delegate.ftype();
- }
-
- public int gid() {
- return delegate.gid();
- }
-
- public boolean groupMember(int gid) {
- return delegate.groupMember(gid);
- }
-
- public long ino() {
- return delegate.ino();
- }
-
- public boolean isBlockDev() {
- return delegate.isBlockDev();
- }
-
- public boolean isCharDev() {
- return delegate.isCharDev();
- }
-
- public boolean isDirectory() {
- return delegate.isDirectory();
- }
-
- public boolean isEmpty() {
- return delegate.isEmpty();
- }
-
- public boolean isExecutable() {
- return delegate.isExecutable();
- }
-
- public boolean isExecutableReal() {
- return delegate.isExecutableReal();
- }
-
- public boolean isFifo() {
- return delegate.isFifo();
- }
-
- public boolean isFile() {
- return delegate.isFile();
- }
-
- public boolean isGroupOwned() {
- return delegate.isGroupOwned();
- }
-
- public boolean isIdentical(FileStat other) {
- return delegate.isIdentical(other);
- }
-
- public boolean isNamedPipe() {
- return delegate.isNamedPipe();
- }
-
- public boolean isOwned() {
- return delegate.isOwned();
- }
-
- public boolean isROwned() {
- return delegate.isROwned();
- }
-
- public boolean isReadable() {
- return delegate.isReadable();
- }
-
- public boolean isReadableReal() {
- return delegate.isReadableReal();
- }
-
- public boolean isWritable() {
- return delegate.isWritable();
- }
-
- public boolean isWritableReal() {
- return delegate.isWritableReal();
- }
-
- public boolean isSetgid() {
- return delegate.isSetgid();
- }
-
- public boolean isSetuid() {
- return delegate.isSetuid();
- }
-
- public boolean isSocket() {
- return delegate.isSocket();
- }
-
- public boolean isSticky() {
- return delegate.isSticky();
- }
-
- public boolean isSymlink() {
- return delegate.isSymlink();
- }
-
- public int major(long dev) {
- return delegate.major(dev);
- }
-
- public int minor(long dev) {
- return delegate.minor(dev);
- }
-
- public int mode() {
- if(isDirectory()){
- return FileSystem.DEFAULT_DIR_MODE;
- }else{
- return FileSystem.DEFAULT_FILE_MODE;
- }
- }
-
- public long mtime() {
- return delegate.mtime();
- }
-
- public int nlink() {
- return delegate.nlink();
- }
-
- public long rdev() {
- return delegate.rdev();
- }
-
- public long st_size() {
- return delegate.st_size();
- }
-
- public int uid() {
- return delegate.uid();
- }
- }
-}
View
190 subprojects/native/src/main/java/org/gradle/internal/nativeplatform/filesystem/FallbackFileStat.java
@@ -0,0 +1,190 @@
+/*
+ * Copyright 2012 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.gradle.internal.nativeplatform.filesystem;
+
+import org.jruby.ext.posix.FileStat;
+
+import java.io.File;
+
+public class FallbackFileStat implements FileStat {
+
+ private final File file;
+
+ public FallbackFileStat(String path) {
+ this.file = new File(path);
+ }
+
+ public long atime() {
+ throw new UnsupportedOperationException("Operation atime() is not supported.");
+ }
+
+ public long blocks() {
+ throw new UnsupportedOperationException("Operation blocks is not supported.");
+ }
+
+ public long blockSize() {
+ throw new UnsupportedOperationException("Operation blockSize() is not supported.");
+ }
+
+ public long ctime() {
+ throw new UnsupportedOperationException("Operation ctime() is not supported.");
+ }
+
+ public long dev() {
+ throw new UnsupportedOperationException("Operation dev() is not supported.");
+ }
+
+ public String ftype() {
+ throw new UnsupportedOperationException("Operation ftype() is not supported.");
+ }
+
+ public int gid() {
+ throw new UnsupportedOperationException("Operation gid() is not supported.");
+ }
+
+ public boolean groupMember(int gid) {
+ throw new UnsupportedOperationException("Operation groupMember() is not supported.");
+ }
+
+ public long ino() {
+ throw new UnsupportedOperationException("Operation ino() is not supported.");
+ }
+
+ public boolean isBlockDev() {
+ throw new UnsupportedOperationException("Operation isBlockDev() is not supported.");
+ }
+
+ public boolean isCharDev() {
+ throw new UnsupportedOperationException("Operation isCharDev() is not supported.");
+ }
+
+ public boolean isDirectory() {
+ return file.isDirectory();
+ }
+
+ public boolean isEmpty() {
+ throw new UnsupportedOperationException("Operation isEmpty() is not supported.");
+ }
+
+ public boolean isExecutable() {
+ throw new UnsupportedOperationException("Operation isExecutable() is not supported.");
+ }
+
+ public boolean isExecutableReal() {
+ throw new UnsupportedOperationException("Operation isExecutableReal() is not supported.");
+ }
+
+ public boolean isFifo() {
+ throw new UnsupportedOperationException("Operation isFifo() is not supported.");
+ }
+
+ public boolean isFile() {
+ return file.isFile();
+ }
+
+ public boolean isGroupOwned() {
+ throw new UnsupportedOperationException("Operation isGroupOwned() is not supported.");
+ }
+
+ public boolean isIdentical(FileStat other) {
+ throw new UnsupportedOperationException("Operation isIdentical() is not supported.");
+ }
+
+ public boolean isNamedPipe() {
+ throw new UnsupportedOperationException("Operation isNamedPipe() is not supported.");
+ }
+
+ public boolean isOwned() {
+ throw new UnsupportedOperationException("Operation isOwned() is not supported.");
+ }
+
+ public boolean isROwned() {
+ throw new UnsupportedOperationException("Operation isROwned() is not supported.");
+ }
+
+ public boolean isReadable() {
+ throw new UnsupportedOperationException("Operation isReadable() is not supported.");
+ }
+
+ public boolean isReadableReal() {
+ throw new UnsupportedOperationException("Operation isReadableReal() is not supported.");
+ }
+
+ public boolean isWritable() {
+ throw new UnsupportedOperationException("Operation isWritable() is not supported.");
+ }
+
+ public boolean isWritableReal() {
+ throw new UnsupportedOperationException("Operation isWritableReal() is not supported.");
+ }
+
+ public boolean isSetgid() {
+ throw new UnsupportedOperationException("Operation isSetgid() is not supported.");
+ }
+
+ public boolean isSetuid() {
+ throw new UnsupportedOperationException("Operation isSetuid() is not supported.");
+ }
+
+ public boolean isSocket() {
+ throw new UnsupportedOperationException("Operation isSocket() is not supported.");
+ }
+
+ public boolean isSticky() {
+ throw new UnsupportedOperationException("Operation isSticky() is not supported.");
+ }
+
+ public boolean isSymlink() {
+ throw new UnsupportedOperationException("Operation isSymlink() is not supported.");
+ }
+
+ public int major(long dev) {
+ throw new UnsupportedOperationException("Operation major() is not supported.");
+ }
+
+ public int minor(long dev) {
+ throw new UnsupportedOperationException("Operation minor() is not supported.");
+ }
+
+ public int mode() {
+ if (isDirectory()) {
+ return FileSystem.DEFAULT_DIR_MODE;
+ } else {
+ return FileSystem.DEFAULT_FILE_MODE;
+ }
+ }
+
+ public long mtime() {
+ throw new UnsupportedOperationException("Operation mtime() is not supported.");
+ }
+
+ public int nlink() {
+ throw new UnsupportedOperationException("Operation nlink() is not supported.");
+ }
+
+ public long rdev() {
+ throw new UnsupportedOperationException("Operation rdev() is not supported.");
+ }
+
+ public long st_size() {
+ throw new UnsupportedOperationException("Operation st_size() is not supported.");
+ }
+
+ public int uid() {
+ throw new UnsupportedOperationException("Operation uid() is not supported.");
+ }
+}
View
224 subprojects/native/src/main/java/org/gradle/internal/nativeplatform/filesystem/FallbackPOSIX.java
@@ -0,0 +1,224 @@
+/*
+ * Copyright 2012 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.gradle.internal.nativeplatform.filesystem;
+
+import org.jruby.ext.posix.FileStat;
+import org.jruby.ext.posix.Group;
+import org.jruby.ext.posix.POSIX;
+import org.jruby.ext.posix.Passwd;
+
+import java.io.FileDescriptor;
+import java.io.IOException;
+
+public class FallbackPOSIX implements POSIX {
+
+ public int chmod(String filename, int mode) {
+ return 0;
+ }
+
+ public int chown(String filename, int user, int group) {
+ throw new UnsupportedOperationException("This operation is not supported.");
+ }
+
+ public int fork() {
+ throw new UnsupportedOperationException("This operation is not supported.");
+ }
+
+ public FileStat fstat(FileDescriptor descriptor) {
+ throw new UnsupportedOperationException("This operation is not supported.");
+ }
+
+ public int getegid() {
+ throw new UnsupportedOperationException("This operation is not supported.");
+ }
+
+ public int geteuid() {
+ throw new UnsupportedOperationException("This operation is not supported.");
+ }
+
+ public int seteuid(int euid) {
+ throw new UnsupportedOperationException("This operation is not supported.");
+ }
+
+ public int getgid() {
+ throw new UnsupportedOperationException("This operation is not supported.");
+ }
+
+ public String getlogin() {
+ throw new UnsupportedOperationException("This operation is not supported.");
+ }
+
+ public int getpgid() {
+ throw new UnsupportedOperationException("This operation is not supported.");
+ }
+
+ public int getpgid(int pid) {
+ throw new UnsupportedOperationException("This operation is not supported.");
+ }
+
+ public int getpgrp() {
+ throw new UnsupportedOperationException("This operation is not supported.");
+ }
+
+ public int getpid() {
+ throw new UnsupportedOperationException("This operation is not supported.");
+ }
+
+ public int getppid() {
+ throw new UnsupportedOperationException("This operation is not supported.");
+ }
+
+ public int getpriority(int which, int who) {
+ throw new UnsupportedOperationException("This operation is not supported.");
+ }
+
+ public Passwd getpwent() {
+ throw new UnsupportedOperationException("This operation is not supported.");
+ }
+
+ public Passwd getpwuid(int which) {
+ throw new UnsupportedOperationException("This operation is not supported.");
+ }
+
+ public Passwd getpwnam(String which) {
+ throw new UnsupportedOperationException("This operation is not supported.");
+ }
+
+ public Group getgrgid(int which) {
+ throw new UnsupportedOperationException("This operation is not supported.");
+ }
+
+ public Group getgrnam(String which) {
+ throw new UnsupportedOperationException("This operation is not supported.");
+ }
+
+ public Group getgrent() {
+ throw new UnsupportedOperationException("This operation is not supported.");
+ }
+
+ public int endgrent() {
+ throw new UnsupportedOperationException("This operation is not supported.");
+ }
+
+ public int setgrent() {
+ throw new UnsupportedOperationException("This operation is not supported.");
+ }
+
+ public int endpwent() {
+ throw new UnsupportedOperationException("This operation is not supported.");
+ }
+
+ public int setpwent() {
+ throw new UnsupportedOperationException("This operation is not supported.");
+ }
+
+ public int getuid() {
+ throw new UnsupportedOperationException("This operation is not supported.");
+ }
+
+ public boolean isatty(FileDescriptor descriptor) {
+ throw new UnsupportedOperationException("This operation is not supported.");
+ }
+
+ public int kill(int pid, int signal) {
+ throw new UnsupportedOperationException("This operation is not supported.");
+ }
+
+ public int lchmod(String filename, int mode) {
+ throw new UnsupportedOperationException("This operation is not supported.");
+ }
+
+ public int lchown(String filename, int user, int group) {
+ throw new UnsupportedOperationException("This operation is not supported.");
+ }
+
+ public int link(String oldpath, String newpath) {
+ throw new UnsupportedOperationException("This operation is not supported.");
+ }
+
+ public FileStat lstat(String path) {
+ throw new UnsupportedOperationException("This operation is not supported.");
+ }
+
+ public int mkdir(String path, int mode) {
+ throw new UnsupportedOperationException("This operation is not supported.");
+ }
+
+ public String readlink(String path) throws IOException {
+ throw new UnsupportedOperationException("This operation is not supported.");
+ }
+
+ public int setsid() {
+ throw new UnsupportedOperationException("This operation is not supported.");
+ }
+
+ public int setgid(int gid) {
+ throw new UnsupportedOperationException("This operation is not supported.");
+ }
+
+ public int setegid(int egid) {
+ throw new UnsupportedOperationException("This operation is not supported.");
+ }
+
+ public int setpgid(int pid, int pgid) {
+ throw new UnsupportedOperationException("This operation is not supported.");
+ }
+
+ public int setpgrp(int pid, int pgrp) {
+ throw new UnsupportedOperationException("This operation is not supported.");
+ }
+
+ public int setpriority(int which, int who, int prio) {
+ throw new UnsupportedOperationException("This operation is not supported.");
+ }
+
+ public int setuid(int uid) {
+ throw new UnsupportedOperationException("This operation is not supported.");
+ }
+
+ public FileStat stat(String path) {
+ return new FallbackFileStat(path);
+ }
+
+ public int symlink(String oldpath, String newpath) {
+ return 0;
+ }
+
+ public int umask(int mask) {
+ throw new UnsupportedOperationException("This operation is not supported.");
+ }
+
+ public int utimes(String path, long[] atimeval, long[] mtimeval) {
+ throw new UnsupportedOperationException("This operation is not supported.");
+ }
+
+ public int waitpid(int pid, int[] status, int flags) {
+ throw new UnsupportedOperationException("This operation is not supported.");
+ }
+
+ public int wait(int[] status) {
+ throw new UnsupportedOperationException("This operation is not supported.");
+ }
+
+ public int errno() {
+ throw new UnsupportedOperationException("This operation is not supported.");
+ }
+
+ public void errno(int value) {
+ throw new UnsupportedOperationException("This operation is not supported.");
+ }
+}
View
16 subprojects/native/src/main/java/org/gradle/internal/nativeplatform/filesystem/PosixUtil.java
@@ -16,21 +16,29 @@
package org.gradle.internal.nativeplatform.filesystem;
-import org.jruby.ext.posix.POSIX;
-import org.jruby.ext.posix.POSIXFactory;
-import org.jruby.ext.posix.POSIXHandler;
+import org.jruby.ext.posix.*;
import java.io.File;
import java.io.InputStream;
import java.io.PrintStream;
public class PosixUtil {
- private static final POSIX POSIX = PosixWrapper.wrap(POSIXFactory.getPOSIX(new POSIXHandlerImpl(), true));
+ private static final POSIX POSIX = FallbackAwarePosixFactory.getPOSIX();
public static POSIX current() {
return POSIX;
}
+ private static class FallbackAwarePosixFactory{
+ public static POSIX getPOSIX() {
+ POSIX posix = POSIXFactory.getPOSIX(new POSIXHandlerImpl(), true);
+ if(posix instanceof JavaPOSIX || posix instanceof WindowsPOSIX){
+ return new FallbackPOSIX();
+ }
+ return posix;
+ }
+ }
+
private static class POSIXHandlerImpl implements POSIXHandler {
public void error(POSIX.ERRORS error, String message) {
throw new UnsupportedOperationException(error + " - " + message);
View
440 subprojects/native/src/main/java/org/gradle/internal/nativeplatform/filesystem/PosixWrapper.java
@@ -1,440 +0,0 @@
-/*
- * Copyright 2012 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.gradle.internal.nativeplatform.filesystem;
-
-import org.jruby.ext.posix.*;
-
-import java.io.FileDescriptor;
-import java.io.IOException;
-
-/**
- * Util class to wrap / modify results of calls to the {@link org.jruby.ext.posix.POSIXFactory#getPOSIX(org.jruby.ext.posix.POSIXHandler, boolean)}
- * */
-public class PosixWrapper {
-
- public static POSIX wrap(POSIX posix) {
- if (posix instanceof JavaPOSIX) {
- return new ChmodDisabledFallbackPOSIX(posix);
- } else if (posix instanceof WindowsPOSIX) {
- return new FilePermissionFallbackPOSIX(posix);
- } else {
- return posix;
- }
- }
-
- private static class ChmodDisabledFallbackPOSIX extends FilePermissionFallbackPOSIX {
-
- public ChmodDisabledFallbackPOSIX(POSIX posix) {
- super(posix);
- }
-
- public int chmod(String filename, int mode) {
- // short circuit this call to return incoming mode
- return mode;
- }
- }
-
- private static class FilePermissionFallbackPOSIX extends DelegatePOSIX{
- public FilePermissionFallbackPOSIX(POSIX posix) {
- super(posix);
- }
-
- public FileStat stat(String path) {
- return new FallbackFileStat(super.stat(path));
- }
- }
-
- /**
- * a Plain DelegatePosix to keep own posix implementations "clean"
- * */
- private abstract static class DelegatePOSIX implements POSIX {
- private POSIX delegate;
-
- public DelegatePOSIX(POSIX posix) {
- this.delegate = posix;
- }
-
- public int chmod(String filename, int mode) {
- return delegate.chmod(filename, mode);
- }
-
- public int chown(String filename, int user, int group) {
- return delegate.chown(filename, user, group);
- }
-
- public int fork() {
- return delegate.fork();
- }
-
- public FileStat fstat(FileDescriptor descriptor) {
- return delegate.fstat(descriptor);
- }
-
- public int getegid() {
- return delegate.getegid();
- }
-
- public int geteuid() {
- return delegate.geteuid();
- }
-
- public int seteuid(int euid) {
- return delegate.seteuid(euid);
- }
-
- public int getgid() {
- return delegate.getgid();
- }
-
- public String getlogin() {
- return delegate.getlogin();
- }
-
- public int getpgid() {
- return delegate.getpgid();
- }
-
- public int getpgid(int pid) {
- return delegate.getpgid(pid);
- }
-
- public int getpgrp() {
- return delegate.getpgrp();
- }
-
- public int getpid() {
- return delegate.getpid();
- }
-
- public int getppid() {
- return delegate.getppid();
- }
-
- public int getpriority(int which, int who) {
- return delegate.getpriority(which, who);
- }
-
- public Passwd getpwent() {
- return delegate.getpwent();
- }
-
- public Passwd getpwuid(int which) {
- return delegate.getpwuid(which);
- }
-
- public Passwd getpwnam(String which) {
- return delegate.getpwnam(which);
- }
-
- public Group getgrgid(int which) {
- return delegate.getgrgid(which);
- }
-
- public Group getgrnam(String which) {
- return delegate.getgrnam(which);
- }
-
- public Group getgrent() {
- return delegate.getgrent();
- }
-
- public int endgrent() {
- return delegate.endgrent();
- }
-
- public int setgrent() {
- return delegate.setgrent();
- }
-
- public int endpwent() {
- return delegate.endpwent();
- }
-
- public int setpwent() {
- return delegate.setpwent();
- }
-
- public int getuid() {
- return delegate.getuid();
- }
-
- public boolean isatty(FileDescriptor descriptor) {
- return delegate.isatty(descriptor);
- }
-
- public int kill(int pid, int signal) {
- return delegate.kill(pid, signal);
- }
-
- public int lchmod(String filename, int mode) {
- return delegate.lchmod(filename, mode);
- }
-
- public int lchown(String filename, int user, int group) {
- return delegate.lchown(filename, user, group);
- }
-
- public int link(String oldpath, String newpath) {
- return delegate.link(oldpath, newpath);
- }
-
- public FileStat lstat(String path) {
- return delegate.lstat(path);
- }
-
- public int mkdir(String path, int mode) {
- return delegate.mkdir(path, mode);
- }
-
- public String readlink(String path) throws IOException {
- return delegate.readlink(path);
- }
-
- public int setsid() {
- return delegate.setsid();
- }
-
- public int setgid(int gid) {
- return delegate.setgid(gid);
- }
-
- public int setegid(int egid) {
- return delegate.setegid(egid);
- }
-
- public int setpgid(int pid, int pgid) {
- return delegate.setpgid(pid, pgid);
- }
-
- public int setpgrp(int pid, int pgrp) {
- return delegate.setpgrp(pid, pgrp);
- }
-
- public int setpriority(int which, int who, int prio) {
- return delegate.setpriority(which, who, prio);
- }
-
- public int setuid(int uid) {
- return delegate.setuid(uid);
- }
-
- public FileStat stat(String path) {
- return new FallbackFileStat(delegate.stat(path));
- }
-
- public int symlink(String oldpath, String newpath) {
- return delegate.symlink(oldpath, newpath);
- }
-
- public int umask(int mask) {
- return delegate.umask(mask);
- }
-
- public int utimes(String path, long[] atimeval, long[] mtimeval) {
- return delegate.utimes(path, atimeval, mtimeval);
- }
-
- public int waitpid(int pid, int[] status, int flags) {
- return delegate.waitpid(pid, status, flags);
- }
-
- public int wait(int[] status) {
- return delegate.wait(status);
- }
-
- public int errno() {
- return delegate.errno();
- }
-
- public void errno(int value) {
- delegate.errno(value);
- }
- }
-
- /**
- * Calls to {@link #mode()} return 664 for files and 755 for directories.
- * Other method calls are delegated to delegate FileStat.
- * */
- private static class FallbackFileStat implements FileStat {
-
- private FileStat delegate;
-
- public FallbackFileStat(FileStat stat) {
- this.delegate = stat;
- }
-
- public long atime() {
- return delegate.atime();
- }
-
- public long blocks() {
- return delegate.blocks();
- }
-
- public long blockSize() {
- return delegate.blockSize();
- }
-
- public long ctime() {
- return delegate.ctime();
- }
-
- public long dev() {
- return delegate.dev();
- }
-
- public String ftype() {
- return delegate.ftype();
- }
-
- public int gid() {
- return delegate.gid();
- }
-
- public boolean groupMember(int gid) {
- return delegate.groupMember(gid);
- }
-
- public long ino() {
- return delegate.ino();
- }
-
- public boolean isBlockDev() {
- return delegate.isBlockDev();
- }
-
- public boolean isCharDev() {
- return delegate.isCharDev();
- }
-
- public boolean isDirectory() {
- return delegate.isDirectory();
- }
-
- public boolean isEmpty() {
- return delegate.isEmpty();
- }
-
- public boolean isExecutable() {
- return delegate.isExecutable();
- }
-
- public boolean isExecutableReal() {
- return delegate.isExecutableReal();
- }
-
- public boolean isFifo() {
- return delegate.isFifo();
- }
-
- public boolean isFile() {
- return delegate.isFile();
- }
-
- public boolean isGroupOwned() {
- return delegate.isGroupOwned();
- }
-
- public boolean isIdentical(FileStat other) {
- return delegate.isIdentical(other);
- }
-
- public boolean isNamedPipe() {
- return delegate.isNamedPipe();
- }
-
- public boolean isOwned() {
- return delegate.isOwned();
- }
-
- public boolean isROwned() {
- return delegate.isROwned();
- }
-
- public boolean isReadable() {
- return delegate.isReadable();
- }
-
- public boolean isReadableReal() {
- return delegate.isReadableReal();
- }
-
- public boolean isWritable() {
- return delegate.isWritable();
- }
-
- public boolean isWritableReal() {
- return delegate.isWritableReal();
- }
-
- public boolean isSetgid() {
- return delegate.isSetgid();
- }
-
- public boolean isSetuid() {
- return delegate.isSetuid();
- }
-
- public boolean isSocket() {
- return delegate.isSocket();
- }
-
- public boolean isSticky() {
- return delegate.isSticky();
- }
-
- public boolean isSymlink() {
- return delegate.isSymlink();
- }
-
- public int major(long dev) {
- return delegate.major(dev);
- }
-
- public int minor(long dev) {
- return delegate.minor(dev);
- }
-
- public int mode() {
- if(isDirectory()){
- return FileSystem.DEFAULT_DIR_MODE;
- }else{
- return FileSystem.DEFAULT_FILE_MODE;
- }
- }
-
- public long mtime() {
- return delegate.mtime();
- }
-
- public int nlink() {
- return delegate.nlink();
- }
-
- public long rdev() {
- return delegate.rdev();
- }
-
- public long st_size() {
- return delegate.st_size();
- }
-
- public int uid() {
- return delegate.uid();
- }
- }
-}
View
103 subprojects/native/src/test/groovy/org/gradle/internal/nativeplatform/PosixWrapperTest.groovy
@@ -1,103 +0,0 @@
-/*
- * Copyright 2012 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.gradle.internal.nativeplatform
-
-import org.gradle.internal.nativeplatform.filesystem.FileSystem
-import spock.lang.Specification
-import org.jruby.ext.posix.*
-
-class PosixWrapperTest extends Specification {
-
- def void "wraps JavaPOSIX to ChmodDisabledFallbackPOSIX"() {
- JavaPOSIX posix = Mock()
- when:
- def wrappedPosix = PosixWrapper.wrap(posix)
- then:
- wrappedPosix instanceof PosixWrapper.ChmodDisabledFallbackPOSIX
- }
-
- def void "wraps WindowsPOSIX to FilePermissionFallbackPOSIX"() {
- WindowsPOSIX posix = Mock()
- when:
- def wrappedPosix = PosixWrapper.wrap(posix)
- then:
- wrappedPosix instanceof PosixWrapper.FilePermissionFallbackPOSIX
- }
-
- def void "returns input object for other than JavaPOSIX implementations"() {
- when:
- def originPosix = Mock(SolarisPOSIX)
- def posix = PosixWrapper.wrap(originPosix)
- then:
- originPosix == posix
-
- when:
- originPosix = Mock(BaseNativePOSIX)
- posix = PosixWrapper.wrap(originPosix)
- then:
- originPosix == posix
- }
-
- def "FilePermissionFallbackPOSIX does not delegate chmod calls"() {
- setup:
- POSIX delegatePosix = Mock()
- def posix = new PosixWrapper.ChmodDisabledFallbackPOSIX(delegatePosix)
- when:
- posix.chmod("filepath", 755)
- then:
- 0 * delegatePosix.chmod(_, _)
- }
-
- def "ChmodDisabledFallbackPOSIX wraps filestat chmod calls"() {
- setup:
- POSIX delegatePosix = Mock()
- def posix = new PosixWrapper.ChmodDisabledFallbackPOSIX(delegatePosix)
-
- when:
- def fileStat = posix.stat("filepath")
-
- then:
- fileStat instanceof PosixWrapper.FallbackFileStat
-
- }
-
- def "FallbackFileStat mode() returns 755 for directories"() {
- setup:
- FileStat delegate = Mock()
- PosixWrapper.FallbackFileStat filestat = new PosixWrapper.FallbackFileStat(delegate);
- delegate.isDirectory() >> true
-
- when:
- def mode = filestat.mode();
-
- then:
- mode == FileSystem.DEFAULT_DIR_MODE
- }
-
- def "FallbackFileStat mode() returns 644 for non directories"() {
- setup:
- FileStat delegate = Mock()
- PosixWrapper.FallbackFileStat filestat = new PosixWrapper.FallbackFileStat(delegate);
- delegate.isDirectory() >> false
-
- when:
- def mode = filestat.mode();
-
- then:
- mode == FileSystem.DEFAULT_FILE_MODE
- }
-}
View
42 ...rojects/native/src/test/groovy/org/gradle/internal/nativeplatform/filesystem/FallbackFileStatTest.groovy
@@ -0,0 +1,42 @@
+/*
+ * Copyright 2012 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.gradle.internal.nativeplatform.filesystem
+
+import spock.lang.Specification
+import org.junit.Rule
+import org.junit.rules.TemporaryFolder
+
+class FallbackFileStatTest extends Specification {
+
+ @Rule TemporaryFolder temporaryFolder;
+
+ def "mode() returns FileSystem.DEFAULT_FILE_MODE for files"() {
+ setup:
+ def testfile = temporaryFolder.newFile()
+ FallbackFileStat fallbackFileStat = new FallbackFileStat(testfile.absolutePath)
+ expect:
+ FileSystem.DEFAULT_FILE_MODE == fallbackFileStat.mode()
+ }
+
+ def "mode() returns FileSystem.DEFAULT_DIR_MODE for directories"() {
+ setup:
+ def testfolder = temporaryFolder.newFolder()
+ FallbackFileStat fallbackFileStat = new FallbackFileStat(testfolder.absolutePath)
+ expect:
+ FileSystem.DEFAULT_DIR_MODE == fallbackFileStat.mode()
+ }
+}
View
51 subprojects/native/src/test/groovy/org/gradle/internal/nativeplatform/filesystem/FallbackPOSIXTest.groovy
@@ -0,0 +1,51 @@
+/*
+ * Copyright 2012 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.gradle.internal.nativeplatform.filesystem
+
+import org.junit.Rule
+import org.junit.rules.TemporaryFolder
+import spock.lang.Specification
+
+class FallbackPOSIXTest extends Specification {
+
+ FallbackPOSIX posix = new FallbackPOSIX()
+
+ @Rule TemporaryFolder tempFolder;
+
+ def "returns 0 on chmod calls"() {
+ setup:
+ def testFile = tempFolder.newFile();
+ expect:
+ 0 == posix.chmod(testFile.absolutePath, mode)
+ where:
+ mode << [644, 755, 777];
+ }
+
+ def "stat() returns instance of FallbackStat"() {
+ setup:
+ def testFile = tempFolder.newFile();
+ when:
+ def stat = posix.stat(testFile.absolutePath)
+ then:
+ stat instanceof FallbackFileStat
+ }
+
+ def "returns 0 for symlink calls"() {
+ expect:
+ 0 == posix.symlink("/old/path", "new/path")
+ }
+}
View
42 subprojects/native/src/test/groovy/org/gradle/internal/nativeplatform/filesystem/PosixUtilTest.groovy
@@ -0,0 +1,42 @@
+/*
+ * Copyright 2012 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.gradle.internal.nativeplatform.filesystem
+
+import spock.lang.Specification
+import org.gradle.util.Requires
+import org.gradle.util.TestPrecondition;
+
+public class PosixUtilTest extends Specification{
+
+ @Requires(TestPrecondition.UNKNOWN_OS)
+ def "PosixUtil.current returns FallbackPOSIX on Unknown OS"(){
+ expect:
+ PosixUtil.current() instanceof FallbackPOSIX
+ }
+
+ @Requires(TestPrecondition.WINDOWS)
+ def "PosixUtil.current returns FallbackPOSIX on WindowsOS"(){
+ expect:
+ PosixUtil.current() instanceof FallbackPOSIX
+ }
+
+ @Requires(TestPrecondition.FILE_PERMISSIONS)
+ def "PosixUtil.current returns no FallbackPOSIX on Macosx and Unix"(){
+ expect:
+ !(PosixUtil.current() instanceof FallbackPOSIX)
+ }
+}
View
102 subprojects/native/src/test/groovy/org/gradle/internal/nativeplatform/filesystem/PosixWrapperTest.groovy
@@ -1,102 +0,0 @@
-/*
- * Copyright 2012 the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.gradle.internal.nativeplatform.filesystem
-
-import spock.lang.Specification
-import org.jruby.ext.posix.*
-
-class PosixWrapperTest extends Specification {
-
- def void "wraps JavaPOSIX to ChmodDisabledFallbackPOSIX"() {
- JavaPOSIX posix = Mock()
- when:
- def wrappedPosix = PosixWrapper.wrap(posix)
- then:
- wrappedPosix instanceof PosixWrapper.ChmodDisabledFallbackPOSIX
- }
-
- def void "wraps WindowsPOSIX to FilePermissionFallbackPOSIX"() {
- WindowsPOSIX posix = Mock()
- when:
- def wrappedPosix = PosixWrapper.wrap(posix)
- then:
- wrappedPosix instanceof PosixWrapper.FilePermissionFallbackPOSIX
- }
-
- def void "returns input object for other than JavaPOSIX implementations"() {
- when:
- def originPosix = Mock(SolarisPOSIX)
- def posix = PosixWrapper.wrap(originPosix)
- then:
- originPosix == posix
-
- when:
- originPosix = Mock(BaseNativePOSIX)
- posix = PosixWrapper.wrap(originPosix)
- then:
- originPosix == posix
- }
-
- def "FilePermissionFallbackPOSIX does not delegate chmod calls"() {
- setup:
- POSIX delegatePosix = Mock()
- def posix = new PosixWrapper.ChmodDisabledFallbackPOSIX(delegatePosix)
- when:
- posix.chmod("filepath", 755)
- then:
- 0 * delegatePosix.chmod(_, _)
- }
-
- def "ChmodDisabledFallbackPOSIX wraps filestat chmod calls"() {
- setup:
- POSIX delegatePosix = Mock()
- def posix = new PosixWrapper.ChmodDisabledFallbackPOSIX(delegatePosix)
-
- when:
- def fileStat = posix.stat("filepath")
-
- then:
- fileStat instanceof PosixWrapper.FallbackFileStat
-
- }
-
- def "FallbackFileStat mode() returns 755 for directories"() {
- setup:
- FileStat delegate = Mock()
- PosixWrapper.FallbackFileStat filestat = new PosixWrapper.FallbackFileStat(delegate);
- delegate.isDirectory() >> true
-
- when:
- def mode = filestat.mode();
-
- then:
- mode == FileSystem.DEFAULT_DIR_MODE
- }
-
- def "FallbackFileStat mode() returns 644 for non directories"() {
- setup:
- FileStat delegate = Mock()
- PosixWrapper.FallbackFileStat filestat = new PosixWrapper.FallbackFileStat(delegate);
- delegate.isDirectory() >> false
-
- when:
- def mode = filestat.mode();
-
- then:
- mode == FileSystem.DEFAULT_FILE_MODE
- }
-}
Please sign in to comment.
Something went wrong with that request. Please try again.