maven-file-management-1.2.1/ 0000755 0001750 0001750 00000000000 11226716142 015610 5 ustar twerner twerner maven-file-management-1.2.1/src/ 0000755 0001750 0001750 00000000000 11226716142 016377 5 ustar twerner twerner maven-file-management-1.2.1/src/site/ 0000755 0001750 0001750 00000000000 11226716142 017343 5 ustar twerner twerner maven-file-management-1.2.1/src/site/site.xml 0000644 0001750 0001750 00000002016 11020006575 021022 0 ustar twerner twerner
fileSet
rules to select files and directories.
*
* @parameter
*/
private List filesets;
/**
* A specific fileSet
rule to select files and directories.
*
* @parameter
*/
private FileSet fileset;
...
}
+-----+
To use the <<null
.
* @param link The link to create, must not be null
.
* @return
* @throws InterruptedException
* @throws CommandLineException
*/
private boolean createSymlink( File target, File link )
throws InterruptedException, CommandLineException
{
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() );
int result = cli.execute().waitFor();
linkFiles.add( link );
return result == 0;
}
/**
* @param directoryName
* @return
* @throws IOException
*/
private File setupTestDirectory( String directoryName )
throws IOException
{
System.out.println( "Setting up directory for test: " + directoryName );
URL sourceResource = getClass().getClassLoader().getResource( directoryName );
if ( sourceResource == null )
{
Assert.fail( "Source directory for test: " + directoryName + " cannot be found." );
}
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" );
File testDir = new File( basedir, testBase + "/" + directoryName );
testDir.mkdirs();
FileUtils.copyDirectoryStructure( sourceDir, testDir );
testDirectories.add( testDir );
return testDir;
}
}
maven-file-management-1.2.1/src/main/ 0000755 0001750 0001750 00000000000 11226716142 017323 5 ustar twerner twerner maven-file-management-1.2.1/src/main/mdo/ 0000755 0001750 0001750 00000000000 11226716141 020101 5 ustar twerner twerner maven-file-management-1.2.1/src/main/mdo/fileset.mdo 0000644 0001750 0001750 00000025502 11020006575 022234 0 ustar twerner twerner
This original code comes from org.apache.tools.ant.util package.
maven-file-management-1.2.1/src/main/java/ 0000755 0001750 0001750 00000000000 11226716141 020243 5 ustar twerner twerner maven-file-management-1.2.1/src/main/java/org/ 0000755 0001750 0001750 00000000000 11226716141 021032 5 ustar twerner twerner maven-file-management-1.2.1/src/main/java/org/apache/ 0000755 0001750 0001750 00000000000 11226716141 022253 5 ustar twerner twerner maven-file-management-1.2.1/src/main/java/org/apache/maven/ 0000755 0001750 0001750 00000000000 11226716141 023361 5 ustar twerner twerner maven-file-management-1.2.1/src/main/java/org/apache/maven/shared/ 0000755 0001750 0001750 00000000000 11226716141 024627 5 ustar twerner twerner maven-file-management-1.2.1/src/main/java/org/apache/maven/shared/model/ 0000755 0001750 0001750 00000000000 11226716141 025727 5 ustar twerner twerner maven-file-management-1.2.1/src/main/java/org/apache/maven/shared/model/fileset/ 0000755 0001750 0001750 00000000000 11226716142 027363 5 ustar twerner twerner maven-file-management-1.2.1/src/main/java/org/apache/maven/shared/model/fileset/mappers/ 0000755 0001750 0001750 00000000000 11226716142 031032 5 ustar twerner twerner ././@LongLink 0000000 0000000 0000000 00000000154 00000000000 011565 L ustar root root maven-file-management-1.2.1/src/main/java/org/apache/maven/shared/model/fileset/mappers/IdentityMapper.java maven-file-management-1.2.1/src/main/java/org/apache/maven/shared/model/fileset/mappers/IdentityMapp0000644 0001750 0001750 00000002703 11020006575 033360 0 ustar twerner twerner 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 * 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. */ /** * Implementation of FileNameMapper that always returns the source file name. * *This is the default FileNameMapper for the copy and move * tasks.
* * @version $Id: IdentityMapper.java 661727 2008-05-30 14:21:49Z bentmann $ */ public class IdentityMapper implements FileNameMapper { /** {@inheritDoc} */ public void setFrom( String from ) { // nop } /** {@inheritDoc} */ public void setTo( String to ) { // nop } /** {@inheritDoc} */ public String mapFileName( String sourceFileName ) { return sourceFileName; } } ././@LongLink 0000000 0000000 0000000 00000000161 00000000000 011563 L ustar root root maven-file-management-1.2.1/src/main/java/org/apache/maven/shared/model/fileset/mappers/UnPackageNameMapper.java maven-file-management-1.2.1/src/main/java/org/apache/maven/shared/model/fileset/mappers/UnPackageNam0000644 0001750 0001750 00000003136 11020006575 033244 0 ustar twerner twerner 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 * 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. */ import java.io.File; /** * Maps dotted package name matches to a directory name. * This is the inverse of the package mapper. * This is useful for matching XML formatter results against their JUnit test * cases. ** <mapper classname="org.apache.tools.ant.util.UnPackageNameMapper" * from="${test.data.dir}/TEST-*Test.xml" to="*Test.java"> ** * @version $Id: UnPackageNameMapper.java 661727 2008-05-30 14:21:49Z bentmann $ */ public class UnPackageNameMapper extends GlobPatternMapper { /** {@inheritDoc} */ protected String extractVariablePart( String name ) { String var = name.substring( prefixLength, name.length() - postfixLength ); return var.replace( '.', File.separatorChar ); } } ././@LongLink 0000000 0000000 0000000 00000000150 00000000000 011561 L ustar root root maven-file-management-1.2.1/src/main/java/org/apache/maven/shared/model/fileset/mappers/MapperUtil.java maven-file-management-1.2.1/src/main/java/org/apache/maven/shared/model/fileset/mappers/MapperUtil.j0000644 0001750 0001750 00000007736 11020006575 033276 0 ustar twerner twerner 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 * 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. */ import org.apache.maven.shared.model.fileset.Mapper; import org.codehaus.plexus.util.IOUtil; import java.io.IOException; import java.io.InputStream; import java.util.Properties; /** * Element to define a FileNameMapper. * * @version $Id: MapperUtil.java 661727 2008-05-30 14:21:49Z bentmann $ */ public final class MapperUtil { private static final String MAPPER_PROPERTIES = "mapper.properties"; private static Properties implementations; private MapperUtil() { // nop } /** * Initializes a properties object to store the built-in classnames. */ private static void initializeBuiltIns() { if ( implementations == null ) { Properties props = new Properties(); ClassLoader cloader = Thread.currentThread().getContextClassLoader(); InputStream stream = null; try { stream = cloader.getResourceAsStream( MAPPER_PROPERTIES ); if ( stream == null ) { throw new IllegalStateException( "Cannot find classpath resource: " + MAPPER_PROPERTIES ); } try { props.load( stream ); } catch ( IOException e ) { throw new IllegalStateException( "Cannot find classpath resource: " + MAPPER_PROPERTIES ); } } finally { IOUtil.close( stream ); } } } /** * Returns a fully configured FileNameMapper implementation. * * @param mapper * @return * @throws MapperException */ public static FileNameMapper getFileNameMapper( Mapper mapper ) throws MapperException { if ( mapper == null ) { return null; } initializeBuiltIns(); 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( "must not specify both type and classname attribute" ); } if ( type != null ) { classname = implementations.getProperty( type ); } try { FileNameMapper m = (FileNameMapper) Class.forName( classname ).newInstance(); m.setFrom( mapper.getFrom() ); m.setTo( mapper.getTo() ); return m; } catch ( ClassNotFoundException e ) { throw new MapperException( "Cannot find mapper implementation: " + classname, e ); } catch ( InstantiationException e ) { throw new MapperException( "Cannot load mapper implementation: " + classname, e ); } catch ( IllegalAccessException e ) { throw new MapperException( "Cannot load mapper implementation: " + classname, e ); } } } ././@LongLink 0000000 0000000 0000000 00000000160 00000000000 011562 L ustar root root maven-file-management-1.2.1/src/main/java/org/apache/maven/shared/model/fileset/mappers/FlatFileNameMapper.java maven-file-management-1.2.1/src/main/java/org/apache/maven/shared/model/fileset/mappers/FlatFileName0000644 0001750 0001750 00000003112 11020006575 033233 0 ustar twerner twerner 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 * 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. */ /** * Implementation of FileNameMapper that always returns the source * file name without any leading directory information. * *
This is the default FileNameMapper for the copy and move * tasks if the flatten attribute has been set.
* * @version $Id: FlatFileNameMapper.java 661727 2008-05-30 14:21:49Z bentmann $ */ public class FlatFileNameMapper implements FileNameMapper { /** {@inheritDoc} */ public void setFrom( String from ) { // nop } /** {@inheritDoc} */ public void setTo( String to ) { // nop } /** {@inheritDoc} */ public String mapFileName( String sourceFileName ) { return new String( new java.io.File( sourceFileName ).getName() ); } } ././@LongLink 0000000 0000000 0000000 00000000157 00000000000 011570 L ustar root root maven-file-management-1.2.1/src/main/java/org/apache/maven/shared/model/fileset/mappers/GlobPatternMapper.java maven-file-management-1.2.1/src/main/java/org/apache/maven/shared/model/fileset/mappers/GlobPatternM0000644 0001750 0001750 00000011311 11020006575 033302 0 ustar twerner twerner 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 * 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. */ /** * Implementation of FileNameMapper that does simple wildcard pattern * replacements. * *This does simple translations like *.foo -> *.bar where the * prefix to .foo will be left unchanged. It only handles a single * * character, use regular expressions for more complicated * situations.
* *This is one of the more useful Mappers, it is used by javac for * example.
* * @version $Id: GlobPatternMapper.java 661727 2008-05-30 14:21:49Z bentmann $ */ public class GlobPatternMapper implements FileNameMapper { /** * Part of "from" pattern before the *. */ protected String fromPrefix = null; /** * Part of "from" pattern after the *. */ protected String fromPostfix = null; /** * Length of the prefix ("from" pattern). */ protected int prefixLength; /** * Length of the postfix ("from" pattern). */ protected int postfixLength; /** * Part of "to" pattern before the *. */ protected String toPrefix = null; /** * Part of "to" pattern after the *. */ protected String toPostfix = null; private boolean handleDirSep = false; private boolean caseSensitive = true; /** * Attribute specifing whether to ignore the difference * between / and \ (the two common directory characters). * @param handleDirSep a boolean, default is false. */ public void setHandleDirSep( boolean handleDirSep ) { this.handleDirSep = handleDirSep; } /** * Attribute specifing whether to ignore the case difference * in the names. * * @param caseSensitive a boolean, default is false. */ public void setCaseSensitive( boolean caseSensitive ) { this.caseSensitive = caseSensitive; } /** {@inheritDoc} */ 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 ); } prefixLength = fromPrefix.length(); postfixLength = fromPostfix.length(); } /** {@inheritDoc} */ 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 ); } } /** {@inheritDoc} */ public String mapFileName( String sourceFileName ) { if ( fromPrefix == null || !modifyName( sourceFileName ).startsWith( modifyName( fromPrefix ) ) || !modifyName( sourceFileName ).endsWith( modifyName( fromPostfix ) ) ) { return null; } return new String( toPrefix + extractVariablePart( sourceFileName ) + toPostfix ); } /** * Returns the part of the given string that matches the * in the * "from" pattern. * @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 ); } /** * modify string based on dir char mapping and case sensitivity * @param name the name to convert * @return the converted name */ private String modifyName( String name ) { if ( !caseSensitive ) { name = name.toLowerCase(); } if ( handleDirSep ) { if ( name.indexOf( '\\' ) != -1 ) { name = name.replace( '\\', '/' ); } } return name; } } ././@LongLink 0000000 0000000 0000000 00000000157 00000000000 011570 L ustar root root maven-file-management-1.2.1/src/main/java/org/apache/maven/shared/model/fileset/mappers/PackageNameMapper.java maven-file-management-1.2.1/src/main/java/org/apache/maven/shared/model/fileset/mappers/PackageNameM0000644 0001750 0001750 00000003054 11020006575 033222 0 ustar twerner twerner 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 * 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. */ import java.io.File; /** * Maps directory name matches into a dotted package name. This is * useful for matching JUnit test cases againt their XML formatter * results. ** <mapper classname="org.apache.tools.ant.util.PackageNameMapper" * from="*Test.java" to="${test.data.dir}/TEST-*Test.xml"/> ** * @version $Id: PackageNameMapper.java 661727 2008-05-30 14:21:49Z bentmann $ */ public class PackageNameMapper extends GlobPatternMapper { /** {@inheritDoc} */ protected String extractVariablePart( String name ) { String var = name.substring( prefixLength, name.length() - postfixLength ); return var.replace( File.separatorChar, '.' ); } } ././@LongLink 0000000 0000000 0000000 00000000153 00000000000 011564 L ustar root root maven-file-management-1.2.1/src/main/java/org/apache/maven/shared/model/fileset/mappers/MergingMapper.java maven-file-management-1.2.1/src/main/java/org/apache/maven/shared/model/fileset/mappers/MergingMappe0000644 0001750 0001750 00000003001 11020006575 033314 0 ustar twerner twerner 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 * 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. */ /** * Implementation of FileNameMapper that always returns the same * target file name. * *
This is the default FileNameMapper for the archiving tasks and * uptodate.
* * @version $Id: MergingMapper.java 661727 2008-05-30 14:21:49Z bentmann $ */ public class MergingMapper implements FileNameMapper { protected String mergedFile = null; /** {@inheritDoc} */ public void setFrom( String from ) { // nop } /** {@inheritDoc} */ public void setTo( String to ) { mergedFile = to; } /** {@inheritDoc} */ public String mapFileName( String sourceFileName ) { return mergedFile; } } ././@LongLink 0000000 0000000 0000000 00000000155 00000000000 011566 L ustar root root maven-file-management-1.2.1/src/main/java/org/apache/maven/shared/model/fileset/mappers/MapperException.java maven-file-management-1.2.1/src/main/java/org/apache/maven/shared/model/fileset/mappers/MapperExcept0000644 0001750 0001750 00000002625 11020006575 033351 0 ustar twerner twerner 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 * 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. */ /** * Mapper Exception * * @version $Id: MapperException.java 661727 2008-05-30 14:21:49Z bentmann $ */ public class MapperException extends Exception { static final long serialVersionUID = 20064059145045044L; /** * Constructor * * @param message * @param cause */ public MapperException( String message, Throwable cause ) { super( message, cause ); } /** * Constructor * * @param message */ public MapperException( String message ) { super( message ); } } ././@LongLink 0000000 0000000 0000000 00000000154 00000000000 011565 L ustar root root maven-file-management-1.2.1/src/main/java/org/apache/maven/shared/model/fileset/mappers/FileNameMapper.java maven-file-management-1.2.1/src/main/java/org/apache/maven/shared/model/fileset/mappers/FileNameMapp0000644 0001750 0001750 00000003756 11020006575 033260 0 ustar twerner twerner 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 * 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. */ /** * Interface to be used by SourceFileScanner. * *Used to find the name of the target file(s) corresponding to a * source file.
* *The rule by which the file names are transformed is specified * via the setFrom and setTo methods. The exact meaning of these is * implementation dependent.
* * @version $Id: FileNameMapper.java 661727 2008-05-30 14:21:49Z bentmann $ */ public interface FileNameMapper { /** * Sets the from part of the transformation rule. * * @param from */ void setFrom( String from ); /** * Sets the to part of the transformation rule. * * @param to */ void setTo( String to ); /** * Returns the target filename for the * given source file. * *if the given rule doesn't apply to the source file, * implementation must return null. SourceFileScanner will then * omit the source file in question.
* * @param sourceFileName the name of the source file relative to some given basedirectory. * @return the target filename for the given source file. */ String mapFileName( String sourceFileName ); } maven-file-management-1.2.1/src/main/java/org/apache/maven/shared/model/fileset/util/ 0000755 0001750 0001750 00000000000 11226716142 030340 5 ustar twerner twerner ././@LongLink 0000000 0000000 0000000 00000000151 00000000000 011562 L ustar root root maven-file-management-1.2.1/src/main/java/org/apache/maven/shared/model/fileset/util/FileSetManager.java maven-file-management-1.2.1/src/main/java/org/apache/maven/shared/model/fileset/util/FileSetManager.0000644 0001750 0001750 00000055233 11062236507 033177 0 ustar twerner twerner 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 * 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. */ import org.apache.maven.plugin.logging.Log; import org.apache.maven.shared.io.logging.DefaultMessageHolder; import org.apache.maven.shared.io.logging.MessageHolder; import org.apache.maven.shared.io.logging.MessageLevels; import org.apache.maven.shared.io.logging.MojoLogSink; import org.apache.maven.shared.io.logging.PlexusLoggerSink; import org.apache.maven.shared.model.fileset.FileSet; import org.apache.maven.shared.model.fileset.mappers.FileNameMapper; import org.apache.maven.shared.model.fileset.mappers.MapperException; import org.apache.maven.shared.model.fileset.mappers.MapperUtil; import org.codehaus.plexus.logging.Logger; import org.codehaus.plexus.util.DirectoryScanner; import org.codehaus.plexus.util.FileUtils; import java.io.File; import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.HashSet; import java.util.Iterator; import java.util.LinkedHashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Set; /** * Provides operations for use with FileSet instances, such as retrieving the included/excluded files, deleting all * matching entries, etc. * * @author jdcasey * @version $Id: FileSetManager.java 694312 2008-09-11 15:46:15Z bentmann $ */ public class FileSetManager { private static final String[] EMPTY_STRING_ARRAY = new String[0]; private final boolean verbose; private MessageHolder messages; // ---------------------------------------------------------------------- // Constructors // ---------------------------------------------------------------------- /** * Create a new manager instance with the supplied log instance and flag for whether to output verbose messages. * * @param log The mojo log instance * @param verbose Whether to output verbose messages */ public FileSetManager( Log log, boolean verbose ) { if ( verbose ) { this.messages = new DefaultMessageHolder( MessageLevels.LEVEL_DEBUG, MessageLevels.LEVEL_INFO, new MojoLogSink( log ) ); } else { this.messages = new DefaultMessageHolder( MessageLevels.LEVEL_INFO, MessageLevels.LEVEL_INFO, new MojoLogSink( log ) ); } this.verbose = verbose; } /** * Create a new manager instance with the supplied log instance. Verbose flag is set to false. * * @param log The mojo log instance */ public FileSetManager( Log log ) { this.messages = new DefaultMessageHolder( MessageLevels.LEVEL_INFO, MessageLevels.LEVEL_INFO, new MojoLogSink( log ) ); this.verbose = false; } /** * Create a new manager instance with the supplied log instance and flag for whether to output verbose messages. * * @param log The mojo log instance * @param verbose Whether to output verbose messages */ public FileSetManager( Logger log, boolean verbose ) { if ( verbose ) { this.messages = new DefaultMessageHolder( MessageLevels.LEVEL_DEBUG, MessageLevels.LEVEL_INFO, new PlexusLoggerSink( log ) ); } else { this.messages = new DefaultMessageHolder( MessageLevels.LEVEL_INFO, MessageLevels.LEVEL_INFO, new PlexusLoggerSink( log ) ); } this.verbose = verbose; } /** * Create a new manager instance with the supplied log instance. Verbose flag is set to false. * * @param log The mojo log instance */ public FileSetManager( Logger log ) { this.messages = new DefaultMessageHolder( MessageLevels.LEVEL_INFO, MessageLevels.LEVEL_INFO, new PlexusLoggerSink( log ) ); this.verbose = false; } /** * Create a new manager instance with an empty messages. Verbose flag is set to false. */ public FileSetManager() { this.verbose = false; } // ---------------------------------------------------------------------- // Public methods // ---------------------------------------------------------------------- /** * * @param fileSet * @return the included files as map * @throws MapperException if any * @see #getIncludedFiles(FileSet) */ public Map mapIncludedFiles( FileSet fileSet ) throws MapperException { String[] sourcePaths = getIncludedFiles( fileSet ); Map mappedPaths = new LinkedHashMap(); FileNameMapper fileMapper = MapperUtil.getFileNameMapper( fileSet.getMapper() ); for ( int i = 0; i < sourcePaths.length; i++ ) { String sourcePath = sourcePaths[i]; String destPath; if ( fileMapper != null ) { destPath = fileMapper.mapFileName( sourcePath ); } else { destPath = sourcePath; } mappedPaths.put( sourcePath, destPath ); } return mappedPaths; } /** * Get all the filenames which have been included by the rules in this fileset. * * @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 ); if ( scanner != null ) { return scanner.getIncludedFiles(); } return EMPTY_STRING_ARRAY; } /** * Get all the directory names which have been included by the rules in this fileset. * * @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 ); if ( scanner != null ) { return scanner.getIncludedDirectories(); } return EMPTY_STRING_ARRAY; } /** * Get all the filenames which have been excluded by the rules in this fileset. * * @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 ); if ( scanner != null ) { return scanner.getExcludedFiles(); } return EMPTY_STRING_ARRAY; } /** * Get all the directory names which have been excluded by the rules in this fileset. * * @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 ); if ( scanner != null ) { return scanner.getExcludedDirectories(); } return EMPTY_STRING_ARRAY; } /** * Delete the matching files and directories for the given file-set definition. * * @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 ); } /** * Delete the matching files and directories for the given file-set definition. * * @param fileSet The file-set matching rules, along with search base directory. * @param throwsError Throw IOException when errors have occurred by deleting files or directories. * @throws IOException If a matching file cannot be deleted andthrowsError=true
, otherwise
* print warning messages.
*/
public void delete( FileSet fileSet, boolean throwsError )
throws IOException
{
Set deletablePaths = findDeletablePaths( fileSet );
if ( messages != null && messages.isDebugEnabled() )
{
messages
.addDebugMessage( "Found deletable paths: " + String.valueOf( deletablePaths ).replace( ',', '\n' ) ).flush();
}
List warnMessages = new LinkedList();
for ( Iterator it = deletablePaths.iterator(); it.hasNext(); )
{
String path = (String) it.next();
File file = new File( fileSet.getDirectory(), path );
if ( file.exists() )
{
if ( file.isDirectory() )
{
if ( fileSet.isFollowSymlinks() || !isSymlink( file ) )
{
if ( verbose && messages != null )
{
messages.addInfoMessage( "Deleting directory: " + file ).flush();
}
removeDir( file, fileSet.isFollowSymlinks(), throwsError, warnMessages );
}
else
{ // delete a symlink to a directory without follow
if ( verbose && messages != null )
{
messages.addInfoMessage( "Deleting symlink to directory: " + file ).flush();
}
if ( !file.delete() )
{
String message = "Unable to delete symlink " + file.getAbsolutePath();
if ( throwsError )
{
throw new IOException( message );
}
if ( !warnMessages.contains( message ) )
{
warnMessages.add( message );
}
}
}
}
else
{
if ( verbose && messages != null )
{
messages.addInfoMessage( "Deleting file: " + file ).flush();
}
if ( !delete( file ) )
{
String message = "Failed to delete file " + file.getAbsolutePath() + ". Reason is unknown.";
if ( throwsError )
{
throw new IOException( message );
}
warnMessages.add( message );
}
}
}
}
if ( messages != null && messages.isWarningEnabled() && !throwsError && ( warnMessages.size() > 0 ) )
{
for ( Iterator it = warnMessages.iterator(); it.hasNext(); )
{
String msg = (String) it.next();
messages.addWarningMessage( msg ).flush();
}
}
}
// ----------------------------------------------------------------------
// Private methods
// ----------------------------------------------------------------------
private boolean isSymlink( File file )
throws IOException
{
File fileInCanonicalParent = null;
File parentDir = file.getParentFile();
if ( parentDir == null )
{
fileInCanonicalParent = file;
}
else
{
fileInCanonicalParent = new File( parentDir.getCanonicalPath(), file.getName() );
}
if ( messages != null && messages.isDebugEnabled() )
{
messages.addDebugMessage(
"Checking for symlink:\nFile's canonical path: "
+ fileInCanonicalParent.getCanonicalPath()
+ "\nFile's absolute path with canonical parent: "
+ fileInCanonicalParent.getPath() ).flush();
}
return !fileInCanonicalParent.getCanonicalFile().equals( fileInCanonicalParent.getAbsoluteFile() );
}
private Set findDeletablePaths( FileSet fileSet )
{
Set includes = findDeletableDirectories( fileSet );
includes.addAll( findDeletableFiles( fileSet, includes ) );
return includes;
}
private Set findDeletableDirectories( FileSet fileSet )
{
if ( verbose && messages != null )
{
messages.addInfoMessage( "Scanning for deletable directories." ).flush();
}
DirectoryScanner scanner = scan( fileSet );
if ( scanner == null )
{
return Collections.EMPTY_SET;
}
Set includes = new HashSet( Arrays.asList( scanner.getIncludedDirectories() ) );
Collection excludes = new ArrayList( Arrays.asList( scanner.getExcludedDirectories() ) );
Collection linksForDeletion = new ArrayList();
if ( !fileSet.isFollowSymlinks() )
{
if ( verbose && messages != null )
{
messages
.addInfoMessage( "Adding symbolic link dirs which were previously excluded to the list being deleted." ).flush();
}
// we need to see which entries were only excluded because they're symlinks...
scanner.setFollowSymlinks( true );
scanner.scan();
if ( messages != null && messages.isDebugEnabled() )
{
messages.addDebugMessage( "Originally marked for delete: " + includes ).flush();
messages.addDebugMessage( "Marked for preserve (with followSymlinks == false): " + excludes ).flush();
}
List includedDirsAndSymlinks = Arrays.asList( scanner.getIncludedDirectories() );
linksForDeletion.addAll( excludes );
linksForDeletion.retainAll( includedDirsAndSymlinks );
if ( messages != null && messages.isDebugEnabled() )
{
messages.addDebugMessage( "Symlinks marked for deletion (originally mismarked): " + linksForDeletion ).flush();
}
excludes.removeAll( includedDirsAndSymlinks );
}
excludeParentDirectoriesOfExcludedPaths( excludes, includes );
includes.addAll( linksForDeletion );
return includes;
}
private Set findDeletableFiles( FileSet fileSet, Set deletableDirectories )
{
if ( verbose && messages != null )
{
messages.addInfoMessage( "Re-scanning for deletable files." ).flush();
}
DirectoryScanner scanner = scan( fileSet );
if ( scanner == null )
{
return deletableDirectories;
}
Set includes = deletableDirectories;
includes.addAll( Arrays.asList( scanner.getIncludedFiles() ) );
Collection excludes = new ArrayList( Arrays.asList( scanner.getExcludedFiles() ) );
Collection linksForDeletion = new ArrayList();
if ( !fileSet.isFollowSymlinks() )
{
if ( verbose && messages != null )
{
messages
.addInfoMessage( "Adding symbolic link files which were previously excluded to the list being deleted." ).flush();
}
// we need to see which entries were only excluded because they're symlinks...
scanner.setFollowSymlinks( true );
scanner.scan();
if ( messages != null && messages.isDebugEnabled() )
{
messages.addDebugMessage( "Originally marked for delete: " + includes ).flush();
messages.addDebugMessage( "Marked for preserve (with followSymlinks == false): " + excludes ).flush();
}
List includedFilesAndSymlinks = Arrays.asList( scanner.getIncludedFiles() );
linksForDeletion.addAll( excludes );
linksForDeletion.retainAll( includedFilesAndSymlinks );
if ( messages != null && messages.isDebugEnabled() )
{
messages.addDebugMessage( "Symlinks marked for deletion (originally mismarked): " + linksForDeletion ).flush();
}
excludes.removeAll( includedFilesAndSymlinks );
}
excludeParentDirectoriesOfExcludedPaths( excludes, includes );
includes.addAll( linksForDeletion );
return includes;
}
/**
* 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
* null
.
* @param deletablePaths The relative paths to files/directories which are scheduled for deletion, must not be
* null
.
*/
private void excludeParentDirectoriesOfExcludedPaths( Collection excludedPaths, Set deletablePaths )
{
for ( Iterator it = excludedPaths.iterator(); it.hasNext(); )
{
String path = (String) it.next();
String parentPath = new File( path ).getParent();
while ( parentPath != null )
{
if ( messages != null && messages.isDebugEnabled() )
{
messages.addDebugMessage( "Verifying path " + parentPath
+ " is not present; contains file which is excluded." ).flush();
}
boolean removed = deletablePaths.remove( parentPath );
if ( removed && messages != null && messages.isDebugEnabled() )
{
messages.addDebugMessage( "Path " + parentPath + " was removed from delete list." ).flush();
}
parentPath = new File( parentPath ).getParent();
}
}
if ( !excludedPaths.isEmpty() )
{
if ( messages != null && messages.isDebugEnabled() )
{
messages.addDebugMessage( "Verifying path " + "."
+ " is not present; contains file which is excluded." ).flush();
}
boolean removed = deletablePaths.remove( "" );
if ( removed && messages != null && messages.isDebugEnabled() )
{
messages.addDebugMessage( "Path " + "." + " was removed from delete list." ).flush();
}
}
}
/**
* Delete a directory
*
* @param dir the directory to delete
* @param followSymlinks whether to follow symbolic links, or simply delete the link
* @param throwsError Throw IOException when errors have occurred by deleting files or directories.
* @param warnMessages A list of warning messages used when throwsError=false
.
* @throws IOException If a matching file cannot be deleted and throwsError=true
.
*/
private void removeDir( File dir, boolean followSymlinks, boolean throwsError, List warnMessages )
throws IOException
{
String[] list = dir.list();
if ( list == null )
{
list = new String[0];
}
for ( int i = 0; i < list.length; i++ )
{
String s = list[i];
File f = new File( dir, s );
if ( f.isDirectory() && ( followSymlinks || !isSymlink( f ) ) )
{
removeDir( f, followSymlinks, throwsError, warnMessages );
}
else
{
if ( !delete( f ) )
{
String message = "Unable to delete file " + f.getAbsolutePath();
if ( throwsError )
{
throw new IOException( message );
}
if ( !warnMessages.contains( message ) )
{
warnMessages.add( message );
}
}
}
}
if ( !delete( dir ) )
{
String message = "Unable to delete directory " + dir.getAbsolutePath();
if ( throwsError )
{
throw new IOException( message );
}
if ( !warnMessages.contains( message ) )
{
warnMessages.add( message );
}
}
}
/**
* Delete a file
*
* @param f a file
*/
private boolean delete( File f )
{
try
{
FileUtils.forceDelete( f );
}
catch ( IOException e )
{
return false;
}
return true;
}
private DirectoryScanner scan( FileSet fileSet )
{
File basedir = new File( fileSet.getDirectory() );
if ( !basedir.exists() || !basedir.isDirectory() )
{
return null;
}
DirectoryScanner scanner = new DirectoryScanner();
String[] includesArray = fileSet.getIncludesArray();
String[] excludesArray = fileSet.getExcludesArray();
if ( includesArray.length > 0 )
{
scanner.setIncludes( includesArray );
}
if ( excludesArray.length > 0 )
{
scanner.setExcludes( excludesArray );
}
if ( fileSet.isUseDefaultExcludes() )
{
scanner.addDefaultExcludes();
}
scanner.setBasedir( basedir );
scanner.setFollowSymlinks( fileSet.isFollowSymlinks() );
scanner.scan();
return scanner;
}
}
maven-file-management-1.2.1/pom.xml 0000644 0001750 0001750 00000007262 11131007134 017121 0 ustar twerner twerner