Skip to content

Commit

Permalink
Bundle the migration-utils as an executable jar
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Woods authored and mikedurbin committed May 25, 2015
1 parent 678a881 commit 2ec0df6
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -1,3 +1,4 @@
target/
.idea
migration-bean.xml*
*~
6 changes: 3 additions & 3 deletions README.md
Expand Up @@ -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)).
Expand All @@ -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 <relative-or-absolute-path-to-configuration-file>
```

## Property Mappings
Expand Down
24 changes: 24 additions & 0 deletions pom.xml
Expand Up @@ -275,6 +275,30 @@
</execution>
</executions>
</plugin>

<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.5.4</version>
<configuration>
<descriptors>
<descriptor>src/assembly/driver.xml</descriptor>
</descriptors>
<archive>
<manifest>
<mainClass>org.fcrepo.migration.Migrator</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>

</plugins>
</build>

Expand Down
24 changes: 24 additions & 0 deletions src/assembly/driver.xml
@@ -0,0 +1,24 @@
<assembly>
<id>driver</id>
<includeBaseDirectory>false</includeBaseDirectory>
<formats>
<format>jar</format>
</formats>

<fileSets>
<fileSet>
<directory>src/main/resources</directory>
<includes>
<include>*.properties</include>
</includes>
</fileSet>
</fileSets>

<dependencySets>
<dependencySet>
<unpack>true</unpack>
</dependencySet>
</dependencySets>

</assembly>

42 changes: 40 additions & 2 deletions src/main/java/org/fcrepo/migration/Migrator.java
Expand Up @@ -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
Expand All @@ -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();
Expand Down Expand Up @@ -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());
}

}

0 comments on commit 2ec0df6

Please sign in to comment.