From 2ec0df675b2f2b0e8b919f4a4a8ece4d942ee1ce Mon Sep 17 00:00:00 2001 From: Andrew Woods Date: Thu, 21 May 2015 21:10:11 -0400 Subject: [PATCH] Bundle the migration-utils as an executable jar Resolves: https://jira.duraspace.org/browse/FCREPO-1525 --- .gitignore | 1 + README.md | 6 +-- pom.xml | 24 +++++++++++ src/assembly/driver.xml | 24 +++++++++++ .../java/org/fcrepo/migration/Migrator.java | 42 ++++++++++++++++++- 5 files changed, 92 insertions(+), 5 deletions(-) create mode 100644 src/assembly/driver.xml diff --git a/.gitignore b/.gitignore index e1f89843..f34bdd47 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ target/ .idea +migration-bean.xml* *~ diff --git a/README.md b/README.md index 1f4ff248..e2900bab 100644 --- a/README.md +++ b/README.md @@ -24,8 +24,8 @@ Background work * There is currently only one implemented pid-mapping strategy, but you can configure it to put all of your migrated content under a given path ([line 93](https://github.com/fcrepo4-labs/migration-utils/blob/master/src/main/resources/spring/migration-bean.xml#L93), sets that value to "migrated-fedora3"). Getting started: -* Clone the repository `https://github.com/fcrepo4-labs/migration-utils.git` -* Edit the Spring XML configuration in your editor of choice (`src/main/resources/spring/migration-bean.xml`). +* [Download](https://github.com/fcrepo4-labs/migration-utils/releases) the executable jar file +* Create a local copy of the example [configuration file](https://github.com/fcrepo4-labs/migration-utils/blob/master/src/main/resources/spring/migration-bean.xml) and update as described below: * If you are migrating from exported FOXML, you will leave [line 9](https://github.com/fcrepo4-labs/migration-utils/blob/master/src/main/resources/spring/migration-bean.xml#L9). * If you are migrating from a native fcrepo3 file system, you will need to change `exportedFoxmlDirectoryObjectSource` to `nativeFoxmlDirectoryObjectSource` in [line 9](https://github.com/fcrepo4-labs/migration-utils/blob/master/src/main/resources/spring/migration-bean.xml#L9). * If you are migrating from a native fcrepo3 file system, you will need to set the paths to the `objectStore` and `datastreamStore` ([Lines 143-139](https://github.com/fcrepo4-labs/migration-utils/blob/master/src/main/resources/spring/migration-bean.xml#L143-L149)). @@ -38,7 +38,7 @@ Getting started: To run the migration scenario you have configured in the Spring XML configuration file: ``` -mvn clean compile exec:java -Dexec.mainClass=org.fcrepo.migration.Migrator +java -jar migration-utils-{version}-driver.jar ``` ## Property Mappings diff --git a/pom.xml b/pom.xml index 91808cca..b6ba5452 100644 --- a/pom.xml +++ b/pom.xml @@ -275,6 +275,30 @@ + + + maven-assembly-plugin + 2.5.4 + + + src/assembly/driver.xml + + + + org.fcrepo.migration.Migrator + + + + + + package + + single + + + + + diff --git a/src/assembly/driver.xml b/src/assembly/driver.xml new file mode 100644 index 00000000..cce71c69 --- /dev/null +++ b/src/assembly/driver.xml @@ -0,0 +1,24 @@ + + driver + false + + jar + + + + + src/main/resources + + *.properties + + + + + + + true + + + + + diff --git a/src/main/java/org/fcrepo/migration/Migrator.java b/src/main/java/org/fcrepo/migration/Migrator.java index 8f916098..28a84f8b 100644 --- a/src/main/java/org/fcrepo/migration/Migrator.java +++ b/src/main/java/org/fcrepo/migration/Migrator.java @@ -2,13 +2,17 @@ import static org.slf4j.LoggerFactory.getLogger; +import java.io.BufferedReader; import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; import javax.xml.stream.XMLStreamException; import org.slf4j.Logger; import org.springframework.context.ConfigurableApplicationContext; -import org.springframework.context.support.ClassPathXmlApplicationContext; +import org.springframework.context.support.FileSystemXmlApplicationContext; +import org.springframework.core.io.ClassPathResource; /** * A class that represents a command-line program to migrate a fedora 3 @@ -31,8 +35,13 @@ public class Migrator { * @throws XMLStreamException xml stream exception */ public static void main(final String [] args) throws IOException, XMLStreamException { + // Single arg with path to properties file is required + if (args.length != 1) { + printHelp(); + return; + } - final ConfigurableApplicationContext context = new ClassPathXmlApplicationContext("spring/migration-bean.xml"); + final ConfigurableApplicationContext context = new FileSystemXmlApplicationContext(args[0]); final Migrator m = context.getBean("migrator", Migrator.class); m.run(); context.close(); @@ -101,4 +110,33 @@ public void run() throws XMLStreamException { o.processObject(handler); } } + + private static void printHelp() throws IOException { + final StringBuilder sb = new StringBuilder(); + sb.append("============================\n"); + sb.append("Please provide the directory path to a configuration file!"); + sb.append("\n"); + sb.append("See: https://github.com/fcrepo4-labs/migration-utils/blob/master/"); + sb.append("src/main/resources/spring/migration-bean.xml"); + sb.append("\n\n"); + sb.append("The configuration file should contain the following (with appropriate values):"); + sb.append("\n"); + sb.append("~~~~~~~~~~~~~~\n"); + + final ClassPathResource resource = new ClassPathResource("spring/migration-bean.xml"); + final InputStream example = resource.getInputStream(); + final BufferedReader reader = new BufferedReader(new InputStreamReader(example)); + String line = reader.readLine(); + while (null != line) { + sb.append(line); + sb.append("\n"); + line = reader.readLine(); + } + + sb.append("~~~~~~~~~~~~~~\n\n"); + sb.append("See top of this output for details.\n"); + sb.append("============================\n"); + System.out.println(sb.toString()); + } + }