All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.bluestemsoftware.open.eoa.plugin.install.AbstractInstallMojo Maven / Gradle / Ivy

/**
 * Copyright 2008 Bluestem Software LLC.  All Rights Reserved.
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see .
 * 
 */

package org.bluestemsoftware.open.eoa.plugin.install;

/*
 * Adapted from org.apache.maven.plugin.install.AbstractInstallMojo which was released under the following
 * license:
 * 

* Copyright 2001-2005 The Apache Software Foundation. * * 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. */ import java.io.File; import java.io.IOException; import java.security.NoSuchAlgorithmException; import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.installer.ArtifactInstaller; import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.plugin.MojoExecutionException; import org.bluestemsoftware.open.eoa.plugin.AbstractDeploymentMojo; import org.bluestemsoftware.open.eoa.plugin.util.Digester; import org.codehaus.plexus.util.FileUtils; /** * Common fields for installation mojos. */ public abstract class AbstractInstallMojo extends AbstractDeploymentMojo { /** * @parameter expression="${component.org.apache.maven.artifact.installer.ArtifactInstaller}" * @required * @readonly */ protected ArtifactInstaller installer; /** * @parameter expression="${localRepository}" * @required * @readonly */ protected ArtifactRepository localRepository; // ********** commented out TWW ********** // /** // * Used to get the checksum of a file. // * // * @component role="org.apache.maven.repository.digest.Digester" // */ // private Digester digester; /** * Flag Whether to create checksums(MD5, SHA1) or not. * * @parameter expression="${createChecksum}" default-value="false" */ protected boolean createChecksum; protected void installCheckSum(File file, boolean isPom) throws MojoExecutionException { installCheckSum(file, null, isPom); } protected void installCheckSum(File file, Artifact artifact, boolean isPom) throws MojoExecutionException { try { getLog().info("Creating Checksums..."); String md5Sum = getChecksum(file, Digester.MD5); String sha1Sum = getChecksum(file, Digester.SHA1); File temp = File.createTempFile("maven-md5-checksum", null); temp.deleteOnExit(); FileUtils.fileWrite(temp.getAbsolutePath(), md5Sum); File tempSha1 = File.createTempFile("maven-sha1-checksum", null); tempSha1.deleteOnExit(); FileUtils.fileWrite(tempSha1.getAbsolutePath(), sha1Sum); File destination = null; if (isPom) { destination = file; } else { String localPath = localRepository.pathOf(artifact); destination = new File(localRepository.getBasedir(), localPath); } if (!destination.getParentFile().exists()) { destination.getParentFile().mkdirs(); } getLog().debug("Installing checksum for " + destination); FileUtils.copyFile(temp, new File(destination + ".md5")); FileUtils.copyFile(tempSha1, new File(destination + ".sha1")); } catch (IOException e) { throw new MojoExecutionException("Error creating checksum", e); } catch (NoSuchAlgorithmException e) { throw new MojoExecutionException("Error in algorithm", e); } catch (Exception ex) { throw new MojoExecutionException(ex.getMessage(), ex); } } protected String getChecksum(File file, String algo) throws NoSuchAlgorithmException, IOException { return Digester.createChecksum(file, algo); // modified to invoke static method TWW } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy