diff --git a/doc/usage/INSTALL.md b/doc/usage/INSTALL.md index 3401814..6527175 100644 --- a/doc/usage/INSTALL.md +++ b/doc/usage/INSTALL.md @@ -1,12 +1,33 @@ -# Install ADR-J - -## Windows - -1. Download the source code. -2. Make sure you have gradle installed (https://gradle.org/). -3. Run `gradlew releaseJar`. This should create a file `build/releases/adr-j.jar`. -4. Set the environment variable `ADR_HOME` to the folder where you downloaded the source code. This should contain the `build` folder. -5. Set the environment variable `EDITOR` or `VISUAL` to the location of the editor you what to use for editing the ADRs (e.g. Atom) -6. Add `%ADR_HOME%\launch-scripts` to the `PATH` environment variable - -You should now be able to type `adr` from the command line and see a response. +# Install ADR-J + +## Windows + +1. Download the source code. +2. Make sure you have gradle installed (https://gradle.org/). +3. Run `gradlew releaseJar`. This should create a file `build/releases/adr-j.jar`. +4. Set the environment variable `ADR_HOME` to the folder where you downloaded the source code. This should contain the `build` folder. +5. Set the environment variable `EDITOR` or `VISUAL` to the location of the editor you what to use for editing the ADRs (e.g. Atom) +6. Add `%ADR_HOME%\launch-scripts` to the `PATH` environment variable + +You should now be able to type `adr` from the command line and see a response. + +## Unix + +1. Download the source code. +2. Make sure you have gradle installed (https://gradle.org/). +3. Run `.\gradlew releaseJar`. This should create a file `build/releases/adr-j.jar`. +4. Set the environment variable `ADR_HOME` to the folder where you downloaded the source code. This should contain the `build` folder. For instance this could be done by using the adding the following to the `~/.bashrc` file: +``` +# For example +export ADR_HOME=~/adr-j +``` + +5. Set the environment variable `EDITOR` or `VISUAL` to the location of the editor you what to use for editing the ADRs (e.g. Atom), e.g. in the `~/.bashrc` file: +``` +# For example +export EDITOR=/usr/bin/vi +``` + +6. Move `%ADR_HOME%\launch-scripts\adr` to the `~/bin` directory. + +Of course, there are many other ways to install adr-j on unix depending on your personal preferences; important is that the environment variables are set. diff --git a/launch-scripts/adr b/launch-scripts/adr new file mode 100644 index 0000000..d7846cd --- /dev/null +++ b/launch-scripts/adr @@ -0,0 +1,2 @@ +#!/bin/bash +java -jar $ADR_HOME/build/releases/adr-j.jar "$@" diff --git a/src/main/java/org/doble/adr/SystemEditorRunner.java b/src/main/java/org/doble/adr/SystemEditorRunner.java index 8d192f3..7e62f41 100644 --- a/src/main/java/org/doble/adr/SystemEditorRunner.java +++ b/src/main/java/org/doble/adr/SystemEditorRunner.java @@ -1,37 +1,43 @@ -/** - * Fires up the editor when the tool is being invoked from the command line. - * - */ -package org.doble.adr; - -import java.io.IOException; -import java.nio.file.Path; - -/** - * @author adoble - * - */ -public class SystemEditorRunner extends EditorRunner { - - /* (non-Javadoc) - * @see org.doble.adr.EditorRunner#run(java.nio.file.Path, org.doble.adr.Environment) - */ - @Override - public void run(Path path, String editorCommand) throws ADRException { - -// String adrFileName = path.getFileName().toString(); - String adrPathName = path.toString(); - - try { - Runtime runTime = Runtime.getRuntime(); - String cmd = editorCommand + " " + adrPathName; - runTime.exec(cmd); - - } catch (IOException e) { - throw new ADRException("FATAL: Could not open the editor.", e); - - } - - } - -} +/** + * Fires up the editor when the tool is being invoked from the command line. + * + */ +package org.doble.adr; + +import java.io.IOException; +import java.nio.file.Path; + +/** + * @author adoble + * + */ +public class SystemEditorRunner extends EditorRunner { + + /* (non-Javadoc) + * @see org.doble.adr.EditorRunner#run(java.nio.file.Path, org.doble.adr.Environment) + */ + @Override + public void run(Path path, String editorCommand) throws ADRException { + + String adrPathName = path.toString(); + Process p = null; + try { + ProcessBuilder processBuilder = new ProcessBuilder(editorCommand,adrPathName); + processBuilder.redirectOutput(ProcessBuilder.Redirect.INHERIT); + processBuilder.redirectError(ProcessBuilder.Redirect.INHERIT); + processBuilder.redirectInput(ProcessBuilder.Redirect.INHERIT); + + p = processBuilder.start(); + p.waitFor(); + + } catch (IOException | InterruptedException e) { + throw new ADRException("FATAL: Could not open the editor.", e); + } finally { + if (p != null){ + p.destroy(); + } + } + + } + +}