/*
 * 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.mojo;

import net.nicoulaj.maven.plugins.checksum.Constants;
import net.nicoulaj.maven.plugins.checksum.execution.Execution;
import net.nicoulaj.maven.plugins.checksum.execution.ExecutionException;
import net.nicoulaj.maven.plugins.checksum.execution.FailOnErrorExecution;
import net.nicoulaj.maven.plugins.checksum.execution.NeverFailExecution;
import net.nicoulaj.maven.plugins.checksum.execution.target.CsvSummaryFileTarget;
import net.nicoulaj.maven.plugins.checksum.execution.target.MavenLogTarget;

import org.apache.maven.artifact.Artifact;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.project.MavenProject;

import java.io.File;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;

/**
 * Compute project dependencies checksum digests and store them in a summary file.
 *
 * @author <a href="mailto:julien.nicoulaud@gmail.com">Julien Nicoulaud</a>
 * @goal dependencies
 * @phase verify
 * @requiresProject true
 * @inheritByDefault false
 * @requiresDependencyResolution runtime
 * @since 1.0
 */
public class DependenciesMojo extends AbstractMojo
{
    /**
     * The Maven project.
     *
     * @parameter expression="${project}"
     * @required
     * @readonly
     * @since 1.0
     */
    protected MavenProject project;

    /**
     * The list of checksum algorithms used.
     *
     * <p>Default value is MD5 and SHA-1.<br/>Allowed values are CRC32, MD2, MD4, MD5, SHA-1, SHA-224, SHA-256, SHA-384,
     * SHA-512, RIPEMD128, RIPEMD160, RIPEMD256, RIPEMD320, GOST3411 and Tiger.</p>
     *
     * <p> Use the following syntax:
     * <pre>&lt;algorithms&gt;
     *   &lt;algorithm&gt;MD5&lt;algorithm&gt;
     *   &lt;algorithm&gt;SHA-1&lt;algorithm&gt;
     * &lt;/algorithms&gt;</pre>
     * </p>
     *
     * @parameter
     * @since 1.0
     */
    protected List<String> algorithms = Arrays.asList( Constants.DEFAULT_EXECUTION_ALGORITHMS );

    /**
     * Indicates whether the build will fail if there are errors.
     *
     * @parameter default-value="true"
     * @since 1.0
     */
    protected boolean failOnError;

    /**
     * Indicates whether the build will print checksums in the build log.
     *
     * @parameter default-value="false"
     * @since 1.0
     */
    protected boolean quiet;

    /**
     * The name of the summary file created.
     *
     * @parameter default-value="dependencies-checksums.csv"
     * @since 1.0
     */
    protected String summaryFileName;

    /**
     * The dependency scopes to include.
     *
     * <p>Allowed values are compile, test, runtime, provided and system.<br/>All scopes are included by default.</p>
     *
     * <p> Use the following syntax:
     * <pre>&lt;scopes&gt;
     *   &lt;scope&gt;compile&lt;scope&gt;
     *   &lt;scope&gt;runtime&lt;scope&gt;
     * &lt;/scopes&gt;</pre>
     * </p>
     *
     * @parameter
     * @since 1.0
     */
    protected List<String> scopes;

    /**
     * The dependency types to include.
     *
     * <p>All types are included by default.</p>
     *
     * <p> Use the following syntax:
     * <pre>&lt;types&gt;
     *   &lt;type&gt;jar&lt;type&gt;
     *   &lt;type&gt;zip&lt;type&gt;
     * &lt;/types&gt;</pre>
     * </p>
     *
     * @parameter
     * @since 1.0
     */
    protected List<String> types;

    /**
     * {@inheritDoc}
     */
    public void execute() throws MojoExecutionException, MojoFailureException
    {
        // Prepare an execution.
        Execution execution = ( failOnError ) ? new FailOnErrorExecution() : new NeverFailExecution( getLog() );
        execution.setAlgorithms( algorithms );
        execution.setFiles( getFilesToProcess() );
        if ( !quiet )
        {
            execution.addTarget( new MavenLogTarget( getLog() ) );
        }
        execution.addTarget( new CsvSummaryFileTarget( project.getBuild().getDirectory()
                                                       + File.separator + summaryFileName ) );

        // Run the execution.
        try
        {
            execution.run();
        }
        catch ( ExecutionException e )
        {
            getLog().error( e.getMessage() );
            throw new MojoFailureException( e.getMessage() );
        }
    }

    /**
     * Build the list of files from which digests should be generated.
     *
     * <p>The list is composed of the project dependencies.</p>
     *
     * @return the list of files that should be processed.
     */
    protected List<File> getFilesToProcess()
    {
        List<File> files = new LinkedList<File>();

        for ( Artifact artifact : ( Set<Artifact> ) project.getDependencyArtifacts() )
        {
            if ( ( scopes == null || scopes != null && scopes.contains( artifact.getScope() ) )
                 && ( types == null || types != null && types.contains( artifact.getType() ) ) )
            {
                files.add( artifact.getFile() );
            }
        }

        return files;
    }
}

@@ -5488,26 +5488,8 @@
 l %7C%7C
- scopes != null &&
  sco
@@ -5568,25 +5568,8 @@
 l %7C%7C
- types != null &&
  typ

Remove unnecessary check