Implemented 5 file method.

git-svn-id: https://svn.apache.org/repos/asf/maven/maven-1/plugins/trunk@113532 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
michal 2003-06-23 09:49:38 +00:00
parent 9307df7255
commit f230073241

View File

@ -56,9 +56,7 @@ package org.apache.maven.artifact.deployer;
*/
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Writer;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
@ -76,7 +74,7 @@ import org.apache.maven.util.MD5Sum;
* Default implemenataion of Artifact Deployer interface
*
* @author <a href="michal.maczka@dimatics.com">Michal Maczka</a>
* @version $Id: DefaultArtifactDeployer.java,v 1.5 2003/06/20 15:24:52 michal Exp $
* @version $Id: DefaultArtifactDeployer.java,v 1.6 2003/06/23 09:49:38 michal Exp $
*/
public class DefaultArtifactDeployer implements ArtifactDeployer
{
@ -89,6 +87,15 @@ public class DefaultArtifactDeployer implements ArtifactDeployer
/**
* @see ArtifactDeployer#deploy(String, String, Project)
* This is "5 files" version.
* It deploys (example):
* foo-20030620.124616.jar,
* foo-20030620.124616.jar.md5 ,
* foo-SNAPSHOT.jar
* foo-SNAPSHOT.jar.md5
* foo-snapshot-version
*
*
*/
public void deploy(String artifact, String type, Project project)
throws MavenException
@ -100,7 +107,13 @@ public class DefaultArtifactDeployer implements ArtifactDeployer
getRepositoryPath(type, project, project.getCurrentVersion());
String repositoryFile =
getRepositoryFile(type, project, project.getCurrentVersion());
doDeploy(file, md5File, project, repositoryPath, repositoryFile);
String[] inputFilenames =
{ file.getAbsolutePath(), md5File.getAbsolutePath()};
String[] outputFilenames = { repositoryFile, repositoryFile + ".md5" };
doDeploy(inputFilenames, outputFilenames, repositoryPath, project);
}
/**
@ -109,16 +122,35 @@ public class DefaultArtifactDeployer implements ArtifactDeployer
public void deploySnapshot(String artifact, String type, Project project)
throws MavenException
{
String snapshotVersion = getSnapshotVersion();
File file = getFileForArtifact(artifact);
File md5File = createMD5Checksum(file);
File snapshotVersionFile =
createSnapshotVersionFile(file, snapshotVersion, project, type);
String repositoryPath =
getRepositoryPath(type, project, MavenConstants.SNAPSHOT_SIGNIFIER);
String repositoryFile =
getRepositoryFile(type, project, MavenConstants.SNAPSHOT_SIGNIFIER);
doDeploy(file, md5File, project, repositoryPath, repositoryFile);
doDeploy(file, md5File, project, repositoryPath, repositoryFile);
}
String[] inputFilenames = new String[5];
inputFilenames[0] = file.getAbsolutePath();
inputFilenames[1] = file.getAbsolutePath();
inputFilenames[2] = md5File.getAbsolutePath();
inputFilenames[3] = md5File.getAbsolutePath();
inputFilenames[4] = snapshotVersionFile.getAbsolutePath();
String out1 =
getRepositoryFile(type, project, MavenConstants.SNAPSHOT_SIGNIFIER);
String out2 = getRepositoryFile(type, project, snapshotVersion);
String[] outputFilenames = new String[5];
outputFilenames[0] = out1;
outputFilenames[1] = out2;
outputFilenames[2] = out1 + ".md5";
outputFilenames[3] = out2 + ".md5";
outputFilenames[4] = project.getArtifactId() + "-snapshot-version";
doDeploy(inputFilenames, outputFilenames, repositoryPath, project);
};
/**
* @see ArtifactDeployer#install(String, String, Project)
@ -207,11 +239,10 @@ public class DefaultArtifactDeployer implements ArtifactDeployer
* @param snapshot
*/
private void doDeploy(
File file,
File md5File,
Project project,
String repositoryPath,
String repositoryFile)
String[] inputFilenames,
String[] outputFilenames,
String outputPath,
Project project)
throws MavenException
{
@ -247,60 +278,45 @@ public class DefaultArtifactDeployer implements ArtifactDeployer
System.out.println(
"Will deploy to " + repoArray.length + " repo(s): " + repos);
for (int i = 0; i < repoArray.length; i++)
{
String repo = repoArray[i].trim();
System.out.println("Deploying to repo: " + repo);
MavenDeployRequest deployRequest =
new MavenDeployRequest(
repo,
project,
repo,
file.getAbsolutePath(),
repositoryPath,
repositoryFile);
MavenDeployRequest md5DeployRequest =
new MavenDeployRequest(
repo,
project,
repo,
md5File.getAbsolutePath(),
repositoryPath,
repositoryFile + ".md5");
try
for (int j = 0; j < inputFilenames.length; j++)
{
System.out.println(
"Deploying: '"
+ file
+ "' to host: '"
+ deployRequest.getHost()
+ "' remote path: '"
+ deployRequest.getOutputDir());
deployTool.performUpload(deployRequest);
System.out.println(
"Deploying: '"
+ md5File
+ "' to host: '"
+ md5DeployRequest.getHost()
+ "' remote path: '"
+ md5DeployRequest.getOutputDir());
deployTool.performUpload(md5DeployRequest);
}
catch (Exception e)
{
e.printStackTrace();
throw new MavenException(
"Cannot deploy. Reason:" + e.getMessage(),
e);
}
MavenDeployRequest deployRequest =
new MavenDeployRequest(
repo,
project,
repo,
inputFilenames[j],
outputPath,
outputFilenames[j]);
try
{
System.out.println(
"Deploying: '"
+ outputFilenames[j]
+ "' to host: '"
+ deployRequest.getHost()
+ "' remote path: '"
+ deployRequest.getOutputDir()
+ "' remote file: '"
+ deployRequest.getOutputFile());
deployTool.performUpload(deployRequest);
}
catch (Exception e)
{
e.printStackTrace();
throw new MavenException(
"Cannot deploy. Reason:" + e.getMessage(),
e);
}
}
}
}
@ -400,6 +416,40 @@ public class DefaultArtifactDeployer implements ArtifactDeployer
}
/**
* @param snapshotVersion
* @param project
* @param type
* @return
*/
private File createSnapshotVersionFile(
File artifact,
String snapshotVersion,
Project project,
String type)
throws MavenException
{
File file = null;
String basename = FileUtils.basename(artifact.getAbsolutePath());
String filename =
project.getArtifactId() + "-" + type + "-snapshot-version";
try
{
file = new File(artifact.getParent(), filename);
FileUtils.fileWrite(file.getAbsolutePath(), snapshotVersion);
}
catch (Exception e)
{
throw new MavenException(
"Cannot create snapshot-version file:" + file);
}
return file;
}
/**
*/
private File createMD5Checksum(File file) throws MavenException
{
MD5Sum md5Sum = new MD5Sum();
@ -410,54 +460,24 @@ public class DefaultArtifactDeployer implements ArtifactDeployer
}
catch (Exception e)
{
throw new MavenException("MD5 checksum error: " + e.getMessage(), e);
throw new MavenException(
"MD5 checksum error: " + e.getMessage(),
e);
}
String checksum = md5Sum.getChecksum();
String basename = FileUtils.basename(file.getAbsolutePath());
File md5ChecksumFile = null;
try
{
md5ChecksumFile =
File.createTempFile(basename, ".md5", file.getParentFile());
md5ChecksumFile = new File(file.getAbsoluteFile() + ".md5");
FileUtils.fileWrite(md5ChecksumFile.getAbsolutePath(), checksum);
}
catch (IOException e)
catch (Exception e)
{
// Cannot create file in the same directory where we have
// will try in default temporary-file directory
try
{
md5ChecksumFile = File.createTempFile(basename, ".md5");
}
catch (Exception e2)
{
throw new MavenException("Cannot create md5 checksum file");
}
}
Writer writer = null;
try
{
System.out.println("sum:" + checksum);
writer = new FileWriter(md5ChecksumFile);
writer.write(checksum);
}
catch (IOException e1)
{
throw new MavenException("Error occured while writing to md5 cheksum file");
}
finally
{
if (writer != null)
{
try
{
writer.close();
}
catch (IOException e2)
{
}
}
throw new MavenException(
"Cannot create md5 checksum file: " + md5ChecksumFile);
}
return md5ChecksumFile;