net.nicoulaj.maven.plugins.checksum.execution.target.OneHashPerFileTarget Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of maven-checksum-plugin Show documentation
Show all versions of maven-checksum-plugin Show documentation
Compute project artifacts/dependencies/files checksum digests and output them to individual or summary files.
/*
* Copyright 2010 Julien Nicoulaud
*
* 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 Julien Nicoulaud
* @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
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy