From d6f36c6b1c71c04e47d272f3323943eebcbf7db7 Mon Sep 17 00:00:00 2001 From: Plamen Totev Date: Sun, 27 Mar 2022 07:33:24 +0000 Subject: [PATCH 01/86] [maven-release-plugin] prepare for next development iteration --- pom.xml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index 798f119a..a029806a 100644 --- a/pom.xml +++ b/pom.xml @@ -8,7 +8,7 @@ plexus-io - 3.3.0 + 3.3.1-SNAPSHOT Plexus IO Components @@ -16,7 +16,7 @@ scm:git:git@github.com:codehaus-plexus/plexus-io.git scm:git:git@github.com:codehaus-plexus/plexus-io.git http://github.com/codehaus-plexus/plexus-io - plexus-io-3.3.0 + HEAD jira @@ -32,7 +32,7 @@ true 8 - 2022-03-27T07:31:26Z + 2022-03-27T07:33:23Z From 7e252ac6929b72e953b88719d5be23eb9e97b5aa Mon Sep 17 00:00:00 2001 From: Plamen Totev Date: Sun, 27 Mar 2022 17:16:11 +0300 Subject: [PATCH 02/86] Use shared GitHub workflows This would ease the maintenance of the build and other utility actions, such as release-drafter. --- .github/workflows/maven.yml | 21 ++------------------- .github/workflows/release-drafter.yml | 7 ++----- 2 files changed, 4 insertions(+), 24 deletions(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index ff4a45d1..ad0c4c22 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -21,22 +21,5 @@ on: [push, pull_request] jobs: build: - - strategy: - matrix: - os: [ubuntu-latest,windows-latest, macOS-latest] - java: [8, 11, 17] - fail-fast: false - - runs-on: ${{ matrix.os }} - - steps: - - uses: actions/checkout@v2.4.0 - - uses: actions/setup-java@v2 - with: - java-version: ${{ matrix.java }} - distribution: 'temurin' - cache: 'maven' - - - name: Build with Maven - run: mvn install javadoc:javadoc site -e -B -V -Pno-tests-if-not-on-osx + name: Build with Maven + uses: codehaus-plexus/.github/.github/workflows/maven.yml@v0.0.4 diff --git a/.github/workflows/release-drafter.yml b/.github/workflows/release-drafter.yml index 96f54b5d..eb83e9b3 100644 --- a/.github/workflows/release-drafter.yml +++ b/.github/workflows/release-drafter.yml @@ -5,8 +5,5 @@ on: - master jobs: update_release_draft: - runs-on: ubuntu-latest - steps: - - uses: release-drafter/release-drafter@v5.19.0 - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + name: Update Release Notes Draft + uses: codehaus-plexus/.github/.github/workflows/release-drafter.yml@v0.0.4 From c7986d3fd9784b66ff5cb013d59bfad763d6fb53 Mon Sep 17 00:00:00 2001 From: Plamen Totev Date: Sun, 27 Mar 2022 17:18:25 +0300 Subject: [PATCH 03/86] Add license header to release-drafter.yml --- .github/workflows/release-drafter.yml | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/.github/workflows/release-drafter.yml b/.github/workflows/release-drafter.yml index eb83e9b3..35084c5d 100644 --- a/.github/workflows/release-drafter.yml +++ b/.github/workflows/release-drafter.yml @@ -1,3 +1,20 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you 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. + name: Release Drafter on: push: From 920227807f4cab9d0e9cbbcb3a085e62c48480e4 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 21 Apr 2022 21:03:16 +0000 Subject: [PATCH 04/86] Bump actions/checkout from 2.4.0 to 3.0.2 Bumps [actions/checkout](https://github.com/actions/checkout) from 2.4.0 to 3.0.2. - [Release notes](https://github.com/actions/checkout/releases) - [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md) - [Commits](https://github.com/actions/checkout/compare/v2.4.0...v3.0.2) --- updated-dependencies: - dependency-name: actions/checkout dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/codeql-analysis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 7d1e5b90..3b0900f9 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -35,7 +35,7 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@v2.4.0 + uses: actions/checkout@v3.0.2 # Initializes the CodeQL tools for scanning. - name: Initialize CodeQL From ddfdd3dd49ff7b95d8c89d46c8db6017d28f4aa5 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 25 Apr 2022 21:03:58 +0000 Subject: [PATCH 05/86] Bump github/codeql-action from 1 to 2 Bumps [github/codeql-action](https://github.com/github/codeql-action) from 1 to 2. - [Release notes](https://github.com/github/codeql-action/releases) - [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md) - [Commits](https://github.com/github/codeql-action/compare/v1...v2) --- updated-dependencies: - dependency-name: github/codeql-action dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/codeql-analysis.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index 3b0900f9..ffe5bb29 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -39,7 +39,7 @@ jobs: # Initializes the CodeQL tools for scanning. - name: Initialize CodeQL - uses: github/codeql-action/init@v1 + uses: github/codeql-action/init@v2 with: languages: ${{ matrix.language }} # If you wish to specify custom queries, you can do so here or in a config file. @@ -50,7 +50,7 @@ jobs: # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). # If this step fails, then you should remove it and run the build manually (see below) - name: Autobuild - uses: github/codeql-action/autobuild@v1 + uses: github/codeql-action/autobuild@v2 # â„šī¸ Command-line programs to run using the OS shell. # 📚 https://git.io/JvXDl @@ -64,4 +64,4 @@ jobs: # make release - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@v1 + uses: github/codeql-action/analyze@v2 From bf86860f0dfc27a26cff847caa0d101bda510131 Mon Sep 17 00:00:00 2001 From: Plamen Totev Date: Mon, 25 Apr 2022 18:08:50 +0000 Subject: [PATCH 06/86] Revert "Speed improvements (#33)" The commit intorduces regression. Symlinks to directories are no longer considered directories. See #71 This reverts commit 5b79b54893015aa5af971a7ad54e238fdbde0fd2. --- .../io/attributes/FileAttributes.java | 126 ++++++------------ .../PlexusIoResourceAttributeUtils.java | 116 ++++++++-------- .../attributes/SimpleResourceAttributes.java | 10 -- .../UserGroupModeFileAttributes.java | 47 ------- .../io/resources/PlexusIoFileResource.java | 26 ---- .../PlexusIoFileResourceCollection.java | 4 +- .../io/resources/proxy/ProxyFactory.java | 2 +- 7 files changed, 100 insertions(+), 231 deletions(-) delete mode 100644 src/main/java/org/codehaus/plexus/components/io/attributes/UserGroupModeFileAttributes.java diff --git a/src/main/java/org/codehaus/plexus/components/io/attributes/FileAttributes.java b/src/main/java/org/codehaus/plexus/components/io/attributes/FileAttributes.java index 6b90fdff..d052d200 100644 --- a/src/main/java/org/codehaus/plexus/components/io/attributes/FileAttributes.java +++ b/src/main/java/org/codehaus/plexus/components/io/attributes/FileAttributes.java @@ -22,7 +22,6 @@ import java.nio.file.LinkOption; import java.nio.file.Path; import java.nio.file.attribute.FileOwnerAttributeView; -import java.nio.file.attribute.FileTime; import java.nio.file.attribute.PosixFilePermission; import java.security.Principal; import java.util.Collections; @@ -53,77 +52,62 @@ public class FileAttributes private final boolean symbolicLink; - private final boolean regularFile; - - private final boolean directory; - - private final boolean other; - private final int octalMode; private final Set permissions; - private final long size; - - private final FileTime lastModifiedTime; - public FileAttributes( @Nonnull File file, @Nonnull Map userCache, @Nonnull Map groupCache ) throws IOException { Path path = file.toPath(); - Set views = path.getFileSystem().supportedFileAttributeViews(); - String names; - if ( views.contains( "unix" ) ) - { - names = "unix:*"; - } - else if ( views.contains( "posix" ) ) + if ( AttributeUtils.isUnix( path ) ) { - names = "posix:*"; + Map attrs = Files.readAttributes( path, "unix:permissions,gid,uid,isSymbolicLink,mode", LinkOption.NOFOLLOW_LINKS ); + this.permissions = (Set) attrs.get( "permissions" ); + + groupId = (Integer) attrs.get( "gid" ); + + String groupName = groupCache.get( groupId ); + if ( groupName != null ) + { + this.groupName = groupName; + } + else + { + Object group = Files.getAttribute( path, "unix:group", LinkOption.NOFOLLOW_LINKS ); + this.groupName = ( (Principal) group ).getName(); + groupCache.put( groupId, this.groupName ); + } + userId = (Integer) attrs.get( "uid" ); + String userName = userCache.get( userId ); + if ( userName != null ) + { + this.userName = userName; + } + else + { + Object owner = Files.getAttribute( path, "unix:owner", LinkOption.NOFOLLOW_LINKS ); + this.userName = ( (Principal) owner ).getName(); + userCache.put( userId, this.userName ); + } + octalMode = (Integer) attrs.get( "mode" ) & 0xfff; // Mask off top bits for compatibilty. Maybe check if we + // can skip this + symbolicLink = (Boolean) attrs.get( "isSymbolicLink" ); } else { - names = "basic:*"; + FileOwnerAttributeView fa = AttributeUtils.getFileOwnershipInfo( file ); + this.userName = fa.getOwner().getName(); + userId = null; + this.groupName = null; + this.groupId = null; + octalMode = PlexusIoResourceAttributes.UNKNOWN_OCTAL_MODE; + permissions = Collections.emptySet(); + symbolicLink = Files.isSymbolicLink( path ); } - Map attrs = Files.readAttributes( path, names, LinkOption.NOFOLLOW_LINKS); - if ( !attrs.containsKey( "group" ) && !attrs.containsKey( "owner" ) && views.contains( "owner" ) ) - { - Map ownerAttrs = Files.readAttributes( path, "owner:*", LinkOption.NOFOLLOW_LINKS); - Map newAttrs = new HashMap<>( attrs ); - newAttrs.putAll( ownerAttrs ); - attrs = newAttrs; - } - this.groupId = (Integer) attrs.get( "gid" ); - this.groupName = attrs.containsKey( "group" ) ? ((Principal) attrs.get( "group" ) ).getName() : null; - this.userId = (Integer) attrs.get( "uid" ); - this.userName = attrs.containsKey( "owner" ) ? ((Principal) attrs.get( "owner" ) ).getName() : null; - this.symbolicLink = (Boolean) attrs.get( "isSymbolicLink" ); - this.regularFile = (Boolean) attrs.get( "isRegularFile" ); - this.directory = (Boolean) attrs.get( "isDirectory" ); - this.other = (Boolean) attrs.get( "isOther" ); - this.octalMode = attrs.containsKey( "mode" ) ? (Integer) attrs.get( "mode" ) & 0xfff : PlexusIoResourceAttributes.UNKNOWN_OCTAL_MODE; - this.permissions = attrs.containsKey( "permissions" ) ? (Set) attrs.get( "permissions" ) : Collections.emptySet(); - this.size = (Long) attrs.get( "size" ); - this.lastModifiedTime = (FileTime) attrs.get( "lastModifiedTime" ); - } - public FileAttributes( @Nullable Integer userId, String userName, @Nullable Integer groupId, @Nullable String groupName, - int octalMode, boolean symbolicLink, boolean regularFile, boolean directory, boolean other, - Set permissions, long size, FileTime lastModifiedTime) { - this.userId = userId; - this.userName = userName; - this.groupId = groupId; - this.groupName = groupName; - this.octalMode = octalMode; - this.symbolicLink = symbolicLink; - this.regularFile = regularFile; - this.directory = directory; - this.other = other; - this.permissions = permissions; - this.size = size; - this.lastModifiedTime = lastModifiedTime; } public static @Nonnull @@ -306,34 +290,4 @@ public boolean isSymbolicLink() { return symbolicLink; } - - public boolean isRegularFile() - { - return regularFile; - } - - public boolean isDirectory() - { - return directory; - } - - public boolean isOther() - { - return other; - } - - public long getSize() - { - return size; - } - - public FileTime getLastModifiedTime() - { - return lastModifiedTime; - } - - protected Set getPermissions() - { - return permissions; - } } \ No newline at end of file diff --git a/src/main/java/org/codehaus/plexus/components/io/attributes/PlexusIoResourceAttributeUtils.java b/src/main/java/org/codehaus/plexus/components/io/attributes/PlexusIoResourceAttributeUtils.java index 3e2c44b8..526a7c2e 100644 --- a/src/main/java/org/codehaus/plexus/components/io/attributes/PlexusIoResourceAttributeUtils.java +++ b/src/main/java/org/codehaus/plexus/components/io/attributes/PlexusIoResourceAttributeUtils.java @@ -43,71 +43,69 @@ public static PlexusIoResourceAttributes mergeAttributes( PlexusIoResourceAttrib { return base; } + SimpleResourceAttributes result; if ( base == null ) { - return new SimpleResourceAttributes( - override.getUserId() != null && override.getUserId() != -1 - ? override.getUserId() - : def != null && def.getUserId() != null && def.getUserId() != -1 - ? def.getUserId() - : null, - override.getUserName() != null - ? override.getUserName() - : def != null - ? def.getUserName() - : null, - override.getGroupId() != null && override.getGroupId() != -1 - ? override.getGroupId() - : def != null && def.getGroupId() != null && def.getGroupId() != -1 - ? def.getGroupId() - : null, - override.getGroupName() != null - ? override.getGroupName() - : def != null - ? def.getGroupName() - : null, - override.getOctalMode() ); + result = new SimpleResourceAttributes(); } else { - Integer uid = override.getUserId() != null && override.getUserId() != -1 - ? override.getUserId() - : base.getUserId() != null && base.getUserId() != -1 - ? base.getUserId() - : def.getUserId() != null && def.getUserId() != -1 - ? def.getUserId() - : null; - String uname = override.getUserName() != null - ? override.getUserName() - : base.getUserName() != null - ? base.getUserName() - : def.getUserName(); - Integer gid = override.getGroupId() != null && override.getGroupId() != -1 - ? override.getGroupId() - : base.getGroupId() != null && base.getGroupId() != -1 - ? base.getGroupId() - : def.getGroupId() != null && def.getGroupId() != -1 - ? def.getGroupId() - : null; - String gname = override.getGroupName() != null - ? override.getGroupName() - : base.getGroupName() != null - ? base.getGroupName() - : def.getGroupName(); - int mode = override.getOctalMode() > 0 - ? override.getOctalMode() - : base.getOctalMode() >= 0 - ? base.getOctalMode() - : def.getOctalMode(); - if ( base instanceof FileAttributes ) - { - return new UserGroupModeFileAttributes( uid, uname, gid, gname, mode, (FileAttributes) base ); - } - else - { - return new SimpleResourceAttributes( uid, uname, gid, gname, mode, base.isSymbolicLink() ); - } + result = new SimpleResourceAttributes( base.getUserId(), base.getUserName(), base.getGroupId(), + base.getGroupName(), base.getOctalMode() ); + result.setSymbolicLink( base.isSymbolicLink() ); } + + if ( override.getGroupId() != null && override.getGroupId() != -1 ) + { + result.setGroupId( override.getGroupId() ); + } + + if ( def != null && def.getGroupId() >= 0 && ( result.getGroupId() == null || result.getGroupId() < 0 ) ) + { + result.setGroupId( def.getGroupId() ); + } + + if ( override.getGroupName() != null ) + { + result.setGroupName( override.getGroupName() ); + } + + if ( def != null && result.getGroupName() == null ) + { + result.setGroupName( def.getGroupName() ); + } + + if ( override.getUserId() != null && override.getUserId() != -1 ) + { + result.setUserId( override.getUserId() ); + } + + if ( def != null && def.getUserId() >= 0 && ( result.getUserId() == null || result.getUserId() < 0 ) ) + { + result.setUserId( def.getUserId() ); + } + + if ( override.getUserName() != null ) + { + result.setUserName( override.getUserName() ); + } + + if ( def != null && result.getUserName() == null ) + { + result.setUserName( def.getUserName() ); + } + + if ( override.getOctalMode() > 0 ) + { + result.setOctalMode( override.getOctalMode() ); + } + + if ( def != null && result.getOctalMode() < 0 ) + { + result.setOctalMode( def.getOctalMode() ); + } + + return result; } public static boolean isGroupExecutableInOctal( int mode ) diff --git a/src/main/java/org/codehaus/plexus/components/io/attributes/SimpleResourceAttributes.java b/src/main/java/org/codehaus/plexus/components/io/attributes/SimpleResourceAttributes.java index a92d7411..301905e5 100644 --- a/src/main/java/org/codehaus/plexus/components/io/attributes/SimpleResourceAttributes.java +++ b/src/main/java/org/codehaus/plexus/components/io/attributes/SimpleResourceAttributes.java @@ -46,16 +46,6 @@ public SimpleResourceAttributes( Integer uid, String userName, Integer gid, Stri this.mode = mode; } - public SimpleResourceAttributes( Integer uid, String userName, Integer gid, String groupName, int mode, boolean isSymbolicLink ) - { - this.uid = uid; - this.userName = userName; - this.gid = gid; - this.groupName = groupName; - this.mode = mode; - this.isSymbolicLink = isSymbolicLink; - } - public static PlexusIoResourceAttributes lastResortDummyAttributesForBrokenOS() { return new SimpleResourceAttributes(); diff --git a/src/main/java/org/codehaus/plexus/components/io/attributes/UserGroupModeFileAttributes.java b/src/main/java/org/codehaus/plexus/components/io/attributes/UserGroupModeFileAttributes.java deleted file mode 100644 index 37984b17..00000000 --- a/src/main/java/org/codehaus/plexus/components/io/attributes/UserGroupModeFileAttributes.java +++ /dev/null @@ -1,47 +0,0 @@ -package org.codehaus.plexus.components.io.attributes; - -/* - * Copyright 2007 The Codehaus Foundation. - * - * 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. - */ - -import javax.annotation.Nullable; - -/* - * A very simple pojo based PlexusIoResourceAttributes without any kind of backing - */ -public class UserGroupModeFileAttributes - extends FileAttributes -{ - - public UserGroupModeFileAttributes( Integer uid, String userName, Integer gid, String groupName, int mode, FileAttributes base ) - { - super( uid, userName, gid, groupName, mode, - base.isSymbolicLink(), base.isRegularFile(), base.isDirectory(), base.isOther(), - base.getPermissions(), base.getSize(), base.getLastModifiedTime() ); - } - - public String toString() - { - return String.format( - "%nResource Attributes:%n------------------------------%nuser: %s%ngroup: %s%nuid: %d%ngid: %d%nmode: %06o", - getUserName() == null ? "" : getUserName(), - getGroupName() == null ? "" : getGroupName(), - getUserId() != null ? getUserId() : 0, - getGroupId() != null ? getGroupId() : 0, - getOctalMode() ); - } - - -} diff --git a/src/main/java/org/codehaus/plexus/components/io/resources/PlexusIoFileResource.java b/src/main/java/org/codehaus/plexus/components/io/resources/PlexusIoFileResource.java index c999a32c..c8ca266b 100755 --- a/src/main/java/org/codehaus/plexus/components/io/resources/PlexusIoFileResource.java +++ b/src/main/java/org/codehaus/plexus/components/io/resources/PlexusIoFileResource.java @@ -22,12 +22,10 @@ import java.io.IOException; import java.io.InputStream; import java.net.URL; -import java.nio.file.attribute.FileTime; import org.apache.commons.io.IOUtils; import org.apache.commons.io.output.DeferredFileOutputStream; import org.codehaus.plexus.components.io.attributes.AttributeUtils; -import org.codehaus.plexus.components.io.attributes.FileAttributes; import org.codehaus.plexus.components.io.attributes.PlexusIoResourceAttributes; import org.codehaus.plexus.components.io.functions.ContentSupplier; import org.codehaus.plexus.components.io.functions.FileSupplier; @@ -159,10 +157,6 @@ public long getSize() { if ( dfos == null ) { - if ( attributes instanceof FileAttributes) - { - return ( ( FileAttributes ) attributes ).getSize(); - } return getFile().length(); } if ( dfos.isInMemory() ) @@ -177,28 +171,16 @@ public long getSize() public boolean isDirectory() { - if ( attributes instanceof FileAttributes ) - { - return ( ( FileAttributes ) attributes ).isDirectory(); - } return getFile().isDirectory(); } public boolean isExisting() { - if ( attributes instanceof FileAttributes ) - { - return true; - } return getFile().exists(); } public boolean isFile() { - if ( attributes instanceof FileAttributes ) - { - return ( ( FileAttributes ) attributes ).isRegularFile(); - } return getFile().isFile(); } @@ -210,14 +192,6 @@ public PlexusIoResourceAttributes getAttributes() public long getLastModified() { - if ( attributes instanceof FileAttributes ) - { - FileTime lastModified = ( ( FileAttributes ) attributes ).getLastModifiedTime(); - if ( lastModified != null ) - { - return lastModified.toMillis(); - } - } return AttributeUtils.getLastModified( getFile() ); } diff --git a/src/main/java/org/codehaus/plexus/components/io/resources/PlexusIoFileResourceCollection.java b/src/main/java/org/codehaus/plexus/components/io/resources/PlexusIoFileResourceCollection.java index 75631f15..2293de96 100644 --- a/src/main/java/org/codehaus/plexus/components/io/resources/PlexusIoFileResourceCollection.java +++ b/src/main/java/org/codehaus/plexus/components/io/resources/PlexusIoFileResourceCollection.java @@ -159,8 +159,8 @@ private void addResources( List result, String[] resources ) String sourceDir = name.replace( '\\', '/' ); File f = new File( dir, sourceDir ); - FileAttributes fattrs = new FileAttributes( f, cache1, cache2 ); - PlexusIoResourceAttributes attrs = mergeAttributes( fattrs, fattrs.isDirectory() ); + PlexusIoResourceAttributes attrs = new FileAttributes( f, cache1, cache2 ); + attrs = mergeAttributes( attrs, f.isDirectory() ); String remappedName = getName( name ); diff --git a/src/main/java/org/codehaus/plexus/components/io/resources/proxy/ProxyFactory.java b/src/main/java/org/codehaus/plexus/components/io/resources/proxy/ProxyFactory.java index 4b4bf9bd..15597b03 100644 --- a/src/main/java/org/codehaus/plexus/components/io/resources/proxy/ProxyFactory.java +++ b/src/main/java/org/codehaus/plexus/components/io/resources/proxy/ProxyFactory.java @@ -40,7 +40,7 @@ public static PlexusIoResource createProxy( @Nonnull PlexusIoResource target, Ob interfaces.add( ResourceAttributeSupplier.class ); return (PlexusIoResource) Proxy.newProxyInstance( PlexusIoResource.class.getClassLoader(), - interfaces.toArray( new Class[0] ), + interfaces.toArray( new Class[interfaces.size()] ), new ResourceInvocationHandler( target, alternateSupplier ) ); } } From 9e244df57f8d417c48c848fc65626476aaa5200d Mon Sep 17 00:00:00 2001 From: Plamen Totev Date: Mon, 25 Apr 2022 18:06:15 +0000 Subject: [PATCH 07/86] Update PlexusIoPlexusIoFileResourceTest with symlink dir assertion We had regression in which symlinks to directories are no longer considered directories. Add assertion to ensure the behaviour is not changed in future. --- .../io/resources/PlexusIoPlexusIoFileResourceTest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/test/java/org/codehaus/plexus/components/io/resources/PlexusIoPlexusIoFileResourceTest.java b/src/test/java/org/codehaus/plexus/components/io/resources/PlexusIoPlexusIoFileResourceTest.java index 17905f22..f636277a 100644 --- a/src/test/java/org/codehaus/plexus/components/io/resources/PlexusIoPlexusIoFileResourceTest.java +++ b/src/test/java/org/codehaus/plexus/components/io/resources/PlexusIoPlexusIoFileResourceTest.java @@ -23,6 +23,7 @@ public void testRealSymlink() assertTrue( attrs.isSymbolicLink() ); PlexusIoFileResource r = new PlexusIoFileResource( file, "symDir", attrs ); assertTrue( r.isSymbolicLink() ); + assertTrue( r.isDirectory() ); final File target = SymlinkUtils.readSymbolicLink( file ); assertTrue( target.getName().endsWith( "targetDir" ) ); } From 7f4e419b618330c445a53bc04aa81c4909737510 Mon Sep 17 00:00:00 2001 From: Plamen Totev Date: Mon, 2 May 2022 06:11:25 +0000 Subject: [PATCH 08/86] [maven-release-plugin] prepare release plexus-io-3.3.1 --- pom.xml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index a029806a..899a7d5b 100644 --- a/pom.xml +++ b/pom.xml @@ -8,7 +8,7 @@ plexus-io - 3.3.1-SNAPSHOT + 3.3.1 Plexus IO Components @@ -16,7 +16,7 @@ scm:git:git@github.com:codehaus-plexus/plexus-io.git scm:git:git@github.com:codehaus-plexus/plexus-io.git http://github.com/codehaus-plexus/plexus-io - HEAD + plexus-io-3.3.1 jira @@ -32,7 +32,7 @@ true 8 - 2022-03-27T07:33:23Z + 2022-05-02T06:08:27Z From ef42233af712465a36e69b8e9dcafc412ac5b305 Mon Sep 17 00:00:00 2001 From: Plamen Totev Date: Mon, 2 May 2022 06:11:29 +0000 Subject: [PATCH 09/86] [maven-release-plugin] prepare for next development iteration --- pom.xml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index 899a7d5b..7c2f7b80 100644 --- a/pom.xml +++ b/pom.xml @@ -8,7 +8,7 @@ plexus-io - 3.3.1 + 3.3.2-SNAPSHOT Plexus IO Components @@ -16,7 +16,7 @@ scm:git:git@github.com:codehaus-plexus/plexus-io.git scm:git:git@github.com:codehaus-plexus/plexus-io.git http://github.com/codehaus-plexus/plexus-io - plexus-io-3.3.1 + HEAD jira @@ -32,7 +32,7 @@ true 8 - 2022-05-02T06:08:27Z + 2022-05-02T06:11:29Z From 7394f0453a089cf2164cd9a3e6fd913350ff8510 Mon Sep 17 00:00:00 2001 From: Guillaume Nodet Date: Mon, 2 May 2022 09:59:12 +0200 Subject: [PATCH 10/86] Code style: missing spaces inside parenthesis --- .../plexus/components/io/resources/ResourceFactory.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/codehaus/plexus/components/io/resources/ResourceFactory.java b/src/main/java/org/codehaus/plexus/components/io/resources/ResourceFactory.java index a482a32a..5c0a7584 100644 --- a/src/main/java/org/codehaus/plexus/components/io/resources/ResourceFactory.java +++ b/src/main/java/org/codehaus/plexus/components/io/resources/ResourceFactory.java @@ -54,7 +54,7 @@ public static PlexusIoResource createResource( File f, String name, final Conten { boolean symbolicLink = attributes.isSymbolicLink(); return symbolicLink ? new PlexusIoSymlinkResource( f, name, attributes ) - : new PlexusIoFileResource(f, name, attributes, contentSupplier, inputStreamTransformer); + : new PlexusIoFileResource( f, name, attributes, contentSupplier, inputStreamTransformer ); } } From 306612ce651f15f5c13612555a91b7b592626996 Mon Sep 17 00:00:00 2001 From: Guillaume Nodet Date: Mon, 2 May 2022 10:01:04 +0200 Subject: [PATCH 11/86] Code style: missing line break --- .../plexus/components/io/resources/PlexusIoFileResource.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/codehaus/plexus/components/io/resources/PlexusIoFileResource.java b/src/main/java/org/codehaus/plexus/components/io/resources/PlexusIoFileResource.java index c8ca266b..5079b9b7 100755 --- a/src/main/java/org/codehaus/plexus/components/io/resources/PlexusIoFileResource.java +++ b/src/main/java/org/codehaus/plexus/components/io/resources/PlexusIoFileResource.java @@ -195,7 +195,9 @@ public long getLastModified() return AttributeUtils.getLastModified( getFile() ); } - @Override public boolean isSymbolicLink() { + @Override + public boolean isSymbolicLink() + { return getAttributes().isSymbolicLink(); } From 85d63328c90ebc38128dd6b9f61217246cf25f22 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 18 May 2022 21:02:58 +0000 Subject: [PATCH 12/86] Bump plexus-utils from 3.4.1 to 3.4.2 Bumps [plexus-utils](https://github.com/codehaus-plexus/plexus-utils) from 3.4.1 to 3.4.2. - [Release notes](https://github.com/codehaus-plexus/plexus-utils/releases) - [Commits](https://github.com/codehaus-plexus/plexus-utils/compare/plexus-utils-3.4.1...plexus-utils-3.4.2) --- updated-dependencies: - dependency-name: org.codehaus.plexus:plexus-utils dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 7c2f7b80..277f3f6e 100644 --- a/pom.xml +++ b/pom.xml @@ -39,7 +39,7 @@ org.codehaus.plexus plexus-utils - 3.4.1 + 3.4.2 org.codehaus.plexus From cd1712f7d91bc4980005f117abf8cbe286ea5b0b Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 10 Jun 2022 21:03:26 +0000 Subject: [PATCH 13/86] Bump plexus from 8 to 10 Bumps [plexus](https://github.com/codehaus-plexus/plexus-pom) from 8 to 10. - [Release notes](https://github.com/codehaus-plexus/plexus-pom/releases) - [Commits](https://github.com/codehaus-plexus/plexus-pom/commits) --- updated-dependencies: - dependency-name: org.codehaus.plexus:plexus dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 277f3f6e..682abcba 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ org.codehaus.plexus plexus - 8 + 10 plexus-io From 6ffc902096d3408cb4a32406d8df0e56baa3aace Mon Sep 17 00:00:00 2001 From: Guillaume Nodet Date: Thu, 23 Jun 2022 10:01:52 +0200 Subject: [PATCH 14/86] Restore speed improvements (#79) Reimplement speed improvements (that were once reverted). Co-authored-by: Tamas Cservenak --- .../io/attributes/FileAttributes.java | 151 +++++++++++++----- .../PlexusIoResourceAttributeUtils.java | 140 ++++++++-------- .../PlexusIoResourceAttributes.java | 2 +- .../attributes/SimpleResourceAttributes.java | 10 ++ .../UserGroupModeFileAttributes.java | 47 ++++++ .../io/resources/PlexusIoFileResource.java | 55 +++++-- .../PlexusIoFileResourceCollection.java | 6 +- .../io/resources/PlexusIoSymlinkResource.java | 95 ++++++++++- .../io/resources/ResourceFactory.java | 4 +- .../io/resources/proxy/ProxyFactory.java | 2 +- .../io/attributes/AttributeUtilsTest.java | 6 +- .../io/attributes/FileAttributesTest.java | 4 +- .../PlexusIoPlexusIoFileResourceTest.java | 36 ++++- src/test/resources/symlinks/src/symSymR | 1 + 14 files changed, 424 insertions(+), 135 deletions(-) create mode 100644 src/main/java/org/codehaus/plexus/components/io/attributes/UserGroupModeFileAttributes.java create mode 120000 src/test/resources/symlinks/src/symSymR diff --git a/src/main/java/org/codehaus/plexus/components/io/attributes/FileAttributes.java b/src/main/java/org/codehaus/plexus/components/io/attributes/FileAttributes.java index d052d200..2b4512a3 100644 --- a/src/main/java/org/codehaus/plexus/components/io/attributes/FileAttributes.java +++ b/src/main/java/org/codehaus/plexus/components/io/attributes/FileAttributes.java @@ -22,6 +22,7 @@ import java.nio.file.LinkOption; import java.nio.file.Path; import java.nio.file.attribute.FileOwnerAttributeView; +import java.nio.file.attribute.FileTime; import java.nio.file.attribute.PosixFilePermission; import java.security.Principal; import java.util.Collections; @@ -39,6 +40,10 @@ public class FileAttributes implements PlexusIoResourceAttributes { + public static final LinkOption[] FOLLOW_LINK_OPTIONS = new LinkOption[] { }; + + public static final LinkOption[] NOFOLLOW_LINK_OPTIONS = new LinkOption[] { LinkOption.NOFOLLOW_LINKS }; + @Nullable private final Integer groupId; @@ -52,69 +57,101 @@ public class FileAttributes private final boolean symbolicLink; + private final boolean regularFile; + + private final boolean directory; + + private final boolean other; + private final int octalMode; private final Set permissions; + private final long size; + + private final FileTime lastModifiedTime; + + /** + * @deprecated use {@link #FileAttributes(File)} and remove the unused userCache and groupCache parameters + */ + @Deprecated public FileAttributes( @Nonnull File file, @Nonnull Map userCache, @Nonnull Map groupCache ) throws IOException { + this( file ); + } + + public FileAttributes( @Nonnull File file ) + throws IOException + { + this( file, false ); + } + public FileAttributes( @Nonnull File file, boolean followLinks ) + throws IOException + { + LinkOption[] options = followLinks ? FOLLOW_LINK_OPTIONS : NOFOLLOW_LINK_OPTIONS; Path path = file.toPath(); - if ( AttributeUtils.isUnix( path ) ) + Set views = path.getFileSystem().supportedFileAttributeViews(); + String names; + if ( views.contains( "unix" ) ) + { + names = "unix:*"; + } + else if ( views.contains( "posix" ) ) { - Map attrs = Files.readAttributes( path, "unix:permissions,gid,uid,isSymbolicLink,mode", LinkOption.NOFOLLOW_LINKS ); - this.permissions = (Set) attrs.get( "permissions" ); - - groupId = (Integer) attrs.get( "gid" ); - - String groupName = groupCache.get( groupId ); - if ( groupName != null ) - { - this.groupName = groupName; - } - else - { - Object group = Files.getAttribute( path, "unix:group", LinkOption.NOFOLLOW_LINKS ); - this.groupName = ( (Principal) group ).getName(); - groupCache.put( groupId, this.groupName ); - } - userId = (Integer) attrs.get( "uid" ); - String userName = userCache.get( userId ); - if ( userName != null ) - { - this.userName = userName; - } - else - { - Object owner = Files.getAttribute( path, "unix:owner", LinkOption.NOFOLLOW_LINKS ); - this.userName = ( (Principal) owner ).getName(); - userCache.put( userId, this.userName ); - } - octalMode = (Integer) attrs.get( "mode" ) & 0xfff; // Mask off top bits for compatibilty. Maybe check if we - // can skip this - symbolicLink = (Boolean) attrs.get( "isSymbolicLink" ); + names = "posix:*"; } else { - FileOwnerAttributeView fa = AttributeUtils.getFileOwnershipInfo( file ); - this.userName = fa.getOwner().getName(); - userId = null; - this.groupName = null; - this.groupId = null; - octalMode = PlexusIoResourceAttributes.UNKNOWN_OCTAL_MODE; - permissions = Collections.emptySet(); - symbolicLink = Files.isSymbolicLink( path ); + names = "basic:*"; } + Map attrs = Files.readAttributes( path, names, options ); + if ( !attrs.containsKey( "group" ) && !attrs.containsKey( "owner" ) && views.contains( "owner" ) ) + { + Map ownerAttrs = Files.readAttributes( path, "owner:*", options ); + Map newAttrs = new HashMap<>( attrs ); + newAttrs.putAll( ownerAttrs ); + attrs = newAttrs; + } + this.groupId = (Integer) attrs.get( "gid" ); + this.groupName = attrs.containsKey( "group" ) ? ((Principal) attrs.get( "group" ) ).getName() : null; + this.userId = (Integer) attrs.get( "uid" ); + this.userName = attrs.containsKey( "owner" ) ? ((Principal) attrs.get( "owner" ) ).getName() : null; + this.symbolicLink = (Boolean) attrs.get( "isSymbolicLink" ); + this.regularFile = (Boolean) attrs.get( "isRegularFile" ); + this.directory = (Boolean) attrs.get( "isDirectory" ); + this.other = (Boolean) attrs.get( "isOther" ); + this.octalMode = attrs.containsKey( "mode" ) ? (Integer) attrs.get( "mode" ) & 0xfff : PlexusIoResourceAttributes.UNKNOWN_OCTAL_MODE; + this.permissions = attrs.containsKey( "permissions" ) ? (Set) attrs.get( "permissions" ) : Collections.emptySet(); + this.size = (Long) attrs.get( "size" ); + this.lastModifiedTime = (FileTime) attrs.get( "lastModifiedTime" ); + } + public FileAttributes( @Nullable Integer userId, String userName, @Nullable Integer groupId, @Nullable String groupName, + int octalMode, boolean symbolicLink, boolean regularFile, boolean directory, boolean other, + Set permissions, long size, FileTime lastModifiedTime ) + { + this.userId = userId; + this.userName = userName; + this.groupId = groupId; + this.groupName = groupName; + this.octalMode = octalMode; + this.symbolicLink = symbolicLink; + this.regularFile = regularFile; + this.directory = directory; + this.other = other; + this.permissions = permissions; + this.size = size; + this.lastModifiedTime = lastModifiedTime; } public static @Nonnull PlexusIoResourceAttributes uncached( @Nonnull File file ) throws IOException { - return new FileAttributes( file, new HashMap(), new HashMap() ); + return new FileAttributes( file ); } @Nullable @@ -290,4 +327,34 @@ public boolean isSymbolicLink() { return symbolicLink; } -} \ No newline at end of file + + public boolean isRegularFile() + { + return regularFile; + } + + public boolean isDirectory() + { + return directory; + } + + public boolean isOther() + { + return other; + } + + public long getSize() + { + return size; + } + + public FileTime getLastModifiedTime() + { + return lastModifiedTime; + } + + protected Set getPermissions() + { + return permissions; + } +} diff --git a/src/main/java/org/codehaus/plexus/components/io/attributes/PlexusIoResourceAttributeUtils.java b/src/main/java/org/codehaus/plexus/components/io/attributes/PlexusIoResourceAttributeUtils.java index 526a7c2e..1cc81669 100644 --- a/src/main/java/org/codehaus/plexus/components/io/attributes/PlexusIoResourceAttributeUtils.java +++ b/src/main/java/org/codehaus/plexus/components/io/attributes/PlexusIoResourceAttributeUtils.java @@ -22,7 +22,6 @@ import java.io.File; import java.io.IOException; import java.util.Collections; -import java.util.HashMap; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -43,69 +42,71 @@ public static PlexusIoResourceAttributes mergeAttributes( PlexusIoResourceAttrib { return base; } - SimpleResourceAttributes result; if ( base == null ) { - result = new SimpleResourceAttributes(); + return new SimpleResourceAttributes( + override.getUserId() != null && override.getUserId() != -1 + ? override.getUserId() + : def != null && def.getUserId() != null && def.getUserId() != -1 + ? def.getUserId() + : null, + override.getUserName() != null + ? override.getUserName() + : def != null + ? def.getUserName() + : null, + override.getGroupId() != null && override.getGroupId() != -1 + ? override.getGroupId() + : def != null && def.getGroupId() != null && def.getGroupId() != -1 + ? def.getGroupId() + : null, + override.getGroupName() != null + ? override.getGroupName() + : def != null + ? def.getGroupName() + : null, + override.getOctalMode() ); } else { - result = new SimpleResourceAttributes( base.getUserId(), base.getUserName(), base.getGroupId(), - base.getGroupName(), base.getOctalMode() ); - result.setSymbolicLink( base.isSymbolicLink() ); + Integer uid = override.getUserId() != null && override.getUserId() != -1 + ? override.getUserId() + : base.getUserId() != null && base.getUserId() != -1 + ? base.getUserId() + : def.getUserId() != null && def.getUserId() != -1 + ? def.getUserId() + : null; + String uname = override.getUserName() != null + ? override.getUserName() + : base.getUserName() != null + ? base.getUserName() + : def.getUserName(); + Integer gid = override.getGroupId() != null && override.getGroupId() != -1 + ? override.getGroupId() + : base.getGroupId() != null && base.getGroupId() != -1 + ? base.getGroupId() + : def.getGroupId() != null && def.getGroupId() != -1 + ? def.getGroupId() + : null; + String gname = override.getGroupName() != null + ? override.getGroupName() + : base.getGroupName() != null + ? base.getGroupName() + : def.getGroupName(); + int mode = override.getOctalMode() > 0 + ? override.getOctalMode() + : base.getOctalMode() >= 0 + ? base.getOctalMode() + : def.getOctalMode(); + if ( base instanceof FileAttributes ) + { + return new UserGroupModeFileAttributes( uid, uname, gid, gname, mode, (FileAttributes) base ); + } + else + { + return new SimpleResourceAttributes( uid, uname, gid, gname, mode, base.isSymbolicLink() ); + } } - - if ( override.getGroupId() != null && override.getGroupId() != -1 ) - { - result.setGroupId( override.getGroupId() ); - } - - if ( def != null && def.getGroupId() >= 0 && ( result.getGroupId() == null || result.getGroupId() < 0 ) ) - { - result.setGroupId( def.getGroupId() ); - } - - if ( override.getGroupName() != null ) - { - result.setGroupName( override.getGroupName() ); - } - - if ( def != null && result.getGroupName() == null ) - { - result.setGroupName( def.getGroupName() ); - } - - if ( override.getUserId() != null && override.getUserId() != -1 ) - { - result.setUserId( override.getUserId() ); - } - - if ( def != null && def.getUserId() >= 0 && ( result.getUserId() == null || result.getUserId() < 0 ) ) - { - result.setUserId( def.getUserId() ); - } - - if ( override.getUserName() != null ) - { - result.setUserName( override.getUserName() ); - } - - if ( def != null && result.getUserName() == null ) - { - result.setUserName( def.getUserName() ); - } - - if ( override.getOctalMode() > 0 ) - { - result.setOctalMode( override.getOctalMode() ); - } - - if ( def != null && result.getOctalMode() < 0 ) - { - result.setOctalMode( def.getOctalMode() ); - } - - return result; } public static boolean isGroupExecutableInOctal( int mode ) @@ -158,11 +159,16 @@ public static boolean isOctalModeEnabled( int mode, int targetMode ) return ( mode & targetMode ) != 0; } - @SuppressWarnings( { "UnusedDeclaration" } ) public static PlexusIoResourceAttributes getFileAttributes( File file ) throws IOException { - Map byPath = getFileAttributesByPath( file, false ); + return getFileAttributes( file, false ); + } + + public static PlexusIoResourceAttributes getFileAttributes( File file, boolean followLinks ) + throws IOException + { + Map byPath = getFileAttributesByPath( file, false, followLinks ); final PlexusIoResourceAttributes o = byPath.get( file.getAbsolutePath() ); if ( o == null ) { @@ -184,8 +190,15 @@ Map getFileAttributesByPath( @Nonnull File d boolean recursive ) throws IOException { - Map userCache = new HashMap<>(); - Map groupCache = new HashMap<>(); + return getFileAttributesByPath( dir, recursive, false ); + } + + public static @Nonnull + Map getFileAttributesByPath( @Nonnull File dir, + boolean recursive, + boolean followLinks ) + throws IOException + { final List fileAndDirectoryNames; if ( recursive && dir.isDirectory() ) { @@ -200,8 +213,7 @@ Map getFileAttributesByPath( @Nonnull File d for ( String fileAndDirectoryName : fileAndDirectoryNames ) { - attributesByPath.put( fileAndDirectoryName, - new FileAttributes( new File( fileAndDirectoryName ), userCache, groupCache ) ); + attributesByPath.put( fileAndDirectoryName, new FileAttributes( new File( fileAndDirectoryName ), followLinks ) ); } return attributesByPath; } diff --git a/src/main/java/org/codehaus/plexus/components/io/attributes/PlexusIoResourceAttributes.java b/src/main/java/org/codehaus/plexus/components/io/attributes/PlexusIoResourceAttributes.java index 21b29db9..4470ae6b 100644 --- a/src/main/java/org/codehaus/plexus/components/io/attributes/PlexusIoResourceAttributes.java +++ b/src/main/java/org/codehaus/plexus/components/io/attributes/PlexusIoResourceAttributes.java @@ -74,7 +74,7 @@ public interface PlexusIoResourceAttributes */ int getOctalMode(); - @Nonnull + //@Nonnull //String getOctalModeString(); /** diff --git a/src/main/java/org/codehaus/plexus/components/io/attributes/SimpleResourceAttributes.java b/src/main/java/org/codehaus/plexus/components/io/attributes/SimpleResourceAttributes.java index 301905e5..a92d7411 100644 --- a/src/main/java/org/codehaus/plexus/components/io/attributes/SimpleResourceAttributes.java +++ b/src/main/java/org/codehaus/plexus/components/io/attributes/SimpleResourceAttributes.java @@ -46,6 +46,16 @@ public SimpleResourceAttributes( Integer uid, String userName, Integer gid, Stri this.mode = mode; } + public SimpleResourceAttributes( Integer uid, String userName, Integer gid, String groupName, int mode, boolean isSymbolicLink ) + { + this.uid = uid; + this.userName = userName; + this.gid = gid; + this.groupName = groupName; + this.mode = mode; + this.isSymbolicLink = isSymbolicLink; + } + public static PlexusIoResourceAttributes lastResortDummyAttributesForBrokenOS() { return new SimpleResourceAttributes(); diff --git a/src/main/java/org/codehaus/plexus/components/io/attributes/UserGroupModeFileAttributes.java b/src/main/java/org/codehaus/plexus/components/io/attributes/UserGroupModeFileAttributes.java new file mode 100644 index 00000000..37984b17 --- /dev/null +++ b/src/main/java/org/codehaus/plexus/components/io/attributes/UserGroupModeFileAttributes.java @@ -0,0 +1,47 @@ +package org.codehaus.plexus.components.io.attributes; + +/* + * Copyright 2007 The Codehaus Foundation. + * + * 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. + */ + +import javax.annotation.Nullable; + +/* + * A very simple pojo based PlexusIoResourceAttributes without any kind of backing + */ +public class UserGroupModeFileAttributes + extends FileAttributes +{ + + public UserGroupModeFileAttributes( Integer uid, String userName, Integer gid, String groupName, int mode, FileAttributes base ) + { + super( uid, userName, gid, groupName, mode, + base.isSymbolicLink(), base.isRegularFile(), base.isDirectory(), base.isOther(), + base.getPermissions(), base.getSize(), base.getLastModifiedTime() ); + } + + public String toString() + { + return String.format( + "%nResource Attributes:%n------------------------------%nuser: %s%ngroup: %s%nuid: %d%ngid: %d%nmode: %06o", + getUserName() == null ? "" : getUserName(), + getGroupName() == null ? "" : getGroupName(), + getUserId() != null ? getUserId() : 0, + getGroupId() != null ? getGroupId() : 0, + getOctalMode() ); + } + + +} diff --git a/src/main/java/org/codehaus/plexus/components/io/resources/PlexusIoFileResource.java b/src/main/java/org/codehaus/plexus/components/io/resources/PlexusIoFileResource.java index 5079b9b7..b6babcc5 100755 --- a/src/main/java/org/codehaus/plexus/components/io/resources/PlexusIoFileResource.java +++ b/src/main/java/org/codehaus/plexus/components/io/resources/PlexusIoFileResource.java @@ -22,10 +22,13 @@ import java.io.IOException; import java.io.InputStream; import java.net.URL; +import java.nio.file.attribute.FileTime; +import java.util.function.Supplier; import org.apache.commons.io.IOUtils; import org.apache.commons.io.output.DeferredFileOutputStream; import org.codehaus.plexus.components.io.attributes.AttributeUtils; +import org.codehaus.plexus.components.io.attributes.FileAttributes; import org.codehaus.plexus.components.io.attributes.PlexusIoResourceAttributes; import org.codehaus.plexus.components.io.functions.ContentSupplier; import org.codehaus.plexus.components.io.functions.FileSupplier; @@ -34,6 +37,8 @@ import javax.annotation.Nonnull; +import static java.util.Objects.requireNonNull; + /** * Implementation of {@link PlexusIoResource} for files. */ @@ -48,6 +53,9 @@ public class PlexusIoFileResource @Nonnull private final PlexusIoResourceAttributes attributes; + @Nonnull + private final FileAttributes fileAttributes; + private final ContentSupplier contentSupplier; private final DeferredFileOutputStream dfos; @@ -59,23 +67,32 @@ protected PlexusIoFileResource( @Nonnull File file, @Nonnull String name, this( file, name, attrs, null, null ); } - @SuppressWarnings( "ConstantConditions" ) PlexusIoFileResource( @Nonnull final File file, @Nonnull String name, @Nonnull PlexusIoResourceAttributes attrs, final ContentSupplier contentSupplier, final InputStreamTransformer streamTransformer ) throws IOException { - super( name, file.lastModified(), file.length(), file.isFile(), file.isDirectory(), file.exists() ); - this.file = file; + this( file, name, attrs, + new FileAttributes( file, true ), + contentSupplier, streamTransformer ); + } + PlexusIoFileResource( @Nonnull final File file, @Nonnull String name, + @Nonnull PlexusIoResourceAttributes attrs, @Nonnull FileAttributes fileAttributes, + final ContentSupplier contentSupplier, final InputStreamTransformer streamTransformer ) + throws IOException + { + super( name, fileAttributes.getLastModifiedTime().toMillis(), fileAttributes.getSize(), + fileAttributes.isRegularFile(), fileAttributes.isDirectory(), + fileAttributes.isRegularFile() || fileAttributes.isDirectory() || fileAttributes.isSymbolicLink() || fileAttributes.isOther() ); + this.file = file; + this.attributes = requireNonNull( attrs, "attributes is null for file " + file.getName() ); + this.fileAttributes = requireNonNull( fileAttributes, "fileAttributes is null for file " + file.getName() ); this.contentSupplier = contentSupplier != null ? contentSupplier : getRootContentSupplier( file ); boolean hasTransformer = streamTransformer != null && streamTransformer != identityTransformer; InputStreamTransformer transToUse = streamTransformer != null ? streamTransformer : identityTransformer; dfos = hasTransformer && file.isFile() ? asDeferredStream( this.contentSupplier, transToUse, this ) : null; - if ( attrs == null ) - throw new IllegalArgumentException( "attrs is null for file " + file.getName() ); - this.attributes = attrs; } private static DeferredFileOutputStream asDeferredStream( @Nonnull ContentSupplier supplier, @@ -157,7 +174,7 @@ public long getSize() { if ( dfos == null ) { - return getFile().length(); + return fileAttributes.getSize(); } if ( dfos.isInMemory() ) { @@ -171,17 +188,21 @@ public long getSize() public boolean isDirectory() { - return getFile().isDirectory(); + return fileAttributes.isDirectory(); } public boolean isExisting() { + if ( attributes instanceof FileAttributes ) + { + return true; + } return getFile().exists(); } public boolean isFile() { - return getFile().isFile(); + return fileAttributes.isRegularFile(); } @Nonnull @@ -190,8 +211,19 @@ public PlexusIoResourceAttributes getAttributes() return attributes; } + @Nonnull + public FileAttributes getFileAttributes() + { + return fileAttributes; + } + public long getLastModified() { + FileTime lastModified = fileAttributes.getLastModifiedTime(); + if ( lastModified != null ) + { + return lastModified.toMillis(); + } return AttributeUtils.getLastModified( getFile() ); } @@ -201,5 +233,10 @@ public boolean isSymbolicLink() return getAttributes().isSymbolicLink(); } + protected DeferredFileOutputStream getDfos() + { + return dfos; + } + private static final InputStreamTransformer identityTransformer = AbstractPlexusIoResourceCollection.identityTransformer; } \ No newline at end of file diff --git a/src/main/java/org/codehaus/plexus/components/io/resources/PlexusIoFileResourceCollection.java b/src/main/java/org/codehaus/plexus/components/io/resources/PlexusIoFileResourceCollection.java index 2293de96..b1094797 100644 --- a/src/main/java/org/codehaus/plexus/components/io/resources/PlexusIoFileResourceCollection.java +++ b/src/main/java/org/codehaus/plexus/components/io/resources/PlexusIoFileResourceCollection.java @@ -152,15 +152,13 @@ private void addResources( List result, String[] resources ) { final File dir = getBaseDir(); - final HashMap cache1 = new HashMap<>(); - final HashMap cache2 = new HashMap<>(); for ( String name : resources ) { String sourceDir = name.replace( '\\', '/' ); File f = new File( dir, sourceDir ); - PlexusIoResourceAttributes attrs = new FileAttributes( f, cache1, cache2 ); - attrs = mergeAttributes( attrs, f.isDirectory() ); + FileAttributes fattrs = new FileAttributes( f ); + PlexusIoResourceAttributes attrs = mergeAttributes( fattrs, fattrs.isDirectory() ); String remappedName = getName( name ); diff --git a/src/main/java/org/codehaus/plexus/components/io/resources/PlexusIoSymlinkResource.java b/src/main/java/org/codehaus/plexus/components/io/resources/PlexusIoSymlinkResource.java index 05a24cfd..9cdf4eda 100644 --- a/src/main/java/org/codehaus/plexus/components/io/resources/PlexusIoSymlinkResource.java +++ b/src/main/java/org/codehaus/plexus/components/io/resources/PlexusIoSymlinkResource.java @@ -1,5 +1,6 @@ package org.codehaus.plexus.components.io.resources; +import org.apache.commons.io.output.DeferredFileOutputStream; import org.codehaus.plexus.components.io.attributes.PlexusIoResourceAttributes; import org.codehaus.plexus.components.io.attributes.SymlinkUtils; import org.codehaus.plexus.components.io.functions.SymlinkDestinationSupplier; @@ -7,23 +8,107 @@ import javax.annotation.Nonnull; import java.io.File; import java.io.IOException; +import java.nio.file.Path; public class PlexusIoSymlinkResource extends PlexusIoFileResource implements SymlinkDestinationSupplier { - private final File symnlinkDestination; + private final String symLinkDestination; + private final PlexusIoFileResource targetResource; PlexusIoSymlinkResource( @Nonnull File symlinkfile, String name, @Nonnull PlexusIoResourceAttributes attrs ) - throws IOException + throws IOException { - super( symlinkfile, name, attrs ); - this.symnlinkDestination = null; + this( symlinkfile, name, attrs, symlinkfile.toPath() ); + } + + PlexusIoSymlinkResource( @Nonnull File symlinkfile, String name, @Nonnull PlexusIoResourceAttributes attrs, + Path linkPath ) + throws IOException + { + this( symlinkfile, name, attrs, linkPath, java.nio.file.Files.readSymbolicLink( linkPath ) ); + } + + private PlexusIoSymlinkResource( @Nonnull File symlinkfile, String name, @Nonnull PlexusIoResourceAttributes attrs, + Path path, Path linkPath ) + throws IOException + { + this( symlinkfile, name, attrs, linkPath.toString(), + ( PlexusIoFileResource ) ResourceFactory.createResource( path.resolveSibling( linkPath ).toFile() ) ); + } + + private PlexusIoSymlinkResource( @Nonnull File symlinkfile, String name, @Nonnull PlexusIoResourceAttributes attrs, + String symLinkDestination, PlexusIoFileResource targetResource ) + throws IOException + { + super( symlinkfile, name, attrs, targetResource.getFileAttributes(), null, null ); + this.symLinkDestination = symLinkDestination; + this.targetResource = targetResource; } public String getSymlinkDestination() throws IOException { - return symnlinkDestination == null ? SymlinkUtils.readSymbolicLink( getFile() ).getPath() : symnlinkDestination.getPath(); + return targetResource.getName(); + } + + public PlexusIoResource getTarget() + { + return targetResource; + } + + public PlexusIoResource getLink() throws IOException + { + return new PlexusIoFileResource( getFile(), getName(), getAttributes() ); + } + + @Override + public long getSize() + { + DeferredFileOutputStream dfos = getDfos(); + if ( dfos == null ) + { + return targetResource.getSize(); + } + else if ( dfos.isInMemory() ) + { + return dfos.getByteCount(); + } + else + { + return dfos.getFile().length(); + } + } + + @Override + public boolean isDirectory() + { + return targetResource.isDirectory(); + } + + @Override + public boolean isExisting() + { + return targetResource.isExisting(); + } + + @Override + public boolean isFile() + { + return targetResource.isFile(); + } + + @Override + public long getLastModified() + { + return targetResource.getLastModified(); + } + + @Nonnull + @Override + public PlexusIoResourceAttributes getAttributes() + { + return super.getAttributes(); } } diff --git a/src/main/java/org/codehaus/plexus/components/io/resources/ResourceFactory.java b/src/main/java/org/codehaus/plexus/components/io/resources/ResourceFactory.java index 5c0a7584..d8f97bba 100644 --- a/src/main/java/org/codehaus/plexus/components/io/resources/ResourceFactory.java +++ b/src/main/java/org/codehaus/plexus/components/io/resources/ResourceFactory.java @@ -1,5 +1,6 @@ package org.codehaus.plexus.components.io.resources; +import org.codehaus.plexus.components.io.attributes.FileAttributes; import org.codehaus.plexus.components.io.attributes.PlexusIoResourceAttributes; import org.codehaus.plexus.components.io.functions.ContentSupplier; import org.codehaus.plexus.components.io.functions.InputStreamTransformer; @@ -54,7 +55,8 @@ public static PlexusIoResource createResource( File f, String name, final Conten { boolean symbolicLink = attributes.isSymbolicLink(); return symbolicLink ? new PlexusIoSymlinkResource( f, name, attributes ) - : new PlexusIoFileResource( f, name, attributes, contentSupplier, inputStreamTransformer ); + : new PlexusIoFileResource( f, name, attributes, + new FileAttributes( f, true ), contentSupplier, inputStreamTransformer ); } } diff --git a/src/main/java/org/codehaus/plexus/components/io/resources/proxy/ProxyFactory.java b/src/main/java/org/codehaus/plexus/components/io/resources/proxy/ProxyFactory.java index 15597b03..4b4bf9bd 100644 --- a/src/main/java/org/codehaus/plexus/components/io/resources/proxy/ProxyFactory.java +++ b/src/main/java/org/codehaus/plexus/components/io/resources/proxy/ProxyFactory.java @@ -40,7 +40,7 @@ public static PlexusIoResource createProxy( @Nonnull PlexusIoResource target, Ob interfaces.add( ResourceAttributeSupplier.class ); return (PlexusIoResource) Proxy.newProxyInstance( PlexusIoResource.class.getClassLoader(), - interfaces.toArray( new Class[interfaces.size()] ), + interfaces.toArray( new Class[0] ), new ResourceInvocationHandler( target, alternateSupplier ) ); } } diff --git a/src/test/java/org/codehaus/plexus/components/io/attributes/AttributeUtilsTest.java b/src/test/java/org/codehaus/plexus/components/io/attributes/AttributeUtilsTest.java index dee75ad5..d3a762c2 100644 --- a/src/test/java/org/codehaus/plexus/components/io/attributes/AttributeUtilsTest.java +++ b/src/test/java/org/codehaus/plexus/components/io/attributes/AttributeUtilsTest.java @@ -54,14 +54,12 @@ public void testChmodBackAndForth() return; final File bxx = File.createTempFile( "bxx", "ff" ); AttributeUtils.chmod( bxx, 0422 ); - PlexusIoResourceAttributes firstAttrs = - new FileAttributes( bxx, new HashMap(), new HashMap() ); + PlexusIoResourceAttributes firstAttrs = new FileAttributes( bxx ); assertTrue( firstAttrs.isOwnerReadable() ); assertFalse( firstAttrs.isOwnerWritable() ); assertFalse( firstAttrs.isOwnerExecutable() ); AttributeUtils.chmod( bxx, 0777 ); - PlexusIoResourceAttributes secondAttrs = - new FileAttributes( bxx, new HashMap(), new HashMap() ); + PlexusIoResourceAttributes secondAttrs = new FileAttributes( bxx ); assertTrue( secondAttrs.isOwnerReadable() ); assertTrue( secondAttrs.isOwnerWritable() ); assertTrue( secondAttrs.isOwnerExecutable() ); diff --git a/src/test/java/org/codehaus/plexus/components/io/attributes/FileAttributesTest.java b/src/test/java/org/codehaus/plexus/components/io/attributes/FileAttributesTest.java index 8e5073c8..04867004 100644 --- a/src/test/java/org/codehaus/plexus/components/io/attributes/FileAttributesTest.java +++ b/src/test/java/org/codehaus/plexus/components/io/attributes/FileAttributesTest.java @@ -39,10 +39,8 @@ public void testGetPosixFileAttributes() } File file = new File( "." ); - Map userCache = new HashMap<>(); - Map groupCache = new HashMap<>(); - PlexusIoResourceAttributes fa = new FileAttributes( file, userCache, groupCache ); + PlexusIoResourceAttributes fa = new FileAttributes( file ); assertNotNull( fa ); } diff --git a/src/test/java/org/codehaus/plexus/components/io/resources/PlexusIoPlexusIoFileResourceTest.java b/src/test/java/org/codehaus/plexus/components/io/resources/PlexusIoPlexusIoFileResourceTest.java index f636277a..e8722a1e 100644 --- a/src/test/java/org/codehaus/plexus/components/io/resources/PlexusIoPlexusIoFileResourceTest.java +++ b/src/test/java/org/codehaus/plexus/components/io/resources/PlexusIoPlexusIoFileResourceTest.java @@ -21,10 +21,44 @@ public void testRealSymlink() final File file = new File( "src/test/resources/symlinks/src/symDir" ); PlexusIoResourceAttributes attrs = FileAttributes.uncached( file ); assertTrue( attrs.isSymbolicLink() ); - PlexusIoFileResource r = new PlexusIoFileResource( file, "symDir", attrs ); + PlexusIoResource r = ResourceFactory.createResource( file ); assertTrue( r.isSymbolicLink() ); assertTrue( r.isDirectory() ); final File target = SymlinkUtils.readSymbolicLink( file ); assertTrue( target.getName().endsWith( "targetDir" ) ); } + + public void testSymSymlinkFile() + throws IOException + { + if ( Os.isFamily( Os.FAMILY_WINDOWS ) ) + return; + final File file = new File( "src/test/resources/symlinks/src/symSymR" ); + PlexusIoResource r = ResourceFactory.createResource( file ); + assertTrue( r.isSymbolicLink() ); + assertEquals( 38, r.getSize() ); + PlexusIoResource rL = ( ( PlexusIoSymlinkResource ) r ).getLink(); + assertFalse( rL instanceof PlexusIoSymlinkResource ); + PlexusIoResource rT = ( ( PlexusIoSymlinkResource ) r ).getTarget(); + assertTrue( rT instanceof PlexusIoSymlinkResource ); + PlexusIoResource rTT = ( ( PlexusIoSymlinkResource ) rT ).getTarget(); + assertFalse( rTT instanceof PlexusIoSymlinkResource ); + } + + public void testSymlinkFile() + throws IOException + { + if ( Os.isFamily( Os.FAMILY_WINDOWS ) ) + return; + final File file = new File( "src/test/resources/symlinks/src/symR" ); + PlexusIoResource r = ResourceFactory.createResource( file ); + assertTrue( r.isSymbolicLink() ); + assertEquals( 38, r.getSize() ); + + final File file2 = new File( "src/test/resources/symlinks/src/symSymR" ); + PlexusIoResource r2 = ResourceFactory.createResource( file2 ); + assertTrue( r2.isSymbolicLink() ); + assertEquals( 38, r2.getSize() ); + PlexusIoResource r3 = ( ( PlexusIoSymlinkResource ) r2 ).getTarget(); + } } \ No newline at end of file diff --git a/src/test/resources/symlinks/src/symSymR b/src/test/resources/symlinks/src/symSymR new file mode 120000 index 00000000..95277162 --- /dev/null +++ b/src/test/resources/symlinks/src/symSymR @@ -0,0 +1 @@ +symR \ No newline at end of file From 9316dfd5f8c51ba68364aad8ded5451b1ff2118b Mon Sep 17 00:00:00 2001 From: Tamas Cservenak Date: Thu, 23 Jun 2022 10:09:26 +0200 Subject: [PATCH 15/86] Drop legacy and make components pure JSR330 (#84) Drop Plexus Container alltogether, components are now pure JSR330, also move from oldie PlexuesTestCase to Junit4 generally. --- pom.xml | 67 +++++++++++-- .../io/filemappers/DefaultFileMapper.java | 27 ++++++ .../io/filemappers/FileExtensionMapper.java | 2 + .../components/io/filemappers/FileMapper.java | 12 +-- .../io/filemappers/FlattenFileMapper.java | 2 + .../io/filemappers/IdentityMapper.java | 2 + .../io/filemappers/MergeFileMapper.java | 2 + .../io/filemappers/PrefixFileMapper.java | 2 + .../io/filemappers/RegExpFileMapper.java | 3 + .../io/filemappers/SuffixFileMapper.java | 2 + .../fileselectors/AllFilesFileSelector.java | 4 + .../io/fileselectors/DefaultFileSelector.java | 29 ++++++ .../io/fileselectors/FileSelector.java | 10 -- .../IncludeExcludeFileSelector.java | 2 + .../functions/SymlinkDestinationSupplier.java | 2 +- ...DefaultPlexusIoFileResourceCollection.java | 28 ++++++ .../io/resources/EncodingSupported.java | 2 +- .../PlexusIoFileResourceCollection.java | 3 + .../io/resources/PlexusIoResource.java | 4 +- .../resources/PlexusIoResourceCollection.java | 13 +-- .../io/resources/PlexusIoURLResource.java | 4 +- .../components/io/resources/Stream.java | 2 +- .../resources/META-INF/plexus/components.xml | 95 ------------------- .../AbstractResourceAttributesTCK.java | 11 ++- .../io/attributes/AttributeUtilsTest.java | 11 ++- .../io/attributes/FileAttributesTest.java | 6 +- .../PlexusIoResourceAttributeUtilsTest.java | 20 +++- .../io/filemappers/FileMapperTest.java | 34 ++++--- .../io/filemappers/FileSelectorTest.java | 18 ++-- .../io/filemappers/ResourcesTest.java | 15 ++- .../io/filemappers/TestSupport.java | 26 +++++ ...bstractPlexusIoResourceCollectionTest.java | 6 +- ...sIoFileSupplierResourceCollectionTest.java | 6 +- .../PlexusIoPlexusIoFileResourceTest.java | 11 ++- .../PlexusIoProxyResourceCollectionTest.java | 10 +- .../io/resources/proxy/ProxyFactoryTest.java | 15 ++- 36 files changed, 320 insertions(+), 188 deletions(-) create mode 100644 src/main/java/org/codehaus/plexus/components/io/filemappers/DefaultFileMapper.java create mode 100644 src/main/java/org/codehaus/plexus/components/io/fileselectors/DefaultFileSelector.java create mode 100644 src/main/java/org/codehaus/plexus/components/io/resources/DefaultPlexusIoFileResourceCollection.java delete mode 100644 src/main/resources/META-INF/plexus/components.xml create mode 100644 src/test/java/org/codehaus/plexus/components/io/filemappers/TestSupport.java diff --git a/pom.xml b/pom.xml index 682abcba..462db8ff 100644 --- a/pom.xml +++ b/pom.xml @@ -30,22 +30,25 @@ - true 8 + 0.3.5 + 1.7.36 + true 2022-05-02T06:11:29Z + - org.codehaus.plexus - plexus-utils - 3.4.2 + javax.inject + javax.inject + 1 + org.codehaus.plexus - plexus-container-default - test - 2.1.1 + plexus-utils + 3.4.2 com.google.code.findbugs @@ -58,17 +61,63 @@ commons-io 2.11.0 + + junit junit 4.13.2 test + + + org.hamcrest + hamcrest-core + + + + + org.hamcrest + hamcrest + 2.2 + test + + + org.slf4j + slf4j-simple + ${slf4jVersion} + test + + + + org.eclipse.sisu + org.eclipse.sisu.inject + ${sisuVersion} + test + + + com.google.inject + guice + 5.1.0 + test - + + org.eclipse.sisu + sisu-maven-plugin + ${sisuVersion} + + + index-project + + main-index + test-index + + + + org.apache.maven.plugins maven-scm-publish-plugin @@ -128,7 +177,7 @@ org.codehaus.mojo.signature - java17 + java18 1.0 diff --git a/src/main/java/org/codehaus/plexus/components/io/filemappers/DefaultFileMapper.java b/src/main/java/org/codehaus/plexus/components/io/filemappers/DefaultFileMapper.java new file mode 100644 index 00000000..2cecc8df --- /dev/null +++ b/src/main/java/org/codehaus/plexus/components/io/filemappers/DefaultFileMapper.java @@ -0,0 +1,27 @@ +package org.codehaus.plexus.components.io.filemappers; + +/* + * Copyright 2007 The Codehaus Foundation. + * + * 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. + */ + +import javax.inject.Named; + +/** + * Alias for {@link IdentityMapper} + */ +@Named +public class DefaultFileMapper extends IdentityMapper +{ +} \ No newline at end of file diff --git a/src/main/java/org/codehaus/plexus/components/io/filemappers/FileExtensionMapper.java b/src/main/java/org/codehaus/plexus/components/io/filemappers/FileExtensionMapper.java index ca4709ca..934b7b9f 100644 --- a/src/main/java/org/codehaus/plexus/components/io/filemappers/FileExtensionMapper.java +++ b/src/main/java/org/codehaus/plexus/components/io/filemappers/FileExtensionMapper.java @@ -17,10 +17,12 @@ */ import javax.annotation.Nonnull; +import javax.inject.Named; /** * An implementation of {@link FileMapper}, which changes the files extension. */ +@Named( FileExtensionMapper.ROLE_HINT ) public class FileExtensionMapper extends AbstractFileMapper { /** diff --git a/src/main/java/org/codehaus/plexus/components/io/filemappers/FileMapper.java b/src/main/java/org/codehaus/plexus/components/io/filemappers/FileMapper.java index a14b808c..d0478f80 100644 --- a/src/main/java/org/codehaus/plexus/components/io/filemappers/FileMapper.java +++ b/src/main/java/org/codehaus/plexus/components/io/filemappers/FileMapper.java @@ -21,16 +21,6 @@ */ public interface FileMapper { - /** - * Role used to register component implementations with the container. - */ - public static final String ROLE = FileMapper.class.getName(); - - /** - * The default role-hint: "default". - */ - public static final String DEFAULT_ROLE_HINT = "default"; - /** * Maps the given source name to a target name. * @@ -40,5 +30,5 @@ public interface FileMapper * @throws IllegalArgumentException * The source name is null or empty. */ - public String getMappedFileName( String pName ); + String getMappedFileName( String pName ); } \ No newline at end of file diff --git a/src/main/java/org/codehaus/plexus/components/io/filemappers/FlattenFileMapper.java b/src/main/java/org/codehaus/plexus/components/io/filemappers/FlattenFileMapper.java index 249c9fc4..93cfab98 100644 --- a/src/main/java/org/codehaus/plexus/components/io/filemappers/FlattenFileMapper.java +++ b/src/main/java/org/codehaus/plexus/components/io/filemappers/FlattenFileMapper.java @@ -17,10 +17,12 @@ */ import javax.annotation.Nonnull; +import javax.inject.Named; /** * Implementation of a flattening file mapper: Removes all directory parts. */ +@Named( FlattenFileMapper.ROLE_HINT ) public class FlattenFileMapper extends AbstractFileMapper { /** diff --git a/src/main/java/org/codehaus/plexus/components/io/filemappers/IdentityMapper.java b/src/main/java/org/codehaus/plexus/components/io/filemappers/IdentityMapper.java index f4533d69..80a025e0 100644 --- a/src/main/java/org/codehaus/plexus/components/io/filemappers/IdentityMapper.java +++ b/src/main/java/org/codehaus/plexus/components/io/filemappers/IdentityMapper.java @@ -17,10 +17,12 @@ */ import javax.annotation.Nonnull; +import javax.inject.Named; /** * Default implementation of {@link FileMapper}, which performs the identity mapping: All names are left unchanged. */ +@Named( IdentityMapper.ROLE_HINT ) public class IdentityMapper extends AbstractFileMapper { /** diff --git a/src/main/java/org/codehaus/plexus/components/io/filemappers/MergeFileMapper.java b/src/main/java/org/codehaus/plexus/components/io/filemappers/MergeFileMapper.java index a4227490..80eb1f93 100644 --- a/src/main/java/org/codehaus/plexus/components/io/filemappers/MergeFileMapper.java +++ b/src/main/java/org/codehaus/plexus/components/io/filemappers/MergeFileMapper.java @@ -17,10 +17,12 @@ */ import javax.annotation.Nonnull; +import javax.inject.Named; /** * A file mapper, which maps to a constant target name. */ +@Named( MergeFileMapper.ROLE_HINT ) public class MergeFileMapper extends AbstractFileMapper { /** diff --git a/src/main/java/org/codehaus/plexus/components/io/filemappers/PrefixFileMapper.java b/src/main/java/org/codehaus/plexus/components/io/filemappers/PrefixFileMapper.java index 389a39c7..3f9112e7 100644 --- a/src/main/java/org/codehaus/plexus/components/io/filemappers/PrefixFileMapper.java +++ b/src/main/java/org/codehaus/plexus/components/io/filemappers/PrefixFileMapper.java @@ -17,10 +17,12 @@ */ import javax.annotation.Nonnull; +import javax.inject.Named; /** * A file mapper, which maps by adding a prefix. */ +@Named( PrefixFileMapper.ROLE_HINT ) public class PrefixFileMapper extends AbstractFileMapper { /** diff --git a/src/main/java/org/codehaus/plexus/components/io/filemappers/RegExpFileMapper.java b/src/main/java/org/codehaus/plexus/components/io/filemappers/RegExpFileMapper.java index 7e0382d7..1890e59a 100644 --- a/src/main/java/org/codehaus/plexus/components/io/filemappers/RegExpFileMapper.java +++ b/src/main/java/org/codehaus/plexus/components/io/filemappers/RegExpFileMapper.java @@ -17,12 +17,15 @@ */ import javax.annotation.Nonnull; +import javax.inject.Named; + import java.util.regex.Matcher; import java.util.regex.Pattern; /** * Implementation of a file mapper, which uses regular expressions. */ +@Named( RegExpFileMapper.ROLE_HINT ) public class RegExpFileMapper extends AbstractFileMapper { diff --git a/src/main/java/org/codehaus/plexus/components/io/filemappers/SuffixFileMapper.java b/src/main/java/org/codehaus/plexus/components/io/filemappers/SuffixFileMapper.java index 2372d840..3f5964a5 100644 --- a/src/main/java/org/codehaus/plexus/components/io/filemappers/SuffixFileMapper.java +++ b/src/main/java/org/codehaus/plexus/components/io/filemappers/SuffixFileMapper.java @@ -15,12 +15,14 @@ */ import javax.annotation.Nonnull; +import javax.inject.Named; /** * A file mapper, which maps by adding a suffix to the filename. * If the filename contains dot, the suffix will be added before. * Example: {@code directory/archive.tar.gz => directory/archivesuffix.tar.gz} */ +@Named( SuffixFileMapper.ROLE_HINT ) public class SuffixFileMapper extends AbstractFileMapper { /** diff --git a/src/main/java/org/codehaus/plexus/components/io/fileselectors/AllFilesFileSelector.java b/src/main/java/org/codehaus/plexus/components/io/fileselectors/AllFilesFileSelector.java index 0bcfb5b6..90110616 100644 --- a/src/main/java/org/codehaus/plexus/components/io/fileselectors/AllFilesFileSelector.java +++ b/src/main/java/org/codehaus/plexus/components/io/fileselectors/AllFilesFileSelector.java @@ -17,10 +17,14 @@ */ import javax.annotation.Nonnull; +import javax.inject.Named; +import javax.inject.Singleton; /** * The default file selector: Selects all files. */ +@Singleton +@Named( AllFilesFileSelector.ROLE_HINT ) public class AllFilesFileSelector implements FileSelector { /** diff --git a/src/main/java/org/codehaus/plexus/components/io/fileselectors/DefaultFileSelector.java b/src/main/java/org/codehaus/plexus/components/io/fileselectors/DefaultFileSelector.java new file mode 100644 index 00000000..c1292ec0 --- /dev/null +++ b/src/main/java/org/codehaus/plexus/components/io/fileselectors/DefaultFileSelector.java @@ -0,0 +1,29 @@ +package org.codehaus.plexus.components.io.fileselectors; + +/* + * Copyright 2007 The Codehaus Foundation. + * + * 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. + */ + +import javax.inject.Named; +import javax.inject.Singleton; + +/** + * Alias for {@link AllFilesFileSelector} + */ +@Singleton +@Named +public class DefaultFileSelector extends AllFilesFileSelector +{ +} \ No newline at end of file diff --git a/src/main/java/org/codehaus/plexus/components/io/fileselectors/FileSelector.java b/src/main/java/org/codehaus/plexus/components/io/fileselectors/FileSelector.java index e5cf7cf0..d0ad4af0 100644 --- a/src/main/java/org/codehaus/plexus/components/io/fileselectors/FileSelector.java +++ b/src/main/java/org/codehaus/plexus/components/io/fileselectors/FileSelector.java @@ -24,16 +24,6 @@ */ public interface FileSelector { - /** - * Role used to register component implementations with the container. - */ - public static final String ROLE = FileSelector.class.getName(); - - /** - * The default role-hint: "default". - */ - public static final String DEFAULT_ROLE_HINT = "default"; - /** * Returns, whether the given file is selected. * @param fileInfo An instance of FileInfo with the files meta data. diff --git a/src/main/java/org/codehaus/plexus/components/io/fileselectors/IncludeExcludeFileSelector.java b/src/main/java/org/codehaus/plexus/components/io/fileselectors/IncludeExcludeFileSelector.java index 309dba64..47b3f1c9 100644 --- a/src/main/java/org/codehaus/plexus/components/io/fileselectors/IncludeExcludeFileSelector.java +++ b/src/main/java/org/codehaus/plexus/components/io/fileselectors/IncludeExcludeFileSelector.java @@ -24,11 +24,13 @@ import javax.annotation.Nonnull; import javax.annotation.Nullable; +import javax.inject.Named; /** * This file selector uses a set of patterns for including/excluding * files. */ +@Named( IncludeExcludeFileSelector.ROLE_HINT ) public class IncludeExcludeFileSelector implements FileSelector { diff --git a/src/main/java/org/codehaus/plexus/components/io/functions/SymlinkDestinationSupplier.java b/src/main/java/org/codehaus/plexus/components/io/functions/SymlinkDestinationSupplier.java index 8aa8dfbb..9f5932ad 100644 --- a/src/main/java/org/codehaus/plexus/components/io/functions/SymlinkDestinationSupplier.java +++ b/src/main/java/org/codehaus/plexus/components/io/functions/SymlinkDestinationSupplier.java @@ -23,6 +23,6 @@ */ public interface SymlinkDestinationSupplier { - public String getSymlinkDestination() + String getSymlinkDestination() throws IOException; } diff --git a/src/main/java/org/codehaus/plexus/components/io/resources/DefaultPlexusIoFileResourceCollection.java b/src/main/java/org/codehaus/plexus/components/io/resources/DefaultPlexusIoFileResourceCollection.java new file mode 100644 index 00000000..44634f4c --- /dev/null +++ b/src/main/java/org/codehaus/plexus/components/io/resources/DefaultPlexusIoFileResourceCollection.java @@ -0,0 +1,28 @@ +package org.codehaus.plexus.components.io.resources; + +/* + * Copyright 2007 The Codehaus Foundation. + * + * 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. + */ + +import javax.inject.Named; + +/** + * Alias for {@link PlexusIoFileResourceCollection} + */ +@Named +public class DefaultPlexusIoFileResourceCollection + extends PlexusIoFileResourceCollection +{ +} diff --git a/src/main/java/org/codehaus/plexus/components/io/resources/EncodingSupported.java b/src/main/java/org/codehaus/plexus/components/io/resources/EncodingSupported.java index ffaa6dcc..74b1a20b 100644 --- a/src/main/java/org/codehaus/plexus/components/io/resources/EncodingSupported.java +++ b/src/main/java/org/codehaus/plexus/components/io/resources/EncodingSupported.java @@ -27,5 +27,5 @@ public interface EncodingSupported * Supplies the encoding to be used for decoding filenames/paths * @param charset The charset to use */ - public void setEncoding( Charset charset ); + void setEncoding( Charset charset ); } diff --git a/src/main/java/org/codehaus/plexus/components/io/resources/PlexusIoFileResourceCollection.java b/src/main/java/org/codehaus/plexus/components/io/resources/PlexusIoFileResourceCollection.java index b1094797..39eb46a3 100644 --- a/src/main/java/org/codehaus/plexus/components/io/resources/PlexusIoFileResourceCollection.java +++ b/src/main/java/org/codehaus/plexus/components/io/resources/PlexusIoFileResourceCollection.java @@ -16,6 +16,8 @@ * limitations under the License. */ +import javax.inject.Named; + import org.codehaus.plexus.components.io.attributes.FileAttributes; import org.codehaus.plexus.components.io.attributes.PlexusIoResourceAttributes; import org.codehaus.plexus.components.io.attributes.SimpleResourceAttributes; @@ -39,6 +41,7 @@ * Implementation of {@link PlexusIoResourceCollection} for the set * of files in a common directory. */ +@Named( PlexusIoFileResourceCollection.ROLE_HINT ) public class PlexusIoFileResourceCollection extends AbstractPlexusIoResourceCollectionWithAttributes { diff --git a/src/main/java/org/codehaus/plexus/components/io/resources/PlexusIoResource.java b/src/main/java/org/codehaus/plexus/components/io/resources/PlexusIoResource.java index 887e84f7..db1aaf17 100644 --- a/src/main/java/org/codehaus/plexus/components/io/resources/PlexusIoResource.java +++ b/src/main/java/org/codehaus/plexus/components/io/resources/PlexusIoResource.java @@ -36,12 +36,12 @@ public interface PlexusIoResource extends FileInfo, SizeSupplier, ContentSupplie /** * Unknown resource size. */ - public static final long UNKNOWN_RESOURCE_SIZE = -1; + long UNKNOWN_RESOURCE_SIZE = -1; /** * Unknown modification date */ - public static final long UNKNOWN_MODIFICATION_DATE = 0; + long UNKNOWN_MODIFICATION_DATE = 0; /** * Returns the date, when the resource was last modified, if known. diff --git a/src/main/java/org/codehaus/plexus/components/io/resources/PlexusIoResourceCollection.java b/src/main/java/org/codehaus/plexus/components/io/resources/PlexusIoResourceCollection.java index 3100d4d8..8ef060ab 100644 --- a/src/main/java/org/codehaus/plexus/components/io/resources/PlexusIoResourceCollection.java +++ b/src/main/java/org/codehaus/plexus/components/io/resources/PlexusIoResourceCollection.java @@ -25,17 +25,6 @@ */ public interface PlexusIoResourceCollection extends Iterable { - /** - * Role of the ResourceCollection component. - */ - public static final String ROLE = PlexusIoResourceCollection.class.getName(); - - /** - * Role hint of the default resource collection, which is a set - * of files in a base directory. - */ - public static final String DEFAULT_ROLE_HINT = "default"; - /** * Returns an iterator over the resources in the collection. * @return An iterator @@ -47,7 +36,7 @@ public interface PlexusIoResourceCollection extends Iterable * Returns the resources as a stream. * @return A stream for functional iteration */ - public Stream stream(); + Stream stream(); /** * Returns the resources suggested name. This is used for diff --git a/src/main/java/org/codehaus/plexus/components/io/resources/PlexusIoURLResource.java b/src/main/java/org/codehaus/plexus/components/io/resources/PlexusIoURLResource.java index d840b9e7..c8c3df5b 100644 --- a/src/main/java/org/codehaus/plexus/components/io/resources/PlexusIoURLResource.java +++ b/src/main/java/org/codehaus/plexus/components/io/resources/PlexusIoURLResource.java @@ -44,9 +44,7 @@ public InputStream getContents() } catch ( IOException e ) { - IOException ex = new IOException( getDescriptionForError( url ) ); - ex.initCause( e ); - throw ex; + throw new IOException( getDescriptionForError( url ), e ); } } diff --git a/src/main/java/org/codehaus/plexus/components/io/resources/Stream.java b/src/main/java/org/codehaus/plexus/components/io/resources/Stream.java index e3576d1f..8a4fb5b8 100644 --- a/src/main/java/org/codehaus/plexus/components/io/resources/Stream.java +++ b/src/main/java/org/codehaus/plexus/components/io/resources/Stream.java @@ -26,6 +26,6 @@ public interface Stream * @param resourceConsumer The consumer of the resource * @throws java.io.IOException . */ - public void forEach( PlexusIoResourceConsumer resourceConsumer ) throws IOException; + void forEach( PlexusIoResourceConsumer resourceConsumer ) throws IOException; } diff --git a/src/main/resources/META-INF/plexus/components.xml b/src/main/resources/META-INF/plexus/components.xml deleted file mode 100644 index 544289a7..00000000 --- a/src/main/resources/META-INF/plexus/components.xml +++ /dev/null @@ -1,95 +0,0 @@ - - - - org.codehaus.plexus.components.io.filemappers.FileMapper - identity - org.codehaus.plexus.components.io.filemappers.IdentityMapper - per-lookup - - - - org.codehaus.plexus.components.io.filemappers.FileMapper - default - org.codehaus.plexus.components.io.filemappers.IdentityMapper - per-lookup - - - - org.codehaus.plexus.components.io.filemappers.FileMapper - fileExtension - org.codehaus.plexus.components.io.filemappers.FileExtensionMapper - per-lookup - - - - org.codehaus.plexus.components.io.filemappers.FileMapper - flatten - org.codehaus.plexus.components.io.filemappers.FlattenFileMapper - per-lookup - - - - org.codehaus.plexus.components.io.filemappers.FileMapper - merge - org.codehaus.plexus.components.io.filemappers.MergeFileMapper - per-lookup - - - - org.codehaus.plexus.components.io.filemappers.FileMapper - prefix - org.codehaus.plexus.components.io.filemappers.PrefixFileMapper - per-lookup - - - - org.codehaus.plexus.components.io.filemappers.FileMapper - suffix - org.codehaus.plexus.components.io.filemappers.SuffixFileMapper - per-lookup - - - - org.codehaus.plexus.components.io.filemappers.FileMapper - regexp - org.codehaus.plexus.components.io.filemappers.RegExpFileMapper - per-lookup - - - - - org.codehaus.plexus.components.io.fileselectors.FileSelector - default - org.codehaus.plexus.components.io.fileselectors.AllFilesFileSelector - singleton - - - - org.codehaus.plexus.components.io.fileselectors.FileSelector - all - org.codehaus.plexus.components.io.fileselectors.AllFilesFileSelector - singleton - - - - org.codehaus.plexus.components.io.fileselectors.FileSelector - standard - org.codehaus.plexus.components.io.fileselectors.IncludeExcludeFileSelector - singleton - - - - - org.codehaus.plexus.components.io.resources.PlexusIoResourceCollection - default - org.codehaus.plexus.components.io.resources.PlexusIoFileResourceCollection - per-lookup - - - org.codehaus.plexus.components.io.resources.PlexusIoResourceCollection - files - org.codehaus.plexus.components.io.resources.PlexusIoFileResourceCollection - per-lookup - - - diff --git a/src/test/java/org/codehaus/plexus/components/io/attributes/AbstractResourceAttributesTCK.java b/src/test/java/org/codehaus/plexus/components/io/attributes/AbstractResourceAttributesTCK.java index 0e0351ba..5364426f 100644 --- a/src/test/java/org/codehaus/plexus/components/io/attributes/AbstractResourceAttributesTCK.java +++ b/src/test/java/org/codehaus/plexus/components/io/attributes/AbstractResourceAttributesTCK.java @@ -16,10 +16,11 @@ * limitations under the License. */ -import junit.framework.TestCase; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; public abstract class AbstractResourceAttributesTCK - extends TestCase { protected AbstractResourceAttributesTCK() @@ -31,6 +32,7 @@ protected AbstractResourceAttributesTCK() protected abstract PlexusIoResourceAttributes newAttributes( String mode ); + @Test public final void testSetOctalModeString_OwnerModes() { verifyStringOctalModeSet( "700", new boolean[] { true, true, true, false, false, false, false, false, false } ); @@ -39,6 +41,7 @@ public final void testSetOctalModeString_OwnerModes() verifyStringOctalModeSet( "200", new boolean[] { false, true, false, false, false, false, false, false, false } ); } + @Test public final void testSetOctalModeString_GroupModes() { verifyStringOctalModeSet( "070", new boolean[] { false, false, false, true, true, true, false, false, false } ); @@ -47,6 +50,7 @@ public final void testSetOctalModeString_GroupModes() verifyStringOctalModeSet( "020", new boolean[] { false, false, false, false, true, false, false, false, false } ); } + @Test public final void testSetOctalModeString_WorldModes() { verifyStringOctalModeSet( "007", new boolean[] { false, false, false, false, false, false, true, true, true } ); @@ -55,6 +59,7 @@ public final void testSetOctalModeString_WorldModes() verifyStringOctalModeSet( "002", new boolean[] { false, false, false, false, false, false, false, true, false } ); } + @Test public final void testSetOctalMode_OwnerModes() { verifyOctalModeSet( "700", new boolean[] { true, true, true, false, false, false, false, false, false } ); @@ -63,6 +68,7 @@ public final void testSetOctalMode_OwnerModes() verifyOctalModeSet( "200", new boolean[] { false, true, false, false, false, false, false, false, false } ); } + @Test public final void testSetOctalMode_GroupModes() { verifyOctalModeSet( "070", new boolean[] { false, false, false, true, true, true, false, false, false } ); @@ -71,6 +77,7 @@ public final void testSetOctalMode_GroupModes() verifyOctalModeSet( "020", new boolean[] { false, false, false, false, true, false, false, false, false } ); } + @Test public final void testSetOctalMode_WorldModes() { verifyOctalModeSet( "007", new boolean[] { false, false, false, false, false, false, true, true, true } ); diff --git a/src/test/java/org/codehaus/plexus/components/io/attributes/AttributeUtilsTest.java b/src/test/java/org/codehaus/plexus/components/io/attributes/AttributeUtilsTest.java index d3a762c2..ff79285b 100644 --- a/src/test/java/org/codehaus/plexus/components/io/attributes/AttributeUtilsTest.java +++ b/src/test/java/org/codehaus/plexus/components/io/attributes/AttributeUtilsTest.java @@ -1,7 +1,7 @@ package org.codehaus.plexus.components.io.attributes; -import junit.framework.TestCase; import org.codehaus.plexus.util.Os; +import org.junit.Test; import java.io.File; import java.io.IOException; @@ -9,12 +9,15 @@ import java.util.HashMap; import java.util.Set; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + /** * @author Kristian Rosenvold */ public class AttributeUtilsTest - extends TestCase { + @Test public void testMiscPatterns() throws Exception { @@ -24,6 +27,7 @@ public void testMiscPatterns() assertTrue( permissions.contains( PosixFilePermission.OTHERS_READ ) ); } + @Test public void testMorePatterns() throws Exception { final Set permissions = AttributeUtils.getPermissions( 0241 ); @@ -32,6 +36,7 @@ public void testMorePatterns() throws Exception assertTrue( permissions.contains( PosixFilePermission.OTHERS_EXECUTE ) ); } + @Test public void testEvenMorePatterns() throws Exception { final Set permissions = AttributeUtils.getPermissions( 0412 ); @@ -40,6 +45,7 @@ public void testEvenMorePatterns() throws Exception assertTrue( permissions.contains( PosixFilePermission.OTHERS_WRITE ) ); } + @Test public void test777() throws Exception { @@ -47,6 +53,7 @@ public void test777() assertTrue( permissions.size() == 9 ); } + @Test public void testChmodBackAndForth() throws IOException { diff --git a/src/test/java/org/codehaus/plexus/components/io/attributes/FileAttributesTest.java b/src/test/java/org/codehaus/plexus/components/io/attributes/FileAttributesTest.java index 04867004..84206e52 100644 --- a/src/test/java/org/codehaus/plexus/components/io/attributes/FileAttributesTest.java +++ b/src/test/java/org/codehaus/plexus/components/io/attributes/FileAttributesTest.java @@ -21,14 +21,16 @@ import java.util.Map; import org.codehaus.plexus.util.Os; -import junit.framework.TestCase; +import org.junit.Test; + +import static org.junit.Assert.assertNotNull; /** * @author Kristian Rosenvold */ public class FileAttributesTest - extends TestCase { + @Test public void testGetPosixFileAttributes() throws Exception { diff --git a/src/test/java/org/codehaus/plexus/components/io/attributes/PlexusIoResourceAttributeUtilsTest.java b/src/test/java/org/codehaus/plexus/components/io/attributes/PlexusIoResourceAttributeUtilsTest.java index 573fb2d8..ba0c0023 100644 --- a/src/test/java/org/codehaus/plexus/components/io/attributes/PlexusIoResourceAttributeUtilsTest.java +++ b/src/test/java/org/codehaus/plexus/components/io/attributes/PlexusIoResourceAttributeUtilsTest.java @@ -27,14 +27,21 @@ import java.net.URL; import java.util.Map; -import junit.framework.TestCase; +import org.junit.Test; import static org.codehaus.plexus.components.io.attributes.PlexusIoResourceAttributeUtils.getFileAttributes; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; public class PlexusIoResourceAttributeUtilsTest - extends TestCase { + @Test public void testGetAttributesForThisTestClass() throws IOException { @@ -67,6 +74,7 @@ public void testGetAttributesForThisTestClass() assertEquals( System.getProperty( "user.name" ), fileAttrs.getUserName() ); } + @Test public void testDirectory() throws IOException, CommandLineException { @@ -112,6 +120,7 @@ public void testDirectory() assertNotNull( fileAttrs ); } + @Test public void testSrcResource() throws IOException { @@ -134,6 +143,8 @@ public void testSrcResource() assertTrue( pr.getOctalMode() > 0 ); } + + @Test public void testNonExistingDirectory() { File dir = new File( "src/test/noSuchDirectory" ); @@ -148,6 +159,7 @@ public void testNonExistingDirectory() } } + @Test public void testMergeAttributesWithNullBase() { PlexusIoResourceAttributes override = @@ -162,6 +174,7 @@ public void testMergeAttributesWithNullBase() assertEquals( Integer.valueOf( 1001 ), attributes.getUserId() ); } + @Test public void testMergeAttributesWithNullOverrideGroup() { final PlexusIoResourceAttributes override = @@ -176,6 +189,7 @@ public void testMergeAttributesWithNullOverrideGroup() assertEquals( attributes.getUserId(), Integer.valueOf( 1001 ) ); } + @Test public void testMergeAttributesOverride() { final PlexusIoResourceAttributes blank = new SimpleResourceAttributes(); @@ -285,6 +299,7 @@ public void testMergeAttributesOverride() assertEquals( 0111, attributes.getOctalMode() ); } + @Test public void testFileAttributes() throws IOException { @@ -299,6 +314,7 @@ public void testFileAttributes() } } + @Test public void testMergeAttributesDefault() { final PlexusIoResourceAttributes blank = new SimpleResourceAttributes( null, null, null, null, 0 ); diff --git a/src/test/java/org/codehaus/plexus/components/io/filemappers/FileMapperTest.java b/src/test/java/org/codehaus/plexus/components/io/filemappers/FileMapperTest.java index a19a683c..0e398e70 100644 --- a/src/test/java/org/codehaus/plexus/components/io/filemappers/FileMapperTest.java +++ b/src/test/java/org/codehaus/plexus/components/io/filemappers/FileMapperTest.java @@ -19,12 +19,14 @@ import java.lang.reflect.UndeclaredThrowableException; import java.util.Arrays; -import org.codehaus.plexus.PlexusTestCase; +import org.junit.Test; + +import static org.junit.Assert.fail; /** * Test case for the various file mappers. */ -public class FileMapperTest extends PlexusTestCase +public class FileMapperTest extends TestSupport { protected void testFileMapper( FileMapper pMapper, String[] pInput, String[] pOutput ) { @@ -73,6 +75,7 @@ protected void testFileMapper( FileMapper pMapper, String[] pInput, String[] pOu new String[] { null, "", "a", "xyz.gif", "b/a", "b/xyz.gif", "b\\a", "b\\xyz.gif", "c.c/a", "c.c/xyz.gif", "c.c\\a", "c.c\\xyz.gif" }; + @Test public void testIdentityMapper() throws Exception { final String[] results = getIdentityResults(); @@ -87,14 +90,16 @@ private String[] getIdentityResults() return results; } + @Test public void testDefaultMapper() throws Exception { final String[] results = getIdentityResults(); - testFileMapper( (FileMapper) lookup( FileMapper.ROLE ), SAMPLES, results ); - testFileMapper( (FileMapper) lookup( FileMapper.ROLE, IdentityMapper.ROLE_HINT ), SAMPLES, results ); - testFileMapper( (FileMapper) lookup( FileMapper.ROLE, FileMapper.DEFAULT_ROLE_HINT ), SAMPLES, results ); + testFileMapper( (FileMapper) lookup( FileMapper.class ), SAMPLES, results ); + testFileMapper( (FileMapper) lookup( FileMapper.class, IdentityMapper.ROLE_HINT ), SAMPLES, results ); + testFileMapper( (FileMapper) lookup( FileMapper.class ), SAMPLES, results ); } + @Test public void testFileExtensionMapper() throws Exception { final String[] results = getIdentityResults(); @@ -107,7 +112,7 @@ public void testFileExtensionMapper() throws Exception results[i] = results[i].substring( 0, results[i].length() - ".gif".length() ) + ".png"; } testFileExtensionMapper( results, new FileExtensionMapper() ); - testFileExtensionMapper( results, (FileExtensionMapper) lookup( FileMapper.ROLE, FileExtensionMapper.ROLE_HINT ) ); + testFileExtensionMapper( results, (FileExtensionMapper) lookup( FileMapper.class, FileExtensionMapper.ROLE_HINT ) ); } private void testFileExtensionMapper( final String[] results, final FileExtensionMapper mapper ) @@ -118,13 +123,14 @@ private void testFileExtensionMapper( final String[] results, final FileExtensio testFileMapper( mapper, SAMPLES, results ); } + @Test public void testFlattenMapper() throws Exception { final String[] results = getIdentityResults(); results[4] = results[6] = results[8] = results[10] = results[2]; results[5] = results[7] = results[9] = results[11] = results[3]; testFileMapper( new FlattenFileMapper(), SAMPLES, results ); - testFileMapper( (FileMapper) lookup( FileMapper.ROLE, FlattenFileMapper.ROLE_HINT ), SAMPLES, results ); + testFileMapper( (FileMapper) lookup( FileMapper.class, FlattenFileMapper.ROLE_HINT ), SAMPLES, results ); } private void testMergeMapper( String pTargetName, String[] pResults, MergeFileMapper pMapper ) @@ -133,6 +139,7 @@ private void testMergeMapper( String pTargetName, String[] pResults, MergeFileMa testFileMapper( pMapper, SAMPLES, pResults ); } + @Test public void testMergeMapper() throws Exception { final String[] results = getIdentityResults(); @@ -142,15 +149,16 @@ public void testMergeMapper() throws Exception results[i] = targetName; } testMergeMapper( targetName, results, new MergeFileMapper() ); - testMergeMapper( targetName, results, (MergeFileMapper) lookup( FileMapper.ROLE, MergeFileMapper.ROLE_HINT ) ); + testMergeMapper( targetName, results, (MergeFileMapper) lookup( FileMapper.class, MergeFileMapper.ROLE_HINT ) ); } + @Test public void testPrefixMapper() throws Exception { final String prefix = "x7Rtf"; final String[] results = getIdentityResults(); testFileMapper( new PrefixFileMapper(), SAMPLES, results ); - testFileMapper( (PrefixFileMapper) lookup( FileMapper.ROLE, PrefixFileMapper.ROLE_HINT ), SAMPLES, results ); + testFileMapper( (PrefixFileMapper) lookup( FileMapper.class, PrefixFileMapper.ROLE_HINT ), SAMPLES, results ); for ( int i = 0; i < results.length; i++ ) { if ( results[i] != null ) @@ -161,11 +169,12 @@ public void testPrefixMapper() throws Exception PrefixFileMapper mapper = new PrefixFileMapper(); mapper.setPrefix( prefix ); testFileMapper( mapper, SAMPLES, results ); - mapper = (PrefixFileMapper) lookup( FileMapper.ROLE, PrefixFileMapper.ROLE_HINT ); + mapper = (PrefixFileMapper) lookup( FileMapper.class, PrefixFileMapper.ROLE_HINT ); mapper.setPrefix( prefix ); testFileMapper( mapper, SAMPLES, results ); } + @Test public void testSuffixMapper() throws Exception { final String suffix = "suffix"; @@ -178,7 +187,7 @@ public void testSuffixMapper() throws Exception SuffixFileMapper mapper = new SuffixFileMapper(); mapper.setSuffix( suffix ); testFileMapper( mapper, samples, results ); - mapper = (SuffixFileMapper) lookup( FileMapper.ROLE, SuffixFileMapper.ROLE_HINT ); + mapper = (SuffixFileMapper) lookup( FileMapper.class, SuffixFileMapper.ROLE_HINT ); mapper.setSuffix( suffix ); testFileMapper( mapper, samples, results ); } @@ -190,6 +199,7 @@ private RegExpFileMapper configure( RegExpFileMapper pMapper, String pPattern, S return pMapper; } + @Test public void testRegExpFileMapper() throws Exception { final String[] results = getIdentityResults(); @@ -200,7 +210,7 @@ public void testRegExpFileMapper() throws Exception results[11] = "c.c\\xyz.jpg"; testFileMapper( configure(new RegExpFileMapper(), "\\.gif$", ".jpg"), SAMPLES, results ); testFileMapper( configure(new RegExpFileMapper(), "^(.*)\\.gif$", "$1.jpg"), SAMPLES, results ); - testFileMapper( configure((RegExpFileMapper) lookup( FileMapper.ROLE, RegExpFileMapper.ROLE_HINT ), "\\.gif$", ".jpg"), SAMPLES, results ); + testFileMapper( configure((RegExpFileMapper) lookup( FileMapper.class, RegExpFileMapper.ROLE_HINT ), "\\.gif$", ".jpg"), SAMPLES, results ); final RegExpFileMapper mapper = configure( new RegExpFileMapper(), "c", "f" ); mapper.setReplaceAll( true ); final String[] fResults = getIdentityResults(); diff --git a/src/test/java/org/codehaus/plexus/components/io/filemappers/FileSelectorTest.java b/src/test/java/org/codehaus/plexus/components/io/filemappers/FileSelectorTest.java index 1aed4169..6ec4a98f 100644 --- a/src/test/java/org/codehaus/plexus/components/io/filemappers/FileSelectorTest.java +++ b/src/test/java/org/codehaus/plexus/components/io/filemappers/FileSelectorTest.java @@ -20,19 +20,22 @@ import java.io.InputStream; import java.net.URL; -import org.codehaus.plexus.PlexusTestCase; import org.codehaus.plexus.components.io.fileselectors.AllFilesFileSelector; import org.codehaus.plexus.components.io.fileselectors.FileSelector; import org.codehaus.plexus.components.io.fileselectors.IncludeExcludeFileSelector; import org.codehaus.plexus.components.io.resources.AbstractPlexusIoResource; +import org.junit.Test; import javax.annotation.Nonnull; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + /** * Test case for implementations of {@link FileSelector}. */ -public class FileSelectorTest extends PlexusTestCase +public class FileSelectorTest extends TestSupport { protected void testFileSelector( FileSelector pSelector, String[] pInput, boolean[] pOutput) throws IOException @@ -87,11 +90,12 @@ private boolean[] getAllTrues() return trues; } + @Test public void testAllFilesFileSelector() throws Exception { testFileSelector( new AllFilesFileSelector() ); - testFileSelector( (AllFilesFileSelector) lookup( FileSelector.ROLE, FileSelector.DEFAULT_ROLE_HINT ) ); - testFileSelector( (AllFilesFileSelector) lookup( FileSelector.ROLE, AllFilesFileSelector.ROLE_HINT ) ); + testFileSelector( (AllFilesFileSelector) lookup( FileSelector.class ) ); + testFileSelector( (AllFilesFileSelector) lookup( FileSelector.class, AllFilesFileSelector.ROLE_HINT ) ); } protected boolean[] getIncludeGifs( String[] pSamples ) @@ -127,13 +131,15 @@ protected void testFileSelector( IncludeExcludeFileSelector pSelector ) throws E testFileSelector( pSelector, SAMPLES, getExcludeBar( SAMPLES, getAllTrues() ) ); } + @Test public void testIncludeExcludeFileSelector() throws Exception { testFileSelector( new IncludeExcludeFileSelector() ); - testFileSelector( (IncludeExcludeFileSelector) lookup( FileSelector.ROLE, + testFileSelector( (IncludeExcludeFileSelector) lookup( FileSelector.class, IncludeExcludeFileSelector.ROLE_HINT ) ); } - + + @Test public void testIncludeExcludeFileSelector_SetExcludes() throws Exception { IncludeExcludeFileSelector selector = new IncludeExcludeFileSelector(); diff --git a/src/test/java/org/codehaus/plexus/components/io/filemappers/ResourcesTest.java b/src/test/java/org/codehaus/plexus/components/io/filemappers/ResourcesTest.java index 0d59eb9c..f89d4d1a 100644 --- a/src/test/java/org/codehaus/plexus/components/io/filemappers/ResourcesTest.java +++ b/src/test/java/org/codehaus/plexus/components/io/filemappers/ResourcesTest.java @@ -27,19 +27,24 @@ import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; -import org.codehaus.plexus.PlexusTestCase; import org.codehaus.plexus.components.io.resources.AbstractPlexusIoArchiveResourceCollection; import org.codehaus.plexus.components.io.resources.PlexusIoFileResource; import org.codehaus.plexus.components.io.resources.PlexusIoFileResourceCollection; import org.codehaus.plexus.components.io.resources.PlexusIoResource; import org.codehaus.plexus.components.io.resources.PlexusIoResourceCollection; import org.codehaus.plexus.util.FileUtils; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; /** * Test case for resource collections. */ -public class ResourcesTest extends PlexusTestCase +public class ResourcesTest extends TestSupport { private static final String X_PATH = "x"; private static final String A_PATH = X_PATH + "/a"; @@ -231,12 +236,12 @@ private void testFileResourceCollection( PlexusIoFileResourceCollection resource testPlexusIoResourceCollection( resourceCollection ); } + @Test public void testFileCollection() throws Exception { createFiles(); - testFileResourceCollection( (PlexusIoFileResourceCollection) lookup( PlexusIoResourceCollection.ROLE, - PlexusIoResourceCollection.DEFAULT_ROLE_HINT ) ); - testFileResourceCollection( (PlexusIoFileResourceCollection) lookup( PlexusIoResourceCollection.ROLE, + testFileResourceCollection( (PlexusIoFileResourceCollection) lookup( PlexusIoResourceCollection.class ) ); + testFileResourceCollection( (PlexusIoFileResourceCollection) lookup( PlexusIoResourceCollection.class, PlexusIoFileResourceCollection.ROLE_HINT ) ); } diff --git a/src/test/java/org/codehaus/plexus/components/io/filemappers/TestSupport.java b/src/test/java/org/codehaus/plexus/components/io/filemappers/TestSupport.java new file mode 100644 index 00000000..4ca439d6 --- /dev/null +++ b/src/test/java/org/codehaus/plexus/components/io/filemappers/TestSupport.java @@ -0,0 +1,26 @@ +package org.codehaus.plexus.components.io.filemappers; + +/* + * Copyright 2007 The Codehaus Foundation. + * + * 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. + */ + +import org.eclipse.sisu.launch.InjectedTest; + +/** + * Support for componentized testing. + */ +public abstract class TestSupport extends InjectedTest +{ +} \ No newline at end of file diff --git a/src/test/java/org/codehaus/plexus/components/io/resources/AbstractPlexusIoResourceCollectionTest.java b/src/test/java/org/codehaus/plexus/components/io/resources/AbstractPlexusIoResourceCollectionTest.java index f3e46263..4abda75d 100644 --- a/src/test/java/org/codehaus/plexus/components/io/resources/AbstractPlexusIoResourceCollectionTest.java +++ b/src/test/java/org/codehaus/plexus/components/io/resources/AbstractPlexusIoResourceCollectionTest.java @@ -1,7 +1,7 @@ package org.codehaus.plexus.components.io.resources; -import junit.framework.TestCase; import org.codehaus.plexus.components.io.functions.InputStreamTransformer; +import org.junit.Test; import javax.annotation.Nonnull; import java.io.ByteArrayInputStream; @@ -11,13 +11,15 @@ import java.util.Arrays; import java.util.Iterator; +import static org.junit.Assert.assertEquals; + /** * @author Kristian Rosenvold */ public class AbstractPlexusIoResourceCollectionTest - extends TestCase { @SuppressWarnings( "ResultOfMethodCallIgnored" ) + @Test public void testGetIncludes() throws Exception { diff --git a/src/test/java/org/codehaus/plexus/components/io/resources/PlexusIoFileSupplierResourceCollectionTest.java b/src/test/java/org/codehaus/plexus/components/io/resources/PlexusIoFileSupplierResourceCollectionTest.java index d45762d0..954748d2 100755 --- a/src/test/java/org/codehaus/plexus/components/io/resources/PlexusIoFileSupplierResourceCollectionTest.java +++ b/src/test/java/org/codehaus/plexus/components/io/resources/PlexusIoFileSupplierResourceCollectionTest.java @@ -1,16 +1,18 @@ package org.codehaus.plexus.components.io.resources; -import junit.framework.TestCase; +import org.junit.Test; import java.io.File; import java.util.Iterator; +import static org.junit.Assert.assertTrue; + /** * @author Kristian Rosenvold */ public class PlexusIoFileSupplierResourceCollectionTest - extends TestCase { + @Test public void testGetName() throws Exception { diff --git a/src/test/java/org/codehaus/plexus/components/io/resources/PlexusIoPlexusIoFileResourceTest.java b/src/test/java/org/codehaus/plexus/components/io/resources/PlexusIoPlexusIoFileResourceTest.java index e8722a1e..96e9141e 100644 --- a/src/test/java/org/codehaus/plexus/components/io/resources/PlexusIoPlexusIoFileResourceTest.java +++ b/src/test/java/org/codehaus/plexus/components/io/resources/PlexusIoPlexusIoFileResourceTest.java @@ -6,13 +6,18 @@ import org.codehaus.plexus.components.io.attributes.FileAttributes; import org.codehaus.plexus.components.io.attributes.PlexusIoResourceAttributes; -import junit.framework.TestCase; import org.codehaus.plexus.components.io.attributes.SymlinkUtils; import org.codehaus.plexus.util.Os; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; public class PlexusIoPlexusIoFileResourceTest - extends TestCase { +{ + @Test public void testRealSymlink() throws IOException { @@ -28,6 +33,7 @@ public void testRealSymlink() assertTrue( target.getName().endsWith( "targetDir" ) ); } + @Test public void testSymSymlinkFile() throws IOException { @@ -45,6 +51,7 @@ public void testSymSymlinkFile() assertFalse( rTT instanceof PlexusIoSymlinkResource ); } + @Test public void testSymlinkFile() throws IOException { diff --git a/src/test/java/org/codehaus/plexus/components/io/resources/proxy/PlexusIoProxyResourceCollectionTest.java b/src/test/java/org/codehaus/plexus/components/io/resources/proxy/PlexusIoProxyResourceCollectionTest.java index a7f4b6d3..b4c14420 100644 --- a/src/test/java/org/codehaus/plexus/components/io/resources/proxy/PlexusIoProxyResourceCollectionTest.java +++ b/src/test/java/org/codehaus/plexus/components/io/resources/proxy/PlexusIoProxyResourceCollectionTest.java @@ -16,11 +16,11 @@ * limitations under the License. */ -import org.codehaus.plexus.PlexusTestCase; import org.codehaus.plexus.components.io.resources.AbstractPlexusIoResource; import org.codehaus.plexus.components.io.resources.AbstractPlexusIoResourceCollection; import org.codehaus.plexus.components.io.resources.PlexusIoResource; import org.codehaus.plexus.components.io.resources.Stream; +import org.junit.Test; import javax.annotation.Nonnull; import java.io.Closeable; @@ -29,17 +29,20 @@ import java.net.URL; import java.util.Iterator; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + /** * Test case for {@link PlexusIoProxyResourceCollection}. */ public class PlexusIoProxyResourceCollectionTest - extends PlexusTestCase { private final String[] SAMPLE_INCLUDES = { "junk.*", "test/**", "dir*/file.xml" }; private final String[] SAMPLE_EXCLUDES = { "*.junk", "somwhere/**" }; + @Test public void testGetDefaultFileSelector() throws Exception { @@ -103,7 +106,8 @@ public void remove() throw new UnsupportedOperationException(); } } - + + @Test public void testClosing() throws IOException { diff --git a/src/test/java/org/codehaus/plexus/components/io/resources/proxy/ProxyFactoryTest.java b/src/test/java/org/codehaus/plexus/components/io/resources/proxy/ProxyFactoryTest.java index 380585fd..035fcb31 100644 --- a/src/test/java/org/codehaus/plexus/components/io/resources/proxy/ProxyFactoryTest.java +++ b/src/test/java/org/codehaus/plexus/components/io/resources/proxy/ProxyFactoryTest.java @@ -1,6 +1,5 @@ package org.codehaus.plexus.components.io.resources.proxy; -import junit.framework.TestCase; import org.codehaus.plexus.components.io.attributes.FileAttributes; import org.codehaus.plexus.components.io.attributes.PlexusIoResourceAttributes; import org.codehaus.plexus.components.io.attributes.SimpleResourceAttributes; @@ -12,6 +11,7 @@ import org.codehaus.plexus.components.io.functions.SymlinkDestinationSupplier; import org.codehaus.plexus.components.io.resources.PlexusIoFileResource; import org.codehaus.plexus.components.io.resources.PlexusIoResource; +import org.junit.Test; import javax.annotation.Nonnull; import java.io.ByteArrayInputStream; @@ -19,10 +19,15 @@ import java.io.IOException; import java.io.InputStream; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertTrue; + public class ProxyFactoryTest - extends TestCase { + @Test public void testCreateProxy() throws Exception { @@ -32,6 +37,7 @@ public void testCreateProxy() assertFalse( proxy instanceof SymlinkDestinationSupplier ); } + @Test public void testCreateProxyWithNameOverride() throws Exception { @@ -46,6 +52,7 @@ public String getName() assertEquals( "fred", proxy.getName() ); } + @Test public void testCreateProxyWithResourceAttributeOverride() throws Exception { @@ -61,6 +68,7 @@ public PlexusIoResourceAttributes getAttributes() assertSame( s, ( (ResourceAttributeSupplier) proxy ).getAttributes() ); } + @Test public void testCreateProxyWithSizeSupplierOverride() throws Exception { @@ -76,7 +84,7 @@ public long getSize() assertEquals( 42, proxy.getSize() ); } - + @Test public void testCreateProxyWithContentSupplierOverride() throws Exception { @@ -94,6 +102,7 @@ public InputStream getContents() assertEquals( s, proxy.getContents() ); } + @Test public void testCreateProxyWithSymlinkDestinationSupplierOverride() throws Exception { From fcddc97abd888f57d85e8129c4e59d167edb639d Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Thu, 23 Jun 2022 18:15:47 +1000 Subject: [PATCH 16/86] bump version to 3.4.0 Signed-off-by: Olivier Lamy --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 462db8ff..da2271db 100644 --- a/pom.xml +++ b/pom.xml @@ -8,7 +8,7 @@ plexus-io - 3.3.2-SNAPSHOT + 3.4.0-SNAPSHOT Plexus IO Components From 15376de9340cb28590ebcb1c064e9d4598c74d79 Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Thu, 23 Jun 2022 18:17:58 +1000 Subject: [PATCH 17/86] [maven-release-plugin] prepare release plexus-io-3.4.0 --- pom.xml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index da2271db..8a10baae 100644 --- a/pom.xml +++ b/pom.xml @@ -8,7 +8,7 @@ plexus-io - 3.4.0-SNAPSHOT + 3.4.0 Plexus IO Components @@ -16,7 +16,7 @@ scm:git:git@github.com:codehaus-plexus/plexus-io.git scm:git:git@github.com:codehaus-plexus/plexus-io.git http://github.com/codehaus-plexus/plexus-io - HEAD + plexus-io-3.4.0 jira @@ -34,7 +34,7 @@ 0.3.5 1.7.36 true - 2022-05-02T06:11:29Z + 2022-06-23T08:17:51Z From 85be4bff6fd1aec192831617316b3f4d4fb73927 Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Thu, 23 Jun 2022 18:18:33 +1000 Subject: [PATCH 18/86] [maven-release-plugin] prepare for next development iteration --- pom.xml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index 8a10baae..e22f4a32 100644 --- a/pom.xml +++ b/pom.xml @@ -8,7 +8,7 @@ plexus-io - 3.4.0 + 3.4.1-SNAPSHOT Plexus IO Components @@ -16,7 +16,7 @@ scm:git:git@github.com:codehaus-plexus/plexus-io.git scm:git:git@github.com:codehaus-plexus/plexus-io.git http://github.com/codehaus-plexus/plexus-io - plexus-io-3.4.0 + HEAD jira @@ -34,7 +34,7 @@ 0.3.5 1.7.36 true - 2022-06-23T08:17:51Z + 2022-06-23T08:18:33Z From 9e1bb6bba461689eff9117732fdc8b7b79c9d33f Mon Sep 17 00:00:00 2001 From: Plamen Totev Date: Sat, 30 Jul 2022 17:49:59 +0300 Subject: [PATCH 19/86] Build with the latest JDK version Update the shared workflow to use the latest version so we always build with the latest JDK versions. --- .github/workflows/maven.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index ad0c4c22..aed2cc52 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -22,4 +22,4 @@ on: [push, pull_request] jobs: build: name: Build with Maven - uses: codehaus-plexus/.github/.github/workflows/maven.yml@v0.0.4 + uses: codehaus-plexus/.github/.github/workflows/maven.yml@master From 985020960f1a01bedd8f5441944c9fac78d08cef Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 16 Aug 2022 21:02:11 +0000 Subject: [PATCH 20/86] Bump animal-sniffer-maven-plugin from 1.21 to 1.22 Bumps [animal-sniffer-maven-plugin](https://github.com/mojohaus/animal-sniffer) from 1.21 to 1.22. - [Release notes](https://github.com/mojohaus/animal-sniffer/releases) - [Commits](https://github.com/mojohaus/animal-sniffer/compare/animal-sniffer-parent-1.21...animal-sniffer-parent-1.22) --- updated-dependencies: - dependency-name: org.codehaus.mojo:animal-sniffer-maven-plugin dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index e22f4a32..fc806851 100644 --- a/pom.xml +++ b/pom.xml @@ -164,7 +164,7 @@ org.codehaus.mojo animal-sniffer-maven-plugin - 1.21 + 1.22 sniff From 70370455f64b17651b56c233ca0a8d728dad0067 Mon Sep 17 00:00:00 2001 From: Sylwester Lachiewicz Date: Sun, 11 Sep 2022 18:47:07 +0200 Subject: [PATCH 21/86] Delete codeql-analysis.yml --- .github/workflows/codeql-analysis.yml | 67 --------------------------- 1 file changed, 67 deletions(-) delete mode 100644 .github/workflows/codeql-analysis.yml diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml deleted file mode 100644 index ffe5bb29..00000000 --- a/.github/workflows/codeql-analysis.yml +++ /dev/null @@ -1,67 +0,0 @@ -# For most projects, this workflow file will not need changing; you simply need -# to commit it to your repository. -# -# You may wish to alter this file to override the set of languages analyzed, -# or to provide custom queries or build logic. -# -# ******** NOTE ******** -# We have attempted to detect the languages in your repository. Please check -# the `language` matrix defined below to confirm you have the correct set of -# supported CodeQL languages. -# -name: "CodeQL" - -on: - push: - branches: [ master ] - pull_request: - # The branches below must be a subset of the branches above - branches: [ master ] - schedule: - - cron: '24 19 * * 0' - -jobs: - analyze: - name: Analyze - runs-on: ubuntu-latest - - strategy: - fail-fast: false - matrix: - language: [ 'java' ] - # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ] - # Learn more: - # https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed - - steps: - - name: Checkout repository - uses: actions/checkout@v3.0.2 - - # Initializes the CodeQL tools for scanning. - - name: Initialize CodeQL - uses: github/codeql-action/init@v2 - with: - languages: ${{ matrix.language }} - # If you wish to specify custom queries, you can do so here or in a config file. - # By default, queries listed here will override any specified in a config file. - # Prefix the list here with "+" to use these queries and those in the config file. - # queries: ./path/to/local/query, your-org/your-repo/queries@main - - # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). - # If this step fails, then you should remove it and run the build manually (see below) - - name: Autobuild - uses: github/codeql-action/autobuild@v2 - - # â„šī¸ Command-line programs to run using the OS shell. - # 📚 https://git.io/JvXDl - - # âœī¸ If the Autobuild fails above, remove it and uncomment the following three lines - # and modify them (or add more) to build your code if your project - # uses a compiled language - - #- run: | - # make bootstrap - # make release - - - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@v2 From 3edad298419482a3d256eef44c17e2902c44427d Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 24 Oct 2022 21:02:57 +0000 Subject: [PATCH 22/86] Bump plexus-utils from 3.4.2 to 3.5.0 Bumps [plexus-utils](https://github.com/codehaus-plexus/plexus-utils) from 3.4.2 to 3.5.0. - [Release notes](https://github.com/codehaus-plexus/plexus-utils/releases) - [Commits](https://github.com/codehaus-plexus/plexus-utils/compare/plexus-utils-3.4.2...plexus-utils-3.5.0) --- updated-dependencies: - dependency-name: org.codehaus.plexus:plexus-utils dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index fc806851..bcfcf0ac 100644 --- a/pom.xml +++ b/pom.xml @@ -48,7 +48,7 @@ org.codehaus.plexus plexus-utils - 3.4.2 + 3.5.0 com.google.code.findbugs From 2d4c703d3fef628bda2b39c5b91b3fcabb6d6a3a Mon Sep 17 00:00:00 2001 From: Guillaume Nodet Date: Mon, 19 Sep 2022 08:47:52 +0200 Subject: [PATCH 23/86] Fix link destination, fixes #89 --- .../components/io/resources/PlexusIoSymlinkResource.java | 2 +- .../io/resources/PlexusIoPlexusIoFileResourceTest.java | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/codehaus/plexus/components/io/resources/PlexusIoSymlinkResource.java b/src/main/java/org/codehaus/plexus/components/io/resources/PlexusIoSymlinkResource.java index 9cdf4eda..135ee248 100644 --- a/src/main/java/org/codehaus/plexus/components/io/resources/PlexusIoSymlinkResource.java +++ b/src/main/java/org/codehaus/plexus/components/io/resources/PlexusIoSymlinkResource.java @@ -50,7 +50,7 @@ private PlexusIoSymlinkResource( @Nonnull File symlinkfile, String name, @Nonnul public String getSymlinkDestination() throws IOException { - return targetResource.getName(); + return symLinkDestination; } public PlexusIoResource getTarget() diff --git a/src/test/java/org/codehaus/plexus/components/io/resources/PlexusIoPlexusIoFileResourceTest.java b/src/test/java/org/codehaus/plexus/components/io/resources/PlexusIoPlexusIoFileResourceTest.java index 96e9141e..4b3ba449 100644 --- a/src/test/java/org/codehaus/plexus/components/io/resources/PlexusIoPlexusIoFileResourceTest.java +++ b/src/test/java/org/codehaus/plexus/components/io/resources/PlexusIoPlexusIoFileResourceTest.java @@ -7,6 +7,7 @@ import org.codehaus.plexus.components.io.attributes.PlexusIoResourceAttributes; import org.codehaus.plexus.components.io.attributes.SymlinkUtils; +import org.codehaus.plexus.components.io.functions.SymlinkDestinationSupplier; import org.codehaus.plexus.util.Os; import org.junit.Test; @@ -31,6 +32,8 @@ public void testRealSymlink() assertTrue( r.isDirectory() ); final File target = SymlinkUtils.readSymbolicLink( file ); assertTrue( target.getName().endsWith( "targetDir" ) ); + assertTrue( r instanceof SymlinkDestinationSupplier ); + assertEquals( "targetDir/", ( ( SymlinkDestinationSupplier ) r ).getSymlinkDestination() ); } @Test From df50d9e140e9547b8da73ed23bd0268aa175911c Mon Sep 17 00:00:00 2001 From: Plamen Totev Date: Tue, 28 Feb 2023 11:11:42 +0200 Subject: [PATCH 24/86] Update build status badge --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 28c4a0b1..bc828328 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ Plexus-IO ========= -[![Build Status](https://travis-ci.org/codehaus-plexus/plexus-io.svg?branch=master)](https://travis-ci.org/codehaus-plexus/plexus-io) +[![Build Status](https://github.com/codehaus-plexus/plexus-io/actions/workflows/maven.yml/badge.svg)](https://github.com/codehaus-plexus/plexus-io/actions/workflows/maven.yml) [![Maven Central](https://img.shields.io/maven-central/v/org.codehaus.plexus/plexus-io.svg?label=Maven%20Central)](https://search.maven.org/artifact/org.codehaus.plexus/plexus-io) The current master is now at https://github.com/codehaus-plexus/plexus-io From 234dffc205c8c1d2eab7b70a2ca3e9e171aa7de5 Mon Sep 17 00:00:00 2001 From: Plamen Totev Date: Tue, 28 Feb 2023 16:42:48 +0000 Subject: [PATCH 25/86] [maven-release-plugin] prepare release plexus-io-3.4.1 --- pom.xml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index bcfcf0ac..896fe779 100644 --- a/pom.xml +++ b/pom.xml @@ -8,7 +8,7 @@ plexus-io - 3.4.1-SNAPSHOT + 3.4.1 Plexus IO Components @@ -16,7 +16,7 @@ scm:git:git@github.com:codehaus-plexus/plexus-io.git scm:git:git@github.com:codehaus-plexus/plexus-io.git http://github.com/codehaus-plexus/plexus-io - HEAD + plexus-io-3.4.1 jira @@ -34,7 +34,7 @@ 0.3.5 1.7.36 true - 2022-06-23T08:18:33Z + 2023-02-28T16:42:00Z From bf2ae989500732add2816bc3f63c27b1b60c4643 Mon Sep 17 00:00:00 2001 From: Plamen Totev Date: Tue, 28 Feb 2023 16:42:48 +0000 Subject: [PATCH 26/86] [maven-release-plugin] prepare for next development iteration --- pom.xml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index 896fe779..fb59b3f4 100644 --- a/pom.xml +++ b/pom.xml @@ -8,7 +8,7 @@ plexus-io - 3.4.1 + 3.4.2-SNAPSHOT Plexus IO Components @@ -16,7 +16,7 @@ scm:git:git@github.com:codehaus-plexus/plexus-io.git scm:git:git@github.com:codehaus-plexus/plexus-io.git http://github.com/codehaus-plexus/plexus-io - plexus-io-3.4.1 + HEAD jira @@ -34,7 +34,7 @@ 0.3.5 1.7.36 true - 2023-02-28T16:42:00Z + 2023-02-28T16:42:48Z From 70823b5244ce58cd0db64aedf8758e099cf76afd Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 2 Mar 2023 21:56:44 +0000 Subject: [PATCH 27/86] Bump plexus-utils from 3.5.0 to 3.5.1 Bumps [plexus-utils](https://github.com/codehaus-plexus/plexus-utils) from 3.5.0 to 3.5.1. - [Release notes](https://github.com/codehaus-plexus/plexus-utils/releases) - [Commits](https://github.com/codehaus-plexus/plexus-utils/compare/plexus-utils-3.5.0...plexus-utils-3.5.1) --- updated-dependencies: - dependency-name: org.codehaus.plexus:plexus-utils dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index fb59b3f4..e1e189ea 100644 --- a/pom.xml +++ b/pom.xml @@ -48,7 +48,7 @@ org.codehaus.plexus plexus-utils - 3.5.0 + 3.5.1 com.google.code.findbugs From 10a449fc78d65b15c74a1b7a93fd5bc4edb16987 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 24 Mar 2023 18:29:03 +0100 Subject: [PATCH 28/86] Bump maven-resources-plugin from 2.7 to 3.3.1 (#85) Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Sylwester Lachiewicz --- pom.xml | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/pom.xml b/pom.xml index e1e189ea..3c1f41ac 100644 --- a/pom.xml +++ b/pom.xml @@ -185,12 +185,7 @@ org.apache.maven.plugins maven-resources-plugin - - 2.7 + 3.3.1 From 32818b77d3b6fa0aa86ce55682cda614a746675c Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 27 Mar 2023 21:56:52 +0000 Subject: [PATCH 29/86] Bump animal-sniffer-maven-plugin from 1.22 to 1.23 Bumps [animal-sniffer-maven-plugin](https://github.com/mojohaus/animal-sniffer) from 1.22 to 1.23. - [Release notes](https://github.com/mojohaus/animal-sniffer/releases) - [Commits](https://github.com/mojohaus/animal-sniffer/compare/animal-sniffer-parent-1.22...1.23) --- updated-dependencies: - dependency-name: org.codehaus.mojo:animal-sniffer-maven-plugin dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 3c1f41ac..bf505e01 100644 --- a/pom.xml +++ b/pom.xml @@ -164,7 +164,7 @@ org.codehaus.mojo animal-sniffer-maven-plugin - 1.22 + 1.23 sniff From cb53f1978a8013f983df0f6ad8175ec06c7044ed Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 24 Mar 2023 21:56:37 +0000 Subject: [PATCH 30/86] Bump codehaus-plexus/.github from 0.0.4 to 0.0.5 Bumps [codehaus-plexus/.github](https://github.com/codehaus-plexus/.github) from 0.0.4 to 0.0.5. - [Release notes](https://github.com/codehaus-plexus/.github/releases) - [Commits](https://github.com/codehaus-plexus/.github.amrom.workers.devpare/v0.0.4...v0.0.5) --- updated-dependencies: - dependency-name: codehaus-plexus/.github dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- .github/workflows/release-drafter.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release-drafter.yml b/.github/workflows/release-drafter.yml index 35084c5d..02e42b3d 100644 --- a/.github/workflows/release-drafter.yml +++ b/.github/workflows/release-drafter.yml @@ -23,4 +23,4 @@ on: jobs: update_release_draft: name: Update Release Notes Draft - uses: codehaus-plexus/.github/.github/workflows/release-drafter.yml@v0.0.4 + uses: codehaus-plexus/.github/.github/workflows/release-drafter.yml@v0.0.5 From 8c1e78f6ba36e941c9f9f2c01fce5c27083d29a7 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 22 May 2023 21:56:46 +0000 Subject: [PATCH 31/86] Bump plexus from 10 to 13 Bumps [plexus](https://github.com/codehaus-plexus/plexus-pom) from 10 to 13. - [Release notes](https://github.com/codehaus-plexus/plexus-pom/releases) - [Commits](https://github.com/codehaus-plexus/plexus-pom/commits) --- updated-dependencies: - dependency-name: org.codehaus.plexus:plexus dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index bf505e01..aef9977b 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ org.codehaus.plexus plexus - 10 + 13 plexus-io From 0e03ea5ef07418cabd36743b10eddddb6c578b55 Mon Sep 17 00:00:00 2001 From: Sylwester Lachiewicz Date: Tue, 23 May 2023 00:01:08 +0200 Subject: [PATCH 32/86] Reformat code --- pom.xml | 27 +- .../io/attributes/AttributeConstants.java | 10 +- .../io/attributes/AttributeUtils.java | 129 ++---- .../io/attributes/FileAttributes.java | 275 +++++------- .../PlexusIoResourceAttributeUtils.java | 195 +++----- .../PlexusIoResourceAttributes.java | 12 +- .../attributes/SimpleResourceAttributes.java | 128 +++--- .../io/attributes/SymlinkUtils.java | 23 +- .../UserGroupModeFileAttributes.java | 43 +- .../PlexusIoProxyResourceAttributes.java | 67 ++- .../io/filemappers/AbstractFileMapper.java | 12 +- .../io/filemappers/DefaultFileMapper.java | 4 +- .../io/filemappers/FileExtensionMapper.java | 56 +-- .../components/io/filemappers/FileMapper.java | 9 +- .../io/filemappers/FlattenFileMapper.java | 27 +- .../io/filemappers/IdentityMapper.java | 16 +- .../io/filemappers/MergeFileMapper.java | 38 +- .../io/filemappers/PrefixFileMapper.java | 27 +- .../io/filemappers/RegExpFileMapper.java | 53 +-- .../io/filemappers/SuffixFileMapper.java | 45 +- .../fileselectors/AllFilesFileSelector.java | 10 +- .../io/fileselectors/DefaultFileSelector.java | 4 +- .../components/io/fileselectors/FileInfo.java | 9 +- .../io/fileselectors/FileSelector.java | 8 +- .../IncludeExcludeFileSelector.java | 116 ++--- .../io/functions/ContentSupplier.java | 3 +- .../components/io/functions/FileSupplier.java | 4 +- .../io/functions/InputStreamTransformer.java | 11 +- .../components/io/functions/NameSupplier.java | 3 +- .../functions/PlexusIoResourceConsumer.java | 5 +- .../functions/ResourceAttributeSupplier.java | 3 +- .../components/io/functions/SizeSupplier.java | 3 +- .../functions/SymlinkDestinationSupplier.java | 6 +- ...ractPlexusIoArchiveResourceCollection.java | 95 ++-- .../resources/AbstractPlexusIoResource.java | 37 +- .../AbstractPlexusIoResourceCollection.java | 162 +++---- ...xusIoResourceCollectionWithAttributes.java | 50 +-- .../io/resources/ClosingInputStream.java | 49 +-- ...DefaultPlexusIoFileResourceCollection.java | 5 +- .../components/io/resources/Deferred.java | 80 ++-- .../io/resources/EncodingSupported.java | 5 +- .../components/io/resources/LinefeedMode.java | 7 +- .../PlexusIoArchivedResourceCollection.java | 8 +- ...xusIoCompressedFileResourceCollection.java | 137 ++---- .../io/resources/PlexusIoFileResource.java | 192 ++++---- .../PlexusIoFileResourceCollection.java | 208 ++++----- .../io/resources/PlexusIoResource.java | 11 +- .../resources/PlexusIoResourceCollection.java | 12 +- .../io/resources/PlexusIoSymlinkResource.java | 96 ++-- .../io/resources/PlexusIoURLResource.java | 35 +- .../io/resources/ResourceFactory.java | 66 ++- .../components/io/resources/Stream.java | 10 +- .../resources/proxy/ForwardingIterator.java | 45 +- .../PlexusIoProxyResourceCollection.java | 168 +++---- .../io/resources/proxy/ProxyFactory.java | 35 +- .../proxy/ResourceInvocationHandler.java | 60 +-- .../AbstractResourceAttributesTCK.java | 129 +++--- .../io/attributes/AttributeUtilsTest.java | 81 ++-- .../io/attributes/FileAttributesTest.java | 21 +- .../PlexusIoResourceAttributeUtilsTest.java | 416 ++++++++---------- .../SimpleResourceAttributesTest.java | 16 +- .../io/attributes/SymlinkUtilsTest.java | 71 ++- .../io/filemappers/FileMapperTest.java | 222 +++++----- .../io/filemappers/FileSelectorTest.java | 126 ++---- .../io/filemappers/ResourcesTest.java | 228 ++++------ .../io/filemappers/TestSupport.java | 4 +- ...bstractPlexusIoResourceCollectionTest.java | 69 ++- ...sIoFileSupplierResourceCollectionTest.java | 22 +- .../PlexusIoPlexusIoFileResourceTest.java | 87 ++-- .../PlexusIoProxyResourceCollectionTest.java | 106 ++--- .../io/resources/proxy/ProxyFactoryTest.java | 144 +++--- 71 files changed, 1901 insertions(+), 2795 deletions(-) diff --git a/pom.xml b/pom.xml index aef9977b..b0762fe8 100644 --- a/pom.xml +++ b/pom.xml @@ -1,3 +1,4 @@ + 4.0.0 @@ -15,8 +16,8 @@ scm:git:git@github.com:codehaus-plexus/plexus-io.git scm:git:git@github.com:codehaus-plexus/plexus-io.git - http://github.com/codehaus-plexus/plexus-io HEAD + http://github.com/codehaus-plexus/plexus-io jira @@ -122,15 +123,17 @@ org.apache.maven.plugins maven-scm-publish-plugin - ${project.reporting.outputDirectory} + ${project.reporting.outputDirectory} + scm-publish - site-deploy + publish-scm + site-deploy @@ -147,10 +150,10 @@ enforce-java - validate enforce + validate @@ -165,22 +168,22 @@ org.codehaus.mojo animal-sniffer-maven-plugin 1.23 + + + org.codehaus.mojo.signature + java18 + 1.0 + + sniff - test check + test - - - org.codehaus.mojo.signature - java18 - 1.0 - - org.apache.maven.plugins diff --git a/src/main/java/org/codehaus/plexus/components/io/attributes/AttributeConstants.java b/src/main/java/org/codehaus/plexus/components/io/attributes/AttributeConstants.java index 95c26f22..5ff5ba1a 100644 --- a/src/main/java/org/codehaus/plexus/components/io/attributes/AttributeConstants.java +++ b/src/main/java/org/codehaus/plexus/components/io/attributes/AttributeConstants.java @@ -16,8 +16,7 @@ * limitations under the License. */ -public final class AttributeConstants -{ +public final class AttributeConstants { public static final int OCTAL_OWNER_READ = 0400; @@ -37,8 +36,5 @@ public final class AttributeConstants public static final int OCTAL_WORLD_EXECUTE = 01; - private AttributeConstants() - { - } - -} \ No newline at end of file + private AttributeConstants() {} +} diff --git a/src/main/java/org/codehaus/plexus/components/io/attributes/AttributeUtils.java b/src/main/java/org/codehaus/plexus/components/io/attributes/AttributeUtils.java index 03e7944a..37462dc3 100644 --- a/src/main/java/org/codehaus/plexus/components/io/attributes/AttributeUtils.java +++ b/src/main/java/org/codehaus/plexus/components/io/attributes/AttributeUtils.java @@ -15,6 +15,9 @@ */ package org.codehaus.plexus.components.io.attributes; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + import java.io.File; import java.io.IOException; import java.nio.file.Files; @@ -27,134 +30,96 @@ import java.util.HashSet; import java.util.Set; -import javax.annotation.Nonnull; -import javax.annotation.Nullable; - /** * @author Kristian Rosenvold */ -public class AttributeUtils -{ +public class AttributeUtils { /* Reads last-modified with proper failure handling if something goes wrong. */ - public static long getLastModified( @Nonnull File file ) - { - try - { - BasicFileAttributes basicFileAttributes = Files.readAttributes( file.toPath(), BasicFileAttributes.class ); + public static long getLastModified(@Nonnull File file) { + try { + BasicFileAttributes basicFileAttributes = Files.readAttributes(file.toPath(), BasicFileAttributes.class); return basicFileAttributes.lastModifiedTime().toMillis(); + } catch (IOException e) { + throw new RuntimeException(e); } - catch ( IOException e ) - { - throw new RuntimeException( e ); - } - } - public static void chmod( @Nonnull File file, int mode ) - throws IOException - { + public static void chmod(@Nonnull File file, int mode) throws IOException { final Path path = file.toPath(); - if ( !Files.isSymbolicLink( path ) ) - { - Files.setPosixFilePermissions( path, getPermissions( mode ) ); + if (!Files.isSymbolicLink(path)) { + Files.setPosixFilePermissions(path, getPermissions(mode)); } } @Nonnull - public static Set getPermissions( int mode ) - { + public static Set getPermissions(int mode) { Set perms = new HashSet<>(); // add owners permission - if ( ( mode & 0400 ) > 0 ) - { - perms.add( PosixFilePermission.OWNER_READ ); + if ((mode & 0400) > 0) { + perms.add(PosixFilePermission.OWNER_READ); } - if ( ( mode & 0200 ) > 0 ) - { - perms.add( PosixFilePermission.OWNER_WRITE ); + if ((mode & 0200) > 0) { + perms.add(PosixFilePermission.OWNER_WRITE); } - if ( ( mode & 0100 ) > 0 ) - { - perms.add( PosixFilePermission.OWNER_EXECUTE ); + if ((mode & 0100) > 0) { + perms.add(PosixFilePermission.OWNER_EXECUTE); } // add group permissions - if ( ( mode & 0040 ) > 0 ) - { - perms.add( PosixFilePermission.GROUP_READ ); + if ((mode & 0040) > 0) { + perms.add(PosixFilePermission.GROUP_READ); } - if ( ( mode & 0020 ) > 0 ) - { - perms.add( PosixFilePermission.GROUP_WRITE ); + if ((mode & 0020) > 0) { + perms.add(PosixFilePermission.GROUP_WRITE); } - if ( ( mode & 0010 ) > 0 ) - { - perms.add( PosixFilePermission.GROUP_EXECUTE ); + if ((mode & 0010) > 0) { + perms.add(PosixFilePermission.GROUP_EXECUTE); } // add others permissions - if ( ( mode & 0004 ) > 0 ) - { - perms.add( PosixFilePermission.OTHERS_READ ); + if ((mode & 0004) > 0) { + perms.add(PosixFilePermission.OTHERS_READ); } - if ( ( mode & 0002 ) > 0 ) - { - perms.add( PosixFilePermission.OTHERS_WRITE ); + if ((mode & 0002) > 0) { + perms.add(PosixFilePermission.OTHERS_WRITE); } - if ( ( mode & 0001 ) > 0 ) - { - perms.add( PosixFilePermission.OTHERS_EXECUTE ); + if ((mode & 0001) > 0) { + perms.add(PosixFilePermission.OTHERS_EXECUTE); } return perms; } @Nonnull - public static PosixFileAttributes getPosixFileAttributes( @Nonnull File file ) - throws IOException - { - return Files.readAttributes( file.toPath(), PosixFileAttributes.class, LinkOption.NOFOLLOW_LINKS ); + public static PosixFileAttributes getPosixFileAttributes(@Nonnull File file) throws IOException { + return Files.readAttributes(file.toPath(), PosixFileAttributes.class, LinkOption.NOFOLLOW_LINKS); } @Nonnull - public static BasicFileAttributes getFileAttributes( @Nonnull File file ) - throws IOException - { - return getFileAttributes( file.toPath() ); + public static BasicFileAttributes getFileAttributes(@Nonnull File file) throws IOException { + return getFileAttributes(file.toPath()); } - public static BasicFileAttributes getFileAttributes( Path path ) - throws IOException - { - if ( isUnix( path ) ) - { + public static BasicFileAttributes getFileAttributes(Path path) throws IOException { + if (isUnix(path)) { - try - { - return Files.readAttributes( path, PosixFileAttributes.class, LinkOption.NOFOLLOW_LINKS ); - } - catch ( UnsupportedOperationException ignore ) - { + try { + return Files.readAttributes(path, PosixFileAttributes.class, LinkOption.NOFOLLOW_LINKS); + } catch (UnsupportedOperationException ignore) { // Maybe ignoring is dramatic. Maybe not. But we do get the basic attrs anyway } } - return Files.readAttributes( path, BasicFileAttributes.class, LinkOption.NOFOLLOW_LINKS ); + return Files.readAttributes(path, BasicFileAttributes.class, LinkOption.NOFOLLOW_LINKS); } - public static boolean isUnix( Path path ) - { - return path.getFileSystem().supportedFileAttributeViews().contains( "unix" ); + public static boolean isUnix(Path path) { + return path.getFileSystem().supportedFileAttributeViews().contains("unix"); } @Nullable - public static FileOwnerAttributeView getFileOwnershipInfo( @Nonnull File file ) - throws IOException - { - try - { - return Files.getFileAttributeView( file.toPath(), FileOwnerAttributeView.class, LinkOption.NOFOLLOW_LINKS ); - } - catch ( UnsupportedOperationException e ) - { + public static FileOwnerAttributeView getFileOwnershipInfo(@Nonnull File file) throws IOException { + try { + return Files.getFileAttributeView(file.toPath(), FileOwnerAttributeView.class, LinkOption.NOFOLLOW_LINKS); + } catch (UnsupportedOperationException e) { return null; } } diff --git a/src/main/java/org/codehaus/plexus/components/io/attributes/FileAttributes.java b/src/main/java/org/codehaus/plexus/components/io/attributes/FileAttributes.java index 2b4512a3..20c8396c 100644 --- a/src/main/java/org/codehaus/plexus/components/io/attributes/FileAttributes.java +++ b/src/main/java/org/codehaus/plexus/components/io/attributes/FileAttributes.java @@ -16,12 +16,14 @@ * limitations under the License. */ +import javax.annotation.Nonnull; +import javax.annotation.Nullable; + import java.io.File; import java.io.IOException; import java.nio.file.Files; import java.nio.file.LinkOption; import java.nio.file.Path; -import java.nio.file.attribute.FileOwnerAttributeView; import java.nio.file.attribute.FileTime; import java.nio.file.attribute.PosixFilePermission; import java.security.Principal; @@ -30,19 +32,14 @@ import java.util.Map; import java.util.Set; -import javax.annotation.Nonnull; -import javax.annotation.Nullable; - /* * File attributes * Immutable */ -public class FileAttributes - implements PlexusIoResourceAttributes -{ - public static final LinkOption[] FOLLOW_LINK_OPTIONS = new LinkOption[] { }; +public class FileAttributes implements PlexusIoResourceAttributes { + public static final LinkOption[] FOLLOW_LINK_OPTIONS = new LinkOption[] {}; - public static final LinkOption[] NOFOLLOW_LINK_OPTIONS = new LinkOption[] { LinkOption.NOFOLLOW_LINKS }; + public static final LinkOption[] NOFOLLOW_LINK_OPTIONS = new LinkOption[] {LinkOption.NOFOLLOW_LINKS}; @Nullable private final Integer groupId; @@ -75,64 +72,66 @@ public class FileAttributes * @deprecated use {@link #FileAttributes(File)} and remove the unused userCache and groupCache parameters */ @Deprecated - public FileAttributes( @Nonnull File file, @Nonnull Map userCache, - @Nonnull Map groupCache ) - throws IOException - { - this( file ); + public FileAttributes( + @Nonnull File file, @Nonnull Map userCache, @Nonnull Map groupCache) + throws IOException { + this(file); } - public FileAttributes( @Nonnull File file ) - throws IOException - { - this( file, false ); + public FileAttributes(@Nonnull File file) throws IOException { + this(file, false); } - public FileAttributes( @Nonnull File file, boolean followLinks ) - throws IOException - { + public FileAttributes(@Nonnull File file, boolean followLinks) throws IOException { LinkOption[] options = followLinks ? FOLLOW_LINK_OPTIONS : NOFOLLOW_LINK_OPTIONS; Path path = file.toPath(); Set views = path.getFileSystem().supportedFileAttributeViews(); String names; - if ( views.contains( "unix" ) ) - { + if (views.contains("unix")) { names = "unix:*"; - } - else if ( views.contains( "posix" ) ) - { + } else if (views.contains("posix")) { names = "posix:*"; - } - else - { + } else { names = "basic:*"; } - Map attrs = Files.readAttributes( path, names, options ); - if ( !attrs.containsKey( "group" ) && !attrs.containsKey( "owner" ) && views.contains( "owner" ) ) - { - Map ownerAttrs = Files.readAttributes( path, "owner:*", options ); - Map newAttrs = new HashMap<>( attrs ); - newAttrs.putAll( ownerAttrs ); + Map attrs = Files.readAttributes(path, names, options); + if (!attrs.containsKey("group") && !attrs.containsKey("owner") && views.contains("owner")) { + Map ownerAttrs = Files.readAttributes(path, "owner:*", options); + Map newAttrs = new HashMap<>(attrs); + newAttrs.putAll(ownerAttrs); attrs = newAttrs; } - this.groupId = (Integer) attrs.get( "gid" ); - this.groupName = attrs.containsKey( "group" ) ? ((Principal) attrs.get( "group" ) ).getName() : null; - this.userId = (Integer) attrs.get( "uid" ); - this.userName = attrs.containsKey( "owner" ) ? ((Principal) attrs.get( "owner" ) ).getName() : null; - this.symbolicLink = (Boolean) attrs.get( "isSymbolicLink" ); - this.regularFile = (Boolean) attrs.get( "isRegularFile" ); - this.directory = (Boolean) attrs.get( "isDirectory" ); - this.other = (Boolean) attrs.get( "isOther" ); - this.octalMode = attrs.containsKey( "mode" ) ? (Integer) attrs.get( "mode" ) & 0xfff : PlexusIoResourceAttributes.UNKNOWN_OCTAL_MODE; - this.permissions = attrs.containsKey( "permissions" ) ? (Set) attrs.get( "permissions" ) : Collections.emptySet(); - this.size = (Long) attrs.get( "size" ); - this.lastModifiedTime = (FileTime) attrs.get( "lastModifiedTime" ); - } - - public FileAttributes( @Nullable Integer userId, String userName, @Nullable Integer groupId, @Nullable String groupName, - int octalMode, boolean symbolicLink, boolean regularFile, boolean directory, boolean other, - Set permissions, long size, FileTime lastModifiedTime ) - { + this.groupId = (Integer) attrs.get("gid"); + this.groupName = attrs.containsKey("group") ? ((Principal) attrs.get("group")).getName() : null; + this.userId = (Integer) attrs.get("uid"); + this.userName = attrs.containsKey("owner") ? ((Principal) attrs.get("owner")).getName() : null; + this.symbolicLink = (Boolean) attrs.get("isSymbolicLink"); + this.regularFile = (Boolean) attrs.get("isRegularFile"); + this.directory = (Boolean) attrs.get("isDirectory"); + this.other = (Boolean) attrs.get("isOther"); + this.octalMode = attrs.containsKey("mode") + ? (Integer) attrs.get("mode") & 0xfff + : PlexusIoResourceAttributes.UNKNOWN_OCTAL_MODE; + this.permissions = attrs.containsKey("permissions") + ? (Set) attrs.get("permissions") + : Collections.emptySet(); + this.size = (Long) attrs.get("size"); + this.lastModifiedTime = (FileTime) attrs.get("lastModifiedTime"); + } + + public FileAttributes( + @Nullable Integer userId, + String userName, + @Nullable Integer groupId, + @Nullable String groupName, + int octalMode, + boolean symbolicLink, + boolean regularFile, + boolean directory, + boolean other, + Set permissions, + long size, + FileTime lastModifiedTime) { this.userId = userId; this.userName = userName; this.groupId = groupId; @@ -147,214 +146,174 @@ public FileAttributes( @Nullable Integer userId, String userName, @Nullable Inte this.lastModifiedTime = lastModifiedTime; } - public static @Nonnull - PlexusIoResourceAttributes uncached( @Nonnull File file ) - throws IOException - { - return new FileAttributes( file ); + public static @Nonnull PlexusIoResourceAttributes uncached(@Nonnull File file) throws IOException { + return new FileAttributes(file); } @Nullable - public Integer getGroupId() - { + public Integer getGroupId() { return groupId; } - public boolean hasGroupId() - { + public boolean hasGroupId() { return false; } - public boolean hasUserId() - { + public boolean hasUserId() { return false; } @Nullable - public String getGroupName() - { + public String getGroupName() { return groupName; } - public Integer getUserId() - { + public Integer getUserId() { return userId; } - public String getUserName() - { + public String getUserName() { return userName; } - public boolean isGroupExecutable() - { - return containsPermission( PosixFilePermission.GROUP_EXECUTE ); + public boolean isGroupExecutable() { + return containsPermission(PosixFilePermission.GROUP_EXECUTE); } - private boolean containsPermission( PosixFilePermission groupExecute ) - { - return permissions.contains( groupExecute ); + private boolean containsPermission(PosixFilePermission groupExecute) { + return permissions.contains(groupExecute); } - public boolean isGroupReadable() - { - return containsPermission( PosixFilePermission.GROUP_READ ); + public boolean isGroupReadable() { + return containsPermission(PosixFilePermission.GROUP_READ); } - public boolean isGroupWritable() - { - return containsPermission( PosixFilePermission.GROUP_WRITE ); + public boolean isGroupWritable() { + return containsPermission(PosixFilePermission.GROUP_WRITE); } - public boolean isOwnerExecutable() - { - return containsPermission( PosixFilePermission.OWNER_EXECUTE ); + public boolean isOwnerExecutable() { + return containsPermission(PosixFilePermission.OWNER_EXECUTE); } - public boolean isOwnerReadable() - { - return containsPermission( PosixFilePermission.OWNER_READ ); + public boolean isOwnerReadable() { + return containsPermission(PosixFilePermission.OWNER_READ); } - public boolean isOwnerWritable() - { - return containsPermission( PosixFilePermission.OWNER_WRITE ); + public boolean isOwnerWritable() { + return containsPermission(PosixFilePermission.OWNER_WRITE); } - public boolean isWorldExecutable() - { - return containsPermission( PosixFilePermission.OTHERS_EXECUTE ); - + public boolean isWorldExecutable() { + return containsPermission(PosixFilePermission.OTHERS_EXECUTE); } - public boolean isWorldReadable() - { - return containsPermission( PosixFilePermission.OTHERS_READ ); + public boolean isWorldReadable() { + return containsPermission(PosixFilePermission.OTHERS_READ); } - public boolean isWorldWritable() - { - return containsPermission( PosixFilePermission.OTHERS_WRITE ); + public boolean isWorldWritable() { + return containsPermission(PosixFilePermission.OTHERS_WRITE); } - public String toString() - { + public String toString() { StringBuilder sb = new StringBuilder(); - sb.append( System.lineSeparator() ); - sb.append( "File Attributes:" ); - sb.append( System.lineSeparator() ); - sb.append( "------------------------------" ); - sb.append( System.lineSeparator() ); - sb.append( "user: " ); - sb.append( userName == null ? "" : userName ); - sb.append( System.lineSeparator() ); - sb.append( "group: " ); - sb.append( groupName == null ? "" : groupName ); - sb.append( System.lineSeparator() ); - sb.append( "uid: " ); - sb.append( hasUserId() ? Integer.toString( userId ) : "" ); - sb.append( System.lineSeparator() ); - sb.append( "gid: " ); - sb.append( hasGroupId() ? Integer.toString( groupId ) : "" ); + sb.append(System.lineSeparator()); + sb.append("File Attributes:"); + sb.append(System.lineSeparator()); + sb.append("------------------------------"); + sb.append(System.lineSeparator()); + sb.append("user: "); + sb.append(userName == null ? "" : userName); + sb.append(System.lineSeparator()); + sb.append("group: "); + sb.append(groupName == null ? "" : groupName); + sb.append(System.lineSeparator()); + sb.append("uid: "); + sb.append(hasUserId() ? Integer.toString(userId) : ""); + sb.append(System.lineSeparator()); + sb.append("gid: "); + sb.append(hasGroupId() ? Integer.toString(groupId) : ""); return sb.toString(); } - public int getOctalMode() - { + public int getOctalMode() { return octalMode; } - public int calculatePosixOctalMode() - { + public int calculatePosixOctalMode() { int result = 0; - if ( isOwnerReadable() ) - { + if (isOwnerReadable()) { result |= AttributeConstants.OCTAL_OWNER_READ; } - if ( isOwnerWritable() ) - { + if (isOwnerWritable()) { result |= AttributeConstants.OCTAL_OWNER_WRITE; } - if ( isOwnerExecutable() ) - { + if (isOwnerExecutable()) { result |= AttributeConstants.OCTAL_OWNER_EXECUTE; } - if ( isGroupReadable() ) - { + if (isGroupReadable()) { result |= AttributeConstants.OCTAL_GROUP_READ; } - if ( isGroupWritable() ) - { + if (isGroupWritable()) { result |= AttributeConstants.OCTAL_GROUP_WRITE; } - if ( isGroupExecutable() ) - { + if (isGroupExecutable()) { result |= AttributeConstants.OCTAL_GROUP_EXECUTE; } - if ( isWorldReadable() ) - { + if (isWorldReadable()) { result |= AttributeConstants.OCTAL_WORLD_READ; } - if ( isWorldWritable() ) - { + if (isWorldWritable()) { result |= AttributeConstants.OCTAL_WORLD_WRITE; } - if ( isWorldExecutable() ) - { + if (isWorldExecutable()) { result |= AttributeConstants.OCTAL_WORLD_EXECUTE; } return result; } - public String getOctalModeString() - { - return Integer.toString( getOctalMode(), 8 ); + public String getOctalModeString() { + return Integer.toString(getOctalMode(), 8); } - public boolean isSymbolicLink() - { + public boolean isSymbolicLink() { return symbolicLink; } - public boolean isRegularFile() - { + public boolean isRegularFile() { return regularFile; } - public boolean isDirectory() - { + public boolean isDirectory() { return directory; } - public boolean isOther() - { + public boolean isOther() { return other; } - public long getSize() - { + public long getSize() { return size; } - public FileTime getLastModifiedTime() - { + public FileTime getLastModifiedTime() { return lastModifiedTime; } - protected Set getPermissions() - { + protected Set getPermissions() { return permissions; } } diff --git a/src/main/java/org/codehaus/plexus/components/io/attributes/PlexusIoResourceAttributeUtils.java b/src/main/java/org/codehaus/plexus/components/io/attributes/PlexusIoResourceAttributeUtils.java index 1cc81669..1d707385 100644 --- a/src/main/java/org/codehaus/plexus/components/io/attributes/PlexusIoResourceAttributeUtils.java +++ b/src/main/java/org/codehaus/plexus/components/io/attributes/PlexusIoResourceAttributeUtils.java @@ -16,9 +16,8 @@ * limitations under the License. */ -import org.codehaus.plexus.util.FileUtils; - import javax.annotation.Nonnull; + import java.io.File; import java.io.IOException; import java.util.Collections; @@ -26,196 +25,136 @@ import java.util.List; import java.util.Map; -@SuppressWarnings( { "NullableProblems" } ) -public final class PlexusIoResourceAttributeUtils -{ +import org.codehaus.plexus.util.FileUtils; - private PlexusIoResourceAttributeUtils() - { - } +@SuppressWarnings({"NullableProblems"}) +public final class PlexusIoResourceAttributeUtils { + + private PlexusIoResourceAttributeUtils() {} - public static PlexusIoResourceAttributes mergeAttributes( PlexusIoResourceAttributes override, - PlexusIoResourceAttributes base, - PlexusIoResourceAttributes def ) - { - if ( override == null ) - { + public static PlexusIoResourceAttributes mergeAttributes( + PlexusIoResourceAttributes override, PlexusIoResourceAttributes base, PlexusIoResourceAttributes def) { + if (override == null) { return base; } - if ( base == null ) - { + if (base == null) { return new SimpleResourceAttributes( override.getUserId() != null && override.getUserId() != -1 ? override.getUserId() - : def != null && def.getUserId() != null && def.getUserId() != -1 - ? def.getUserId() - : null, - override.getUserName() != null - ? override.getUserName() - : def != null - ? def.getUserName() - : null, + : def != null && def.getUserId() != null && def.getUserId() != -1 ? def.getUserId() : null, + override.getUserName() != null ? override.getUserName() : def != null ? def.getUserName() : null, override.getGroupId() != null && override.getGroupId() != -1 ? override.getGroupId() : def != null && def.getGroupId() != null && def.getGroupId() != -1 - ? def.getGroupId() - : null, - override.getGroupName() != null - ? override.getGroupName() - : def != null - ? def.getGroupName() - : null, - override.getOctalMode() ); - } - else - { + ? def.getGroupId() + : null, + override.getGroupName() != null ? override.getGroupName() : def != null ? def.getGroupName() : null, + override.getOctalMode()); + } else { Integer uid = override.getUserId() != null && override.getUserId() != -1 ? override.getUserId() : base.getUserId() != null && base.getUserId() != -1 - ? base.getUserId() - : def.getUserId() != null && def.getUserId() != -1 - ? def.getUserId() - : null; + ? base.getUserId() + : def.getUserId() != null && def.getUserId() != -1 ? def.getUserId() : null; String uname = override.getUserName() != null ? override.getUserName() - : base.getUserName() != null - ? base.getUserName() - : def.getUserName(); + : base.getUserName() != null ? base.getUserName() : def.getUserName(); Integer gid = override.getGroupId() != null && override.getGroupId() != -1 ? override.getGroupId() : base.getGroupId() != null && base.getGroupId() != -1 - ? base.getGroupId() - : def.getGroupId() != null && def.getGroupId() != -1 - ? def.getGroupId() - : null; + ? base.getGroupId() + : def.getGroupId() != null && def.getGroupId() != -1 ? def.getGroupId() : null; String gname = override.getGroupName() != null ? override.getGroupName() - : base.getGroupName() != null - ? base.getGroupName() - : def.getGroupName(); + : base.getGroupName() != null ? base.getGroupName() : def.getGroupName(); int mode = override.getOctalMode() > 0 ? override.getOctalMode() - : base.getOctalMode() >= 0 - ? base.getOctalMode() - : def.getOctalMode(); - if ( base instanceof FileAttributes ) - { - return new UserGroupModeFileAttributes( uid, uname, gid, gname, mode, (FileAttributes) base ); - } - else - { - return new SimpleResourceAttributes( uid, uname, gid, gname, mode, base.isSymbolicLink() ); + : base.getOctalMode() >= 0 ? base.getOctalMode() : def.getOctalMode(); + if (base instanceof FileAttributes) { + return new UserGroupModeFileAttributes(uid, uname, gid, gname, mode, (FileAttributes) base); + } else { + return new SimpleResourceAttributes(uid, uname, gid, gname, mode, base.isSymbolicLink()); } } } - public static boolean isGroupExecutableInOctal( int mode ) - { - return isOctalModeEnabled( mode, AttributeConstants.OCTAL_GROUP_EXECUTE ); + public static boolean isGroupExecutableInOctal(int mode) { + return isOctalModeEnabled(mode, AttributeConstants.OCTAL_GROUP_EXECUTE); } - public static boolean isGroupReadableInOctal( int mode ) - { - return isOctalModeEnabled( mode, AttributeConstants.OCTAL_GROUP_READ ); + public static boolean isGroupReadableInOctal(int mode) { + return isOctalModeEnabled(mode, AttributeConstants.OCTAL_GROUP_READ); } - public static boolean isGroupWritableInOctal( int mode ) - { - return isOctalModeEnabled( mode, AttributeConstants.OCTAL_GROUP_WRITE ); + public static boolean isGroupWritableInOctal(int mode) { + return isOctalModeEnabled(mode, AttributeConstants.OCTAL_GROUP_WRITE); } - public static boolean isOwnerExecutableInOctal( int mode ) - { - return isOctalModeEnabled( mode, AttributeConstants.OCTAL_OWNER_EXECUTE ); + public static boolean isOwnerExecutableInOctal(int mode) { + return isOctalModeEnabled(mode, AttributeConstants.OCTAL_OWNER_EXECUTE); } - public static boolean isOwnerReadableInOctal( int mode ) - { - return isOctalModeEnabled( mode, AttributeConstants.OCTAL_OWNER_READ ); + public static boolean isOwnerReadableInOctal(int mode) { + return isOctalModeEnabled(mode, AttributeConstants.OCTAL_OWNER_READ); } - public static boolean isOwnerWritableInOctal( int mode ) - { - return isOctalModeEnabled( mode, AttributeConstants.OCTAL_OWNER_WRITE ); + public static boolean isOwnerWritableInOctal(int mode) { + return isOctalModeEnabled(mode, AttributeConstants.OCTAL_OWNER_WRITE); } - public static boolean isWorldExecutableInOctal( int mode ) - { - return isOctalModeEnabled( mode, AttributeConstants.OCTAL_WORLD_EXECUTE ); + public static boolean isWorldExecutableInOctal(int mode) { + return isOctalModeEnabled(mode, AttributeConstants.OCTAL_WORLD_EXECUTE); } - public static boolean isWorldReadableInOctal( int mode ) - { - return isOctalModeEnabled( mode, AttributeConstants.OCTAL_WORLD_READ ); + public static boolean isWorldReadableInOctal(int mode) { + return isOctalModeEnabled(mode, AttributeConstants.OCTAL_WORLD_READ); } - public static boolean isWorldWritableInOctal( int mode ) - { - return isOctalModeEnabled( mode, AttributeConstants.OCTAL_WORLD_WRITE ); + public static boolean isWorldWritableInOctal(int mode) { + return isOctalModeEnabled(mode, AttributeConstants.OCTAL_WORLD_WRITE); } - public static boolean isOctalModeEnabled( int mode, int targetMode ) - { - return ( mode & targetMode ) != 0; + public static boolean isOctalModeEnabled(int mode, int targetMode) { + return (mode & targetMode) != 0; } - public static PlexusIoResourceAttributes getFileAttributes( File file ) - throws IOException - { - return getFileAttributes( file, false ); + public static PlexusIoResourceAttributes getFileAttributes(File file) throws IOException { + return getFileAttributes(file, false); } - public static PlexusIoResourceAttributes getFileAttributes( File file, boolean followLinks ) - throws IOException - { - Map byPath = getFileAttributesByPath( file, false, followLinks ); - final PlexusIoResourceAttributes o = byPath.get( file.getAbsolutePath() ); - if ( o == null ) - { + public static PlexusIoResourceAttributes getFileAttributes(File file, boolean followLinks) throws IOException { + Map byPath = getFileAttributesByPath(file, false, followLinks); + final PlexusIoResourceAttributes o = byPath.get(file.getAbsolutePath()); + if (o == null) { // We're on a crappy old java version (5) or the OS from hell. Just "fail". return SimpleResourceAttributes.lastResortDummyAttributesForBrokenOS(); - } return o; } - public static Map getFileAttributesByPath( File dir ) - throws IOException - { - return getFileAttributesByPath( dir, true ); + public static Map getFileAttributesByPath(File dir) throws IOException { + return getFileAttributesByPath(dir, true); } - public static @Nonnull - Map getFileAttributesByPath( @Nonnull File dir, - boolean recursive ) - throws IOException - { - return getFileAttributesByPath( dir, recursive, false ); + public static @Nonnull Map getFileAttributesByPath( + @Nonnull File dir, boolean recursive) throws IOException { + return getFileAttributesByPath(dir, recursive, false); } - public static @Nonnull - Map getFileAttributesByPath( @Nonnull File dir, - boolean recursive, - boolean followLinks ) - throws IOException - { + public static @Nonnull Map getFileAttributesByPath( + @Nonnull File dir, boolean recursive, boolean followLinks) throws IOException { final List fileAndDirectoryNames; - if ( recursive && dir.isDirectory() ) - { - fileAndDirectoryNames = FileUtils.getFileAndDirectoryNames( dir, null, null, true, true, true, true ); - } - else - { - fileAndDirectoryNames = Collections.singletonList( dir.getAbsolutePath() ); + if (recursive && dir.isDirectory()) { + fileAndDirectoryNames = FileUtils.getFileAndDirectoryNames(dir, null, null, true, true, true, true); + } else { + fileAndDirectoryNames = Collections.singletonList(dir.getAbsolutePath()); } final Map attributesByPath = new LinkedHashMap<>(); - for ( String fileAndDirectoryName : fileAndDirectoryNames ) - { - attributesByPath.put( fileAndDirectoryName, new FileAttributes( new File( fileAndDirectoryName ), followLinks ) ); + for (String fileAndDirectoryName : fileAndDirectoryNames) { + attributesByPath.put(fileAndDirectoryName, new FileAttributes(new File(fileAndDirectoryName), followLinks)); } return attributesByPath; } - } diff --git a/src/main/java/org/codehaus/plexus/components/io/attributes/PlexusIoResourceAttributes.java b/src/main/java/org/codehaus/plexus/components/io/attributes/PlexusIoResourceAttributes.java index 4470ae6b..0b1dcb36 100644 --- a/src/main/java/org/codehaus/plexus/components/io/attributes/PlexusIoResourceAttributes.java +++ b/src/main/java/org/codehaus/plexus/components/io/attributes/PlexusIoResourceAttributes.java @@ -16,11 +16,9 @@ * limitations under the License. */ -import javax.annotation.Nonnull; import javax.annotation.Nullable; -public interface PlexusIoResourceAttributes -{ +public interface PlexusIoResourceAttributes { int UNKNOWN_OCTAL_MODE = -1; boolean isOwnerReadable(); @@ -46,7 +44,7 @@ public interface PlexusIoResourceAttributes * @return The unix user id, may be null ("not set"), even on unix */ Integer getUserId(); - + /** * Gets the unix group id. * @return The unix group id, may be null ("not set"), even on unix @@ -74,8 +72,8 @@ public interface PlexusIoResourceAttributes */ int getOctalMode(); - //@Nonnull - //String getOctalModeString(); + // @Nonnull + // String getOctalModeString(); /** * Indicates if this is a symbolic link element. @@ -83,4 +81,4 @@ public interface PlexusIoResourceAttributes * @return True if the file is a symlink or false if not. */ boolean isSymbolicLink(); -} \ No newline at end of file +} diff --git a/src/main/java/org/codehaus/plexus/components/io/attributes/SimpleResourceAttributes.java b/src/main/java/org/codehaus/plexus/components/io/attributes/SimpleResourceAttributes.java index a92d7411..3fdf7320 100644 --- a/src/main/java/org/codehaus/plexus/components/io/attributes/SimpleResourceAttributes.java +++ b/src/main/java/org/codehaus/plexus/components/io/attributes/SimpleResourceAttributes.java @@ -21,9 +21,7 @@ /* * A very simple pojo based PlexusIoResourceAttributes without any kind of backing */ -public class SimpleResourceAttributes - implements PlexusIoResourceAttributes -{ +public class SimpleResourceAttributes implements PlexusIoResourceAttributes { private Integer gid; @@ -37,8 +35,7 @@ public class SimpleResourceAttributes private boolean isSymbolicLink; - public SimpleResourceAttributes( Integer uid, String userName, Integer gid, String groupName, int mode ) - { + public SimpleResourceAttributes(Integer uid, String userName, Integer gid, String groupName, int mode) { this.uid = uid; this.userName = userName; this.gid = gid; @@ -46,8 +43,8 @@ public SimpleResourceAttributes( Integer uid, String userName, Integer gid, Stri this.mode = mode; } - public SimpleResourceAttributes( Integer uid, String userName, Integer gid, String groupName, int mode, boolean isSymbolicLink ) - { + public SimpleResourceAttributes( + Integer uid, String userName, Integer gid, String groupName, int mode, boolean isSymbolicLink) { this.uid = uid; this.userName = userName; this.gid = gid; @@ -56,146 +53,119 @@ public SimpleResourceAttributes( Integer uid, String userName, Integer gid, Stri this.isSymbolicLink = isSymbolicLink; } - public static PlexusIoResourceAttributes lastResortDummyAttributesForBrokenOS() - { + public static PlexusIoResourceAttributes lastResortDummyAttributesForBrokenOS() { return new SimpleResourceAttributes(); } - SimpleResourceAttributes() - { - } + SimpleResourceAttributes() {} - public int getOctalMode() - { + public int getOctalMode() { return mode; } - @Nullable public Integer getGroupId() - { + @Nullable + public Integer getGroupId() { return gid; } - @Nullable public String getGroupName() - { + @Nullable + public String getGroupName() { return groupName; } - - public Integer getUserId() - { + public Integer getUserId() { return uid; } - public String getUserName() - { + public String getUserName() { return userName; } - public boolean isGroupExecutable() - { - return PlexusIoResourceAttributeUtils.isGroupExecutableInOctal( mode ); + public boolean isGroupExecutable() { + return PlexusIoResourceAttributeUtils.isGroupExecutableInOctal(mode); } - public boolean isGroupReadable() - { - return PlexusIoResourceAttributeUtils.isGroupReadableInOctal( mode ); + public boolean isGroupReadable() { + return PlexusIoResourceAttributeUtils.isGroupReadableInOctal(mode); } - public boolean isGroupWritable() - { - return PlexusIoResourceAttributeUtils.isGroupWritableInOctal( mode ); + public boolean isGroupWritable() { + return PlexusIoResourceAttributeUtils.isGroupWritableInOctal(mode); } - public boolean isOwnerExecutable() - { - return PlexusIoResourceAttributeUtils.isOwnerExecutableInOctal( mode ); + public boolean isOwnerExecutable() { + return PlexusIoResourceAttributeUtils.isOwnerExecutableInOctal(mode); } - public boolean isOwnerReadable() - { - return PlexusIoResourceAttributeUtils.isOwnerReadableInOctal( mode ); + public boolean isOwnerReadable() { + return PlexusIoResourceAttributeUtils.isOwnerReadableInOctal(mode); } - public boolean isOwnerWritable() - { - return PlexusIoResourceAttributeUtils.isOwnerWritableInOctal( mode ); + public boolean isOwnerWritable() { + return PlexusIoResourceAttributeUtils.isOwnerWritableInOctal(mode); } - public boolean isWorldExecutable() - { - return PlexusIoResourceAttributeUtils.isWorldExecutableInOctal( mode ); + public boolean isWorldExecutable() { + return PlexusIoResourceAttributeUtils.isWorldExecutableInOctal(mode); } - public boolean isWorldReadable() - { - return PlexusIoResourceAttributeUtils.isWorldReadableInOctal( mode ); + public boolean isWorldReadable() { + return PlexusIoResourceAttributeUtils.isWorldReadableInOctal(mode); } - public boolean isWorldWritable() - { - return PlexusIoResourceAttributeUtils.isWorldWritableInOctal( mode ); + public boolean isWorldWritable() { + return PlexusIoResourceAttributeUtils.isWorldWritableInOctal(mode); } - public String getOctalModeString() - { - return Integer.toString( mode, 8 ); + public String getOctalModeString() { + return Integer.toString(mode, 8); } - public PlexusIoResourceAttributes setOctalMode( int mode ) - { + public PlexusIoResourceAttributes setOctalMode(int mode) { this.mode = mode; return this; } - public PlexusIoResourceAttributes setGroupId( Integer gid ) - { + public PlexusIoResourceAttributes setGroupId(Integer gid) { this.gid = gid; return this; } - public PlexusIoResourceAttributes setGroupName( String name ) - { + public PlexusIoResourceAttributes setGroupName(String name) { this.groupName = name; return this; } - public PlexusIoResourceAttributes setUserId( Integer uid ) - { + public PlexusIoResourceAttributes setUserId(Integer uid) { this.uid = uid; return this; } - public PlexusIoResourceAttributes setUserName( String name ) - { + public PlexusIoResourceAttributes setUserName(String name) { this.userName = name; return this; } - public PlexusIoResourceAttributes setOctalModeString( String mode ) - { - setOctalMode( Integer.parseInt( mode, 8 ) ); + public PlexusIoResourceAttributes setOctalModeString(String mode) { + setOctalMode(Integer.parseInt(mode, 8)); return this; } - public String toString() - { + public String toString() { return String.format( - "%nResource Attributes:%n------------------------------%nuser: %s%ngroup: %s%nuid: %d%ngid: %d%nmode: %06o", - userName == null ? "" : userName, - groupName == null ? "" : groupName, - uid != null ? uid : 0, - gid != null ? gid : 0, - mode ); + "%nResource Attributes:%n------------------------------%nuser: %s%ngroup: %s%nuid: %d%ngid: %d%nmode: %06o", + userName == null ? "" : userName, + groupName == null ? "" : groupName, + uid != null ? uid : 0, + gid != null ? gid : 0, + mode); } - - public void setSymbolicLink( boolean isSymbolicLink ) - { + public void setSymbolicLink(boolean isSymbolicLink) { this.isSymbolicLink = isSymbolicLink; } - public boolean isSymbolicLink() - { + public boolean isSymbolicLink() { return isSymbolicLink; } } diff --git a/src/main/java/org/codehaus/plexus/components/io/attributes/SymlinkUtils.java b/src/main/java/org/codehaus/plexus/components/io/attributes/SymlinkUtils.java index beddad07..00b6d4fe 100644 --- a/src/main/java/org/codehaus/plexus/components/io/attributes/SymlinkUtils.java +++ b/src/main/java/org/codehaus/plexus/components/io/attributes/SymlinkUtils.java @@ -16,6 +16,7 @@ package org.codehaus.plexus.components.io.attributes; import javax.annotation.Nonnull; + import java.io.File; import java.io.IOException; import java.nio.file.Files; @@ -25,8 +26,7 @@ /** * @author Kristian Rosenvold */ -public class SymlinkUtils -{ +public class SymlinkUtils { /** * Reads the target of the symbolic link * @@ -34,25 +34,16 @@ public class SymlinkUtils * @return A file that is the target of the symlink * @throws java.io.IOException */ - - public static @Nonnull - File readSymbolicLink( @Nonnull File symlink ) - throws IOException - { - final java.nio.file.Path path = java.nio.file.Files.readSymbolicLink( symlink.toPath() ); + public static @Nonnull File readSymbolicLink(@Nonnull File symlink) throws IOException { + final java.nio.file.Path path = java.nio.file.Files.readSymbolicLink(symlink.toPath()); return path.toFile(); } - public static @Nonnull - File createSymbolicLink( @Nonnull File symlink, File target ) - throws IOException - { + public static @Nonnull File createSymbolicLink(@Nonnull File symlink, File target) throws IOException { Path link = symlink.toPath(); - if ( !Files.exists( link, LinkOption.NOFOLLOW_LINKS ) ) - { - link = java.nio.file.Files.createSymbolicLink( link, target.toPath() ); + if (!Files.exists(link, LinkOption.NOFOLLOW_LINKS)) { + link = java.nio.file.Files.createSymbolicLink(link, target.toPath()); } return link.toFile(); - } } diff --git a/src/main/java/org/codehaus/plexus/components/io/attributes/UserGroupModeFileAttributes.java b/src/main/java/org/codehaus/plexus/components/io/attributes/UserGroupModeFileAttributes.java index 37984b17..df21c1a1 100644 --- a/src/main/java/org/codehaus/plexus/components/io/attributes/UserGroupModeFileAttributes.java +++ b/src/main/java/org/codehaus/plexus/components/io/attributes/UserGroupModeFileAttributes.java @@ -16,32 +16,35 @@ * limitations under the License. */ -import javax.annotation.Nullable; - /* * A very simple pojo based PlexusIoResourceAttributes without any kind of backing */ -public class UserGroupModeFileAttributes - extends FileAttributes -{ +public class UserGroupModeFileAttributes extends FileAttributes { - public UserGroupModeFileAttributes( Integer uid, String userName, Integer gid, String groupName, int mode, FileAttributes base ) - { - super( uid, userName, gid, groupName, mode, - base.isSymbolicLink(), base.isRegularFile(), base.isDirectory(), base.isOther(), - base.getPermissions(), base.getSize(), base.getLastModifiedTime() ); + public UserGroupModeFileAttributes( + Integer uid, String userName, Integer gid, String groupName, int mode, FileAttributes base) { + super( + uid, + userName, + gid, + groupName, + mode, + base.isSymbolicLink(), + base.isRegularFile(), + base.isDirectory(), + base.isOther(), + base.getPermissions(), + base.getSize(), + base.getLastModifiedTime()); } - public String toString() - { + public String toString() { return String.format( - "%nResource Attributes:%n------------------------------%nuser: %s%ngroup: %s%nuid: %d%ngid: %d%nmode: %06o", - getUserName() == null ? "" : getUserName(), - getGroupName() == null ? "" : getGroupName(), - getUserId() != null ? getUserId() : 0, - getGroupId() != null ? getGroupId() : 0, - getOctalMode() ); + "%nResource Attributes:%n------------------------------%nuser: %s%ngroup: %s%nuid: %d%ngid: %d%nmode: %06o", + getUserName() == null ? "" : getUserName(), + getGroupName() == null ? "" : getGroupName(), + getUserId() != null ? getUserId() : 0, + getGroupId() != null ? getGroupId() : 0, + getOctalMode()); } - - } diff --git a/src/main/java/org/codehaus/plexus/components/io/attributes/proxy/PlexusIoProxyResourceAttributes.java b/src/main/java/org/codehaus/plexus/components/io/attributes/proxy/PlexusIoProxyResourceAttributes.java index e579c66e..a751b36f 100644 --- a/src/main/java/org/codehaus/plexus/components/io/attributes/proxy/PlexusIoProxyResourceAttributes.java +++ b/src/main/java/org/codehaus/plexus/components/io/attributes/proxy/PlexusIoProxyResourceAttributes.java @@ -1,98 +1,81 @@ package org.codehaus.plexus.components.io.attributes.proxy; -import org.codehaus.plexus.components.io.attributes.PlexusIoResourceAttributes; - import javax.annotation.Nullable; -public class PlexusIoProxyResourceAttributes - implements PlexusIoResourceAttributes +import org.codehaus.plexus.components.io.attributes.PlexusIoResourceAttributes; +public class PlexusIoProxyResourceAttributes implements PlexusIoResourceAttributes { -{ PlexusIoResourceAttributes target; - public PlexusIoProxyResourceAttributes( PlexusIoResourceAttributes thisAttr ) - { + public PlexusIoProxyResourceAttributes(PlexusIoResourceAttributes thisAttr) { this.target = thisAttr; } - public boolean isOwnerReadable() - { + public boolean isOwnerReadable() { return target.isOwnerReadable(); } - public int getOctalMode() - { + public int getOctalMode() { return target.getOctalMode(); } - public String getUserName() - { + public String getUserName() { return target.getUserName(); } - public boolean isGroupReadable() - { + public boolean isGroupReadable() { return target.isGroupReadable(); } - public boolean isWorldExecutable() - { + public boolean isWorldExecutable() { return target.isWorldExecutable(); } - @Nullable public Integer getGroupId() - { + @Nullable + public Integer getGroupId() { return target.getGroupId(); } - public boolean isGroupWritable() - { + public boolean isGroupWritable() { return target.isGroupWritable(); } - public Integer getUserId() - { + public Integer getUserId() { return target.getUserId(); } -/* public String getOctalModeString() - { - return target.getOctalModeString(); - } -*/ - public boolean isOwnerWritable() - { + /* public String getOctalModeString() + { + return target.getOctalModeString(); + } + */ + public boolean isOwnerWritable() { return target.isOwnerWritable(); } - public boolean isOwnerExecutable() - { + public boolean isOwnerExecutable() { return target.isOwnerExecutable(); } - public boolean isSymbolicLink() - { + public boolean isSymbolicLink() { return target.isSymbolicLink(); } - public boolean isGroupExecutable() - { + public boolean isGroupExecutable() { return target.isGroupExecutable(); } - public boolean isWorldWritable() - { + public boolean isWorldWritable() { return target.isWorldWritable(); } - @Nullable public String getGroupName() - { + @Nullable + public String getGroupName() { return target.getGroupName(); } - public boolean isWorldReadable() - { + public boolean isWorldReadable() { return target.isWorldReadable(); } } diff --git a/src/main/java/org/codehaus/plexus/components/io/filemappers/AbstractFileMapper.java b/src/main/java/org/codehaus/plexus/components/io/filemappers/AbstractFileMapper.java index 565ae9ea..a0540ad3 100644 --- a/src/main/java/org/codehaus/plexus/components/io/filemappers/AbstractFileMapper.java +++ b/src/main/java/org/codehaus/plexus/components/io/filemappers/AbstractFileMapper.java @@ -16,7 +16,6 @@ * limitations under the License. */ - import javax.annotation.Nonnull; /** @@ -25,16 +24,13 @@ * this might allow to extend the FileMapper interface later on * without loosing upwards compatibility. */ -public abstract class AbstractFileMapper implements FileMapper -{ +public abstract class AbstractFileMapper implements FileMapper { /** * Checks the input and returns it without modifications. */ - public @Nonnull String getMappedFileName( @Nonnull String pName ) - { - if ( pName == null || pName.length() == 0 ) - { - throw new IllegalArgumentException( "The source name must not be null." ); + public @Nonnull String getMappedFileName(@Nonnull String pName) { + if (pName == null || pName.length() == 0) { + throw new IllegalArgumentException("The source name must not be null."); } return pName; } diff --git a/src/main/java/org/codehaus/plexus/components/io/filemappers/DefaultFileMapper.java b/src/main/java/org/codehaus/plexus/components/io/filemappers/DefaultFileMapper.java index 2cecc8df..57ead3c8 100644 --- a/src/main/java/org/codehaus/plexus/components/io/filemappers/DefaultFileMapper.java +++ b/src/main/java/org/codehaus/plexus/components/io/filemappers/DefaultFileMapper.java @@ -22,6 +22,4 @@ * Alias for {@link IdentityMapper} */ @Named -public class DefaultFileMapper extends IdentityMapper -{ -} \ No newline at end of file +public class DefaultFileMapper extends IdentityMapper {} diff --git a/src/main/java/org/codehaus/plexus/components/io/filemappers/FileExtensionMapper.java b/src/main/java/org/codehaus/plexus/components/io/filemappers/FileExtensionMapper.java index 934b7b9f..14e0a4c9 100644 --- a/src/main/java/org/codehaus/plexus/components/io/filemappers/FileExtensionMapper.java +++ b/src/main/java/org/codehaus/plexus/components/io/filemappers/FileExtensionMapper.java @@ -22,9 +22,8 @@ /** * An implementation of {@link FileMapper}, which changes the files extension. */ -@Named( FileExtensionMapper.ROLE_HINT ) -public class FileExtensionMapper extends AbstractFileMapper -{ +@Named(FileExtensionMapper.ROLE_HINT) +public class FileExtensionMapper extends AbstractFileMapper { /** * The file extension mappers role-hint: "fileExtension". */ @@ -34,27 +33,21 @@ public class FileExtensionMapper extends AbstractFileMapper /** * Sets the target files extension. - * + * * @param pTargetExtension the target extensions * @throws IllegalArgumentException * The target extension is null or empty. */ - public void setTargetExtension( String pTargetExtension ) - { - if ( pTargetExtension == null ) - { - throw new IllegalArgumentException( "The target extension is null." ); + public void setTargetExtension(String pTargetExtension) { + if (pTargetExtension == null) { + throw new IllegalArgumentException("The target extension is null."); } - if ( pTargetExtension.length() == 0 ) - { - throw new IllegalArgumentException( "The target extension is empty." ); + if (pTargetExtension.length() == 0) { + throw new IllegalArgumentException("The target extension is empty."); } - if ( pTargetExtension.charAt( 0 ) == '.' ) - { + if (pTargetExtension.charAt(0) == '.') { targetExtension = pTargetExtension; - } - else - { + } else { targetExtension = '.' + pTargetExtension; } } @@ -63,28 +56,23 @@ public void setTargetExtension( String pTargetExtension ) * Returns the target files extension. * @return The target extension */ - public String getTargetExtension() - { + public String getTargetExtension() { return targetExtension; } - @Nonnull public String getMappedFileName( @Nonnull String pName ) - { + @Nonnull + public String getMappedFileName(@Nonnull String pName) { final String ext = getTargetExtension(); - if ( ext == null ) - { - throw new IllegalStateException( "The target extension has not been set." ); + if (ext == null) { + throw new IllegalStateException("The target extension has not been set."); } - final String name = super.getMappedFileName( pName ); // Check arguments - final int dirSep = Math.max( pName.lastIndexOf( '/' ), pName.lastIndexOf( '\\' ) ); - final int offset = pName.lastIndexOf( '.' ); - if ( offset <= dirSep ) - { + final String name = super.getMappedFileName(pName); // Check arguments + final int dirSep = Math.max(pName.lastIndexOf('/'), pName.lastIndexOf('\\')); + final int offset = pName.lastIndexOf('.'); + if (offset <= dirSep) { return name + ext; - } - else - { - return name.substring( 0, offset ) + ext; + } else { + return name.substring(0, offset) + ext; } } -} \ No newline at end of file +} diff --git a/src/main/java/org/codehaus/plexus/components/io/filemappers/FileMapper.java b/src/main/java/org/codehaus/plexus/components/io/filemappers/FileMapper.java index d0478f80..77f414b1 100644 --- a/src/main/java/org/codehaus/plexus/components/io/filemappers/FileMapper.java +++ b/src/main/java/org/codehaus/plexus/components/io/filemappers/FileMapper.java @@ -19,16 +19,15 @@ /** * Interface of a component, which may be used to map file names. */ -public interface FileMapper -{ +public interface FileMapper { /** * Maps the given source name to a target name. - * + * * @param pName * The source name. * @return The target name. * @throws IllegalArgumentException * The source name is null or empty. */ - String getMappedFileName( String pName ); -} \ No newline at end of file + String getMappedFileName(String pName); +} diff --git a/src/main/java/org/codehaus/plexus/components/io/filemappers/FlattenFileMapper.java b/src/main/java/org/codehaus/plexus/components/io/filemappers/FlattenFileMapper.java index 93cfab98..517b3a11 100644 --- a/src/main/java/org/codehaus/plexus/components/io/filemappers/FlattenFileMapper.java +++ b/src/main/java/org/codehaus/plexus/components/io/filemappers/FlattenFileMapper.java @@ -22,27 +22,24 @@ /** * Implementation of a flattening file mapper: Removes all directory parts. */ -@Named( FlattenFileMapper.ROLE_HINT ) -public class FlattenFileMapper extends AbstractFileMapper -{ +@Named(FlattenFileMapper.ROLE_HINT) +public class FlattenFileMapper extends AbstractFileMapper { /** * The flatten file mappers role-hint: "flatten". */ public static final String ROLE_HINT = "flatten"; - @Nonnull public String getMappedFileName( @Nonnull String pName ) - { - String name = super.getMappedFileName( pName ); // Check for null, etc. - int offset = pName.lastIndexOf( '/' ); - if ( offset >= 0 ) - { - name = name.substring( offset + 1 ); + @Nonnull + public String getMappedFileName(@Nonnull String pName) { + String name = super.getMappedFileName(pName); // Check for null, etc. + int offset = pName.lastIndexOf('/'); + if (offset >= 0) { + name = name.substring(offset + 1); } - offset = pName.lastIndexOf( '\\' ); - if ( offset >= 0 ) - { - name = name.substring( offset + 1 ); + offset = pName.lastIndexOf('\\'); + if (offset >= 0) { + name = name.substring(offset + 1); } return name; } -} \ No newline at end of file +} diff --git a/src/main/java/org/codehaus/plexus/components/io/filemappers/IdentityMapper.java b/src/main/java/org/codehaus/plexus/components/io/filemappers/IdentityMapper.java index 80a025e0..c45cbb37 100644 --- a/src/main/java/org/codehaus/plexus/components/io/filemappers/IdentityMapper.java +++ b/src/main/java/org/codehaus/plexus/components/io/filemappers/IdentityMapper.java @@ -22,20 +22,18 @@ /** * Default implementation of {@link FileMapper}, which performs the identity mapping: All names are left unchanged. */ -@Named( IdentityMapper.ROLE_HINT ) -public class IdentityMapper extends AbstractFileMapper -{ +@Named(IdentityMapper.ROLE_HINT) +public class IdentityMapper extends AbstractFileMapper { /** * The identity mappers role-hint: "identity". */ public static final String ROLE_HINT = "identity"; - @Nonnull public String getMappedFileName( @Nonnull String pName ) - { - if ( pName == null || pName.length() == 0 ) - { - throw new IllegalArgumentException( "The source name must not be null." ); + @Nonnull + public String getMappedFileName(@Nonnull String pName) { + if (pName == null || pName.length() == 0) { + throw new IllegalArgumentException("The source name must not be null."); } return pName; } -} \ No newline at end of file +} diff --git a/src/main/java/org/codehaus/plexus/components/io/filemappers/MergeFileMapper.java b/src/main/java/org/codehaus/plexus/components/io/filemappers/MergeFileMapper.java index 80eb1f93..2a503af7 100644 --- a/src/main/java/org/codehaus/plexus/components/io/filemappers/MergeFileMapper.java +++ b/src/main/java/org/codehaus/plexus/components/io/filemappers/MergeFileMapper.java @@ -22,9 +22,8 @@ /** * A file mapper, which maps to a constant target name. */ -@Named( MergeFileMapper.ROLE_HINT ) -public class MergeFileMapper extends AbstractFileMapper -{ +@Named(MergeFileMapper.ROLE_HINT) +public class MergeFileMapper extends AbstractFileMapper { /** * The merge mappers role-hint: "merge". */ @@ -34,42 +33,37 @@ public class MergeFileMapper extends AbstractFileMapper /** * Sets the merge mappers target name. - * + * * @throws IllegalArgumentException * The target name is null or empty. */ - public void setTargetName( String pName ) - { - if ( pName == null ) - { - throw new IllegalArgumentException( "The target name is null." ); + public void setTargetName(String pName) { + if (pName == null) { + throw new IllegalArgumentException("The target name is null."); } - if ( pName.length() == 0 ) - { - throw new IllegalArgumentException( "The target name is empty." ); + if (pName.length() == 0) { + throw new IllegalArgumentException("The target name is empty."); } targetName = pName; } /** * Returns the merge mappers target name. - * + * * @throws IllegalArgumentException * The target name is null or empty. */ - public String getTargetName() - { + public String getTargetName() { return targetName; } - @Nonnull public String getMappedFileName( @Nonnull String pName ) - { + @Nonnull + public String getMappedFileName(@Nonnull String pName) { final String name = getTargetName(); - if ( name == null ) - { - throw new IllegalStateException( "The target file name has not been set." ); + if (name == null) { + throw new IllegalStateException("The target file name has not been set."); } - super.getMappedFileName( pName ); // Check for null, etc. + super.getMappedFileName(pName); // Check for null, etc. return name; } -} \ No newline at end of file +} diff --git a/src/main/java/org/codehaus/plexus/components/io/filemappers/PrefixFileMapper.java b/src/main/java/org/codehaus/plexus/components/io/filemappers/PrefixFileMapper.java index 3f9112e7..1bb5ca22 100644 --- a/src/main/java/org/codehaus/plexus/components/io/filemappers/PrefixFileMapper.java +++ b/src/main/java/org/codehaus/plexus/components/io/filemappers/PrefixFileMapper.java @@ -22,9 +22,8 @@ /** * A file mapper, which maps by adding a prefix. */ -@Named( PrefixFileMapper.ROLE_HINT ) -public class PrefixFileMapper extends AbstractFileMapper -{ +@Named(PrefixFileMapper.ROLE_HINT) +public class PrefixFileMapper extends AbstractFileMapper { /** * The merge mappers role-hint: "prefix". */ @@ -32,37 +31,33 @@ public class PrefixFileMapper extends AbstractFileMapper private String prefix; - @Nonnull public String getMappedFileName( @Nonnull String name ) - { - final String s = super.getMappedFileName( name ); // Check for null, etc. - return getMappedFileName( prefix, s ); + @Nonnull + public String getMappedFileName(@Nonnull String name) { + final String s = super.getMappedFileName(name); // Check for null, etc. + return getMappedFileName(prefix, s); } /** * Returns the prefix to add. */ - public String getPrefix() - { + public String getPrefix() { return prefix; } /** * Sets the prefix to add. */ - public void setPrefix( String prefix ) - { + public void setPrefix(String prefix) { this.prefix = prefix; } /** * Performs the mapping of a file name by adding a prefix. */ - public static String getMappedFileName( String prefix, String name ) - { - if ( prefix == null || prefix.length() == 0 ) - { + public static String getMappedFileName(String prefix, String name) { + if (prefix == null || prefix.length() == 0) { return name; } return prefix + name; } -} \ No newline at end of file +} diff --git a/src/main/java/org/codehaus/plexus/components/io/filemappers/RegExpFileMapper.java b/src/main/java/org/codehaus/plexus/components/io/filemappers/RegExpFileMapper.java index 1890e59a..aa4dc121 100644 --- a/src/main/java/org/codehaus/plexus/components/io/filemappers/RegExpFileMapper.java +++ b/src/main/java/org/codehaus/plexus/components/io/filemappers/RegExpFileMapper.java @@ -25,10 +25,8 @@ /** * Implementation of a file mapper, which uses regular expressions. */ -@Named( RegExpFileMapper.ROLE_HINT ) -public class RegExpFileMapper - extends AbstractFileMapper -{ +@Named(RegExpFileMapper.ROLE_HINT) +public class RegExpFileMapper extends AbstractFileMapper { /** * The regexp mappers role-hint: "regexp". */ @@ -43,32 +41,28 @@ public class RegExpFileMapper /** * Sets the regular expression pattern. */ - public void setPattern( String pPattern ) - { - pattern = Pattern.compile( pPattern ); + public void setPattern(String pPattern) { + pattern = Pattern.compile(pPattern); } /** * Returns the regular expression pattern. */ - public String getPattern() - { + public String getPattern() { return pattern == null ? null : pattern.pattern(); } /** * Sets the replacement string. */ - public void setReplacement( String pReplacement ) - { + public void setReplacement(String pReplacement) { replacement = pReplacement; } /** * Returns the replacement string. */ - public String getReplacement() - { + public String getReplacement() { return replacement; } @@ -76,8 +70,7 @@ public String getReplacement() * Returns, whether to replace the first occurrence of the pattern * (default), or all. */ - public boolean getReplaceAll() - { + public boolean getReplaceAll() { return replaceAll; } @@ -85,32 +78,26 @@ public boolean getReplaceAll() * Sets, whether to replace the first occurrence of the pattern * (default), or all. */ - public void setReplaceAll( boolean pReplaceAll ) - { + public void setReplaceAll(boolean pReplaceAll) { replaceAll = pReplaceAll; } @Nonnull - public String getMappedFileName( @Nonnull String pName) - { - final String name = super.getMappedFileName( pName ); - if ( pattern == null ) - { - throw new IllegalStateException( "The regular expression pattern has not been set." ); + public String getMappedFileName(@Nonnull String pName) { + final String name = super.getMappedFileName(pName); + if (pattern == null) { + throw new IllegalStateException("The regular expression pattern has not been set."); } - if (replacement == null) - { - throw new IllegalStateException( "The pattern replacement string has not been set." ); + if (replacement == null) { + throw new IllegalStateException("The pattern replacement string has not been set."); } - final Matcher matcher = pattern.matcher( name ); - if ( !matcher.find() ) - { + final Matcher matcher = pattern.matcher(name); + if (!matcher.find()) { return name; } - if ( !getReplaceAll() ) - { - return matcher.replaceFirst( replacement ); + if (!getReplaceAll()) { + return matcher.replaceFirst(replacement); } - return matcher.replaceAll( replacement ); + return matcher.replaceAll(replacement); } } diff --git a/src/main/java/org/codehaus/plexus/components/io/filemappers/SuffixFileMapper.java b/src/main/java/org/codehaus/plexus/components/io/filemappers/SuffixFileMapper.java index 3f5964a5..3601ff01 100644 --- a/src/main/java/org/codehaus/plexus/components/io/filemappers/SuffixFileMapper.java +++ b/src/main/java/org/codehaus/plexus/components/io/filemappers/SuffixFileMapper.java @@ -22,12 +22,11 @@ * If the filename contains dot, the suffix will be added before. * Example: {@code directory/archive.tar.gz => directory/archivesuffix.tar.gz} */ -@Named( SuffixFileMapper.ROLE_HINT ) -public class SuffixFileMapper extends AbstractFileMapper -{ +@Named(SuffixFileMapper.ROLE_HINT) +public class SuffixFileMapper extends AbstractFileMapper { /** - * The suffix mappers role-hint: "suffix". - */ + * The suffix mappers role-hint: "suffix". + */ public static final String ROLE_HINT = "suffix"; private String suffix; @@ -35,40 +34,34 @@ public class SuffixFileMapper extends AbstractFileMapper /** * Returns the suffix to add. */ - public String getSuffix() - { + public String getSuffix() { return suffix; } /** * Sets the suffix to add. */ - public void setSuffix( String suffix ) - { - if ( suffix == null ) - { - throw new IllegalArgumentException( "The suffix is null." ); + public void setSuffix(String suffix) { + if (suffix == null) { + throw new IllegalArgumentException("The suffix is null."); } this.suffix = suffix; } @Nonnull - public String getMappedFileName( @Nonnull String pName) - { - final String name = super.getMappedFileName( pName ); - if ( suffix == null ) - { - throw new IllegalStateException( "The suffix has not been set." ); + public String getMappedFileName(@Nonnull String pName) { + final String name = super.getMappedFileName(pName); + if (suffix == null) { + throw new IllegalStateException("The suffix has not been set."); } - final int dirSep = Math.max( name.lastIndexOf( '/' ), name.lastIndexOf( '\\' ) ); - String filename = dirSep > 0 ? name.substring( dirSep + 1 ) : name; - String dirname = dirSep > 0 ? name.substring( 0, dirSep + 1 ) : ""; - if ( filename.contains( "." ) ) - { - String beforeExtension = filename.substring( 0, filename.indexOf( '.' ) ); - String afterExtension = filename.substring( filename.indexOf( '.' ) + 1 ) ; + final int dirSep = Math.max(name.lastIndexOf('/'), name.lastIndexOf('\\')); + String filename = dirSep > 0 ? name.substring(dirSep + 1) : name; + String dirname = dirSep > 0 ? name.substring(0, dirSep + 1) : ""; + if (filename.contains(".")) { + String beforeExtension = filename.substring(0, filename.indexOf('.')); + String afterExtension = filename.substring(filename.indexOf('.') + 1); return dirname + beforeExtension + suffix + "." + afterExtension; } return name + suffix; } -} \ No newline at end of file +} diff --git a/src/main/java/org/codehaus/plexus/components/io/fileselectors/AllFilesFileSelector.java b/src/main/java/org/codehaus/plexus/components/io/fileselectors/AllFilesFileSelector.java index 90110616..cea7fe96 100644 --- a/src/main/java/org/codehaus/plexus/components/io/fileselectors/AllFilesFileSelector.java +++ b/src/main/java/org/codehaus/plexus/components/io/fileselectors/AllFilesFileSelector.java @@ -24,16 +24,14 @@ * The default file selector: Selects all files. */ @Singleton -@Named( AllFilesFileSelector.ROLE_HINT ) -public class AllFilesFileSelector implements FileSelector -{ +@Named(AllFilesFileSelector.ROLE_HINT) +public class AllFilesFileSelector implements FileSelector { /** * The all files selectors role-hint: "all". */ public static final String ROLE_HINT = "all"; - public boolean isSelected( @Nonnull FileInfo fileInfo ) - { + public boolean isSelected(@Nonnull FileInfo fileInfo) { return true; } -} \ No newline at end of file +} diff --git a/src/main/java/org/codehaus/plexus/components/io/fileselectors/DefaultFileSelector.java b/src/main/java/org/codehaus/plexus/components/io/fileselectors/DefaultFileSelector.java index c1292ec0..5886f857 100644 --- a/src/main/java/org/codehaus/plexus/components/io/fileselectors/DefaultFileSelector.java +++ b/src/main/java/org/codehaus/plexus/components/io/fileselectors/DefaultFileSelector.java @@ -24,6 +24,4 @@ */ @Singleton @Named -public class DefaultFileSelector extends AllFilesFileSelector -{ -} \ No newline at end of file +public class DefaultFileSelector extends AllFilesFileSelector {} diff --git a/src/main/java/org/codehaus/plexus/components/io/fileselectors/FileInfo.java b/src/main/java/org/codehaus/plexus/components/io/fileselectors/FileInfo.java index 615160c7..8fab34bf 100644 --- a/src/main/java/org/codehaus/plexus/components/io/fileselectors/FileInfo.java +++ b/src/main/java/org/codehaus/plexus/components/io/fileselectors/FileInfo.java @@ -16,11 +16,11 @@ * limitations under the License. */ -import org.codehaus.plexus.components.io.functions.NameSupplier; - import java.io.IOException; import java.io.InputStream; +import org.codehaus.plexus.components.io.functions.NameSupplier; + /** * An object implementing this interface is passed to the * file selector when the method @@ -28,8 +28,7 @@ * is invoked. This object provides information about * the file to select or deselect. */ -public interface FileInfo extends NameSupplier -{ +public interface FileInfo extends NameSupplier { /** * Returns the resources name, which may include path components, * like directory names, or something like that. The resources name @@ -66,4 +65,4 @@ public interface FileInfo extends NameSupplier * This method will return "false" for java versions prior to java7. */ boolean isSymbolicLink(); -} \ No newline at end of file +} diff --git a/src/main/java/org/codehaus/plexus/components/io/fileselectors/FileSelector.java b/src/main/java/org/codehaus/plexus/components/io/fileselectors/FileSelector.java index d0ad4af0..ac84157f 100644 --- a/src/main/java/org/codehaus/plexus/components/io/fileselectors/FileSelector.java +++ b/src/main/java/org/codehaus/plexus/components/io/fileselectors/FileSelector.java @@ -17,18 +17,18 @@ */ import javax.annotation.Nonnull; + import java.io.IOException; /** * Interface of a component, which selects/deselects files. */ -public interface FileSelector -{ +public interface FileSelector { /** * Returns, whether the given file is selected. * @param fileInfo An instance of FileInfo with the files meta data. * It is recommended, that the caller creates an instance * of {@link org.codehaus.plexus.components.io.resources.PlexusIoResource}. */ - boolean isSelected( @Nonnull FileInfo fileInfo ) throws IOException; -} \ No newline at end of file + boolean isSelected(@Nonnull FileInfo fileInfo) throws IOException; +} diff --git a/src/main/java/org/codehaus/plexus/components/io/fileselectors/IncludeExcludeFileSelector.java b/src/main/java/org/codehaus/plexus/components/io/fileselectors/IncludeExcludeFileSelector.java index 47b3f1c9..9f7af5f6 100644 --- a/src/main/java/org/codehaus/plexus/components/io/fileselectors/IncludeExcludeFileSelector.java +++ b/src/main/java/org/codehaus/plexus/components/io/fileselectors/IncludeExcludeFileSelector.java @@ -16,30 +16,28 @@ * limitations under the License. */ +import javax.annotation.Nonnull; +import javax.annotation.Nullable; +import javax.inject.Named; + import java.io.File; import org.codehaus.plexus.util.FileUtils; import org.codehaus.plexus.util.MatchPatterns; import org.codehaus.plexus.util.SelectorUtils; -import javax.annotation.Nonnull; -import javax.annotation.Nullable; -import javax.inject.Named; - /** * This file selector uses a set of patterns for including/excluding * files. */ -@Named( IncludeExcludeFileSelector.ROLE_HINT ) -public class IncludeExcludeFileSelector - implements FileSelector -{ +@Named(IncludeExcludeFileSelector.ROLE_HINT) +public class IncludeExcludeFileSelector implements FileSelector { /** * The include/exclude file selectors role-hint: "standard". */ public static final String ROLE_HINT = "standard"; - private static final MatchPatterns ALL_INCLUDES = MatchPatterns.from( getCanonicalName( "**/*" ) ); + private static final MatchPatterns ALL_INCLUDES = MatchPatterns.from(getCanonicalName("**/*")); private static final MatchPatterns ZERO_EXCLUDES = MatchPatterns.from(); @@ -63,9 +61,8 @@ public class IncludeExcludeFileSelector * @return true when the name matches against at least one * exclude pattern, or false otherwise. */ - protected boolean isExcluded( @Nonnull String name ) - { - return computedExcludes.matches( name, isCaseSensitive ); + protected boolean isExcluded(@Nonnull String name) { + return computedExcludes.matches(name, isCaseSensitive); } /** @@ -81,35 +78,27 @@ protected boolean isExcluded( @Nonnull String name ) * list is given, all elements must be * non-null. */ - public void setIncludes( @Nullable String[] includes ) - { + public void setIncludes(@Nullable String[] includes) { this.includes = includes; - if ( includes == null ) - { + if (includes == null) { computedIncludes = ALL_INCLUDES; - } - else - { + } else { String[] cleaned; cleaned = new String[includes.length]; - for ( int i = 0; i < includes.length; i++ ) - { - cleaned[i] = asPattern( includes[i] ); + for (int i = 0; i < includes.length; i++) { + cleaned[i] = asPattern(includes[i]); } - computedIncludes = MatchPatterns.from( cleaned ); + computedIncludes = MatchPatterns.from(cleaned); } } - private static @Nonnull String getCanonicalName( @Nonnull String pName ) - { - return pName.replace( '/', File.separatorChar ).replace( '\\', File.separatorChar ); + private static @Nonnull String getCanonicalName(@Nonnull String pName) { + return pName.replace('/', File.separatorChar).replace('\\', File.separatorChar); } - private String asPattern( @Nonnull String pPattern ) - { - String pattern = getCanonicalName( pPattern.trim() ); - if ( pattern.endsWith( File.separator ) ) - { + private String asPattern(@Nonnull String pPattern) { + String pattern = getCanonicalName(pPattern.trim()); + if (pattern.endsWith(File.separator)) { pattern += "**"; } return pattern; @@ -124,8 +113,7 @@ private String asPattern( @Nonnull String pPattern ) * list is given, all elements must be * non-null. */ - public @Nullable String[] getIncludes() - { + public @Nullable String[] getIncludes() { return includes; } @@ -141,28 +129,21 @@ private String asPattern( @Nonnull String pPattern ) * should be excluded. If a non-null list is * given, all elements must be non-null. */ - public void setExcludes( @Nullable String[] excludes ) - { + public void setExcludes(@Nullable String[] excludes) { this.excludes = excludes; final String[] defaultExcludes = useDefaultExcludes ? FileUtils.getDefaultExcludes() : new String[] {}; - if ( excludes == null ) - { - computedExcludes = MatchPatterns.from( defaultExcludes ); - } - else - { + if (excludes == null) { + computedExcludes = MatchPatterns.from(defaultExcludes); + } else { String[] temp = new String[excludes.length + defaultExcludes.length]; - for ( int i = 0; i < excludes.length; i++ ) - { - temp[i] = asPattern( excludes[i] ); + for (int i = 0; i < excludes.length; i++) { + temp[i] = asPattern(excludes[i]); } - if ( defaultExcludes.length > 0 ) - { - System.arraycopy( defaultExcludes, 0, temp, excludes.length, defaultExcludes.length ); + if (defaultExcludes.length > 0) { + System.arraycopy(defaultExcludes, 0, temp, excludes.length, defaultExcludes.length); } - computedExcludes = MatchPatterns.from( temp ); - + computedExcludes = MatchPatterns.from(temp); } } @@ -174,8 +155,7 @@ public void setExcludes( @Nullable String[] excludes ) * should be excluded. If a non-null list is * given, all elements must be non-null. */ - public @Nullable String[] getExcludes() - { + public @Nullable String[] getExcludes() { return excludes; } @@ -186,10 +166,8 @@ public void setExcludes( @Nullable String[] excludes ) * @param isCaseSensitive Whether the pattern is case sensitive. * @return True, if the pattern matches, otherwise false */ - protected boolean matchPath( @Nonnull String pattern, @Nonnull String name, - boolean isCaseSensitive ) - { - return SelectorUtils.matchPath( pattern, name, isCaseSensitive ); + protected boolean matchPath(@Nonnull String pattern, @Nonnull String name, boolean isCaseSensitive) { + return SelectorUtils.matchPath(pattern, name, isCaseSensitive); } /** @@ -200,23 +178,20 @@ protected boolean matchPath( @Nonnull String pattern, @Nonnull String name, * @return true when the name matches against at least one * include pattern, or false otherwise. */ - protected boolean isIncluded( @Nonnull String name ) - { - return computedIncludes.matches( name, isCaseSensitive ); + protected boolean isIncluded(@Nonnull String name) { + return computedIncludes.matches(name, isCaseSensitive); } - public boolean isSelected( @Nonnull FileInfo fileInfo ) - { - final String name = getCanonicalName( fileInfo.getName() ); - return isIncluded( name ) && !isExcluded( name ); + public boolean isSelected(@Nonnull FileInfo fileInfo) { + final String name = getCanonicalName(fileInfo.getName()); + return isIncluded(name) && !isExcluded(name); } /** * Returns, whether the include/exclude patterns are case sensitive. * @return True, if the patterns are case sensitive (default), or false. */ - public boolean isCaseSensitive() - { + public boolean isCaseSensitive() { return isCaseSensitive; } @@ -224,8 +199,7 @@ public boolean isCaseSensitive() * Sets, whether the include/exclude patterns are case sensitive. * @param caseSensitive True, if the patterns are case sensitive (default), or false. */ - public void setCaseSensitive( boolean caseSensitive ) - { + public void setCaseSensitive(boolean caseSensitive) { isCaseSensitive = caseSensitive; } @@ -233,8 +207,7 @@ public void setCaseSensitive( boolean caseSensitive ) * Returns, whether to use the default excludes, as specified by * {@link FileUtils#getDefaultExcludes()}. */ - public boolean isUseDefaultExcludes() - { + public boolean isUseDefaultExcludes() { return useDefaultExcludes; } @@ -242,9 +215,8 @@ public boolean isUseDefaultExcludes() * Sets, whether to use the default excludes, as specified by * {@link FileUtils#getDefaultExcludes()}. */ - public void setUseDefaultExcludes( boolean pUseDefaultExcludes ) - { + public void setUseDefaultExcludes(boolean pUseDefaultExcludes) { useDefaultExcludes = pUseDefaultExcludes; - setExcludes( excludes ); + setExcludes(excludes); } -} \ No newline at end of file +} diff --git a/src/main/java/org/codehaus/plexus/components/io/functions/ContentSupplier.java b/src/main/java/org/codehaus/plexus/components/io/functions/ContentSupplier.java index 9c885b6f..21b3ec1e 100644 --- a/src/main/java/org/codehaus/plexus/components/io/functions/ContentSupplier.java +++ b/src/main/java/org/codehaus/plexus/components/io/functions/ContentSupplier.java @@ -24,7 +24,6 @@ * * Someday this will extends java.util.function.Supplier */ -public interface ContentSupplier -{ +public interface ContentSupplier { InputStream getContents() throws IOException; } diff --git a/src/main/java/org/codehaus/plexus/components/io/functions/FileSupplier.java b/src/main/java/org/codehaus/plexus/components/io/functions/FileSupplier.java index 116c279f..1fbee255 100644 --- a/src/main/java/org/codehaus/plexus/components/io/functions/FileSupplier.java +++ b/src/main/java/org/codehaus/plexus/components/io/functions/FileSupplier.java @@ -17,13 +17,13 @@ */ import javax.annotation.Nonnull; + import java.io.File; /** * Implemented by resources that are files on something filesystem-like. */ -public interface FileSupplier -{ +public interface FileSupplier { /** * Supplies the file for this resource, not null. * @return The file diff --git a/src/main/java/org/codehaus/plexus/components/io/functions/InputStreamTransformer.java b/src/main/java/org/codehaus/plexus/components/io/functions/InputStreamTransformer.java index f0073dbf..a63ca7ff 100644 --- a/src/main/java/org/codehaus/plexus/components/io/functions/InputStreamTransformer.java +++ b/src/main/java/org/codehaus/plexus/components/io/functions/InputStreamTransformer.java @@ -15,18 +15,18 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import org.codehaus.plexus.components.io.resources.PlexusIoResource; - import javax.annotation.Nonnull; + import java.io.IOException; import java.io.InputStream; +import org.codehaus.plexus.components.io.resources.PlexusIoResource; + /** * Transform a stream into some other kind of stream. May be used to apply filtering or other * kinds of transformations. */ -public interface InputStreamTransformer -{ +public interface InputStreamTransformer { /** * Transform the supplied input stream into another input stream. * @@ -37,5 +37,6 @@ public interface InputStreamTransformer * @return A transformed stream or possibly the supplied stream * @throws IOException */ - @Nonnull InputStream transform( @Nonnull PlexusIoResource resource, @Nonnull InputStream inputStream ) throws IOException; + @Nonnull + InputStream transform(@Nonnull PlexusIoResource resource, @Nonnull InputStream inputStream) throws IOException; } diff --git a/src/main/java/org/codehaus/plexus/components/io/functions/NameSupplier.java b/src/main/java/org/codehaus/plexus/components/io/functions/NameSupplier.java index 179cc807..64204314 100644 --- a/src/main/java/org/codehaus/plexus/components/io/functions/NameSupplier.java +++ b/src/main/java/org/codehaus/plexus/components/io/functions/NameSupplier.java @@ -16,8 +16,7 @@ * limitations under the License. */ -public interface NameSupplier -{ +public interface NameSupplier { /** * Returns the resources name, which may include path components, * like directory names, or something like that. The resources name diff --git a/src/main/java/org/codehaus/plexus/components/io/functions/PlexusIoResourceConsumer.java b/src/main/java/org/codehaus/plexus/components/io/functions/PlexusIoResourceConsumer.java index 841a724f..893074fe 100644 --- a/src/main/java/org/codehaus/plexus/components/io/functions/PlexusIoResourceConsumer.java +++ b/src/main/java/org/codehaus/plexus/components/io/functions/PlexusIoResourceConsumer.java @@ -23,7 +23,6 @@ * Consume a PlexusIoResource * @author Kristian Rosenvold */ -public interface PlexusIoResourceConsumer -{ - void accept( PlexusIoResource resource ) throws IOException; +public interface PlexusIoResourceConsumer { + void accept(PlexusIoResource resource) throws IOException; } diff --git a/src/main/java/org/codehaus/plexus/components/io/functions/ResourceAttributeSupplier.java b/src/main/java/org/codehaus/plexus/components/io/functions/ResourceAttributeSupplier.java index a14e3bf2..c8f1c060 100644 --- a/src/main/java/org/codehaus/plexus/components/io/functions/ResourceAttributeSupplier.java +++ b/src/main/java/org/codehaus/plexus/components/io/functions/ResourceAttributeSupplier.java @@ -18,7 +18,6 @@ import org.codehaus.plexus.components.io.attributes.PlexusIoResourceAttributes; -public interface ResourceAttributeSupplier -{ +public interface ResourceAttributeSupplier { PlexusIoResourceAttributes getAttributes(); } diff --git a/src/main/java/org/codehaus/plexus/components/io/functions/SizeSupplier.java b/src/main/java/org/codehaus/plexus/components/io/functions/SizeSupplier.java index 05a5b402..bfb3c97b 100644 --- a/src/main/java/org/codehaus/plexus/components/io/functions/SizeSupplier.java +++ b/src/main/java/org/codehaus/plexus/components/io/functions/SizeSupplier.java @@ -16,7 +16,6 @@ * limitations under the License. */ -public interface SizeSupplier -{ +public interface SizeSupplier { long getSize(); } diff --git a/src/main/java/org/codehaus/plexus/components/io/functions/SymlinkDestinationSupplier.java b/src/main/java/org/codehaus/plexus/components/io/functions/SymlinkDestinationSupplier.java index 9f5932ad..e47e7ce0 100644 --- a/src/main/java/org/codehaus/plexus/components/io/functions/SymlinkDestinationSupplier.java +++ b/src/main/java/org/codehaus/plexus/components/io/functions/SymlinkDestinationSupplier.java @@ -21,8 +21,6 @@ /** * @author Kristian Rosenvold */ -public interface SymlinkDestinationSupplier -{ - String getSymlinkDestination() - throws IOException; +public interface SymlinkDestinationSupplier { + String getSymlinkDestination() throws IOException; } diff --git a/src/main/java/org/codehaus/plexus/components/io/resources/AbstractPlexusIoArchiveResourceCollection.java b/src/main/java/org/codehaus/plexus/components/io/resources/AbstractPlexusIoArchiveResourceCollection.java index 573b234a..da2bef06 100644 --- a/src/main/java/org/codehaus/plexus/components/io/resources/AbstractPlexusIoArchiveResourceCollection.java +++ b/src/main/java/org/codehaus/plexus/components/io/resources/AbstractPlexusIoArchiveResourceCollection.java @@ -30,28 +30,23 @@ * */ public abstract class AbstractPlexusIoArchiveResourceCollection extends AbstractPlexusIoResourceCollection - implements PlexusIoArchivedResourceCollection -{ + implements PlexusIoArchivedResourceCollection { private File file; - protected AbstractPlexusIoArchiveResourceCollection() - { - } + protected AbstractPlexusIoArchiveResourceCollection() {} /** * Sets the zip file */ - public void setFile( File file ) - { + public void setFile(File file) { this.file = file; } /** * Returns the zip file */ - public File getFile() - { + public File getFile() { return file; } @@ -62,100 +57,74 @@ public File getFile() */ protected abstract Iterator getEntries() throws IOException; - public Iterator getResources() throws IOException - { + public Iterator getResources() throws IOException { return new FilteringIterator(); } - class FilteringIterator - implements Iterator, Closeable - { + class FilteringIterator implements Iterator, Closeable { final Iterator it = getEntries(); PlexusIoResource next; - public FilteringIterator() - throws IOException - { - } + public FilteringIterator() throws IOException {} - boolean doNext() - { - while ( it.hasNext() ) - { + boolean doNext() { + while (it.hasNext()) { PlexusIoResource candidate = it.next(); - try - { - if ( isSelected( candidate ) ) - { + try { + if (isSelected(candidate)) { next = candidate; return true; } - } - catch ( IOException e ) - { - throw new RuntimeException( e ); + } catch (IOException e) { + throw new RuntimeException(e); } } return false; } - public boolean hasNext() - { + + public boolean hasNext() { return doNext(); } - public PlexusIoResource next() - { - if ( next == null ) - doNext(); + public PlexusIoResource next() { + if (next == null) doNext(); PlexusIoResource res = next; next = null; return res; } - public void remove() - { + public void remove() { throw new UnsupportedOperationException(); } - public void close() - throws IOException - { - if ( it instanceof Closeable ) - { - ( (Closeable) it ).close(); + public void close() throws IOException { + if (it instanceof Closeable) { + ((Closeable) it).close(); } } } - public Stream stream() - { - return new Stream() - { - public void forEach( PlexusIoResourceConsumer resourceConsumer ) - throws IOException - { + + public Stream stream() { + return new Stream() { + public void forEach(PlexusIoResourceConsumer resourceConsumer) throws IOException { final Iterator it = getEntries(); - while ( it.hasNext() ) - { + while (it.hasNext()) { final PlexusIoResource res = it.next(); - if ( isSelected( res ) ) - { - resourceConsumer.accept( res ); + if (isSelected(res)) { + resourceConsumer.accept(res); } } - if ( it instanceof Closeable ) - { - ( (Closeable) it ).close(); + if (it instanceof Closeable) { + ((Closeable) it).close(); } } }; } - public long getLastModified() - throws IOException - { + public long getLastModified() throws IOException { File f = getFile(); return f == null ? PlexusIoResource.UNKNOWN_MODIFICATION_DATE : f.lastModified(); } -} \ No newline at end of file +} diff --git a/src/main/java/org/codehaus/plexus/components/io/resources/AbstractPlexusIoResource.java b/src/main/java/org/codehaus/plexus/components/io/resources/AbstractPlexusIoResource.java index 736c4d32..b9bedec1 100644 --- a/src/main/java/org/codehaus/plexus/components/io/resources/AbstractPlexusIoResource.java +++ b/src/main/java/org/codehaus/plexus/components/io/resources/AbstractPlexusIoResource.java @@ -21,17 +21,19 @@ /** * Default implementation of {@link PlexusIoResource}. */ -public abstract class AbstractPlexusIoResource implements PlexusIoResource -{ +public abstract class AbstractPlexusIoResource implements PlexusIoResource { private final String name; private final long lastModified, size; - private final boolean isFile, isDirectory, isExisting; - protected AbstractPlexusIoResource( @Nonnull String name, long lastModified, long size, boolean isFile, - boolean isDirectory, boolean isExisting ) - { + protected AbstractPlexusIoResource( + @Nonnull String name, + long lastModified, + long size, + boolean isFile, + boolean isDirectory, + boolean isExisting) { this.name = name; this.lastModified = lastModified; this.size = size; @@ -40,39 +42,32 @@ protected AbstractPlexusIoResource( @Nonnull String name, long lastModified, lon this.isExisting = isExisting; } - public long getLastModified() - { + public long getLastModified() { return lastModified; } @Nonnull - public String getName() - { + public String getName() { return name; } - public long getSize() - { + public long getSize() { return size; } - public boolean isDirectory() - { + public boolean isDirectory() { return isDirectory; } - public boolean isExisting() - { + public boolean isExisting() { return isExisting; } - public boolean isFile() - { + public boolean isFile() { return isFile; } - public boolean isSymbolicLink() - { + public boolean isSymbolicLink() { return false; } -} \ No newline at end of file +} diff --git a/src/main/java/org/codehaus/plexus/components/io/resources/AbstractPlexusIoResourceCollection.java b/src/main/java/org/codehaus/plexus/components/io/resources/AbstractPlexusIoResourceCollection.java index 431b762e..cafae1d3 100644 --- a/src/main/java/org/codehaus/plexus/components/io/resources/AbstractPlexusIoResourceCollection.java +++ b/src/main/java/org/codehaus/plexus/components/io/resources/AbstractPlexusIoResourceCollection.java @@ -16,30 +16,26 @@ * limitations under the License. */ -import org.codehaus.plexus.components.io.filemappers.FileMapper; -import org.codehaus.plexus.components.io.filemappers.PrefixFileMapper; -import org.codehaus.plexus.components.io.fileselectors.FileSelector; -import org.codehaus.plexus.components.io.functions.InputStreamTransformer; - import javax.annotation.Nonnull; + import java.io.IOException; import java.io.InputStream; import java.util.Iterator; +import org.codehaus.plexus.components.io.filemappers.FileMapper; +import org.codehaus.plexus.components.io.filemappers.PrefixFileMapper; +import org.codehaus.plexus.components.io.fileselectors.FileSelector; +import org.codehaus.plexus.components.io.functions.InputStreamTransformer; + /** * Default implementation of a resource collection. */ -public abstract class AbstractPlexusIoResourceCollection - implements PlexusIoResourceCollection -{ +public abstract class AbstractPlexusIoResourceCollection implements PlexusIoResourceCollection { - static class IdentityTransformer - implements InputStreamTransformer - { + static class IdentityTransformer implements InputStreamTransformer { @Nonnull - public InputStream transform( @Nonnull PlexusIoResource resource, @Nonnull InputStream inputStream ) - throws IOException - { + public InputStream transform(@Nonnull PlexusIoResource resource, @Nonnull InputStream inputStream) + throws IOException { return inputStream; } } @@ -64,16 +60,13 @@ public InputStream transform( @Nonnull PlexusIoResource resource, @Nonnull Input private InputStreamTransformer streamTransformer = identityTransformer; - protected AbstractPlexusIoResourceCollection() - { - } + protected AbstractPlexusIoResourceCollection() {} /** * Sets a string of patterns, which excluded files * should match. */ - public void setExcludes( String[] excludes ) - { + public void setExcludes(String[] excludes) { this.excludes = excludes; } @@ -81,8 +74,7 @@ public void setExcludes( String[] excludes ) * Returns a string of patterns, which excluded files * should match. */ - public String[] getExcludes() - { + public String[] getExcludes() { return excludes; } @@ -90,8 +82,7 @@ public String[] getExcludes() * Sets a set of file selectors, which should be used * to select the included files. */ - public void setFileSelectors( FileSelector[] fileSelectors ) - { + public void setFileSelectors(FileSelector[] fileSelectors) { this.fileSelectors = fileSelectors; } @@ -99,25 +90,19 @@ public void setFileSelectors( FileSelector[] fileSelectors ) * Returns a set of file selectors, which should be used * to select the included files. */ - public FileSelector[] getFileSelectors() - { + public FileSelector[] getFileSelectors() { return fileSelectors; } - public void setStreamTransformer( InputStreamTransformer streamTransformer ) - { - if ( streamTransformer == null ) - { + public void setStreamTransformer(InputStreamTransformer streamTransformer) { + if (streamTransformer == null) { this.streamTransformer = identityTransformer; - } - else - { + } else { this.streamTransformer = streamTransformer; } } - protected InputStreamTransformer getStreamTransformer() - { + protected InputStreamTransformer getStreamTransformer() { return streamTransformer; } @@ -125,8 +110,7 @@ protected InputStreamTransformer getStreamTransformer() * Sets a string of patterns, which included files * should match. */ - public void setIncludes( String[] includes ) - { + public void setIncludes(String[] includes) { this.includes = includes; } @@ -134,8 +118,7 @@ public void setIncludes( String[] includes ) * Returns a string of patterns, which included files * should match. */ - public String[] getIncludes() - { + public String[] getIncludes() { return includes; } @@ -143,8 +126,7 @@ public String[] getIncludes() * Sets the prefix, which the file sets contents shall * have. */ - public void setPrefix( String prefix ) - { + public void setPrefix(String prefix) { this.prefix = prefix; } @@ -152,8 +134,7 @@ public void setPrefix( String prefix ) * Returns the prefix, which the file sets contents shall * have. */ - public String getPrefix() - { + public String getPrefix() { return prefix; } @@ -161,8 +142,7 @@ public String getPrefix() * Sets, whether the include/exclude patterns are * case sensitive. Defaults to true. */ - public void setCaseSensitive( boolean caseSensitive ) - { + public void setCaseSensitive(boolean caseSensitive) { this.caseSensitive = caseSensitive; } @@ -170,8 +150,7 @@ public void setCaseSensitive( boolean caseSensitive ) * Returns, whether the include/exclude patterns are * case sensitive. Defaults to true. */ - public boolean isCaseSensitive() - { + public boolean isCaseSensitive() { return caseSensitive; } @@ -179,8 +158,7 @@ public boolean isCaseSensitive() * Sets, whether the default excludes are being * applied. Defaults to true. */ - public void setUsingDefaultExcludes( boolean usingDefaultExcludes ) - { + public void setUsingDefaultExcludes(boolean usingDefaultExcludes) { this.usingDefaultExcludes = usingDefaultExcludes; } @@ -188,8 +166,7 @@ public void setUsingDefaultExcludes( boolean usingDefaultExcludes ) * Returns, whether the default excludes are being * applied. Defaults to true. */ - public boolean isUsingDefaultExcludes() - { + public boolean isUsingDefaultExcludes() { return usingDefaultExcludes; } @@ -197,8 +174,7 @@ public boolean isUsingDefaultExcludes() * Sets, whether empty directories are being included. Defaults * to true. */ - public void setIncludingEmptyDirectories( boolean includingEmptyDirectories ) - { + public void setIncludingEmptyDirectories(boolean includingEmptyDirectories) { this.includingEmptyDirectories = includingEmptyDirectories; } @@ -206,21 +182,15 @@ public void setIncludingEmptyDirectories( boolean includingEmptyDirectories ) * Returns, whether empty directories are being included. Defaults * to true. */ - public boolean isIncludingEmptyDirectories() - { + public boolean isIncludingEmptyDirectories() { return includingEmptyDirectories; } - protected boolean isSelected( PlexusIoResource plexusIoResource ) - throws IOException - { + protected boolean isSelected(PlexusIoResource plexusIoResource) throws IOException { FileSelector[] fileSelectors = getFileSelectors(); - if ( fileSelectors != null ) - { - for ( FileSelector fileSelector : fileSelectors ) - { - if ( !fileSelector.isSelected( plexusIoResource ) ) - { + if (fileSelectors != null) { + for (FileSelector fileSelector : fileSelectors) { + if (!fileSelector.isSelected(plexusIoResource)) { return false; } } @@ -232,8 +202,7 @@ protected boolean isSelected( PlexusIoResource plexusIoResource ) * Returns the file name mappers, which are used to transform * the resource names. */ - public FileMapper[] getFileMappers() - { + public FileMapper[] getFileMappers() { return fileMappers; } @@ -241,76 +210,55 @@ public FileMapper[] getFileMappers() * Sets the file name mappers, which are used to transform * the resource names. */ - public void setFileMappers( FileMapper[] fileMappers ) - { + public void setFileMappers(FileMapper[] fileMappers) { this.fileMappers = fileMappers; } - public Iterator iterator() - { - try - { + public Iterator iterator() { + try { return getResources(); - } - catch ( IOException e ) - { - throw new RuntimeException( e ); + } catch (IOException e) { + throw new RuntimeException(e); } } - public String getName( PlexusIoResource resource ) - { - return getName( resource.getName() ); + public String getName(PlexusIoResource resource) { + return getName(resource.getName()); } - protected String getName( String resourceName ) - { + protected String getName(String resourceName) { String name = resourceName; final FileMapper[] mappers = getFileMappers(); - if ( mappers != null ) - { - for ( FileMapper mapper : mappers ) - { - name = mapper.getMappedFileName( name ); + if (mappers != null) { + for (FileMapper mapper : mappers) { + name = mapper.getMappedFileName(name); } } - return PrefixFileMapper.getMappedFileName( getPrefix(), name ); + return PrefixFileMapper.getMappedFileName(getPrefix(), name); } - - public InputStream getInputStream( PlexusIoResource resource ) - throws IOException - { + public InputStream getInputStream(PlexusIoResource resource) throws IOException { InputStream contents = resource.getContents(); - return new ClosingInputStream( streamTransformer.transform( resource, contents ), contents ); + return new ClosingInputStream(streamTransformer.transform(resource, contents), contents); } - - public PlexusIoResource resolve( final PlexusIoResource resource ) - throws IOException - { - final Deferred deferred = new Deferred( resource, this, streamTransformer != identityTransformer ); + public PlexusIoResource resolve(final PlexusIoResource resource) throws IOException { + final Deferred deferred = new Deferred(resource, this, streamTransformer != identityTransformer); return deferred.asResource(); } - public long getLastModified() - throws IOException - { + public long getLastModified() throws IOException { long lastModified = PlexusIoResource.UNKNOWN_MODIFICATION_DATE; - for ( final Iterator iter = getResources(); iter.hasNext(); ) - { + for (final Iterator iter = getResources(); iter.hasNext(); ) { final PlexusIoResource res = (PlexusIoResource) iter.next(); long l = res.getLastModified(); - if ( l == PlexusIoResource.UNKNOWN_MODIFICATION_DATE ) - { + if (l == PlexusIoResource.UNKNOWN_MODIFICATION_DATE) { return PlexusIoResource.UNKNOWN_MODIFICATION_DATE; } - if ( lastModified == PlexusIoResource.UNKNOWN_MODIFICATION_DATE || l > lastModified ) - { + if (lastModified == PlexusIoResource.UNKNOWN_MODIFICATION_DATE || l > lastModified) { lastModified = l; } } return lastModified; } - -} \ No newline at end of file +} diff --git a/src/main/java/org/codehaus/plexus/components/io/resources/AbstractPlexusIoResourceCollectionWithAttributes.java b/src/main/java/org/codehaus/plexus/components/io/resources/AbstractPlexusIoResourceCollectionWithAttributes.java index e8bee2f5..5b158db2 100644 --- a/src/main/java/org/codehaus/plexus/components/io/resources/AbstractPlexusIoResourceCollectionWithAttributes.java +++ b/src/main/java/org/codehaus/plexus/components/io/resources/AbstractPlexusIoResourceCollectionWithAttributes.java @@ -22,9 +22,7 @@ /** * Default implementation of a resource collection with attributes. */ -public abstract class AbstractPlexusIoResourceCollectionWithAttributes - extends AbstractPlexusIoResourceCollection -{ +public abstract class AbstractPlexusIoResourceCollectionWithAttributes extends AbstractPlexusIoResourceCollection { private PlexusIoResourceAttributes defaultFileAttributes; @@ -34,61 +32,47 @@ public abstract class AbstractPlexusIoResourceCollectionWithAttributes private PlexusIoResourceAttributes overrideDirAttributes; - protected AbstractPlexusIoResourceCollectionWithAttributes() - { - } + protected AbstractPlexusIoResourceCollectionWithAttributes() {} - protected PlexusIoResourceAttributes getDefaultFileAttributes() - { + protected PlexusIoResourceAttributes getDefaultFileAttributes() { return defaultFileAttributes; } - protected void setDefaultFileAttributes( final PlexusIoResourceAttributes defaultFileAttributes ) - { + protected void setDefaultFileAttributes(final PlexusIoResourceAttributes defaultFileAttributes) { this.defaultFileAttributes = defaultFileAttributes; } - protected PlexusIoResourceAttributes getDefaultDirAttributes() - { + protected PlexusIoResourceAttributes getDefaultDirAttributes() { return defaultDirAttributes; } - protected void setDefaultDirAttributes( final PlexusIoResourceAttributes defaultDirAttributes ) - { + protected void setDefaultDirAttributes(final PlexusIoResourceAttributes defaultDirAttributes) { this.defaultDirAttributes = defaultDirAttributes; } - protected PlexusIoResourceAttributes getOverrideFileAttributes() - { + protected PlexusIoResourceAttributes getOverrideFileAttributes() { return overrideFileAttributes; } - protected void setOverrideFileAttributes( final PlexusIoResourceAttributes overrideFileAttributes ) - { + protected void setOverrideFileAttributes(final PlexusIoResourceAttributes overrideFileAttributes) { this.overrideFileAttributes = overrideFileAttributes; } - protected PlexusIoResourceAttributes getOverrideDirAttributes() - { + protected PlexusIoResourceAttributes getOverrideDirAttributes() { return overrideDirAttributes; } - protected void setOverrideDirAttributes( final PlexusIoResourceAttributes overrideDirAttributes ) - { + protected void setOverrideDirAttributes(final PlexusIoResourceAttributes overrideDirAttributes) { this.overrideDirAttributes = overrideDirAttributes; } - protected PlexusIoResourceAttributes mergeAttributes( PlexusIoResourceAttributes currentAttrs, boolean isDirectory ) - { - if ( isDirectory ) - { - currentAttrs = PlexusIoResourceAttributeUtils.mergeAttributes( getOverrideDirAttributes(), currentAttrs, - getDefaultDirAttributes() ); - } - else - { - currentAttrs = PlexusIoResourceAttributeUtils.mergeAttributes( getOverrideFileAttributes(), currentAttrs, - getDefaultFileAttributes() ); + protected PlexusIoResourceAttributes mergeAttributes(PlexusIoResourceAttributes currentAttrs, boolean isDirectory) { + if (isDirectory) { + currentAttrs = PlexusIoResourceAttributeUtils.mergeAttributes( + getOverrideDirAttributes(), currentAttrs, getDefaultDirAttributes()); + } else { + currentAttrs = PlexusIoResourceAttributeUtils.mergeAttributes( + getOverrideFileAttributes(), currentAttrs, getDefaultFileAttributes()); } return currentAttrs; } diff --git a/src/main/java/org/codehaus/plexus/components/io/resources/ClosingInputStream.java b/src/main/java/org/codehaus/plexus/components/io/resources/ClosingInputStream.java index 8eb275ff..13f210e3 100644 --- a/src/main/java/org/codehaus/plexus/components/io/resources/ClosingInputStream.java +++ b/src/main/java/org/codehaus/plexus/components/io/resources/ClosingInputStream.java @@ -6,78 +6,59 @@ /** * @author Kristian Rosenvold */ -public class ClosingInputStream - extends InputStream -{ +public class ClosingInputStream extends InputStream { private final InputStream target; private final InputStream other; - public ClosingInputStream( InputStream target, InputStream other ) - { + public ClosingInputStream(InputStream target, InputStream other) { this.target = target; this.other = other; } @Override - public int read() - throws IOException - { + public int read() throws IOException { return target.read(); } @Override - public int read( byte[] b ) - throws IOException - { - return target.read( b ); + public int read(byte[] b) throws IOException { + return target.read(b); } @Override - public int read( byte[] b, int off, int len ) - throws IOException - { - return target.read( b, off, len ); + public int read(byte[] b, int off, int len) throws IOException { + return target.read(b, off, len); } @Override - public long skip( long n ) - throws IOException - { - return target.skip( n ); + public long skip(long n) throws IOException { + return target.skip(n); } @Override - public int available() - throws IOException - { + public int available() throws IOException { return target.available(); } @Override - public void close() - throws IOException - { + public void close() throws IOException { other.close(); target.close(); } @Override - public void mark( int readlimit ) - { - target.mark( readlimit ); + public void mark(int readlimit) { + target.mark(readlimit); } @Override - public void reset() - throws IOException - { + public void reset() throws IOException { target.reset(); } @Override - public boolean markSupported() - { + public boolean markSupported() { return target.markSupported(); } } diff --git a/src/main/java/org/codehaus/plexus/components/io/resources/DefaultPlexusIoFileResourceCollection.java b/src/main/java/org/codehaus/plexus/components/io/resources/DefaultPlexusIoFileResourceCollection.java index 44634f4c..fbfdccc0 100644 --- a/src/main/java/org/codehaus/plexus/components/io/resources/DefaultPlexusIoFileResourceCollection.java +++ b/src/main/java/org/codehaus/plexus/components/io/resources/DefaultPlexusIoFileResourceCollection.java @@ -22,7 +22,4 @@ * Alias for {@link PlexusIoFileResourceCollection} */ @Named -public class DefaultPlexusIoFileResourceCollection - extends PlexusIoFileResourceCollection -{ -} +public class DefaultPlexusIoFileResourceCollection extends PlexusIoFileResourceCollection {} diff --git a/src/main/java/org/codehaus/plexus/components/io/resources/Deferred.java b/src/main/java/org/codehaus/plexus/components/io/resources/Deferred.java index 77b4af1e..c7461f3a 100644 --- a/src/main/java/org/codehaus/plexus/components/io/resources/Deferred.java +++ b/src/main/java/org/codehaus/plexus/components/io/resources/Deferred.java @@ -15,6 +15,13 @@ */ package org.codehaus.plexus.components.io.resources; +import javax.annotation.Nonnull; + +import java.io.ByteArrayInputStream; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; + import org.apache.commons.io.IOUtils; import org.apache.commons.io.output.DeferredFileOutputStream; import org.codehaus.plexus.components.io.functions.ContentSupplier; @@ -22,55 +29,36 @@ import org.codehaus.plexus.components.io.functions.SizeSupplier; import org.codehaus.plexus.components.io.resources.proxy.ProxyFactory; -import javax.annotation.Nonnull; -import java.io.ByteArrayInputStream; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.InputStream; - -class Deferred implements ContentSupplier, NameSupplier, SizeSupplier -{ +class Deferred implements ContentSupplier, NameSupplier, SizeSupplier { final DeferredFileOutputStream dfos; final PlexusIoResource resource; final PlexusIoResourceCollection owner; - public Deferred( final PlexusIoResource resource, PlexusIoResourceCollection owner, boolean hasTransformer ) - throws IOException - { + public Deferred(final PlexusIoResource resource, PlexusIoResourceCollection owner, boolean hasTransformer) + throws IOException { this.resource = resource; this.owner = owner; - dfos = hasTransformer ? new DeferredFileOutputStream( 5000000, "p-archiver", null, null ) : null; - if ( dfos != null ) - { - InputStream inputStream = owner.getInputStream( resource ); - IOUtils.copy( inputStream, dfos ); - IOUtils.closeQuietly( inputStream ); + dfos = hasTransformer ? new DeferredFileOutputStream(5000000, "p-archiver", null, null) : null; + if (dfos != null) { + InputStream inputStream = owner.getInputStream(resource); + IOUtils.copy(inputStream, dfos); + IOUtils.closeQuietly(inputStream); } - } @Nonnull - public InputStream getContents() - throws IOException - { - if ( dfos == null ) - { + public InputStream getContents() throws IOException { + if (dfos == null) { return resource.getContents(); } - if ( dfos.isInMemory() ) - { - return new ByteArrayInputStream( dfos.getData() ); - } - else - { - return new FileInputStream( dfos.getFile() ) - { + if (dfos.isInMemory()) { + return new ByteArrayInputStream(dfos.getData()); + } else { + return new FileInputStream(dfos.getFile()) { @Override - public void close() - throws IOException - { + public void close() throws IOException { super.close(); dfos.getFile().delete(); } @@ -78,30 +66,22 @@ public void close() } } - public long getSize() - { - if ( dfos == null ) - { + public long getSize() { + if (dfos == null) { return resource.getSize(); } - if ( dfos.isInMemory() ) - { + if (dfos.isInMemory()) { return dfos.getByteCount(); - } - else - { + } else { return dfos.getFile().length(); } } - public String getName() - { - return owner.getName( resource ); + public String getName() { + return owner.getName(resource); } - public PlexusIoResource asResource() - { - return ProxyFactory.createProxy( resource, Deferred.this ); + public PlexusIoResource asResource() { + return ProxyFactory.createProxy(resource, Deferred.this); } - } diff --git a/src/main/java/org/codehaus/plexus/components/io/resources/EncodingSupported.java b/src/main/java/org/codehaus/plexus/components/io/resources/EncodingSupported.java index 74b1a20b..f036a3de 100644 --- a/src/main/java/org/codehaus/plexus/components/io/resources/EncodingSupported.java +++ b/src/main/java/org/codehaus/plexus/components/io/resources/EncodingSupported.java @@ -21,11 +21,10 @@ /** * Implemented by plexus io resources that support some kind of encoding notion */ -public interface EncodingSupported -{ +public interface EncodingSupported { /** * Supplies the encoding to be used for decoding filenames/paths * @param charset The charset to use */ - void setEncoding( Charset charset ); + void setEncoding(Charset charset); } diff --git a/src/main/java/org/codehaus/plexus/components/io/resources/LinefeedMode.java b/src/main/java/org/codehaus/plexus/components/io/resources/LinefeedMode.java index 281c2a97..b7c9ab64 100644 --- a/src/main/java/org/codehaus/plexus/components/io/resources/LinefeedMode.java +++ b/src/main/java/org/codehaus/plexus/components/io/resources/LinefeedMode.java @@ -18,7 +18,8 @@ /** * @author Kristian Rosenvold */ -public enum LinefeedMode -{ - dos, unix, preserve +public enum LinefeedMode { + dos, + unix, + preserve } diff --git a/src/main/java/org/codehaus/plexus/components/io/resources/PlexusIoArchivedResourceCollection.java b/src/main/java/org/codehaus/plexus/components/io/resources/PlexusIoArchivedResourceCollection.java index a5e1270e..56b7051b 100644 --- a/src/main/java/org/codehaus/plexus/components/io/resources/PlexusIoArchivedResourceCollection.java +++ b/src/main/java/org/codehaus/plexus/components/io/resources/PlexusIoArchivedResourceCollection.java @@ -22,16 +22,14 @@ * Extension of {@link PlexusIoResourceCollection} for archive * files: zip, tar, gzip, bzip2, etc. files. */ -public interface PlexusIoArchivedResourceCollection - extends PlexusIoResourceCollection -{ +public interface PlexusIoArchivedResourceCollection extends PlexusIoResourceCollection { /** * Sets the archive file */ - void setFile( File file ); + void setFile(File file); /** * Returns the archive file */ File getFile(); -} \ No newline at end of file +} diff --git a/src/main/java/org/codehaus/plexus/components/io/resources/PlexusIoCompressedFileResourceCollection.java b/src/main/java/org/codehaus/plexus/components/io/resources/PlexusIoCompressedFileResourceCollection.java index 8be86877..e1038032 100644 --- a/src/main/java/org/codehaus/plexus/components/io/resources/PlexusIoCompressedFileResourceCollection.java +++ b/src/main/java/org/codehaus/plexus/components/io/resources/PlexusIoCompressedFileResourceCollection.java @@ -16,12 +16,8 @@ * limitations under the License. */ -import org.codehaus.plexus.components.io.attributes.PlexusIoResourceAttributes; -import org.codehaus.plexus.components.io.functions.ContentSupplier; -import org.codehaus.plexus.components.io.functions.InputStreamTransformer; -import org.codehaus.plexus.components.io.functions.PlexusIoResourceConsumer; - import javax.annotation.Nonnull; + import java.io.Closeable; import java.io.File; import java.io.IOException; @@ -29,166 +25,129 @@ import java.util.Collections; import java.util.Iterator; +import org.codehaus.plexus.components.io.attributes.PlexusIoResourceAttributes; +import org.codehaus.plexus.components.io.functions.ContentSupplier; +import org.codehaus.plexus.components.io.functions.InputStreamTransformer; +import org.codehaus.plexus.components.io.functions.PlexusIoResourceConsumer; /** * Abstract base class for compressed files, aka singleton * resource collections. */ public abstract class PlexusIoCompressedFileResourceCollection - implements PlexusIoArchivedResourceCollection, Iterable -{ + implements PlexusIoArchivedResourceCollection, Iterable { private File file; private String path; private InputStreamTransformer streamTransformers = AbstractPlexusIoResourceCollection.identityTransformer; - - public File getFile() - { + public File getFile() { return file; } - public void setFile( File file ) - { + public void setFile(File file) { this.file = file; - } - public String getPath() - { + public String getPath() { return path; } - public void setPath( String path ) - { + public void setPath(String path) { this.path = path; - } // return the file attributes of the uncompressed file // may be null. - protected abstract PlexusIoResourceAttributes getAttributes( File f ) - throws IOException; + protected abstract PlexusIoResourceAttributes getAttributes(File f) throws IOException; - public void setStreamTransformer( InputStreamTransformer streamTransformers ) - { + public void setStreamTransformer(InputStreamTransformer streamTransformers) { this.streamTransformers = streamTransformers; } - public Stream stream() - { - return new Stream() - { - public void forEach( PlexusIoResourceConsumer resourceConsumer ) - throws IOException - { + public Stream stream() { + return new Stream() { + public void forEach(PlexusIoResourceConsumer resourceConsumer) throws IOException { final Iterator it = getResources(); - while ( it.hasNext() ) - { - resourceConsumer.accept( it.next() ); + while (it.hasNext()) { + resourceConsumer.accept(it.next()); } - if ( it instanceof Closeable ) - { - ( (Closeable) it ).close(); + if (it instanceof Closeable) { + ((Closeable) it).close(); } } }; } - public Iterator getResources() - throws IOException - { + public Iterator getResources() throws IOException { final File f = getFile(); - final String p = ( getPath() == null ? getName( f ) : getPath() ).replace( '\\', '/' ); - if ( f == null ) - { - throw new IOException( "No archive file is set." ); + final String p = (getPath() == null ? getName(f) : getPath()).replace('\\', '/'); + if (f == null) { + throw new IOException("No archive file is set."); } - if ( !f.isFile() ) - { - throw new IOException( "The archive file " + f.getPath() + " does not exist or is no file." ); + if (!f.isFile()) { + throw new IOException("The archive file " + f.getPath() + " does not exist or is no file."); } - final PlexusIoResourceAttributes attributes = getAttributes( f ); + final PlexusIoResourceAttributes attributes = getAttributes(f); - final ContentSupplier contentSupplier = new ContentSupplier() - { + final ContentSupplier contentSupplier = new ContentSupplier() { @Nonnull - public InputStream getContents() - throws IOException - { - return getInputStream( f ); + public InputStream getContents() throws IOException { + return getInputStream(f); } }; - final PlexusIoResource resource = - ResourceFactory.createResource( f, p, contentSupplier, attributes ); + final PlexusIoResource resource = ResourceFactory.createResource(f, p, contentSupplier, attributes); - return Collections.singleton( resource ).iterator(); + return Collections.singleton(resource).iterator(); } - protected String getName( File file ) - throws IOException - { + protected String getName(File file) throws IOException { final String name = file.getPath(); final String ext = getDefaultExtension(); - if ( ext != null && ext.length() > 0 && name.endsWith( ext ) ) - { - return name.substring( 0, name.length() - ext.length() ); + if (ext != null && ext.length() > 0 && name.endsWith(ext)) { + return name.substring(0, name.length() - ext.length()); } return name; } protected abstract String getDefaultExtension(); - protected abstract @Nonnull InputStream getInputStream( File file ) - throws IOException; + protected abstract @Nonnull InputStream getInputStream(File file) throws IOException; - public InputStream getInputStream( PlexusIoResource resource ) - throws IOException - { + public InputStream getInputStream(PlexusIoResource resource) throws IOException { InputStream contents = resource.getContents(); - return new ClosingInputStream( streamTransformers.transform( resource, contents ), contents ); + return new ClosingInputStream(streamTransformers.transform(resource, contents), contents); } - public PlexusIoResource resolve( final PlexusIoResource resource ) - throws IOException - { - final Deferred deferred = new Deferred( resource, this, streamTransformers - != AbstractPlexusIoResourceCollection.identityTransformer ); + public PlexusIoResource resolve(final PlexusIoResource resource) throws IOException { + final Deferred deferred = new Deferred( + resource, this, streamTransformers != AbstractPlexusIoResourceCollection.identityTransformer); return deferred.asResource(); } - - public Iterator iterator() - { - try - { + public Iterator iterator() { + try { return getResources(); - } - catch ( IOException e ) - { - throw new RuntimeException( e ); + } catch (IOException e) { + throw new RuntimeException(e); } } - public String getName( PlexusIoResource resource ) - { + public String getName(PlexusIoResource resource) { return resource.getName(); } - public long getLastModified() - throws IOException - { + public long getLastModified() throws IOException { File f = getFile(); return f == null ? PlexusIoResource.UNKNOWN_MODIFICATION_DATE : f.lastModified(); } - public boolean isConcurrentAccessSupported() - { + public boolean isConcurrentAccessSupported() { // There is a single resource in the collection so it is safe return true; } -} \ No newline at end of file +} diff --git a/src/main/java/org/codehaus/plexus/components/io/resources/PlexusIoFileResource.java b/src/main/java/org/codehaus/plexus/components/io/resources/PlexusIoFileResource.java index b6babcc5..a97334c3 100755 --- a/src/main/java/org/codehaus/plexus/components/io/resources/PlexusIoFileResource.java +++ b/src/main/java/org/codehaus/plexus/components/io/resources/PlexusIoFileResource.java @@ -16,6 +16,8 @@ * limitations under the License. */ +import javax.annotation.Nonnull; + import java.io.ByteArrayInputStream; import java.io.File; import java.io.FileInputStream; @@ -23,7 +25,6 @@ import java.io.InputStream; import java.net.URL; import java.nio.file.attribute.FileTime; -import java.util.function.Supplier; import org.apache.commons.io.IOUtils; import org.apache.commons.io.output.DeferredFileOutputStream; @@ -35,18 +36,13 @@ import org.codehaus.plexus.components.io.functions.InputStreamTransformer; import org.codehaus.plexus.components.io.functions.ResourceAttributeSupplier; -import javax.annotation.Nonnull; - import static java.util.Objects.requireNonNull; /** * Implementation of {@link PlexusIoResource} for files. */ -public class PlexusIoFileResource - extends AbstractPlexusIoResource - implements ResourceAttributeSupplier, FileSupplier +public class PlexusIoFileResource extends AbstractPlexusIoResource implements ResourceAttributeSupplier, FileSupplier { -{ @Nonnull private final File file; @@ -60,102 +56,94 @@ public class PlexusIoFileResource private final DeferredFileOutputStream dfos; - protected PlexusIoFileResource( @Nonnull File file, @Nonnull String name, - @Nonnull PlexusIoResourceAttributes attrs ) - throws IOException - { - this( file, name, attrs, null, null ); - } - - PlexusIoFileResource( @Nonnull final File file, @Nonnull String name, @Nonnull PlexusIoResourceAttributes attrs, - final ContentSupplier contentSupplier, final InputStreamTransformer streamTransformer ) - throws IOException - { - this( file, name, attrs, - new FileAttributes( file, true ), - contentSupplier, streamTransformer ); - } - - PlexusIoFileResource( @Nonnull final File file, @Nonnull String name, - @Nonnull PlexusIoResourceAttributes attrs, @Nonnull FileAttributes fileAttributes, - final ContentSupplier contentSupplier, final InputStreamTransformer streamTransformer ) - throws IOException - { - super( name, fileAttributes.getLastModifiedTime().toMillis(), fileAttributes.getSize(), - fileAttributes.isRegularFile(), fileAttributes.isDirectory(), - fileAttributes.isRegularFile() || fileAttributes.isDirectory() || fileAttributes.isSymbolicLink() || fileAttributes.isOther() ); + protected PlexusIoFileResource(@Nonnull File file, @Nonnull String name, @Nonnull PlexusIoResourceAttributes attrs) + throws IOException { + this(file, name, attrs, null, null); + } + + PlexusIoFileResource( + @Nonnull final File file, + @Nonnull String name, + @Nonnull PlexusIoResourceAttributes attrs, + final ContentSupplier contentSupplier, + final InputStreamTransformer streamTransformer) + throws IOException { + this(file, name, attrs, new FileAttributes(file, true), contentSupplier, streamTransformer); + } + + PlexusIoFileResource( + @Nonnull final File file, + @Nonnull String name, + @Nonnull PlexusIoResourceAttributes attrs, + @Nonnull FileAttributes fileAttributes, + final ContentSupplier contentSupplier, + final InputStreamTransformer streamTransformer) + throws IOException { + super( + name, + fileAttributes.getLastModifiedTime().toMillis(), + fileAttributes.getSize(), + fileAttributes.isRegularFile(), + fileAttributes.isDirectory(), + fileAttributes.isRegularFile() + || fileAttributes.isDirectory() + || fileAttributes.isSymbolicLink() + || fileAttributes.isOther()); this.file = file; - this.attributes = requireNonNull( attrs, "attributes is null for file " + file.getName() ); - this.fileAttributes = requireNonNull( fileAttributes, "fileAttributes is null for file " + file.getName() ); - this.contentSupplier = contentSupplier != null ? contentSupplier : getRootContentSupplier( file ); + this.attributes = requireNonNull(attrs, "attributes is null for file " + file.getName()); + this.fileAttributes = requireNonNull(fileAttributes, "fileAttributes is null for file " + file.getName()); + this.contentSupplier = contentSupplier != null ? contentSupplier : getRootContentSupplier(file); boolean hasTransformer = streamTransformer != null && streamTransformer != identityTransformer; InputStreamTransformer transToUse = streamTransformer != null ? streamTransformer : identityTransformer; - dfos = hasTransformer && file.isFile() ? asDeferredStream( this.contentSupplier, transToUse, this ) : null; + dfos = hasTransformer && file.isFile() ? asDeferredStream(this.contentSupplier, transToUse, this) : null; } - private static DeferredFileOutputStream asDeferredStream( @Nonnull ContentSupplier supplier, - @Nonnull InputStreamTransformer transToUse, - PlexusIoResource resource ) - throws IOException - { - DeferredFileOutputStream dfos = new DeferredFileOutputStream( 5000000, "p-archiver", null, null ); + private static DeferredFileOutputStream asDeferredStream( + @Nonnull ContentSupplier supplier, @Nonnull InputStreamTransformer transToUse, PlexusIoResource resource) + throws IOException { + DeferredFileOutputStream dfos = new DeferredFileOutputStream(5000000, "p-archiver", null, null); InputStream inputStream = supplier.getContents(); - InputStream transformed = transToUse.transform( resource, inputStream ); - IOUtils.copy( transformed, dfos ); - IOUtils.closeQuietly( inputStream ); - IOUtils.closeQuietly( transformed ); + InputStream transformed = transToUse.transform(resource, inputStream); + IOUtils.copy(transformed, dfos); + IOUtils.closeQuietly(inputStream); + IOUtils.closeQuietly(transformed); return dfos; } - private static ContentSupplier getRootContentSupplier( final File file ) - { - return new ContentSupplier() - { - public InputStream getContents() - throws IOException - { - return new FileInputStream( file ); + private static ContentSupplier getRootContentSupplier(final File file) { + return new ContentSupplier() { + public InputStream getContents() throws IOException { + return new FileInputStream(file); } }; } - public static String getName( File file ) - { - return file.getPath().replace( '\\', '/' ); + public static String getName(File file) { + return file.getPath().replace('\\', '/'); } /** * Returns the resource file. */ @Nonnull - public File getFile() - { + public File getFile() { return file; } @Nonnull - public InputStream getContents() - throws IOException - { - if ( dfos == null ) - { + public InputStream getContents() throws IOException { + if (dfos == null) { return contentSupplier.getContents(); } - if ( dfos.isInMemory() ) - { - return new ByteArrayInputStream( dfos.getData() ); - } - else - { - return new FileInputStream( dfos.getFile() ) - { - @SuppressWarnings( "ResultOfMethodCallIgnored" ) + if (dfos.isInMemory()) { + return new ByteArrayInputStream(dfos.getData()); + } else { + return new FileInputStream(dfos.getFile()) { + @SuppressWarnings("ResultOfMethodCallIgnored") @Override - public void close() - throws IOException - { + public void close() throws IOException { super.close(); dfos.getFile().delete(); } @@ -164,79 +152,63 @@ public void close() } @Nonnull - public URL getURL() - throws IOException - { + public URL getURL() throws IOException { return getFile().toURI().toURL(); } - public long getSize() - { - if ( dfos == null ) - { + public long getSize() { + if (dfos == null) { return fileAttributes.getSize(); } - if ( dfos.isInMemory() ) - { + if (dfos.isInMemory()) { return dfos.getByteCount(); - } - else - { + } else { return dfos.getFile().length(); } } - public boolean isDirectory() - { + public boolean isDirectory() { return fileAttributes.isDirectory(); } - public boolean isExisting() - { - if ( attributes instanceof FileAttributes ) - { + public boolean isExisting() { + if (attributes instanceof FileAttributes) { return true; } return getFile().exists(); } - public boolean isFile() - { + public boolean isFile() { return fileAttributes.isRegularFile(); } @Nonnull - public PlexusIoResourceAttributes getAttributes() - { + public PlexusIoResourceAttributes getAttributes() { return attributes; } @Nonnull - public FileAttributes getFileAttributes() - { + public FileAttributes getFileAttributes() { return fileAttributes; } - public long getLastModified() - { + public long getLastModified() { FileTime lastModified = fileAttributes.getLastModifiedTime(); - if ( lastModified != null ) - { + if (lastModified != null) { return lastModified.toMillis(); } - return AttributeUtils.getLastModified( getFile() ); + return AttributeUtils.getLastModified(getFile()); } @Override - public boolean isSymbolicLink() - { + public boolean isSymbolicLink() { return getAttributes().isSymbolicLink(); } - protected DeferredFileOutputStream getDfos() - { + protected DeferredFileOutputStream getDfos() { return dfos; } - private static final InputStreamTransformer identityTransformer = AbstractPlexusIoResourceCollection.identityTransformer; -} \ No newline at end of file + private static final InputStreamTransformer identityTransformer = + AbstractPlexusIoResourceCollection.identityTransformer; +} diff --git a/src/main/java/org/codehaus/plexus/components/io/resources/PlexusIoFileResourceCollection.java b/src/main/java/org/codehaus/plexus/components/io/resources/PlexusIoFileResourceCollection.java index 39eb46a3..71dcc5f3 100644 --- a/src/main/java/org/codehaus/plexus/components/io/resources/PlexusIoFileResourceCollection.java +++ b/src/main/java/org/codehaus/plexus/components/io/resources/PlexusIoFileResourceCollection.java @@ -18,33 +18,30 @@ import javax.inject.Named; -import org.codehaus.plexus.components.io.attributes.FileAttributes; -import org.codehaus.plexus.components.io.attributes.PlexusIoResourceAttributes; -import org.codehaus.plexus.components.io.attributes.SimpleResourceAttributes; -import org.codehaus.plexus.components.io.functions.PlexusIoResourceConsumer; -import org.codehaus.plexus.util.DirectoryScanner; -import org.codehaus.plexus.util.StringUtils; - import java.io.Closeable; import java.io.File; import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; import java.util.Comparator; -import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.concurrent.Callable; import java.util.concurrent.ExecutorService; +import org.codehaus.plexus.components.io.attributes.FileAttributes; +import org.codehaus.plexus.components.io.attributes.PlexusIoResourceAttributes; +import org.codehaus.plexus.components.io.attributes.SimpleResourceAttributes; +import org.codehaus.plexus.components.io.functions.PlexusIoResourceConsumer; +import org.codehaus.plexus.util.DirectoryScanner; +import org.codehaus.plexus.util.StringUtils; + /** * Implementation of {@link PlexusIoResourceCollection} for the set * of files in a common directory. */ -@Named( PlexusIoFileResourceCollection.ROLE_HINT ) -public class PlexusIoFileResourceCollection - extends AbstractPlexusIoResourceCollectionWithAttributes -{ +@Named(PlexusIoFileResourceCollection.ROLE_HINT) +public class PlexusIoFileResourceCollection extends AbstractPlexusIoResourceCollectionWithAttributes { /** * Role hint of this component */ @@ -59,45 +56,33 @@ public class PlexusIoFileResourceCollection */ private Comparator filenameComparator; - public PlexusIoFileResourceCollection() - { - } - + public PlexusIoFileResourceCollection() {} - public PlexusIoResource resolve( final PlexusIoResource resource ) - throws IOException - { + public PlexusIoResource resolve(final PlexusIoResource resource) throws IOException { return resource; } - @Override - public InputStream getInputStream( PlexusIoResource resource ) - throws IOException - { + public InputStream getInputStream(PlexusIoResource resource) throws IOException { return resource.getContents(); } - @Override - public String getName( PlexusIoResource resource ) - { + public String getName(PlexusIoResource resource) { return resource.getName(); } /** * @param baseDir The base directory of the file collection */ - public void setBaseDir( File baseDir ) - { + public void setBaseDir(File baseDir) { this.baseDir = baseDir; } /** * @return Returns the file collections base directory. */ - public File getBaseDir() - { + public File getBaseDir() { return baseDir; } @@ -105,174 +90,149 @@ public File getBaseDir() * @return Returns, whether symbolic links should be followed. * Defaults to true. */ - public boolean isFollowingSymLinks() - { + public boolean isFollowingSymLinks() { return isFollowingSymLinks; } /** * @param pIsFollowingSymLinks whether symbolic links should be followed */ - @SuppressWarnings({ "UnusedDeclaration" }) - public void setFollowingSymLinks( boolean pIsFollowingSymLinks ) - { + @SuppressWarnings({"UnusedDeclaration"}) + public void setFollowingSymLinks(boolean pIsFollowingSymLinks) { isFollowingSymLinks = pIsFollowingSymLinks; } - public void setDefaultAttributes( final int uid, final String userName, final int gid, final String groupName, - final int fileMode, final int dirMode ) - { - setDefaultFileAttributes( createDefaults( uid, userName, gid, groupName, fileMode ) ); + public void setDefaultAttributes( + final int uid, + final String userName, + final int gid, + final String groupName, + final int fileMode, + final int dirMode) { + setDefaultFileAttributes(createDefaults(uid, userName, gid, groupName, fileMode)); - setDefaultDirAttributes( createDefaults( uid, userName, gid, groupName, dirMode ) ); + setDefaultDirAttributes(createDefaults(uid, userName, gid, groupName, dirMode)); } - public void setOverrideAttributes( final int uid, final String userName, final int gid, final String groupName, - final int fileMode, final int dirMode ) - { - setOverrideFileAttributes( createDefaults( uid, userName, gid, groupName, fileMode ) ); + public void setOverrideAttributes( + final int uid, + final String userName, + final int gid, + final String groupName, + final int fileMode, + final int dirMode) { + setOverrideFileAttributes(createDefaults(uid, userName, gid, groupName, fileMode)); - setOverrideDirAttributes( createDefaults( uid, userName, gid, groupName, dirMode ) ); + setOverrideDirAttributes(createDefaults(uid, userName, gid, groupName, dirMode)); } - private static PlexusIoResourceAttributes createDefaults( final int uid, final String userName, final int gid, - final String groupName, final int mode ) - { - return new SimpleResourceAttributes( uid, userName, gid, groupName, - mode >= 0 ? mode : PlexusIoResourceAttributes.UNKNOWN_OCTAL_MODE ); + private static PlexusIoResourceAttributes createDefaults( + final int uid, final String userName, final int gid, final String groupName, final int mode) { + return new SimpleResourceAttributes( + uid, userName, gid, groupName, mode >= 0 ? mode : PlexusIoResourceAttributes.UNKNOWN_OCTAL_MODE); } - @Override - public void setPrefix( String prefix ) - { + public void setPrefix(String prefix) { char nonSeparator = File.separatorChar == '/' ? '\\' : '/'; - super.setPrefix( StringUtils.replace( prefix, nonSeparator, File.separatorChar ) ); + super.setPrefix(StringUtils.replace(prefix, nonSeparator, File.separatorChar)); } - private void addResources( List result, String[] resources ) - throws IOException - { + private void addResources(List result, String[] resources) throws IOException { final File dir = getBaseDir(); - for ( String name : resources ) - { - String sourceDir = name.replace( '\\', '/' ); - File f = new File( dir, sourceDir ); + for (String name : resources) { + String sourceDir = name.replace('\\', '/'); + File f = new File(dir, sourceDir); - FileAttributes fattrs = new FileAttributes( f ); - PlexusIoResourceAttributes attrs = mergeAttributes( fattrs, fattrs.isDirectory() ); + FileAttributes fattrs = new FileAttributes(f); + PlexusIoResourceAttributes attrs = mergeAttributes(fattrs, fattrs.isDirectory()); - String remappedName = getName( name ); + String remappedName = getName(name); PlexusIoResource resource = - ResourceFactory.createResource( f, remappedName, null, getStreamTransformer(), attrs ); + ResourceFactory.createResource(f, remappedName, null, getStreamTransformer(), attrs); - if ( isSelected( resource ) ) - { - result.add( resource ); + if (isSelected(resource)) { + result.add(resource); } } } - public Stream stream() - { - return new Stream() - { - public void forEach( PlexusIoResourceConsumer resourceConsumer ) - throws IOException - { + public Stream stream() { + return new Stream() { + public void forEach(PlexusIoResourceConsumer resourceConsumer) throws IOException { Iterator resources = getResources(); - while ( resources.hasNext() ) - { + while (resources.hasNext()) { PlexusIoResource next = resources.next(); - if ( isSelected( next ) ) - { - resourceConsumer.accept( next ); + if (isSelected(next)) { + resourceConsumer.accept(next); } } - if ( resources instanceof Closeable ) - { - ( (Closeable) resources ).close(); + if (resources instanceof Closeable) { + ((Closeable) resources).close(); } - } - public void forEach( ExecutorService es, final PlexusIoResourceConsumer resourceConsumer ) - throws IOException - { + public void forEach(ExecutorService es, final PlexusIoResourceConsumer resourceConsumer) + throws IOException { Iterator resources = getResources(); - while ( resources.hasNext() ) - { + while (resources.hasNext()) { final PlexusIoResource next = resources.next(); - Callable future = new Callable() - { - public Object call() - throws Exception - { - resourceConsumer.accept( next ); + Callable future = new Callable() { + public Object call() throws Exception { + resourceConsumer.accept(next); return this; } }; - es.submit( future ); + es.submit(future); } - if ( resources instanceof Closeable ) - { - ( (Closeable) resources ).close(); + if (resources instanceof Closeable) { + ((Closeable) resources).close(); } - } }; - } - public Iterator getResources() - throws IOException - { + public Iterator getResources() throws IOException { final DirectoryScanner ds = new DirectoryScanner(); final File dir = getBaseDir(); - ds.setBasedir( dir ); + ds.setBasedir(dir); final String[] inc = getIncludes(); - if ( inc != null && inc.length > 0 ) - { - ds.setIncludes( inc ); + if (inc != null && inc.length > 0) { + ds.setIncludes(inc); } final String[] exc = getExcludes(); - if ( exc != null && exc.length > 0 ) - { - ds.setExcludes( exc ); + if (exc != null && exc.length > 0) { + ds.setExcludes(exc); } - if ( isUsingDefaultExcludes() ) - { + if (isUsingDefaultExcludes()) { ds.addDefaultExcludes(); } - ds.setCaseSensitive( isCaseSensitive() ); - ds.setFollowSymlinks( isFollowingSymLinks() ); - ds.setFilenameComparator( filenameComparator ); + ds.setCaseSensitive(isCaseSensitive()); + ds.setFollowSymlinks(isFollowingSymLinks()); + ds.setFilenameComparator(filenameComparator); ds.scan(); final List result = new ArrayList<>(); - if ( isIncludingEmptyDirectories() ) - { + if (isIncludingEmptyDirectories()) { String[] dirs = ds.getIncludedDirectories(); - addResources( result, dirs ); + addResources(result, dirs); } String[] files = ds.getIncludedFiles(); - addResources( result, files ); + addResources(result, files); return result.iterator(); } - public boolean isConcurrentAccessSupported() - { + public boolean isConcurrentAccessSupported() { return true; } /** * @since 3.2.0 */ - public void setFilenameComparator( Comparator filenameComparator ) - { + public void setFilenameComparator(Comparator filenameComparator) { this.filenameComparator = filenameComparator; } } diff --git a/src/main/java/org/codehaus/plexus/components/io/resources/PlexusIoResource.java b/src/main/java/org/codehaus/plexus/components/io/resources/PlexusIoResource.java index db1aaf17..27791a08 100644 --- a/src/main/java/org/codehaus/plexus/components/io/resources/PlexusIoResource.java +++ b/src/main/java/org/codehaus/plexus/components/io/resources/PlexusIoResource.java @@ -16,6 +16,8 @@ * limitations under the License. */ +import javax.annotation.Nonnull; + import java.io.IOException; import java.io.InputStream; import java.net.URL; @@ -24,15 +26,11 @@ import org.codehaus.plexus.components.io.functions.ContentSupplier; import org.codehaus.plexus.components.io.functions.SizeSupplier; -import javax.annotation.Nonnull; - - /** * A resource is a file-like entity. It may be an actual file, * an URL, a zip entry, or something like that. */ -public interface PlexusIoResource extends FileInfo, SizeSupplier, ContentSupplier -{ +public interface PlexusIoResource extends FileInfo, SizeSupplier, ContentSupplier { /** * Unknown resource size. */ @@ -61,7 +59,6 @@ public interface PlexusIoResource extends FileInfo, SizeSupplier, ContentSupplie */ long getSize(); - /** * Returns, whether the {@link FileInfo} refers to a file. */ @@ -90,4 +87,4 @@ public interface PlexusIoResource extends FileInfo, SizeSupplier, ContentSupplie * In the latter case, you are forced to use {@link #getContents()}. */ URL getURL() throws IOException; -} \ No newline at end of file +} diff --git a/src/main/java/org/codehaus/plexus/components/io/resources/PlexusIoResourceCollection.java b/src/main/java/org/codehaus/plexus/components/io/resources/PlexusIoResourceCollection.java index 8ef060ab..d4c2287f 100644 --- a/src/main/java/org/codehaus/plexus/components/io/resources/PlexusIoResourceCollection.java +++ b/src/main/java/org/codehaus/plexus/components/io/resources/PlexusIoResourceCollection.java @@ -23,8 +23,7 @@ /** * A resource collection is a set of {@link PlexusIoResource} instances. */ -public interface PlexusIoResourceCollection extends Iterable -{ +public interface PlexusIoResourceCollection extends Iterable { /** * Returns an iterator over the resources in the collection. * @return An iterator @@ -45,7 +44,7 @@ public interface PlexusIoResourceCollection extends Iterable * calling {@link #getResources()}. * @return The resource name. If it is a file, it should be normalized to platform separators */ - String getName( PlexusIoResource resource ); + String getName(PlexusIoResource resource); /** * Returns the collections last modification time. For a @@ -66,7 +65,7 @@ public interface PlexusIoResourceCollection extends Iterable * @return A possibly transformed resource * @throws IOException when something goes bad */ - InputStream getInputStream( PlexusIoResource resource ) throws IOException; + InputStream getInputStream(PlexusIoResource resource) throws IOException; /** * Resolves the supplied resource into a "real" resource. Resolving @@ -76,7 +75,7 @@ public interface PlexusIoResourceCollection extends Iterable * @return A possibly transformed resource * @throws IOException when something goes bad */ - PlexusIoResource resolve( PlexusIoResource resource ) throws IOException; + PlexusIoResource resolve(PlexusIoResource resource) throws IOException; /** * Indicates if this collection supports concurrent access to its resources. @@ -96,5 +95,4 @@ public interface PlexusIoResourceCollection extends Iterable * otherwise {@code false} */ boolean isConcurrentAccessSupported(); - -} \ No newline at end of file +} diff --git a/src/main/java/org/codehaus/plexus/components/io/resources/PlexusIoSymlinkResource.java b/src/main/java/org/codehaus/plexus/components/io/resources/PlexusIoSymlinkResource.java index 135ee248..441fabfb 100644 --- a/src/main/java/org/codehaus/plexus/components/io/resources/PlexusIoSymlinkResource.java +++ b/src/main/java/org/codehaus/plexus/components/io/resources/PlexusIoSymlinkResource.java @@ -1,114 +1,96 @@ package org.codehaus.plexus.components.io.resources; -import org.apache.commons.io.output.DeferredFileOutputStream; -import org.codehaus.plexus.components.io.attributes.PlexusIoResourceAttributes; -import org.codehaus.plexus.components.io.attributes.SymlinkUtils; -import org.codehaus.plexus.components.io.functions.SymlinkDestinationSupplier; - import javax.annotation.Nonnull; + import java.io.File; import java.io.IOException; import java.nio.file.Path; -public class PlexusIoSymlinkResource - extends PlexusIoFileResource - implements SymlinkDestinationSupplier -{ +import org.apache.commons.io.output.DeferredFileOutputStream; +import org.codehaus.plexus.components.io.attributes.PlexusIoResourceAttributes; +import org.codehaus.plexus.components.io.functions.SymlinkDestinationSupplier; + +public class PlexusIoSymlinkResource extends PlexusIoFileResource implements SymlinkDestinationSupplier { private final String symLinkDestination; private final PlexusIoFileResource targetResource; - PlexusIoSymlinkResource( @Nonnull File symlinkfile, String name, @Nonnull PlexusIoResourceAttributes attrs ) - throws IOException - { - this( symlinkfile, name, attrs, symlinkfile.toPath() ); + PlexusIoSymlinkResource(@Nonnull File symlinkfile, String name, @Nonnull PlexusIoResourceAttributes attrs) + throws IOException { + this(symlinkfile, name, attrs, symlinkfile.toPath()); } - PlexusIoSymlinkResource( @Nonnull File symlinkfile, String name, @Nonnull PlexusIoResourceAttributes attrs, - Path linkPath ) - throws IOException - { - this( symlinkfile, name, attrs, linkPath, java.nio.file.Files.readSymbolicLink( linkPath ) ); + PlexusIoSymlinkResource( + @Nonnull File symlinkfile, String name, @Nonnull PlexusIoResourceAttributes attrs, Path linkPath) + throws IOException { + this(symlinkfile, name, attrs, linkPath, java.nio.file.Files.readSymbolicLink(linkPath)); } - private PlexusIoSymlinkResource( @Nonnull File symlinkfile, String name, @Nonnull PlexusIoResourceAttributes attrs, - Path path, Path linkPath ) - throws IOException - { - this( symlinkfile, name, attrs, linkPath.toString(), - ( PlexusIoFileResource ) ResourceFactory.createResource( path.resolveSibling( linkPath ).toFile() ) ); + private PlexusIoSymlinkResource( + @Nonnull File symlinkfile, String name, @Nonnull PlexusIoResourceAttributes attrs, Path path, Path linkPath) + throws IOException { + this(symlinkfile, name, attrs, linkPath.toString(), (PlexusIoFileResource) + ResourceFactory.createResource(path.resolveSibling(linkPath).toFile())); } - private PlexusIoSymlinkResource( @Nonnull File symlinkfile, String name, @Nonnull PlexusIoResourceAttributes attrs, - String symLinkDestination, PlexusIoFileResource targetResource ) - throws IOException - { - super( symlinkfile, name, attrs, targetResource.getFileAttributes(), null, null ); + private PlexusIoSymlinkResource( + @Nonnull File symlinkfile, + String name, + @Nonnull PlexusIoResourceAttributes attrs, + String symLinkDestination, + PlexusIoFileResource targetResource) + throws IOException { + super(symlinkfile, name, attrs, targetResource.getFileAttributes(), null, null); this.symLinkDestination = symLinkDestination; this.targetResource = targetResource; } - public String getSymlinkDestination() - throws IOException - { + public String getSymlinkDestination() throws IOException { return symLinkDestination; } - public PlexusIoResource getTarget() - { + public PlexusIoResource getTarget() { return targetResource; } - public PlexusIoResource getLink() throws IOException - { - return new PlexusIoFileResource( getFile(), getName(), getAttributes() ); + public PlexusIoResource getLink() throws IOException { + return new PlexusIoFileResource(getFile(), getName(), getAttributes()); } @Override - public long getSize() - { + public long getSize() { DeferredFileOutputStream dfos = getDfos(); - if ( dfos == null ) - { + if (dfos == null) { return targetResource.getSize(); - } - else if ( dfos.isInMemory() ) - { + } else if (dfos.isInMemory()) { return dfos.getByteCount(); - } - else - { + } else { return dfos.getFile().length(); } } @Override - public boolean isDirectory() - { + public boolean isDirectory() { return targetResource.isDirectory(); } @Override - public boolean isExisting() - { + public boolean isExisting() { return targetResource.isExisting(); } @Override - public boolean isFile() - { + public boolean isFile() { return targetResource.isFile(); } @Override - public long getLastModified() - { + public long getLastModified() { return targetResource.getLastModified(); } @Nonnull @Override - public PlexusIoResourceAttributes getAttributes() - { + public PlexusIoResourceAttributes getAttributes() { return super.getAttributes(); } } diff --git a/src/main/java/org/codehaus/plexus/components/io/resources/PlexusIoURLResource.java b/src/main/java/org/codehaus/plexus/components/io/resources/PlexusIoURLResource.java index c8c3df5b..6a414b7b 100644 --- a/src/main/java/org/codehaus/plexus/components/io/resources/PlexusIoURLResource.java +++ b/src/main/java/org/codehaus/plexus/components/io/resources/PlexusIoURLResource.java @@ -17,39 +17,36 @@ */ import javax.annotation.Nonnull; + import java.io.IOException; import java.io.InputStream; import java.net.URL; import java.net.URLConnection; -public abstract class PlexusIoURLResource - extends AbstractPlexusIoResource -{ - protected PlexusIoURLResource( @Nonnull String name, long lastModified, long size, boolean isFile, - boolean isDirectory, boolean isExisting ) - { - super( name, lastModified, size, isFile, isDirectory, isExisting ); +public abstract class PlexusIoURLResource extends AbstractPlexusIoResource { + protected PlexusIoURLResource( + @Nonnull String name, + long lastModified, + long size, + boolean isFile, + boolean isDirectory, + boolean isExisting) { + super(name, lastModified, size, isFile, isDirectory, isExisting); } @Nonnull - public InputStream getContents() - throws IOException - { + public InputStream getContents() throws IOException { final URL url = getURL(); - try - { + try { URLConnection uc = url.openConnection(); - uc.setUseCaches( false ); + uc.setUseCaches(false); return uc.getInputStream(); - } - catch ( IOException e ) - { - throw new IOException( getDescriptionForError( url ), e ); + } catch (IOException e) { + throw new IOException(getDescriptionForError(url), e); } } - public String getDescriptionForError( URL url ) - { + public String getDescriptionForError(URL url) { return url != null ? url.toExternalForm() : "url=null"; } diff --git a/src/main/java/org/codehaus/plexus/components/io/resources/ResourceFactory.java b/src/main/java/org/codehaus/plexus/components/io/resources/ResourceFactory.java index d8f97bba..8db319b4 100644 --- a/src/main/java/org/codehaus/plexus/components/io/resources/ResourceFactory.java +++ b/src/main/java/org/codehaus/plexus/components/io/resources/ResourceFactory.java @@ -1,62 +1,56 @@ package org.codehaus.plexus.components.io.resources; +import java.io.File; +import java.io.IOException; + import org.codehaus.plexus.components.io.attributes.FileAttributes; import org.codehaus.plexus.components.io.attributes.PlexusIoResourceAttributes; import org.codehaus.plexus.components.io.functions.ContentSupplier; import org.codehaus.plexus.components.io.functions.InputStreamTransformer; -import java.io.File; -import java.io.IOException; - import static org.codehaus.plexus.components.io.attributes.PlexusIoResourceAttributeUtils.getFileAttributes; import static org.codehaus.plexus.components.io.resources.PlexusIoFileResource.getName; /** * @author Kristian Rosenvold */ -public class ResourceFactory -{ - public static PlexusIoResource createResource( File f ) - throws IOException - { - return createResource( f, getName( f ), null, null, getFileAttributes( f ) ); +public class ResourceFactory { + public static PlexusIoResource createResource(File f) throws IOException { + return createResource(f, getName(f), null, null, getFileAttributes(f)); } - public static PlexusIoResource createResource( File f, String name ) - throws IOException - { - return createResource( f, name, null, null, getFileAttributes( f ) ); + public static PlexusIoResource createResource(File f, String name) throws IOException { + return createResource(f, name, null, null, getFileAttributes(f)); } - public static PlexusIoResource createResource( File f, String name, final ContentSupplier contentSupplier, - PlexusIoResourceAttributes attributes ) - throws IOException - { - return createResource( f, name, contentSupplier, null, attributes ); + public static PlexusIoResource createResource( + File f, String name, final ContentSupplier contentSupplier, PlexusIoResourceAttributes attributes) + throws IOException { + return createResource(f, name, contentSupplier, null, attributes); } - public static PlexusIoResource createResource( File f, InputStreamTransformer inputStreamTransformer ) - throws IOException - { - return createResource( f, getName( f ), null, inputStreamTransformer, getFileAttributes( f ) ); + public static PlexusIoResource createResource(File f, InputStreamTransformer inputStreamTransformer) + throws IOException { + return createResource(f, getName(f), null, inputStreamTransformer, getFileAttributes(f)); } - public static PlexusIoResource createResource( File f, String name, final ContentSupplier contentSupplier, - InputStreamTransformer inputStreamTransformer ) - throws IOException - { - return createResource( f, name, contentSupplier, inputStreamTransformer, getFileAttributes( f ) ); + public static PlexusIoResource createResource( + File f, String name, final ContentSupplier contentSupplier, InputStreamTransformer inputStreamTransformer) + throws IOException { + return createResource(f, name, contentSupplier, inputStreamTransformer, getFileAttributes(f)); } - public static PlexusIoResource createResource( File f, String name, final ContentSupplier contentSupplier, - InputStreamTransformer inputStreamTransformer, - PlexusIoResourceAttributes attributes ) - throws IOException - { + public static PlexusIoResource createResource( + File f, + String name, + final ContentSupplier contentSupplier, + InputStreamTransformer inputStreamTransformer, + PlexusIoResourceAttributes attributes) + throws IOException { boolean symbolicLink = attributes.isSymbolicLink(); - return symbolicLink ? new PlexusIoSymlinkResource( f, name, attributes ) - : new PlexusIoFileResource( f, name, attributes, - new FileAttributes( f, true ), contentSupplier, inputStreamTransformer ); + return symbolicLink + ? new PlexusIoSymlinkResource(f, name, attributes) + : new PlexusIoFileResource( + f, name, attributes, new FileAttributes(f, true), contentSupplier, inputStreamTransformer); } - } diff --git a/src/main/java/org/codehaus/plexus/components/io/resources/Stream.java b/src/main/java/org/codehaus/plexus/components/io/resources/Stream.java index 8a4fb5b8..ab6946e3 100644 --- a/src/main/java/org/codehaus/plexus/components/io/resources/Stream.java +++ b/src/main/java/org/codehaus/plexus/components/io/resources/Stream.java @@ -15,17 +15,15 @@ * limitations under the License. */ -import org.codehaus.plexus.components.io.functions.PlexusIoResourceConsumer; - import java.io.IOException; -public interface Stream -{ +import org.codehaus.plexus.components.io.functions.PlexusIoResourceConsumer; + +public interface Stream { /** * Invokes the #PlexusIoResourceConsumer for each resource in this collection * @param resourceConsumer The consumer of the resource * @throws java.io.IOException . */ - void forEach( PlexusIoResourceConsumer resourceConsumer ) throws IOException; - + void forEach(PlexusIoResourceConsumer resourceConsumer) throws IOException; } diff --git a/src/main/java/org/codehaus/plexus/components/io/resources/proxy/ForwardingIterator.java b/src/main/java/org/codehaus/plexus/components/io/resources/proxy/ForwardingIterator.java index 37b5c9a8..cb077018 100644 --- a/src/main/java/org/codehaus/plexus/components/io/resources/proxy/ForwardingIterator.java +++ b/src/main/java/org/codehaus/plexus/components/io/resources/proxy/ForwardingIterator.java @@ -15,45 +15,35 @@ */ package org.codehaus.plexus.components.io.resources.proxy; -import org.codehaus.plexus.components.io.resources.PlexusIoResource; - import java.io.Closeable; import java.io.IOException; import java.util.Iterator; import java.util.NoSuchElementException; -abstract class ForwardingIterator - implements Iterator, Closeable -{ +import org.codehaus.plexus.components.io.resources.PlexusIoResource; + +abstract class ForwardingIterator implements Iterator, Closeable { private final Object possiblyCloseable; private PlexusIoResource next = null; - ForwardingIterator( Object possiblyCloseable ) - { + ForwardingIterator(Object possiblyCloseable) { this.possiblyCloseable = possiblyCloseable; } - public boolean hasNext() - { - if ( next == null ) - { - try - { + public boolean hasNext() { + if (next == null) { + try { next = getNextResource(); - } - catch ( IOException e ) - { - throw new RuntimeException( e ); + } catch (IOException e) { + throw new RuntimeException(e); } } return next != null; } - public PlexusIoResource next() - { - if ( !hasNext() ) - { + public PlexusIoResource next() { + if (!hasNext()) { throw new NoSuchElementException(); } PlexusIoResource ret = next; @@ -61,19 +51,14 @@ public PlexusIoResource next() return ret; } - public void remove() - { + public void remove() { throw new UnsupportedOperationException(); } - public void close() - throws IOException - { - if ( possiblyCloseable instanceof Closeable ) - { - ( (Closeable) possiblyCloseable ).close(); + public void close() throws IOException { + if (possiblyCloseable instanceof Closeable) { + ((Closeable) possiblyCloseable).close(); } - } /** diff --git a/src/main/java/org/codehaus/plexus/components/io/resources/proxy/PlexusIoProxyResourceCollection.java b/src/main/java/org/codehaus/plexus/components/io/resources/proxy/PlexusIoProxyResourceCollection.java index 61c16d80..b540ee44 100644 --- a/src/main/java/org/codehaus/plexus/components/io/resources/proxy/PlexusIoProxyResourceCollection.java +++ b/src/main/java/org/codehaus/plexus/components/io/resources/proxy/PlexusIoProxyResourceCollection.java @@ -16,6 +16,12 @@ * limitations under the License. */ +import javax.annotation.Nonnull; + +import java.io.IOException; +import java.nio.charset.Charset; +import java.util.Iterator; + import org.codehaus.plexus.components.io.attributes.PlexusIoResourceAttributes; import org.codehaus.plexus.components.io.attributes.SimpleResourceAttributes; import org.codehaus.plexus.components.io.filemappers.FileMapper; @@ -31,174 +37,143 @@ import org.codehaus.plexus.components.io.resources.PlexusIoResourceCollection; import org.codehaus.plexus.components.io.resources.Stream; -import javax.annotation.Nonnull; -import java.io.IOException; -import java.nio.charset.Charset; -import java.util.Iterator; - /** * Implementation of {@link PlexusIoResourceCollection} for an archives contents. */ -public class PlexusIoProxyResourceCollection - extends AbstractPlexusIoResourceCollectionWithAttributes implements EncodingSupported -{ +public class PlexusIoProxyResourceCollection extends AbstractPlexusIoResourceCollectionWithAttributes + implements EncodingSupported { private PlexusIoResourceCollection src; - - public PlexusIoProxyResourceCollection( @Nonnull PlexusIoResourceCollection src ) - { + public PlexusIoProxyResourceCollection(@Nonnull PlexusIoResourceCollection src) { this.src = src; } /** * Returns the archive to read. */ - public PlexusIoResourceCollection getSrc() - { + public PlexusIoResourceCollection getSrc() { return src; } - public void setDefaultAttributes( final int uid, final String userName, final int gid, final String groupName, - final int fileMode, final int dirMode ) - { - setDefaultFileAttributes( new SimpleResourceAttributes( uid, userName, gid, groupName, fileMode ) ); + public void setDefaultAttributes( + final int uid, + final String userName, + final int gid, + final String groupName, + final int fileMode, + final int dirMode) { + setDefaultFileAttributes(new SimpleResourceAttributes(uid, userName, gid, groupName, fileMode)); - setDefaultDirAttributes( new SimpleResourceAttributes( uid, userName, gid, groupName, dirMode ) ); + setDefaultDirAttributes(new SimpleResourceAttributes(uid, userName, gid, groupName, dirMode)); } - public void setOverrideAttributes( final int uid, final String userName, final int gid, final String groupName, - final int fileMode, final int dirMode ) - { - setOverrideFileAttributes( new SimpleResourceAttributes( uid, userName, gid, groupName, fileMode ) ); + public void setOverrideAttributes( + final int uid, + final String userName, + final int gid, + final String groupName, + final int fileMode, + final int dirMode) { + setOverrideFileAttributes(new SimpleResourceAttributes(uid, userName, gid, groupName, fileMode)); - setOverrideDirAttributes( new SimpleResourceAttributes( uid, userName, gid, groupName, dirMode ) ); + setOverrideDirAttributes(new SimpleResourceAttributes(uid, userName, gid, groupName, dirMode)); } @Override - public void setStreamTransformer( InputStreamTransformer streamTransformer ) - { - if ( src instanceof AbstractPlexusIoResourceCollection ) - { - ( (AbstractPlexusIoResourceCollection) src ).setStreamTransformer( streamTransformer ); + public void setStreamTransformer(InputStreamTransformer streamTransformer) { + if (src instanceof AbstractPlexusIoResourceCollection) { + ((AbstractPlexusIoResourceCollection) src).setStreamTransformer(streamTransformer); } - super.setStreamTransformer( streamTransformer ); + super.setStreamTransformer(streamTransformer); } - protected FileSelector getDefaultFileSelector() - { + protected FileSelector getDefaultFileSelector() { final IncludeExcludeFileSelector fileSelector = new IncludeExcludeFileSelector(); - fileSelector.setIncludes( getIncludes() ); - fileSelector.setExcludes( getExcludes() ); - fileSelector.setCaseSensitive( isCaseSensitive() ); - fileSelector.setUseDefaultExcludes( isUsingDefaultExcludes() ); + fileSelector.setIncludes(getIncludes()); + fileSelector.setExcludes(getExcludes()); + fileSelector.setCaseSensitive(isCaseSensitive()); + fileSelector.setUseDefaultExcludes(isUsingDefaultExcludes()); return fileSelector; } - private String getNonEmptyPrfix() - { + private String getNonEmptyPrfix() { String prefix = getPrefix(); - if ( prefix != null && prefix.length() == 0 ) - { + if (prefix != null && prefix.length() == 0) { return null; } return prefix; - } - class FwdIterator - extends ForwardingIterator - { + class FwdIterator extends ForwardingIterator { Iterator iter; private final FileSelector fileSelector = getDefaultFileSelector(); private final String prefix = getNonEmptyPrfix(); - FwdIterator( Iterator resources ) - { - super( resources ); + FwdIterator(Iterator resources) { + super(resources); this.iter = resources; } /** * Returns the next resource or null if no next resource; */ - protected PlexusIoResource getNextResource() - throws IOException - { - if ( !iter.hasNext() ) - return null; + protected PlexusIoResource getNextResource() throws IOException { + if (!iter.hasNext()) return null; PlexusIoResource plexusIoResource = iter.next(); - while ( ( !fileSelector.isSelected( plexusIoResource ) || !isSelected( plexusIoResource ) ) - || ( plexusIoResource.isDirectory() && !isIncludingEmptyDirectories() ) ) - { - if ( !iter.hasNext() ) - return null; + while ((!fileSelector.isSelected(plexusIoResource) || !isSelected(plexusIoResource)) + || (plexusIoResource.isDirectory() && !isIncludingEmptyDirectories())) { + if (!iter.hasNext()) return null; plexusIoResource = iter.next(); } PlexusIoResourceAttributes attrs = null; - if ( plexusIoResource instanceof ResourceAttributeSupplier ) - { - attrs = ( (ResourceAttributeSupplier) plexusIoResource ).getAttributes(); + if (plexusIoResource instanceof ResourceAttributeSupplier) { + attrs = ((ResourceAttributeSupplier) plexusIoResource).getAttributes(); } - if ( attrs == null ) - { + if (attrs == null) { attrs = SimpleResourceAttributes.lastResortDummyAttributesForBrokenOS(); } - attrs = mergeAttributes( attrs, plexusIoResource.isDirectory() ); + attrs = mergeAttributes(attrs, plexusIoResource.isDirectory()); - if ( prefix != null ) - { + if (prefix != null) { final String name = plexusIoResource.getName(); final PlexusIoResourceAttributes attrs2 = attrs; - DualSupplier supplier = new DualSupplier() - { - public String getName() - { + DualSupplier supplier = new DualSupplier() { + public String getName() { return prefix + name; } - public PlexusIoResourceAttributes getAttributes() - { + public PlexusIoResourceAttributes getAttributes() { return attrs2; } }; - plexusIoResource = ProxyFactory.createProxy( plexusIoResource, supplier ); + plexusIoResource = ProxyFactory.createProxy(plexusIoResource, supplier); } return plexusIoResource; } } - public Stream stream() - { + public Stream stream() { return getSrc().stream(); } - public Iterator getResources() - throws IOException - { - return new FwdIterator( getSrc().getResources() ); + public Iterator getResources() throws IOException { + return new FwdIterator(getSrc().getResources()); } - abstract static class DualSupplier - implements NameSupplier, ResourceAttributeSupplier - { - - } + abstract static class DualSupplier implements NameSupplier, ResourceAttributeSupplier {} - public String getName( final PlexusIoResource resource ) - { + public String getName(final PlexusIoResource resource) { String name = resource.getName(); final FileMapper[] mappers = getFileMappers(); - if ( mappers != null ) - { - for ( FileMapper mapper : mappers ) - { - name = mapper.getMappedFileName( name ); + if (mappers != null) { + for (FileMapper mapper : mappers) { + name = mapper.getMappedFileName(name); } } /* @@ -208,22 +183,17 @@ public String getName( final PlexusIoResource resource ) return name; } - public long getLastModified() - throws IOException - { + public long getLastModified() throws IOException { return src.getLastModified(); } - public void setEncoding( Charset charset ) - { - if ( src instanceof EncodingSupported ) - { - ( (EncodingSupported) src ).setEncoding( charset ); + public void setEncoding(Charset charset) { + if (src instanceof EncodingSupported) { + ((EncodingSupported) src).setEncoding(charset); } } - public boolean isConcurrentAccessSupported() - { + public boolean isConcurrentAccessSupported() { return src.isConcurrentAccessSupported(); } } diff --git a/src/main/java/org/codehaus/plexus/components/io/resources/proxy/ProxyFactory.java b/src/main/java/org/codehaus/plexus/components/io/resources/proxy/ProxyFactory.java index 4b4bf9bd..3670a2e5 100644 --- a/src/main/java/org/codehaus/plexus/components/io/resources/proxy/ProxyFactory.java +++ b/src/main/java/org/codehaus/plexus/components/io/resources/proxy/ProxyFactory.java @@ -15,32 +15,29 @@ */ package org.codehaus.plexus.components.io.resources.proxy; -import org.codehaus.plexus.components.io.functions.FileSupplier; -import org.codehaus.plexus.components.io.functions.ResourceAttributeSupplier; -import org.codehaus.plexus.components.io.functions.SymlinkDestinationSupplier; -import org.codehaus.plexus.components.io.resources.PlexusIoResource; - import javax.annotation.Nonnull; + import java.lang.reflect.Proxy; import java.util.ArrayList; import java.util.List; -public class ProxyFactory -{ - public static PlexusIoResource createProxy( @Nonnull PlexusIoResource target, Object alternateSupplier ) - { +import org.codehaus.plexus.components.io.functions.FileSupplier; +import org.codehaus.plexus.components.io.functions.ResourceAttributeSupplier; +import org.codehaus.plexus.components.io.functions.SymlinkDestinationSupplier; +import org.codehaus.plexus.components.io.resources.PlexusIoResource; + +public class ProxyFactory { + public static PlexusIoResource createProxy(@Nonnull PlexusIoResource target, Object alternateSupplier) { List interfaces = new ArrayList<>(); - interfaces.add( PlexusIoResource.class ); - if ( target instanceof SymlinkDestinationSupplier ) - interfaces.add( SymlinkDestinationSupplier.class ); - if ( target instanceof FileSupplier ) - interfaces.add( FileSupplier.class ); - if ( target instanceof ResourceAttributeSupplier ) - interfaces.add( ResourceAttributeSupplier.class ); + interfaces.add(PlexusIoResource.class); + if (target instanceof SymlinkDestinationSupplier) interfaces.add(SymlinkDestinationSupplier.class); + if (target instanceof FileSupplier) interfaces.add(FileSupplier.class); + if (target instanceof ResourceAttributeSupplier) interfaces.add(ResourceAttributeSupplier.class); - return (PlexusIoResource) Proxy.newProxyInstance( PlexusIoResource.class.getClassLoader(), - interfaces.toArray( new Class[0] ), - new ResourceInvocationHandler( target, alternateSupplier ) ); + return (PlexusIoResource) Proxy.newProxyInstance( + PlexusIoResource.class.getClassLoader(), + interfaces.toArray(new Class[0]), + new ResourceInvocationHandler(target, alternateSupplier)); } } diff --git a/src/main/java/org/codehaus/plexus/components/io/resources/proxy/ResourceInvocationHandler.java b/src/main/java/org/codehaus/plexus/components/io/resources/proxy/ResourceInvocationHandler.java index d8601757..503317b1 100644 --- a/src/main/java/org/codehaus/plexus/components/io/resources/proxy/ResourceInvocationHandler.java +++ b/src/main/java/org/codehaus/plexus/components/io/resources/proxy/ResourceInvocationHandler.java @@ -15,6 +15,11 @@ */ package org.codehaus.plexus.components.io.resources.proxy; +import javax.annotation.Nonnull; + +import java.lang.reflect.InvocationHandler; +import java.lang.reflect.Method; + import org.codehaus.plexus.components.io.functions.ContentSupplier; import org.codehaus.plexus.components.io.functions.NameSupplier; import org.codehaus.plexus.components.io.functions.ResourceAttributeSupplier; @@ -22,13 +27,7 @@ import org.codehaus.plexus.components.io.functions.SymlinkDestinationSupplier; import org.codehaus.plexus.components.io.resources.PlexusIoResource; -import javax.annotation.Nonnull; -import java.lang.reflect.InvocationHandler; -import java.lang.reflect.Method; - -class ResourceInvocationHandler - implements InvocationHandler -{ +class ResourceInvocationHandler implements InvocationHandler { private PlexusIoResource testImpl; private final ContentSupplier contentSupplier; @@ -37,53 +36,40 @@ class ResourceInvocationHandler private final SymlinkDestinationSupplier symlinkDestinationSupplier; private final ResourceAttributeSupplier resourceAttributeSupplier; - public ResourceInvocationHandler( @Nonnull PlexusIoResource target, Object alternativeHandler ) - { + public ResourceInvocationHandler(@Nonnull PlexusIoResource target, Object alternativeHandler) { this.testImpl = target; - this.contentSupplier = asOrNull( alternativeHandler, ContentSupplier.class ); - this.nameSupplier = asOrNull( alternativeHandler, NameSupplier.class ); - this.sizeSupplier = asOrNull( alternativeHandler, SizeSupplier.class ); - this.symlinkDestinationSupplier = asOrNull( alternativeHandler, SymlinkDestinationSupplier.class ); - this.resourceAttributeSupplier = asOrNull( alternativeHandler, ResourceAttributeSupplier.class ); - + this.contentSupplier = asOrNull(alternativeHandler, ContentSupplier.class); + this.nameSupplier = asOrNull(alternativeHandler, NameSupplier.class); + this.sizeSupplier = asOrNull(alternativeHandler, SizeSupplier.class); + this.symlinkDestinationSupplier = asOrNull(alternativeHandler, SymlinkDestinationSupplier.class); + this.resourceAttributeSupplier = asOrNull(alternativeHandler, ResourceAttributeSupplier.class); } - @SuppressWarnings( "unchecked" ) - private static T asOrNull( Object instance, Class clazz ) - { - if ( instance != null && clazz.isAssignableFrom( instance.getClass() ) ) - return (T) instance; - else - return null; + @SuppressWarnings("unchecked") + private static T asOrNull(Object instance, Class clazz) { + if (instance != null && clazz.isAssignableFrom(instance.getClass())) return (T) instance; + else return null; } - public Object invoke( Object proxy, Method method, Object[] args ) - throws Throwable - { + public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { String name = method.getName(); - if ( contentSupplier != null && "getContents".equals( name ) ) - { + if (contentSupplier != null && "getContents".equals(name)) { return contentSupplier.getContents(); } - if ( nameSupplier != null && "getName".equals( name ) ) - { + if (nameSupplier != null && "getName".equals(name)) { return nameSupplier.getName(); } - if ( sizeSupplier != null && "getSize".equals( name ) ) - { + if (sizeSupplier != null && "getSize".equals(name)) { return sizeSupplier.getSize(); } - if ( symlinkDestinationSupplier != null && "getSymlinkDestination".equals( name ) ) - { + if (symlinkDestinationSupplier != null && "getSymlinkDestination".equals(name)) { return symlinkDestinationSupplier.getSymlinkDestination(); } - if ( resourceAttributeSupplier != null && "getAttributes".equals( name ) ) - { + if (resourceAttributeSupplier != null && "getAttributes".equals(name)) { return resourceAttributeSupplier.getAttributes(); } - return method.invoke( testImpl, args ); + return method.invoke(testImpl, args); } } - diff --git a/src/test/java/org/codehaus/plexus/components/io/attributes/AbstractResourceAttributesTCK.java b/src/test/java/org/codehaus/plexus/components/io/attributes/AbstractResourceAttributesTCK.java index 5364426f..b8755958 100644 --- a/src/test/java/org/codehaus/plexus/components/io/attributes/AbstractResourceAttributesTCK.java +++ b/src/test/java/org/codehaus/plexus/components/io/attributes/AbstractResourceAttributesTCK.java @@ -20,104 +20,91 @@ import static org.junit.Assert.assertEquals; -public abstract class AbstractResourceAttributesTCK -{ - - protected AbstractResourceAttributesTCK() - { - } - - protected abstract PlexusIoResourceAttributes newAttributes( int mode ); +public abstract class AbstractResourceAttributesTCK { + + protected AbstractResourceAttributesTCK() {} - protected abstract PlexusIoResourceAttributes newAttributes( String mode ); + protected abstract PlexusIoResourceAttributes newAttributes(int mode); + protected abstract PlexusIoResourceAttributes newAttributes(String mode); @Test - public final void testSetOctalModeString_OwnerModes() - { - verifyStringOctalModeSet( "700", new boolean[] { true, true, true, false, false, false, false, false, false } ); - verifyStringOctalModeSet( "600", new boolean[] { true, true, false, false, false, false, false, false, false } ); - verifyStringOctalModeSet( "400", new boolean[] { true, false, false, false, false, false, false, false, false } ); - verifyStringOctalModeSet( "200", new boolean[] { false, true, false, false, false, false, false, false, false } ); + public final void testSetOctalModeString_OwnerModes() { + verifyStringOctalModeSet("700", new boolean[] {true, true, true, false, false, false, false, false, false}); + verifyStringOctalModeSet("600", new boolean[] {true, true, false, false, false, false, false, false, false}); + verifyStringOctalModeSet("400", new boolean[] {true, false, false, false, false, false, false, false, false}); + verifyStringOctalModeSet("200", new boolean[] {false, true, false, false, false, false, false, false, false}); } @Test - public final void testSetOctalModeString_GroupModes() - { - verifyStringOctalModeSet( "070", new boolean[] { false, false, false, true, true, true, false, false, false } ); - verifyStringOctalModeSet( "060", new boolean[] { false, false, false, true, true, false, false, false, false } ); - verifyStringOctalModeSet( "040", new boolean[] { false, false, false, true, false, false, false, false, false } ); - verifyStringOctalModeSet( "020", new boolean[] { false, false, false, false, true, false, false, false, false } ); + public final void testSetOctalModeString_GroupModes() { + verifyStringOctalModeSet("070", new boolean[] {false, false, false, true, true, true, false, false, false}); + verifyStringOctalModeSet("060", new boolean[] {false, false, false, true, true, false, false, false, false}); + verifyStringOctalModeSet("040", new boolean[] {false, false, false, true, false, false, false, false, false}); + verifyStringOctalModeSet("020", new boolean[] {false, false, false, false, true, false, false, false, false}); } @Test - public final void testSetOctalModeString_WorldModes() - { - verifyStringOctalModeSet( "007", new boolean[] { false, false, false, false, false, false, true, true, true } ); - verifyStringOctalModeSet( "006", new boolean[] { false, false, false, false, false, false, true, true, false } ); - verifyStringOctalModeSet( "004", new boolean[] { false, false, false, false, false, false, true, false, false } ); - verifyStringOctalModeSet( "002", new boolean[] { false, false, false, false, false, false, false, true, false } ); + public final void testSetOctalModeString_WorldModes() { + verifyStringOctalModeSet("007", new boolean[] {false, false, false, false, false, false, true, true, true}); + verifyStringOctalModeSet("006", new boolean[] {false, false, false, false, false, false, true, true, false}); + verifyStringOctalModeSet("004", new boolean[] {false, false, false, false, false, false, true, false, false}); + verifyStringOctalModeSet("002", new boolean[] {false, false, false, false, false, false, false, true, false}); } @Test - public final void testSetOctalMode_OwnerModes() - { - verifyOctalModeSet( "700", new boolean[] { true, true, true, false, false, false, false, false, false } ); - verifyOctalModeSet( "600", new boolean[] { true, true, false, false, false, false, false, false, false } ); - verifyOctalModeSet( "400", new boolean[] { true, false, false, false, false, false, false, false, false } ); - verifyOctalModeSet( "200", new boolean[] { false, true, false, false, false, false, false, false, false } ); + public final void testSetOctalMode_OwnerModes() { + verifyOctalModeSet("700", new boolean[] {true, true, true, false, false, false, false, false, false}); + verifyOctalModeSet("600", new boolean[] {true, true, false, false, false, false, false, false, false}); + verifyOctalModeSet("400", new boolean[] {true, false, false, false, false, false, false, false, false}); + verifyOctalModeSet("200", new boolean[] {false, true, false, false, false, false, false, false, false}); } @Test - public final void testSetOctalMode_GroupModes() - { - verifyOctalModeSet( "070", new boolean[] { false, false, false, true, true, true, false, false, false } ); - verifyOctalModeSet( "060", new boolean[] { false, false, false, true, true, false, false, false, false } ); - verifyOctalModeSet( "040", new boolean[] { false, false, false, true, false, false, false, false, false } ); - verifyOctalModeSet( "020", new boolean[] { false, false, false, false, true, false, false, false, false } ); + public final void testSetOctalMode_GroupModes() { + verifyOctalModeSet("070", new boolean[] {false, false, false, true, true, true, false, false, false}); + verifyOctalModeSet("060", new boolean[] {false, false, false, true, true, false, false, false, false}); + verifyOctalModeSet("040", new boolean[] {false, false, false, true, false, false, false, false, false}); + verifyOctalModeSet("020", new boolean[] {false, false, false, false, true, false, false, false, false}); } @Test - public final void testSetOctalMode_WorldModes() - { - verifyOctalModeSet( "007", new boolean[] { false, false, false, false, false, false, true, true, true } ); - verifyOctalModeSet( "006", new boolean[] { false, false, false, false, false, false, true, true, false } ); - verifyOctalModeSet( "004", new boolean[] { false, false, false, false, false, false, true, false, false } ); - verifyOctalModeSet( "002", new boolean[] { false, false, false, false, false, false, false, true, false } ); + public final void testSetOctalMode_WorldModes() { + verifyOctalModeSet("007", new boolean[] {false, false, false, false, false, false, true, true, true}); + verifyOctalModeSet("006", new boolean[] {false, false, false, false, false, false, true, true, false}); + verifyOctalModeSet("004", new boolean[] {false, false, false, false, false, false, true, false, false}); + verifyOctalModeSet("002", new boolean[] {false, false, false, false, false, false, false, true, false}); } - private void verifyStringOctalModeSet( String mode, boolean[] checkValues ) - { - PlexusIoResourceAttributes attrs = newAttributes( Integer.parseInt( mode, 8 ) ); + private void verifyStringOctalModeSet(String mode, boolean[] checkValues) { + PlexusIoResourceAttributes attrs = newAttributes(Integer.parseInt(mode, 8)); - assertEquals( checkValues[0], attrs.isOwnerReadable() ); - assertEquals( checkValues[1], attrs.isOwnerWritable() ); - assertEquals( checkValues[2], attrs.isOwnerExecutable() ); + assertEquals(checkValues[0], attrs.isOwnerReadable()); + assertEquals(checkValues[1], attrs.isOwnerWritable()); + assertEquals(checkValues[2], attrs.isOwnerExecutable()); - assertEquals( checkValues[3], attrs.isGroupReadable() ); - assertEquals( checkValues[4], attrs.isGroupWritable() ); - assertEquals( checkValues[5], attrs.isGroupExecutable() ); + assertEquals(checkValues[3], attrs.isGroupReadable()); + assertEquals(checkValues[4], attrs.isGroupWritable()); + assertEquals(checkValues[5], attrs.isGroupExecutable()); - assertEquals( checkValues[6], attrs.isWorldReadable() ); - assertEquals( checkValues[7], attrs.isWorldWritable() ); - assertEquals( checkValues[8], attrs.isWorldExecutable() ); + assertEquals(checkValues[6], attrs.isWorldReadable()); + assertEquals(checkValues[7], attrs.isWorldWritable()); + assertEquals(checkValues[8], attrs.isWorldExecutable()); } - private void verifyOctalModeSet( String mode, boolean[] checkValues ) - { - PlexusIoResourceAttributes attrs = newAttributes( Integer.parseInt( mode, 8 ) ); + private void verifyOctalModeSet(String mode, boolean[] checkValues) { + PlexusIoResourceAttributes attrs = newAttributes(Integer.parseInt(mode, 8)); - assertEquals( checkValues[0], attrs.isOwnerReadable() ); - assertEquals( checkValues[1], attrs.isOwnerWritable() ); - assertEquals( checkValues[2], attrs.isOwnerExecutable() ); + assertEquals(checkValues[0], attrs.isOwnerReadable()); + assertEquals(checkValues[1], attrs.isOwnerWritable()); + assertEquals(checkValues[2], attrs.isOwnerExecutable()); - assertEquals( checkValues[3], attrs.isGroupReadable() ); - assertEquals( checkValues[4], attrs.isGroupWritable() ); - assertEquals( checkValues[5], attrs.isGroupExecutable() ); + assertEquals(checkValues[3], attrs.isGroupReadable()); + assertEquals(checkValues[4], attrs.isGroupWritable()); + assertEquals(checkValues[5], attrs.isGroupExecutable()); - assertEquals( checkValues[6], attrs.isWorldReadable() ); - assertEquals( checkValues[7], attrs.isWorldWritable() ); - assertEquals( checkValues[8], attrs.isWorldExecutable() ); + assertEquals(checkValues[6], attrs.isWorldReadable()); + assertEquals(checkValues[7], attrs.isWorldWritable()); + assertEquals(checkValues[8], attrs.isWorldExecutable()); } - -} \ No newline at end of file +} diff --git a/src/test/java/org/codehaus/plexus/components/io/attributes/AttributeUtilsTest.java b/src/test/java/org/codehaus/plexus/components/io/attributes/AttributeUtilsTest.java index ff79285b..74f3ce54 100644 --- a/src/test/java/org/codehaus/plexus/components/io/attributes/AttributeUtilsTest.java +++ b/src/test/java/org/codehaus/plexus/components/io/attributes/AttributeUtilsTest.java @@ -1,74 +1,63 @@ package org.codehaus.plexus.components.io.attributes; -import org.codehaus.plexus.util.Os; -import org.junit.Test; - import java.io.File; import java.io.IOException; import java.nio.file.attribute.PosixFilePermission; -import java.util.HashMap; import java.util.Set; +import org.codehaus.plexus.util.Os; +import org.junit.Test; + import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; /** * @author Kristian Rosenvold */ -public class AttributeUtilsTest -{ +public class AttributeUtilsTest { @Test - public void testMiscPatterns() - throws Exception - { - final Set permissions = AttributeUtils.getPermissions( 0124 ); - assertTrue( permissions.contains( PosixFilePermission.OWNER_EXECUTE ) ); - assertTrue( permissions.contains( PosixFilePermission.GROUP_WRITE ) ); - assertTrue( permissions.contains( PosixFilePermission.OTHERS_READ ) ); + public void testMiscPatterns() throws Exception { + final Set permissions = AttributeUtils.getPermissions(0124); + assertTrue(permissions.contains(PosixFilePermission.OWNER_EXECUTE)); + assertTrue(permissions.contains(PosixFilePermission.GROUP_WRITE)); + assertTrue(permissions.contains(PosixFilePermission.OTHERS_READ)); } @Test - public void testMorePatterns() throws Exception - { - final Set permissions = AttributeUtils.getPermissions( 0241 ); - assertTrue( permissions.contains( PosixFilePermission.OWNER_WRITE ) ); - assertTrue( permissions.contains( PosixFilePermission.GROUP_READ ) ); - assertTrue( permissions.contains( PosixFilePermission.OTHERS_EXECUTE ) ); + public void testMorePatterns() throws Exception { + final Set permissions = AttributeUtils.getPermissions(0241); + assertTrue(permissions.contains(PosixFilePermission.OWNER_WRITE)); + assertTrue(permissions.contains(PosixFilePermission.GROUP_READ)); + assertTrue(permissions.contains(PosixFilePermission.OTHERS_EXECUTE)); } @Test - public void testEvenMorePatterns() throws Exception - { - final Set permissions = AttributeUtils.getPermissions( 0412 ); - assertTrue( permissions.contains( PosixFilePermission.OWNER_READ ) ); - assertTrue( permissions.contains( PosixFilePermission.GROUP_EXECUTE ) ); - assertTrue( permissions.contains( PosixFilePermission.OTHERS_WRITE ) ); + public void testEvenMorePatterns() throws Exception { + final Set permissions = AttributeUtils.getPermissions(0412); + assertTrue(permissions.contains(PosixFilePermission.OWNER_READ)); + assertTrue(permissions.contains(PosixFilePermission.GROUP_EXECUTE)); + assertTrue(permissions.contains(PosixFilePermission.OTHERS_WRITE)); } @Test - public void test777() - throws Exception - { - final Set permissions = AttributeUtils.getPermissions( 0777 ); - assertTrue( permissions.size() == 9 ); + public void test777() throws Exception { + final Set permissions = AttributeUtils.getPermissions(0777); + assertTrue(permissions.size() == 9); } @Test - public void testChmodBackAndForth() - throws IOException - { - if ( Os.isFamily( Os.FAMILY_WINDOWS ) ) - return; - final File bxx = File.createTempFile( "bxx", "ff" ); - AttributeUtils.chmod( bxx, 0422 ); - PlexusIoResourceAttributes firstAttrs = new FileAttributes( bxx ); - assertTrue( firstAttrs.isOwnerReadable() ); - assertFalse( firstAttrs.isOwnerWritable() ); - assertFalse( firstAttrs.isOwnerExecutable() ); - AttributeUtils.chmod( bxx, 0777 ); - PlexusIoResourceAttributes secondAttrs = new FileAttributes( bxx ); - assertTrue( secondAttrs.isOwnerReadable() ); - assertTrue( secondAttrs.isOwnerWritable() ); - assertTrue( secondAttrs.isOwnerExecutable() ); + public void testChmodBackAndForth() throws IOException { + if (Os.isFamily(Os.FAMILY_WINDOWS)) return; + final File bxx = File.createTempFile("bxx", "ff"); + AttributeUtils.chmod(bxx, 0422); + PlexusIoResourceAttributes firstAttrs = new FileAttributes(bxx); + assertTrue(firstAttrs.isOwnerReadable()); + assertFalse(firstAttrs.isOwnerWritable()); + assertFalse(firstAttrs.isOwnerExecutable()); + AttributeUtils.chmod(bxx, 0777); + PlexusIoResourceAttributes secondAttrs = new FileAttributes(bxx); + assertTrue(secondAttrs.isOwnerReadable()); + assertTrue(secondAttrs.isOwnerWritable()); + assertTrue(secondAttrs.isOwnerExecutable()); } } diff --git a/src/test/java/org/codehaus/plexus/components/io/attributes/FileAttributesTest.java b/src/test/java/org/codehaus/plexus/components/io/attributes/FileAttributesTest.java index 84206e52..db2dc0d6 100644 --- a/src/test/java/org/codehaus/plexus/components/io/attributes/FileAttributesTest.java +++ b/src/test/java/org/codehaus/plexus/components/io/attributes/FileAttributesTest.java @@ -17,10 +17,8 @@ */ import java.io.File; -import java.util.HashMap; -import java.util.Map; -import org.codehaus.plexus.util.Os; +import org.codehaus.plexus.util.Os; import org.junit.Test; import static org.junit.Assert.assertNotNull; @@ -28,22 +26,17 @@ /** * @author Kristian Rosenvold */ -public class FileAttributesTest -{ +public class FileAttributesTest { @Test - public void testGetPosixFileAttributes() - throws Exception - { + public void testGetPosixFileAttributes() throws Exception { - if ( Os.isFamily( Os.FAMILY_WINDOWS ) ) - { + if (Os.isFamily(Os.FAMILY_WINDOWS)) { return; } - File file = new File( "." ); + File file = new File("."); - PlexusIoResourceAttributes fa = new FileAttributes( file ); - assertNotNull( fa ); + PlexusIoResourceAttributes fa = new FileAttributes(file); + assertNotNull(fa); } - } diff --git a/src/test/java/org/codehaus/plexus/components/io/attributes/PlexusIoResourceAttributeUtilsTest.java b/src/test/java/org/codehaus/plexus/components/io/attributes/PlexusIoResourceAttributeUtilsTest.java index ba0c0023..92af5c78 100644 --- a/src/test/java/org/codehaus/plexus/components/io/attributes/PlexusIoResourceAttributeUtilsTest.java +++ b/src/test/java/org/codehaus/plexus/components/io/attributes/PlexusIoResourceAttributeUtilsTest.java @@ -16,17 +16,16 @@ * limitations under the License. */ -import org.codehaus.plexus.util.Os; -import org.codehaus.plexus.util.StringUtils; -import org.codehaus.plexus.util.cli.CommandLineException; -import org.codehaus.plexus.util.cli.CommandLineUtils; -import org.codehaus.plexus.util.cli.Commandline; - import java.io.File; import java.io.IOException; import java.net.URL; import java.util.Map; +import org.codehaus.plexus.util.Os; +import org.codehaus.plexus.util.StringUtils; +import org.codehaus.plexus.util.cli.CommandLineException; +import org.codehaus.plexus.util.cli.CommandLineUtils; +import org.codehaus.plexus.util.cli.Commandline; import org.junit.Test; import static org.codehaus.plexus.components.io.attributes.PlexusIoResourceAttributeUtils.getFileAttributes; @@ -38,344 +37,313 @@ import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; -public class PlexusIoResourceAttributeUtilsTest -{ +public class PlexusIoResourceAttributeUtilsTest { @Test - public void testGetAttributesForThisTestClass() - throws IOException - { - if ( Os.isFamily( Os.FAMILY_WINDOWS ) ) - { - System.out.println( "WARNING: Unsupported OS, skipping test" ); + public void testGetAttributesForThisTestClass() throws IOException { + if (Os.isFamily(Os.FAMILY_WINDOWS)) { + System.out.println("WARNING: Unsupported OS, skipping test"); return; } - URL resource = Thread.currentThread().getContextClassLoader().getResource( - getClass().getName().replace( '.', '/' ) + ".class" ); + URL resource = Thread.currentThread() + .getContextClassLoader() + .getResource(getClass().getName().replace('.', '/') + ".class"); - if ( resource == null ) - { - throw new IllegalStateException( - "SOMETHING IS VERY WRONG. CANNOT FIND THIS TEST CLASS IN THE CLASSLOADER." ); + if (resource == null) { + throw new IllegalStateException("SOMETHING IS VERY WRONG. CANNOT FIND THIS TEST CLASS IN THE CLASSLOADER."); } - File f = new File( resource.getPath().replaceAll( "%20", " " ) ); + File f = new File(resource.getPath().replaceAll("%20", " ")); - Map attrs = - PlexusIoResourceAttributeUtils.getFileAttributesByPath( f, true ); + Map attrs = PlexusIoResourceAttributeUtils.getFileAttributesByPath(f, true); - PlexusIoResourceAttributes fileAttrs = attrs.get( f.getAbsolutePath() ); + PlexusIoResourceAttributes fileAttrs = attrs.get(f.getAbsolutePath()); - System.out.println( "Got attributes for: " + f.getAbsolutePath() + fileAttrs ); + System.out.println("Got attributes for: " + f.getAbsolutePath() + fileAttrs); - assertNotNull( fileAttrs ); - assertTrue( fileAttrs.isOwnerReadable() ); - assertEquals( System.getProperty( "user.name" ), fileAttrs.getUserName() ); + assertNotNull(fileAttrs); + assertTrue(fileAttrs.isOwnerReadable()); + assertEquals(System.getProperty("user.name"), fileAttrs.getUserName()); } @Test - public void testDirectory() - throws IOException, CommandLineException - { + public void testDirectory() throws IOException, CommandLineException { - if ( Os.isFamily( Os.FAMILY_WINDOWS ) ) - { + if (Os.isFamily(Os.FAMILY_WINDOWS)) { return; // Nothing to do here. } - URL resource = Thread.currentThread().getContextClassLoader().getResource( - getClass().getName().replace( '.', '/' ) + ".class" ); + URL resource = Thread.currentThread() + .getContextClassLoader() + .getResource(getClass().getName().replace('.', '/') + ".class"); - if ( resource == null ) - { - throw new IllegalStateException( - "SOMETHING IS VERY WRONG. CANNOT FIND THIS TEST CLASS IN THE CLASSLOADER." ); + if (resource == null) { + throw new IllegalStateException("SOMETHING IS VERY WRONG. CANNOT FIND THIS TEST CLASS IN THE CLASSLOADER."); } - File f = new File( resource.getPath().replaceAll( "%20", " " ) ); + File f = new File(resource.getPath().replaceAll("%20", " ")); final File aDir = f.getParentFile().getParentFile().getParentFile(); - Commandline commandLine = new Commandline( "chmod" ); - commandLine.addArguments( new String[] { "763", f.getAbsolutePath() } ); + Commandline commandLine = new Commandline("chmod"); + commandLine.addArguments(new String[] {"763", f.getAbsolutePath()}); - CommandLineUtils.executeCommandLine( commandLine, null, null ); + CommandLineUtils.executeCommandLine(commandLine, null, null); Map attrs = - PlexusIoResourceAttributeUtils.getFileAttributesByPath( aDir, true ); + PlexusIoResourceAttributeUtils.getFileAttributesByPath(aDir, true); - PlexusIoResourceAttributes fileAttrs = attrs.get( f.getAbsolutePath() ); + PlexusIoResourceAttributes fileAttrs = attrs.get(f.getAbsolutePath()); - assertTrue( fileAttrs.isGroupReadable() ); - assertTrue( fileAttrs.isGroupWritable() ); - assertFalse( fileAttrs.isGroupExecutable() ); + assertTrue(fileAttrs.isGroupReadable()); + assertTrue(fileAttrs.isGroupWritable()); + assertFalse(fileAttrs.isGroupExecutable()); - assertTrue( fileAttrs.isOwnerExecutable() ); - assertTrue( fileAttrs.isOwnerReadable() ); - assertTrue( fileAttrs.isOwnerWritable() ); + assertTrue(fileAttrs.isOwnerExecutable()); + assertTrue(fileAttrs.isOwnerReadable()); + assertTrue(fileAttrs.isOwnerWritable()); - assertTrue( fileAttrs.isWorldExecutable() ); - assertFalse( fileAttrs.isWorldReadable() ); - assertTrue( fileAttrs.isWorldWritable() ); + assertTrue(fileAttrs.isWorldExecutable()); + assertFalse(fileAttrs.isWorldReadable()); + assertTrue(fileAttrs.isWorldWritable()); - assertNotNull( fileAttrs ); + assertNotNull(fileAttrs); } @Test - public void testSrcResource() - throws IOException - { - if ( Os.isFamily( Os.FAMILY_WINDOWS ) ) - { + public void testSrcResource() throws IOException { + if (Os.isFamily(Os.FAMILY_WINDOWS)) { return; // Nothing to do here. } - File dir = new File( "src/test/resources/symlinks" ); + File dir = new File("src/test/resources/symlinks"); final Map fileAttributesByPathScreenScrape = - PlexusIoResourceAttributeUtils.getFileAttributesByPath( dir, true ); - assertNotNull( fileAttributesByPathScreenScrape ); + PlexusIoResourceAttributeUtils.getFileAttributesByPath(dir, true); + assertNotNull(fileAttributesByPathScreenScrape); PlexusIoResourceAttributes pr = null; - for ( String s : fileAttributesByPathScreenScrape.keySet() ) - { - if ( s.endsWith( "targetFile.txt" ) ) - pr = fileAttributesByPathScreenScrape.get( s ); + for (String s : fileAttributesByPathScreenScrape.keySet()) { + if (s.endsWith("targetFile.txt")) pr = fileAttributesByPathScreenScrape.get(s); } - assertNotNull( pr ); + assertNotNull(pr); - assertTrue( pr.getOctalMode() > 0 ); + assertTrue(pr.getOctalMode() > 0); } @Test - public void testNonExistingDirectory() - { - File dir = new File( "src/test/noSuchDirectory" ); - try - { - PlexusIoResourceAttributeUtils.getFileAttributesByPath( dir, true ); - fail( "We were supposed to get an io exceptions" ); - } - catch ( IOException ignore ) - { + public void testNonExistingDirectory() { + File dir = new File("src/test/noSuchDirectory"); + try { + PlexusIoResourceAttributeUtils.getFileAttributesByPath(dir, true); + fail("We were supposed to get an io exceptions"); + } catch (IOException ignore) { ignore.printStackTrace(); } } @Test - public void testMergeAttributesWithNullBase() - { - PlexusIoResourceAttributes override = - new SimpleResourceAttributes( 1001, "myUser", 1001, "test", 0 ); - PlexusIoResourceAttributes defaults = - new SimpleResourceAttributes( 1000, "defaultUser", 1000, "defaultTest", 0 ); + public void testMergeAttributesWithNullBase() { + PlexusIoResourceAttributes override = new SimpleResourceAttributes(1001, "myUser", 1001, "test", 0); + PlexusIoResourceAttributes defaults = new SimpleResourceAttributes(1000, "defaultUser", 1000, "defaultTest", 0); PlexusIoResourceAttributes attributes; - attributes = PlexusIoResourceAttributeUtils.mergeAttributes( override, null, defaults ); + attributes = PlexusIoResourceAttributeUtils.mergeAttributes(override, null, defaults); - assertEquals( Integer.valueOf( 1001 ), attributes.getGroupId() ); - assertEquals( Integer.valueOf( 1001 ), attributes.getUserId() ); + assertEquals(Integer.valueOf(1001), attributes.getGroupId()); + assertEquals(Integer.valueOf(1001), attributes.getUserId()); } @Test - public void testMergeAttributesWithNullOverrideGroup() - { - final PlexusIoResourceAttributes override = - new SimpleResourceAttributes( 1001, "myUser", -1, null, 0 ); + public void testMergeAttributesWithNullOverrideGroup() { + final PlexusIoResourceAttributes override = new SimpleResourceAttributes(1001, "myUser", -1, null, 0); final PlexusIoResourceAttributes defaults = - new SimpleResourceAttributes( 1000, "defaultUser", 1000, "defaultGroup", 0 ); + new SimpleResourceAttributes(1000, "defaultUser", 1000, "defaultGroup", 0); PlexusIoResourceAttributes attributes = - PlexusIoResourceAttributeUtils.mergeAttributes( override, null, defaults ); + PlexusIoResourceAttributeUtils.mergeAttributes(override, null, defaults); - assertEquals( attributes.getGroupId(), Integer.valueOf( 1000 ) ); - assertEquals( attributes.getUserId(), Integer.valueOf( 1001 ) ); + assertEquals(attributes.getGroupId(), Integer.valueOf(1000)); + assertEquals(attributes.getUserId(), Integer.valueOf(1001)); } @Test - public void testMergeAttributesOverride() - { + public void testMergeAttributesOverride() { final PlexusIoResourceAttributes blank = new SimpleResourceAttributes(); - final PlexusIoResourceAttributes invalid = new SimpleResourceAttributes( -1, null, -1, null, -1 ); + final PlexusIoResourceAttributes invalid = new SimpleResourceAttributes(-1, null, -1, null, -1); final PlexusIoResourceAttributes override = - new SimpleResourceAttributes( 1111, "testUser", 2222, "testGroup", 0777 ); + new SimpleResourceAttributes(1111, "testUser", 2222, "testGroup", 0777); final PlexusIoResourceAttributes defaults = - new SimpleResourceAttributes( 3333, "defaultUser", 4444, "defaultGroup", 0444 ); - final PlexusIoResourceAttributes base = - new SimpleResourceAttributes( 5555, "baseUser", 6666, "baseGroup", 0111 ); + new SimpleResourceAttributes(3333, "defaultUser", 4444, "defaultGroup", 0444); + final PlexusIoResourceAttributes base = new SimpleResourceAttributes(5555, "baseUser", 6666, "baseGroup", 0111); PlexusIoResourceAttributes attributes; // When override is null, base is returned verbatim - attributes = PlexusIoResourceAttributeUtils.mergeAttributes( null, null, null ); - assertNull( attributes ); + attributes = PlexusIoResourceAttributeUtils.mergeAttributes(null, null, null); + assertNull(attributes); - attributes = PlexusIoResourceAttributeUtils.mergeAttributes( null, null, defaults ); - assertNull( attributes ); + attributes = PlexusIoResourceAttributeUtils.mergeAttributes(null, null, defaults); + assertNull(attributes); - attributes = PlexusIoResourceAttributeUtils.mergeAttributes( null, base, null ); - assertSame( base, attributes ); + attributes = PlexusIoResourceAttributeUtils.mergeAttributes(null, base, null); + assertSame(base, attributes); - attributes = PlexusIoResourceAttributeUtils.mergeAttributes( null, base, defaults ); - assertSame( base, attributes ); + attributes = PlexusIoResourceAttributeUtils.mergeAttributes(null, base, defaults); + assertSame(base, attributes); // Test cases when override is non-null - attributes = PlexusIoResourceAttributeUtils.mergeAttributes( override, null, null ); + attributes = PlexusIoResourceAttributeUtils.mergeAttributes(override, null, null); - assertEquals( Integer.valueOf( 1111 ), attributes.getUserId() ); - assertEquals( "testUser", attributes.getUserName() ); - assertEquals( Integer.valueOf( 2222 ), attributes.getGroupId() ); - assertEquals( "testGroup", attributes.getGroupName() ); - assertEquals( 0777, attributes.getOctalMode() ); + assertEquals(Integer.valueOf(1111), attributes.getUserId()); + assertEquals("testUser", attributes.getUserName()); + assertEquals(Integer.valueOf(2222), attributes.getGroupId()); + assertEquals("testGroup", attributes.getGroupName()); + assertEquals(0777, attributes.getOctalMode()); - attributes = PlexusIoResourceAttributeUtils.mergeAttributes( override, base, null ); + attributes = PlexusIoResourceAttributeUtils.mergeAttributes(override, base, null); - assertEquals( Integer.valueOf( 1111 ), attributes.getUserId() ); - assertEquals( "testUser", attributes.getUserName() ); - assertEquals( Integer.valueOf( 2222 ), attributes.getGroupId() ); - assertEquals( "testGroup", attributes.getGroupName() ); - assertEquals( 0777, attributes.getOctalMode() ); + assertEquals(Integer.valueOf(1111), attributes.getUserId()); + assertEquals("testUser", attributes.getUserName()); + assertEquals(Integer.valueOf(2222), attributes.getGroupId()); + assertEquals("testGroup", attributes.getGroupName()); + assertEquals(0777, attributes.getOctalMode()); - attributes = PlexusIoResourceAttributeUtils.mergeAttributes( override, null, defaults ); + attributes = PlexusIoResourceAttributeUtils.mergeAttributes(override, null, defaults); - assertEquals( Integer.valueOf( 1111 ), attributes.getUserId() ); - assertEquals( "testUser", attributes.getUserName() ); - assertEquals( Integer.valueOf( 2222 ), attributes.getGroupId() ); - assertEquals( "testGroup", attributes.getGroupName() ); - assertEquals( 0777, attributes.getOctalMode() ); + assertEquals(Integer.valueOf(1111), attributes.getUserId()); + assertEquals("testUser", attributes.getUserName()); + assertEquals(Integer.valueOf(2222), attributes.getGroupId()); + assertEquals("testGroup", attributes.getGroupName()); + assertEquals(0777, attributes.getOctalMode()); - attributes = PlexusIoResourceAttributeUtils.mergeAttributes( override, base, defaults ); + attributes = PlexusIoResourceAttributeUtils.mergeAttributes(override, base, defaults); - assertEquals( Integer.valueOf( 1111 ), attributes.getUserId() ); - assertEquals( "testUser", attributes.getUserName() ); - assertEquals( Integer.valueOf( 2222 ), attributes.getGroupId() ); - assertEquals( "testGroup", attributes.getGroupName() ); - assertEquals( 0777, attributes.getOctalMode() ); + assertEquals(Integer.valueOf(1111), attributes.getUserId()); + assertEquals("testUser", attributes.getUserName()); + assertEquals(Integer.valueOf(2222), attributes.getGroupId()); + assertEquals("testGroup", attributes.getGroupName()); + assertEquals(0777, attributes.getOctalMode()); - attributes = PlexusIoResourceAttributeUtils.mergeAttributes( override, blank, null ); + attributes = PlexusIoResourceAttributeUtils.mergeAttributes(override, blank, null); - assertEquals( Integer.valueOf( 1111 ), attributes.getUserId() ); - assertEquals( "testUser", attributes.getUserName() ); - assertEquals( Integer.valueOf( 2222 ), attributes.getGroupId() ); - assertEquals( "testGroup", attributes.getGroupName() ); - assertEquals( 0777, attributes.getOctalMode() ); + assertEquals(Integer.valueOf(1111), attributes.getUserId()); + assertEquals("testUser", attributes.getUserName()); + assertEquals(Integer.valueOf(2222), attributes.getGroupId()); + assertEquals("testGroup", attributes.getGroupName()); + assertEquals(0777, attributes.getOctalMode()); - attributes = PlexusIoResourceAttributeUtils.mergeAttributes( override, invalid, null ); + attributes = PlexusIoResourceAttributeUtils.mergeAttributes(override, invalid, null); - assertEquals( Integer.valueOf( 1111 ), attributes.getUserId() ); - assertEquals( "testUser", attributes.getUserName() ); - assertEquals( Integer.valueOf( 2222 ), attributes.getGroupId() ); - assertEquals( "testGroup", attributes.getGroupName() ); - assertEquals( 0777, attributes.getOctalMode() ); + assertEquals(Integer.valueOf(1111), attributes.getUserId()); + assertEquals("testUser", attributes.getUserName()); + assertEquals(Integer.valueOf(2222), attributes.getGroupId()); + assertEquals("testGroup", attributes.getGroupName()); + assertEquals(0777, attributes.getOctalMode()); // Test cases when override has only blank values - attributes = PlexusIoResourceAttributeUtils.mergeAttributes( blank, base, null ); + attributes = PlexusIoResourceAttributeUtils.mergeAttributes(blank, base, null); - assertEquals( Integer.valueOf( 5555 ), attributes.getUserId() ); - assertEquals( "baseUser", attributes.getUserName() ); - assertEquals( Integer.valueOf( 6666 ), attributes.getGroupId() ); - assertEquals( "baseGroup", attributes.getGroupName() ); - assertEquals( 0111, attributes.getOctalMode() ); + assertEquals(Integer.valueOf(5555), attributes.getUserId()); + assertEquals("baseUser", attributes.getUserName()); + assertEquals(Integer.valueOf(6666), attributes.getGroupId()); + assertEquals("baseGroup", attributes.getGroupName()); + assertEquals(0111, attributes.getOctalMode()); - attributes = PlexusIoResourceAttributeUtils.mergeAttributes( invalid, base, null ); + attributes = PlexusIoResourceAttributeUtils.mergeAttributes(invalid, base, null); - assertEquals( Integer.valueOf( 5555 ), attributes.getUserId() ); - assertEquals( "baseUser", attributes.getUserName() ); - assertEquals( Integer.valueOf( 6666 ), attributes.getGroupId() ); - assertEquals( "baseGroup", attributes.getGroupName() ); - assertEquals( 0111, attributes.getOctalMode() ); + assertEquals(Integer.valueOf(5555), attributes.getUserId()); + assertEquals("baseUser", attributes.getUserName()); + assertEquals(Integer.valueOf(6666), attributes.getGroupId()); + assertEquals("baseGroup", attributes.getGroupName()); + assertEquals(0111, attributes.getOctalMode()); - attributes = PlexusIoResourceAttributeUtils.mergeAttributes( blank, base, defaults ); + attributes = PlexusIoResourceAttributeUtils.mergeAttributes(blank, base, defaults); - assertEquals( Integer.valueOf( 5555 ), attributes.getUserId() ); - assertEquals( "baseUser", attributes.getUserName() ); - assertEquals( Integer.valueOf( 6666 ), attributes.getGroupId() ); - assertEquals( "baseGroup", attributes.getGroupName() ); - assertEquals( 0111, attributes.getOctalMode() ); + assertEquals(Integer.valueOf(5555), attributes.getUserId()); + assertEquals("baseUser", attributes.getUserName()); + assertEquals(Integer.valueOf(6666), attributes.getGroupId()); + assertEquals("baseGroup", attributes.getGroupName()); + assertEquals(0111, attributes.getOctalMode()); - attributes = PlexusIoResourceAttributeUtils.mergeAttributes( invalid, base, defaults ); + attributes = PlexusIoResourceAttributeUtils.mergeAttributes(invalid, base, defaults); - assertEquals( Integer.valueOf( 5555 ), attributes.getUserId() ); - assertEquals( "baseUser", attributes.getUserName() ); - assertEquals( Integer.valueOf( 6666 ), attributes.getGroupId() ); - assertEquals( "baseGroup", attributes.getGroupName() ); - assertEquals( 0111, attributes.getOctalMode() ); + assertEquals(Integer.valueOf(5555), attributes.getUserId()); + assertEquals("baseUser", attributes.getUserName()); + assertEquals(Integer.valueOf(6666), attributes.getGroupId()); + assertEquals("baseGroup", attributes.getGroupName()); + assertEquals(0111, attributes.getOctalMode()); } @Test - public void testFileAttributes() - throws IOException - { - PlexusIoResourceAttributes attrs = getFileAttributes( new File( "src/test/resources/symlinks/src/fileW.txt" ) ); - assertFalse( attrs.isSymbolicLink() ); - assertTrue( StringUtils.isNotEmpty( attrs.getUserName() ) ); - if ( !Os.isFamily( Os.FAMILY_WINDOWS ) ) - { - assertTrue( StringUtils.isNotEmpty( attrs.getGroupName() ) ); - assertNotNull( attrs.getGroupId() ); - assertNotNull( attrs.getUserId() ); + public void testFileAttributes() throws IOException { + PlexusIoResourceAttributes attrs = getFileAttributes(new File("src/test/resources/symlinks/src/fileW.txt")); + assertFalse(attrs.isSymbolicLink()); + assertTrue(StringUtils.isNotEmpty(attrs.getUserName())); + if (!Os.isFamily(Os.FAMILY_WINDOWS)) { + assertTrue(StringUtils.isNotEmpty(attrs.getGroupName())); + assertNotNull(attrs.getGroupId()); + assertNotNull(attrs.getUserId()); } } @Test - public void testMergeAttributesDefault() - { - final PlexusIoResourceAttributes blank = new SimpleResourceAttributes( null, null, null, null, 0 ); - final PlexusIoResourceAttributes invalid = new SimpleResourceAttributes( -1, null, -1, null, -1 ); + public void testMergeAttributesDefault() { + final PlexusIoResourceAttributes blank = new SimpleResourceAttributes(null, null, null, null, 0); + final PlexusIoResourceAttributes invalid = new SimpleResourceAttributes(-1, null, -1, null, -1); final PlexusIoResourceAttributes defaults = - new SimpleResourceAttributes( 3333, "defaultUser", 4444, "defaultGroup", 0444 ); + new SimpleResourceAttributes(3333, "defaultUser", 4444, "defaultGroup", 0444); PlexusIoResourceAttributes attributes; // Test cases when override and base have blank values - attributes = PlexusIoResourceAttributeUtils.mergeAttributes( blank, blank, defaults ); + attributes = PlexusIoResourceAttributeUtils.mergeAttributes(blank, blank, defaults); - assertEquals( Integer.valueOf( 3333 ), attributes.getUserId() ); - assertEquals( "defaultUser", attributes.getUserName() ); - assertEquals( Integer.valueOf( 4444 ), attributes.getGroupId() ); - assertEquals( "defaultGroup", attributes.getGroupName() ); + assertEquals(Integer.valueOf(3333), attributes.getUserId()); + assertEquals("defaultUser", attributes.getUserName()); + assertEquals(Integer.valueOf(4444), attributes.getGroupId()); + assertEquals("defaultGroup", attributes.getGroupName()); // 0 is a borderline case, for backwards compatibility it is not overridden by value from defaults - assertEquals( 0, attributes.getOctalMode() ); + assertEquals(0, attributes.getOctalMode()); - attributes = PlexusIoResourceAttributeUtils.mergeAttributes( invalid, blank, defaults ); + attributes = PlexusIoResourceAttributeUtils.mergeAttributes(invalid, blank, defaults); - assertEquals( Integer.valueOf( 3333 ), attributes.getUserId() ); - assertEquals( "defaultUser", attributes.getUserName() ); - assertEquals( Integer.valueOf( 4444 ), attributes.getGroupId() ); - assertEquals( "defaultGroup", attributes.getGroupName() ); + assertEquals(Integer.valueOf(3333), attributes.getUserId()); + assertEquals("defaultUser", attributes.getUserName()); + assertEquals(Integer.valueOf(4444), attributes.getGroupId()); + assertEquals("defaultGroup", attributes.getGroupName()); // 0 is a borderline case, for backwards compatibility it is not overridden by value from defaults // Not just that, but 0 is correct. - assertEquals( 0, attributes.getOctalMode() ); + assertEquals(0, attributes.getOctalMode()); - attributes = PlexusIoResourceAttributeUtils.mergeAttributes( blank, invalid, defaults ); + attributes = PlexusIoResourceAttributeUtils.mergeAttributes(blank, invalid, defaults); - assertEquals( Integer.valueOf( 3333 ), attributes.getUserId() ); - assertEquals( "defaultUser", attributes.getUserName() ); - assertEquals( Integer.valueOf( 4444 ), attributes.getGroupId() ); - assertEquals( "defaultGroup", attributes.getGroupName() ); - assertEquals( 0444, attributes.getOctalMode() ); + assertEquals(Integer.valueOf(3333), attributes.getUserId()); + assertEquals("defaultUser", attributes.getUserName()); + assertEquals(Integer.valueOf(4444), attributes.getGroupId()); + assertEquals("defaultGroup", attributes.getGroupName()); + assertEquals(0444, attributes.getOctalMode()); - attributes = PlexusIoResourceAttributeUtils.mergeAttributes( invalid, invalid, defaults ); + attributes = PlexusIoResourceAttributeUtils.mergeAttributes(invalid, invalid, defaults); - assertEquals( Integer.valueOf( 3333 ), attributes.getUserId() ); - assertEquals( "defaultUser", attributes.getUserName() ); - assertEquals( Integer.valueOf( 4444 ), attributes.getGroupId() ); - assertEquals( "defaultGroup", attributes.getGroupName() ); - assertEquals( 0444, attributes.getOctalMode() ); + assertEquals(Integer.valueOf(3333), attributes.getUserId()); + assertEquals("defaultUser", attributes.getUserName()); + assertEquals(Integer.valueOf(4444), attributes.getGroupId()); + assertEquals("defaultGroup", attributes.getGroupName()); + assertEquals(0444, attributes.getOctalMode()); // Test cases when invalid defaults should not override blank values - attributes = PlexusIoResourceAttributeUtils.mergeAttributes( blank, blank, invalid ); + attributes = PlexusIoResourceAttributeUtils.mergeAttributes(blank, blank, invalid); - assertNull( attributes.getUserId() ); - assertNull( attributes.getUserName() ); - assertNull( attributes.getGroupId() ); - assertNull( attributes.getGroupName() ); - assertEquals( 0, attributes.getOctalMode() ); + assertNull(attributes.getUserId()); + assertNull(attributes.getUserName()); + assertNull(attributes.getGroupId()); + assertNull(attributes.getGroupName()); + assertEquals(0, attributes.getOctalMode()); - attributes = PlexusIoResourceAttributeUtils.mergeAttributes( invalid, blank, invalid ); + attributes = PlexusIoResourceAttributeUtils.mergeAttributes(invalid, blank, invalid); - assertNull( attributes.getUserId() ); - assertNull( attributes.getUserName() ); - assertNull( attributes.getGroupId() ); - assertNull( attributes.getGroupName() ); - assertEquals( 0, attributes.getOctalMode() ); + assertNull(attributes.getUserId()); + assertNull(attributes.getUserName()); + assertNull(attributes.getGroupId()); + assertNull(attributes.getGroupName()); + assertEquals(0, attributes.getOctalMode()); } - } diff --git a/src/test/java/org/codehaus/plexus/components/io/attributes/SimpleResourceAttributesTest.java b/src/test/java/org/codehaus/plexus/components/io/attributes/SimpleResourceAttributesTest.java index 9673f884..9383fcd3 100644 --- a/src/test/java/org/codehaus/plexus/components/io/attributes/SimpleResourceAttributesTest.java +++ b/src/test/java/org/codehaus/plexus/components/io/attributes/SimpleResourceAttributesTest.java @@ -16,21 +16,17 @@ * limitations under the License. */ -public class SimpleResourceAttributesTest - extends AbstractResourceAttributesTCK -{ +public class SimpleResourceAttributesTest extends AbstractResourceAttributesTCK { - protected PlexusIoResourceAttributes newAttributes( int mode ) - { + protected PlexusIoResourceAttributes newAttributes(int mode) { final SimpleResourceAttributes simpleResourceAttributes = new SimpleResourceAttributes(); - simpleResourceAttributes.setOctalMode( mode ); + simpleResourceAttributes.setOctalMode(mode); return simpleResourceAttributes; } - protected PlexusIoResourceAttributes newAttributes( String mode ) - { + protected PlexusIoResourceAttributes newAttributes(String mode) { final SimpleResourceAttributes simpleResourceAttributes = new SimpleResourceAttributes(); - simpleResourceAttributes.setOctalModeString( mode ); + simpleResourceAttributes.setOctalModeString(mode); return simpleResourceAttributes; } -} \ No newline at end of file +} diff --git a/src/test/java/org/codehaus/plexus/components/io/attributes/SymlinkUtilsTest.java b/src/test/java/org/codehaus/plexus/components/io/attributes/SymlinkUtilsTest.java index 0d1875d7..7d250f35 100644 --- a/src/test/java/org/codehaus/plexus/components/io/attributes/SymlinkUtilsTest.java +++ b/src/test/java/org/codehaus/plexus/components/io/attributes/SymlinkUtilsTest.java @@ -16,68 +16,53 @@ package org.codehaus.plexus.components.io.attributes; -import org.apache.commons.io.FileUtils; -import org.junit.Before; -import org.junit.Test; - import java.io.File; import java.io.IOException; import java.nio.file.Files; +import org.apache.commons.io.FileUtils; +import org.junit.Before; +import org.junit.Test; + import static org.junit.Assert.*; -public class SymlinkUtilsTest -{ - File target = new File( "target/symlinkCapabilities" ); +public class SymlinkUtilsTest { + File target = new File("target/symlinkCapabilities"); String expected = "This is a filed that we'll be symlinking to\n"; @Before - public void setup() - throws IOException - { - FileUtils.deleteDirectory( target ); - Files.createDirectories( target.toPath() ); + public void setup() throws IOException { + FileUtils.deleteDirectory(target); + Files.createDirectories(target.toPath()); } @Test - public void testName() - throws Exception - { - - } + public void testName() throws Exception {} @Test - public void create_read_symbolic_link_to_file() - throws Exception - { - File symlink = new File( target, "symlinkToTarget" ); - File relativePath = createTargetFile( target ); - SymlinkUtils.createSymbolicLink( symlink, relativePath ); - assertEquals( expected, FileUtils.readFileToString( symlink ) ); - assertEquals( new File( "actualFile" ), - SymlinkUtils.readSymbolicLink( new File( target, "symlinkToTarget" ) ) ); + public void create_read_symbolic_link_to_file() throws Exception { + File symlink = new File(target, "symlinkToTarget"); + File relativePath = createTargetFile(target); + SymlinkUtils.createSymbolicLink(symlink, relativePath); + assertEquals(expected, FileUtils.readFileToString(symlink)); + assertEquals(new File("actualFile"), SymlinkUtils.readSymbolicLink(new File(target, "symlinkToTarget"))); } @Test - public void create_read_symbolic_link_to_directory() - throws Exception - { - File subDir = new File( target, "aSubDir" ); - createTargetFile( subDir ); - File symlink = new File( target, "symlinkToDir" ); - SymlinkUtils.createSymbolicLink( symlink, new File( "aSubDir" ) ); - assertEquals( expected, FileUtils.readFileToString( new File( symlink, "actualFile" ) ) ); - assertEquals( new File( "aSubDir" ), SymlinkUtils.readSymbolicLink( new File( target, "symlinkToDir" ) ) ); - + public void create_read_symbolic_link_to_directory() throws Exception { + File subDir = new File(target, "aSubDir"); + createTargetFile(subDir); + File symlink = new File(target, "symlinkToDir"); + SymlinkUtils.createSymbolicLink(symlink, new File("aSubDir")); + assertEquals(expected, FileUtils.readFileToString(new File(symlink, "actualFile"))); + assertEquals(new File("aSubDir"), SymlinkUtils.readSymbolicLink(new File(target, "symlinkToDir"))); } - private File createTargetFile( File target ) - throws IOException - { - File relativePath = new File( "actualFile" ); - File actualFile = new File( target, relativePath.getPath() ); - FileUtils.write( actualFile, expected ); + private File createTargetFile(File target) throws IOException { + File relativePath = new File("actualFile"); + File actualFile = new File(target, relativePath.getPath()); + FileUtils.write(actualFile, expected); return relativePath; } -} \ No newline at end of file +} diff --git a/src/test/java/org/codehaus/plexus/components/io/filemappers/FileMapperTest.java b/src/test/java/org/codehaus/plexus/components/io/filemappers/FileMapperTest.java index 0e398e70..9471d324 100644 --- a/src/test/java/org/codehaus/plexus/components/io/filemappers/FileMapperTest.java +++ b/src/test/java/org/codehaus/plexus/components/io/filemappers/FileMapperTest.java @@ -26,198 +26,198 @@ /** * Test case for the various file mappers. */ -public class FileMapperTest extends TestSupport -{ - protected void testFileMapper( FileMapper pMapper, String[] pInput, String[] pOutput ) - { - for ( int i = 0; i < pInput.length; i++ ) - { +public class FileMapperTest extends TestSupport { + protected void testFileMapper(FileMapper pMapper, String[] pInput, String[] pOutput) { + for (int i = 0; i < pInput.length; i++) { final String input = pInput[i]; final String output = pOutput[i]; final String result; - try - { - if ( output == null ) - { - try - { - pMapper.getMappedFileName( input ); - fail( "Expected IllegalArgumentException for mapper " + pMapper.getClass().getName() - + " and input: " + input ); - } - catch ( IllegalArgumentException e ) - { + try { + if (output == null) { + try { + pMapper.getMappedFileName(input); + fail("Expected IllegalArgumentException for mapper " + + pMapper.getClass().getName() + " and input: " + input); + } catch (IllegalArgumentException e) { // Ok } continue; } - result = pMapper.getMappedFileName( input ); - if ( output.equals( result ) ) - { + result = pMapper.getMappedFileName(input); + if (output.equals(result)) { continue; } + } catch (Throwable t) { + throw new UndeclaredThrowableException( + t, + "Mapper " + pMapper.getClass().getName() + " failed for input " + input + ": " + + t.getMessage()); } - catch ( Throwable t ) - { - throw new UndeclaredThrowableException( t, "Mapper " + pMapper.getClass().getName() - + " failed for input " + input + ": " + t.getMessage() ); - } - if ( !output.equals( result ) ) - { - fail( "Mapper " + pMapper.getClass().getName() + " failed for input nr. " + i - + ", " + input + ": Expected " + output - + ", got " + result ); + if (!output.equals(result)) { + fail("Mapper " + pMapper.getClass().getName() + " failed for input nr. " + i + + ", " + input + ": Expected " + output + + ", got " + result); } } } - protected static final String[] SAMPLES = - new String[] { null, "", "a", "xyz.gif", "b/a", "b/xyz.gif", "b\\a", "b\\xyz.gif", "c.c/a", "c.c/xyz.gif", - "c.c\\a", "c.c\\xyz.gif" }; + protected static final String[] SAMPLES = new String[] { + null, + "", + "a", + "xyz.gif", + "b/a", + "b/xyz.gif", + "b\\a", + "b\\xyz.gif", + "c.c/a", + "c.c/xyz.gif", + "c.c\\a", + "c.c\\xyz.gif" + }; @Test - public void testIdentityMapper() throws Exception - { + public void testIdentityMapper() throws Exception { final String[] results = getIdentityResults(); - testFileMapper( new IdentityMapper(), SAMPLES, results ); + testFileMapper(new IdentityMapper(), SAMPLES, results); } - private String[] getIdentityResults() - { + private String[] getIdentityResults() { final String[] results = new String[SAMPLES.length]; - System.arraycopy( SAMPLES, 0, results, 0, SAMPLES.length ); + System.arraycopy(SAMPLES, 0, results, 0, SAMPLES.length); results[1] = null; return results; } @Test - public void testDefaultMapper() throws Exception - { + public void testDefaultMapper() throws Exception { final String[] results = getIdentityResults(); - testFileMapper( (FileMapper) lookup( FileMapper.class ), SAMPLES, results ); - testFileMapper( (FileMapper) lookup( FileMapper.class, IdentityMapper.ROLE_HINT ), SAMPLES, results ); - testFileMapper( (FileMapper) lookup( FileMapper.class ), SAMPLES, results ); + testFileMapper((FileMapper) lookup(FileMapper.class), SAMPLES, results); + testFileMapper((FileMapper) lookup(FileMapper.class, IdentityMapper.ROLE_HINT), SAMPLES, results); + testFileMapper((FileMapper) lookup(FileMapper.class), SAMPLES, results); } @Test - public void testFileExtensionMapper() throws Exception - { + public void testFileExtensionMapper() throws Exception { final String[] results = getIdentityResults(); - for ( int i = 2; i <= 10; i += 2 ) - { + for (int i = 2; i <= 10; i += 2) { results[i] += ".png"; } - for ( int i = 3; i <= 11; i += 2 ) - { - results[i] = results[i].substring( 0, results[i].length() - ".gif".length() ) + ".png"; + for (int i = 3; i <= 11; i += 2) { + results[i] = results[i].substring(0, results[i].length() - ".gif".length()) + ".png"; } - testFileExtensionMapper( results, new FileExtensionMapper() ); - testFileExtensionMapper( results, (FileExtensionMapper) lookup( FileMapper.class, FileExtensionMapper.ROLE_HINT ) ); + testFileExtensionMapper(results, new FileExtensionMapper()); + testFileExtensionMapper(results, (FileExtensionMapper) lookup(FileMapper.class, FileExtensionMapper.ROLE_HINT)); } - private void testFileExtensionMapper( final String[] results, final FileExtensionMapper mapper ) - { - mapper.setTargetExtension( "png" ); - testFileMapper( mapper, SAMPLES, results ); - mapper.setTargetExtension( ".png" ); - testFileMapper( mapper, SAMPLES, results ); + private void testFileExtensionMapper(final String[] results, final FileExtensionMapper mapper) { + mapper.setTargetExtension("png"); + testFileMapper(mapper, SAMPLES, results); + mapper.setTargetExtension(".png"); + testFileMapper(mapper, SAMPLES, results); } @Test - public void testFlattenMapper() throws Exception - { + public void testFlattenMapper() throws Exception { final String[] results = getIdentityResults(); results[4] = results[6] = results[8] = results[10] = results[2]; results[5] = results[7] = results[9] = results[11] = results[3]; - testFileMapper( new FlattenFileMapper(), SAMPLES, results ); - testFileMapper( (FileMapper) lookup( FileMapper.class, FlattenFileMapper.ROLE_HINT ), SAMPLES, results ); + testFileMapper(new FlattenFileMapper(), SAMPLES, results); + testFileMapper((FileMapper) lookup(FileMapper.class, FlattenFileMapper.ROLE_HINT), SAMPLES, results); } - private void testMergeMapper( String pTargetName, String[] pResults, MergeFileMapper pMapper ) - { - pMapper.setTargetName( pTargetName ); - testFileMapper( pMapper, SAMPLES, pResults ); + private void testMergeMapper(String pTargetName, String[] pResults, MergeFileMapper pMapper) { + pMapper.setTargetName(pTargetName); + testFileMapper(pMapper, SAMPLES, pResults); } @Test - public void testMergeMapper() throws Exception - { + public void testMergeMapper() throws Exception { final String[] results = getIdentityResults(); final String targetName = "zgh"; - for ( int i = 2; i < results.length; i++ ) - { + for (int i = 2; i < results.length; i++) { results[i] = targetName; } - testMergeMapper( targetName, results, new MergeFileMapper() ); - testMergeMapper( targetName, results, (MergeFileMapper) lookup( FileMapper.class, MergeFileMapper.ROLE_HINT ) ); + testMergeMapper(targetName, results, new MergeFileMapper()); + testMergeMapper(targetName, results, (MergeFileMapper) lookup(FileMapper.class, MergeFileMapper.ROLE_HINT)); } @Test - public void testPrefixMapper() throws Exception - { + public void testPrefixMapper() throws Exception { final String prefix = "x7Rtf"; final String[] results = getIdentityResults(); - testFileMapper( new PrefixFileMapper(), SAMPLES, results ); - testFileMapper( (PrefixFileMapper) lookup( FileMapper.class, PrefixFileMapper.ROLE_HINT ), SAMPLES, results ); - for ( int i = 0; i < results.length; i++ ) - { - if ( results[i] != null ) - { + testFileMapper(new PrefixFileMapper(), SAMPLES, results); + testFileMapper((PrefixFileMapper) lookup(FileMapper.class, PrefixFileMapper.ROLE_HINT), SAMPLES, results); + for (int i = 0; i < results.length; i++) { + if (results[i] != null) { results[i] = prefix + results[i]; } } PrefixFileMapper mapper = new PrefixFileMapper(); - mapper.setPrefix( prefix ); - testFileMapper( mapper, SAMPLES, results ); - mapper = (PrefixFileMapper) lookup( FileMapper.class, PrefixFileMapper.ROLE_HINT ); - mapper.setPrefix( prefix ); - testFileMapper( mapper, SAMPLES, results ); + mapper.setPrefix(prefix); + testFileMapper(mapper, SAMPLES, results); + mapper = (PrefixFileMapper) lookup(FileMapper.class, PrefixFileMapper.ROLE_HINT); + mapper.setPrefix(prefix); + testFileMapper(mapper, SAMPLES, results); } @Test - public void testSuffixMapper() throws Exception - { + public void testSuffixMapper() throws Exception { final String suffix = "suffix"; - String[] samples = Arrays.copyOf( SAMPLES, SAMPLES.length + 2 ); + String[] samples = Arrays.copyOf(SAMPLES, SAMPLES.length + 2); samples[samples.length - 2] = "archive.tar.gz"; samples[samples.length - 1] = "directory/archive.tar.gz"; - String[] results = new String[] { null, null, "asuffix", "xyzsuffix.gif", "b/asuffix", "b/xyzsuffix.gif", - "b\\asuffix", "b\\xyzsuffix.gif", "c.c/asuffix", "c.c/xyzsuffix.gif", "c.c\\asuffix", "c.c\\xyzsuffix.gif", - "archivesuffix.tar.gz", "directory/archivesuffix.tar.gz" }; + String[] results = new String[] { + null, + null, + "asuffix", + "xyzsuffix.gif", + "b/asuffix", + "b/xyzsuffix.gif", + "b\\asuffix", + "b\\xyzsuffix.gif", + "c.c/asuffix", + "c.c/xyzsuffix.gif", + "c.c\\asuffix", + "c.c\\xyzsuffix.gif", + "archivesuffix.tar.gz", + "directory/archivesuffix.tar.gz" + }; SuffixFileMapper mapper = new SuffixFileMapper(); - mapper.setSuffix( suffix ); - testFileMapper( mapper, samples, results ); - mapper = (SuffixFileMapper) lookup( FileMapper.class, SuffixFileMapper.ROLE_HINT ); - mapper.setSuffix( suffix ); - testFileMapper( mapper, samples, results ); + mapper.setSuffix(suffix); + testFileMapper(mapper, samples, results); + mapper = (SuffixFileMapper) lookup(FileMapper.class, SuffixFileMapper.ROLE_HINT); + mapper.setSuffix(suffix); + testFileMapper(mapper, samples, results); } - private RegExpFileMapper configure( RegExpFileMapper pMapper, String pPattern, String pReplacement ) - { - pMapper.setPattern( pPattern ); - pMapper.setReplacement( pReplacement ); + private RegExpFileMapper configure(RegExpFileMapper pMapper, String pPattern, String pReplacement) { + pMapper.setPattern(pPattern); + pMapper.setReplacement(pReplacement); return pMapper; } @Test - public void testRegExpFileMapper() throws Exception - { + public void testRegExpFileMapper() throws Exception { final String[] results = getIdentityResults(); results[3] = "xyz.jpg"; results[5] = "b/xyz.jpg"; results[7] = "b\\xyz.jpg"; results[9] = "c.c/xyz.jpg"; results[11] = "c.c\\xyz.jpg"; - testFileMapper( configure(new RegExpFileMapper(), "\\.gif$", ".jpg"), SAMPLES, results ); - testFileMapper( configure(new RegExpFileMapper(), "^(.*)\\.gif$", "$1.jpg"), SAMPLES, results ); - testFileMapper( configure((RegExpFileMapper) lookup( FileMapper.class, RegExpFileMapper.ROLE_HINT ), "\\.gif$", ".jpg"), SAMPLES, results ); - final RegExpFileMapper mapper = configure( new RegExpFileMapper(), "c", "f" ); - mapper.setReplaceAll( true ); + testFileMapper(configure(new RegExpFileMapper(), "\\.gif$", ".jpg"), SAMPLES, results); + testFileMapper(configure(new RegExpFileMapper(), "^(.*)\\.gif$", "$1.jpg"), SAMPLES, results); + testFileMapper( + configure((RegExpFileMapper) lookup(FileMapper.class, RegExpFileMapper.ROLE_HINT), "\\.gif$", ".jpg"), + SAMPLES, + results); + final RegExpFileMapper mapper = configure(new RegExpFileMapper(), "c", "f"); + mapper.setReplaceAll(true); final String[] fResults = getIdentityResults(); fResults[8] = "f.f/a"; fResults[9] = "f.f/xyz.gif"; fResults[10] = "f.f\\a"; fResults[11] = "f.f\\xyz.gif"; - testFileMapper( mapper, SAMPLES, fResults ); + testFileMapper(mapper, SAMPLES, fResults); } -} \ No newline at end of file +} diff --git a/src/test/java/org/codehaus/plexus/components/io/filemappers/FileSelectorTest.java b/src/test/java/org/codehaus/plexus/components/io/filemappers/FileSelectorTest.java index 6ec4a98f..f867658f 100644 --- a/src/test/java/org/codehaus/plexus/components/io/filemappers/FileSelectorTest.java +++ b/src/test/java/org/codehaus/plexus/components/io/filemappers/FileSelectorTest.java @@ -16,6 +16,8 @@ * limitations under the License. */ +import javax.annotation.Nonnull; + import java.io.IOException; import java.io.InputStream; import java.net.URL; @@ -26,132 +28,100 @@ import org.codehaus.plexus.components.io.resources.AbstractPlexusIoResource; import org.junit.Test; -import javax.annotation.Nonnull; - import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; - /** * Test case for implementations of {@link FileSelector}. */ -public class FileSelectorTest extends TestSupport -{ - protected void testFileSelector( FileSelector pSelector, String[] pInput, boolean[] pOutput) - throws IOException - { - for ( int i = 0; i < pInput.length; i++ ) - { +public class FileSelectorTest extends TestSupport { + protected void testFileSelector(FileSelector pSelector, String[] pInput, boolean[] pOutput) throws IOException { + for (int i = 0; i < pInput.length; i++) { final String name = pInput[i]; - AbstractPlexusIoResource resource = new AbstractPlexusIoResource( name, 0, 0, true, false, true ) - { + AbstractPlexusIoResource resource = new AbstractPlexusIoResource(name, 0, 0, true, false, true) { @Nonnull - public InputStream getContents() throws IOException - { - throw new IllegalStateException( "Not implemented" ); + public InputStream getContents() throws IOException { + throw new IllegalStateException("Not implemented"); } - public URL getURL() throws IOException - { - throw new IllegalStateException( "Not implemented" ); + public URL getURL() throws IOException { + throw new IllegalStateException("Not implemented"); } }; - boolean result = pSelector.isSelected( resource ); - if ( result != pOutput[i] ) - { - fail( "Test fails for selector " + pSelector.getClass().getName() - + " and input " + name + ": Expected " - + pOutput[i] ); + boolean result = pSelector.isSelected(resource); + if (result != pOutput[i]) { + fail("Test fails for selector " + pSelector.getClass().getName() + + " and input " + name + ": Expected " + + pOutput[i]); } } } - protected static final String[] SAMPLES = - new String[] - { - "foo/x.gif", - "foo/y.png", - "bar/x.gif" - }; + protected static final String[] SAMPLES = new String[] {"foo/x.gif", "foo/y.png", "bar/x.gif"}; - protected void testFileSelector( AllFilesFileSelector pSelector ) throws Exception - { + protected void testFileSelector(AllFilesFileSelector pSelector) throws Exception { final boolean[] trues = getAllTrues(); - testFileSelector( pSelector, SAMPLES, trues ); + testFileSelector(pSelector, SAMPLES, trues); } - private boolean[] getAllTrues() - { + private boolean[] getAllTrues() { final boolean[] trues = new boolean[SAMPLES.length]; - for ( int i = 0; i < trues.length; i++ ) - { + for (int i = 0; i < trues.length; i++) { trues[i] = true; } return trues; } @Test - public void testAllFilesFileSelector() throws Exception - { - testFileSelector( new AllFilesFileSelector() ); - testFileSelector( (AllFilesFileSelector) lookup( FileSelector.class ) ); - testFileSelector( (AllFilesFileSelector) lookup( FileSelector.class, AllFilesFileSelector.ROLE_HINT ) ); + public void testAllFilesFileSelector() throws Exception { + testFileSelector(new AllFilesFileSelector()); + testFileSelector((AllFilesFileSelector) lookup(FileSelector.class)); + testFileSelector((AllFilesFileSelector) lookup(FileSelector.class, AllFilesFileSelector.ROLE_HINT)); } - protected boolean[] getIncludeGifs( String[] pSamples ) - { + protected boolean[] getIncludeGifs(String[] pSamples) { boolean[] result = new boolean[pSamples.length]; - for ( int i = 0; i < pSamples.length; i++ ) - { - result[i] = pSamples[i].endsWith( ".gif" ); + for (int i = 0; i < pSamples.length; i++) { + result[i] = pSamples[i].endsWith(".gif"); } return result; } - protected boolean[] getExcludeBar( String[] pSamples, boolean[] pResult ) - { - for ( int i = 0; i < pSamples.length; i++ ) - { - if ( pSamples[i].startsWith( "bar/" ) ) - { + protected boolean[] getExcludeBar(String[] pSamples, boolean[] pResult) { + for (int i = 0; i < pSamples.length; i++) { + if (pSamples[i].startsWith("bar/")) { pResult[i] = false; } } return pResult; } - - protected void testFileSelector( IncludeExcludeFileSelector pSelector ) throws Exception - { - testFileSelector( pSelector, SAMPLES, getAllTrues() ); - pSelector.setIncludes( new String[] { "**/*.gif" } ); - testFileSelector( pSelector, SAMPLES, getIncludeGifs( SAMPLES ) ); - pSelector.setExcludes( new String[] { "bar/*" } ); - testFileSelector( pSelector, SAMPLES, getExcludeBar( SAMPLES, getIncludeGifs( SAMPLES ) ) ); - pSelector.setIncludes( null ); - testFileSelector( pSelector, SAMPLES, getExcludeBar( SAMPLES, getAllTrues() ) ); + + protected void testFileSelector(IncludeExcludeFileSelector pSelector) throws Exception { + testFileSelector(pSelector, SAMPLES, getAllTrues()); + pSelector.setIncludes(new String[] {"**/*.gif"}); + testFileSelector(pSelector, SAMPLES, getIncludeGifs(SAMPLES)); + pSelector.setExcludes(new String[] {"bar/*"}); + testFileSelector(pSelector, SAMPLES, getExcludeBar(SAMPLES, getIncludeGifs(SAMPLES))); + pSelector.setIncludes(null); + testFileSelector(pSelector, SAMPLES, getExcludeBar(SAMPLES, getAllTrues())); } @Test - public void testIncludeExcludeFileSelector() throws Exception - { - testFileSelector( new IncludeExcludeFileSelector() ); - testFileSelector( (IncludeExcludeFileSelector) lookup( FileSelector.class, - IncludeExcludeFileSelector.ROLE_HINT ) ); + public void testIncludeExcludeFileSelector() throws Exception { + testFileSelector(new IncludeExcludeFileSelector()); + testFileSelector((IncludeExcludeFileSelector) lookup(FileSelector.class, IncludeExcludeFileSelector.ROLE_HINT)); } @Test - public void testIncludeExcludeFileSelector_SetExcludes() throws Exception - { + public void testIncludeExcludeFileSelector_SetExcludes() throws Exception { IncludeExcludeFileSelector selector = new IncludeExcludeFileSelector(); // Test that the setExcludes method does not modify the excludes. - selector.setExcludes( SAMPLES ); + selector.setExcludes(SAMPLES); String[] sltrExcludes = selector.getExcludes(); - assertEquals( SAMPLES.length, sltrExcludes.length ); - for ( int i = 0; i < sltrExcludes.length; ++i ) - { - assertEquals( SAMPLES[i], sltrExcludes[i] ); + assertEquals(SAMPLES.length, sltrExcludes.length); + for (int i = 0; i < sltrExcludes.length; ++i) { + assertEquals(SAMPLES[i], sltrExcludes[i]); } - } -} \ No newline at end of file +} diff --git a/src/test/java/org/codehaus/plexus/components/io/filemappers/ResourcesTest.java b/src/test/java/org/codehaus/plexus/components/io/filemappers/ResourcesTest.java index f89d4d1a..66429a3e 100644 --- a/src/test/java/org/codehaus/plexus/components/io/filemappers/ResourcesTest.java +++ b/src/test/java/org/codehaus/plexus/components/io/filemappers/ResourcesTest.java @@ -40,215 +40,169 @@ import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; - /** * Test case for resource collections. */ -public class ResourcesTest extends TestSupport -{ +public class ResourcesTest extends TestSupport { private static final String X_PATH = "x"; private static final String A_PATH = X_PATH + "/a"; private static final String B_PATH = X_PATH + "/b"; private static final String Y_PATH = "y"; - private File getTestDir() - { - final String testDirPath = System.getProperty( "plexus.io.testDirPath" ); - return new File( testDirPath == null ? "target/plexus.io.testDir" : testDirPath ); + private File getTestDir() { + final String testDirPath = System.getProperty("plexus.io.testDirPath"); + return new File(testDirPath == null ? "target/plexus.io.testDir" : testDirPath); } - private File getFilesDir() - { - return new File( getTestDir(), "files" ); + private File getFilesDir() { + return new File(getTestDir(), "files"); } - private void createFiles() - throws IOException - { + private void createFiles() throws IOException { final File baseDir = getFilesDir(); - FileUtils.deleteDirectory( baseDir ); - FileUtils.mkdir( baseDir.getPath() ); - final File aFile = new File( baseDir, A_PATH ); - FileUtils.mkdir( aFile.getParentFile().getPath() ); - FileOutputStream fos = new FileOutputStream( aFile ); - fos.write( "0123456789".getBytes( "US-ASCII" ) ); + FileUtils.deleteDirectory(baseDir); + FileUtils.mkdir(baseDir.getPath()); + final File aFile = new File(baseDir, A_PATH); + FileUtils.mkdir(aFile.getParentFile().getPath()); + FileOutputStream fos = new FileOutputStream(aFile); + fos.write("0123456789".getBytes("US-ASCII")); fos.close(); - final File bFile = new File( baseDir, B_PATH ); - fos = new FileOutputStream( bFile ); - fos.write( "abcdefghijklmnopqrstuvwxyz".getBytes( "US-ASCII" ) ); + final File bFile = new File(baseDir, B_PATH); + fos = new FileOutputStream(bFile); + fos.write("abcdefghijklmnopqrstuvwxyz".getBytes("US-ASCII")); fos.close(); - final File yDir = new File( baseDir, Y_PATH ); - FileUtils.mkdir( yDir.getPath() ); + final File yDir = new File(baseDir, Y_PATH); + FileUtils.mkdir(yDir.getPath()); } - private void addDirToZipFile( ZipOutputStream zos, File dir, String path ) - throws IOException - { - final String prefix = path == null ? "" : ( path + "/" ); + private void addDirToZipFile(ZipOutputStream zos, File dir, String path) throws IOException { + final String prefix = path == null ? "" : (path + "/"); File[] files = dir.listFiles(); - for ( File f : files ) - { + for (File f : files) { final String entryName = prefix + f.getName(); - ZipEntry ze = new ZipEntry( entryName ); - if ( f.isFile() ) - { - ze.setSize( f.length() ); - zos.putNextEntry( ze ); - FileInputStream fis = new FileInputStream( f ); + ZipEntry ze = new ZipEntry(entryName); + if (f.isFile()) { + ze.setSize(f.length()); + zos.putNextEntry(ze); + FileInputStream fis = new FileInputStream(f); byte[] buffer = new byte[1024]; - for ( ;; ) - { - int res = fis.read( buffer ); - if ( res == -1 ) - { + for (; ; ) { + int res = fis.read(buffer); + if (res == -1) { break; } - if ( res > 0 ) - { - zos.write( buffer, 0, res ); + if (res > 0) { + zos.write(buffer, 0, res); } } fis.close(); - ze.setTime( f.lastModified() ); + ze.setTime(f.lastModified()); zos.closeEntry(); - } - else - { - addDirToZipFile( zos, f, entryName ); + } else { + addDirToZipFile(zos, f, entryName); } } } - private void createZipFile( File dest, File dir ) throws IOException - { - FileOutputStream fos = new FileOutputStream( dest ); - ZipOutputStream zos = new ZipOutputStream( fos ); - addDirToZipFile( zos, dir, null ); + private void createZipFile(File dest, File dir) throws IOException { + FileOutputStream fos = new FileOutputStream(dest); + ZipOutputStream zos = new ZipOutputStream(fos); + addDirToZipFile(zos, dir, null); zos.close(); } - private void compare( InputStream in, File file ) - throws IOException - { - try( InputStream fIn = new FileInputStream( file ) ) - { - for ( ;; ) - { + private void compare(InputStream in, File file) throws IOException { + try (InputStream fIn = new FileInputStream(file)) { + for (; ; ) { int i1 = in.read(); int i2 = fIn.read(); - assertEquals( i2, i1 ); - if ( i1 == -1 ) - { + assertEquals(i2, i1); + if (i1 == -1) { break; } } } } - private void compare( PlexusIoResource res, File file ) - throws IOException - { - assertTrue( res.getLastModified() != PlexusIoResource.UNKNOWN_MODIFICATION_DATE ); - if ( res instanceof PlexusIoFileResource ) - { - assertEquals( res.getLastModified() / 1000, file.lastModified() / 1000 ); + private void compare(PlexusIoResource res, File file) throws IOException { + assertTrue(res.getLastModified() != PlexusIoResource.UNKNOWN_MODIFICATION_DATE); + if (res instanceof PlexusIoFileResource) { + assertEquals(res.getLastModified() / 1000, file.lastModified() / 1000); } - assertTrue( res.getSize() != PlexusIoResource.UNKNOWN_RESOURCE_SIZE ); - assertEquals( res.getSize(), file.length() ); + assertTrue(res.getSize() != PlexusIoResource.UNKNOWN_RESOURCE_SIZE); + assertEquals(res.getSize(), file.length()); InputStream in = res.getContents(); - compare( in, file ); + compare(in, file); in.close(); URLConnection uc = res.getURL().openConnection(); - uc.setUseCaches( false ); + uc.setUseCaches(false); in = uc.getInputStream(); - compare( in, file ); + compare(in, file); in.close(); } - private void testPlexusIoResourceCollection( PlexusIoResourceCollection plexusIoResourceCollection ) - throws IOException - { + private void testPlexusIoResourceCollection(PlexusIoResourceCollection plexusIoResourceCollection) + throws IOException { boolean xPathSeen = false; boolean yPathSeen = false; boolean aFileSeen = false; boolean bFileSeen = false; Iterator iter = plexusIoResourceCollection.getResources(); - while ( iter.hasNext() ) - { + while (iter.hasNext()) { PlexusIoResource res = (PlexusIoResource) iter.next(); - final String resName = res.getName().replace( File.separatorChar, '/' ); - if ( res.isDirectory() ) - { - assertFalse( "The directory " + resName + " is a file.", res.isFile() ); - if ( X_PATH.equals( resName ) ) - { + final String resName = res.getName().replace(File.separatorChar, '/'); + if (res.isDirectory()) { + assertFalse("The directory " + resName + " is a file.", res.isFile()); + if (X_PATH.equals(resName)) { xPathSeen = true; - } - else if ( Y_PATH.equals( resName ) ) - { + } else if (Y_PATH.equals(resName)) { yPathSeen = true; - } - else if ( "".equals( resName ) || ".".equals( resName ) ) - { + } else if ("".equals(resName) || ".".equals(resName)) { // Ignore me + } else { + fail("Unexpected directory entry: " + resName); } - else - { - fail( "Unexpected directory entry: " + resName ); - } - final File dir = new File( getFilesDir(), resName ); - assertTrue( "The directory " + dir + " doesn't exist.", dir.isDirectory() ); - } - else - { - assertTrue( "The file " + resName + " isn't reported to be a file.", res.isFile() ); - assertTrue( "The file " + resName + " doesn't exist.", res.isExisting() ); - final File f = new File( getFilesDir(), resName ); - assertTrue( "A file " + f + " doesn't exist.", f.isFile() && f.exists() ); - if ( A_PATH.equals( resName ) ) - { + final File dir = new File(getFilesDir(), resName); + assertTrue("The directory " + dir + " doesn't exist.", dir.isDirectory()); + } else { + assertTrue("The file " + resName + " isn't reported to be a file.", res.isFile()); + assertTrue("The file " + resName + " doesn't exist.", res.isExisting()); + final File f = new File(getFilesDir(), resName); + assertTrue("A file " + f + " doesn't exist.", f.isFile() && f.exists()); + if (A_PATH.equals(resName)) { aFileSeen = true; - } - else if ( B_PATH.equals( resName ) ) - { + } else if (B_PATH.equals(resName)) { bFileSeen = true; + } else { + fail("Unexpected file entry: " + resName); } - else - { - fail( "Unexpected file entry: " + resName ); - } - compare( res, f ); + compare(res, f); } } - assertTrue( aFileSeen ); - assertTrue( bFileSeen ); - if ( iter instanceof Closeable ) - { - ( (Closeable) iter ).close(); + assertTrue(aFileSeen); + assertTrue(bFileSeen); + if (iter instanceof Closeable) { + ((Closeable) iter).close(); } } - private void testFileResourceCollection( PlexusIoFileResourceCollection resourceCollection ) - throws IOException - { - resourceCollection.setBaseDir( getFilesDir() ); - testPlexusIoResourceCollection( resourceCollection ); + private void testFileResourceCollection(PlexusIoFileResourceCollection resourceCollection) throws IOException { + resourceCollection.setBaseDir(getFilesDir()); + testPlexusIoResourceCollection(resourceCollection); } @Test - public void testFileCollection() throws Exception - { + public void testFileCollection() throws Exception { createFiles(); - testFileResourceCollection( (PlexusIoFileResourceCollection) lookup( PlexusIoResourceCollection.class ) ); - testFileResourceCollection( (PlexusIoFileResourceCollection) lookup( PlexusIoResourceCollection.class, - PlexusIoFileResourceCollection.ROLE_HINT ) ); + testFileResourceCollection((PlexusIoFileResourceCollection) lookup(PlexusIoResourceCollection.class)); + testFileResourceCollection((PlexusIoFileResourceCollection) + lookup(PlexusIoResourceCollection.class, PlexusIoFileResourceCollection.ROLE_HINT)); } - private void testZipFileCollection( AbstractPlexusIoArchiveResourceCollection resourceCollection, File zipFile ) - throws IOException - { - resourceCollection.setFile( zipFile ); - testPlexusIoResourceCollection( resourceCollection ); + private void testZipFileCollection(AbstractPlexusIoArchiveResourceCollection resourceCollection, File zipFile) + throws IOException { + resourceCollection.setFile(zipFile); + testPlexusIoResourceCollection(resourceCollection); } -} \ No newline at end of file +} diff --git a/src/test/java/org/codehaus/plexus/components/io/filemappers/TestSupport.java b/src/test/java/org/codehaus/plexus/components/io/filemappers/TestSupport.java index 4ca439d6..aa88691d 100644 --- a/src/test/java/org/codehaus/plexus/components/io/filemappers/TestSupport.java +++ b/src/test/java/org/codehaus/plexus/components/io/filemappers/TestSupport.java @@ -21,6 +21,4 @@ /** * Support for componentized testing. */ -public abstract class TestSupport extends InjectedTest -{ -} \ No newline at end of file +public abstract class TestSupport extends InjectedTest {} diff --git a/src/test/java/org/codehaus/plexus/components/io/resources/AbstractPlexusIoResourceCollectionTest.java b/src/test/java/org/codehaus/plexus/components/io/resources/AbstractPlexusIoResourceCollectionTest.java index 4abda75d..635b5ced 100644 --- a/src/test/java/org/codehaus/plexus/components/io/resources/AbstractPlexusIoResourceCollectionTest.java +++ b/src/test/java/org/codehaus/plexus/components/io/resources/AbstractPlexusIoResourceCollectionTest.java @@ -1,9 +1,7 @@ package org.codehaus.plexus.components.io.resources; -import org.codehaus.plexus.components.io.functions.InputStreamTransformer; -import org.junit.Test; - import javax.annotation.Nonnull; + import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; @@ -11,78 +9,61 @@ import java.util.Arrays; import java.util.Iterator; +import org.codehaus.plexus.components.io.functions.InputStreamTransformer; +import org.junit.Test; + import static org.junit.Assert.assertEquals; /** * @author Kristian Rosenvold */ -public class AbstractPlexusIoResourceCollectionTest -{ - @SuppressWarnings( "ResultOfMethodCallIgnored" ) +public class AbstractPlexusIoResourceCollectionTest { + @SuppressWarnings("ResultOfMethodCallIgnored") @Test - public void testGetIncludes() - throws Exception - { - AbstractPlexusIoResourceCollection sut = new AbstractPlexusIoResourceCollection() - { - public Iterator getResources() - throws IOException - { - return Arrays.asList( getResource( "r1" ), getResource( "r2" ) ).iterator(); + public void testGetIncludes() throws Exception { + AbstractPlexusIoResourceCollection sut = new AbstractPlexusIoResourceCollection() { + public Iterator getResources() throws IOException { + return Arrays.asList(getResource("r1"), getResource("r2")).iterator(); } - public Stream stream() - { + public Stream stream() { throw new UnsupportedOperationException(); } - public boolean isConcurrentAccessSupported() - { + public boolean isConcurrentAccessSupported() { return true; } - }; - sut.setStreamTransformer( new InputStreamTransformer() - { + sut.setStreamTransformer(new InputStreamTransformer() { @Nonnull - public InputStream transform( @Nonnull PlexusIoResource resource, @Nonnull final InputStream inputStream ) - throws IOException - { + public InputStream transform(@Nonnull PlexusIoResource resource, @Nonnull final InputStream inputStream) + throws IOException { final byte[] buf = new byte[2]; buf[0] = (byte) inputStream.read(); buf[1] = (byte) inputStream.read(); - return new ByteArrayInputStream( buf ); + return new ByteArrayInputStream(buf); } - } ); + }); final PlexusIoResource next = sut.getResources().next(); - final InputStream inputStream = sut.getInputStream( next ); + final InputStream inputStream = sut.getInputStream(next); inputStream.read(); inputStream.read(); - assertEquals( -1, inputStream.read() ); + assertEquals(-1, inputStream.read()); inputStream.close(); - } - private static PlexusIoResource getResource( final String r1 ) - { - return new AbstractPlexusIoResource( r1, 0, 0, true, false, true ) - { + private static PlexusIoResource getResource(final String r1) { + return new AbstractPlexusIoResource(r1, 0, 0, true, false, true) { @Nonnull - public InputStream getContents() - throws IOException - { - return new ByteArrayInputStream( (r1 + "Payload").getBytes() ); + public InputStream getContents() throws IOException { + return new ByteArrayInputStream((r1 + "Payload").getBytes()); } - public URL getURL() - throws IOException - { - throw new IllegalStateException( "Not implemented" ); + public URL getURL() throws IOException { + throw new IllegalStateException("Not implemented"); } }; } - } - diff --git a/src/test/java/org/codehaus/plexus/components/io/resources/PlexusIoFileSupplierResourceCollectionTest.java b/src/test/java/org/codehaus/plexus/components/io/resources/PlexusIoFileSupplierResourceCollectionTest.java index 954748d2..418a3f04 100755 --- a/src/test/java/org/codehaus/plexus/components/io/resources/PlexusIoFileSupplierResourceCollectionTest.java +++ b/src/test/java/org/codehaus/plexus/components/io/resources/PlexusIoFileSupplierResourceCollectionTest.java @@ -1,32 +1,28 @@ package org.codehaus.plexus.components.io.resources; -import org.junit.Test; - import java.io.File; import java.util.Iterator; +import org.junit.Test; + import static org.junit.Assert.assertTrue; /** * @author Kristian Rosenvold */ -public class PlexusIoFileSupplierResourceCollectionTest -{ +public class PlexusIoFileSupplierResourceCollectionTest { @Test - public void testGetName() - throws Exception - { + public void testGetName() throws Exception { PlexusIoFileResourceCollection coll = new PlexusIoFileResourceCollection(); char nonSeparator = File.separatorChar == '/' ? '\\' : '/'; - coll.setPrefix( "fud" + nonSeparator ); + coll.setPrefix("fud" + nonSeparator); - coll.setBaseDir( new File( "src/test/resources/symlinks" ) ); + coll.setBaseDir(new File("src/test/resources/symlinks")); final Iterator resources = coll.getResources(); - while ( resources.hasNext() ) - { + while (resources.hasNext()) { final PlexusIoResource next = resources.next(); - final String name = coll.getName( next ); - assertTrue( name.indexOf( nonSeparator ) < 0 ); + final String name = coll.getName(next); + assertTrue(name.indexOf(nonSeparator) < 0); } } } diff --git a/src/test/java/org/codehaus/plexus/components/io/resources/PlexusIoPlexusIoFileResourceTest.java b/src/test/java/org/codehaus/plexus/components/io/resources/PlexusIoPlexusIoFileResourceTest.java index 4b3ba449..289087c4 100644 --- a/src/test/java/org/codehaus/plexus/components/io/resources/PlexusIoPlexusIoFileResourceTest.java +++ b/src/test/java/org/codehaus/plexus/components/io/resources/PlexusIoPlexusIoFileResourceTest.java @@ -5,7 +5,6 @@ import org.codehaus.plexus.components.io.attributes.FileAttributes; import org.codehaus.plexus.components.io.attributes.PlexusIoResourceAttributes; - import org.codehaus.plexus.components.io.attributes.SymlinkUtils; import org.codehaus.plexus.components.io.functions.SymlinkDestinationSupplier; import org.codehaus.plexus.util.Os; @@ -15,60 +14,50 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; -public class PlexusIoPlexusIoFileResourceTest -{ +public class PlexusIoPlexusIoFileResourceTest { @Test - public void testRealSymlink() - throws IOException - { - if ( Os.isFamily( Os.FAMILY_WINDOWS ) ) - return; - final File file = new File( "src/test/resources/symlinks/src/symDir" ); - PlexusIoResourceAttributes attrs = FileAttributes.uncached( file ); - assertTrue( attrs.isSymbolicLink() ); - PlexusIoResource r = ResourceFactory.createResource( file ); - assertTrue( r.isSymbolicLink() ); - assertTrue( r.isDirectory() ); - final File target = SymlinkUtils.readSymbolicLink( file ); - assertTrue( target.getName().endsWith( "targetDir" ) ); - assertTrue( r instanceof SymlinkDestinationSupplier ); - assertEquals( "targetDir/", ( ( SymlinkDestinationSupplier ) r ).getSymlinkDestination() ); + public void testRealSymlink() throws IOException { + if (Os.isFamily(Os.FAMILY_WINDOWS)) return; + final File file = new File("src/test/resources/symlinks/src/symDir"); + PlexusIoResourceAttributes attrs = FileAttributes.uncached(file); + assertTrue(attrs.isSymbolicLink()); + PlexusIoResource r = ResourceFactory.createResource(file); + assertTrue(r.isSymbolicLink()); + assertTrue(r.isDirectory()); + final File target = SymlinkUtils.readSymbolicLink(file); + assertTrue(target.getName().endsWith("targetDir")); + assertTrue(r instanceof SymlinkDestinationSupplier); + assertEquals("targetDir/", ((SymlinkDestinationSupplier) r).getSymlinkDestination()); } @Test - public void testSymSymlinkFile() - throws IOException - { - if ( Os.isFamily( Os.FAMILY_WINDOWS ) ) - return; - final File file = new File( "src/test/resources/symlinks/src/symSymR" ); - PlexusIoResource r = ResourceFactory.createResource( file ); - assertTrue( r.isSymbolicLink() ); - assertEquals( 38, r.getSize() ); - PlexusIoResource rL = ( ( PlexusIoSymlinkResource ) r ).getLink(); - assertFalse( rL instanceof PlexusIoSymlinkResource ); - PlexusIoResource rT = ( ( PlexusIoSymlinkResource ) r ).getTarget(); - assertTrue( rT instanceof PlexusIoSymlinkResource ); - PlexusIoResource rTT = ( ( PlexusIoSymlinkResource ) rT ).getTarget(); - assertFalse( rTT instanceof PlexusIoSymlinkResource ); + public void testSymSymlinkFile() throws IOException { + if (Os.isFamily(Os.FAMILY_WINDOWS)) return; + final File file = new File("src/test/resources/symlinks/src/symSymR"); + PlexusIoResource r = ResourceFactory.createResource(file); + assertTrue(r.isSymbolicLink()); + assertEquals(38, r.getSize()); + PlexusIoResource rL = ((PlexusIoSymlinkResource) r).getLink(); + assertFalse(rL instanceof PlexusIoSymlinkResource); + PlexusIoResource rT = ((PlexusIoSymlinkResource) r).getTarget(); + assertTrue(rT instanceof PlexusIoSymlinkResource); + PlexusIoResource rTT = ((PlexusIoSymlinkResource) rT).getTarget(); + assertFalse(rTT instanceof PlexusIoSymlinkResource); } @Test - public void testSymlinkFile() - throws IOException - { - if ( Os.isFamily( Os.FAMILY_WINDOWS ) ) - return; - final File file = new File( "src/test/resources/symlinks/src/symR" ); - PlexusIoResource r = ResourceFactory.createResource( file ); - assertTrue( r.isSymbolicLink() ); - assertEquals( 38, r.getSize() ); - - final File file2 = new File( "src/test/resources/symlinks/src/symSymR" ); - PlexusIoResource r2 = ResourceFactory.createResource( file2 ); - assertTrue( r2.isSymbolicLink() ); - assertEquals( 38, r2.getSize() ); - PlexusIoResource r3 = ( ( PlexusIoSymlinkResource ) r2 ).getTarget(); + public void testSymlinkFile() throws IOException { + if (Os.isFamily(Os.FAMILY_WINDOWS)) return; + final File file = new File("src/test/resources/symlinks/src/symR"); + PlexusIoResource r = ResourceFactory.createResource(file); + assertTrue(r.isSymbolicLink()); + assertEquals(38, r.getSize()); + + final File file2 = new File("src/test/resources/symlinks/src/symSymR"); + PlexusIoResource r2 = ResourceFactory.createResource(file2); + assertTrue(r2.isSymbolicLink()); + assertEquals(38, r2.getSize()); + PlexusIoResource r3 = ((PlexusIoSymlinkResource) r2).getTarget(); } -} \ No newline at end of file +} diff --git a/src/test/java/org/codehaus/plexus/components/io/resources/proxy/PlexusIoProxyResourceCollectionTest.java b/src/test/java/org/codehaus/plexus/components/io/resources/proxy/PlexusIoProxyResourceCollectionTest.java index b4c14420..87ba1e42 100644 --- a/src/test/java/org/codehaus/plexus/components/io/resources/proxy/PlexusIoProxyResourceCollectionTest.java +++ b/src/test/java/org/codehaus/plexus/components/io/resources/proxy/PlexusIoProxyResourceCollectionTest.java @@ -16,126 +16,102 @@ * limitations under the License. */ -import org.codehaus.plexus.components.io.resources.AbstractPlexusIoResource; -import org.codehaus.plexus.components.io.resources.AbstractPlexusIoResourceCollection; -import org.codehaus.plexus.components.io.resources.PlexusIoResource; -import org.codehaus.plexus.components.io.resources.Stream; -import org.junit.Test; - import javax.annotation.Nonnull; + import java.io.Closeable; import java.io.IOException; import java.io.InputStream; import java.net.URL; import java.util.Iterator; +import org.codehaus.plexus.components.io.resources.AbstractPlexusIoResource; +import org.codehaus.plexus.components.io.resources.AbstractPlexusIoResourceCollection; +import org.codehaus.plexus.components.io.resources.PlexusIoResource; +import org.codehaus.plexus.components.io.resources.Stream; +import org.junit.Test; + import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; - /** * Test case for {@link PlexusIoProxyResourceCollection}. */ -public class PlexusIoProxyResourceCollectionTest -{ - private final String[] SAMPLE_INCLUDES = { "junk.*", "test/**", "dir*/file.xml" }; +public class PlexusIoProxyResourceCollectionTest { + private final String[] SAMPLE_INCLUDES = {"junk.*", "test/**", "dir*/file.xml"}; - private final String[] SAMPLE_EXCLUDES = { "*.junk", "somwhere/**" }; + private final String[] SAMPLE_EXCLUDES = {"*.junk", "somwhere/**"}; @Test - public void testGetDefaultFileSelector() - throws Exception - { - PlexusIoProxyResourceCollection resCol = new PlexusIoProxyResourceCollection( null ); + public void testGetDefaultFileSelector() throws Exception { + PlexusIoProxyResourceCollection resCol = new PlexusIoProxyResourceCollection(null); // This will throw an exception if there is a bug resCol.getDefaultFileSelector(); - resCol.setIncludes( SAMPLE_INCLUDES ); - resCol.setExcludes( SAMPLE_EXCLUDES ); + resCol.setIncludes(SAMPLE_INCLUDES); + resCol.setExcludes(SAMPLE_EXCLUDES); // This will throw an exception if there is a bug resCol.getDefaultFileSelector(); - } - class CloseableIterator - implements Iterator, Closeable - { + class CloseableIterator implements Iterator, Closeable { boolean next = true; boolean closed = false; - public void close() - throws IOException - { + public void close() throws IOException { closed = true; } - public boolean hasNext() - { - if ( next ) - { + public boolean hasNext() { + if (next) { next = false; return true; } return false; } - public PlexusIoResource next() - { - return new AbstractPlexusIoResource( "fud", 123, 22, true, false, false ) - { + public PlexusIoResource next() { + return new AbstractPlexusIoResource("fud", 123, 22, true, false, false) { @Nonnull - public InputStream getContents() - throws IOException - { + public InputStream getContents() throws IOException { return null; } - public URL getURL() - throws IOException - { + public URL getURL() throws IOException { return null; } }; } - public void remove() - { + public void remove() { throw new UnsupportedOperationException(); } } @Test - public void testClosing() - throws IOException - { + public void testClosing() throws IOException { final CloseableIterator closeableIterator = new CloseableIterator(); PlexusIoProxyResourceCollection resCol = - new PlexusIoProxyResourceCollection( new AbstractPlexusIoResourceCollection() - { - public Iterator getResources() - throws IOException - { - return closeableIterator; - } - - public Stream stream() - { - throw new UnsupportedOperationException(); - } - - public boolean isConcurrentAccessSupported() - { - return true; - } - } ); + new PlexusIoProxyResourceCollection(new AbstractPlexusIoResourceCollection() { + public Iterator getResources() throws IOException { + return closeableIterator; + } + + public Stream stream() { + throw new UnsupportedOperationException(); + } + + public boolean isConcurrentAccessSupported() { + return true; + } + }); Iterator resources1 = resCol.getResources(); resources1.hasNext(); resources1.next(); - assertFalse( resources1.hasNext() ); - ( (Closeable) resources1 ).close(); - assertTrue( closeableIterator.closed ); + assertFalse(resources1.hasNext()); + ((Closeable) resources1).close(); + assertTrue(closeableIterator.closed); } -} \ No newline at end of file +} diff --git a/src/test/java/org/codehaus/plexus/components/io/resources/proxy/ProxyFactoryTest.java b/src/test/java/org/codehaus/plexus/components/io/resources/proxy/ProxyFactoryTest.java index 035fcb31..78383324 100644 --- a/src/test/java/org/codehaus/plexus/components/io/resources/proxy/ProxyFactoryTest.java +++ b/src/test/java/org/codehaus/plexus/components/io/resources/proxy/ProxyFactoryTest.java @@ -1,5 +1,12 @@ package org.codehaus.plexus.components.io.resources.proxy; +import javax.annotation.Nonnull; + +import java.io.ByteArrayInputStream; +import java.io.File; +import java.io.IOException; +import java.io.InputStream; + import org.codehaus.plexus.components.io.attributes.FileAttributes; import org.codehaus.plexus.components.io.attributes.PlexusIoResourceAttributes; import org.codehaus.plexus.components.io.attributes.SimpleResourceAttributes; @@ -13,143 +20,100 @@ import org.codehaus.plexus.components.io.resources.PlexusIoResource; import org.junit.Test; -import javax.annotation.Nonnull; -import java.io.ByteArrayInputStream; -import java.io.File; -import java.io.IOException; -import java.io.InputStream; - import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; -public class ProxyFactoryTest -{ +public class ProxyFactoryTest { @Test - public void testCreateProxy() - throws Exception - { - final PlexusIoResource proxy = ProxyFactory.createProxy( getPomResource(), null ); - assertTrue( proxy instanceof ResourceAttributeSupplier ); - assertTrue( proxy instanceof FileSupplier ); - assertFalse( proxy instanceof SymlinkDestinationSupplier ); + public void testCreateProxy() throws Exception { + final PlexusIoResource proxy = ProxyFactory.createProxy(getPomResource(), null); + assertTrue(proxy instanceof ResourceAttributeSupplier); + assertTrue(proxy instanceof FileSupplier); + assertFalse(proxy instanceof SymlinkDestinationSupplier); } @Test - public void testCreateProxyWithNameOverride() - throws Exception - { - NameSupplier ns = new NameSupplier() - { - public String getName() - { + public void testCreateProxyWithNameOverride() throws Exception { + NameSupplier ns = new NameSupplier() { + public String getName() { return "fred"; } }; - final PlexusIoResource proxy = ProxyFactory.createProxy( getPomResource(), ns ); - assertEquals( "fred", proxy.getName() ); + final PlexusIoResource proxy = ProxyFactory.createProxy(getPomResource(), ns); + assertEquals("fred", proxy.getName()); } @Test - public void testCreateProxyWithResourceAttributeOverride() - throws Exception - { + public void testCreateProxyWithResourceAttributeOverride() throws Exception { final PlexusIoResourceAttributes s = SimpleResourceAttributes.lastResortDummyAttributesForBrokenOS(); - ResourceAttributeSupplier ns = new ResourceAttributeSupplier() - { - public PlexusIoResourceAttributes getAttributes() - { + ResourceAttributeSupplier ns = new ResourceAttributeSupplier() { + public PlexusIoResourceAttributes getAttributes() { return s; } }; - final PlexusIoResource proxy = ProxyFactory.createProxy( getPomResource(), ns ); - assertSame( s, ( (ResourceAttributeSupplier) proxy ).getAttributes() ); + final PlexusIoResource proxy = ProxyFactory.createProxy(getPomResource(), ns); + assertSame(s, ((ResourceAttributeSupplier) proxy).getAttributes()); } @Test - public void testCreateProxyWithSizeSupplierOverride() - throws Exception - { + public void testCreateProxyWithSizeSupplierOverride() throws Exception { final PlexusIoResourceAttributes s = SimpleResourceAttributes.lastResortDummyAttributesForBrokenOS(); - SizeSupplier ns = new SizeSupplier() - { - public long getSize() - { + SizeSupplier ns = new SizeSupplier() { + public long getSize() { return 42; } }; - final PlexusIoResource proxy = ProxyFactory.createProxy( getPomResource(), ns ); - assertEquals( 42, proxy.getSize() ); + final PlexusIoResource proxy = ProxyFactory.createProxy(getPomResource(), ns); + assertEquals(42, proxy.getSize()); } @Test - public void testCreateProxyWithContentSupplierOverride() - throws Exception - { - final InputStream s = new ByteArrayInputStream( new byte[10] ); - ContentSupplier ns = new ContentSupplier() - { - public InputStream getContents() - throws IOException - { + public void testCreateProxyWithContentSupplierOverride() throws Exception { + final InputStream s = new ByteArrayInputStream(new byte[10]); + ContentSupplier ns = new ContentSupplier() { + public InputStream getContents() throws IOException { return s; } - }; - final PlexusIoResource proxy = ProxyFactory.createProxy( getPomResource(), ns ); - assertEquals( s, proxy.getContents() ); + final PlexusIoResource proxy = ProxyFactory.createProxy(getPomResource(), ns); + assertEquals(s, proxy.getContents()); } @Test - public void testCreateProxyWithSymlinkDestinationSupplierOverride() - throws Exception - { - SymlinkDestinationSupplier ns = new SymlinkDestinationSupplier() - { - public String getSymlinkDestination() - throws IOException - { + public void testCreateProxyWithSymlinkDestinationSupplierOverride() throws Exception { + SymlinkDestinationSupplier ns = new SymlinkDestinationSupplier() { + public String getSymlinkDestination() throws IOException { return "mordor"; } }; - final PlexusIoResource proxy = ProxyFactory.createProxy( getDummySymlinkResource(), ns ); - assertEquals( "mordor", ( (SymlinkDestinationSupplier) proxy ).getSymlinkDestination() ); + final PlexusIoResource proxy = ProxyFactory.createProxy(getDummySymlinkResource(), ns); + assertEquals("mordor", ((SymlinkDestinationSupplier) proxy).getSymlinkDestination()); } + private PlexusIoFileResource getPomResource() throws IOException { + final File file = new File("pom.xml"); + PlexusIoResourceAttributes attrs = FileAttributes.uncached(file); - private PlexusIoFileResource getPomResource() - throws IOException - { - final File file = new File( "pom.xml" ); - PlexusIoResourceAttributes attrs = FileAttributes.uncached( file ); - - return new PlexusIoFileResource( file, "pom.xml", attrs ){}; + return new PlexusIoFileResource(file, "pom.xml", attrs) {}; } - class Dummy extends PlexusIoFileResource - implements SymlinkDestinationSupplier - { - public Dummy( @Nonnull File file, @Nonnull PlexusIoResourceAttributes attrs ) - throws IOException - { - super( file, file.getName(), attrs ); + class Dummy extends PlexusIoFileResource implements SymlinkDestinationSupplier { + public Dummy(@Nonnull File file, @Nonnull PlexusIoResourceAttributes attrs) throws IOException { + super(file, file.getName(), attrs); } - public String getSymlinkDestination() - throws IOException - { - throw new IllegalStateException( "Unsupported" ); + public String getSymlinkDestination() throws IOException { + throw new IllegalStateException("Unsupported"); } } - private Dummy getDummySymlinkResource() - throws IOException - { - final File file = new File( "pom.xml" ); - PlexusIoResourceAttributes attrs = FileAttributes.uncached( file ); - return new Dummy( file, attrs ); - } + private Dummy getDummySymlinkResource() throws IOException { + final File file = new File("pom.xml"); + PlexusIoResourceAttributes attrs = FileAttributes.uncached(file); -} \ No newline at end of file + return new Dummy(file, attrs); + } +} From 9f214f5972a461870c738b5ecb2f8aeec168eb0f Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 22 May 2023 21:56:44 +0000 Subject: [PATCH 33/86] Bump plexus-utils from 3.5.1 to 4.0.0 Bumps [plexus-utils](https://github.com/codehaus-plexus/plexus-utils) from 3.5.1 to 4.0.0. - [Release notes](https://github.com/codehaus-plexus/plexus-utils/releases) - [Commits](https://github.com/codehaus-plexus/plexus-utils/compare/plexus-utils-3.5.1...plexus-utils-4.0.0) --- updated-dependencies: - dependency-name: org.codehaus.plexus:plexus-utils dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index b0762fe8..9520fef5 100644 --- a/pom.xml +++ b/pom.xml @@ -49,7 +49,7 @@ org.codehaus.plexus plexus-utils - 3.5.1 + 4.0.0 com.google.code.findbugs From 97375f7243f53bd5c3a49d9533357427a4caa581 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 16 May 2023 21:56:41 +0000 Subject: [PATCH 34/86] Bump commons-io from 2.11.0 to 2.12.0 Bumps commons-io from 2.11.0 to 2.12.0. --- updated-dependencies: - dependency-name: commons-io:commons-io dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 9520fef5..af40c049 100644 --- a/pom.xml +++ b/pom.xml @@ -60,7 +60,7 @@ commons-io commons-io - 2.11.0 + 2.12.0 From 95faf92261c28f002c778849dfce93717a83434b Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 16 May 2023 21:56:38 +0000 Subject: [PATCH 35/86] Bump guice from 5.1.0 to 6.0.0 Bumps [guice](https://github.com/google/guice) from 5.1.0 to 6.0.0. - [Release notes](https://github.com/google/guice/releases) - [Commits](https://github.com/google/guice/compare/5.1.0...6.0.0) --- updated-dependencies: - dependency-name: com.google.inject:guice dependency-type: direct:development update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index af40c049..c0e74264 100644 --- a/pom.xml +++ b/pom.xml @@ -98,7 +98,7 @@ com.google.inject guice - 5.1.0 + 6.0.0 test From 7160c37a2eef32bbbfd94fa92f1854832fb7e8cd Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 7 Jun 2023 21:56:38 +0000 Subject: [PATCH 36/86] Bump commons-io from 2.12.0 to 2.13.0 Bumps commons-io from 2.12.0 to 2.13.0. --- updated-dependencies: - dependency-name: commons-io:commons-io dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index c0e74264..de469157 100644 --- a/pom.xml +++ b/pom.xml @@ -60,7 +60,7 @@ commons-io commons-io - 2.12.0 + 2.13.0 From 792f13c39d6776821b076725f4e5b44b3142e09d Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 25 Jul 2023 21:46:28 +0000 Subject: [PATCH 37/86] Bump org.codehaus.plexus:plexus from 13 to 14 Bumps [org.codehaus.plexus:plexus](https://github.com/codehaus-plexus/plexus-pom) from 13 to 14. - [Release notes](https://github.com/codehaus-plexus/plexus-pom/releases) - [Commits](https://github.com/codehaus-plexus/plexus-pom/commits) --- updated-dependencies: - dependency-name: org.codehaus.plexus:plexus dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index de469157..8304ac94 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ org.codehaus.plexus plexus - 13 + 14 plexus-io From f569e0aff96e038c9f54df241cb045a074831958 Mon Sep 17 00:00:00 2001 From: Sylwester Lachiewicz Date: Thu, 3 Aug 2023 13:37:03 +0200 Subject: [PATCH 38/86] Remove redundant stuff --- pom.xml | 65 --------------------------------------------------------- 1 file changed, 65 deletions(-) diff --git a/pom.xml b/pom.xml index 8304ac94..ef4e14d4 100644 --- a/pom.xml +++ b/pom.xml @@ -31,10 +31,8 @@ - 8 0.3.5 1.7.36 - true 2023-02-28T16:42:48Z @@ -108,16 +106,6 @@ org.eclipse.sisu sisu-maven-plugin - ${sisuVersion} - - - index-project - - main-index - test-index - - - org.apache.maven.plugins @@ -137,59 +125,6 @@ - - org.apache.maven.plugins - maven-surefire-plugin - - never - - - - org.apache.maven.plugins - maven-enforcer-plugin - - - enforce-java - - enforce - - validate - - - - 1.7.0 - - - - - - - - org.codehaus.mojo - animal-sniffer-maven-plugin - 1.23 - - - org.codehaus.mojo.signature - java18 - 1.0 - - - - - sniff - - check - - test - - - - - org.apache.maven.plugins - maven-resources-plugin - 3.3.1 - From d4ff1686d7dc32703bf659b2a0a795e64abfb4ea Mon Sep 17 00:00:00 2001 From: Sylwester Lachiewicz Date: Thu, 21 Sep 2023 21:02:26 +0200 Subject: [PATCH 39/86] JUnit4 to 5 migration --- pom.xml | 29 +++++----- .../AbstractResourceAttributesTCK.java | 16 +++--- .../io/attributes/AttributeUtilsTest.java | 20 ++++--- .../io/attributes/FileAttributesTest.java | 6 +- .../PlexusIoResourceAttributeUtilsTest.java | 55 +++++++------------ .../io/attributes/SymlinkUtilsTest.java | 14 ++--- .../io/filemappers/FileMapperTest.java | 55 ++++++++++++------- .../io/filemappers/FileSelectorTest.java | 34 +++++++----- .../io/filemappers/ResourcesTest.java | 55 ++++++++++--------- ...bstractPlexusIoResourceCollectionTest.java | 6 +- ...sIoFileSupplierResourceCollectionTest.java | 6 +- .../PlexusIoPlexusIoFileResourceTest.java | 12 ++-- .../PlexusIoProxyResourceCollectionTest.java | 14 ++--- .../io/resources/proxy/ProxyFactoryTest.java | 45 +++++---------- 14 files changed, 178 insertions(+), 189 deletions(-) diff --git a/pom.xml b/pom.xml index ef4e14d4..eb28168d 100644 --- a/pom.xml +++ b/pom.xml @@ -49,6 +49,12 @@ plexus-utils 4.0.0 + + org.codehaus.plexus + plexus-xml + 3.0.0 + test + com.google.code.findbugs jsr305 @@ -63,21 +69,8 @@ - junit - junit - 4.13.2 - test - - - org.hamcrest - hamcrest-core - - - - - org.hamcrest - hamcrest - 2.2 + org.junit.jupiter + junit-jupiter test @@ -86,6 +79,12 @@ ${slf4jVersion} test + + org.codehaus.plexus + plexus-testing + 1.1.0 + test + org.eclipse.sisu diff --git a/src/test/java/org/codehaus/plexus/components/io/attributes/AbstractResourceAttributesTCK.java b/src/test/java/org/codehaus/plexus/components/io/attributes/AbstractResourceAttributesTCK.java index b8755958..50daec39 100644 --- a/src/test/java/org/codehaus/plexus/components/io/attributes/AbstractResourceAttributesTCK.java +++ b/src/test/java/org/codehaus/plexus/components/io/attributes/AbstractResourceAttributesTCK.java @@ -16,9 +16,9 @@ * limitations under the License. */ -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; public abstract class AbstractResourceAttributesTCK { @@ -29,7 +29,7 @@ protected AbstractResourceAttributesTCK() {} protected abstract PlexusIoResourceAttributes newAttributes(String mode); @Test - public final void testSetOctalModeString_OwnerModes() { + final void testSetOctalModeString_OwnerModes() { verifyStringOctalModeSet("700", new boolean[] {true, true, true, false, false, false, false, false, false}); verifyStringOctalModeSet("600", new boolean[] {true, true, false, false, false, false, false, false, false}); verifyStringOctalModeSet("400", new boolean[] {true, false, false, false, false, false, false, false, false}); @@ -37,7 +37,7 @@ public final void testSetOctalModeString_OwnerModes() { } @Test - public final void testSetOctalModeString_GroupModes() { + final void testSetOctalModeString_GroupModes() { verifyStringOctalModeSet("070", new boolean[] {false, false, false, true, true, true, false, false, false}); verifyStringOctalModeSet("060", new boolean[] {false, false, false, true, true, false, false, false, false}); verifyStringOctalModeSet("040", new boolean[] {false, false, false, true, false, false, false, false, false}); @@ -45,7 +45,7 @@ public final void testSetOctalModeString_GroupModes() { } @Test - public final void testSetOctalModeString_WorldModes() { + final void testSetOctalModeString_WorldModes() { verifyStringOctalModeSet("007", new boolean[] {false, false, false, false, false, false, true, true, true}); verifyStringOctalModeSet("006", new boolean[] {false, false, false, false, false, false, true, true, false}); verifyStringOctalModeSet("004", new boolean[] {false, false, false, false, false, false, true, false, false}); @@ -53,7 +53,7 @@ public final void testSetOctalModeString_WorldModes() { } @Test - public final void testSetOctalMode_OwnerModes() { + final void testSetOctalMode_OwnerModes() { verifyOctalModeSet("700", new boolean[] {true, true, true, false, false, false, false, false, false}); verifyOctalModeSet("600", new boolean[] {true, true, false, false, false, false, false, false, false}); verifyOctalModeSet("400", new boolean[] {true, false, false, false, false, false, false, false, false}); @@ -61,7 +61,7 @@ public final void testSetOctalMode_OwnerModes() { } @Test - public final void testSetOctalMode_GroupModes() { + final void testSetOctalMode_GroupModes() { verifyOctalModeSet("070", new boolean[] {false, false, false, true, true, true, false, false, false}); verifyOctalModeSet("060", new boolean[] {false, false, false, true, true, false, false, false, false}); verifyOctalModeSet("040", new boolean[] {false, false, false, true, false, false, false, false, false}); @@ -69,7 +69,7 @@ public final void testSetOctalMode_GroupModes() { } @Test - public final void testSetOctalMode_WorldModes() { + final void testSetOctalMode_WorldModes() { verifyOctalModeSet("007", new boolean[] {false, false, false, false, false, false, true, true, true}); verifyOctalModeSet("006", new boolean[] {false, false, false, false, false, false, true, true, false}); verifyOctalModeSet("004", new boolean[] {false, false, false, false, false, false, true, false, false}); diff --git a/src/test/java/org/codehaus/plexus/components/io/attributes/AttributeUtilsTest.java b/src/test/java/org/codehaus/plexus/components/io/attributes/AttributeUtilsTest.java index 74f3ce54..38f1d019 100644 --- a/src/test/java/org/codehaus/plexus/components/io/attributes/AttributeUtilsTest.java +++ b/src/test/java/org/codehaus/plexus/components/io/attributes/AttributeUtilsTest.java @@ -6,17 +6,19 @@ import java.util.Set; import org.codehaus.plexus.util.Os; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * @author Kristian Rosenvold */ +@SuppressWarnings("OctalInteger") public class AttributeUtilsTest { @Test - public void testMiscPatterns() throws Exception { + void testMiscPatterns() { final Set permissions = AttributeUtils.getPermissions(0124); assertTrue(permissions.contains(PosixFilePermission.OWNER_EXECUTE)); assertTrue(permissions.contains(PosixFilePermission.GROUP_WRITE)); @@ -24,7 +26,7 @@ public void testMiscPatterns() throws Exception { } @Test - public void testMorePatterns() throws Exception { + void testMorePatterns() { final Set permissions = AttributeUtils.getPermissions(0241); assertTrue(permissions.contains(PosixFilePermission.OWNER_WRITE)); assertTrue(permissions.contains(PosixFilePermission.GROUP_READ)); @@ -32,7 +34,7 @@ public void testMorePatterns() throws Exception { } @Test - public void testEvenMorePatterns() throws Exception { + void testEvenMorePatterns() throws Exception { final Set permissions = AttributeUtils.getPermissions(0412); assertTrue(permissions.contains(PosixFilePermission.OWNER_READ)); assertTrue(permissions.contains(PosixFilePermission.GROUP_EXECUTE)); @@ -40,13 +42,13 @@ public void testEvenMorePatterns() throws Exception { } @Test - public void test777() throws Exception { + void test777() throws Exception { final Set permissions = AttributeUtils.getPermissions(0777); - assertTrue(permissions.size() == 9); + assertEquals(9, permissions.size()); } @Test - public void testChmodBackAndForth() throws IOException { + void testChmodBackAndForth() throws IOException { if (Os.isFamily(Os.FAMILY_WINDOWS)) return; final File bxx = File.createTempFile("bxx", "ff"); AttributeUtils.chmod(bxx, 0422); diff --git a/src/test/java/org/codehaus/plexus/components/io/attributes/FileAttributesTest.java b/src/test/java/org/codehaus/plexus/components/io/attributes/FileAttributesTest.java index db2dc0d6..0e3025c3 100644 --- a/src/test/java/org/codehaus/plexus/components/io/attributes/FileAttributesTest.java +++ b/src/test/java/org/codehaus/plexus/components/io/attributes/FileAttributesTest.java @@ -19,16 +19,16 @@ import java.io.File; import org.codehaus.plexus.util.Os; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNotNull; /** * @author Kristian Rosenvold */ public class FileAttributesTest { @Test - public void testGetPosixFileAttributes() throws Exception { + void testGetPosixFileAttributes() throws Exception { if (Os.isFamily(Os.FAMILY_WINDOWS)) { return; diff --git a/src/test/java/org/codehaus/plexus/components/io/attributes/PlexusIoResourceAttributeUtilsTest.java b/src/test/java/org/codehaus/plexus/components/io/attributes/PlexusIoResourceAttributeUtilsTest.java index 92af5c78..fe887701 100644 --- a/src/test/java/org/codehaus/plexus/components/io/attributes/PlexusIoResourceAttributeUtilsTest.java +++ b/src/test/java/org/codehaus/plexus/components/io/attributes/PlexusIoResourceAttributeUtilsTest.java @@ -19,6 +19,7 @@ import java.io.File; import java.io.IOException; import java.net.URL; +import java.nio.file.NoSuchFileException; import java.util.Map; import org.codehaus.plexus.util.Os; @@ -26,21 +27,16 @@ import org.codehaus.plexus.util.cli.CommandLineException; import org.codehaus.plexus.util.cli.CommandLineUtils; import org.codehaus.plexus.util.cli.Commandline; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.codehaus.plexus.components.io.attributes.PlexusIoResourceAttributeUtils.getFileAttributes; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.*; +@SuppressWarnings("OctalInteger") public class PlexusIoResourceAttributeUtilsTest { @Test - public void testGetAttributesForThisTestClass() throws IOException { + void testGetAttributesForThisTestClass() throws IOException { if (Os.isFamily(Os.FAMILY_WINDOWS)) { System.out.println("WARNING: Unsupported OS, skipping test"); return; @@ -68,7 +64,7 @@ public void testGetAttributesForThisTestClass() throws IOException { } @Test - public void testDirectory() throws IOException, CommandLineException { + void testDirectory() throws IOException, CommandLineException { if (Os.isFamily(Os.FAMILY_WINDOWS)) { return; // Nothing to do here. @@ -110,7 +106,7 @@ public void testDirectory() throws IOException, CommandLineException { } @Test - public void testSrcResource() throws IOException { + void testSrcResource() throws IOException { if (Os.isFamily(Os.FAMILY_WINDOWS)) { return; // Nothing to do here. } @@ -129,18 +125,15 @@ public void testSrcResource() throws IOException { } @Test - public void testNonExistingDirectory() { - File dir = new File("src/test/noSuchDirectory"); - try { + void testNonExistingDirectory() { + assertThrows(NoSuchFileException.class, () -> { + File dir = new File("src/test/noSuchDirectory"); PlexusIoResourceAttributeUtils.getFileAttributesByPath(dir, true); - fail("We were supposed to get an io exceptions"); - } catch (IOException ignore) { - ignore.printStackTrace(); - } + }); } @Test - public void testMergeAttributesWithNullBase() { + void testMergeAttributesWithNullBase() { PlexusIoResourceAttributes override = new SimpleResourceAttributes(1001, "myUser", 1001, "test", 0); PlexusIoResourceAttributes defaults = new SimpleResourceAttributes(1000, "defaultUser", 1000, "defaultTest", 0); @@ -152,7 +145,7 @@ public void testMergeAttributesWithNullBase() { } @Test - public void testMergeAttributesWithNullOverrideGroup() { + void testMergeAttributesWithNullOverrideGroup() { final PlexusIoResourceAttributes override = new SimpleResourceAttributes(1001, "myUser", -1, null, 0); final PlexusIoResourceAttributes defaults = new SimpleResourceAttributes(1000, "defaultUser", 1000, "defaultGroup", 0); @@ -165,7 +158,7 @@ public void testMergeAttributesWithNullOverrideGroup() { } @Test - public void testMergeAttributesOverride() { + void testMergeAttributesOverride() { final PlexusIoResourceAttributes blank = new SimpleResourceAttributes(); final PlexusIoResourceAttributes invalid = new SimpleResourceAttributes(-1, null, -1, null, -1); final PlexusIoResourceAttributes override = @@ -174,23 +167,17 @@ public void testMergeAttributesOverride() { new SimpleResourceAttributes(3333, "defaultUser", 4444, "defaultGroup", 0444); final PlexusIoResourceAttributes base = new SimpleResourceAttributes(5555, "baseUser", 6666, "baseGroup", 0111); - PlexusIoResourceAttributes attributes; - // When override is null, base is returned verbatim - attributes = PlexusIoResourceAttributeUtils.mergeAttributes(null, null, null); - assertNull(attributes); + assertNull(PlexusIoResourceAttributeUtils.mergeAttributes(null, null, null)); - attributes = PlexusIoResourceAttributeUtils.mergeAttributes(null, null, defaults); - assertNull(attributes); + assertNull(PlexusIoResourceAttributeUtils.mergeAttributes(null, null, defaults)); - attributes = PlexusIoResourceAttributeUtils.mergeAttributes(null, base, null); - assertSame(base, attributes); + assertSame(base, PlexusIoResourceAttributeUtils.mergeAttributes(null, base, null)); - attributes = PlexusIoResourceAttributeUtils.mergeAttributes(null, base, defaults); - assertSame(base, attributes); + assertSame(base, PlexusIoResourceAttributeUtils.mergeAttributes(null, base, defaults)); // Test cases when override is non-null - attributes = PlexusIoResourceAttributeUtils.mergeAttributes(override, null, null); + PlexusIoResourceAttributes attributes = PlexusIoResourceAttributeUtils.mergeAttributes(override, null, null); assertEquals(Integer.valueOf(1111), attributes.getUserId()); assertEquals("testUser", attributes.getUserName()); @@ -273,7 +260,7 @@ public void testMergeAttributesOverride() { } @Test - public void testFileAttributes() throws IOException { + void testFileAttributes() throws IOException { PlexusIoResourceAttributes attrs = getFileAttributes(new File("src/test/resources/symlinks/src/fileW.txt")); assertFalse(attrs.isSymbolicLink()); assertTrue(StringUtils.isNotEmpty(attrs.getUserName())); @@ -285,7 +272,7 @@ public void testFileAttributes() throws IOException { } @Test - public void testMergeAttributesDefault() { + void testMergeAttributesDefault() { final PlexusIoResourceAttributes blank = new SimpleResourceAttributes(null, null, null, null, 0); final PlexusIoResourceAttributes invalid = new SimpleResourceAttributes(-1, null, -1, null, -1); final PlexusIoResourceAttributes defaults = diff --git a/src/test/java/org/codehaus/plexus/components/io/attributes/SymlinkUtilsTest.java b/src/test/java/org/codehaus/plexus/components/io/attributes/SymlinkUtilsTest.java index 7d250f35..b3f97aa6 100644 --- a/src/test/java/org/codehaus/plexus/components/io/attributes/SymlinkUtilsTest.java +++ b/src/test/java/org/codehaus/plexus/components/io/attributes/SymlinkUtilsTest.java @@ -21,27 +21,27 @@ import java.nio.file.Files; import org.apache.commons.io.FileUtils; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.*; +import static org.junit.jupiter.api.Assertions.*; public class SymlinkUtilsTest { File target = new File("target/symlinkCapabilities"); String expected = "This is a filed that we'll be symlinking to\n"; - @Before + @BeforeEach public void setup() throws IOException { FileUtils.deleteDirectory(target); Files.createDirectories(target.toPath()); } @Test - public void testName() throws Exception {} + void testName() throws Exception {} @Test - public void create_read_symbolic_link_to_file() throws Exception { + void create_read_symbolic_link_to_file() throws Exception { File symlink = new File(target, "symlinkToTarget"); File relativePath = createTargetFile(target); SymlinkUtils.createSymbolicLink(symlink, relativePath); @@ -50,7 +50,7 @@ public void create_read_symbolic_link_to_file() throws Exception { } @Test - public void create_read_symbolic_link_to_directory() throws Exception { + void create_read_symbolic_link_to_directory() throws Exception { File subDir = new File(target, "aSubDir"); createTargetFile(subDir); File symlink = new File(target, "symlinkToDir"); diff --git a/src/test/java/org/codehaus/plexus/components/io/filemappers/FileMapperTest.java b/src/test/java/org/codehaus/plexus/components/io/filemappers/FileMapperTest.java index 9471d324..fbd7d948 100644 --- a/src/test/java/org/codehaus/plexus/components/io/filemappers/FileMapperTest.java +++ b/src/test/java/org/codehaus/plexus/components/io/filemappers/FileMapperTest.java @@ -16,17 +16,25 @@ * limitations under the License. */ +import javax.inject.Inject; + import java.lang.reflect.UndeclaredThrowableException; import java.util.Arrays; -import org.junit.Test; +import org.codehaus.plexus.PlexusContainer; +import org.codehaus.plexus.testing.PlexusTest; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.fail; /** * Test case for the various file mappers. */ -public class FileMapperTest extends TestSupport { +@PlexusTest +public class FileMapperTest { + @Inject + PlexusContainer container; + protected void testFileMapper(FileMapper pMapper, String[] pInput, String[] pOutput) { for (int i = 0; i < pInput.length; i++) { final String input = pInput[i]; @@ -77,7 +85,7 @@ protected void testFileMapper(FileMapper pMapper, String[] pInput, String[] pOut }; @Test - public void testIdentityMapper() throws Exception { + void testIdentityMapper() throws Exception { final String[] results = getIdentityResults(); testFileMapper(new IdentityMapper(), SAMPLES, results); } @@ -90,15 +98,15 @@ private String[] getIdentityResults() { } @Test - public void testDefaultMapper() throws Exception { + void testDefaultMapper() throws Exception { final String[] results = getIdentityResults(); - testFileMapper((FileMapper) lookup(FileMapper.class), SAMPLES, results); - testFileMapper((FileMapper) lookup(FileMapper.class, IdentityMapper.ROLE_HINT), SAMPLES, results); - testFileMapper((FileMapper) lookup(FileMapper.class), SAMPLES, results); + testFileMapper(container.lookup(FileMapper.class), SAMPLES, results); + testFileMapper(container.lookup(FileMapper.class, IdentityMapper.ROLE_HINT), SAMPLES, results); + testFileMapper(container.lookup(FileMapper.class), SAMPLES, results); } @Test - public void testFileExtensionMapper() throws Exception { + void testFileExtensionMapper() throws Exception { final String[] results = getIdentityResults(); for (int i = 2; i <= 10; i += 2) { results[i] += ".png"; @@ -107,7 +115,8 @@ public void testFileExtensionMapper() throws Exception { results[i] = results[i].substring(0, results[i].length() - ".gif".length()) + ".png"; } testFileExtensionMapper(results, new FileExtensionMapper()); - testFileExtensionMapper(results, (FileExtensionMapper) lookup(FileMapper.class, FileExtensionMapper.ROLE_HINT)); + testFileExtensionMapper( + results, (FileExtensionMapper) container.lookup(FileMapper.class, FileExtensionMapper.ROLE_HINT)); } private void testFileExtensionMapper(final String[] results, final FileExtensionMapper mapper) { @@ -118,12 +127,12 @@ private void testFileExtensionMapper(final String[] results, final FileExtension } @Test - public void testFlattenMapper() throws Exception { + void testFlattenMapper() throws Exception { final String[] results = getIdentityResults(); results[4] = results[6] = results[8] = results[10] = results[2]; results[5] = results[7] = results[9] = results[11] = results[3]; testFileMapper(new FlattenFileMapper(), SAMPLES, results); - testFileMapper((FileMapper) lookup(FileMapper.class, FlattenFileMapper.ROLE_HINT), SAMPLES, results); + testFileMapper(container.lookup(FileMapper.class, FlattenFileMapper.ROLE_HINT), SAMPLES, results); } private void testMergeMapper(String pTargetName, String[] pResults, MergeFileMapper pMapper) { @@ -132,22 +141,23 @@ private void testMergeMapper(String pTargetName, String[] pResults, MergeFileMap } @Test - public void testMergeMapper() throws Exception { + void testMergeMapper() throws Exception { final String[] results = getIdentityResults(); final String targetName = "zgh"; for (int i = 2; i < results.length; i++) { results[i] = targetName; } testMergeMapper(targetName, results, new MergeFileMapper()); - testMergeMapper(targetName, results, (MergeFileMapper) lookup(FileMapper.class, MergeFileMapper.ROLE_HINT)); + testMergeMapper( + targetName, results, (MergeFileMapper) container.lookup(FileMapper.class, MergeFileMapper.ROLE_HINT)); } @Test - public void testPrefixMapper() throws Exception { + void testPrefixMapper() throws Exception { final String prefix = "x7Rtf"; final String[] results = getIdentityResults(); testFileMapper(new PrefixFileMapper(), SAMPLES, results); - testFileMapper((PrefixFileMapper) lookup(FileMapper.class, PrefixFileMapper.ROLE_HINT), SAMPLES, results); + testFileMapper(container.lookup(FileMapper.class, PrefixFileMapper.ROLE_HINT), SAMPLES, results); for (int i = 0; i < results.length; i++) { if (results[i] != null) { results[i] = prefix + results[i]; @@ -156,13 +166,13 @@ public void testPrefixMapper() throws Exception { PrefixFileMapper mapper = new PrefixFileMapper(); mapper.setPrefix(prefix); testFileMapper(mapper, SAMPLES, results); - mapper = (PrefixFileMapper) lookup(FileMapper.class, PrefixFileMapper.ROLE_HINT); + mapper = (PrefixFileMapper) container.lookup(FileMapper.class, PrefixFileMapper.ROLE_HINT); mapper.setPrefix(prefix); testFileMapper(mapper, SAMPLES, results); } @Test - public void testSuffixMapper() throws Exception { + void testSuffixMapper() throws Exception { final String suffix = "suffix"; String[] samples = Arrays.copyOf(SAMPLES, SAMPLES.length + 2); samples[samples.length - 2] = "archive.tar.gz"; @@ -186,7 +196,7 @@ public void testSuffixMapper() throws Exception { SuffixFileMapper mapper = new SuffixFileMapper(); mapper.setSuffix(suffix); testFileMapper(mapper, samples, results); - mapper = (SuffixFileMapper) lookup(FileMapper.class, SuffixFileMapper.ROLE_HINT); + mapper = (SuffixFileMapper) container.lookup(FileMapper.class, SuffixFileMapper.ROLE_HINT); mapper.setSuffix(suffix); testFileMapper(mapper, samples, results); } @@ -198,7 +208,7 @@ private RegExpFileMapper configure(RegExpFileMapper pMapper, String pPattern, St } @Test - public void testRegExpFileMapper() throws Exception { + void testRegExpFileMapper() throws Exception { final String[] results = getIdentityResults(); results[3] = "xyz.jpg"; results[5] = "b/xyz.jpg"; @@ -208,7 +218,10 @@ public void testRegExpFileMapper() throws Exception { testFileMapper(configure(new RegExpFileMapper(), "\\.gif$", ".jpg"), SAMPLES, results); testFileMapper(configure(new RegExpFileMapper(), "^(.*)\\.gif$", "$1.jpg"), SAMPLES, results); testFileMapper( - configure((RegExpFileMapper) lookup(FileMapper.class, RegExpFileMapper.ROLE_HINT), "\\.gif$", ".jpg"), + configure( + (RegExpFileMapper) container.lookup(FileMapper.class, RegExpFileMapper.ROLE_HINT), + "\\.gif$", + ".jpg"), SAMPLES, results); final RegExpFileMapper mapper = configure(new RegExpFileMapper(), "c", "f"); diff --git a/src/test/java/org/codehaus/plexus/components/io/filemappers/FileSelectorTest.java b/src/test/java/org/codehaus/plexus/components/io/filemappers/FileSelectorTest.java index f867658f..c32b03c8 100644 --- a/src/test/java/org/codehaus/plexus/components/io/filemappers/FileSelectorTest.java +++ b/src/test/java/org/codehaus/plexus/components/io/filemappers/FileSelectorTest.java @@ -17,24 +17,33 @@ */ import javax.annotation.Nonnull; +import javax.inject.Inject; import java.io.IOException; import java.io.InputStream; import java.net.URL; +import java.util.Arrays; +import org.codehaus.plexus.PlexusContainer; import org.codehaus.plexus.components.io.fileselectors.AllFilesFileSelector; import org.codehaus.plexus.components.io.fileselectors.FileSelector; import org.codehaus.plexus.components.io.fileselectors.IncludeExcludeFileSelector; import org.codehaus.plexus.components.io.resources.AbstractPlexusIoResource; -import org.junit.Test; +import org.codehaus.plexus.testing.PlexusTest; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.fail; /** * Test case for implementations of {@link FileSelector}. */ -public class FileSelectorTest extends TestSupport { +@PlexusTest +public class FileSelectorTest { + + @Inject + PlexusContainer container; + protected void testFileSelector(FileSelector pSelector, String[] pInput, boolean[] pOutput) throws IOException { for (int i = 0; i < pInput.length; i++) { final String name = pInput[i]; @@ -66,17 +75,15 @@ protected void testFileSelector(AllFilesFileSelector pSelector) throws Exception private boolean[] getAllTrues() { final boolean[] trues = new boolean[SAMPLES.length]; - for (int i = 0; i < trues.length; i++) { - trues[i] = true; - } + Arrays.fill(trues, true); return trues; } @Test - public void testAllFilesFileSelector() throws Exception { + void testAllFilesFileSelector() throws Exception { testFileSelector(new AllFilesFileSelector()); - testFileSelector((AllFilesFileSelector) lookup(FileSelector.class)); - testFileSelector((AllFilesFileSelector) lookup(FileSelector.class, AllFilesFileSelector.ROLE_HINT)); + testFileSelector((AllFilesFileSelector) container.lookup(FileSelector.class)); + testFileSelector((AllFilesFileSelector) container.lookup(FileSelector.class, AllFilesFileSelector.ROLE_HINT)); } protected boolean[] getIncludeGifs(String[] pSamples) { @@ -107,13 +114,14 @@ protected void testFileSelector(IncludeExcludeFileSelector pSelector) throws Exc } @Test - public void testIncludeExcludeFileSelector() throws Exception { + void testIncludeExcludeFileSelector() throws Exception { testFileSelector(new IncludeExcludeFileSelector()); - testFileSelector((IncludeExcludeFileSelector) lookup(FileSelector.class, IncludeExcludeFileSelector.ROLE_HINT)); + testFileSelector((IncludeExcludeFileSelector) + container.lookup(FileSelector.class, IncludeExcludeFileSelector.ROLE_HINT)); } @Test - public void testIncludeExcludeFileSelector_SetExcludes() throws Exception { + void testIncludeExcludeFileSelector_SetExcludes() throws Exception { IncludeExcludeFileSelector selector = new IncludeExcludeFileSelector(); // Test that the setExcludes method does not modify the excludes. diff --git a/src/test/java/org/codehaus/plexus/components/io/filemappers/ResourcesTest.java b/src/test/java/org/codehaus/plexus/components/io/filemappers/ResourcesTest.java index 66429a3e..540da593 100644 --- a/src/test/java/org/codehaus/plexus/components/io/filemappers/ResourcesTest.java +++ b/src/test/java/org/codehaus/plexus/components/io/filemappers/ResourcesTest.java @@ -16,6 +16,8 @@ * limitations under the License. */ +import javax.inject.Inject; + import java.io.Closeable; import java.io.File; import java.io.FileInputStream; @@ -23,27 +25,32 @@ import java.io.IOException; import java.io.InputStream; import java.net.URLConnection; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; import java.util.Iterator; import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; -import org.codehaus.plexus.components.io.resources.AbstractPlexusIoArchiveResourceCollection; +import org.codehaus.plexus.PlexusContainer; import org.codehaus.plexus.components.io.resources.PlexusIoFileResource; import org.codehaus.plexus.components.io.resources.PlexusIoFileResourceCollection; import org.codehaus.plexus.components.io.resources.PlexusIoResource; import org.codehaus.plexus.components.io.resources.PlexusIoResourceCollection; +import org.codehaus.plexus.testing.PlexusTest; import org.codehaus.plexus.util.FileUtils; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.*; /** * Test case for resource collections. */ -public class ResourcesTest extends TestSupport { +@PlexusTest +public class ResourcesTest { + + @Inject + PlexusContainer container; + private static final String X_PATH = "x"; private static final String A_PATH = X_PATH + "/a"; private static final String B_PATH = X_PATH + "/b"; @@ -65,11 +72,11 @@ private void createFiles() throws IOException { final File aFile = new File(baseDir, A_PATH); FileUtils.mkdir(aFile.getParentFile().getPath()); FileOutputStream fos = new FileOutputStream(aFile); - fos.write("0123456789".getBytes("US-ASCII")); + fos.write("0123456789".getBytes(StandardCharsets.US_ASCII)); fos.close(); final File bFile = new File(baseDir, B_PATH); fos = new FileOutputStream(bFile); - fos.write("abcdefghijklmnopqrstuvwxyz".getBytes("US-ASCII")); + fos.write("abcdefghijklmnopqrstuvwxyz".getBytes(StandardCharsets.US_ASCII)); fos.close(); final File yDir = new File(baseDir, Y_PATH); FileUtils.mkdir(yDir.getPath()); @@ -112,7 +119,7 @@ private void createZipFile(File dest, File dir) throws IOException { } private void compare(InputStream in, File file) throws IOException { - try (InputStream fIn = new FileInputStream(file)) { + try (InputStream fIn = Files.newInputStream(file.toPath())) { for (; ; ) { int i1 = in.read(); int i2 = fIn.read(); @@ -147,28 +154,28 @@ private void testPlexusIoResourceCollection(PlexusIoResourceCollection plexusIoR boolean yPathSeen = false; boolean aFileSeen = false; boolean bFileSeen = false; - Iterator iter = plexusIoResourceCollection.getResources(); + Iterator iter = plexusIoResourceCollection.getResources(); while (iter.hasNext()) { - PlexusIoResource res = (PlexusIoResource) iter.next(); + PlexusIoResource res = iter.next(); final String resName = res.getName().replace(File.separatorChar, '/'); if (res.isDirectory()) { - assertFalse("The directory " + resName + " is a file.", res.isFile()); + assertFalse(res.isFile(), "The directory " + resName + " is a file."); if (X_PATH.equals(resName)) { xPathSeen = true; } else if (Y_PATH.equals(resName)) { yPathSeen = true; - } else if ("".equals(resName) || ".".equals(resName)) { + } else if (resName.isEmpty() || ".".equals(resName)) { // Ignore me } else { fail("Unexpected directory entry: " + resName); } final File dir = new File(getFilesDir(), resName); - assertTrue("The directory " + dir + " doesn't exist.", dir.isDirectory()); + assertTrue(dir.isDirectory(), "The directory " + dir + " doesn't exist."); } else { - assertTrue("The file " + resName + " isn't reported to be a file.", res.isFile()); - assertTrue("The file " + resName + " doesn't exist.", res.isExisting()); + assertTrue(res.isFile(), "The file " + resName + " isn't reported to be a file."); + assertTrue(res.isExisting(), "The file " + resName + " doesn't exist."); final File f = new File(getFilesDir(), resName); - assertTrue("A file " + f + " doesn't exist.", f.isFile() && f.exists()); + assertTrue(f.isFile() && f.exists(), "A file " + f + " doesn't exist."); if (A_PATH.equals(resName)) { aFileSeen = true; } else if (B_PATH.equals(resName)) { @@ -193,16 +200,10 @@ private void testFileResourceCollection(PlexusIoFileResourceCollection resourceC } @Test - public void testFileCollection() throws Exception { + void testFileCollection() throws Exception { createFiles(); - testFileResourceCollection((PlexusIoFileResourceCollection) lookup(PlexusIoResourceCollection.class)); + testFileResourceCollection((PlexusIoFileResourceCollection) container.lookup(PlexusIoResourceCollection.class)); testFileResourceCollection((PlexusIoFileResourceCollection) - lookup(PlexusIoResourceCollection.class, PlexusIoFileResourceCollection.ROLE_HINT)); - } - - private void testZipFileCollection(AbstractPlexusIoArchiveResourceCollection resourceCollection, File zipFile) - throws IOException { - resourceCollection.setFile(zipFile); - testPlexusIoResourceCollection(resourceCollection); + container.lookup(PlexusIoResourceCollection.class, PlexusIoFileResourceCollection.ROLE_HINT)); } } diff --git a/src/test/java/org/codehaus/plexus/components/io/resources/AbstractPlexusIoResourceCollectionTest.java b/src/test/java/org/codehaus/plexus/components/io/resources/AbstractPlexusIoResourceCollectionTest.java index 635b5ced..21c3714c 100644 --- a/src/test/java/org/codehaus/plexus/components/io/resources/AbstractPlexusIoResourceCollectionTest.java +++ b/src/test/java/org/codehaus/plexus/components/io/resources/AbstractPlexusIoResourceCollectionTest.java @@ -10,9 +10,9 @@ import java.util.Iterator; import org.codehaus.plexus.components.io.functions.InputStreamTransformer; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; /** * @author Kristian Rosenvold @@ -20,7 +20,7 @@ public class AbstractPlexusIoResourceCollectionTest { @SuppressWarnings("ResultOfMethodCallIgnored") @Test - public void testGetIncludes() throws Exception { + void testGetIncludes() throws Exception { AbstractPlexusIoResourceCollection sut = new AbstractPlexusIoResourceCollection() { public Iterator getResources() throws IOException { return Arrays.asList(getResource("r1"), getResource("r2")).iterator(); diff --git a/src/test/java/org/codehaus/plexus/components/io/resources/PlexusIoFileSupplierResourceCollectionTest.java b/src/test/java/org/codehaus/plexus/components/io/resources/PlexusIoFileSupplierResourceCollectionTest.java index 418a3f04..dfcce726 100755 --- a/src/test/java/org/codehaus/plexus/components/io/resources/PlexusIoFileSupplierResourceCollectionTest.java +++ b/src/test/java/org/codehaus/plexus/components/io/resources/PlexusIoFileSupplierResourceCollectionTest.java @@ -3,16 +3,16 @@ import java.io.File; import java.util.Iterator; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * @author Kristian Rosenvold */ public class PlexusIoFileSupplierResourceCollectionTest { @Test - public void testGetName() throws Exception { + void testGetName() throws Exception { PlexusIoFileResourceCollection coll = new PlexusIoFileResourceCollection(); char nonSeparator = File.separatorChar == '/' ? '\\' : '/'; coll.setPrefix("fud" + nonSeparator); diff --git a/src/test/java/org/codehaus/plexus/components/io/resources/PlexusIoPlexusIoFileResourceTest.java b/src/test/java/org/codehaus/plexus/components/io/resources/PlexusIoPlexusIoFileResourceTest.java index 289087c4..a4733f9e 100644 --- a/src/test/java/org/codehaus/plexus/components/io/resources/PlexusIoPlexusIoFileResourceTest.java +++ b/src/test/java/org/codehaus/plexus/components/io/resources/PlexusIoPlexusIoFileResourceTest.java @@ -8,16 +8,14 @@ import org.codehaus.plexus.components.io.attributes.SymlinkUtils; import org.codehaus.plexus.components.io.functions.SymlinkDestinationSupplier; import org.codehaus.plexus.util.Os; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.*; public class PlexusIoPlexusIoFileResourceTest { @Test - public void testRealSymlink() throws IOException { + void testRealSymlink() throws IOException { if (Os.isFamily(Os.FAMILY_WINDOWS)) return; final File file = new File("src/test/resources/symlinks/src/symDir"); PlexusIoResourceAttributes attrs = FileAttributes.uncached(file); @@ -32,7 +30,7 @@ public void testRealSymlink() throws IOException { } @Test - public void testSymSymlinkFile() throws IOException { + void testSymSymlinkFile() throws IOException { if (Os.isFamily(Os.FAMILY_WINDOWS)) return; final File file = new File("src/test/resources/symlinks/src/symSymR"); PlexusIoResource r = ResourceFactory.createResource(file); @@ -47,7 +45,7 @@ public void testSymSymlinkFile() throws IOException { } @Test - public void testSymlinkFile() throws IOException { + void testSymlinkFile() throws IOException { if (Os.isFamily(Os.FAMILY_WINDOWS)) return; final File file = new File("src/test/resources/symlinks/src/symR"); PlexusIoResource r = ResourceFactory.createResource(file); diff --git a/src/test/java/org/codehaus/plexus/components/io/resources/proxy/PlexusIoProxyResourceCollectionTest.java b/src/test/java/org/codehaus/plexus/components/io/resources/proxy/PlexusIoProxyResourceCollectionTest.java index 87ba1e42..426ff908 100644 --- a/src/test/java/org/codehaus/plexus/components/io/resources/proxy/PlexusIoProxyResourceCollectionTest.java +++ b/src/test/java/org/codehaus/plexus/components/io/resources/proxy/PlexusIoProxyResourceCollectionTest.java @@ -28,10 +28,10 @@ import org.codehaus.plexus.components.io.resources.AbstractPlexusIoResourceCollection; import org.codehaus.plexus.components.io.resources.PlexusIoResource; import org.codehaus.plexus.components.io.resources.Stream; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; /** * Test case for {@link PlexusIoProxyResourceCollection}. @@ -42,7 +42,7 @@ public class PlexusIoProxyResourceCollectionTest { private final String[] SAMPLE_EXCLUDES = {"*.junk", "somwhere/**"}; @Test - public void testGetDefaultFileSelector() throws Exception { + void testGetDefaultFileSelector() throws Exception { PlexusIoProxyResourceCollection resCol = new PlexusIoProxyResourceCollection(null); // This will throw an exception if there is a bug @@ -55,12 +55,12 @@ public void testGetDefaultFileSelector() throws Exception { resCol.getDefaultFileSelector(); } - class CloseableIterator implements Iterator, Closeable { + static class CloseableIterator implements Iterator, Closeable { boolean next = true; boolean closed = false; - public void close() throws IOException { + public void close() { closed = true; } @@ -91,7 +91,7 @@ public void remove() { } @Test - public void testClosing() throws IOException { + void testClosing() throws IOException { final CloseableIterator closeableIterator = new CloseableIterator(); PlexusIoProxyResourceCollection resCol = new PlexusIoProxyResourceCollection(new AbstractPlexusIoResourceCollection() { diff --git a/src/test/java/org/codehaus/plexus/components/io/resources/proxy/ProxyFactoryTest.java b/src/test/java/org/codehaus/plexus/components/io/resources/proxy/ProxyFactoryTest.java index 78383324..158c3630 100644 --- a/src/test/java/org/codehaus/plexus/components/io/resources/proxy/ProxyFactoryTest.java +++ b/src/test/java/org/codehaus/plexus/components/io/resources/proxy/ProxyFactoryTest.java @@ -18,17 +18,14 @@ import org.codehaus.plexus.components.io.functions.SymlinkDestinationSupplier; import org.codehaus.plexus.components.io.resources.PlexusIoFileResource; import org.codehaus.plexus.components.io.resources.PlexusIoResource; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.*; public class ProxyFactoryTest { @Test - public void testCreateProxy() throws Exception { + void testCreateProxy() throws Exception { final PlexusIoResource proxy = ProxyFactory.createProxy(getPomResource(), null); assertTrue(proxy instanceof ResourceAttributeSupplier); assertTrue(proxy instanceof FileSupplier); @@ -36,42 +33,30 @@ public void testCreateProxy() throws Exception { } @Test - public void testCreateProxyWithNameOverride() throws Exception { - NameSupplier ns = new NameSupplier() { - public String getName() { - return "fred"; - } - }; + void testCreateProxyWithNameOverride() throws Exception { + NameSupplier ns = () -> "fred"; final PlexusIoResource proxy = ProxyFactory.createProxy(getPomResource(), ns); assertEquals("fred", proxy.getName()); } @Test - public void testCreateProxyWithResourceAttributeOverride() throws Exception { + void testCreateProxyWithResourceAttributeOverride() throws Exception { final PlexusIoResourceAttributes s = SimpleResourceAttributes.lastResortDummyAttributesForBrokenOS(); - ResourceAttributeSupplier ns = new ResourceAttributeSupplier() { - public PlexusIoResourceAttributes getAttributes() { - return s; - } - }; + ResourceAttributeSupplier ns = () -> s; final PlexusIoResource proxy = ProxyFactory.createProxy(getPomResource(), ns); assertSame(s, ((ResourceAttributeSupplier) proxy).getAttributes()); } @Test - public void testCreateProxyWithSizeSupplierOverride() throws Exception { + void testCreateProxyWithSizeSupplierOverride() throws Exception { final PlexusIoResourceAttributes s = SimpleResourceAttributes.lastResortDummyAttributesForBrokenOS(); - SizeSupplier ns = new SizeSupplier() { - public long getSize() { - return 42; - } - }; + SizeSupplier ns = () -> 42; final PlexusIoResource proxy = ProxyFactory.createProxy(getPomResource(), ns); assertEquals(42, proxy.getSize()); } @Test - public void testCreateProxyWithContentSupplierOverride() throws Exception { + void testCreateProxyWithContentSupplierOverride() throws Exception { final InputStream s = new ByteArrayInputStream(new byte[10]); ContentSupplier ns = new ContentSupplier() { public InputStream getContents() throws IOException { @@ -83,12 +68,8 @@ public InputStream getContents() throws IOException { } @Test - public void testCreateProxyWithSymlinkDestinationSupplierOverride() throws Exception { - SymlinkDestinationSupplier ns = new SymlinkDestinationSupplier() { - public String getSymlinkDestination() throws IOException { - return "mordor"; - } - }; + void testCreateProxyWithSymlinkDestinationSupplierOverride() throws Exception { + SymlinkDestinationSupplier ns = () -> "mordor"; final PlexusIoResource proxy = ProxyFactory.createProxy(getDummySymlinkResource(), ns); assertEquals("mordor", ((SymlinkDestinationSupplier) proxy).getSymlinkDestination()); } @@ -100,7 +81,7 @@ private PlexusIoFileResource getPomResource() throws IOException { return new PlexusIoFileResource(file, "pom.xml", attrs) {}; } - class Dummy extends PlexusIoFileResource implements SymlinkDestinationSupplier { + static class Dummy extends PlexusIoFileResource implements SymlinkDestinationSupplier { public Dummy(@Nonnull File file, @Nonnull PlexusIoResourceAttributes attrs) throws IOException { super(file, file.getName(), attrs); } From d3fbfc678da5532ba0a43ec8cca574d3a9d203e7 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 29 Sep 2023 21:30:14 +0000 Subject: [PATCH 40/86] Bump commons-io:commons-io from 2.13.0 to 2.14.0 Bumps commons-io:commons-io from 2.13.0 to 2.14.0. --- updated-dependencies: - dependency-name: commons-io:commons-io dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index eb28168d..a5cdc075 100644 --- a/pom.xml +++ b/pom.xml @@ -64,7 +64,7 @@ commons-io commons-io - 2.13.0 + 2.14.0 From f4f7aa1ace020dca91d881073ba75fa6b8c182d5 Mon Sep 17 00:00:00 2001 From: Sylwester Lachiewicz Date: Thu, 21 Sep 2023 23:02:39 +0200 Subject: [PATCH 41/86] Code cleanup --- .../io/attributes/AttributeConstants.java | 1 + .../io/attributes/AttributeUtils.java | 2 +- .../io/attributes/FileAttributes.java | 3 +- .../PlexusIoResourceAttributes.java | 3 -- .../io/attributes/SymlinkUtils.java | 5 ++- .../PlexusIoProxyResourceAttributes.java | 7 +--- .../io/filemappers/AbstractFileMapper.java | 2 +- .../io/filemappers/FileExtensionMapper.java | 2 +- .../io/filemappers/IdentityMapper.java | 2 +- .../io/filemappers/MergeFileMapper.java | 2 +- .../io/filemappers/PrefixFileMapper.java | 2 +- .../io/functions/InputStreamTransformer.java | 2 +- ...ractPlexusIoArchiveResourceCollection.java | 23 +++++------- .../AbstractPlexusIoResourceCollection.java | 5 ++- .../components/io/resources/Deferred.java | 7 +++- ...xusIoCompressedFileResourceCollection.java | 2 +- .../io/resources/PlexusIoFileResource.java | 12 +++---- .../io/resources/PlexusIoResource.java | 2 +- .../io/resources/PlexusIoSymlinkResource.java | 6 ---- .../PlexusIoProxyResourceCollection.java | 6 ++-- .../proxy/ResourceInvocationHandler.java | 2 +- .../io/attributes/AttributeUtilsTest.java | 9 ++--- .../io/attributes/FileAttributesTest.java | 10 ++---- .../PlexusIoResourceAttributeUtilsTest.java | 36 +++++++++---------- .../io/attributes/SymlinkUtilsTest.java | 14 ++++---- .../io/filemappers/FileSelectorTest.java | 6 ++-- ...bstractPlexusIoResourceCollectionTest.java | 6 ++-- .../PlexusIoPlexusIoFileResourceTest.java | 9 ++--- .../PlexusIoProxyResourceCollectionTest.java | 8 ++--- .../io/resources/proxy/ProxyFactoryTest.java | 8 ++--- 30 files changed, 89 insertions(+), 115 deletions(-) diff --git a/src/main/java/org/codehaus/plexus/components/io/attributes/AttributeConstants.java b/src/main/java/org/codehaus/plexus/components/io/attributes/AttributeConstants.java index 5ff5ba1a..fb87b569 100644 --- a/src/main/java/org/codehaus/plexus/components/io/attributes/AttributeConstants.java +++ b/src/main/java/org/codehaus/plexus/components/io/attributes/AttributeConstants.java @@ -16,6 +16,7 @@ * limitations under the License. */ +@SuppressWarnings("OctalInteger") public final class AttributeConstants { public static final int OCTAL_OWNER_READ = 0400; diff --git a/src/main/java/org/codehaus/plexus/components/io/attributes/AttributeUtils.java b/src/main/java/org/codehaus/plexus/components/io/attributes/AttributeUtils.java index 37462dc3..be00c0a5 100644 --- a/src/main/java/org/codehaus/plexus/components/io/attributes/AttributeUtils.java +++ b/src/main/java/org/codehaus/plexus/components/io/attributes/AttributeUtils.java @@ -33,6 +33,7 @@ /** * @author Kristian Rosenvold */ +@SuppressWarnings("OctalInteger") public class AttributeUtils { /* Reads last-modified with proper failure handling if something goes wrong. @@ -101,7 +102,6 @@ public static BasicFileAttributes getFileAttributes(@Nonnull File file) throws I public static BasicFileAttributes getFileAttributes(Path path) throws IOException { if (isUnix(path)) { - try { return Files.readAttributes(path, PosixFileAttributes.class, LinkOption.NOFOLLOW_LINKS); } catch (UnsupportedOperationException ignore) { diff --git a/src/main/java/org/codehaus/plexus/components/io/attributes/FileAttributes.java b/src/main/java/org/codehaus/plexus/components/io/attributes/FileAttributes.java index 20c8396c..94c0d3ce 100644 --- a/src/main/java/org/codehaus/plexus/components/io/attributes/FileAttributes.java +++ b/src/main/java/org/codehaus/plexus/components/io/attributes/FileAttributes.java @@ -112,9 +112,10 @@ public FileAttributes(@Nonnull File file, boolean followLinks) throws IOExceptio this.octalMode = attrs.containsKey("mode") ? (Integer) attrs.get("mode") & 0xfff : PlexusIoResourceAttributes.UNKNOWN_OCTAL_MODE; + //noinspection unchecked this.permissions = attrs.containsKey("permissions") ? (Set) attrs.get("permissions") - : Collections.emptySet(); + : Collections.emptySet(); this.size = (Long) attrs.get("size"); this.lastModifiedTime = (FileTime) attrs.get("lastModifiedTime"); } diff --git a/src/main/java/org/codehaus/plexus/components/io/attributes/PlexusIoResourceAttributes.java b/src/main/java/org/codehaus/plexus/components/io/attributes/PlexusIoResourceAttributes.java index 0b1dcb36..2aa0ef6a 100644 --- a/src/main/java/org/codehaus/plexus/components/io/attributes/PlexusIoResourceAttributes.java +++ b/src/main/java/org/codehaus/plexus/components/io/attributes/PlexusIoResourceAttributes.java @@ -72,9 +72,6 @@ public interface PlexusIoResourceAttributes { */ int getOctalMode(); - // @Nonnull - // String getOctalModeString(); - /** * Indicates if this is a symbolic link element. * For file-based resource attributes this value may be always "false" for versions prior to java7. diff --git a/src/main/java/org/codehaus/plexus/components/io/attributes/SymlinkUtils.java b/src/main/java/org/codehaus/plexus/components/io/attributes/SymlinkUtils.java index 00b6d4fe..6c6ea684 100644 --- a/src/main/java/org/codehaus/plexus/components/io/attributes/SymlinkUtils.java +++ b/src/main/java/org/codehaus/plexus/components/io/attributes/SymlinkUtils.java @@ -35,14 +35,13 @@ public class SymlinkUtils { * @throws java.io.IOException */ public static @Nonnull File readSymbolicLink(@Nonnull File symlink) throws IOException { - final java.nio.file.Path path = java.nio.file.Files.readSymbolicLink(symlink.toPath()); - return path.toFile(); + return Files.readSymbolicLink(symlink.toPath()).toFile(); } public static @Nonnull File createSymbolicLink(@Nonnull File symlink, File target) throws IOException { Path link = symlink.toPath(); if (!Files.exists(link, LinkOption.NOFOLLOW_LINKS)) { - link = java.nio.file.Files.createSymbolicLink(link, target.toPath()); + link = Files.createSymbolicLink(link, target.toPath()); } return link.toFile(); } diff --git a/src/main/java/org/codehaus/plexus/components/io/attributes/proxy/PlexusIoProxyResourceAttributes.java b/src/main/java/org/codehaus/plexus/components/io/attributes/proxy/PlexusIoProxyResourceAttributes.java index a751b36f..15194fe8 100644 --- a/src/main/java/org/codehaus/plexus/components/io/attributes/proxy/PlexusIoProxyResourceAttributes.java +++ b/src/main/java/org/codehaus/plexus/components/io/attributes/proxy/PlexusIoProxyResourceAttributes.java @@ -6,7 +6,7 @@ public class PlexusIoProxyResourceAttributes implements PlexusIoResourceAttributes { - PlexusIoResourceAttributes target; + final PlexusIoResourceAttributes target; public PlexusIoProxyResourceAttributes(PlexusIoResourceAttributes thisAttr) { this.target = thisAttr; @@ -45,11 +45,6 @@ public Integer getUserId() { return target.getUserId(); } - /* public String getOctalModeString() - { - return target.getOctalModeString(); - } - */ public boolean isOwnerWritable() { return target.isOwnerWritable(); } diff --git a/src/main/java/org/codehaus/plexus/components/io/filemappers/AbstractFileMapper.java b/src/main/java/org/codehaus/plexus/components/io/filemappers/AbstractFileMapper.java index a0540ad3..141244fd 100644 --- a/src/main/java/org/codehaus/plexus/components/io/filemappers/AbstractFileMapper.java +++ b/src/main/java/org/codehaus/plexus/components/io/filemappers/AbstractFileMapper.java @@ -29,7 +29,7 @@ public abstract class AbstractFileMapper implements FileMapper { * Checks the input and returns it without modifications. */ public @Nonnull String getMappedFileName(@Nonnull String pName) { - if (pName == null || pName.length() == 0) { + if (pName == null || pName.isEmpty()) { throw new IllegalArgumentException("The source name must not be null."); } return pName; diff --git a/src/main/java/org/codehaus/plexus/components/io/filemappers/FileExtensionMapper.java b/src/main/java/org/codehaus/plexus/components/io/filemappers/FileExtensionMapper.java index 14e0a4c9..53023386 100644 --- a/src/main/java/org/codehaus/plexus/components/io/filemappers/FileExtensionMapper.java +++ b/src/main/java/org/codehaus/plexus/components/io/filemappers/FileExtensionMapper.java @@ -42,7 +42,7 @@ public void setTargetExtension(String pTargetExtension) { if (pTargetExtension == null) { throw new IllegalArgumentException("The target extension is null."); } - if (pTargetExtension.length() == 0) { + if (pTargetExtension.isEmpty()) { throw new IllegalArgumentException("The target extension is empty."); } if (pTargetExtension.charAt(0) == '.') { diff --git a/src/main/java/org/codehaus/plexus/components/io/filemappers/IdentityMapper.java b/src/main/java/org/codehaus/plexus/components/io/filemappers/IdentityMapper.java index c45cbb37..789f7f3e 100644 --- a/src/main/java/org/codehaus/plexus/components/io/filemappers/IdentityMapper.java +++ b/src/main/java/org/codehaus/plexus/components/io/filemappers/IdentityMapper.java @@ -31,7 +31,7 @@ public class IdentityMapper extends AbstractFileMapper { @Nonnull public String getMappedFileName(@Nonnull String pName) { - if (pName == null || pName.length() == 0) { + if (pName == null || pName.isEmpty()) { throw new IllegalArgumentException("The source name must not be null."); } return pName; diff --git a/src/main/java/org/codehaus/plexus/components/io/filemappers/MergeFileMapper.java b/src/main/java/org/codehaus/plexus/components/io/filemappers/MergeFileMapper.java index 2a503af7..796a428b 100644 --- a/src/main/java/org/codehaus/plexus/components/io/filemappers/MergeFileMapper.java +++ b/src/main/java/org/codehaus/plexus/components/io/filemappers/MergeFileMapper.java @@ -41,7 +41,7 @@ public void setTargetName(String pName) { if (pName == null) { throw new IllegalArgumentException("The target name is null."); } - if (pName.length() == 0) { + if (pName.isEmpty()) { throw new IllegalArgumentException("The target name is empty."); } targetName = pName; diff --git a/src/main/java/org/codehaus/plexus/components/io/filemappers/PrefixFileMapper.java b/src/main/java/org/codehaus/plexus/components/io/filemappers/PrefixFileMapper.java index 1bb5ca22..d3be2d31 100644 --- a/src/main/java/org/codehaus/plexus/components/io/filemappers/PrefixFileMapper.java +++ b/src/main/java/org/codehaus/plexus/components/io/filemappers/PrefixFileMapper.java @@ -55,7 +55,7 @@ public void setPrefix(String prefix) { * Performs the mapping of a file name by adding a prefix. */ public static String getMappedFileName(String prefix, String name) { - if (prefix == null || prefix.length() == 0) { + if (prefix == null || prefix.isEmpty()) { return name; } return prefix + name; diff --git a/src/main/java/org/codehaus/plexus/components/io/functions/InputStreamTransformer.java b/src/main/java/org/codehaus/plexus/components/io/functions/InputStreamTransformer.java index a63ca7ff..5907e10b 100644 --- a/src/main/java/org/codehaus/plexus/components/io/functions/InputStreamTransformer.java +++ b/src/main/java/org/codehaus/plexus/components/io/functions/InputStreamTransformer.java @@ -29,7 +29,7 @@ public interface InputStreamTransformer { /** * Transform the supplied input stream into another input stream. - * + *

* The close method will be delegated through the entire call chain * * @param resource The p-io resource the stream is for diff --git a/src/main/java/org/codehaus/plexus/components/io/resources/AbstractPlexusIoArchiveResourceCollection.java b/src/main/java/org/codehaus/plexus/components/io/resources/AbstractPlexusIoArchiveResourceCollection.java index da2bef06..03d73cfa 100644 --- a/src/main/java/org/codehaus/plexus/components/io/resources/AbstractPlexusIoArchiveResourceCollection.java +++ b/src/main/java/org/codehaus/plexus/components/io/resources/AbstractPlexusIoArchiveResourceCollection.java @@ -21,8 +21,6 @@ import java.io.IOException; import java.util.Iterator; -import org.codehaus.plexus.components.io.functions.PlexusIoResourceConsumer; - /** * Default implementation of {@link PlexusIoFileResourceCollection} for * zip files, tar files, etc. @@ -106,20 +104,17 @@ public void close() throws IOException { } public Stream stream() { - return new Stream() { - public void forEach(PlexusIoResourceConsumer resourceConsumer) throws IOException { - - final Iterator it = getEntries(); - while (it.hasNext()) { - final PlexusIoResource res = it.next(); - if (isSelected(res)) { - resourceConsumer.accept(res); - } - } - if (it instanceof Closeable) { - ((Closeable) it).close(); + return resourceConsumer -> { + Iterator it = getEntries(); + while (it.hasNext()) { + final PlexusIoResource res = it.next(); + if (isSelected(res)) { + resourceConsumer.accept(res); } } + if (it instanceof Closeable) { + ((Closeable) it).close(); + } }; } diff --git a/src/main/java/org/codehaus/plexus/components/io/resources/AbstractPlexusIoResourceCollection.java b/src/main/java/org/codehaus/plexus/components/io/resources/AbstractPlexusIoResourceCollection.java index cafae1d3..f0dfe91c 100644 --- a/src/main/java/org/codehaus/plexus/components/io/resources/AbstractPlexusIoResourceCollection.java +++ b/src/main/java/org/codehaus/plexus/components/io/resources/AbstractPlexusIoResourceCollection.java @@ -249,9 +249,8 @@ public PlexusIoResource resolve(final PlexusIoResource resource) throws IOExcept public long getLastModified() throws IOException { long lastModified = PlexusIoResource.UNKNOWN_MODIFICATION_DATE; - for (final Iterator iter = getResources(); iter.hasNext(); ) { - final PlexusIoResource res = (PlexusIoResource) iter.next(); - long l = res.getLastModified(); + for (Iterator iter = getResources(); iter.hasNext(); ) { + long l = iter.next().getLastModified(); if (l == PlexusIoResource.UNKNOWN_MODIFICATION_DATE) { return PlexusIoResource.UNKNOWN_MODIFICATION_DATE; } diff --git a/src/main/java/org/codehaus/plexus/components/io/resources/Deferred.java b/src/main/java/org/codehaus/plexus/components/io/resources/Deferred.java index c7461f3a..7db54f3d 100644 --- a/src/main/java/org/codehaus/plexus/components/io/resources/Deferred.java +++ b/src/main/java/org/codehaus/plexus/components/io/resources/Deferred.java @@ -40,7 +40,12 @@ public Deferred(final PlexusIoResource resource, PlexusIoResourceCollection owne throws IOException { this.resource = resource; this.owner = owner; - dfos = hasTransformer ? new DeferredFileOutputStream(5000000, "p-archiver", null, null) : null; + dfos = hasTransformer + ? DeferredFileOutputStream.builder() + .setThreshold(5000000) + .setPrefix("p-archiver") + .get() + : null; if (dfos != null) { InputStream inputStream = owner.getInputStream(resource); IOUtils.copy(inputStream, dfos); diff --git a/src/main/java/org/codehaus/plexus/components/io/resources/PlexusIoCompressedFileResourceCollection.java b/src/main/java/org/codehaus/plexus/components/io/resources/PlexusIoCompressedFileResourceCollection.java index e1038032..64ba973c 100644 --- a/src/main/java/org/codehaus/plexus/components/io/resources/PlexusIoCompressedFileResourceCollection.java +++ b/src/main/java/org/codehaus/plexus/components/io/resources/PlexusIoCompressedFileResourceCollection.java @@ -108,7 +108,7 @@ public InputStream getContents() throws IOException { protected String getName(File file) throws IOException { final String name = file.getPath(); final String ext = getDefaultExtension(); - if (ext != null && ext.length() > 0 && name.endsWith(ext)) { + if (ext != null && !ext.isEmpty() && name.endsWith(ext)) { return name.substring(0, name.length() - ext.length()); } return name; diff --git a/src/main/java/org/codehaus/plexus/components/io/resources/PlexusIoFileResource.java b/src/main/java/org/codehaus/plexus/components/io/resources/PlexusIoFileResource.java index a97334c3..dd262cb9 100755 --- a/src/main/java/org/codehaus/plexus/components/io/resources/PlexusIoFileResource.java +++ b/src/main/java/org/codehaus/plexus/components/io/resources/PlexusIoFileResource.java @@ -24,6 +24,7 @@ import java.io.IOException; import java.io.InputStream; import java.net.URL; +import java.nio.file.Files; import java.nio.file.attribute.FileTime; import org.apache.commons.io.IOUtils; @@ -103,7 +104,10 @@ protected PlexusIoFileResource(@Nonnull File file, @Nonnull String name, @Nonnul private static DeferredFileOutputStream asDeferredStream( @Nonnull ContentSupplier supplier, @Nonnull InputStreamTransformer transToUse, PlexusIoResource resource) throws IOException { - DeferredFileOutputStream dfos = new DeferredFileOutputStream(5000000, "p-archiver", null, null); + DeferredFileOutputStream dfos = DeferredFileOutputStream.builder() + .setThreshold(5000000) + .setPrefix("p-archiver") + .get(); InputStream inputStream = supplier.getContents(); InputStream transformed = transToUse.transform(resource, inputStream); IOUtils.copy(transformed, dfos); @@ -113,11 +117,7 @@ private static DeferredFileOutputStream asDeferredStream( } private static ContentSupplier getRootContentSupplier(final File file) { - return new ContentSupplier() { - public InputStream getContents() throws IOException { - return new FileInputStream(file); - } - }; + return () -> Files.newInputStream(file.toPath()); } public static String getName(File file) { diff --git a/src/main/java/org/codehaus/plexus/components/io/resources/PlexusIoResource.java b/src/main/java/org/codehaus/plexus/components/io/resources/PlexusIoResource.java index 27791a08..7653744c 100644 --- a/src/main/java/org/codehaus/plexus/components/io/resources/PlexusIoResource.java +++ b/src/main/java/org/codehaus/plexus/components/io/resources/PlexusIoResource.java @@ -73,7 +73,7 @@ public interface PlexusIoResource extends FileInfo, SizeSupplier, ContentSupplie * Creates an {@link java.io.InputStream}, which may be used to read * the files contents. This is useful, if the file selector * comes to a decision based on the files contents. - * + *

* Please note that this InputStream is unbuffered. Clients should wrap this in a * BufferedInputStream or attempt reading reasonably large chunks (8K+). */ diff --git a/src/main/java/org/codehaus/plexus/components/io/resources/PlexusIoSymlinkResource.java b/src/main/java/org/codehaus/plexus/components/io/resources/PlexusIoSymlinkResource.java index 441fabfb..1c6b867d 100644 --- a/src/main/java/org/codehaus/plexus/components/io/resources/PlexusIoSymlinkResource.java +++ b/src/main/java/org/codehaus/plexus/components/io/resources/PlexusIoSymlinkResource.java @@ -87,10 +87,4 @@ public boolean isFile() { public long getLastModified() { return targetResource.getLastModified(); } - - @Nonnull - @Override - public PlexusIoResourceAttributes getAttributes() { - return super.getAttributes(); - } } diff --git a/src/main/java/org/codehaus/plexus/components/io/resources/proxy/PlexusIoProxyResourceCollection.java b/src/main/java/org/codehaus/plexus/components/io/resources/proxy/PlexusIoProxyResourceCollection.java index b540ee44..ffa94301 100644 --- a/src/main/java/org/codehaus/plexus/components/io/resources/proxy/PlexusIoProxyResourceCollection.java +++ b/src/main/java/org/codehaus/plexus/components/io/resources/proxy/PlexusIoProxyResourceCollection.java @@ -42,7 +42,7 @@ */ public class PlexusIoProxyResourceCollection extends AbstractPlexusIoResourceCollectionWithAttributes implements EncodingSupported { - private PlexusIoResourceCollection src; + private final PlexusIoResourceCollection src; public PlexusIoProxyResourceCollection(@Nonnull PlexusIoResourceCollection src) { this.src = src; @@ -98,14 +98,14 @@ protected FileSelector getDefaultFileSelector() { private String getNonEmptyPrfix() { String prefix = getPrefix(); - if (prefix != null && prefix.length() == 0) { + if (prefix != null && prefix.isEmpty()) { return null; } return prefix; } class FwdIterator extends ForwardingIterator { - Iterator iter; + final Iterator iter; private final FileSelector fileSelector = getDefaultFileSelector(); diff --git a/src/main/java/org/codehaus/plexus/components/io/resources/proxy/ResourceInvocationHandler.java b/src/main/java/org/codehaus/plexus/components/io/resources/proxy/ResourceInvocationHandler.java index 503317b1..7ac62cec 100644 --- a/src/main/java/org/codehaus/plexus/components/io/resources/proxy/ResourceInvocationHandler.java +++ b/src/main/java/org/codehaus/plexus/components/io/resources/proxy/ResourceInvocationHandler.java @@ -28,7 +28,7 @@ import org.codehaus.plexus.components.io.resources.PlexusIoResource; class ResourceInvocationHandler implements InvocationHandler { - private PlexusIoResource testImpl; + private final PlexusIoResource testImpl; private final ContentSupplier contentSupplier; private final NameSupplier nameSupplier; diff --git a/src/test/java/org/codehaus/plexus/components/io/attributes/AttributeUtilsTest.java b/src/test/java/org/codehaus/plexus/components/io/attributes/AttributeUtilsTest.java index 38f1d019..8a56959b 100644 --- a/src/test/java/org/codehaus/plexus/components/io/attributes/AttributeUtilsTest.java +++ b/src/test/java/org/codehaus/plexus/components/io/attributes/AttributeUtilsTest.java @@ -5,8 +5,9 @@ import java.nio.file.attribute.PosixFilePermission; import java.util.Set; -import org.codehaus.plexus.util.Os; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.condition.DisabledOnOs; +import org.junit.jupiter.api.condition.OS; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; @@ -34,7 +35,7 @@ void testMorePatterns() { } @Test - void testEvenMorePatterns() throws Exception { + void testEvenMorePatterns() { final Set permissions = AttributeUtils.getPermissions(0412); assertTrue(permissions.contains(PosixFilePermission.OWNER_READ)); assertTrue(permissions.contains(PosixFilePermission.GROUP_EXECUTE)); @@ -42,14 +43,14 @@ void testEvenMorePatterns() throws Exception { } @Test - void test777() throws Exception { + void test777() { final Set permissions = AttributeUtils.getPermissions(0777); assertEquals(9, permissions.size()); } @Test + @DisabledOnOs(OS.WINDOWS) void testChmodBackAndForth() throws IOException { - if (Os.isFamily(Os.FAMILY_WINDOWS)) return; final File bxx = File.createTempFile("bxx", "ff"); AttributeUtils.chmod(bxx, 0422); PlexusIoResourceAttributes firstAttrs = new FileAttributes(bxx); diff --git a/src/test/java/org/codehaus/plexus/components/io/attributes/FileAttributesTest.java b/src/test/java/org/codehaus/plexus/components/io/attributes/FileAttributesTest.java index 0e3025c3..3449f76f 100644 --- a/src/test/java/org/codehaus/plexus/components/io/attributes/FileAttributesTest.java +++ b/src/test/java/org/codehaus/plexus/components/io/attributes/FileAttributesTest.java @@ -18,8 +18,9 @@ import java.io.File; -import org.codehaus.plexus.util.Os; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.condition.DisabledOnOs; +import org.junit.jupiter.api.condition.OS; import static org.junit.jupiter.api.Assertions.assertNotNull; @@ -28,14 +29,9 @@ */ public class FileAttributesTest { @Test + @DisabledOnOs(OS.WINDOWS) void testGetPosixFileAttributes() throws Exception { - - if (Os.isFamily(Os.FAMILY_WINDOWS)) { - return; - } - File file = new File("."); - PlexusIoResourceAttributes fa = new FileAttributes(file); assertNotNull(fa); } diff --git a/src/test/java/org/codehaus/plexus/components/io/attributes/PlexusIoResourceAttributeUtilsTest.java b/src/test/java/org/codehaus/plexus/components/io/attributes/PlexusIoResourceAttributeUtilsTest.java index fe887701..4712e822 100644 --- a/src/test/java/org/codehaus/plexus/components/io/attributes/PlexusIoResourceAttributeUtilsTest.java +++ b/src/test/java/org/codehaus/plexus/components/io/attributes/PlexusIoResourceAttributeUtilsTest.java @@ -22,12 +22,13 @@ import java.nio.file.NoSuchFileException; import java.util.Map; -import org.codehaus.plexus.util.Os; import org.codehaus.plexus.util.StringUtils; import org.codehaus.plexus.util.cli.CommandLineException; import org.codehaus.plexus.util.cli.CommandLineUtils; import org.codehaus.plexus.util.cli.Commandline; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.condition.DisabledOnOs; +import org.junit.jupiter.api.condition.OS; import static org.codehaus.plexus.components.io.attributes.PlexusIoResourceAttributeUtils.getFileAttributes; import static org.junit.jupiter.api.Assertions.*; @@ -36,12 +37,8 @@ public class PlexusIoResourceAttributeUtilsTest { @Test + @DisabledOnOs(OS.WINDOWS) void testGetAttributesForThisTestClass() throws IOException { - if (Os.isFamily(Os.FAMILY_WINDOWS)) { - System.out.println("WARNING: Unsupported OS, skipping test"); - return; - } - URL resource = Thread.currentThread() .getContextClassLoader() .getResource(getClass().getName().replace('.', '/') + ".class"); @@ -64,12 +61,8 @@ void testGetAttributesForThisTestClass() throws IOException { } @Test + @DisabledOnOs(OS.WINDOWS) void testDirectory() throws IOException, CommandLineException { - - if (Os.isFamily(Os.FAMILY_WINDOWS)) { - return; // Nothing to do here. - } - URL resource = Thread.currentThread() .getContextClassLoader() .getResource(getClass().getName().replace('.', '/') + ".class"); @@ -106,11 +99,8 @@ void testDirectory() throws IOException, CommandLineException { } @Test + @DisabledOnOs(OS.WINDOWS) void testSrcResource() throws IOException { - if (Os.isFamily(Os.FAMILY_WINDOWS)) { - return; // Nothing to do here. - } - File dir = new File("src/test/resources/symlinks"); final Map fileAttributesByPathScreenScrape = PlexusIoResourceAttributeUtils.getFileAttributesByPath(dir, true); @@ -260,15 +250,21 @@ void testMergeAttributesOverride() { } @Test + void testFileAttributesGeneric() throws IOException { + PlexusIoResourceAttributes attrs = getFileAttributes(new File("src/test/resources/symlinks/src/fileW.txt")); + assertFalse(attrs.isSymbolicLink()); + assertTrue(StringUtils.isNotEmpty(attrs.getUserName())); + } + + @Test + @DisabledOnOs(OS.WINDOWS) void testFileAttributes() throws IOException { PlexusIoResourceAttributes attrs = getFileAttributes(new File("src/test/resources/symlinks/src/fileW.txt")); assertFalse(attrs.isSymbolicLink()); assertTrue(StringUtils.isNotEmpty(attrs.getUserName())); - if (!Os.isFamily(Os.FAMILY_WINDOWS)) { - assertTrue(StringUtils.isNotEmpty(attrs.getGroupName())); - assertNotNull(attrs.getGroupId()); - assertNotNull(attrs.getUserId()); - } + assertTrue(StringUtils.isNotEmpty(attrs.getGroupName())); + assertNotNull(attrs.getGroupId()); + assertNotNull(attrs.getUserId()); } @Test diff --git a/src/test/java/org/codehaus/plexus/components/io/attributes/SymlinkUtilsTest.java b/src/test/java/org/codehaus/plexus/components/io/attributes/SymlinkUtilsTest.java index b3f97aa6..7b216bb6 100644 --- a/src/test/java/org/codehaus/plexus/components/io/attributes/SymlinkUtilsTest.java +++ b/src/test/java/org/codehaus/plexus/components/io/attributes/SymlinkUtilsTest.java @@ -24,12 +24,13 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import static java.nio.charset.StandardCharsets.UTF_8; import static org.junit.jupiter.api.Assertions.*; public class SymlinkUtilsTest { - File target = new File("target/symlinkCapabilities"); + final File target = new File("target/symlinkCapabilities"); - String expected = "This is a filed that we'll be symlinking to\n"; + final String expected = "This is a filed that we'll be symlinking to\n"; @BeforeEach public void setup() throws IOException { @@ -37,15 +38,12 @@ public void setup() throws IOException { Files.createDirectories(target.toPath()); } - @Test - void testName() throws Exception {} - @Test void create_read_symbolic_link_to_file() throws Exception { File symlink = new File(target, "symlinkToTarget"); File relativePath = createTargetFile(target); SymlinkUtils.createSymbolicLink(symlink, relativePath); - assertEquals(expected, FileUtils.readFileToString(symlink)); + assertEquals(expected, FileUtils.readFileToString(symlink, UTF_8)); assertEquals(new File("actualFile"), SymlinkUtils.readSymbolicLink(new File(target, "symlinkToTarget"))); } @@ -55,14 +53,14 @@ void create_read_symbolic_link_to_directory() throws Exception { createTargetFile(subDir); File symlink = new File(target, "symlinkToDir"); SymlinkUtils.createSymbolicLink(symlink, new File("aSubDir")); - assertEquals(expected, FileUtils.readFileToString(new File(symlink, "actualFile"))); + assertEquals(expected, FileUtils.readFileToString(new File(symlink, "actualFile"), UTF_8)); assertEquals(new File("aSubDir"), SymlinkUtils.readSymbolicLink(new File(target, "symlinkToDir"))); } private File createTargetFile(File target) throws IOException { File relativePath = new File("actualFile"); File actualFile = new File(target, relativePath.getPath()); - FileUtils.write(actualFile, expected); + FileUtils.write(actualFile, expected, UTF_8); return relativePath; } } diff --git a/src/test/java/org/codehaus/plexus/components/io/filemappers/FileSelectorTest.java b/src/test/java/org/codehaus/plexus/components/io/filemappers/FileSelectorTest.java index c32b03c8..6879c7f0 100644 --- a/src/test/java/org/codehaus/plexus/components/io/filemappers/FileSelectorTest.java +++ b/src/test/java/org/codehaus/plexus/components/io/filemappers/FileSelectorTest.java @@ -49,11 +49,11 @@ protected void testFileSelector(FileSelector pSelector, String[] pInput, boolean final String name = pInput[i]; AbstractPlexusIoResource resource = new AbstractPlexusIoResource(name, 0, 0, true, false, true) { @Nonnull - public InputStream getContents() throws IOException { + public InputStream getContents() { throw new IllegalStateException("Not implemented"); } - public URL getURL() throws IOException { + public URL getURL() { throw new IllegalStateException("Not implemented"); } }; @@ -121,7 +121,7 @@ void testIncludeExcludeFileSelector() throws Exception { } @Test - void testIncludeExcludeFileSelector_SetExcludes() throws Exception { + void testIncludeExcludeFileSelector_SetExcludes() { IncludeExcludeFileSelector selector = new IncludeExcludeFileSelector(); // Test that the setExcludes method does not modify the excludes. diff --git a/src/test/java/org/codehaus/plexus/components/io/resources/AbstractPlexusIoResourceCollectionTest.java b/src/test/java/org/codehaus/plexus/components/io/resources/AbstractPlexusIoResourceCollectionTest.java index 21c3714c..4e068ba3 100644 --- a/src/test/java/org/codehaus/plexus/components/io/resources/AbstractPlexusIoResourceCollectionTest.java +++ b/src/test/java/org/codehaus/plexus/components/io/resources/AbstractPlexusIoResourceCollectionTest.java @@ -22,7 +22,7 @@ public class AbstractPlexusIoResourceCollectionTest { @Test void testGetIncludes() throws Exception { AbstractPlexusIoResourceCollection sut = new AbstractPlexusIoResourceCollection() { - public Iterator getResources() throws IOException { + public Iterator getResources() { return Arrays.asList(getResource("r1"), getResource("r2")).iterator(); } @@ -57,11 +57,11 @@ public InputStream transform(@Nonnull PlexusIoResource resource, @Nonnull final private static PlexusIoResource getResource(final String r1) { return new AbstractPlexusIoResource(r1, 0, 0, true, false, true) { @Nonnull - public InputStream getContents() throws IOException { + public InputStream getContents() { return new ByteArrayInputStream((r1 + "Payload").getBytes()); } - public URL getURL() throws IOException { + public URL getURL() { throw new IllegalStateException("Not implemented"); } }; diff --git a/src/test/java/org/codehaus/plexus/components/io/resources/PlexusIoPlexusIoFileResourceTest.java b/src/test/java/org/codehaus/plexus/components/io/resources/PlexusIoPlexusIoFileResourceTest.java index a4733f9e..d61cf544 100644 --- a/src/test/java/org/codehaus/plexus/components/io/resources/PlexusIoPlexusIoFileResourceTest.java +++ b/src/test/java/org/codehaus/plexus/components/io/resources/PlexusIoPlexusIoFileResourceTest.java @@ -7,16 +7,17 @@ import org.codehaus.plexus.components.io.attributes.PlexusIoResourceAttributes; import org.codehaus.plexus.components.io.attributes.SymlinkUtils; import org.codehaus.plexus.components.io.functions.SymlinkDestinationSupplier; -import org.codehaus.plexus.util.Os; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.condition.DisabledOnOs; +import org.junit.jupiter.api.condition.OS; import static org.junit.jupiter.api.Assertions.*; public class PlexusIoPlexusIoFileResourceTest { @Test + @DisabledOnOs(OS.WINDOWS) void testRealSymlink() throws IOException { - if (Os.isFamily(Os.FAMILY_WINDOWS)) return; final File file = new File("src/test/resources/symlinks/src/symDir"); PlexusIoResourceAttributes attrs = FileAttributes.uncached(file); assertTrue(attrs.isSymbolicLink()); @@ -30,8 +31,8 @@ void testRealSymlink() throws IOException { } @Test + @DisabledOnOs(OS.WINDOWS) void testSymSymlinkFile() throws IOException { - if (Os.isFamily(Os.FAMILY_WINDOWS)) return; final File file = new File("src/test/resources/symlinks/src/symSymR"); PlexusIoResource r = ResourceFactory.createResource(file); assertTrue(r.isSymbolicLink()); @@ -45,8 +46,8 @@ void testSymSymlinkFile() throws IOException { } @Test + @DisabledOnOs(OS.WINDOWS) void testSymlinkFile() throws IOException { - if (Os.isFamily(Os.FAMILY_WINDOWS)) return; final File file = new File("src/test/resources/symlinks/src/symR"); PlexusIoResource r = ResourceFactory.createResource(file); assertTrue(r.isSymbolicLink()); diff --git a/src/test/java/org/codehaus/plexus/components/io/resources/proxy/PlexusIoProxyResourceCollectionTest.java b/src/test/java/org/codehaus/plexus/components/io/resources/proxy/PlexusIoProxyResourceCollectionTest.java index 426ff908..1ce7f92e 100644 --- a/src/test/java/org/codehaus/plexus/components/io/resources/proxy/PlexusIoProxyResourceCollectionTest.java +++ b/src/test/java/org/codehaus/plexus/components/io/resources/proxy/PlexusIoProxyResourceCollectionTest.java @@ -42,7 +42,7 @@ public class PlexusIoProxyResourceCollectionTest { private final String[] SAMPLE_EXCLUDES = {"*.junk", "somwhere/**"}; @Test - void testGetDefaultFileSelector() throws Exception { + void testGetDefaultFileSelector() { PlexusIoProxyResourceCollection resCol = new PlexusIoProxyResourceCollection(null); // This will throw an exception if there is a bug @@ -75,11 +75,11 @@ public boolean hasNext() { public PlexusIoResource next() { return new AbstractPlexusIoResource("fud", 123, 22, true, false, false) { @Nonnull - public InputStream getContents() throws IOException { + public InputStream getContents() { return null; } - public URL getURL() throws IOException { + public URL getURL() { return null; } }; @@ -95,7 +95,7 @@ void testClosing() throws IOException { final CloseableIterator closeableIterator = new CloseableIterator(); PlexusIoProxyResourceCollection resCol = new PlexusIoProxyResourceCollection(new AbstractPlexusIoResourceCollection() { - public Iterator getResources() throws IOException { + public Iterator getResources() { return closeableIterator; } diff --git a/src/test/java/org/codehaus/plexus/components/io/resources/proxy/ProxyFactoryTest.java b/src/test/java/org/codehaus/plexus/components/io/resources/proxy/ProxyFactoryTest.java index 158c3630..152b6331 100644 --- a/src/test/java/org/codehaus/plexus/components/io/resources/proxy/ProxyFactoryTest.java +++ b/src/test/java/org/codehaus/plexus/components/io/resources/proxy/ProxyFactoryTest.java @@ -58,11 +58,7 @@ void testCreateProxyWithSizeSupplierOverride() throws Exception { @Test void testCreateProxyWithContentSupplierOverride() throws Exception { final InputStream s = new ByteArrayInputStream(new byte[10]); - ContentSupplier ns = new ContentSupplier() { - public InputStream getContents() throws IOException { - return s; - } - }; + ContentSupplier ns = () -> s; final PlexusIoResource proxy = ProxyFactory.createProxy(getPomResource(), ns); assertEquals(s, proxy.getContents()); } @@ -86,7 +82,7 @@ public Dummy(@Nonnull File file, @Nonnull PlexusIoResourceAttributes attrs) thro super(file, file.getName(), attrs); } - public String getSymlinkDestination() throws IOException { + public String getSymlinkDestination() { throw new IllegalStateException("Unsupported"); } } From 5ad18c992cc73e962bc41d015efb2000603a9e12 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 3 Oct 2023 21:16:37 +0000 Subject: [PATCH 42/86] Bump org.codehaus.plexus:plexus from 14 to 15 Bumps [org.codehaus.plexus:plexus](https://github.com/codehaus-plexus/plexus-pom) from 14 to 15. - [Release notes](https://github.com/codehaus-plexus/plexus-pom/releases) - [Commits](https://github.com/codehaus-plexus/plexus-pom/commits) --- updated-dependencies: - dependency-name: org.codehaus.plexus:plexus dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index a5cdc075..46c2e8e1 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ org.codehaus.plexus plexus - 14 + 15 plexus-io From 11f8db4e9cde36fec65ca1bcb7576864aac5be5b Mon Sep 17 00:00:00 2001 From: Sylwester Lachiewicz Date: Sun, 8 Oct 2023 16:40:22 +0200 Subject: [PATCH 43/86] Correct sisu.inject dependency version --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 46c2e8e1..a766725d 100644 --- a/pom.xml +++ b/pom.xml @@ -31,7 +31,6 @@ - 0.3.5 1.7.36 2023-02-28T16:42:48Z @@ -89,7 +88,8 @@ org.eclipse.sisu org.eclipse.sisu.inject - ${sisuVersion} + + 0.3.5 test From a753eeb075dac8a424236881832e24b927f0ee00 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 23 Oct 2023 21:51:02 +0000 Subject: [PATCH 44/86] Bump org.codehaus.plexus:plexus-testing from 1.1.0 to 1.2.0 Bumps [org.codehaus.plexus:plexus-testing](https://github.com/codehaus-plexus/plexus-testing) from 1.1.0 to 1.2.0. - [Release notes](https://github.com/codehaus-plexus/plexus-testing/releases) - [Commits](https://github.com/codehaus-plexus/plexus-testing/compare/plexus-testing-1.1.0...plexus-testing-1.2.0) --- updated-dependencies: - dependency-name: org.codehaus.plexus:plexus-testing dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index a766725d..46e63cfe 100644 --- a/pom.xml +++ b/pom.xml @@ -81,7 +81,7 @@ org.codehaus.plexus plexus-testing - 1.1.0 + 1.2.0 test From 594c26937a68c326270a7fc44aefd635bd008840 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 25 Oct 2023 21:14:53 +0000 Subject: [PATCH 45/86] Bump commons-io:commons-io from 2.14.0 to 2.15.0 Bumps commons-io:commons-io from 2.14.0 to 2.15.0. --- updated-dependencies: - dependency-name: commons-io:commons-io dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 46e63cfe..104b08f4 100644 --- a/pom.xml +++ b/pom.xml @@ -63,7 +63,7 @@ commons-io commons-io - 2.14.0 + 2.15.0 From 8524fcab4d95fb1ef748ac43825c2fadef80e746 Mon Sep 17 00:00:00 2001 From: Sylwester Lachiewicz Date: Sat, 2 Dec 2023 10:27:41 +0100 Subject: [PATCH 46/86] Reuse plexus-pom action for CI --- .github/workflows/maven.yml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index aed2cc52..09feae47 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -21,5 +21,11 @@ on: [push, pull_request] jobs: build: - name: Build with Maven + name: Build it uses: codehaus-plexus/.github/.github/workflows/maven.yml@master + + deploy: + name: Deploy + needs: build + uses: codehaus-plexus/.github/.github/workflows/maven-deploy.yml@master + secrets: inherit From 5f3c175e1fecbda9157026a1aceff594293d755f Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 11 Dec 2023 21:40:22 +0000 Subject: [PATCH 47/86] Bump org.codehaus.plexus:plexus from 15 to 16 Bumps [org.codehaus.plexus:plexus](https://github.com/codehaus-plexus/plexus-pom) from 15 to 16. - [Release notes](https://github.com/codehaus-plexus/plexus-pom/releases) - [Commits](https://github.com/codehaus-plexus/plexus-pom/commits) --- updated-dependencies: - dependency-name: org.codehaus.plexus:plexus dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 104b08f4..67fef344 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ org.codehaus.plexus plexus - 15 + 16 plexus-io From 1fe3b07aad8cba086b090d6a4f36109c20eb6ff8 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 30 Nov 2023 21:18:21 +0000 Subject: [PATCH 48/86] Bump commons-io:commons-io from 2.15.0 to 2.15.1 Bumps commons-io:commons-io from 2.15.0 to 2.15.1. --- updated-dependencies: - dependency-name: commons-io:commons-io dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 67fef344..77399e1d 100644 --- a/pom.xml +++ b/pom.xml @@ -63,7 +63,7 @@ commons-io commons-io - 2.15.0 + 2.15.1 From ea0c6737fc80efc383a3798ea0a2a2b349f13ad0 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 14 Dec 2023 21:41:40 +0000 Subject: [PATCH 49/86] Bump org.codehaus.plexus:plexus-testing from 1.2.0 to 1.3.0 Bumps [org.codehaus.plexus:plexus-testing](https://github.com/codehaus-plexus/plexus-testing) from 1.2.0 to 1.3.0. - [Release notes](https://github.com/codehaus-plexus/plexus-testing/releases) - [Commits](https://github.com/codehaus-plexus/plexus-testing/compare/plexus-testing-1.2.0...plexus-testing-1.3.0) --- updated-dependencies: - dependency-name: org.codehaus.plexus:plexus-testing dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 77399e1d..221756ef 100644 --- a/pom.xml +++ b/pom.xml @@ -81,7 +81,7 @@ org.codehaus.plexus plexus-testing - 1.2.0 + 1.3.0 test From 74297f1cf6df09faa7257563ec628c447390e7aa Mon Sep 17 00:00:00 2001 From: Sylwester Lachiewicz Date: Sun, 24 Dec 2023 00:25:59 +0100 Subject: [PATCH 50/86] Update sisu.inject to 0.9.0.M2 cleanup junit --- pom.xml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index 221756ef..f9e430c3 100644 --- a/pom.xml +++ b/pom.xml @@ -69,7 +69,7 @@ org.junit.jupiter - junit-jupiter + junit-jupiter-api test @@ -88,8 +88,7 @@ org.eclipse.sisu org.eclipse.sisu.inject - - 0.3.5 + 0.9.0.M2 test From f4a7838b46e24814b1bad5a069d46627056c33f1 Mon Sep 17 00:00:00 2001 From: Sylwester Lachiewicz Date: Sun, 24 Dec 2023 00:42:37 +0100 Subject: [PATCH 51/86] [maven-release-plugin] prepare release plexus-io-3.4.2 --- pom.xml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index f9e430c3..b2a78295 100644 --- a/pom.xml +++ b/pom.xml @@ -9,14 +9,14 @@ plexus-io - 3.4.2-SNAPSHOT + 3.4.2 Plexus IO Components scm:git:git@github.com:codehaus-plexus/plexus-io.git scm:git:git@github.com:codehaus-plexus/plexus-io.git - HEAD + plexus-io-3.4.2 http://github.com/codehaus-plexus/plexus-io @@ -32,7 +32,7 @@ 1.7.36 - 2023-02-28T16:42:48Z + 2023-12-23T23:42:28Z From 3b19c6dc092394e7a48bf2dda20e7ba5b407e0ce Mon Sep 17 00:00:00 2001 From: Sylwester Lachiewicz Date: Sun, 24 Dec 2023 00:42:41 +0100 Subject: [PATCH 52/86] [maven-release-plugin] prepare for next development iteration --- pom.xml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index b2a78295..9fe1b057 100644 --- a/pom.xml +++ b/pom.xml @@ -9,14 +9,14 @@ plexus-io - 3.4.2 + 3.4.3-SNAPSHOT Plexus IO Components scm:git:git@github.com:codehaus-plexus/plexus-io.git scm:git:git@github.com:codehaus-plexus/plexus-io.git - plexus-io-3.4.2 + HEAD http://github.com/codehaus-plexus/plexus-io @@ -32,7 +32,7 @@ 1.7.36 - 2023-12-23T23:42:28Z + 2023-12-23T23:42:41Z From 97207afa73ccfccbf571178981b705e3762c72de Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 4 Mar 2024 21:05:43 +0000 Subject: [PATCH 53/86] Bump org.codehaus.plexus:plexus from 16 to 17 Bumps [org.codehaus.plexus:plexus](https://github.com/codehaus-plexus/plexus-pom) from 16 to 17. - [Release notes](https://github.com/codehaus-plexus/plexus-pom/releases) - [Commits](https://github.com/codehaus-plexus/plexus-pom/commits) --- updated-dependencies: - dependency-name: org.codehaus.plexus:plexus dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 9fe1b057..5bffe558 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ org.codehaus.plexus plexus - 16 + 17 plexus-io From 28bb8433c495674b689d90f2acc5ee714a3c407e Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 29 Mar 2024 21:37:47 +0000 Subject: [PATCH 54/86] Bump commons-io:commons-io from 2.15.1 to 2.16.0 Bumps commons-io:commons-io from 2.15.1 to 2.16.0. --- updated-dependencies: - dependency-name: commons-io:commons-io dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 5bffe558..1c451608 100644 --- a/pom.xml +++ b/pom.xml @@ -63,7 +63,7 @@ commons-io commons-io - 2.15.1 + 2.16.0 From 99c666a29e4703f2370931a382103c06b4df9ecc Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 8 Apr 2024 21:45:25 +0000 Subject: [PATCH 55/86] Bump commons-io:commons-io from 2.16.0 to 2.16.1 Bumps commons-io:commons-io from 2.16.0 to 2.16.1. --- updated-dependencies: - dependency-name: commons-io:commons-io dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 1c451608..3fd6eb90 100644 --- a/pom.xml +++ b/pom.xml @@ -63,7 +63,7 @@ commons-io commons-io - 2.16.0 + 2.16.1 From 8f804de42de00ebe42d5a7609fe4899034baf540 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 15 Apr 2024 21:47:34 +0000 Subject: [PATCH 56/86] Bump org.codehaus.plexus:plexus-utils from 4.0.0 to 4.0.1 Bumps [org.codehaus.plexus:plexus-utils](https://github.com/codehaus-plexus/plexus-utils) from 4.0.0 to 4.0.1. - [Release notes](https://github.com/codehaus-plexus/plexus-utils/releases) - [Commits](https://github.com/codehaus-plexus/plexus-utils/compare/plexus-utils-4.0.0...plexus-utils-4.0.1) --- updated-dependencies: - dependency-name: org.codehaus.plexus:plexus-utils dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 3fd6eb90..3a0ebcaa 100644 --- a/pom.xml +++ b/pom.xml @@ -46,7 +46,7 @@ org.codehaus.plexus plexus-utils - 4.0.0 + 4.0.1 org.codehaus.plexus From aff4d363429cb93ea9b0634a7f38ed0d53d1262b Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 22 May 2024 21:37:26 +0000 Subject: [PATCH 57/86] Bump org.codehaus.plexus:plexus-xml from 3.0.0 to 3.0.1 Bumps [org.codehaus.plexus:plexus-xml](https://github.com/codehaus-plexus/plexus-xml) from 3.0.0 to 3.0.1. - [Release notes](https://github.com/codehaus-plexus/plexus-xml/releases) - [Commits](https://github.com/codehaus-plexus/plexus-xml/compare/plexus-xml-3.0.0...plexus-xml-3.0.1) --- updated-dependencies: - dependency-name: org.codehaus.plexus:plexus-xml dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 3a0ebcaa..25920673 100644 --- a/pom.xml +++ b/pom.xml @@ -51,7 +51,7 @@ org.codehaus.plexus plexus-xml - 3.0.0 + 3.0.1 test From 120d4f87c6b78252cef0d99c2591825a73bb33b3 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 3 Jun 2024 21:42:01 +0000 Subject: [PATCH 58/86] Bump org.eclipse.sisu:org.eclipse.sisu.inject from 0.9.0.M2 to 0.9.0.M3 Bumps [org.eclipse.sisu:org.eclipse.sisu.inject](https://github.com/eclipse/sisu.inject) from 0.9.0.M2 to 0.9.0.M3. - [Release notes](https://github.com/eclipse/sisu.inject/releases) - [Changelog](https://github.com/eclipse-sisu/sisu-project/blob/main/RELEASE.md) - [Commits](https://github.com/eclipse/sisu.inject/compare/milestones/0.9.0.M2...milestones/0.9.0.M3) --- updated-dependencies: - dependency-name: org.eclipse.sisu:org.eclipse.sisu.inject dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 25920673..6dee4ddf 100644 --- a/pom.xml +++ b/pom.xml @@ -88,7 +88,7 @@ org.eclipse.sisu org.eclipse.sisu.inject - 0.9.0.M2 + 0.9.0.M3 test From d7a73bb0f44031225ee2d20c357d7eead0dee915 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 21 May 2024 21:15:17 +0000 Subject: [PATCH 59/86] --- updated-dependencies: - dependency-name: org.codehaus.plexus:plexus dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 6dee4ddf..78c97365 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ org.codehaus.plexus plexus - 17 + 18 plexus-io From 06bba28c06d8d5f113717a7eaea70412a2f9b534 Mon Sep 17 00:00:00 2001 From: Sylwester Lachiewicz Date: Thu, 4 Jul 2024 13:38:22 +0200 Subject: [PATCH 60/86] Update test sisu to 0.9.0.M3 (test scope) --- pom.xml | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 78c97365..1f02c247 100644 --- a/pom.xml +++ b/pom.xml @@ -31,10 +31,25 @@ + 0.9.0.M3 1.7.36 2023-12-23T23:42:41Z + + + + org.eclipse.sisu + org.eclipse.sisu.inject + ${eclipseSisuVersion} + + + org.eclipse.sisu + org.eclipse.sisu.plexus + ${eclipseSisuVersion} + + + @@ -88,7 +103,6 @@ org.eclipse.sisu org.eclipse.sisu.inject - 0.9.0.M3 test From b8e7d5666198da675d36f86b37f985dd822e74ee Mon Sep 17 00:00:00 2001 From: Sylwester Lachiewicz Date: Thu, 4 Jul 2024 13:46:12 +0200 Subject: [PATCH 61/86] (CI) skip Deploy --- .github/workflows/maven.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 09feae47..fb8795b4 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -24,8 +24,8 @@ jobs: name: Build it uses: codehaus-plexus/.github/.github/workflows/maven.yml@master - deploy: - name: Deploy - needs: build - uses: codehaus-plexus/.github/.github/workflows/maven-deploy.yml@master - secrets: inherit +# deploy: +# name: Deploy +# needs: build +# uses: codehaus-plexus/.github/.github/workflows/maven-deploy.yml@master +# secrets: inherit From 2c508039d2bb933112388d9d4c6cd0cd6b204155 Mon Sep 17 00:00:00 2001 From: Sylwester Lachiewicz Date: Thu, 4 Jul 2024 14:26:06 +0200 Subject: [PATCH 62/86] [maven-release-plugin] prepare release plexus-io-3.5.0 --- pom.xml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index 1f02c247..518f28cb 100644 --- a/pom.xml +++ b/pom.xml @@ -9,14 +9,14 @@ plexus-io - 3.4.3-SNAPSHOT + 3.5.0 Plexus IO Components scm:git:git@github.com:codehaus-plexus/plexus-io.git scm:git:git@github.com:codehaus-plexus/plexus-io.git - HEAD + plexus-io-3.5.0 http://github.com/codehaus-plexus/plexus-io @@ -33,7 +33,7 @@ 0.9.0.M3 1.7.36 - 2023-12-23T23:42:41Z + 2024-07-04T12:25:59Z From e06a40b482b1631c3ddf7a848e30dc0337cf4b3a Mon Sep 17 00:00:00 2001 From: Sylwester Lachiewicz Date: Thu, 4 Jul 2024 14:26:13 +0200 Subject: [PATCH 63/86] [maven-release-plugin] prepare for next development iteration --- pom.xml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index 518f28cb..17767059 100644 --- a/pom.xml +++ b/pom.xml @@ -9,14 +9,14 @@ plexus-io - 3.5.0 + 3.5.1-SNAPSHOT Plexus IO Components scm:git:git@github.com:codehaus-plexus/plexus-io.git scm:git:git@github.com:codehaus-plexus/plexus-io.git - plexus-io-3.5.0 + HEAD http://github.com/codehaus-plexus/plexus-io @@ -33,7 +33,7 @@ 0.9.0.M3 1.7.36 - 2024-07-04T12:25:59Z + 2024-07-04T12:26:13Z From 412238dfa135639935466b990c8ca660c830cc64 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 4 Jul 2024 21:27:23 +0000 Subject: [PATCH 64/86] Bump org.codehaus.plexus:plexus-testing from 1.3.0 to 1.4.0 Bumps [org.codehaus.plexus:plexus-testing](https://github.com/codehaus-plexus/plexus-testing) from 1.3.0 to 1.4.0. - [Release notes](https://github.com/codehaus-plexus/plexus-testing/releases) - [Commits](https://github.com/codehaus-plexus/plexus-testing/compare/plexus-testing-1.3.0...plexus-testing-1.4.0) --- updated-dependencies: - dependency-name: org.codehaus.plexus:plexus-testing dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 17767059..0db684f4 100644 --- a/pom.xml +++ b/pom.xml @@ -96,7 +96,7 @@ org.codehaus.plexus plexus-testing - 1.3.0 + 1.4.0 test From 5a52f6e74d7138b372ce2086a1ada0b6ca75d6dd Mon Sep 17 00:00:00 2001 From: Guillaume Nodet Date: Wed, 17 Jul 2024 20:16:26 +0200 Subject: [PATCH 65/86] Fix performance problem by caching unix group and user names (fixes #109) (#135) --- .../io/attributes/FileAttributes.java | 69 +++++++++++++++---- 1 file changed, 57 insertions(+), 12 deletions(-) diff --git a/src/main/java/org/codehaus/plexus/components/io/attributes/FileAttributes.java b/src/main/java/org/codehaus/plexus/components/io/attributes/FileAttributes.java index 94c0d3ce..d530790c 100644 --- a/src/main/java/org/codehaus/plexus/components/io/attributes/FileAttributes.java +++ b/src/main/java/org/codehaus/plexus/components/io/attributes/FileAttributes.java @@ -21,6 +21,7 @@ import java.io.File; import java.io.IOException; +import java.nio.file.FileSystem; import java.nio.file.Files; import java.nio.file.LinkOption; import java.nio.file.Path; @@ -28,9 +29,10 @@ import java.nio.file.attribute.PosixFilePermission; import java.security.Principal; import java.util.Collections; -import java.util.HashMap; import java.util.Map; import java.util.Set; +import java.util.WeakHashMap; +import java.util.concurrent.ConcurrentHashMap; /* * File attributes @@ -68,6 +70,12 @@ public class FileAttributes implements PlexusIoResourceAttributes { private final FileTime lastModifiedTime; + private static final Map> UIDS_CACHE = + Collections.synchronizedMap(new WeakHashMap<>()); + + private static final Map> GIDS_CACHE = + Collections.synchronizedMap(new WeakHashMap<>()); + /** * @deprecated use {@link #FileAttributes(File)} and remove the unused userCache and groupCache parameters */ @@ -79,32 +87,64 @@ public FileAttributes( } public FileAttributes(@Nonnull File file) throws IOException { - this(file, false); + this(file.toPath(), false); } public FileAttributes(@Nonnull File file, boolean followLinks) throws IOException { + this(file.toPath(), followLinks); + } + + private static Map getUserCache(FileSystem fs) { + return UIDS_CACHE.computeIfAbsent(fs, f -> new ConcurrentHashMap<>()); + } + + private static Map getGroupCache(FileSystem fs) { + return GIDS_CACHE.computeIfAbsent(fs, f -> new ConcurrentHashMap<>()); + } + + public FileAttributes(@Nonnull Path path, boolean followLinks) throws IOException { LinkOption[] options = followLinks ? FOLLOW_LINK_OPTIONS : NOFOLLOW_LINK_OPTIONS; - Path path = file.toPath(); Set views = path.getFileSystem().supportedFileAttributeViews(); String names; if (views.contains("unix")) { - names = "unix:*"; + names = + "unix:gid,uid,isSymbolicLink,isRegularFile,isDirectory,isOther,mode,permissions,size,lastModifiedTime"; } else if (views.contains("posix")) { names = "posix:*"; } else { names = "basic:*"; } Map attrs = Files.readAttributes(path, names, options); - if (!attrs.containsKey("group") && !attrs.containsKey("owner") && views.contains("owner")) { - Map ownerAttrs = Files.readAttributes(path, "owner:*", options); - Map newAttrs = new HashMap<>(attrs); - newAttrs.putAll(ownerAttrs); - attrs = newAttrs; - } this.groupId = (Integer) attrs.get("gid"); - this.groupName = attrs.containsKey("group") ? ((Principal) attrs.get("group")).getName() : null; + if (attrs.containsKey("group")) { + this.groupName = ((Principal) attrs.get("group")).getName(); + } else if (this.groupId != null) { + Map cache = getGroupCache(path.getFileSystem()); + String name = cache.get(this.groupId); + if (name == null) { + name = getPrincipalName(path, "unix:group"); + cache.put(this.groupId, name); + } + this.groupName = name; + } else { + this.groupName = null; + } this.userId = (Integer) attrs.get("uid"); - this.userName = attrs.containsKey("owner") ? ((Principal) attrs.get("owner")).getName() : null; + if (attrs.containsKey("owner")) { + this.userName = ((Principal) attrs.get("owner")).getName(); + } else if (this.userId != null) { + Map cache = getUserCache(path.getFileSystem()); + String name = cache.get(this.userId); + if (name == null) { + name = getPrincipalName(path, "unix:owner"); + cache.put(this.userId, name); + } + this.userName = name; + } else if (views.contains("owner")) { + this.userName = getPrincipalName(path, "owner:owner"); + } else { + this.userName = null; + } this.symbolicLink = (Boolean) attrs.get("isSymbolicLink"); this.regularFile = (Boolean) attrs.get("isRegularFile"); this.directory = (Boolean) attrs.get("isDirectory"); @@ -120,6 +160,11 @@ public FileAttributes(@Nonnull File file, boolean followLinks) throws IOExceptio this.lastModifiedTime = (FileTime) attrs.get("lastModifiedTime"); } + private static String getPrincipalName(Path path, String attribute) throws IOException { + Object owner = Files.getAttribute(path, attribute, LinkOption.NOFOLLOW_LINKS); + return ((Principal) owner).getName(); + } + public FileAttributes( @Nullable Integer userId, String userName, From 0886495fa17bb38a9f407a6d67151e6954ca20e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herv=C3=A9=20Boutemy?= Date: Sun, 18 Aug 2024 23:59:44 +0200 Subject: [PATCH 66/86] use new Reproducible Central badge endpoint --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index bc828328..c2e53bb0 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,7 @@ Plexus-IO [![Build Status](https://github.com/codehaus-plexus/plexus-io/actions/workflows/maven.yml/badge.svg)](https://github.com/codehaus-plexus/plexus-io/actions/workflows/maven.yml) [![Maven Central](https://img.shields.io/maven-central/v/org.codehaus.plexus/plexus-io.svg?label=Maven%20Central)](https://search.maven.org/artifact/org.codehaus.plexus/plexus-io) +[![Reproducible Builds](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/jvm-repo-rebuild/reproducible-central/master/content/org/codehaus/plexus/plexus-io/badge.json)](https://github.com/jvm-repo-rebuild/reproducible-central/blob/master/content/content/org/codehaus/plexus/plexus-io/README.md) The current master is now at https://github.com/codehaus-plexus/plexus-io From 51b45fec4df8c64b9996c1e2baadff06986bd941 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Herv=C3=A9=20Boutemy?= Date: Mon, 19 Aug 2024 00:51:46 +0200 Subject: [PATCH 67/86] fix Reproducible Central README link --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c2e53bb0..d05b6753 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ Plexus-IO [![Build Status](https://github.com/codehaus-plexus/plexus-io/actions/workflows/maven.yml/badge.svg)](https://github.com/codehaus-plexus/plexus-io/actions/workflows/maven.yml) [![Maven Central](https://img.shields.io/maven-central/v/org.codehaus.plexus/plexus-io.svg?label=Maven%20Central)](https://search.maven.org/artifact/org.codehaus.plexus/plexus-io) -[![Reproducible Builds](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/jvm-repo-rebuild/reproducible-central/master/content/org/codehaus/plexus/plexus-io/badge.json)](https://github.com/jvm-repo-rebuild/reproducible-central/blob/master/content/content/org/codehaus/plexus/plexus-io/README.md) +[![Reproducible Builds](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/jvm-repo-rebuild/reproducible-central/master/content/org/codehaus/plexus/plexus-io/badge.json)](https://github.com/jvm-repo-rebuild/reproducible-central/blob/master/content/org/codehaus/plexus/plexus-io/README.md) The current master is now at https://github.com/codehaus-plexus/plexus-io From dda852035c328dae550a045130de451f7cbe09a3 Mon Sep 17 00:00:00 2001 From: Guillaume Nodet Date: Mon, 9 Sep 2024 14:58:52 +0200 Subject: [PATCH 68/86] Remove outdated release notes --- README.md | 11 --- ReleaseNotes.md | 243 ------------------------------------------------ 2 files changed, 254 deletions(-) delete mode 100644 ReleaseNotes.md diff --git a/README.md b/README.md index d05b6753..6dec179a 100644 --- a/README.md +++ b/README.md @@ -12,14 +12,3 @@ For publishing [the site](https://codehaus-plexus.github.io/plexus-io/) do the f ``` mvn -Preporting verify site-deploy ``` - -## Release Notes - -You can find details about the different releases in the -[Release Notes](https://github.com/codehaus-plexus/plexus-io/blob/master/ReleaseNotes.md). - - * [Release 3.2.0](https://github.com/codehaus-plexus/plexus-io/blob/master/ReleaseNotes.md#plexus-io-320). - * [Release 3.1.1](https://github.com/codehaus-plexus/plexus-io/blob/master/ReleaseNotes.md#plexus-io-311). - * [Release 3.1.0](https://github.com/codehaus-plexus/plexus-io/blob/master/ReleaseNotes.md#plexus-io-310). - * [Release 3.0.1](https://github.com/codehaus-plexus/plexus-io/blob/master/ReleaseNotes.md#plexus-io-301). - * [Release 3.0.0](https://github.com/codehaus-plexus/plexus-io/blob/master/ReleaseNotes.md#plexus-io-300). diff --git a/ReleaseNotes.md b/ReleaseNotes.md deleted file mode 100644 index 70c00952..00000000 --- a/ReleaseNotes.md +++ /dev/null @@ -1,243 +0,0 @@ -Plexus-IO Release Notes -======================================================================== - -Plexus IO 3.2.0 ---------------- - -Plexus IO 3.2.0 requires Java 7. - -### New Features - - * [Issue #18][issue-18] - Add an option to sort the entries of PlexusIoFileResourceCollection - -Plexus IO 3.1.1 ---------------- - -Plexus IO 3.1.1 requires Java 7. - -### Improvements - - * [Issue #16][issue-16], [Pull Request #17][pr-17] - Improve performance - on systems which have high time penalty when fetching owner and group name. - Thanks to Classe. - -Plexus IO 3.1.0 ---------------- - -Plexus IO 3.1.0 requires Java 7. - -### New Features - - * [Pull Request #14][pr-14] - Add new FileMapper for giving a suffix to filename: - `SuffixFileMapper`. Thanks to Thomas Collignon. - -Plexus IO 3.0.1 ---------------- - -Plexus IO 3.0.1 requires Java 7. - -### Tasks - - * [Issue #9][issue-9], [Issue #10][issue-10] - Updated dependencies: - `plexus-utils` to 3.1.0 and `commons-io` to 2.6 - -Plexus IO 3.0.0 ---------------- - -Plexus IO 3.0.0 requires Java 7 and introduces backward incompatible changes: - - * `Java7FileAttributes` is renamed to `FileAttributes`, replacing - the old `FileAttributes` implementation - * `Java7AttributeUtils` is renamed to `AttributeUtils` - * `PlexusIoResourceAttributeUtils#getFileAttributesByPath( File, boolean, boolean )` - is deleted - -### Improvements - - * [Pull Request #5][pr-5] - The required Java version is upgraded to 7. - Classes that use native tools like `ls` are removed and the pure Java - implementations are used instead. - -### Tasks - - * [Issue #8][issue-8] - Update of `plexus-utils` to 3.0.24 and - `commons-io` to 2.5 - -Plexus IO 2.7.1 ---------------- - -### Improvements - - * [Pull Request #3][pr-3] - Introduce new constant to indicate uknown - octal mode for resources - `PlexusIoResourceAttributes.UNKNOWN_OCTAL_MODE` - -### Bugs - - * [Issue #2][issue-2] - JAR entry not found when JAR is updated inline and - cached by URLConnection - -Plexus IO 2.7 ---------------- - -### Improvements - - * Added TIME_STYLE=long-iso to ls screen scrape - * [Pull Request #1][pr-1] - Add concurrent access flag - to the PlexusIoProxyResourceCollection - - `PlexusIoResourceCollection#isConcurrentAccessSupported()` - -Plexus IO 2.6.1 ---------------- - -### Improvement - - * Performance improvement affecting mac/linux users - with lots of small files in large archives. - -Plexus IO 2.5 -------------- - - * Proper support for closeable on zip archives. - * Removed zip supporting PlexusIoZipFileResourceCollection; which now exists in plexus-archiver. (Drop in replacement, - just change/add jar file). - -Plexus IO 2.4.1 ---------------- - -### Bugs - - * PLXCOMP-279 - PlexusIoProxyResourceCollection does not provide Closeable iterator - * Fixed PLXCOMP-280 - SimpleResourceAttributes has incorrect value for - default file mode - -Plexus IO 2.4 -------------- - -### Improvements - - * PLXCOMP-274 - Simplify use of proxies - * PLXCOMP-275 - Avoid leaky abstractions - * PLXCOMP-276 - Reduce number of ways to create a PlexusIoResource - -Plexus IO 2.3.5 ---------------- - -### Bugs - - * PLXCOMP-278 - Symlink attribute was not preserved through merged/overridden attributes - -Plexus IO 2.3.4 ---------------- - -### Bugs - - * PLXCOMP-270 - Escaping algoritghm leaks through to system classloader - * PLXCOMP-272 - Overriding dirmode/filemode breaks symlinks - -Plexus IO 2.3.3 ---------------- - -### Bugs - - * PLXCOMP-267 - StreamTransformers are consistently applied to all collections - -Plexus IO 2.3.2 ---------------- - -### Bugs - - * PLXCOMP-265 - Locale in shell influences "ls" parsing for screenscraper - -Plexus IO 2.3.1 ---------------- - -### Bugs - - * PLXCOMP-264 - Thread safety issue in streamconsumer - -Plexus IO 2.3 -------------- - -### New Features - - * PLXCOMP-261 - Make plexus io collections support on-the-fly filtering - -### Improvements - - * PLXCOMP-260 - Make plexus io collections iterable - -Plexus IO 2.2 -------------- - -### Bugs - - * PLXCOMP-251 - Date parsing in "ls" screenscraping has locale dependencies - * PLXCOMP-254 - Fix File.separatorChar normalization when prefixes are used - -Plexus IO 2.1.4 ---------------- - -### Improvements - - * PLXCOMP-250 - Upgrade maven-enforcer-plugin to 1.3.1 - -### Bugs - - * PLXCOMP-107 - Fail to unzip archive, which contains file with name - 'How_can_I_annotate_a_part_in_the_AAM%3F.Help' - -Plexus IO 2.1.3 ---------------- - -### Bugs - - * PLXCOMP-247 - Bug with windows AND java5 - -Plexus IO 2.1.2 ---------------- - -### Bugs - - * PLXCOMP-244 - Don't try to set attributes of symbolic links - * PLXCOMP-245 - Archives created on windows get zero permissions, - creates malformed permissions on linux - -Plexus IO 2.1.1 ---------------- - -### Bugs - - * PLXCOMP-243 - Restore JDK1.5 compatibility - -Plexus IO 2.1 -------------- - -### Improvements - - * PLXCOMP-64 - add symlink support to tar unarchiver - * PLXCOMP-117 - add symbolic links managment - -### Bugs - - * PLXCOMP-113 - zip unarchiver doesn't support symlinks (and trivial to fix) - * PLXCOMP-241 - ResourcesTest.compare test failure - * PLXCOMP-248 - Use java7 setAttributes and ignore useJvmChmod flag when applicable - -Plexus IO 2.0.12 ----------------- - -### Bugs - - * PLXCOMP-249 - Add support for java7 chmod - -[issue-2]: https://github.com/codehaus-plexus/plexus-io/issues/2 -[issue-8]: https://github.com/codehaus-plexus/plexus-io/issues/8 -[issue-9]: https://github.com/codehaus-plexus/plexus-io/issues/9 -[issue-10]: https://github.com/codehaus-plexus/plexus-io/issues/10 -[issue-16]: https://github.com/codehaus-plexus/plexus-io/issues/16 -[issue-18]: https://github.com/codehaus-plexus/plexus-io/issues/18 -[pr-1]: https://github.com/codehaus-plexus/plexus-io/pull/1 -[pr-3]: https://github.com/codehaus-plexus/plexus-io/pull/3 -[pr-5]: https://github.com/codehaus-plexus/plexus-io/pull/5 -[pr-14]: https://github.com/codehaus-plexus/plexus-io/pull/14 -[pr-17]: https://github.com/codehaus-plexus/plexus-io/pull/17 From 1ce4e4982337d8affdadfe14271aaadd92af9cd3 Mon Sep 17 00:00:00 2001 From: Guillaume Nodet Date: Mon, 9 Sep 2024 14:59:21 +0200 Subject: [PATCH 69/86] [maven-release-plugin] prepare release plexus-io-3.5.1 --- pom.xml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index 0db684f4..d2ef9432 100644 --- a/pom.xml +++ b/pom.xml @@ -9,14 +9,14 @@ plexus-io - 3.5.1-SNAPSHOT + 3.5.1 Plexus IO Components scm:git:git@github.com:codehaus-plexus/plexus-io.git scm:git:git@github.com:codehaus-plexus/plexus-io.git - HEAD + plexus-io-3.5.1 http://github.com/codehaus-plexus/plexus-io @@ -33,7 +33,7 @@ 0.9.0.M3 1.7.36 - 2024-07-04T12:26:13Z + 2024-09-09T12:59:16Z From 25283f2e1fe0984d5b7ada9025e3e614780fedcf Mon Sep 17 00:00:00 2001 From: Guillaume Nodet Date: Mon, 9 Sep 2024 14:59:25 +0200 Subject: [PATCH 70/86] [maven-release-plugin] prepare for next development iteration --- pom.xml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pom.xml b/pom.xml index d2ef9432..812b1f0d 100644 --- a/pom.xml +++ b/pom.xml @@ -9,14 +9,14 @@ plexus-io - 3.5.1 + 3.5.2-SNAPSHOT Plexus IO Components scm:git:git@github.com:codehaus-plexus/plexus-io.git scm:git:git@github.com:codehaus-plexus/plexus-io.git - plexus-io-3.5.1 + HEAD http://github.com/codehaus-plexus/plexus-io @@ -33,7 +33,7 @@ 0.9.0.M3 1.7.36 - 2024-09-09T12:59:16Z + 2024-09-09T12:59:25Z From 51c9d0d564c227e62f705b10647239fcb65b151d Mon Sep 17 00:00:00 2001 From: Tamas Cservenak Date: Mon, 9 Sep 2024 21:03:31 +0200 Subject: [PATCH 71/86] Add enjoy (testing write access) --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 6dec179a..421dc5a7 100644 --- a/README.md +++ b/README.md @@ -12,3 +12,5 @@ For publishing [the site](https://codehaus-plexus.github.io/plexus-io/) do the f ``` mvn -Preporting verify site-deploy ``` + +Enjoy! From 0ba5613c98df1b09a73ef5c0542a536979fb959a Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 19 Sep 2024 21:47:14 +0000 Subject: [PATCH 72/86] Bump commons-io:commons-io from 2.16.1 to 2.17.0 Bumps commons-io:commons-io from 2.16.1 to 2.17.0. --- updated-dependencies: - dependency-name: commons-io:commons-io dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 812b1f0d..1ecc064d 100644 --- a/pom.xml +++ b/pom.xml @@ -78,7 +78,7 @@ commons-io commons-io - 2.16.1 + 2.17.0 From fcdfbd84bbc0017c8100df36a54dd11e1484031e Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 24 Sep 2024 21:38:14 +0000 Subject: [PATCH 73/86] Bump org.codehaus.plexus:plexus-utils from 4.0.1 to 4.0.2 Bumps [org.codehaus.plexus:plexus-utils](https://github.com/codehaus-plexus/plexus-utils) from 4.0.1 to 4.0.2. - [Release notes](https://github.com/codehaus-plexus/plexus-utils/releases) - [Commits](https://github.com/codehaus-plexus/plexus-utils/compare/plexus-utils-4.0.1...plexus-utils-4.0.2) --- updated-dependencies: - dependency-name: org.codehaus.plexus:plexus-utils dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 1ecc064d..347e820b 100644 --- a/pom.xml +++ b/pom.xml @@ -61,7 +61,7 @@ org.codehaus.plexus plexus-utils - 4.0.1 + 4.0.2 org.codehaus.plexus From 367c0fbd9b336bb28ee0c9f49cbaa7a5e9d351a5 Mon Sep 17 00:00:00 2001 From: Sylwester Lachiewicz Date: Sun, 17 Nov 2024 18:50:40 +0100 Subject: [PATCH 74/86] Update site.xml to Doxia 2 --- src/site/site.xml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/site/site.xml b/src/site/site.xml index 6731ab96..c4497389 100644 --- a/src/site/site.xml +++ b/src/site/site.xml @@ -1,8 +1,8 @@ - + +

@@ -16,4 +16,4 @@ - + From 92fafb8c9ff5bdf33830ef83389ccfab6d720dc1 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 25 Sep 2024 21:08:38 +0000 Subject: [PATCH 75/86] Bump org.codehaus.plexus:plexus from 18 to 19 Bumps [org.codehaus.plexus:plexus](https://github.com/codehaus-plexus/plexus-pom) from 18 to 19. - [Release notes](https://github.com/codehaus-plexus/plexus-pom/releases) - [Commits](https://github.com/codehaus-plexus/plexus-pom/commits) --- updated-dependencies: - dependency-name: org.codehaus.plexus:plexus dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 347e820b..f81b5570 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ org.codehaus.plexus plexus - 18 + 19 plexus-io From 7e9b10f61916dbe227b1bdd368dc7db99f4f124f Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 19 Nov 2024 21:31:32 +0000 Subject: [PATCH 76/86] Bump commons-io:commons-io from 2.17.0 to 2.18.0 Bumps commons-io:commons-io from 2.17.0 to 2.18.0. --- updated-dependencies: - dependency-name: commons-io:commons-io dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index f81b5570..cdd21807 100644 --- a/pom.xml +++ b/pom.xml @@ -78,7 +78,7 @@ commons-io commons-io - 2.17.0 + 2.18.0 From 688b27c97cfa924163531d158b54966c31078ec9 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 7 Feb 2025 21:45:24 +0000 Subject: [PATCH 77/86] Bump org.codehaus.plexus:plexus from 19 to 20 Bumps [org.codehaus.plexus:plexus](https://github.com/codehaus-plexus/plexus-pom) from 19 to 20. - [Release notes](https://github.com/codehaus-plexus/plexus-pom/releases) - [Commits](https://github.com/codehaus-plexus/plexus-pom/commits) --- updated-dependencies: - dependency-name: org.codehaus.plexus:plexus dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index cdd21807..72a84c58 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ org.codehaus.plexus plexus - 19 + 20 plexus-io From 94494e5ee573cfd82841664fb3040d0f26e55f43 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 7 Apr 2025 22:46:08 +0000 Subject: [PATCH 78/86] Bump org.codehaus.plexus:plexus-testing from 1.4.0 to 1.5.0 Bumps [org.codehaus.plexus:plexus-testing](https://github.com/codehaus-plexus/plexus-testing) from 1.4.0 to 1.5.0. - [Release notes](https://github.com/codehaus-plexus/plexus-testing/releases) - [Commits](https://github.com/codehaus-plexus/plexus-testing/compare/plexus-testing-1.4.0...plexus-testing-1.5.0) --- updated-dependencies: - dependency-name: org.codehaus.plexus:plexus-testing dependency-version: 1.5.0 dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 72a84c58..7d24f97d 100644 --- a/pom.xml +++ b/pom.xml @@ -96,7 +96,7 @@ org.codehaus.plexus plexus-testing - 1.4.0 + 1.5.0 test From 8564e4ef00571ca7d6365f2cc811c72db431a445 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 14 Apr 2025 21:13:36 +0000 Subject: [PATCH 79/86] Bump commons-io:commons-io from 2.18.0 to 2.19.0 Bumps commons-io:commons-io from 2.18.0 to 2.19.0. --- updated-dependencies: - dependency-name: commons-io:commons-io dependency-version: 2.19.0 dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 7d24f97d..1b9d062b 100644 --- a/pom.xml +++ b/pom.xml @@ -78,7 +78,7 @@ commons-io commons-io - 2.18.0 + 2.19.0 From 7a0f45e624deb6f3324c594a8fa784a6d5cef6c5 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 23 May 2025 21:19:46 +0000 Subject: [PATCH 80/86] Bump org.codehaus.plexus:plexus from 20 to 21 Bumps [org.codehaus.plexus:plexus](https://github.com/codehaus-plexus/plexus-pom) from 20 to 21. - [Release notes](https://github.com/codehaus-plexus/plexus-pom/releases) - [Commits](https://github.com/codehaus-plexus/plexus-pom/commits) --- updated-dependencies: - dependency-name: org.codehaus.plexus:plexus dependency-version: '21' dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 1b9d062b..7ff3dad4 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ org.codehaus.plexus plexus - 20 + 21 plexus-io From 2e657cdf48b1673c38cdd81d6f794c01ac75ff48 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 20 May 2025 21:07:31 +0000 Subject: [PATCH 81/86] Bump eclipseSisuVersion from 0.9.0.M3 to 0.9.0.M4 Bumps `eclipseSisuVersion` from 0.9.0.M3 to 0.9.0.M4. Updates `org.eclipse.sisu:org.eclipse.sisu.inject` from 0.9.0.M3 to 0.9.0.M4 - [Release notes](https://github.com/eclipse-sisu/sisu-project/releases) - [Changelog](https://github.com/eclipse-sisu/sisu-project/blob/main/RELEASE.md) - [Commits](https://github.com/eclipse-sisu/sisu-project/compare/milestones/0.9.0.M3...milestones/0.9.0.M4) Updates `org.eclipse.sisu:org.eclipse.sisu.plexus` from 0.9.0.M3 to 0.9.0.M4 - [Release notes](https://github.com/eclipse-sisu/sisu-project/releases) - [Changelog](https://github.com/eclipse-sisu/sisu-project/blob/main/RELEASE.md) - [Commits](https://github.com/eclipse-sisu/sisu-project/compare/milestones/0.9.0.M3...milestones/0.9.0.M4) --- updated-dependencies: - dependency-name: org.eclipse.sisu:org.eclipse.sisu.inject dependency-version: 0.9.0.M4 dependency-type: direct:development update-type: version-update:semver-patch - dependency-name: org.eclipse.sisu:org.eclipse.sisu.plexus dependency-version: 0.9.0.M4 dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 7ff3dad4..1e71f3c2 100644 --- a/pom.xml +++ b/pom.xml @@ -31,7 +31,7 @@ - 0.9.0.M3 + 0.9.0.M4 1.7.36 2024-09-09T12:59:25Z From c61eb27d204611ca482a76e62f54f8e7086be747 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 2 Jun 2025 21:24:02 +0000 Subject: [PATCH 82/86] Bump org.codehaus.plexus:plexus from 21 to 22 Bumps [org.codehaus.plexus:plexus](https://github.com/codehaus-plexus/plexus-pom) from 21 to 22. - [Release notes](https://github.com/codehaus-plexus/plexus-pom/releases) - [Commits](https://github.com/codehaus-plexus/plexus-pom/commits) --- updated-dependencies: - dependency-name: org.codehaus.plexus:plexus dependency-version: '22' dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 1e71f3c2..d411831d 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ org.codehaus.plexus plexus - 21 + 22 plexus-io From a8156b2e57ed2ed611b297415b896b41773eb6ca Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 18 Jul 2025 21:58:12 +0000 Subject: [PATCH 83/86] Bump commons-io:commons-io from 2.19.0 to 2.20.0 Bumps [commons-io:commons-io](https://github.com/apache/commons-io) from 2.19.0 to 2.20.0. - [Changelog](https://github.com/apache/commons-io/blob/master/RELEASE-NOTES.txt) - [Commits](https://github.com/apache/commons-io/compare/rel/commons-io-2.19.0...rel/commons-io-2.20.0) --- updated-dependencies: - dependency-name: commons-io:commons-io dependency-version: 2.20.0 dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index d411831d..c8810df3 100644 --- a/pom.xml +++ b/pom.xml @@ -78,7 +78,7 @@ commons-io commons-io - 2.19.0 + 2.20.0 From 436706a0ae68799b408ba972ce6a8e1b49a211c8 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 19 Aug 2025 07:34:51 +0000 Subject: [PATCH 84/86] Bump org.codehaus.plexus:plexus-testing from 1.5.0 to 1.6.0 Bumps [org.codehaus.plexus:plexus-testing](https://github.com/codehaus-plexus/plexus-testing) from 1.5.0 to 1.6.0. - [Release notes](https://github.com/codehaus-plexus/plexus-testing/releases) - [Commits](https://github.com/codehaus-plexus/plexus-testing/compare/plexus-testing-1.5.0...plexus-testing-1.6.0) --- updated-dependencies: - dependency-name: org.codehaus.plexus:plexus-testing dependency-version: 1.6.0 dependency-type: direct:development update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index c8810df3..b9e644f4 100644 --- a/pom.xml +++ b/pom.xml @@ -96,7 +96,7 @@ org.codehaus.plexus plexus-testing - 1.5.0 + 1.6.0 test From c3ca2c0fed16fb5033f2b4f5191869e48a2a2387 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 19 Aug 2025 07:24:37 +0000 Subject: [PATCH 85/86] Bump org.codehaus.plexus:plexus from 22 to 23 Bumps [org.codehaus.plexus:plexus](https://github.com/codehaus-plexus/plexus-pom) from 22 to 23. - [Release notes](https://github.com/codehaus-plexus/plexus-pom/releases) - [Commits](https://github.com/codehaus-plexus/plexus-pom/commits) --- updated-dependencies: - dependency-name: org.codehaus.plexus:plexus dependency-version: '23' dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index b9e644f4..8d505e40 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ org.codehaus.plexus plexus - 22 + 23 plexus-io From 499f757e3f8e782dd766fe9edf56bfd00faefe88 Mon Sep 17 00:00:00 2001 From: Sylwester Lachiewicz Date: Sat, 6 Sep 2025 20:39:06 +0200 Subject: [PATCH 86/86] Cleanup dependencies --- pom.xml | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/pom.xml b/pom.xml index 8d505e40..517106bc 100644 --- a/pom.xml +++ b/pom.xml @@ -61,13 +61,7 @@ org.codehaus.plexus plexus-utils - 4.0.2 - - - org.codehaus.plexus - plexus-xml - 3.0.1 - test + 3.6.0 com.google.code.findbugs @@ -105,12 +99,6 @@ org.eclipse.sisu.inject test - - com.google.inject - guice - 6.0.0 - test -