Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/adoble/adr-j
Browse files Browse the repository at this point in the history
# Conflicts:
#	doc/usage/INSTALL.md
#	src/main/java/org/doble/adr/SystemEditorRunner.java
  • Loading branch information
adoble authored and adoble committed Jun 4, 2019
2 parents c842149 + c01d42a commit 1b4a584
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 49 deletions.
45 changes: 33 additions & 12 deletions doc/usage/INSTALL.md
Original file line number Diff line number Diff line change
@@ -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.
2 changes: 2 additions & 0 deletions launch-scripts/adr
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
java -jar $ADR_HOME/build/releases/adr-j.jar "$@"
80 changes: 43 additions & 37 deletions src/main/java/org/doble/adr/SystemEditorRunner.java
Original file line number Diff line number Diff line change
@@ -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();
}
}

}

}

0 comments on commit 1b4a584

Please sign in to comment.