Skip to content

Commit f4f7aa1

Browse files
committed
Code cleanup
1 parent d3fbfc6 commit f4f7aa1

30 files changed

+89
-115
lines changed

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

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
* limitations under the License.
1717
*/
1818

19+
@SuppressWarnings("OctalInteger")
1920
public final class AttributeConstants {
2021

2122
public static final int OCTAL_OWNER_READ = 0400;

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
/**
3434
* @author Kristian Rosenvold
3535
*/
36+
@SuppressWarnings("OctalInteger")
3637
public class AttributeUtils {
3738
/*
3839
Reads last-modified with proper failure handling if something goes wrong.
@@ -101,7 +102,6 @@ public static BasicFileAttributes getFileAttributes(@Nonnull File file) throws I
101102

102103
public static BasicFileAttributes getFileAttributes(Path path) throws IOException {
103104
if (isUnix(path)) {
104-
105105
try {
106106
return Files.readAttributes(path, PosixFileAttributes.class, LinkOption.NOFOLLOW_LINKS);
107107
} catch (UnsupportedOperationException ignore) {

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,10 @@ public FileAttributes(@Nonnull File file, boolean followLinks) throws IOExceptio
112112
this.octalMode = attrs.containsKey("mode")
113113
? (Integer) attrs.get("mode") & 0xfff
114114
: PlexusIoResourceAttributes.UNKNOWN_OCTAL_MODE;
115+
//noinspection unchecked
115116
this.permissions = attrs.containsKey("permissions")
116117
? (Set<PosixFilePermission>) attrs.get("permissions")
117-
: Collections.<PosixFilePermission>emptySet();
118+
: Collections.emptySet();
118119
this.size = (Long) attrs.get("size");
119120
this.lastModifiedTime = (FileTime) attrs.get("lastModifiedTime");
120121
}

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

-3
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,6 @@ public interface PlexusIoResourceAttributes {
7272
*/
7373
int getOctalMode();
7474

75-
// @Nonnull
76-
// String getOctalModeString();
77-
7875
/**
7976
* Indicates if this is a symbolic link element.
8077
* For file-based resource attributes this value may be always "false" for versions prior to java7.

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

+2-3
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,13 @@ public class SymlinkUtils {
3535
* @throws java.io.IOException
3636
*/
3737
public static @Nonnull File readSymbolicLink(@Nonnull File symlink) throws IOException {
38-
final java.nio.file.Path path = java.nio.file.Files.readSymbolicLink(symlink.toPath());
39-
return path.toFile();
38+
return Files.readSymbolicLink(symlink.toPath()).toFile();
4039
}
4140

4241
public static @Nonnull File createSymbolicLink(@Nonnull File symlink, File target) throws IOException {
4342
Path link = symlink.toPath();
4443
if (!Files.exists(link, LinkOption.NOFOLLOW_LINKS)) {
45-
link = java.nio.file.Files.createSymbolicLink(link, target.toPath());
44+
link = Files.createSymbolicLink(link, target.toPath());
4645
}
4746
return link.toFile();
4847
}

src/main/java/org/codehaus/plexus/components/io/attributes/proxy/PlexusIoProxyResourceAttributes.java

+1-6
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
public class PlexusIoProxyResourceAttributes implements PlexusIoResourceAttributes {
88

9-
PlexusIoResourceAttributes target;
9+
final PlexusIoResourceAttributes target;
1010

1111
public PlexusIoProxyResourceAttributes(PlexusIoResourceAttributes thisAttr) {
1212
this.target = thisAttr;
@@ -45,11 +45,6 @@ public Integer getUserId() {
4545
return target.getUserId();
4646
}
4747

48-
/* public String getOctalModeString()
49-
{
50-
return target.getOctalModeString();
51-
}
52-
*/
5348
public boolean isOwnerWritable() {
5449
return target.isOwnerWritable();
5550
}

src/main/java/org/codehaus/plexus/components/io/filemappers/AbstractFileMapper.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public abstract class AbstractFileMapper implements FileMapper {
2929
* Checks the input and returns it without modifications.
3030
*/
3131
public @Nonnull String getMappedFileName(@Nonnull String pName) {
32-
if (pName == null || pName.length() == 0) {
32+
if (pName == null || pName.isEmpty()) {
3333
throw new IllegalArgumentException("The source name must not be null.");
3434
}
3535
return pName;

src/main/java/org/codehaus/plexus/components/io/filemappers/FileExtensionMapper.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public void setTargetExtension(String pTargetExtension) {
4242
if (pTargetExtension == null) {
4343
throw new IllegalArgumentException("The target extension is null.");
4444
}
45-
if (pTargetExtension.length() == 0) {
45+
if (pTargetExtension.isEmpty()) {
4646
throw new IllegalArgumentException("The target extension is empty.");
4747
}
4848
if (pTargetExtension.charAt(0) == '.') {

src/main/java/org/codehaus/plexus/components/io/filemappers/IdentityMapper.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public class IdentityMapper extends AbstractFileMapper {
3131

3232
@Nonnull
3333
public String getMappedFileName(@Nonnull String pName) {
34-
if (pName == null || pName.length() == 0) {
34+
if (pName == null || pName.isEmpty()) {
3535
throw new IllegalArgumentException("The source name must not be null.");
3636
}
3737
return pName;

src/main/java/org/codehaus/plexus/components/io/filemappers/MergeFileMapper.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public void setTargetName(String pName) {
4141
if (pName == null) {
4242
throw new IllegalArgumentException("The target name is null.");
4343
}
44-
if (pName.length() == 0) {
44+
if (pName.isEmpty()) {
4545
throw new IllegalArgumentException("The target name is empty.");
4646
}
4747
targetName = pName;

src/main/java/org/codehaus/plexus/components/io/filemappers/PrefixFileMapper.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public void setPrefix(String prefix) {
5555
* Performs the mapping of a file name by adding a prefix.
5656
*/
5757
public static String getMappedFileName(String prefix, String name) {
58-
if (prefix == null || prefix.length() == 0) {
58+
if (prefix == null || prefix.isEmpty()) {
5959
return name;
6060
}
6161
return prefix + name;

src/main/java/org/codehaus/plexus/components/io/functions/InputStreamTransformer.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
public interface InputStreamTransformer {
3030
/**
3131
* Transform the supplied input stream into another input stream.
32-
*
32+
* <p>
3333
* The close method will be delegated through the entire call chain
3434
*
3535
* @param resource The p-io resource the stream is for

src/main/java/org/codehaus/plexus/components/io/resources/AbstractPlexusIoArchiveResourceCollection.java

+9-14
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@
2121
import java.io.IOException;
2222
import java.util.Iterator;
2323

24-
import org.codehaus.plexus.components.io.functions.PlexusIoResourceConsumer;
25-
2624
/**
2725
* Default implementation of {@link PlexusIoFileResourceCollection} for
2826
* zip files, tar files, etc.
@@ -106,20 +104,17 @@ public void close() throws IOException {
106104
}
107105

108106
public Stream stream() {
109-
return new Stream() {
110-
public void forEach(PlexusIoResourceConsumer resourceConsumer) throws IOException {
111-
112-
final Iterator<PlexusIoResource> it = getEntries();
113-
while (it.hasNext()) {
114-
final PlexusIoResource res = it.next();
115-
if (isSelected(res)) {
116-
resourceConsumer.accept(res);
117-
}
118-
}
119-
if (it instanceof Closeable) {
120-
((Closeable) it).close();
107+
return resourceConsumer -> {
108+
Iterator<PlexusIoResource> it = getEntries();
109+
while (it.hasNext()) {
110+
final PlexusIoResource res = it.next();
111+
if (isSelected(res)) {
112+
resourceConsumer.accept(res);
121113
}
122114
}
115+
if (it instanceof Closeable) {
116+
((Closeable) it).close();
117+
}
123118
};
124119
}
125120

src/main/java/org/codehaus/plexus/components/io/resources/AbstractPlexusIoResourceCollection.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -249,9 +249,8 @@ public PlexusIoResource resolve(final PlexusIoResource resource) throws IOExcept
249249

250250
public long getLastModified() throws IOException {
251251
long lastModified = PlexusIoResource.UNKNOWN_MODIFICATION_DATE;
252-
for (final Iterator iter = getResources(); iter.hasNext(); ) {
253-
final PlexusIoResource res = (PlexusIoResource) iter.next();
254-
long l = res.getLastModified();
252+
for (Iterator<PlexusIoResource> iter = getResources(); iter.hasNext(); ) {
253+
long l = iter.next().getLastModified();
255254
if (l == PlexusIoResource.UNKNOWN_MODIFICATION_DATE) {
256255
return PlexusIoResource.UNKNOWN_MODIFICATION_DATE;
257256
}

src/main/java/org/codehaus/plexus/components/io/resources/Deferred.java

+6-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,12 @@ public Deferred(final PlexusIoResource resource, PlexusIoResourceCollection owne
4040
throws IOException {
4141
this.resource = resource;
4242
this.owner = owner;
43-
dfos = hasTransformer ? new DeferredFileOutputStream(5000000, "p-archiver", null, null) : null;
43+
dfos = hasTransformer
44+
? DeferredFileOutputStream.builder()
45+
.setThreshold(5000000)
46+
.setPrefix("p-archiver")
47+
.get()
48+
: null;
4449
if (dfos != null) {
4550
InputStream inputStream = owner.getInputStream(resource);
4651
IOUtils.copy(inputStream, dfos);

src/main/java/org/codehaus/plexus/components/io/resources/PlexusIoCompressedFileResourceCollection.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ public InputStream getContents() throws IOException {
108108
protected String getName(File file) throws IOException {
109109
final String name = file.getPath();
110110
final String ext = getDefaultExtension();
111-
if (ext != null && ext.length() > 0 && name.endsWith(ext)) {
111+
if (ext != null && !ext.isEmpty() && name.endsWith(ext)) {
112112
return name.substring(0, name.length() - ext.length());
113113
}
114114
return name;

src/main/java/org/codehaus/plexus/components/io/resources/PlexusIoFileResource.java

+6-6
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import java.io.IOException;
2525
import java.io.InputStream;
2626
import java.net.URL;
27+
import java.nio.file.Files;
2728
import java.nio.file.attribute.FileTime;
2829

2930
import org.apache.commons.io.IOUtils;
@@ -103,7 +104,10 @@ protected PlexusIoFileResource(@Nonnull File file, @Nonnull String name, @Nonnul
103104
private static DeferredFileOutputStream asDeferredStream(
104105
@Nonnull ContentSupplier supplier, @Nonnull InputStreamTransformer transToUse, PlexusIoResource resource)
105106
throws IOException {
106-
DeferredFileOutputStream dfos = new DeferredFileOutputStream(5000000, "p-archiver", null, null);
107+
DeferredFileOutputStream dfos = DeferredFileOutputStream.builder()
108+
.setThreshold(5000000)
109+
.setPrefix("p-archiver")
110+
.get();
107111
InputStream inputStream = supplier.getContents();
108112
InputStream transformed = transToUse.transform(resource, inputStream);
109113
IOUtils.copy(transformed, dfos);
@@ -113,11 +117,7 @@ private static DeferredFileOutputStream asDeferredStream(
113117
}
114118

115119
private static ContentSupplier getRootContentSupplier(final File file) {
116-
return new ContentSupplier() {
117-
public InputStream getContents() throws IOException {
118-
return new FileInputStream(file);
119-
}
120-
};
120+
return () -> Files.newInputStream(file.toPath());
121121
}
122122

123123
public static String getName(File file) {

src/main/java/org/codehaus/plexus/components/io/resources/PlexusIoResource.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public interface PlexusIoResource extends FileInfo, SizeSupplier, ContentSupplie
7373
* Creates an {@link java.io.InputStream}, which may be used to read
7474
* the files contents. This is useful, if the file selector
7575
* comes to a decision based on the files contents.
76-
*
76+
* <p>
7777
* Please note that this InputStream is unbuffered. Clients should wrap this in a
7878
* BufferedInputStream or attempt reading reasonably large chunks (8K+).
7979
*/

src/main/java/org/codehaus/plexus/components/io/resources/PlexusIoSymlinkResource.java

-6
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,4 @@ public boolean isFile() {
8787
public long getLastModified() {
8888
return targetResource.getLastModified();
8989
}
90-
91-
@Nonnull
92-
@Override
93-
public PlexusIoResourceAttributes getAttributes() {
94-
return super.getAttributes();
95-
}
9690
}

src/main/java/org/codehaus/plexus/components/io/resources/proxy/PlexusIoProxyResourceCollection.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
*/
4343
public class PlexusIoProxyResourceCollection extends AbstractPlexusIoResourceCollectionWithAttributes
4444
implements EncodingSupported {
45-
private PlexusIoResourceCollection src;
45+
private final PlexusIoResourceCollection src;
4646

4747
public PlexusIoProxyResourceCollection(@Nonnull PlexusIoResourceCollection src) {
4848
this.src = src;
@@ -98,14 +98,14 @@ protected FileSelector getDefaultFileSelector() {
9898

9999
private String getNonEmptyPrfix() {
100100
String prefix = getPrefix();
101-
if (prefix != null && prefix.length() == 0) {
101+
if (prefix != null && prefix.isEmpty()) {
102102
return null;
103103
}
104104
return prefix;
105105
}
106106

107107
class FwdIterator extends ForwardingIterator {
108-
Iterator<PlexusIoResource> iter;
108+
final Iterator<PlexusIoResource> iter;
109109

110110
private final FileSelector fileSelector = getDefaultFileSelector();
111111

src/main/java/org/codehaus/plexus/components/io/resources/proxy/ResourceInvocationHandler.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
import org.codehaus.plexus.components.io.resources.PlexusIoResource;
2929

3030
class ResourceInvocationHandler implements InvocationHandler {
31-
private PlexusIoResource testImpl;
31+
private final PlexusIoResource testImpl;
3232

3333
private final ContentSupplier contentSupplier;
3434
private final NameSupplier nameSupplier;

src/test/java/org/codehaus/plexus/components/io/attributes/AttributeUtilsTest.java

+5-4
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55
import java.nio.file.attribute.PosixFilePermission;
66
import java.util.Set;
77

8-
import org.codehaus.plexus.util.Os;
98
import org.junit.jupiter.api.Test;
9+
import org.junit.jupiter.api.condition.DisabledOnOs;
10+
import org.junit.jupiter.api.condition.OS;
1011

1112
import static org.junit.jupiter.api.Assertions.assertEquals;
1213
import static org.junit.jupiter.api.Assertions.assertFalse;
@@ -34,22 +35,22 @@ void testMorePatterns() {
3435
}
3536

3637
@Test
37-
void testEvenMorePatterns() throws Exception {
38+
void testEvenMorePatterns() {
3839
final Set<PosixFilePermission> permissions = AttributeUtils.getPermissions(0412);
3940
assertTrue(permissions.contains(PosixFilePermission.OWNER_READ));
4041
assertTrue(permissions.contains(PosixFilePermission.GROUP_EXECUTE));
4142
assertTrue(permissions.contains(PosixFilePermission.OTHERS_WRITE));
4243
}
4344

4445
@Test
45-
void test777() throws Exception {
46+
void test777() {
4647
final Set<PosixFilePermission> permissions = AttributeUtils.getPermissions(0777);
4748
assertEquals(9, permissions.size());
4849
}
4950

5051
@Test
52+
@DisabledOnOs(OS.WINDOWS)
5153
void testChmodBackAndForth() throws IOException {
52-
if (Os.isFamily(Os.FAMILY_WINDOWS)) return;
5354
final File bxx = File.createTempFile("bxx", "ff");
5455
AttributeUtils.chmod(bxx, 0422);
5556
PlexusIoResourceAttributes firstAttrs = new FileAttributes(bxx);

src/test/java/org/codehaus/plexus/components/io/attributes/FileAttributesTest.java

+3-7
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@
1818

1919
import java.io.File;
2020

21-
import org.codehaus.plexus.util.Os;
2221
import org.junit.jupiter.api.Test;
22+
import org.junit.jupiter.api.condition.DisabledOnOs;
23+
import org.junit.jupiter.api.condition.OS;
2324

2425
import static org.junit.jupiter.api.Assertions.assertNotNull;
2526

@@ -28,14 +29,9 @@
2829
*/
2930
public class FileAttributesTest {
3031
@Test
32+
@DisabledOnOs(OS.WINDOWS)
3133
void testGetPosixFileAttributes() throws Exception {
32-
33-
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
34-
return;
35-
}
36-
3734
File file = new File(".");
38-
3935
PlexusIoResourceAttributes fa = new FileAttributes(file);
4036
assertNotNull(fa);
4137
}

0 commit comments

Comments
 (0)