Skip to content

Commit

Permalink
initial import
Browse files Browse the repository at this point in the history
  • Loading branch information
unknown committed Jan 27, 2010
0 parents commit c23ed84
Show file tree
Hide file tree
Showing 17 changed files with 685 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .classpath
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="test"/>
<classpathentry kind="lib" path="lib/svnkit.jar"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
<classpathentry kind="output" path="bin"/>
</classpath>
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
bin/**/*
17 changes: 17 additions & 0 deletions .project
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>svn-diff-export</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
22 changes: 22 additions & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Copyright (c) 2010 Philip Gloyne

Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
42 changes: 42 additions & 0 deletions README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
---------------
Svn Diff Export
---------------
Date: 25-JAN-2010
Author: Philip Gloyne (philip.gloyne@gmail.com)

ABOUT
-----
Patch a baseline svn export to a newer branch. Allows a user to chain multiple svn commands:

svn diff --summarize | svn export <each file> | zip <dir>


WHY?
----
We use it to patch a large deployed project on a server we can't directly export to.


EXAMPLE USAGE:
--------------
Can be found in releases/1.0/svn-diff-export.bat.example


COMMANDS:
---------

Create a diff.patch file
java -jar svn-diff-export-1.0.jar diff <old-branch-url> <new-branch-url> <diff-file>

Export each of the files described in the diff.patch to a target directory
java -jar svn-diff-export-1.0.jar export <diff-file> <old-branch-url> <new-branch-url> <target-dir>

Create a revision file (usually in a public folder - we put ours next to robots.txt)
java -jar svn-diff-export-1.0.jar revision <new-branch-url> <revision-file-full-path>

Create a .zip of the 'export' folder to push to the server
java -jar svn-diff-export-1.0.jar zip <directory-to-zip>


TODO
----
Unit tests. Tidy up docs.
Binary file added lib/svnkit.jar
Binary file not shown.
Binary file added releases/1.0/svn-diff-export-1.0.jar
Binary file not shown.
10 changes: 10 additions & 0 deletions releases/1.0/svn-diff-export.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
@ECHO_OFF
REM %1 old branch url
REM %2 new branch url
REM %3 target directory (created)

mkdir %3
java -jar svn-diff-export-1.0.jar diff %1 %2 %3\diff.patch
java -jar svn-diff-export-1.0.jar export %3\diff.patch %1 %2 %3
java -jar svn-diff-export-1.0.jar revision %2 %3\coldfusion\sites\college_mes\htdocs\revision.txt
java -jar svn-diff-export-1.0.jar zip %3
10 changes: 10 additions & 0 deletions releases/1.0/svn-diff-export.bat.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
@ECHO_OFF
REM %1 old branch url
REM %2 new branch url
REM %3 target directory (created)

mkdir %3
java -jar svn-diff-export-1.0.jar diff %1 %2 %3\diff.patch
java -jar svn-diff-export-1.0.jar export %3\diff.patch %1 %2 %3
java -jar svn-diff-export-1.0.jar revision %2 %3\public\revision.txt
java -jar svn-diff-export-1.0.jar zip %3
2 changes: 2 additions & 0 deletions releases/1.0/svn.properties.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
svn.username=robot
svn.password=robot
102 changes: 102 additions & 0 deletions src/com/primed/sde/SvnDiffExport.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
package com.primed.sde;

import java.io.File;

import org.tmatesoft.svn.core.SVNURL;
import org.tmatesoft.svn.core.auth.BasicAuthenticationManager;
import org.tmatesoft.svn.core.internal.io.dav.DAVRepositoryFactory;
import org.tmatesoft.svn.core.wc.ISVNOptions;
import org.tmatesoft.svn.core.wc.SVNDiffClient;
import org.tmatesoft.svn.core.wc.SVNUpdateClient;
import org.tmatesoft.svn.core.wc.SVNWCClient;
import org.tmatesoft.svn.core.wc.SVNWCUtil;

