You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by el...@apache.org on 2023/03/12 22:27:46 UTC
[maven-file-management] 01/01: update to parent pom 39
This is an automated email from the ASF dual-hosted git repository.
elharo pushed a commit to branch update
in repository https://gitbox.apache.org/repos/asf/maven-file-management.git
commit d0cd50f9bf37b0954f2e14452aa15321fe1b1e50
Author: Elliotte Rusty Harold <el...@ibiblio.org>
AuthorDate: Sun Mar 12 18:27:35 2023 -0400
update to parent pom 39
---
pom.xml | 12 +-
.../model/fileset/mappers/FileNameMapper.java | 12 +-
.../model/fileset/mappers/FlatFileNameMapper.java | 18 +-
.../model/fileset/mappers/GlobPatternMapper.java | 75 ++--
.../model/fileset/mappers/IdentityMapper.java | 16 +-
.../model/fileset/mappers/MapperException.java | 17 +-
.../shared/model/fileset/mappers/MapperUtil.java | 82 ++--
.../model/fileset/mappers/MergingMapper.java | 16 +-
.../model/fileset/mappers/PackageNameMapper.java | 14 +-
.../model/fileset/mappers/RegexpPatternMapper.java | 27 +-
.../model/fileset/mappers/UnPackageNameMapper.java | 14 +-
.../shared/model/fileset/util/FileSetManager.java | 426 ++++++++-------------
.../model/fileset/mappers/MapperUtilTest.java | 85 ++--
.../model/fileset/util/FileSetUtilsTest.java | 287 +++++++-------
14 files changed, 448 insertions(+), 653 deletions(-)
diff --git a/pom.xml b/pom.xml
index bc236f8..bac0142 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1,5 +1,4 @@
-<?xml version='1.0' encoding='UTF-8'?>
-
+<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
@@ -18,7 +17,6 @@
specific language governing permissions and limitations
under the License.
-->
-
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
@@ -26,7 +24,7 @@
<parent>
<groupId>org.apache.maven.shared</groupId>
<artifactId>maven-shared-components</artifactId>
- <version>36</version>
+ <version>39</version>
<relativePath />
</parent>
@@ -46,8 +44,8 @@
<scm>
<connection>scm:git:https://gitbox.apache.org/repos/asf/maven-file-management.git</connection>
<developerConnection>scm:git:https://gitbox.apache.org/repos/asf/maven-file-management.git</developerConnection>
- <url>https://github.com/apache/maven-file-management/tree/${project.scm.tag}</url>
<tag>HEAD</tag>
+ <url>https://github.com/apache/maven-file-management/tree/${project.scm.tag}</url>
</scm>
<issueManagement>
<system>jira</system>
@@ -79,7 +77,7 @@
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-utils</artifactId>
- <version>3.4.2</version>
+ <version>3.5.1</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
@@ -124,10 +122,10 @@
</execution>
<execution>
<id>site-docs</id>
- <phase>pre-site</phase>
<goals>
<goal>xdoc</goal>
</goals>
+ <phase>pre-site</phase>
</execution>
</executions>
</plugin>
diff --git a/src/main/java/org/apache/maven/shared/model/fileset/mappers/FileNameMapper.java b/src/main/java/org/apache/maven/shared/model/fileset/mappers/FileNameMapper.java
index f75c037..ce5a7bd 100644
--- a/src/main/java/org/apache/maven/shared/model/fileset/mappers/FileNameMapper.java
+++ b/src/main/java/org/apache/maven/shared/model/fileset/mappers/FileNameMapper.java
@@ -1,5 +1,3 @@
-package org.apache.maven.shared.model.fileset.mappers;
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -18,6 +16,7 @@ package org.apache.maven.shared.model.fileset.mappers;
* specific language governing permissions and limitations
* under the License.
*/
+package org.apache.maven.shared.model.fileset.mappers;
/**
* Interface used by SourceFileScanner
@@ -28,21 +27,20 @@ package org.apache.maven.shared.model.fileset.mappers;
* via the setFrom and setTo methods. The exact meaning of these is
* implementation dependent.</p>
*/
-public interface FileNameMapper
-{
+public interface FileNameMapper {
/**
* Sets the from part of the transformation rule.
*
* @param from the source
*/
- void setFrom( String from );
+ void setFrom(String from);
/**
* Sets the to part of the transformation rule.
*
* @param to the destination
*/
- void setTo( String to );
+ void setTo(String to);
/**
* Returns the target filename for the
@@ -55,5 +53,5 @@ public interface FileNameMapper
* @param sourceFileName the name of the source file relative to some given base directory
* @return the target filename for the given source file
*/
- String mapFileName( String sourceFileName );
+ String mapFileName(String sourceFileName);
}
diff --git a/src/main/java/org/apache/maven/shared/model/fileset/mappers/FlatFileNameMapper.java b/src/main/java/org/apache/maven/shared/model/fileset/mappers/FlatFileNameMapper.java
index c57bb3b..5cccee5 100644
--- a/src/main/java/org/apache/maven/shared/model/fileset/mappers/FlatFileNameMapper.java
+++ b/src/main/java/org/apache/maven/shared/model/fileset/mappers/FlatFileNameMapper.java
@@ -1,5 +1,3 @@
-package org.apache.maven.shared.model.fileset.mappers;
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -18,6 +16,7 @@ package org.apache.maven.shared.model.fileset.mappers;
* specific language governing permissions and limitations
* under the License.
*/
+package org.apache.maven.shared.model.fileset.mappers;
import java.io.File;
@@ -28,24 +27,19 @@ import java.io.File;
* <p>This is the default FileNameMapper for the copy and move
* tasks if the flatten attribute has been set.</p>
*/
-public class FlatFileNameMapper
- implements FileNameMapper
-{
+public class FlatFileNameMapper implements FileNameMapper {
@Override
- public void setFrom( String from )
- {
+ public void setFrom(String from) {
// nop
}
@Override
- public void setTo( String to )
- {
+ public void setTo(String to) {
// nop
}
@Override
- public String mapFileName( String sourceFileName )
- {
- return new File( sourceFileName ).getName();
+ public String mapFileName(String sourceFileName) {
+ return new File(sourceFileName).getName();
}
}
diff --git a/src/main/java/org/apache/maven/shared/model/fileset/mappers/GlobPatternMapper.java b/src/main/java/org/apache/maven/shared/model/fileset/mappers/GlobPatternMapper.java
index a3c0fdd..3804ddb 100644
--- a/src/main/java/org/apache/maven/shared/model/fileset/mappers/GlobPatternMapper.java
+++ b/src/main/java/org/apache/maven/shared/model/fileset/mappers/GlobPatternMapper.java
@@ -1,5 +1,3 @@
-package org.apache.maven.shared.model.fileset.mappers;
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -18,6 +16,7 @@ package org.apache.maven.shared.model.fileset.mappers;
* specific language governing permissions and limitations
* under the License.
*/
+package org.apache.maven.shared.model.fileset.mappers;
/**
* Implementation of FileNameMapper that does simple wildcard pattern
@@ -31,9 +30,7 @@ package org.apache.maven.shared.model.fileset.mappers;
* <p>This is one of the more useful Mappers, it is used by <code>javac</code> for
* example.</p>
*/
-public class GlobPatternMapper
- implements FileNameMapper
-{
+public class GlobPatternMapper implements FileNameMapper {
/**
* Part of "from" pattern before the *.
*/
@@ -73,8 +70,7 @@ public class GlobPatternMapper
* between / and \ (the two common directory characters).
* @param handleDirSep a boolean, default is false.
*/
- public void setHandleDirSep( boolean handleDirSep )
- {
+ public void setHandleDirSep(boolean handleDirSep) {
this.handleDirSep = handleDirSep;
}
@@ -84,54 +80,44 @@ public class GlobPatternMapper
*
* @param caseSensitive a boolean, default is false.
*/
- public void setCaseSensitive( boolean caseSensitive )
- {
+ public void setCaseSensitive(boolean caseSensitive) {
this.caseSensitive = caseSensitive;
}
@Override
- public void setFrom( String from )
- {
- int index = from.lastIndexOf( "*" );
- if ( index == -1 )
- {
+ public void setFrom(String from) {
+ int index = from.lastIndexOf("*");
+ if (index == -1) {
fromPrefix = from;
fromPostfix = "";
- }
- else
- {
- fromPrefix = from.substring( 0, index );
- fromPostfix = from.substring( index + 1 );
+ } else {
+ fromPrefix = from.substring(0, index);
+ fromPostfix = from.substring(index + 1);
}
prefixLength = fromPrefix.length();
postfixLength = fromPostfix.length();
}
@Override
- public void setTo( String to )
- {
- int index = to.lastIndexOf( "*" );
- if ( index == -1 )
- {
+ public void setTo(String to) {
+ int index = to.lastIndexOf("*");
+ if (index == -1) {
toPrefix = to;
toPostfix = "";
- }
- else
- {
- toPrefix = to.substring( 0, index );
- toPostfix = to.substring( index + 1 );
+ } else {
+ toPrefix = to.substring(0, index);
+ toPostfix = to.substring(index + 1);
}
}
@Override
- public String mapFileName( String sourceFileName )
- {
- if ( fromPrefix == null || !modifyName( sourceFileName ).startsWith( modifyName( fromPrefix ) )
- || !modifyName( sourceFileName ).endsWith( modifyName( fromPostfix ) ) )
- {
+ public String mapFileName(String sourceFileName) {
+ if (fromPrefix == null
+ || !modifyName(sourceFileName).startsWith(modifyName(fromPrefix))
+ || !modifyName(sourceFileName).endsWith(modifyName(fromPostfix))) {
return null;
}
- return toPrefix + extractVariablePart( sourceFileName ) + toPostfix;
+ return toPrefix + extractVariablePart(sourceFileName) + toPostfix;
}
/**
@@ -140,9 +126,8 @@ public class GlobPatternMapper
* @param name the source file name
* @return the variable part of the name
*/
- protected String extractVariablePart( String name )
- {
- return name.substring( prefixLength, name.length() - postfixLength );
+ protected String extractVariablePart(String name) {
+ return name.substring(prefixLength, name.length() - postfixLength);
}
/**
@@ -150,17 +135,13 @@ public class GlobPatternMapper
* @param name the name to convert
* @return the converted name
*/
- private String modifyName( String name )
- {
- if ( !caseSensitive )
- {
+ private String modifyName(String name) {
+ if (!caseSensitive) {
name = name.toLowerCase();
}
- if ( handleDirSep )
- {
- if ( name.indexOf( '\\' ) != -1 )
- {
- name = name.replace( '\\', '/' );
+ if (handleDirSep) {
+ if (name.indexOf('\\') != -1) {
+ name = name.replace('\\', '/');
}
}
return name;
diff --git a/src/main/java/org/apache/maven/shared/model/fileset/mappers/IdentityMapper.java b/src/main/java/org/apache/maven/shared/model/fileset/mappers/IdentityMapper.java
index ab1d3ce..8bf6d0e 100644
--- a/src/main/java/org/apache/maven/shared/model/fileset/mappers/IdentityMapper.java
+++ b/src/main/java/org/apache/maven/shared/model/fileset/mappers/IdentityMapper.java
@@ -1,5 +1,3 @@
-package org.apache.maven.shared.model.fileset.mappers;
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -18,6 +16,7 @@ package org.apache.maven.shared.model.fileset.mappers;
* specific language governing permissions and limitations
* under the License.
*/
+package org.apache.maven.shared.model.fileset.mappers;
/**
* Implementation of FileNameMapper that always returns the source file name.
@@ -25,24 +24,19 @@ package org.apache.maven.shared.model.fileset.mappers;
* <p>This is the default FileNameMapper for the copy and move
* tasks.</p>
*/
-public class IdentityMapper
- implements FileNameMapper
-{
+public class IdentityMapper implements FileNameMapper {
@Override
- public void setFrom( String from )
- {
+ public void setFrom(String from) {
// nop
}
@Override
- public void setTo( String to )
- {
+ public void setTo(String to) {
// nop
}
@Override
- public String mapFileName( String sourceFileName )
- {
+ public String mapFileName(String sourceFileName) {
return sourceFileName;
}
}
diff --git a/src/main/java/org/apache/maven/shared/model/fileset/mappers/MapperException.java b/src/main/java/org/apache/maven/shared/model/fileset/mappers/MapperException.java
index b94ea9c..25ae79c 100644
--- a/src/main/java/org/apache/maven/shared/model/fileset/mappers/MapperException.java
+++ b/src/main/java/org/apache/maven/shared/model/fileset/mappers/MapperException.java
@@ -1,5 +1,3 @@
-package org.apache.maven.shared.model.fileset.mappers;
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -18,13 +16,12 @@ package org.apache.maven.shared.model.fileset.mappers;
* specific language governing permissions and limitations
* under the License.
*/
+package org.apache.maven.shared.model.fileset.mappers;
/**
* Mapper Exception
*/
-public class MapperException
- extends Exception
-{
+public class MapperException extends Exception {
static final long serialVersionUID = 20064059145045044L;
/**
@@ -33,9 +30,8 @@ public class MapperException
* @param message The error message
* @param cause The root cause of the problem.
*/
- public MapperException( String message, Throwable cause )
- {
- super( message, cause );
+ public MapperException(String message, Throwable cause) {
+ super(message, cause);
}
/**
@@ -43,8 +39,7 @@ public class MapperException
*
* @param message The error message.
*/
- public MapperException( String message )
- {
- super( message );
+ public MapperException(String message) {
+ super(message);
}
}
diff --git a/src/main/java/org/apache/maven/shared/model/fileset/mappers/MapperUtil.java b/src/main/java/org/apache/maven/shared/model/fileset/mappers/MapperUtil.java
index 852f0ac..9d8b675 100644
--- a/src/main/java/org/apache/maven/shared/model/fileset/mappers/MapperUtil.java
+++ b/src/main/java/org/apache/maven/shared/model/fileset/mappers/MapperUtil.java
@@ -1,5 +1,3 @@
-package org.apache.maven.shared.model.fileset.mappers;
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -18,51 +16,44 @@ package org.apache.maven.shared.model.fileset.mappers;
* specific language governing permissions and limitations
* under the License.
*/
-
-import org.apache.maven.shared.model.fileset.Mapper;
+package org.apache.maven.shared.model.fileset.mappers;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
+import org.apache.maven.shared.model.fileset.Mapper;
+
/**
* Element to define a FileNameMapper.
*/
-public final class MapperUtil
-{
+public final class MapperUtil {
private static final String MAPPER_PROPERTIES = "mappers.properties";
private static Properties implementations;
- private MapperUtil()
- {
+ private MapperUtil() {
// nop
}
/**
* Initializes a properties object to store the built-in classnames.
*/
- private static void initializeBuiltIns()
- {
- if ( implementations == null )
- {
+ private static void initializeBuiltIns() {
+ if (implementations == null) {
Properties props = new Properties();
ClassLoader cloader = Thread.currentThread().getContextClassLoader();
- try ( InputStream stream = cloader.getResourceAsStream( MAPPER_PROPERTIES ) )
- {
- if ( stream == null )
- {
- throw new IllegalStateException( "Cannot find classpath resource: " + MAPPER_PROPERTIES );
+ try (InputStream stream = cloader.getResourceAsStream(MAPPER_PROPERTIES)) {
+ if (stream == null) {
+ throw new IllegalStateException("Cannot find classpath resource: " + MAPPER_PROPERTIES);
}
- props.load( stream );
+ props.load(stream);
implementations = props;
- }
- catch ( IOException e )
- {
- throw new IllegalStateException( "Cannot find classpath resource: " + MAPPER_PROPERTIES );
+ } catch (IOException e) {
+ throw new IllegalStateException("Cannot find classpath resource: " + MAPPER_PROPERTIES);
}
}
}
@@ -74,11 +65,8 @@ public final class MapperUtil
* @return {@link FileNameMapper}
* @throws MapperException in case of an error
*/
- public static FileNameMapper getFileNameMapper( Mapper mapper )
- throws MapperException
- {
- if ( mapper == null )
- {
+ public static FileNameMapper getFileNameMapper(Mapper mapper) throws MapperException {
+ if (mapper == null) {
return null;
}
@@ -87,37 +75,31 @@ public final class MapperUtil
String type = mapper.getType();
String classname = mapper.getClassname();
- if ( type == null && classname == null )
- {
- throw new MapperException( "nested mapper or " + "one of the attributes type or classname is required" );
+ if (type == null && classname == null) {
+ throw new MapperException("nested mapper or " + "one of the attributes type or classname is required");
}
- if ( type != null && classname != null )
- {
- throw new MapperException( "must not specify both type and classname attribute" );
+ if (type != null && classname != null) {
+ throw new MapperException("must not specify both type and classname attribute");
}
- if ( type != null )
- {
- classname = implementations.getProperty( type );
+ if (type != null) {
+ classname = implementations.getProperty(type);
}
- try
- {
- FileNameMapper m =
- (FileNameMapper) Thread.currentThread().getContextClassLoader().loadClass( classname ).newInstance();
+ try {
+ FileNameMapper m = (FileNameMapper) Thread.currentThread()
+ .getContextClassLoader()
+ .loadClass(classname)
+ .newInstance();
- m.setFrom( mapper.getFrom() );
- m.setTo( mapper.getTo() );
+ m.setFrom(mapper.getFrom());
+ m.setTo(mapper.getTo());
return m;
- }
- catch ( ClassNotFoundException e )
- {
- throw new MapperException( "Cannot find mapper implementation: " + classname, e );
- }
- catch ( InstantiationException | IllegalAccessException e )
- {
- throw new MapperException( "Cannot load mapper implementation: " + classname, e );
+ } catch (ClassNotFoundException e) {
+ throw new MapperException("Cannot find mapper implementation: " + classname, e);
+ } catch (InstantiationException | IllegalAccessException e) {
+ throw new MapperException("Cannot load mapper implementation: " + classname, e);
}
}
}
diff --git a/src/main/java/org/apache/maven/shared/model/fileset/mappers/MergingMapper.java b/src/main/java/org/apache/maven/shared/model/fileset/mappers/MergingMapper.java
index 4967bfa..c889a0d 100644
--- a/src/main/java/org/apache/maven/shared/model/fileset/mappers/MergingMapper.java
+++ b/src/main/java/org/apache/maven/shared/model/fileset/mappers/MergingMapper.java
@@ -1,5 +1,3 @@
-package org.apache.maven.shared.model.fileset.mappers;
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -18,6 +16,7 @@ package org.apache.maven.shared.model.fileset.mappers;
* specific language governing permissions and limitations
* under the License.
*/
+package org.apache.maven.shared.model.fileset.mappers;
/**
* Implementation of FileNameMapper that always returns the same
@@ -26,26 +25,21 @@ package org.apache.maven.shared.model.fileset.mappers;
* <p>This is the default FileNameMapper for the archiving tasks and
* up-to-date.</p>
*/
-public class MergingMapper
- implements FileNameMapper
-{
+public class MergingMapper implements FileNameMapper {
private String mergedFile = null;
@Override
- public void setFrom( String from )
- {
+ public void setFrom(String from) {
// nop
}
@Override
- public void setTo( String to )
- {
+ public void setTo(String to) {
mergedFile = to;
}
@Override
- public String mapFileName( String sourceFileName )
- {
+ public String mapFileName(String sourceFileName) {
return mergedFile;
}
}
diff --git a/src/main/java/org/apache/maven/shared/model/fileset/mappers/PackageNameMapper.java b/src/main/java/org/apache/maven/shared/model/fileset/mappers/PackageNameMapper.java
index 70bb816..77569c0 100644
--- a/src/main/java/org/apache/maven/shared/model/fileset/mappers/PackageNameMapper.java
+++ b/src/main/java/org/apache/maven/shared/model/fileset/mappers/PackageNameMapper.java
@@ -1,5 +1,3 @@
-package org.apache.maven.shared.model.fileset.mappers;
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -18,6 +16,7 @@ package org.apache.maven.shared.model.fileset.mappers;
* specific language governing permissions and limitations
* under the License.
*/
+package org.apache.maven.shared.model.fileset.mappers;
import java.io.File;
@@ -30,13 +29,10 @@ import java.io.File;
* from="*Test.java" to="${test.data.dir}/TEST-*Test.xml"/>
* </pre>
*/
-public class PackageNameMapper
- extends GlobPatternMapper
-{
+public class PackageNameMapper extends GlobPatternMapper {
@Override
- protected String extractVariablePart( String name )
- {
- String var = name.substring( prefixLength, name.length() - postfixLength );
- return var.replace( File.separatorChar, '.' );
+ protected String extractVariablePart(String name) {
+ String var = name.substring(prefixLength, name.length() - postfixLength);
+ return var.replace(File.separatorChar, '.');
}
}
diff --git a/src/main/java/org/apache/maven/shared/model/fileset/mappers/RegexpPatternMapper.java b/src/main/java/org/apache/maven/shared/model/fileset/mappers/RegexpPatternMapper.java
index d01c1f9..cd353c7 100644
--- a/src/main/java/org/apache/maven/shared/model/fileset/mappers/RegexpPatternMapper.java
+++ b/src/main/java/org/apache/maven/shared/model/fileset/mappers/RegexpPatternMapper.java
@@ -1,5 +1,3 @@
-package org.apache.maven.shared.model.fileset.mappers;
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -18,43 +16,38 @@ package org.apache.maven.shared.model.fileset.mappers;
* specific language governing permissions and limitations
* under the License.
*/
+package org.apache.maven.shared.model.fileset.mappers;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* Implementation of RegexpPatternMapper that returns either the source file
- * name or it processed by a matching Regular Expression and its replacement.
+ * name or it processed by a matching Regular Expression and its replacement.
*
* <p>This is a RegexpPatternMapper for the copy and move tasks.</p>
*/
-public class RegexpPatternMapper
- implements FileNameMapper
-{
+public class RegexpPatternMapper implements FileNameMapper {
private Pattern fromPattern;
private String toReplaceExpression;
@Override
- public void setFrom( String from )
- {
- this.fromPattern = Pattern.compile( from );
+ public void setFrom(String from) {
+ this.fromPattern = Pattern.compile(from);
}
@Override
- public void setTo( String to )
- {
+ public void setTo(String to) {
this.toReplaceExpression = to;
}
@Override
- public String mapFileName( String sourceFileName )
- {
- Matcher matcher = this.fromPattern.matcher( sourceFileName );
- if ( !matcher.find( ) )
- {
+ public String mapFileName(String sourceFileName) {
+ Matcher matcher = this.fromPattern.matcher(sourceFileName);
+ if (!matcher.find()) {
return sourceFileName;
}
- return matcher.replaceFirst( this.toReplaceExpression );
+ return matcher.replaceFirst(this.toReplaceExpression);
}
}
diff --git a/src/main/java/org/apache/maven/shared/model/fileset/mappers/UnPackageNameMapper.java b/src/main/java/org/apache/maven/shared/model/fileset/mappers/UnPackageNameMapper.java
index dc5f3fd..3b3d170 100644
--- a/src/main/java/org/apache/maven/shared/model/fileset/mappers/UnPackageNameMapper.java
+++ b/src/main/java/org/apache/maven/shared/model/fileset/mappers/UnPackageNameMapper.java
@@ -1,5 +1,3 @@
-package org.apache.maven.shared.model.fileset.mappers;
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -18,6 +16,7 @@ package org.apache.maven.shared.model.fileset.mappers;
* specific language governing permissions and limitations
* under the License.
*/
+package org.apache.maven.shared.model.fileset.mappers;
import java.io.File;
@@ -31,13 +30,10 @@ import java.io.File;
* from="${test.data.dir}/TEST-*Test.xml" to="*Test.java">
* </pre>
*/
-public class UnPackageNameMapper
- extends GlobPatternMapper
-{
+public class UnPackageNameMapper extends GlobPatternMapper {
@Override
- protected String extractVariablePart( String name )
- {
- String var = name.substring( prefixLength, name.length() - postfixLength );
- return var.replace( '.', File.separatorChar );
+ protected String extractVariablePart(String name) {
+ String var = name.substring(prefixLength, name.length() - postfixLength);
+ return var.replace('.', File.separatorChar);
}
}
diff --git a/src/main/java/org/apache/maven/shared/model/fileset/util/FileSetManager.java b/src/main/java/org/apache/maven/shared/model/fileset/util/FileSetManager.java
index 3016b80..6e597ac 100644
--- a/src/main/java/org/apache/maven/shared/model/fileset/util/FileSetManager.java
+++ b/src/main/java/org/apache/maven/shared/model/fileset/util/FileSetManager.java
@@ -1,5 +1,3 @@
-package org.apache.maven.shared.model.fileset.util;
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -18,6 +16,7 @@ package org.apache.maven.shared.model.fileset.util;
* specific language governing permissions and limitations
* under the License.
*/
+package org.apache.maven.shared.model.fileset.util;
import java.io.File;
import java.io.IOException;
@@ -48,8 +47,7 @@ import static java.util.Objects.requireNonNull;
*
* @author jdcasey
*/
-public class FileSetManager
-{
+public class FileSetManager {
private static final String[] EMPTY_STRING_ARRAY = new String[0];
private final boolean verbose;
@@ -66,9 +64,8 @@ public class FileSetManager
* @param logger the logger instance
* @param verbose whether to output verbose messages
*/
- public FileSetManager( Logger logger, boolean verbose )
- {
- this.logger = requireNonNull( logger );
+ public FileSetManager(Logger logger, boolean verbose) {
+ this.logger = requireNonNull(logger);
this.verbose = verbose;
}
@@ -77,17 +74,15 @@ public class FileSetManager
*
* @param logger The log instance
*/
- public FileSetManager( Logger logger )
- {
- this( logger, false );
+ public FileSetManager(Logger logger) {
+ this(logger, false);
}
/**
* Create a new manager instance with an own logger. Verbose flag is set to false.
*/
- public FileSetManager()
- {
- this( LoggerFactory.getLogger( FileSetManager.class ), false );
+ public FileSetManager() {
+ this(LoggerFactory.getLogger(FileSetManager.class), false);
}
// ----------------------------------------------------------------------
@@ -100,27 +95,21 @@ public class FileSetManager
* @throws MapperException if any
* @see #getIncludedFiles(FileSet)
*/
- public Map<String, String> mapIncludedFiles( FileSet fileSet )
- throws MapperException
- {
- String[] sourcePaths = getIncludedFiles( fileSet );
+ public Map<String, String> mapIncludedFiles(FileSet fileSet) throws MapperException {
+ String[] sourcePaths = getIncludedFiles(fileSet);
Map<String, String> mappedPaths = new LinkedHashMap<>();
- FileNameMapper fileMapper = MapperUtil.getFileNameMapper( fileSet.getMapper() );
+ FileNameMapper fileMapper = MapperUtil.getFileNameMapper(fileSet.getMapper());
- for ( String sourcePath : sourcePaths )
- {
+ for (String sourcePath : sourcePaths) {
String destPath;
- if ( fileMapper != null )
- {
- destPath = fileMapper.mapFileName( sourcePath );
- }
- else
- {
+ if (fileMapper != null) {
+ destPath = fileMapper.mapFileName(sourcePath);
+ } else {
destPath = sourcePath;
}
- mappedPaths.put( sourcePath, destPath );
+ mappedPaths.put(sourcePath, destPath);
}
return mappedPaths;
@@ -132,12 +121,10 @@ public class FileSetManager
* @param fileSet The fileset defining rules for inclusion/exclusion, and base directory.
* @return the array of matching filenames, relative to the basedir of the file-set.
*/
- public String[] getIncludedFiles( FileSet fileSet )
- {
- DirectoryScanner scanner = scan( fileSet );
+ public String[] getIncludedFiles(FileSet fileSet) {
+ DirectoryScanner scanner = scan(fileSet);
- if ( scanner != null )
- {
+ if (scanner != null) {
return scanner.getIncludedFiles();
}
@@ -150,12 +137,10 @@ public class FileSetManager
* @param fileSet The fileset defining rules for inclusion/exclusion, and base directory.
* @return the array of matching dirnames, relative to the basedir of the file-set.
*/
- public String[] getIncludedDirectories( FileSet fileSet )
- {
- DirectoryScanner scanner = scan( fileSet );
+ public String[] getIncludedDirectories(FileSet fileSet) {
+ DirectoryScanner scanner = scan(fileSet);
- if ( scanner != null )
- {
+ if (scanner != null) {
return scanner.getIncludedDirectories();
}
@@ -168,12 +153,10 @@ public class FileSetManager
* @param fileSet The fileset defining rules for inclusion/exclusion, and base directory.
* @return the array of non-matching filenames, relative to the basedir of the file-set.
*/
- public String[] getExcludedFiles( FileSet fileSet )
- {
- DirectoryScanner scanner = scan( fileSet );
+ public String[] getExcludedFiles(FileSet fileSet) {
+ DirectoryScanner scanner = scan(fileSet);
- if ( scanner != null )
- {
+ if (scanner != null) {
return scanner.getExcludedFiles();
}
@@ -186,12 +169,10 @@ public class FileSetManager
* @param fileSet The fileset defining rules for inclusion/exclusion, and base directory.
* @return the array of non-matching dirnames, relative to the basedir of the file-set.
*/
- public String[] getExcludedDirectories( FileSet fileSet )
- {
- DirectoryScanner scanner = scan( fileSet );
+ public String[] getExcludedDirectories(FileSet fileSet) {
+ DirectoryScanner scanner = scan(fileSet);
- if ( scanner != null )
- {
+ if (scanner != null) {
return scanner.getExcludedDirectories();
}
@@ -204,10 +185,8 @@ public class FileSetManager
* @param fileSet The file-set matching rules, along with search base directory
* @throws IOException If a matching file cannot be deleted
*/
- public void delete( FileSet fileSet )
- throws IOException
- {
- delete( fileSet, true );
+ public void delete(FileSet fileSet) throws IOException {
+ delete(fileSet, true);
}
/**
@@ -218,84 +197,63 @@ public class FileSetManager
* @throws IOException If a matching file cannot be deleted and <code>throwsError=true</code>, otherwise print
* warning messages.
*/
- public void delete( FileSet fileSet, boolean throwsError )
- throws IOException
- {
- Set<String> deletablePaths = findDeletablePaths( fileSet );
-
- if ( logger.isDebugEnabled() )
- {
- String paths = String.valueOf( deletablePaths ).replace( ',', '\n' );
- logger.debug( "Found deletable paths: " + paths );
+ public void delete(FileSet fileSet, boolean throwsError) throws IOException {
+ Set<String> deletablePaths = findDeletablePaths(fileSet);
+
+ if (logger.isDebugEnabled()) {
+ String paths = String.valueOf(deletablePaths).replace(',', '\n');
+ logger.debug("Found deletable paths: " + paths);
}
List<String> warnMessages = new LinkedList<>();
- for ( String path : deletablePaths )
- {
- File file = new File( fileSet.getDirectory(), path );
-
- if ( file.exists() )
- {
- if ( file.isDirectory() )
- {
- if ( fileSet.isFollowSymlinks() || !isSymlink( file ) )
- {
- if ( verbose )
- {
- logger.info( "Deleting directory: " + file );
+ for (String path : deletablePaths) {
+ File file = new File(fileSet.getDirectory(), path);
+
+ if (file.exists()) {
+ if (file.isDirectory()) {
+ if (fileSet.isFollowSymlinks() || !isSymlink(file)) {
+ if (verbose) {
+ logger.info("Deleting directory: " + file);
}
- removeDir( file, fileSet.isFollowSymlinks(), throwsError, warnMessages );
- }
- else
- { // delete a symlink to a directory without follow
- if ( verbose )
- {
- logger.info( "Deleting symlink to directory: " + file );
+ removeDir(file, fileSet.isFollowSymlinks(), throwsError, warnMessages);
+ } else { // delete a symlink to a directory without follow
+ if (verbose) {
+ logger.info("Deleting symlink to directory: " + file);
}
- if ( !file.delete() )
- {
+ if (!file.delete()) {
String message = "Unable to delete symlink " + file.getAbsolutePath();
- if ( throwsError )
- {
- throw new IOException( message );
+ if (throwsError) {
+ throw new IOException(message);
}
- if ( !warnMessages.contains( message ) )
- {
- warnMessages.add( message );
+ if (!warnMessages.contains(message)) {
+ warnMessages.add(message);
}
}
}
- }
- else
- {
- if ( verbose )
- {
- logger.info( "Deleting file: " + file );
+ } else {
+ if (verbose) {
+ logger.info("Deleting file: " + file);
}
- if ( !FileUtils.deleteQuietly( file ) )
- {
+ if (!FileUtils.deleteQuietly(file)) {
String message = "Failed to delete file " + file.getAbsolutePath() + ". Reason is unknown.";
- if ( throwsError )
- {
- throw new IOException( message );
+ if (throwsError) {
+ throw new IOException(message);
}
- warnMessages.add( message );
+ warnMessages.add(message);
}
}
}
}
- if ( logger.isWarnEnabled() && !throwsError && ( warnMessages.size() > 0 ) )
- {
- for ( String warnMessage : warnMessages )
- {
- logger.warn( warnMessage );
+ if (logger.isWarnEnabled() && !throwsError && (warnMessages.size() > 0)) {
+ for (String warnMessage : warnMessages) {
+ logger.warn(warnMessage);
}
}
}
@@ -304,146 +262,122 @@ public class FileSetManager
// Private methods
// ----------------------------------------------------------------------
- private boolean isSymlink( File file )
- throws IOException
- {
+ private boolean isSymlink(File file) throws IOException {
File fileInCanonicalParent;
File parentDir = file.getParentFile();
- if ( parentDir == null )
- {
+ if (parentDir == null) {
fileInCanonicalParent = file;
+ } else {
+ fileInCanonicalParent = new File(parentDir.getCanonicalPath(), file.getName());
}
- else
- {
- fileInCanonicalParent = new File( parentDir.getCanonicalPath(), file.getName() );
- }
- if ( logger.isDebugEnabled() )
- {
- logger.debug( "Checking for symlink:\nFile's canonical path: "
- + fileInCanonicalParent.getCanonicalPath() + "\nFile's absolute path with canonical parent: "
- + fileInCanonicalParent.getPath() );
+ if (logger.isDebugEnabled()) {
+ logger.debug("Checking for symlink:\nFile's canonical path: "
+ + fileInCanonicalParent.getCanonicalPath() + "\nFile's absolute path with canonical parent: "
+ + fileInCanonicalParent.getPath());
}
- return !fileInCanonicalParent.getCanonicalFile().equals( fileInCanonicalParent.getAbsoluteFile() );
+ return !fileInCanonicalParent.getCanonicalFile().equals(fileInCanonicalParent.getAbsoluteFile());
}
- private Set<String> findDeletablePaths( FileSet fileSet )
- {
- Set<String> includes = findDeletableDirectories( fileSet );
- includes.addAll( findDeletableFiles( fileSet, includes ) );
+ private Set<String> findDeletablePaths(FileSet fileSet) {
+ Set<String> includes = findDeletableDirectories(fileSet);
+ includes.addAll(findDeletableFiles(fileSet, includes));
return includes;
}
- private Set<String> findDeletableDirectories( FileSet fileSet )
- {
- if ( verbose )
- {
- logger.info( "Scanning for deletable directories." );
+ private Set<String> findDeletableDirectories(FileSet fileSet) {
+ if (verbose) {
+ logger.info("Scanning for deletable directories.");
}
- DirectoryScanner scanner = scan( fileSet );
+ DirectoryScanner scanner = scan(fileSet);
- if ( scanner == null )
- {
+ if (scanner == null) {
return Collections.emptySet();
}
- Set<String> includes = new HashSet<>( Arrays.asList( scanner.getIncludedDirectories() ) );
- List<String> excludes = new ArrayList<>( Arrays.asList( scanner.getExcludedDirectories() ) );
+ Set<String> includes = new HashSet<>(Arrays.asList(scanner.getIncludedDirectories()));
+ List<String> excludes = new ArrayList<>(Arrays.asList(scanner.getExcludedDirectories()));
List<String> linksForDeletion = new ArrayList<>();
- if ( !fileSet.isFollowSymlinks() )
- {
- if ( verbose )
- {
- logger.info( "Adding symbolic link dirs which were previously excluded"
- + " to the list being deleted." );
+ if (!fileSet.isFollowSymlinks()) {
+ if (verbose) {
+ logger.info("Adding symbolic link dirs which were previously excluded" + " to the list being deleted.");
}
// we need to see which entries were only excluded because they're symlinks...
- scanner.setFollowSymlinks( true );
+ scanner.setFollowSymlinks(true);
scanner.scan();
- if ( logger.isDebugEnabled() )
- {
- logger.debug( "Originally marked for delete: " + includes );
- logger.debug( "Marked for preserve (with followSymlinks == false): " + excludes );
+ if (logger.isDebugEnabled()) {
+ logger.debug("Originally marked for delete: " + includes);
+ logger.debug("Marked for preserve (with followSymlinks == false): " + excludes);
}
- List<String> includedDirsAndSymlinks = Arrays.asList( scanner.getIncludedDirectories() );
+ List<String> includedDirsAndSymlinks = Arrays.asList(scanner.getIncludedDirectories());
- linksForDeletion.addAll( excludes );
- linksForDeletion.retainAll( includedDirsAndSymlinks );
+ linksForDeletion.addAll(excludes);
+ linksForDeletion.retainAll(includedDirsAndSymlinks);
- if ( logger.isDebugEnabled() )
- {
- logger.debug( "Symlinks marked for deletion (originally mismarked): "
- + linksForDeletion );
+ if (logger.isDebugEnabled()) {
+ logger.debug("Symlinks marked for deletion (originally mismarked): " + linksForDeletion);
}
- excludes.removeAll( includedDirsAndSymlinks );
+ excludes.removeAll(includedDirsAndSymlinks);
}
- excludeParentDirectoriesOfExcludedPaths( excludes, includes );
+ excludeParentDirectoriesOfExcludedPaths(excludes, includes);
- includes.addAll( linksForDeletion );
+ includes.addAll(linksForDeletion);
return includes;
}
- private Set<String> findDeletableFiles( FileSet fileSet, Set<String> deletableDirectories )
- {
- if ( verbose )
- {
- logger.info( "Re-scanning for deletable files." );
+ private Set<String> findDeletableFiles(FileSet fileSet, Set<String> deletableDirectories) {
+ if (verbose) {
+ logger.info("Re-scanning for deletable files.");
}
- DirectoryScanner scanner = scan( fileSet );
+ DirectoryScanner scanner = scan(fileSet);
- if ( scanner == null )
- {
+ if (scanner == null) {
return deletableDirectories;
}
- deletableDirectories.addAll( Arrays.asList( scanner.getIncludedFiles() ) );
- List<String> excludes = new ArrayList<>( Arrays.asList( scanner.getExcludedFiles() ) );
+ deletableDirectories.addAll(Arrays.asList(scanner.getIncludedFiles()));
+ List<String> excludes = new ArrayList<>(Arrays.asList(scanner.getExcludedFiles()));
List<String> linksForDeletion = new ArrayList<>();
- if ( !fileSet.isFollowSymlinks() )
- {
- if ( verbose )
- {
- logger.info( "Adding symbolic link files which were previously excluded "
- + "to the list being deleted." );
+ if (!fileSet.isFollowSymlinks()) {
+ if (verbose) {
+ logger.info(
+ "Adding symbolic link files which were previously excluded " + "to the list being deleted.");
}
// we need to see which entries were only excluded because they're symlinks...
- scanner.setFollowSymlinks( true );
+ scanner.setFollowSymlinks(true);
scanner.scan();
- if ( logger.isDebugEnabled() )
- {
- logger.debug( "Originally marked for delete: " + deletableDirectories );
- logger.debug( "Marked for preserve (with followSymlinks == false): " + excludes );
+ if (logger.isDebugEnabled()) {
+ logger.debug("Originally marked for delete: " + deletableDirectories);
+ logger.debug("Marked for preserve (with followSymlinks == false): " + excludes);
}
- List<String> includedFilesAndSymlinks = Arrays.asList( scanner.getIncludedFiles() );
+ List<String> includedFilesAndSymlinks = Arrays.asList(scanner.getIncludedFiles());
- linksForDeletion.addAll( excludes );
- linksForDeletion.retainAll( includedFilesAndSymlinks );
+ linksForDeletion.addAll(excludes);
+ linksForDeletion.retainAll(includedFilesAndSymlinks);
- if ( logger.isDebugEnabled() )
- {
- logger.debug( "Symlinks marked for deletion (originally mismarked): "
- + linksForDeletion );
+ if (logger.isDebugEnabled()) {
+ logger.debug("Symlinks marked for deletion (originally mismarked): " + linksForDeletion);
}
- excludes.removeAll( includedFilesAndSymlinks );
+ excludes.removeAll(includedFilesAndSymlinks);
}
- excludeParentDirectoriesOfExcludedPaths( excludes, deletableDirectories );
+ excludeParentDirectoriesOfExcludedPaths(excludes, deletableDirectories);
- deletableDirectories.addAll( linksForDeletion );
+ deletableDirectories.addAll(linksForDeletion);
return deletableDirectories;
}
@@ -451,50 +385,40 @@ public class FileSetManager
/**
* Removes all parent directories of the already excluded files/directories from the given set of deletable
* directories. I.e. if "subdir/excluded.txt" should not be deleted, "subdir" should be excluded from deletion, too.
- *
+ *
* @param excludedPaths The relative paths of the files/directories which are excluded from deletion, must not be
* <code>null</code>.
* @param deletablePaths The relative paths to files/directories which are scheduled for deletion, must not be
* <code>null</code>.
*/
- private void excludeParentDirectoriesOfExcludedPaths( List<String> excludedPaths, Set<String> deletablePaths )
- {
- for ( String path : excludedPaths )
- {
- String parentPath = new File( path ).getParent();
-
- while ( parentPath != null )
- {
- if ( logger.isDebugEnabled() )
- {
- logger.debug(
- "Verifying path " + parentPath + " is not present; contains file which is excluded." );
+ private void excludeParentDirectoriesOfExcludedPaths(List<String> excludedPaths, Set<String> deletablePaths) {
+ for (String path : excludedPaths) {
+ String parentPath = new File(path).getParent();
+
+ while (parentPath != null) {
+ if (logger.isDebugEnabled()) {
+ logger.debug("Verifying path " + parentPath + " is not present; contains file which is excluded.");
}
- boolean removed = deletablePaths.remove( parentPath );
+ boolean removed = deletablePaths.remove(parentPath);
- if ( removed && logger.isDebugEnabled() )
- {
- logger.debug( "Path " + parentPath + " was removed from delete list." );
+ if (removed && logger.isDebugEnabled()) {
+ logger.debug("Path " + parentPath + " was removed from delete list.");
}
- parentPath = new File( parentPath ).getParent();
+ parentPath = new File(parentPath).getParent();
}
}
- if ( !excludedPaths.isEmpty() )
- {
- if ( logger.isDebugEnabled() )
- {
- logger.debug( "Verifying path " + "."
- + " is not present; contains file which is excluded." );
+ if (!excludedPaths.isEmpty()) {
+ if (logger.isDebugEnabled()) {
+ logger.debug("Verifying path " + "." + " is not present; contains file which is excluded.");
}
- boolean removed = deletablePaths.remove( "" );
+ boolean removed = deletablePaths.remove("");
- if ( removed && logger.isDebugEnabled() )
- {
- logger.debug( "Path " + "." + " was removed from delete list." );
+ if (removed && logger.isDebugEnabled()) {
+ logger.debug("Path " + "." + " was removed from delete list.");
}
}
}
@@ -508,60 +432,46 @@ public class FileSetManager
* @param warnMessages A list of warning messages used when <code>throwsError=false</code>.
* @throws IOException If a matching file cannot be deleted and <code>throwsError=true</code>.
*/
- private void removeDir( File dir, boolean followSymlinks, boolean throwsError, List<String> warnMessages )
- throws IOException
- {
+ private void removeDir(File dir, boolean followSymlinks, boolean throwsError, List<String> warnMessages)
+ throws IOException {
String[] list = dir.list();
- if ( list == null )
- {
+ if (list == null) {
list = new String[0];
}
- for ( String s : list )
- {
- File f = new File( dir, s );
- if ( f.isDirectory() && ( followSymlinks || !isSymlink( f ) ) )
- {
- removeDir( f, followSymlinks, throwsError, warnMessages );
- }
- else
- {
- if ( !FileUtils.deleteQuietly( f ) )
- {
+ for (String s : list) {
+ File f = new File(dir, s);
+ if (f.isDirectory() && (followSymlinks || !isSymlink(f))) {
+ removeDir(f, followSymlinks, throwsError, warnMessages);
+ } else {
+ if (!FileUtils.deleteQuietly(f)) {
String message = "Unable to delete file " + f.getAbsolutePath();
- if ( throwsError )
- {
- throw new IOException( message );
+ if (throwsError) {
+ throw new IOException(message);
}
- if ( !warnMessages.contains( message ) )
- {
- warnMessages.add( message );
+ if (!warnMessages.contains(message)) {
+ warnMessages.add(message);
}
}
}
}
- if ( !FileUtils.deleteQuietly( dir ) )
- {
+ if (!FileUtils.deleteQuietly(dir)) {
String message = "Unable to delete directory " + dir.getAbsolutePath();
- if ( throwsError )
- {
- throw new IOException( message );
+ if (throwsError) {
+ throw new IOException(message);
}
- if ( !warnMessages.contains( message ) )
- {
- warnMessages.add( message );
+ if (!warnMessages.contains(message)) {
+ warnMessages.add(message);
}
}
}
- private DirectoryScanner scan( FileSet fileSet )
- {
- File basedir = new File( fileSet.getDirectory() );
- if ( !basedir.exists() || !basedir.isDirectory() )
- {
+ private DirectoryScanner scan(FileSet fileSet) {
+ File basedir = new File(fileSet.getDirectory());
+ if (!basedir.exists() || !basedir.isDirectory()) {
return null;
}
@@ -570,27 +480,23 @@ public class FileSetManager
String[] includesArray = fileSet.getIncludesArray();
String[] excludesArray = fileSet.getExcludesArray();
- if ( includesArray.length > 0 )
- {
- scanner.setIncludes( includesArray );
+ if (includesArray.length > 0) {
+ scanner.setIncludes(includesArray);
}
- if ( excludesArray.length > 0 )
- {
- scanner.setExcludes( excludesArray );
+ if (excludesArray.length > 0) {
+ scanner.setExcludes(excludesArray);
}
- if ( fileSet.isUseDefaultExcludes() )
- {
+ if (fileSet.isUseDefaultExcludes()) {
scanner.addDefaultExcludes();
}
- scanner.setBasedir( basedir );
- scanner.setFollowSymlinks( fileSet.isFollowSymlinks() );
+ scanner.setBasedir(basedir);
+ scanner.setFollowSymlinks(fileSet.isFollowSymlinks());
scanner.scan();
return scanner;
}
-
}
diff --git a/src/test/java/org/apache/maven/shared/model/fileset/mappers/MapperUtilTest.java b/src/test/java/org/apache/maven/shared/model/fileset/mappers/MapperUtilTest.java
index 9a1a3ca..19ad22e 100644
--- a/src/test/java/org/apache/maven/shared/model/fileset/mappers/MapperUtilTest.java
+++ b/src/test/java/org/apache/maven/shared/model/fileset/mappers/MapperUtilTest.java
@@ -1,5 +1,3 @@
-package org.apache.maven.shared.model.fileset.mappers;
-
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -18,83 +16,70 @@ package org.apache.maven.shared.model.fileset.mappers;
* specific language governing permissions and limitations
* under the License.
*/
+package org.apache.maven.shared.model.fileset.mappers;
+
+import org.apache.maven.shared.model.fileset.Mapper;
+import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.fail;
-import org.apache.maven.shared.model.fileset.Mapper;
-import org.junit.Test;
-
/**
* A test-case for the MapperUtil.
*/
-public class MapperUtilTest
-{
+public class MapperUtilTest {
@Test
- public void getFileNameMapperShouldReturnNull()
- throws MapperException
- {
- assertNull( MapperUtil.getFileNameMapper( null ) );
+ public void getFileNameMapperShouldReturnNull() throws MapperException {
+ assertNull(MapperUtil.getFileNameMapper(null));
}
@Test
- public void getFileNameMapperShouldReturnIdentityMapper()
- throws MapperException
- {
+ public void getFileNameMapperShouldReturnIdentityMapper() throws MapperException {
Mapper mapper = new Mapper();
- FileNameMapper fileNameMapper = MapperUtil.getFileNameMapper( mapper );
- assertNotNull( fileNameMapper );
- assertEquals( "/var/some-file.text", fileNameMapper.mapFileName( "/var/some-file.text" ) );
+ FileNameMapper fileNameMapper = MapperUtil.getFileNameMapper(mapper);
+ assertNotNull(fileNameMapper);
+ assertEquals("/var/some-file.text", fileNameMapper.mapFileName("/var/some-file.text"));
}
@Test
- public void getFileNameMapperShouldFileNameMapperType()
- throws MapperException
- {
+ public void getFileNameMapperShouldFileNameMapperType() throws MapperException {
// check with FileNameMapper type
Mapper mapper = new Mapper();
- mapper.setType( "glob" );
- mapper.setFrom( "*.java" );
- mapper.setTo( "*.class" );
- FileNameMapper fileNameMapper = MapperUtil.getFileNameMapper( mapper );
- assertNotNull( fileNameMapper );
- assertEquals( "/var/SomeClasses.class", fileNameMapper.mapFileName( "/var/SomeClasses.java" ) );
+ mapper.setType("glob");
+ mapper.setFrom("*.java");
+ mapper.setTo("*.class");
+ FileNameMapper fileNameMapper = MapperUtil.getFileNameMapper(mapper);
+ assertNotNull(fileNameMapper);
+ assertEquals("/var/SomeClasses.class", fileNameMapper.mapFileName("/var/SomeClasses.java"));
}
@Test
- public void testGetFileNameMapper() throws MapperException
- {
- try
- {
- assertNull( MapperUtil.getFileNameMapper( null ) );
- }
- catch ( MapperException e )
- {
- fail( "Unexpected exception " + e );
+ public void testGetFileNameMapper() throws MapperException {
+ try {
+ assertNull(MapperUtil.getFileNameMapper(null));
+ } catch (MapperException e) {
+ fail("Unexpected exception " + e);
}
Mapper mapper = new Mapper();
- try
- {
+ try {
// default to identity mapper.
- FileNameMapper fileNameMapper = MapperUtil.getFileNameMapper( mapper );
- assertNotNull( fileNameMapper );
- assertEquals( "/var/some-file.text", fileNameMapper.mapFileName( "/var/some-file.text" ) );
- }
- catch ( MapperException e )
- {
- fail( "Unexpected exception " + e );
+ FileNameMapper fileNameMapper = MapperUtil.getFileNameMapper(mapper);
+ assertNotNull(fileNameMapper);
+ assertEquals("/var/some-file.text", fileNameMapper.mapFileName("/var/some-file.text"));
+ } catch (MapperException e) {
+ fail("Unexpected exception " + e);
}
// check with FileNameMapper type
mapper = new Mapper();
- mapper.setType( "glob" );
- mapper.setFrom( "*.java" );
- mapper.setTo( "*.class" );
+ mapper.setType("glob");
+ mapper.setFrom("*.java");
+ mapper.setTo("*.class");
- FileNameMapper fileNameMapper = MapperUtil.getFileNameMapper( mapper );
- assertNotNull( fileNameMapper );
- assertEquals( "/var/SomeClasses.class", fileNameMapper.mapFileName( "/var/SomeClasses.java" ) );
+ FileNameMapper fileNameMapper = MapperUtil.getFileNameMapper(mapper);
+ assertNotNull(fileNameMapper);
+ assertEquals("/var/SomeClasses.class", fileNameMapper.mapFileName("/var/SomeClasses.java"));
}
}
diff --git a/src/test/java/org/apache/maven/shared/model/fileset/util/FileSetUtilsTest.java b/src/test/java/org/apache/maven/shared/model/fileset/util/FileSetUtilsTest.java
index cc46cb6..b50739e 100644
--- a/src/test/java/org/apache/maven/shared/model/fileset/util/FileSetUtilsTest.java
+++ b/src/test/java/org/apache/maven/shared/model/fileset/util/FileSetUtilsTest.java
@@ -1,3 +1,21 @@
+/*
+ * 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.
+ */
package org.apache.maven.shared.model.fileset.util;
/*
@@ -28,7 +46,6 @@ import java.util.Set;
import org.apache.commons.io.FileUtils;
import org.apache.maven.shared.model.fileset.FileSet;
-
import org.codehaus.plexus.util.cli.CommandLineException;
import org.codehaus.plexus.util.cli.Commandline;
import org.junit.After;
@@ -39,25 +56,20 @@ import static org.junit.Assert.*;
/**
* Test the FileSet
*/
-public class FileSetUtilsTest
-{
+public class FileSetUtilsTest {
private final Set<File> testDirectories = new HashSet<>();
private final Set<File> linkFiles = new HashSet<>();
/** {@inheritDoc} */
@After
- public void tearDown()
- throws IOException
- {
- for ( File linkFile : linkFiles )
- {
+ public void tearDown() throws IOException {
+ for (File linkFile : linkFiles) {
linkFile.delete();
}
- for ( File dir : testDirectories )
- {
- FileUtils.deleteDirectory( dir );
+ for (File dir : testDirectories) {
+ FileUtils.deleteDirectory(dir);
}
}
@@ -65,20 +77,18 @@ public class FileSetUtilsTest
* @throws IOException if any
*/
@Test
- public void testGetIncludedFiles()
- throws IOException
- {
- File directory = setupTestDirectory( "testGetIncludedFiles" );
+ public void testGetIncludedFiles() throws IOException {
+ File directory = setupTestDirectory("testGetIncludedFiles");
FileSet set = new FileSet();
- set.setDirectory( directory.getPath() );
- set.addInclude( "**/included.txt" );
+ set.setDirectory(directory.getPath());
+ set.addInclude("**/included.txt");
FileSetManager fileSetManager = new FileSetManager();
- String[] included = fileSetManager.getIncludedFiles( set );
+ String[] included = fileSetManager.getIncludedFiles(set);
- assertEquals( 1, included.length );
+ assertEquals(1, included.length);
}
/**
@@ -86,29 +96,26 @@ public class FileSetUtilsTest
* @throws InterruptedException if any
*/
@Test
- public void testIncludesDontFollowSymlinks()
- throws IOException, InterruptedException, CommandLineException
- {
- File directory = setupTestDirectory( "testIncludesDontFollowSymlinks" );
- File subdir = new File( directory, directory.getName() );
-
- if ( !createSymlink( directory, subdir ) )
- {
+ public void testIncludesDontFollowSymlinks() throws IOException, InterruptedException, CommandLineException {
+ File directory = setupTestDirectory("testIncludesDontFollowSymlinks");
+ File subdir = new File(directory, directory.getName());
+
+ if (!createSymlink(directory, subdir)) {
// assume failure to create a sym link is because the system does not support them
// and not because the sym link creation failed.
return;
}
FileSet set = new FileSet();
- set.setDirectory( directory.getPath() );
- set.addInclude( "**/included.txt" );
- set.setFollowSymlinks( false );
+ set.setDirectory(directory.getPath());
+ set.addInclude("**/included.txt");
+ set.setFollowSymlinks(false);
FileSetManager fileSetManager = new FileSetManager();
- String[] included = fileSetManager.getIncludedFiles( set );
+ String[] included = fileSetManager.getIncludedFiles(set);
- assertEquals( 1, included.length );
+ assertEquals(1, included.length);
}
/**
@@ -117,200 +124,182 @@ public class FileSetUtilsTest
* @throws CommandLineException if any
*/
@Test
- public void testDeleteDontFollowSymlinks()
- throws IOException, InterruptedException, CommandLineException
- {
- File directory = setupTestDirectory( "testDeleteDontFollowSymlinks" );
- File subdir = new File( directory, directory.getName() );
-
- if ( !createSymlink( directory, subdir ) )
- {
+ public void testDeleteDontFollowSymlinks() throws IOException, InterruptedException, CommandLineException {
+ File directory = setupTestDirectory("testDeleteDontFollowSymlinks");
+ File subdir = new File(directory, directory.getName());
+
+ if (!createSymlink(directory, subdir)) {
// assume failure to create a sym link is because the system does not support them
// and not because the sym link creation failed.
return;
}
FileSet set = new FileSet();
- set.setDirectory( directory.getPath() );
- set.addInclude( "**/included.txt" );
- set.addInclude( "**/" + subdir.getName() );
- set.setFollowSymlinks( false );
+ set.setDirectory(directory.getPath());
+ set.addInclude("**/included.txt");
+ set.addInclude("**/" + subdir.getName());
+ set.setFollowSymlinks(false);
FileSetManager fileSetManager = new FileSetManager();
- fileSetManager.delete( set );
+ fileSetManager.delete(set);
- assertFalse( subdir.exists() );
+ assertFalse(subdir.exists());
}
/**
* @throws IOException if any
*/
@Test
- public void testDelete()
- throws IOException
- {
- File directory = setupTestDirectory( "testDelete" );
- File subdirFile = new File( directory, "subdir/excluded.txt" );
+ public void testDelete() throws IOException {
+ File directory = setupTestDirectory("testDelete");
+ File subdirFile = new File(directory, "subdir/excluded.txt");
FileSet set = new FileSet();
- set.setDirectory( directory.getPath() );
- set.addInclude( "**/included.txt" );
- set.addInclude( "**/subdir" );
+ set.setDirectory(directory.getPath());
+ set.addInclude("**/included.txt");
+ set.addInclude("**/subdir");
FileSetManager fileSetManager = new FileSetManager();
- fileSetManager.delete( set );
+ fileSetManager.delete(set);
- assertFalse( "file in marked subdirectory still exists.", subdirFile.exists() );
+ assertFalse("file in marked subdirectory still exists.", subdirFile.exists());
}
/**
* @throws Exception if any
*/
@Test
- public void testDeleteDanglingSymlink()
- throws Exception
- {
- File directory = setupTestDirectory( "testDeleteDanglingSymlink" );
- File targetFile = new File( directory, "test.txt" );
- File linkFile = new File( directory, "symlink" );
-
- if ( !createSymlink( targetFile, linkFile ) )
- {
+ public void testDeleteDanglingSymlink() throws Exception {
+ File directory = setupTestDirectory("testDeleteDanglingSymlink");
+ File targetFile = new File(directory, "test.txt");
+ File linkFile = new File(directory, "symlink");
+
+ if (!createSymlink(targetFile, linkFile)) {
// symlinks apparently not supported, skip test
return;
}
targetFile.delete();
FileSet set = new FileSet();
- set.setDirectory( directory.getPath() );
- set.addInclude( "**" );
+ set.setDirectory(directory.getPath());
+ set.addInclude("**");
FileSetManager fileSetManager = new FileSetManager();
- fileSetManager.delete( set );
+ fileSetManager.delete(set);
- assertFalse( "directory still exists", directory.exists() );
+ assertFalse("directory still exists", directory.exists());
}
/**
* @throws Exception if any
*/
@Test
- public void testDeleteExcludeParentOfExcludedFile()
- throws Exception
- {
- File directory = setupTestDirectory( "testDeleteExcludeParentOfExcludedFile" );
+ public void testDeleteExcludeParentOfExcludedFile() throws Exception {
+ File directory = setupTestDirectory("testDeleteExcludeParentOfExcludedFile");
FileSet set = new FileSet();
- set.setDirectory( directory.getPath() );
- set.addExclude( "*excluded*" );
- set.setFollowSymlinks( true );
+ set.setDirectory(directory.getPath());
+ set.addExclude("*excluded*");
+ set.setFollowSymlinks(true);
FileSetManager fileSetManager = new FileSetManager();
- fileSetManager.delete( set );
+ fileSetManager.delete(set);
- assertTrue( "excluded file has been deleted", new File( directory, "excluded.txt" ).exists() );
+ assertTrue("excluded file has been deleted", new File(directory, "excluded.txt").exists());
}
/**
* @throws Exception if any
*/
@Test
- public void testDeleteExcludeParentOfExcludedDir()
- throws Exception
- {
- File directory = setupTestDirectory( "testDeleteExcludeParentOfExcludedDir" );
+ public void testDeleteExcludeParentOfExcludedDir() throws Exception {
+ File directory = setupTestDirectory("testDeleteExcludeParentOfExcludedDir");
FileSet set = new FileSet();
- set.setDirectory( directory.getPath() );
- set.addExclude( "*excluded*" );
- set.setFollowSymlinks( true );
+ set.setDirectory(directory.getPath());
+ set.addExclude("*excluded*");
+ set.setFollowSymlinks(true);
FileSetManager fileSetManager = new FileSetManager();
- fileSetManager.delete( set );
+ fileSetManager.delete(set);
- assertTrue( "excluded directory has been deleted", new File( directory, "excluded" ).exists() );
+ assertTrue("excluded directory has been deleted", new File(directory, "excluded").exists());
}
/**
* @throws Exception if any
*/
@Test
- public void testDeleteExcludeFollowSymlinks()
- throws Exception
- {
- File directory = setupTestDirectory( "testDeleteExcludeFollowSymlinks" );
+ public void testDeleteExcludeFollowSymlinks() throws Exception {
+ File directory = setupTestDirectory("testDeleteExcludeFollowSymlinks");
FileSet set = new FileSet();
- set.setDirectory( directory.getPath() );
- set.addExclude( "*excluded*" );
- set.setFollowSymlinks( true );
+ set.setDirectory(directory.getPath());
+ set.addExclude("*excluded*");
+ set.setFollowSymlinks(true);
FileSetManager fileSetManager = new FileSetManager();
- fileSetManager.delete( set );
+ fileSetManager.delete(set);
- assertTrue( "excluded file has been deleted", new File( directory, "excluded.txt" ).exists() );
- assertTrue( "excluded directory has been deleted", new File( directory, "excluded" ).exists() );
- assertFalse( "included file has not been deleted", new File( directory, "included.txt" ).exists() );
+ assertTrue("excluded file has been deleted", new File(directory, "excluded.txt").exists());
+ assertTrue("excluded directory has been deleted", new File(directory, "excluded").exists());
+ assertFalse("included file has not been deleted", new File(directory, "included.txt").exists());
}
/**
* @throws Exception if any
*/
@Test
- public void testDeleteExcludeDontFollowSymlinks()
- throws Exception
- {
- File directory = setupTestDirectory( "testDeleteExcludeDontFollowSymlinks" );
+ public void testDeleteExcludeDontFollowSymlinks() throws Exception {
+ File directory = setupTestDirectory("testDeleteExcludeDontFollowSymlinks");
FileSet set = new FileSet();
- set.setDirectory( directory.getPath() );
- set.addExclude( "*excluded*" );
- set.setFollowSymlinks( false );
+ set.setDirectory(directory.getPath());
+ set.addExclude("*excluded*");
+ set.setFollowSymlinks(false);
FileSetManager fileSetManager = new FileSetManager();
- fileSetManager.delete( set );
+ fileSetManager.delete(set);
- assertTrue( "excluded file has been deleted", new File( directory, "excluded.txt" ).exists() );
- assertTrue( "excluded directory has been deleted", new File( directory, "excluded" ).exists() );
- assertFalse( "included file has not been deleted", new File( directory, "included.txt" ).exists() );
+ assertTrue("excluded file has been deleted", new File(directory, "excluded.txt").exists());
+ assertTrue("excluded directory has been deleted", new File(directory, "excluded").exists());
+ assertFalse("included file has not been deleted", new File(directory, "included.txt").exists());
}
/**
* @throws Exception if any
*/
@Test
- public void testDeleteDontFollowSymlinksButDeleteThem()
- throws Exception
- {
- File directory = setupTestDirectory( "testDeleteDontFollowSymlinksButDeleteThem" );
+ public void testDeleteDontFollowSymlinksButDeleteThem() throws Exception {
+ File directory = setupTestDirectory("testDeleteDontFollowSymlinksButDeleteThem");
- createSymlink( new File( directory, "excluded" ), new File( directory, "dirlink" ) );
- createSymlink( new File( directory, "excluded.txt" ), new File( directory, "filelink" ) );
- createSymlink( new File( directory, "excluded" ), new File( directory, "dir0/dirlink" ) );
- createSymlink( new File( directory, "excluded.txt" ), new File( directory, "dir1/filelink" ) );
+ createSymlink(new File(directory, "excluded"), new File(directory, "dirlink"));
+ createSymlink(new File(directory, "excluded.txt"), new File(directory, "filelink"));
+ createSymlink(new File(directory, "excluded"), new File(directory, "dir0/dirlink"));
+ createSymlink(new File(directory, "excluded.txt"), new File(directory, "dir1/filelink"));
FileSet set = new FileSet();
- set.setDirectory( directory.getPath() );
- set.addExclude( "*excluded*" );
- set.setFollowSymlinks( false );
+ set.setDirectory(directory.getPath());
+ set.addExclude("*excluded*");
+ set.setFollowSymlinks(false);
FileSetManager fileSetManager = new FileSetManager();
- fileSetManager.delete( set );
+ fileSetManager.delete(set);
- assertTrue( "excluded file has been deleted", new File( directory, "excluded.txt" ).exists() );
- assertTrue( "excluded directory has been deleted", new File( directory, "excluded" ).exists() );
- assertFalse( "included dirlink has not been deleted", new File( directory, "dirlink" ).exists() );
- assertFalse( "included filelink has not been deleted", new File( directory, "filelink" ).exists() );
- assertFalse( "included directory has not been deleted", new File( directory, "dir0" ).exists() );
- assertFalse( "included directory has not been deleted", new File( directory, "dir1" ).exists() );
+ assertTrue("excluded file has been deleted", new File(directory, "excluded.txt").exists());
+ assertTrue("excluded directory has been deleted", new File(directory, "excluded").exists());
+ assertFalse("included dirlink has not been deleted", new File(directory, "dirlink").exists());
+ assertFalse("included filelink has not been deleted", new File(directory, "filelink").exists());
+ assertFalse("included directory has not been deleted", new File(directory, "dir0").exists());
+ assertFalse("included directory has not been deleted", new File(directory, "dir1").exists());
}
/**
@@ -320,50 +309,44 @@ public class FileSetUtilsTest
* @throws InterruptedException
* @throws CommandLineException
*/
- private boolean createSymlink( File target, File link )
- throws InterruptedException, CommandLineException
+ private boolean createSymlink(File target, File link) throws InterruptedException, CommandLineException {
- {
- if ( link.exists() )
- {
+ if (link.exists()) {
link.delete();
}
Commandline cli = new Commandline();
- cli.setExecutable( "ln" );
- cli.createArg().setValue( "-s" );
- cli.createArg().setValue( target.getPath() );
- cli.createArg().setValue( link.getPath() );
+ cli.setExecutable("ln");
+ cli.createArg().setValue("-s");
+ cli.createArg().setValue(target.getPath());
+ cli.createArg().setValue(link.getPath());
int result = cli.execute().waitFor();
- linkFiles.add( link );
+ linkFiles.add(link);
return result == 0;
}
- private File setupTestDirectory( String directoryName )
- throws IOException
- {
- URL sourceResource = getClass().getClassLoader().getResource( directoryName );
+ private File setupTestDirectory(String directoryName) throws IOException {
+ URL sourceResource = getClass().getClassLoader().getResource(directoryName);
- if ( sourceResource == null )
- {
- fail( "Source directory for test: " + directoryName + " cannot be found." );
+ if (sourceResource == null) {
+ fail("Source directory for test: " + directoryName + " cannot be found.");
}
- File sourceDir = new File( URLDecoder.decode( sourceResource.getPath(), "UTF-8" ) );
+ File sourceDir = new File(URLDecoder.decode(sourceResource.getPath(), "UTF-8"));
- String basedir = System.getProperty( "basedir", System.getProperty( "user.dir" ) );
- String testBase = System.getProperty( "testBase", "target/test-directories" );
+ String basedir = System.getProperty("basedir", System.getProperty("user.dir"));
+ String testBase = System.getProperty("testBase", "target/test-directories");
- File testDir = new File( basedir, testBase + "/" + directoryName );
- if ( testDir.mkdirs() ) {
- FileUtils.copyDirectory( sourceDir, testDir );
- testDirectories.add( testDir );
+ File testDir = new File(basedir, testBase + "/" + directoryName);
+ if (testDir.mkdirs()) {
+ FileUtils.copyDirectory(sourceDir, testDir);
+ testDirectories.add(testDir);
return testDir;
} else {
- throw new IOException( "Could not create test directory " + testDir );
+ throw new IOException("Could not create test directory " + testDir);
}
}
}