Skip to content
Snippets Groups Projects
Commit b3c69a58 authored by Jack MacLauchlan CS2015's avatar Jack MacLauchlan CS2015
Browse files

init done, issue class done

parent 9817796a
No related branches found
No related tags found
No related merge requests found
......@@ -34,6 +34,21 @@
<version>5.2.1.201812262042-r</version>
</dependency>
<!-- https://mvnrepository.com/artifact/commons-io/commons-io -->
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.6</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.3.2</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
......
......@@ -6,15 +6,15 @@ public class CommandLineInterface {
private Options options;
public CommandLineInterface(){
public CommandLineInterface() {
this.options = new Options();
addOptions();
HelpFormatter formatter = new HelpFormatter();
formatter.printHelp( "to do", options); //todo
formatter.printHelp("to do", options); //todo
}
public void addOptions(){
public void addOptions() {
OptionGroup uniqueCommands = new OptionGroup();
......
package command;
import java.io.IOException;
public interface Command {
void execute();
}
package command;
import issue.Issue;
public class CommandCreate implements Command {
private String title;
......@@ -12,7 +14,8 @@ public class CommandCreate implements Command {
}
public void execute() {
System.out.println(title);
System.out.println(description);
Issue issue = new Issue(title, description);
Issue ss = new Issue(title, "different");
System.out.println(issue.hashCode() == ss.hashCode());
}
}
......@@ -5,18 +5,32 @@ import org.eclipse.jgit.api.errors.GitAPIException;
import java.io.File;
import java.io.IOException;
import java.util.Objects;
public class CommandInit implements Command {
private String path = "/home/jack/Documents/testRepo";
private String path = "/home/jack/Documents/testrepo";
public void execute() {
try (Git git = Git.open(new File(path))) {
File dir = new File(path);
try (Git git = Git.open(dir)) { //Newly initialized repositories have a peculiarity in that no branch has yet been created.
git.checkout()
.setCreateBranch(true)
.setOrphan(true)
.setName("issues")
.call();
for (File file : Objects.requireNonNull(dir.listFiles())) {
if (!file.getName().equals(".git")) {
file.delete();
}
}
git.add().setUpdate(true).addFilepattern(".").call();
git.commit().setMessage("initialise issue branch").call();
} catch (IOException e) {
System.out.println("Not a git repository - aborting operation");
} catch (GitAPIException e) {
......@@ -26,4 +40,9 @@ public class CommandInit implements Command {
}
}
// Ref headRef = git.getRepository().getRef( Constants.HEAD );
//if( headRef == null || headRef.getObjectId() == null ) {
// // no commit yet
// }
// System.out.println(System.getProperty("user.dir"));
\ No newline at end of file
......@@ -21,7 +21,7 @@ public class CommandSelector {
Command command;
if (userInput.hasOption("new")) {
command = createIssue(userInput.getOptionValues("new"));
} else if(userInput.hasOption("init")){
} else if (userInput.hasOption("init")) {
command = init();
} else {
command = help();
......@@ -33,7 +33,7 @@ public class CommandSelector {
}
}
private Command init(){
private Command init() {
return new CommandInit();
}
......
package issue;
public class Issue {
import java.io.Serializable;
import java.util.Objects;
public class Issue implements Serializable {
private static final long serialVersionUID = 1L;
private String title;
private String description;
private long creationTime;
private long edited;
public Issue(String title, String description) {
this.title = title;
this.description = description;
long time = System.currentTimeMillis();
this.creationTime = time + 1;
this.edited = time + 1;
}
public Issue(String title, String description){
public void setTitle(String title) {
this.title = title;
edited();
}
public void setDescription(String description) {
this.description = description;
edited();
}
private void edited(){
edited = System.currentTimeMillis();
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Issue issue = (Issue) o;
return creationTime == issue.creationTime &&
Objects.equals(title, issue.title) &&
Objects.equals(description, issue.description);
}
@Override
public int hashCode() {
return Objects.hash(title, description, creationTime);
}
@Override
......
package issue;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
public class IssueHistory implements Serializable {
private List<Issue> issueHistory;
public IssueHistory(){
this.issueHistory = new ArrayList<>();
}
}
import command.Command;
import command.CommandInit;
import org.apache.commons.io.FileUtils;
import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import static org.junit.jupiter.api.Assertions.assertEquals;
class CommandInitTest {
Path dir;
@BeforeAll
void setup() throws IOException, GitAPIException {
dir = Files.createTempDirectory("commandInitTestRepo");
Git git = Git.init().setDirectory(new File(String.valueOf(dir))).call();
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
try {
FileUtils.deleteDirectory(dir.toFile());
} catch (IOException ex) {
ex.printStackTrace();
}
}));
}
@Test
void testCreateBranch() {
Command init = new CommandInit();
init.execute();
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment