Skip to content

Commit 55773f5

Browse files
committed
Reformat to a common code style
1 parent 88cda20 commit 55773f5

File tree

45 files changed

+617
-505
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+617
-505
lines changed

src/main/java/org/codehaus/plexus/components/io/attributes/AttributeUtils.java

+7-6
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public static void chmod( @Nonnull File file, int mode )
6666
public static Set<PosixFilePermission> getPermissions( int mode )
6767
{
6868
Set<PosixFilePermission> perms = new HashSet<>();
69-
//add owners permission
69+
// add owners permission
7070
if ( ( mode & 0400 ) > 0 )
7171
{
7272
perms.add( PosixFilePermission.OWNER_READ );
@@ -79,7 +79,7 @@ public static Set<PosixFilePermission> getPermissions( int mode )
7979
{
8080
perms.add( PosixFilePermission.OWNER_EXECUTE );
8181
}
82-
//add group permissions
82+
// add group permissions
8383
if ( ( mode & 0040 ) > 0 )
8484
{
8585
perms.add( PosixFilePermission.GROUP_READ );
@@ -92,7 +92,7 @@ public static Set<PosixFilePermission> getPermissions( int mode )
9292
{
9393
perms.add( PosixFilePermission.GROUP_EXECUTE );
9494
}
95-
//add others permissions
95+
// add others permissions
9696
if ( ( mode & 0004 ) > 0 )
9797
{
9898
perms.add( PosixFilePermission.OTHERS_READ );
@@ -125,7 +125,7 @@ public static BasicFileAttributes getFileAttributes( @Nonnull File file )
125125
public static BasicFileAttributes getFileAttributes( Path path )
126126
throws IOException
127127
{
128-
if (isUnix(path))
128+
if ( isUnix( path ) )
129129
{
130130

131131
try
@@ -140,8 +140,9 @@ public static BasicFileAttributes getFileAttributes( Path path )
140140
return Files.readAttributes( path, BasicFileAttributes.class, LinkOption.NOFOLLOW_LINKS );
141141
}
142142

143-
public static boolean isUnix(Path path) {
144-
return path.getFileSystem().supportedFileAttributeViews().contains("unix");
143+
public static boolean isUnix( Path path )
144+
{
145+
return path.getFileSystem().supportedFileAttributeViews().contains( "unix" );
145146
}
146147

147148
@Nullable

src/main/java/org/codehaus/plexus/components/io/attributes/FileAttributes.java

+128-88
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@
3737
* Immutable
3838
*/
3939
public class FileAttributes
40-
implements PlexusIoResourceAttributes {
40+
implements PlexusIoResourceAttributes
41+
{
4142
@Nullable
4243
private final Integer groupId;
4344

@@ -55,197 +56,236 @@ public class FileAttributes
5556

5657
private final Set<PosixFilePermission> permissions;
5758

58-
public FileAttributes(@Nonnull File file, @Nonnull Map<Integer, String> userCache,
59-
@Nonnull Map<Integer, String> groupCache)
60-
throws IOException {
61-
59+
public FileAttributes( @Nonnull File file, @Nonnull Map<Integer, String> userCache,
60+
@Nonnull Map<Integer, String> groupCache )
61+
throws IOException
62+
{
6263

6364
Path path = file.toPath();
64-
if (AttributeUtils.isUnix(path)) {
65-
Map<String, Object> attrs = Files.readAttributes(path, "unix:*", LinkOption.NOFOLLOW_LINKS);
66-
this.permissions = (Set<PosixFilePermission>) attrs.get("permissions");
65+
if ( AttributeUtils.isUnix( path ) )
66+
{
67+
Map<String, Object> attrs = Files.readAttributes( path, "unix:*", LinkOption.NOFOLLOW_LINKS );
68+
this.permissions = (Set<PosixFilePermission>) attrs.get( "permissions" );
6769

68-
groupId = (Integer) attrs.get("gid");
70+
groupId = (Integer) attrs.get( "gid" );
6971

70-
String groupName = groupCache.get(groupId);
71-
if (groupName != null) {
72+
String groupName = groupCache.get( groupId );
73+
if ( groupName != null )
74+
{
7275
this.groupName = groupName;
73-
} else {
74-
this.groupName = ((Principal) attrs.get("group")).getName();
75-
groupCache.put(groupId, this.groupName);
7676
}
77-
userId = (Integer) attrs.get("uid");
78-
String userName = userCache.get(userId);
79-
if (userName != null) {
77+
else
78+
{
79+
this.groupName = ( (Principal) attrs.get( "group" ) ).getName();
80+
groupCache.put( groupId, this.groupName );
81+
}
82+
userId = (Integer) attrs.get( "uid" );
83+
String userName = userCache.get( userId );
84+
if ( userName != null )
85+
{
8086
this.userName = userName;
81-
} else {
82-
this.userName = ((Principal) attrs.get("owner")).getName();
83-
userCache.put(userId, this.userName);
8487
}
85-
octalMode = (Integer) attrs.get("mode") & 0xfff; // Mask off top bits for compatibilty. Maybe check if we can skip this
86-
symbolicLink = (Boolean) attrs.get("isSymbolicLink");
87-
} else {
88-
FileOwnerAttributeView fa = AttributeUtils.getFileOwnershipInfo(file);
88+
else
89+
{
90+
this.userName = ( (Principal) attrs.get( "owner" ) ).getName();
91+
userCache.put( userId, this.userName );
92+
}
93+
octalMode = (Integer) attrs.get( "mode" ) & 0xfff; // Mask off top bits for compatibilty. Maybe check if we
94+
// can skip this
95+
symbolicLink = (Boolean) attrs.get( "isSymbolicLink" );
96+
}
97+
else
98+
{
99+
FileOwnerAttributeView fa = AttributeUtils.getFileOwnershipInfo( file );
89100
this.userName = fa.getOwner().getName();
90101
userId = null;
91102
this.groupName = null;
92103
this.groupId = null;
93104
octalMode = PlexusIoResourceAttributes.UNKNOWN_OCTAL_MODE;
94105
permissions = Collections.emptySet();
95-
symbolicLink = Files.isSymbolicLink(path);
106+
symbolicLink = Files.isSymbolicLink( path );
96107
}
97108

98109
}
99110

100-
public static
101-
@Nonnull
102-
PlexusIoResourceAttributes uncached(@Nonnull File file)
103-
throws IOException {
104-
return new FileAttributes(file, new HashMap<Integer, String>(), new HashMap<Integer, String>());
111+
public static @Nonnull
112+
PlexusIoResourceAttributes uncached( @Nonnull File file )
113+
throws IOException
114+
{
115+
return new FileAttributes( file, new HashMap<Integer, String>(), new HashMap<Integer, String>() );
105116
}
106117

107-
108118
@Nullable
109-
public Integer getGroupId() {
119+
public Integer getGroupId()
120+
{
110121

111122
return groupId;
112123
}
113124

114-
public boolean hasGroupId() {
125+
public boolean hasGroupId()
126+
{
115127
return false;
116128
}
117129

118-
public boolean hasUserId() {
130+
public boolean hasUserId()
131+
{
119132
return false;
120133
}
121134

122135
@Nullable
123-
public String getGroupName() {
136+
public String getGroupName()
137+
{
124138
return groupName;
125139
}
126140

127-
public Integer getUserId() {
141+
public Integer getUserId()
142+
{
128143
return userId;
129144
}
130145

131-
public String getUserName() {
146+
public String getUserName()
147+
{
132148
return userName;
133149
}
134150

135-
public boolean isGroupExecutable() {
136-
return containsPermission(PosixFilePermission.GROUP_EXECUTE);
151+
public boolean isGroupExecutable()
152+
{
153+
return containsPermission( PosixFilePermission.GROUP_EXECUTE );
137154
}
138155

139-
private boolean containsPermission(PosixFilePermission groupExecute) {
140-
return permissions.contains(groupExecute);
156+
private boolean containsPermission( PosixFilePermission groupExecute )
157+
{
158+
return permissions.contains( groupExecute );
141159
}
142160

143-
public boolean isGroupReadable() {
144-
return containsPermission(PosixFilePermission.GROUP_READ);
161+
public boolean isGroupReadable()
162+
{
163+
return containsPermission( PosixFilePermission.GROUP_READ );
145164
}
146165

147-
public boolean isGroupWritable() {
148-
return containsPermission(PosixFilePermission.GROUP_WRITE);
166+
public boolean isGroupWritable()
167+
{
168+
return containsPermission( PosixFilePermission.GROUP_WRITE );
149169
}
150170

151-
public boolean isOwnerExecutable() {
152-
return containsPermission(PosixFilePermission.OWNER_EXECUTE);
171+
public boolean isOwnerExecutable()
172+
{
173+
return containsPermission( PosixFilePermission.OWNER_EXECUTE );
153174
}
154175

155-
public boolean isOwnerReadable() {
156-
return containsPermission(PosixFilePermission.OWNER_READ);
176+
public boolean isOwnerReadable()
177+
{
178+
return containsPermission( PosixFilePermission.OWNER_READ );
157179
}
158180

159-
public boolean isOwnerWritable() {
160-
return containsPermission(PosixFilePermission.OWNER_WRITE);
181+
public boolean isOwnerWritable()
182+
{
183+
return containsPermission( PosixFilePermission.OWNER_WRITE );
161184
}
162185

163-
public boolean isWorldExecutable() {
164-
return containsPermission(PosixFilePermission.OTHERS_EXECUTE);
186+
public boolean isWorldExecutable()
187+
{
188+
return containsPermission( PosixFilePermission.OTHERS_EXECUTE );
165189

166190
}
167191

168-
public boolean isWorldReadable() {
169-
return containsPermission(PosixFilePermission.OTHERS_READ);
192+
public boolean isWorldReadable()
193+
{
194+
return containsPermission( PosixFilePermission.OTHERS_READ );
170195
}
171196

172-
public boolean isWorldWritable() {
173-
return containsPermission(PosixFilePermission.OTHERS_WRITE);
197+
public boolean isWorldWritable()
198+
{
199+
return containsPermission( PosixFilePermission.OTHERS_WRITE );
174200
}
175201

176-
public String toString() {
202+
public String toString()
203+
{
177204
StringBuilder sb = new StringBuilder();
178-
sb.append(System.lineSeparator());
179-
sb.append("File Attributes:");
180-
sb.append(System.lineSeparator());
181-
sb.append("------------------------------");
182-
sb.append(System.lineSeparator());
183-
sb.append("user: ");
184-
sb.append(userName == null ? "" : userName);
185-
sb.append(System.lineSeparator());
186-
sb.append("group: ");
187-
sb.append(groupName == null ? "" : groupName);
188-
sb.append(System.lineSeparator());
189-
sb.append("uid: ");
190-
sb.append(hasUserId() ? Integer.toString(userId) : "");
191-
sb.append(System.lineSeparator());
192-
sb.append("gid: ");
193-
sb.append(hasGroupId() ? Integer.toString(groupId) : "");
205+
sb.append( System.lineSeparator() );
206+
sb.append( "File Attributes:" );
207+
sb.append( System.lineSeparator() );
208+
sb.append( "------------------------------" );
209+
sb.append( System.lineSeparator() );
210+
sb.append( "user: " );
211+
sb.append( userName == null ? "" : userName );
212+
sb.append( System.lineSeparator() );
213+
sb.append( "group: " );
214+
sb.append( groupName == null ? "" : groupName );
215+
sb.append( System.lineSeparator() );
216+
sb.append( "uid: " );
217+
sb.append( hasUserId() ? Integer.toString( userId ) : "" );
218+
sb.append( System.lineSeparator() );
219+
sb.append( "gid: " );
220+
sb.append( hasGroupId() ? Integer.toString( groupId ) : "" );
194221

195222
return sb.toString();
196223
}
197224

198-
public int getOctalMode() {
225+
public int getOctalMode()
226+
{
199227
return octalMode;
200228
}
201229

202-
public int calculatePosixOctalMode() {
230+
public int calculatePosixOctalMode()
231+
{
203232
int result = 0;
204233

205-
if (isOwnerReadable()) {
234+
if ( isOwnerReadable() )
235+
{
206236
result |= AttributeConstants.OCTAL_OWNER_READ;
207237
}
208238

209-
if (isOwnerWritable()) {
239+
if ( isOwnerWritable() )
240+
{
210241
result |= AttributeConstants.OCTAL_OWNER_WRITE;
211242
}
212243

213-
if (isOwnerExecutable()) {
244+
if ( isOwnerExecutable() )
245+
{
214246
result |= AttributeConstants.OCTAL_OWNER_EXECUTE;
215247
}
216248

217-
if (isGroupReadable()) {
249+
if ( isGroupReadable() )
250+
{
218251
result |= AttributeConstants.OCTAL_GROUP_READ;
219252
}
220253

221-
if (isGroupWritable()) {
254+
if ( isGroupWritable() )
255+
{
222256
result |= AttributeConstants.OCTAL_GROUP_WRITE;
223257
}
224258

225-
if (isGroupExecutable()) {
259+
if ( isGroupExecutable() )
260+
{
226261
result |= AttributeConstants.OCTAL_GROUP_EXECUTE;
227262
}
228263

229-
if (isWorldReadable()) {
264+
if ( isWorldReadable() )
265+
{
230266
result |= AttributeConstants.OCTAL_WORLD_READ;
231267
}
232268

233-
if (isWorldWritable()) {
269+
if ( isWorldWritable() )
270+
{
234271
result |= AttributeConstants.OCTAL_WORLD_WRITE;
235272
}
236273

237-
if (isWorldExecutable()) {
274+
if ( isWorldExecutable() )
275+
{
238276
result |= AttributeConstants.OCTAL_WORLD_EXECUTE;
239277
}
240278

241279
return result;
242280
}
243281

244-
public String getOctalModeString() {
245-
return Integer.toString(getOctalMode(), 8);
282+
public String getOctalModeString()
283+
{
284+
return Integer.toString( getOctalMode(), 8 );
246285
}
247286

248-
public boolean isSymbolicLink() {
287+
public boolean isSymbolicLink()
288+
{
249289
return symbolicLink;
250290
}
251291
}

0 commit comments

Comments
 (0)