Search in sources :

Example 1 with HgAnnotationLine

use of org.zmlx.hg4idea.provider.annotate.HgAnnotationLine in project intellij-community by JetBrains.

the class HgAnnotationTest method testAnnotationWithVerboseOption.

public void testAnnotationWithVerboseOption() throws VcsException {
    myRepository.refresh(false, true);
    final VirtualFile file = myRepository.findFileByRelativePath(firstCreatedFile);
    assert file != null;
    List<String> users = Arrays.asList(defaultAuthor, author1, author2);
    final HgFile hgFile = new HgFile(myRepository, VfsUtilCore.virtualToIoFile(file));
    final String date = DateFormatUtil.formatPrettyDate(Clock.getTime());
    List<HgAnnotationLine> annotationLines = new HgAnnotateCommand(myProject).execute(hgFile, null);
    for (int i = 0; i < annotationLines.size(); ++i) {
        HgAnnotationLine line = annotationLines.get(i);
        assertEquals(users.get(i), line.get(HgAnnotation.FIELD.USER));
        assertEquals(date, line.get(HgAnnotation.FIELD.DATE));
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) HgFile(org.zmlx.hg4idea.HgFile) HgAnnotationLine(org.zmlx.hg4idea.provider.annotate.HgAnnotationLine) HgAnnotateCommand(org.zmlx.hg4idea.command.HgAnnotateCommand)

Example 2 with HgAnnotationLine

use of org.zmlx.hg4idea.provider.annotate.HgAnnotationLine in project intellij-community by JetBrains.

the class HgAnnotateCommandTest method loadEthalonAnnotations.

@BeforeClass
private void loadEthalonAnnotations() throws IOException {
    myPluginRoot = new File(PluginPathManager.getPluginHomePath(HgVcs.VCS_NAME));
    myAnnotateDataDir = new File(myPluginRoot, "testData/annotate");
    myOutputsDir = new File(myAnnotateDataDir, "outputs");
    final File etalonFile = new File(myAnnotateDataDir, "etalon");
    XStream xStream = new XStream();
    FileReader reader = new FileReader(etalonFile);
    try {
        myAnnotations = (List<HgAnnotationLine>) xStream.fromXML(reader);
    } finally {
        reader.close();
    }
}
Also used : HgAnnotationLine(org.zmlx.hg4idea.provider.annotate.HgAnnotationLine) XStream(com.thoughtworks.xstream.XStream) FileReader(java.io.FileReader) File(java.io.File) BeforeClass(org.testng.annotations.BeforeClass)

Example 3 with HgAnnotationLine

use of org.zmlx.hg4idea.provider.annotate.HgAnnotationLine in project intellij-community by JetBrains.

the class HgAnnotateCommandTest method generateCorrectAnnotation.

//@Test
public void generateCorrectAnnotation() throws IOException {
    final File etalonFile = new File(myAnnotateDataDir, "etalon");
    File outputFile = new File(myOutputsDir, "hg_1.9.0");
    String output = FileUtil.loadFile(outputFile);
    String[] split = output.split("(\n|\r|\r\n)");
    List<HgAnnotationLine> annotationLines = new ArrayList<>(split.length);
    Pattern pattern = Pattern.compile("\\s*(.+)\\s+(\\d+)\\s+([a-fA-F0-9]+)\\s+(\\d{4}-\\d{2}-\\d{2}):\\s*(\\d+): ?(.*)");
    for (String line : split) {
        Matcher matcher = pattern.matcher(line);
        if (!matcher.matches()) {
            fail("Couldn't parse line [ " + line + " ]");
        }
        String user = matcher.group(1);
        String shortRev = matcher.group(2);
        String fullRev = matcher.group(3);
        String date = matcher.group(4);
        String lineNum = matcher.group(5);
        String content = matcher.group(6);
        annotationLines.add(new HgAnnotationLine(user, HgRevisionNumber.getInstance(shortRev, fullRev), date, Integer.parseInt(lineNum), content));
    }
    XStream xStream = new XStream();
    FileWriter writer = new FileWriter(etalonFile);
    try {
        xStream.toXML(annotationLines, writer);
    } finally {
        writer.close();
    }
}
Also used : Pattern(java.util.regex.Pattern) HgAnnotationLine(org.zmlx.hg4idea.provider.annotate.HgAnnotationLine) Matcher(java.util.regex.Matcher) XStream(com.thoughtworks.xstream.XStream) FileWriter(java.io.FileWriter) ArrayList(java.util.ArrayList) File(java.io.File)

Example 4 with HgAnnotationLine

use of org.zmlx.hg4idea.provider.annotate.HgAnnotationLine in project intellij-community by JetBrains.

the class HgAnnotateCommand method parse.

private static List<HgAnnotationLine> parse(List<String> outputLines) {
    List<HgAnnotationLine> annotations = new ArrayList<>(outputLines.size());
    for (String line : outputLines) {
        Matcher matcher = LINE_PATTERN.matcher(line);
        if (matcher.matches()) {
            String user = matcher.group(USER_GROUP).trim();
            HgRevisionNumber rev = HgRevisionNumber.getInstance(matcher.group(REVISION_GROUP), matcher.group(CHANGESET_GROUP));
            String dateGroup = matcher.group(DATE_GROUP).trim();
            SimpleDateFormat dateFormat = new SimpleDateFormat("EEE MMM dd HH:mm:ss yyyy", Locale.US);
            String date = "";
            try {
                date = DateFormatUtil.formatPrettyDate(dateFormat.parse(dateGroup));
            } catch (ParseException e) {
                LOG.error("Couldn't parse annotation date ", e);
            }
            Integer lineNumber = Integer.valueOf(matcher.group(LINE_NUMBER_GROUP));
            String content = matcher.group(CONTENT_GROUP);
            HgAnnotationLine annotationLine = new HgAnnotationLine(user, rev, date, lineNumber, content);
            annotations.add(annotationLine);
        }
    }
    return annotations;
}
Also used : HgAnnotationLine(org.zmlx.hg4idea.provider.annotate.HgAnnotationLine) Matcher(java.util.regex.Matcher) HgRevisionNumber(org.zmlx.hg4idea.HgRevisionNumber) ArrayList(java.util.ArrayList) ParseException(java.text.ParseException) SimpleDateFormat(java.text.SimpleDateFormat)

Example 5 with HgAnnotationLine

use of org.zmlx.hg4idea.provider.annotate.HgAnnotationLine in project intellij-community by JetBrains.

the class HgAnnotationTest method annotationWithWhitespaceOption.

private void annotationWithWhitespaceOption(boolean ignoreWhitespaces) {
    cd(myRepository);
    String whitespaceFile = "whitespaces.txt";
    touch(whitespaceFile, "not whitespaces");
    myRepository.refresh(false, true);
    String whiteSpaceAuthor = "Mr.Whitespace";
    final VirtualFile file = myRepository.findFileByRelativePath(whitespaceFile);
    assert file != null;
    hg("add " + whitespaceFile);
    hg("commit -m modify -u '" + defaultAuthor + "'");
    //add several whitespaces
    echo(whitespaceFile, "    ");
    hg("commit -m whitespaces -u '" + whiteSpaceAuthor + "'");
    final HgFile hgFile = new HgFile(myRepository, VfsUtilCore.virtualToIoFile(file));
    myVcs.getProjectSettings().setIgnoreWhitespacesInAnnotations(ignoreWhitespaces);
    List<HgAnnotationLine> annotationLines = new HgAnnotateCommand(myProject).execute(hgFile, null);
    HgAnnotationLine line = annotationLines.get(0);
    assertEquals(ignoreWhitespaces ? defaultAuthor : whiteSpaceAuthor, line.get(HgAnnotation.FIELD.USER));
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) HgFile(org.zmlx.hg4idea.HgFile) HgAnnotationLine(org.zmlx.hg4idea.provider.annotate.HgAnnotationLine) HgAnnotateCommand(org.zmlx.hg4idea.command.HgAnnotateCommand)

Aggregations

HgAnnotationLine (org.zmlx.hg4idea.provider.annotate.HgAnnotationLine)6 ArrayList (java.util.ArrayList)3 HgAnnotateCommand (org.zmlx.hg4idea.command.HgAnnotateCommand)3 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 XStream (com.thoughtworks.xstream.XStream)2 File (java.io.File)2 Matcher (java.util.regex.Matcher)2 HgFile (org.zmlx.hg4idea.HgFile)2 FileReader (java.io.FileReader)1 FileWriter (java.io.FileWriter)1 Method (java.lang.reflect.Method)1 ParseException (java.text.ParseException)1 SimpleDateFormat (java.text.SimpleDateFormat)1 List (java.util.List)1 Pattern (java.util.regex.Pattern)1 BeforeClass (org.testng.annotations.BeforeClass)1 BeforeMethod (org.testng.annotations.BeforeMethod)1 Test (org.testng.annotations.Test)1 HgRevisionNumber (org.zmlx.hg4idea.HgRevisionNumber)1