You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@maven.apache.org by mi...@apache.org on 2003/06/23 11:49:38 UTC
cvs commit: maven/src/plugins-build/artifact/src/main/org/apache/maven/artifact/deployer DefaultArtifactDeployer.java
michal 2003/06/23 02:49:38
Modified: src/plugins-build/artifact/src/main/org/apache/maven/artifact/deployer
DefaultArtifactDeployer.java
Log:
Implemented 5 file method.
Revision Changes Path
1.6 +119 -99 maven/src/plugins-build/artifact/src/main/org/apache/maven/artifact/deployer/DefaultArtifactDeployer.java
Index: DefaultArtifactDeployer.java
===================================================================
RCS file: /home/cvs/maven/src/plugins-build/artifact/src/main/org/apache/maven/artifact/deployer/DefaultArtifactDeployer.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- DefaultArtifactDeployer.java 20 Jun 2003 15:24:52 -0000 1.5
+++ DefaultArtifactDeployer.java 23 Jun 2003 09:49:38 -0000 1.6
@@ -56,9 +56,7 @@
*/
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;
@@ -89,6 +87,15 @@
/**
* @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 @@
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 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 =
+
+ 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);
- doDeploy(file, md5File, project, repositoryPath, repositoryFile);
- doDeploy(file, md5File, project, repositoryPath, repositoryFile);
+ 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 @@
* @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 @@
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 @@
}
+ /**
+ * @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 @@
}
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());
- }
- catch (IOException 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");
+ md5ChecksumFile = new File(file.getAbsoluteFile() + ".md5");
+ FileUtils.fileWrite(md5ChecksumFile.getAbsolutePath(), checksum);
}
- finally
+ catch (Exception e)
{
- if (writer != null)
- {
- try
- {
- writer.close();
- }
- catch (IOException e2)
- {
- }
- }
+ throw new MavenException(
+ "Cannot create md5 checksum file: " + md5ChecksumFile);
+
}
return md5ChecksumFile;
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
For additional commands, e-mail: dev-help@maven.apache.org