/*
 * Copyright 2010 Julien Nicoulaud <julien.nicoulaud@gmail.com>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package net.nicoulaj.maven.plugins.checksum.execution.target;

import net.nicoulaj.maven.plugins.checksum.digest.DigesterFactory;

import org.codehaus.plexus.util.FileUtils;

import java.io.File;
import java.io.IOException;
import java.security.NoSuchAlgorithmException;

/**
 * An {@link ExecutionTarget} that writes digests to separate files.
 *
 * @author <a href="mailto:julien.nicoulaud@gmail.com">Julien Nicoulaud</a>
 * @since 1.0
 */
public class OneHashPerFileTarget implements ExecutionTarget
{
    /**
     * Encoding to use for generated files.
     */
    protected String encoding;

    /**
     * Build a new instance of {@link OneHashPerFileTarget}.
     *
     * @param encoding the encoding to use for generated files.
     */
    public OneHashPerFileTarget( String encoding )
    {
        this.encoding = encoding;
    }

    /**
     * {@inheritDoc}
     */
    public void init()
    {
        // Nothing to do
    }

    /**
     * {@inheritDoc}
     */
    public void write( String digest, File file, String algorithm ) throws ExecutionTargetWriteException
    {
        try
        {
            FileUtils.fileWrite( file.getPath() + DigesterFactory.getInstance()
                                                                 .getFileDigester( algorithm )
                                                                 .getFileExtension(),
                                 digest );
        }
        catch ( IOException e )
        {
            throw new ExecutionTargetWriteException( e.getMessage() );
        }
        catch ( NoSuchAlgorithmException e )
        {
            throw new ExecutionTargetWriteException( e.getMessage() );
        }
    }

    /**
     * {@inheritDoc}
     */
    public void close()
    {
        // Nothing to do
    }
}

@@ -1219,16 +1219,485 @@
 oding;%0A%0A
+    /**%0A     * The files output directory.%0A     */%0A    protected File outputDirectory;%0A%0A    /**%0A     * Build a new instance of %7B@link OneHashPerFileTarget%7D.%0A     *%0A     * @param encoding        the encoding to use for generated files.%0A     * @param outputDirectory the files output directory.%0A     */%0A    public OneHashPerFileTarget( String encoding, File outputDirectory )%0A    %7B%0A        this.encoding = encoding;%0A        this.outputDirectory = outputDirectory;%0A    %7D%0A%0A
     /**%0A
@@ -1901,33 +1901,34 @@
         this
-.
+( 
 encoding
  = encoding;
@@ -1911,35 +1911,32 @@
 is( encoding
- = encoding
+, null )
 ;%0A    %7D%0A%0A   
@@ -1995,39 +1995,526 @@
 it()
-%0A    %7B%0A        // Nothing to do
+ throws ExecutionTargetInitializationException%0A    %7B%0A        // Make sure the output directory exists or can be created.%0A        if ( outputDirectory != null )%0A        %7B%0A            if ( outputDirectory.exists() && !outputDirectory.isDirectory() )%0A            %7B%0A                throw new ExecutionTargetInitializationException( %22'%22 + outputDirectory.getPath() + %22' already exists and is not a directory.%22 );%0A            %7D%0A            else%0A            %7B%0A                outputDirectory.mkdirs();%0A            %7D%0A        %7D
 %0A   
@@ -2707,37 +2707,149 @@
 File
-Utils.fileWrite( file.getPath
+ outputFileDirectory = ( outputDirectory != null ) ? outputDirectory : file.getParentFile();%0A            String outputFileName = file.getName
 () +
@@ -2875,24 +2875,27 @@
 tInstance()%0A
+   
             
@@ -3034,32 +3034,35 @@
                 
+   
 .getFileExtensio
@@ -3068,15 +3068,10 @@
 on()
-,%0A     
+;%0A
     
@@ -3078,31 +3078,101 @@
         
-               
+FileUtils.fileWrite( outputFileDirectory.getPath() + File.separator + outputFileName,
  digest 

Allow to customize individual files output directory