Top Description Inners Constructors Methods
org.apache.tools.ant.util

public Class PermissionUtils

extends Object
Class Inheritance
Imports
java.io.IOException, java.nio.file.Files, .Path, java.nio.file.attribute.BasicFileAttributes, .PosixFileAttributeView, .PosixFilePermission, java.util.EnumSet, .Set, java.util.function.Consumer, .Function, org.apache.tools.ant.types.Resource, org.apache.tools.ant.types.resources.ArchiveResource, .FileProvider

Contains helper methods for dealing with PosixFilePermission or the traditional Unix mode representation of permissions.
Since
Ant 1.10.0

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static enum
PermissionUtils.FileType

The supported types of files, maps to the isFoo methods in java.nio.file.attribute.BasicFileAttributes.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
private static void
addPermissions(Set<PosixFilePermission> permissions, String prefix, long mode)

public static Set<PosixFilePermission>

Returns:

the permissions
getPermissions
(Resource
the resource to read permissions from
r
,
Function<Path, Set<PosixFilePermission>>
optional fallback function to provide permissions for file system that don't support PosixFilePermissions. The Path corresponding to the file is passed to the callback.
posixNotSupportedFallback
)

Sets permissions of a Resource - returns an empty set for unsupported resource types or file systems that don't support PosixFilePermissions and no fallback has been provided..

public static int

Returns:

the "mode"
modeFromPermissions
(Set<PosixFilePermission>
the permissions
permissions
,
PermissionUtils.FileType
the file type
type
)

Translates a set of permissions into a Unix stat(2) st_mode result.

private static long
public static Set<PosixFilePermission>

Returns:

set of permissions
permissionsFromMode
(int
the "mode"
mode
)

Translates a Unix stat(2) st_mode compatible value into a set of permissions.

public static void
setPermissions(Resource
the resource to set permissions for
r
,
Set<PosixFilePermission>
the permissions
permissions
,
Consumer<Path>
optional callback that is invoked for a file provider resource if the file-system holding the file doesn't support PosixFilePermissions. The Path corresponding to the file is passed to the callback.
posixNotSupportedCallback
)

Sets permissions on a Resource - doesn't do anything for unsupported resource types.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

PermissionUtilsback to summary
private PermissionUtils()

Method Detail

addPermissionsback to summary
private static void addPermissions(Set<PosixFilePermission> permissions, String prefix, long mode)
getPermissionsback to summary
public static Set<PosixFilePermission> getPermissions(Resource r, Function<Path, Set<PosixFilePermission>> posixNotSupportedFallback) throws IOException

Sets permissions of a Resource - returns an empty set for unsupported resource types or file systems that don't support PosixFilePermissions and no fallback has been provided..

Supported types are:

Parameters
r:Resource

the resource to read permissions from

posixNotSupportedFallback:Function<Path, Set<PosixFilePermission>>

optional fallback function to provide permissions for file system that don't support PosixFilePermissions. The Path corresponding to the file is passed to the callback.

Returns:Set<PosixFilePermission>

the permissions

Exceptions
IOException:
if something goes wrong
modeFromPermissionsback to summary
public static int modeFromPermissions(Set<PosixFilePermission> permissions, PermissionUtils.FileType type)

Translates a set of permissions into a Unix stat(2) st_mode result.

Parameters
permissions:Set<PosixFilePermission>

the permissions

type:PermissionUtils.FileType

the file type

Returns:int

the "mode"

modeFromPermissionsback to summary
private static long modeFromPermissions(Set<PosixFilePermission> permissions, String prefix)
permissionsFromModeback to summary
public static Set<PosixFilePermission> permissionsFromMode(int mode)

Translates a Unix stat(2) st_mode compatible value into a set of permissions.

Parameters
mode:int

the "mode"

Returns:Set<PosixFilePermission>

set of permissions

setPermissionsback to summary
public static void setPermissions(Resource r, Set<PosixFilePermission> permissions, Consumer<Path> posixNotSupportedCallback) throws IOException

Sets permissions on a Resource - doesn't do anything for unsupported resource types.

Supported types are:

Parameters
r:Resource

the resource to set permissions for

permissions:Set<PosixFilePermission>

the permissions

posixNotSupportedCallback:Consumer<Path>

optional callback that is invoked for a file provider resource if the file-system holding the file doesn't support PosixFilePermissions. The Path corresponding to the file is passed to the callback.

Exceptions
IOException:
if something goes wrong
org.apache.tools.ant.util back to summary

public final Enum PermissionUtils.FileType

extends Enum<PermissionUtils.FileType>
Class Inheritance

The supported types of files, maps to the isFoo methods in java.nio.file.attribute.BasicFileAttributes.

Field Summary

Modifier and TypeField and Description
public static final PermissionUtils.FileType
DIR

A directory.

public static final PermissionUtils.FileType
OTHER

Something that is neither a regular file nor a directory nor a symbolic link.

public static final PermissionUtils.FileType
REGULAR_FILE

A regular file.

public static final PermissionUtils.FileType
SYMLINK

A symbolic link.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static PermissionUtils.FileType

Returns:

FileType
of
(Path
Path
p
)

Determines the file type of a Path.

public static PermissionUtils.FileType

Returns:

FileType
of
(Resource
Resource
r
)

Determines the file type of a Resource.

public static PermissionUtils.FileType
public static PermissionUtils.FileType[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

DIRback to summary
public static final PermissionUtils.FileType DIR

A directory.

OTHERback to summary
public static final PermissionUtils.FileType OTHER

Something that is neither a regular file nor a directory nor a symbolic link.

REGULAR_FILEback to summary
public static final PermissionUtils.FileType REGULAR_FILE

A regular file.

Constructor Detail

FileTypeback to summary
private FileType()

Method Detail

ofback to summary
public static PermissionUtils.FileType of(Path p) throws IOException

Determines the file type of a Path.

Parameters
p:Path

Path

Returns:PermissionUtils.FileType

FileType

Exceptions
IOException:
if file attributes cannot be read
ofback to summary
public static PermissionUtils.FileType of(Resource r)

Determines the file type of a Resource.

Parameters
r:Resource

Resource

Returns:PermissionUtils.FileType

FileType

valueOfback to summary
public static PermissionUtils.FileType valueOf(String name)
valuesback to summary
public static PermissionUtils.FileType[] values()