import com.primed.sde.command.Diff;
import com.primed.sde.command.Export;
import com.primed.sde.command.Revision;
import com.primed.sde.command.Zip;

/**
* Utility project used to patch a baseline export to a newer branch.
* Assumes you have already 'tagged' a branch for release.
* The commands:
*
* Create a diff.patch file
* diff <old-branch-url> <new-branch-url> <diff-file>
*
* Export each of the files described in the diff.patch to a target directory:
* export <diff-file> <old-branch-url> <new-branch-url> <target-dir>
*
* Create a revision file:
* revision <new-branch-url> <revision-file-full-path>
*
* Zip the new pack for transport via your mechanism ftp,ssh,xcopy...
* zip <directory-to-zip>
*
* @author philip gloyne (philip.gloyne@gmail.com)
* @since 25-JAN-2010
*/
public class SvnDiffExport {

enum Command { diff, export, revision, zip };

public static void main(String[] args) throws Exception {
Long start = System.currentTimeMillis();

SvnProperties properties = new SvnProperties(new File("svn.properties"));
String svnUsername = properties.getSvnUsername();
String svnPassword = properties.getSvnPassword();

ISVNOptions options = SVNWCUtil.createDefaultOptions(true);
BasicAuthenticationManager bam = new BasicAuthenticationManager(svnUsername, svnPassword);
DAVRepositoryFactory.setup();

Command command = Command.valueOf(args[0]);
switch(command) {

case diff:
System.out.println("diff..");
SVNURL oldBranch = SVNURL.parseURIEncoded(args[1]);
SVNURL newBranch = SVNURL.parseURIEncoded(args[2]);
String diff = args[3];
new Diff(new SVNDiffClient(bam, options),oldBranch,newBranch,diff).execute();
break;

case export:
System.out.println("export..");
File diffFile = new File(args[1]);
if (!diffFile.exists()) {
throw new RuntimeException("diff file: "+args[1]+" not found.");
}
String oldBranchURL = args[2];
String newBranchURL = args[3];
String exportTo = args[4];
new Export(new SVNUpdateClient(bam, options),diffFile,oldBranchURL,newBranchURL,exportTo).execute();
break;

case revision:
System.out.println("revision..");
SVNURL branch = SVNURL.parseURIEncoded(args[1]);
String target = args[2];
new Revision(new SVNWCClient(bam, options), branch, target).execute();
break;

case zip:
System.out.println("zip..");
File zipTarget = new File(args[1]);
if (!zipTarget.exists()) {
throw new RuntimeException("zip target dir/file: "+args[1]+" not found.");
}
new Zip(zipTarget).execute();
break;

}

Long end = System.currentTimeMillis();
System.out.println("finished. time: "+ ((end - start)/1000) + " seconds.");

}



}
46 changes: 46 additions & 0 deletions src/com/primed/sde/SvnProperties.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.primed.sde;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;

/**
* Svn properties.
* For read-only operations you may omit a .properties file if you have a
* read-only user setup with the username:robot, password:robot.
*
* @author philip gloyne (philip.gloyne@gmail.com)
* @since 25-JAN-2010
*/
public class SvnProperties extends Properties {

private static final long serialVersionUID = -2243343266732814909L;

public SvnProperties() {}

public SvnProperties(File propsFile) throws IOException {
try {
load(new FileInputStream(propsFile));
} catch (FileNotFoundException e) {
System.out.println("svn.properties file not found. Using user: robot, pw: robot.");
}
}

/**
* Defaults to 'robot'.
* @return the svn username.
*/
public String getSvnUsername() {
return getProperty("svn.username", "robot");
}

/**
* Defaults to 'robot'.
* @return the svn password.
*/
public String getSvnPassword() {
return getProperty("svn.password", "robot");
}
}
Loading

0 comments on commit c23ed84

Please sign in to comment.