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/20 17:24:52 UTC
cvs commit: maven/src/plugins-build/artifact/src/main/org/apache/maven/deploy/deployers FileDeployer.java
michal 2003/06/20 08:24:52
Modified: src/plugins-build/artifact/src/main/org/apache/maven/artifact/deployer
DefaultArtifactDeployer.java
MavenDeployRequest.java
src/plugins-build/artifact/src/main/org/apache/maven/deploy/deployers
FileDeployer.java
Log:
Partialy implemeneted "6 files method"
described http://nagoya.apache.org/wiki/apachewiki.cgi?Maven/DeployDependCycle
I need to copy foo-snapshot-version and copy foo-snapshot-version.md5 files.
Revision Changes Path
1.5 +167 -42 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.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- DefaultArtifactDeployer.java 19 Jun 2003 22:02:37 -0000 1.4
+++ DefaultArtifactDeployer.java 20 Jun 2003 15:24:52 -0000 1.5
@@ -56,7 +56,9 @@
*/
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;
@@ -67,6 +69,7 @@
import org.apache.maven.MavenException;
import org.apache.maven.deploy.DeployTool;
import org.apache.maven.project.Project;
+import org.apache.maven.util.MD5Sum;
/**
*
@@ -87,20 +90,34 @@
/**
* @see ArtifactDeployer#deploy(String, String, Project)
*/
- public void deploy(String file, String type, Project project)
+ public void deploy(String artifact, String type, Project project)
throws MavenException
{
- System.out.println("deploy");
- doDeploy(file, type, project, project.getCurrentVersion());
+
+ File file = getFileForArtifact(artifact);
+ File md5File = createMD5Checksum(file);
+ String repositoryPath =
+ getRepositoryPath(type, project, project.getCurrentVersion());
+ String repositoryFile =
+ getRepositoryFile(type, project, project.getCurrentVersion());
+ doDeploy(file, md5File, project, repositoryPath, repositoryFile);
}
/**
* @see DefaultArtifactDeployer#deploySnapshot(String, String, Project)
*/
- public void deploySnapshot(String file, String type, Project project)
+ public void deploySnapshot(String artifact, String type, Project project)
throws MavenException
{
- doDeploy(file, type, project, MavenConstants.SNAPSHOT_SIGNIFIER);
+ File file = getFileForArtifact(artifact);
+ File md5File = createMD5Checksum(file);
+ 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);
+
}
/**
@@ -109,7 +126,8 @@
public void install(String artifact, String type, Project project)
throws MavenException
{
- doInstall(artifact, type, project, project.getCurrentVersion());
+ File file = getFileForArtifact(artifact);
+ doInstall(file, type, project, project.getCurrentVersion());
}
/**
@@ -118,14 +136,11 @@
public void installSnapshot(String artifact, String type, Project project)
throws MavenException
{
+ File file = getFileForArtifact(artifact);
System.out.println("Installing snapshot of:'" + artifact + "''");
try
{
- doInstall(
- artifact,
- type,
- project,
- MavenConstants.SNAPSHOT_SIGNIFIER);
+ doInstall(file, type, project, MavenConstants.SNAPSHOT_SIGNIFIER);
}
catch (MavenException e)
{
@@ -133,7 +148,7 @@
}
try
{
- doInstall(artifact, type, project, getSnapshotVersion());
+ doInstall(file, type, project, getSnapshotVersion());
}
catch (MavenException e)
{
@@ -150,7 +165,7 @@
* @throws MavenException
*/
private void doInstall(
- String artifact,
+ File file,
String type,
Project project,
String version)
@@ -158,27 +173,26 @@
{
try
- {
- File file =
+ {
+ File destFile =
new File(
getLocalRepository(project),
getRepositoryPath(type, project, version));
-
if (!file.exists())
{
file.mkdirs();
}
file = new File(file, getRepositoryFile(type, project, version));
System.out.println(
- "Copying: from '" + artifact + "' to: '" + file + "'");
- FileUtils.copyFile(new File(artifact), file);
+ "Copying: from '" + file + "' to: '" + destFile + "'");
+ FileUtils.copyFile(file, destFile);
}
catch (IOException e)
{
String msg =
"Cannot install file: '"
- + artifact
+ + file
+ "'. Reason: "
+ e.getMessage();
throw new MavenException(msg, e);
@@ -193,10 +207,11 @@
* @param snapshot
*/
private void doDeploy(
- String artifact,
- String type,
+ File file,
+ File md5File,
Project project,
- String version)
+ String repositoryPath,
+ String repositoryFile)
throws MavenException
{
@@ -206,8 +221,8 @@
String repos =
(String) project.getContext().getVariable("maven.repo.repos");
-
- System.out.println( "repos: "+ repos );
+
+ System.out.println("repos: " + repos);
String distSite = project.getDistributionSite();
if (distSite != null && distSite.length() > 0)
@@ -221,50 +236,69 @@
repos = "central, " + repos;
}
-
if (repos == null || repos.length() == 0)
{
- System.out.println("No remote repository is defined");
- return;
+ System.out.println("No remote repository is defined");
+ return;
}
String[] repoArray = StringUtils.split(repos, ",");
System.out.println(
"Will deploy to " + repoArray.length + " repo(s): " + repos);
+
- String repositoryPath = getRepositoryPath(type, project, version);
-
+
for (int i = 0; i < repoArray.length; i++)
{
String repo = repoArray[i].trim();
System.out.println("Deploying to repo: " + repo);
- MavenDeployRequest request =
+ MavenDeployRequest deployRequest =
new MavenDeployRequest(
repo,
project,
repo,
- artifact,
+ file.getAbsolutePath(),
repositoryPath,
- getRepositoryFile(type, project, version));
+ repositoryFile);
+
+ MavenDeployRequest md5DeployRequest =
+ new MavenDeployRequest(
+ repo,
+ project,
+ repo,
+ md5File.getAbsolutePath(),
+ repositoryPath,
+ repositoryFile + ".md5");
- System.out.println(
- "Deploying: '"
- + artifact
- + "' to host: '"
- + request.getHost()
- + "' remote path: '"
- + request.getOutputDir());
try
{
- deployTool.performUpload(request);
+ 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);
+ throw new MavenException(
+ "Cannot deploy. Reason:" + e.getMessage(),
+ e);
}
}
@@ -336,6 +370,97 @@
return "jar";
}
return type;
+ }
+
+ /**
+ *
+ * @param artifact
+ * @return
+ */
+ private File getFileForArtifact(String artifact) throws MavenException
+ {
+ File file = new File(artifact);
+ if (!file.exists())
+ {
+ String msg = "Artifact file: '" + artifact + "' must exist";
+ throw new MavenException(msg);
+ }
+ if (!file.canRead())
+ {
+ String msg = "Artifact file: '" + artifact + "' must be readable";
+ throw new MavenException(msg);
+ }
+ if (file.isDirectory())
+ {
+ String msg =
+ "Artifact file: '" + artifact + "' must not be a directory";
+ throw new MavenException(msg);
+ }
+ return file.getAbsoluteFile();
+
+ }
+
+ private File createMD5Checksum(File file) throws MavenException
+ {
+ MD5Sum md5Sum = new MD5Sum();
+ md5Sum.setFile(file);
+ try
+ {
+ md5Sum.execute();
+ }
+ catch (Exception 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");
+ }
+ finally
+ {
+ if (writer != null)
+ {
+ try
+ {
+ writer.close();
+ }
+ catch (IOException e2)
+ {
+ }
+ }
+ }
+ return md5ChecksumFile;
+
}
}
1.4 +6 -3 maven/src/plugins-build/artifact/src/main/org/apache/maven/artifact/deployer/MavenDeployRequest.java
Index: MavenDeployRequest.java
===================================================================
RCS file: /home/cvs/maven/src/plugins-build/artifact/src/main/org/apache/maven/artifact/deployer/MavenDeployRequest.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- MavenDeployRequest.java 19 Jun 2003 22:02:37 -0000 1.3
+++ MavenDeployRequest.java 20 Jun 2003 15:24:52 -0000 1.4
@@ -167,9 +167,12 @@
setInputFile(inputFile);
- String ouputDir = dir + "/" + outputDir;
+ if (dir != null)
+ {
+ outputDir = dir + "/" + outputDir;
+ }
setOutputFile(outputFile);
- setOutputDir(ouputDir);
+ setOutputDir(outputDir);
}
1.3 +2 -5 maven/src/plugins-build/artifact/src/main/org/apache/maven/deploy/deployers/FileDeployer.java
Index: FileDeployer.java
===================================================================
RCS file: /home/cvs/maven/src/plugins-build/artifact/src/main/org/apache/maven/deploy/deployers/FileDeployer.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- FileDeployer.java 19 Jun 2003 22:02:36 -0000 1.2
+++ FileDeployer.java 20 Jun 2003 15:24:52 -0000 1.3
@@ -87,10 +87,7 @@
{
outputFile.mkdirs();
}
- outputFile = new File( outputFile, request.getOutputFile());
- System.out.println("Copining from: " + inputFile + " to: " + outputFile);
-
-
+ outputFile = new File( outputFile, request.getOutputFile());
FileUtils.copyFile(inputFile, outputFile);
}
catch (IOException e)
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
For additional commands, e-mail: dev-help@maven.apache.org