Skip to content

Commit

Permalink
Merge pull request #59 from sawickil/master
Browse files Browse the repository at this point in the history
#53 View/Annotate page rebuilt
  • Loading branch information
yu55 committed Feb 8, 2016
2 parents 79da9d0 + 7e2fd9b commit 07399c3
Show file tree
Hide file tree
Showing 27 changed files with 334 additions and 97 deletions.
Binary file modified docs/screenshots/yagga-detail.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@
@Component
public class AnnotateService {

private final AnnotateHandler gitAnnotateHandler;
private final AnnotateHandler annotateHandler;

@Autowired
public AnnotateService(AnnotateHandler gitAnnotateHandler) {
this.gitAnnotateHandler = gitAnnotateHandler;
public AnnotateService(AnnotateHandler annotateHandler) {
this.annotateHandler = annotateHandler;
}

public AnnotateResponse annotate(AnnotateRequest annotateRequest) {
return gitAnnotateHandler.annotate(annotateRequest);
return annotateHandler.annotate(annotateRequest);
}

}
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;
}
}
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;
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
package org.yu55.yagga.handler.generic;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.yu55.yagga.handler.api.DvcsRepository;

import java.util.List;
import java.util.Optional;

public class Repositories {
import org.yu55.yagga.handler.api.DvcsRepository;

private static final Logger logger = LoggerFactory.getLogger(Repositories.class);
public class Repositories {

private List<DvcsRepository> repositories;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.yu55.yagga.handler.generic.command;

import java.io.File;

import org.apache.commons.exec.DefaultExecutor;
import org.apache.commons.exec.PumpStreamHandler;
import org.springframework.stereotype.Component;
Expand All @@ -8,18 +10,18 @@
@Component
public class CommandExecutorFactory {

public CommandExecutor factorize(Command command) {
return factorize(new File("."), null, command);
}

public CommandExecutor factorize(DvcsRepository repository, Command command) {
DefaultExecutor executor = new DefaultExecutor();
executor.setWorkingDirectory(repository.getDirectory().toFile());
CommandExecutorStreamHandler executorStreamHandler =
new CommandExecutorStreamHandler(repository.getDirectoryName());
executor.setStreamHandler(new PumpStreamHandler(executorStreamHandler));
return new CommandExecutor(command, executor, executorStreamHandler::getOutput);
return factorize(repository.getDirectory().toFile(), repository.getDirectoryName(), command);
}

public CommandExecutor factorize(Command command) {
private CommandExecutor factorize(File dir, String name, Command command) {
DefaultExecutor executor = new DefaultExecutor();
CommandExecutorStreamHandler executorStreamHandler = new CommandExecutorStreamHandler();
executor.setWorkingDirectory(dir);
CommandExecutorStreamHandler executorStreamHandler = new CommandExecutorStreamHandler(name);
executor.setStreamHandler(new PumpStreamHandler(executorStreamHandler));
return new CommandExecutor(command, executor, executorStreamHandler::getOutput);
}
Expand Down
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));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import org.apache.commons.exec.CommandLine;
import org.yu55.yagga.handler.api.command.annotate.AnnotateParameters;
import org.yu55.yagga.handler.generic.command.Command;
import org.yu55.yagga.handler.mercurial.command.common.MercurialCommand;

public class MercurialAnnotateCommand implements MercurialCommand {
Expand All @@ -18,7 +17,7 @@ public CommandLine getCommandLine() {
CommandLine commandLine = CommandLine.parse(COMMAND);
commandLine.addArgument("annotate", false);
commandLine.addArgument("-u", false);
commandLine.addArgument("-n", false);
commandLine.addArgument("-c", false);
commandLine.addArgument("-l", false);
commandLine.addArgument("-d", false);
commandLine.addArgument(annotateParameters.getFile(), false);
Expand Down
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));
}

}
38 changes: 25 additions & 13 deletions src/main/resources/static/preview.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,37 @@
<title>[{{params.repository}}] {{params.file}}</title>

<script src="//cdnjs.cloudflare.com/ajax/libs/angular.js/1.2.28/angular.min.js" type="text/javascript"></script>
<script src="https://cdn.rawgit.com/google/code-prettify/master/loader/run_prettify.js" type="text/javascript"></script>
<script src="https://cdn.rawgit.com/google/code-prettify/master/loader/run_prettify.js"
type="text/javascript"></script>
<script src="https://cdn.rawgit.com/google/code-prettify/master/loader/prettify.js" type="text/javascript"></script>
<script src="yagga/js/preview.js" type="text/javascript"></script>
<link href="yagga/css/yagga.css" rel="stylesheet">

</head>
<body>
<h1 style="font-family: monospace">[{{params.repository}}] {{params.file}}</h1>
<table>
<tr>
<td>
<pre>{{annotate.annotations}}</pre>
<body style="padding: 0px; margin: 0px">
<div id="viewTitle">
<h1>&nbsp; <span style="color: #3a8ea1">[{{params.repository}}]</span> {{params.file}}</h1>
</div>
<table cellpadding="0" cellspacing="0" border="0" class="annotate" style="margin-top: 10px">
<tbody>
<tr ng-repeat="annotation in annotate.annotationResponseLines track by $index">
<td class="noselect annotateInfoLight">
<pre>{{annotation.commitId}}</pre>
</td>
<td class="noselect annotateInfo">
<pre>{{annotation.author}}</pre>
</td>
<td class="noselect annotateInfoLight">
<pre>{{annotation.commitDate}}</pre>
</td>
<td class="noselect lineNumber">
<pre>{{annotation.lineNumber}}</pre>
</td>
<td>
<div>
<prettify target="annotate">
<code class="prettyprint">{{target.fileContent}}</code>
</prettify>
</div>
<td class="code">
<prettify target="annotation"><code class="prettyprint">{{target.line}}</code></prettify>
</td>
</tr>
</tbody>
</table>

</body>
Expand Down
Loading

0 comments on commit 07399c3

Please sign in to comment.