-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #59 from sawickil/master
#53 View/Annotate page rebuilt
- Loading branch information
Showing
27 changed files
with
334 additions
and
97 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 16 additions & 9 deletions
25
src/main/java/org/yu55/yagga/core/annotate/model/AnnotateResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,28 @@ | ||
package org.yu55.yagga.core.annotate.model; | ||
|
||
import java.util.LinkedList; | ||
import java.util.List; | ||
|
||
/** | ||
* Main class containing a content of selected file to view. | ||
*/ | ||
public class AnnotateResponse { | ||
|
||
private String annotations; | ||
private List<AnnotateResponseLine> annotationResponseLines; | ||
|
||
private String fileContent; | ||
public AnnotateResponse(List<AnnotateResponseLine> annotateResponseLines) { | ||
this.annotationResponseLines = annotateResponseLines; | ||
} | ||
|
||
public AnnotateResponse(String annotations, String fileContent) { | ||
this.annotations = annotations; | ||
this.fileContent = fileContent; | ||
public AnnotateResponse() { | ||
this.annotationResponseLines = new LinkedList<>(); | ||
} | ||
|
||
public String getAnnotations() { | ||
return annotations; | ||
public void addAnnotationResponseLine(AnnotateResponseLine line) { | ||
annotationResponseLines.add(line); | ||
} | ||
|
||
public String getFileContent() { | ||
return fileContent; | ||
public List<AnnotateResponseLine> getAnnotationResponseLines() { | ||
return annotationResponseLines; | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
src/main/java/org/yu55/yagga/core/annotate/model/AnnotateResponseLine.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package org.yu55.yagga.core.annotate.model; | ||
|
||
/** | ||
* This class represents a single line of code displayed on the view page. | ||
*/ | ||
public class AnnotateResponseLine { | ||
|
||
private String commitId; | ||
|
||
private String author; | ||
|
||
private String commitDate; | ||
|
||
private int lineNumber; | ||
|
||
private String line; | ||
|
||
public AnnotateResponseLine(String commitId, String author, String commitDate, int lineNumber, | ||
String line) { | ||
this.commitId = commitId; | ||
this.author = author; | ||
this.commitDate = commitDate; | ||
this.lineNumber = lineNumber; | ||
this.line = line; | ||
} | ||
|
||
public AnnotateResponseLine(String line) { | ||
this(null, null, null, 0, line); | ||
} | ||
|
||
public String getCommitId() { | ||
return commitId; | ||
} | ||
|
||
public String getAuthor() { | ||
return author; | ||
} | ||
|
||
public String getCommitDate() { | ||
return commitDate; | ||
} | ||
|
||
public int getLineNumber() { | ||
return lineNumber; | ||
} | ||
|
||
public String getLine() { | ||
return line; | ||
} | ||
} |
8 changes: 2 additions & 6 deletions
8
src/main/java/org/yu55/yagga/handler/generic/Repositories.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 28 additions & 14 deletions
42
src/main/java/org/yu55/yagga/handler/git/command/annotate/GitAnnotateResponseFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,54 @@ | ||
package org.yu55.yagga.handler.git.command.annotate; | ||
|
||
import java.util.List; | ||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
|
||
import org.yu55.yagga.core.annotate.model.AnnotateResponse; | ||
import org.yu55.yagga.core.annotate.model.AnnotateResponseLine; | ||
import org.yu55.yagga.handler.generic.command.CommandOutput; | ||
import org.yu55.yagga.handler.generic.command.CommandOutputLine; | ||
|
||
public class GitAnnotateResponseFactory { | ||
|
||
private static final String LINE_PATTERN = | ||
"(\\w+)\\s+\\(\\s?(.+)\\s+(\\d{4}-\\d{2}-\\d{2}\\s+\\d{2}:\\d{2}:\\d{2}\\s+[\\+\\-]?\\d{4})\\s+(\\d+)\\)(" + | ||
".*)"; | ||
|
||
/* | ||
* Don't touch it for now as I think we will have to re-think of the entire code structure, which does not seem | ||
* pretty well right now;) | ||
*/ | ||
public static AnnotateResponse factorizeAnnotateResponse(CommandOutput output) { | ||
List<CommandOutputLine> outputLines = output.getOutputLines(); | ||
|
||
StringBuilder annotationsStringBuilder = new StringBuilder(); | ||
StringBuilder fileContentStringBuilder = new StringBuilder(); | ||
AnnotateResponse response = new AnnotateResponse(); | ||
|
||
for (CommandOutputLine outputLine : outputLines) { | ||
String annotatedLine = outputLine.getLine(); | ||
if (output.getExitValue() == 0) { | ||
generateSuccessfulContent(annotationsStringBuilder, fileContentStringBuilder, annotatedLine); | ||
generateSuccessfulContent(response, annotatedLine); | ||
} else { | ||
generateFailureContent(annotationsStringBuilder, annotatedLine); | ||
generateUnsuccessfulContent(response, annotatedLine); | ||
} | ||
} | ||
|
||
return new AnnotateResponse(annotationsStringBuilder.toString(), fileContentStringBuilder.toString()); | ||
return response; | ||
} | ||
|
||
private static void generateSuccessfulContent(StringBuilder annotationsStringBuilder, | ||
StringBuilder fileContentStringBuilder, String annotatedLine) { | ||
int splitIndex = annotatedLine.indexOf(")"); | ||
annotationsStringBuilder.append(annotatedLine.substring(0, splitIndex + 1)).append("\n"); | ||
fileContentStringBuilder.append(annotatedLine.substring(splitIndex + 1)).append("\n"); | ||
private static void generateSuccessfulContent(AnnotateResponse response, String annotatedLine) { | ||
Matcher matcher = Pattern.compile(LINE_PATTERN).matcher(annotatedLine); | ||
if (matcher.matches()) { | ||
String author = matcher.group(2).trim(); | ||
AnnotateResponseLine annotationResponseLine = new AnnotateResponseLine( | ||
!author.equals("Not Committed Yet") ? matcher.group(1).trim() : "", | ||
author, matcher.group(3).trim(), | ||
Integer.parseInt(matcher.group(4).trim()), | ||
matcher.group(5)); | ||
response.addAnnotationResponseLine(annotationResponseLine); | ||
} | ||
} | ||
|
||
private static void generateFailureContent(StringBuilder annotationsStringBuilder, String annotatedLine) { | ||
annotationsStringBuilder.append(annotatedLine).append("\n"); | ||
private static void generateUnsuccessfulContent(AnnotateResponse response, String line) { | ||
response.addAnnotationResponseLine(new AnnotateResponseLine(line)); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 25 additions & 17 deletions
42
...a/org/yu55/yagga/handler/mercurial/command/annotate/MercurialAnnotateResponseFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,49 @@ | ||
package org.yu55.yagga.handler.mercurial.command.annotate; | ||
|
||
import org.apache.commons.lang3.StringUtils; | ||
import java.util.List; | ||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
|
||
import org.yu55.yagga.core.annotate.model.AnnotateResponse; | ||
import org.yu55.yagga.core.annotate.model.AnnotateResponseLine; | ||
import org.yu55.yagga.handler.generic.command.CommandOutput; | ||
import org.yu55.yagga.handler.generic.command.CommandOutputLine; | ||
|
||
import java.util.List; | ||
|
||
public class MercurialAnnotateResponseFactory { | ||
|
||
private static final String LINE_PATTERN = | ||
"(\\w+)\\s+(\\w{12})\\s+(\\w{3}\\s+\\w{3}\\s+\\d{2}\\s+\\d{2}:\\d{2}:\\d{2}\\s+\\d{4}\\s+[\\+\\-]?\\d{4})" + | ||
":(\\d+):\\s+(.*)"; | ||
|
||
public static AnnotateResponse factorizeAnnotateResponse(CommandOutput output) { | ||
List<CommandOutputLine> outputLines = output.getOutputLines(); | ||
|
||
StringBuilder annotationsStringBuilder = new StringBuilder(); | ||
StringBuilder fileContentStringBuilder = new StringBuilder(); | ||
AnnotateResponse response = new AnnotateResponse(); | ||
|
||
for (CommandOutputLine outputLine : outputLines) { | ||
String annotatedLine = outputLine.getLine(); | ||
if (output.getExitValue() == 0) { | ||
generateSuccessfulContent(annotationsStringBuilder, fileContentStringBuilder, annotatedLine); | ||
generateSuccessfulContent(response, annotatedLine); | ||
} else { | ||
generateFailureContent(annotationsStringBuilder, annotatedLine); | ||
generateUnsuccessfulContent(response, annotatedLine); | ||
} | ||
} | ||
|
||
return new AnnotateResponse(annotationsStringBuilder.toString(), fileContentStringBuilder.toString()); | ||
return response; | ||
} | ||
|
||
private static void generateSuccessfulContent(StringBuilder annotationsStringBuilder, | ||
StringBuilder fileContentStringBuilder, String annotatedLine) { | ||
int splitIndex = StringUtils.ordinalIndexOf(annotatedLine,":", 4); | ||
annotationsStringBuilder.append(annotatedLine.substring(0, splitIndex + 1)).append("\n"); | ||
fileContentStringBuilder.append(annotatedLine.substring(splitIndex + 1)).append("\n"); | ||
private static void generateSuccessfulContent(AnnotateResponse response, String annotatedLine) { | ||
Matcher matcher = Pattern.compile(LINE_PATTERN).matcher(annotatedLine); | ||
if (matcher.matches()) { | ||
AnnotateResponseLine annotationResponseLine = new AnnotateResponseLine( | ||
matcher.group(2).trim(), | ||
matcher.group(1).trim(), matcher.group(3).trim(), | ||
Integer.parseInt(matcher.group(4).trim()), | ||
matcher.group(5)); | ||
response.addAnnotationResponseLine(annotationResponseLine); | ||
} | ||
} | ||
|
||
private static void generateFailureContent(StringBuilder annotationsStringBuilder, String annotatedLine) { | ||
annotationsStringBuilder.append(annotatedLine).append("\n"); | ||
private static void generateUnsuccessfulContent(AnnotateResponse response, String line) { | ||
response.addAnnotationResponseLine(new AnnotateResponseLine(line)); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.