Search in sources :

Example 1 with GNUFormat

use of org.eclipse.linuxtools.internal.changelog.core.formatters.GNUFormat in project linuxtools by eclipse.

the class GNUFormatTest method setUp.

@Before
public void setUp() throws Exception {
    gnuFormatter = new GNUFormat();
    project = new ChangeLogTestProject("GNUFormatterTest");
}
Also used : GNUFormat(org.eclipse.linuxtools.internal.changelog.core.formatters.GNUFormat) ChangeLogTestProject(org.eclipse.linuxtools.changelog.tests.fixtures.ChangeLogTestProject) Before(org.junit.Before)

Example 2 with GNUFormat

use of org.eclipse.linuxtools.internal.changelog.core.formatters.GNUFormat in project linuxtools by eclipse.

the class ChangeLogWriterTest method canWriteChangeLogToEmptyChangeLogButWithSomeDefaultContent.

/**
 * Test the use of default text.
 *
 * @throws Exception
 */
@Test
public void canWriteChangeLogToEmptyChangeLogButWithSomeDefaultContent() throws Exception {
    // set GNU formatter
    clogWriter.setFormatter(new GNUFormat());
    // Open up a new ChangeLog file at newPathToChangeLog with empty content
    // and get the IEditorPart
    InputStream newFileInputStream = new ByteArrayInputStream(// no content
    "".getBytes());
    String destinationPath = "/this/is/some/random/path";
    IFile emptyChangeLogFile = project.addFileToProject(destinationPath, CHANGELOG_FILE_NAME, newFileInputStream);
    IEditorPart editorContent = EditorHelper.openEditor(emptyChangeLogFile);
    clogWriter.setChangelog(editorContent);
    String authorName = "Test Author";
    String email = "test@example.com";
    clogWriter.setDateLine(clogWriter.getFormatter().formatDateLine(authorName, email));
    clogWriter.setChangelogLocation(destinationPath + "/" + CHANGELOG_FILE_NAME);
    // Set some default content
    String defaultContent = "Removed.";
    clogWriter.setDefaultContent(defaultContent);
    String relativePathOfChangedFile = "path/to/file/for/new/entry/test.c";
    clogWriter.setEntryFilePath(destinationPath + "/" + relativePathOfChangedFile);
    clogWriter.setGuessedFName("");
    // Write changelog to buffer - need to save for persistence
    clogWriter.writeChangeLog();
    // above written content is not persistent yet; save it to make it persistent
    clogWriter.getChangelog().doSave(null);
    // Construct the changelog entry by hand and match it with what has been written
    String expectedChangeLogEntry = new GNUFormat().formatDateLine(authorName, email);
    expectedChangeLogEntry += "\t* " + relativePathOfChangedFile + ": " + defaultContent + "\n";
    // Read in content written to file
    StringBuffer actualContent = new StringBuffer();
    try (BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(emptyChangeLogFile.getLocation().toFile())))) {
        String line;
        while ((line = br.readLine()) != null) {
            actualContent.append(line + "\n");
        }
    }
    // Assert proper content has been added
    assertEquals(expectedChangeLogEntry, actualContent.toString());
    EditorHelper.closeEditor(editorContent);
}
Also used : IFile(org.eclipse.core.resources.IFile) InputStreamReader(java.io.InputStreamReader) ByteArrayInputStream(java.io.ByteArrayInputStream) FileInputStream(java.io.FileInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) GNUFormat(org.eclipse.linuxtools.internal.changelog.core.formatters.GNUFormat) BufferedReader(java.io.BufferedReader) IEditorPart(org.eclipse.ui.IEditorPart) FileInputStream(java.io.FileInputStream) Test(org.junit.Test)

Example 3 with GNUFormat

use of org.eclipse.linuxtools.internal.changelog.core.formatters.GNUFormat in project linuxtools by eclipse.

the class ChangeLogWriterTest method testWriteChangeLog.

/**
 * Note that there can be several Changelogs inside a directory tree.
 * The {@link ChangeLogWriter#writeChangeLog()} code assumes that the full path to
 * the ChangeLog file and the full path to the file for which to generate a ChangeLog
 * entry have the same ancestor (with some potential overlap).
 *
 * Consider the following example:
 *
 * 1. The ChangeLog file is <project-root>/src/ChangeLog
 * 2. The currently open editor contains code of <project-root>/src/org/eclipse/example/Test.java
 *
 * In the above case entries in <project-root>/src/ChangeLog *should* be of the form:
 *
 * <code>
 *
 * YYYY-MM-DD  Author Name  <email@example.com>
 *
 *    * org/eclipse/example/Test.java: new File
 *
 * </code>
 *
 * Similarly, if the ChangeLog file is in <project-root>/ChangeLog and the currently open
 * file is <project-root>/src/org/eclipse/example/Sun.java, generated entries in
 * <project-root>/ChangeLog would look like (note the "src" path is added in this case):
 *
 * <code>
 *
 * YYYY-MM-DD  Author Name  <email@example.com>
 *
 *    * src/org/eclipse/example/Sun.java: new File
 *
 * </code>
 *
 * Test for method {@link org.eclipse.linuxtools.internal.changelog.core.ChangeLogWriter#writeChangeLog()}
 */
@Test
public void testWriteChangeLog() throws Exception {
    // We want paths up to the ChangeLog file to overlap
    final String pathRelativeToChangeLog = "eclipse/example/test/NewCoffeeMaker.java";
    clogWriter.setEntryFilePath(CHANGELOG_FILE_PATH + pathRelativeToChangeLog);
    // Will show up surrounded by "(" and ")" in ChangeLog
    String guessedFunctionName = "bazinga";
    clogWriter.setGuessedFName(guessedFunctionName);
    // set GNU formatter
    clogWriter.setFormatter(new GNUFormat());
    // Open a document and get the IEditorPart
    IEditorPart editorContent = EditorHelper.openEditor(changelogFile);
    clogWriter.setChangelog(editorContent);
    // set date/author line
    String authorName = "Test Author";
    String email = "test@example.com";
    clogWriter.setDateLine(clogWriter.getFormatter().formatDateLine(authorName, email));
    // full absolute path to ChangeLog file (relative to project root)
    clogWriter.setChangelogLocation(changelogFilePath);
    // Write changelog to buffer - need to save for persistence
    clogWriter.writeChangeLog();
    // above written content is not persistent yet; save it to make it persistent
    clogWriter.getChangelog().doSave(null);
    // Today's date in ISO format
    Calendar c = new GregorianCalendar();
    String isoDate = String.format("%1$tY-%1$tm-%1$td", c);
    // Construct the changelog entry by hand and match it with what has been written
    String expectedChangeLogEntry = isoDate + "  " + authorName + "  <" + email + ">\n\n";
    expectedChangeLogEntry += "\t* " + pathRelativeToChangeLog + " (" + guessedFunctionName + "): \n\n";
    String expectedContent = expectedChangeLogEntry + changeLogContent;
    // Read in content written to file
    StringBuffer actualContent = new StringBuffer();
    try (BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(changelogFile.getLocation().toFile())))) {
        String line;
        while ((line = br.readLine()) != null) {
            actualContent.append(line + "\n");
        }
    }
    // Assert proper content has been added
    assertEquals(expectedContent, actualContent.toString());
    EditorHelper.closeEditor(editorContent);
}
Also used : InputStreamReader(java.io.InputStreamReader) GregorianCalendar(java.util.GregorianCalendar) Calendar(java.util.Calendar) GNUFormat(org.eclipse.linuxtools.internal.changelog.core.formatters.GNUFormat) GregorianCalendar(java.util.GregorianCalendar) BufferedReader(java.io.BufferedReader) IEditorPart(org.eclipse.ui.IEditorPart) FileInputStream(java.io.FileInputStream) Test(org.junit.Test)

Example 4 with GNUFormat

use of org.eclipse.linuxtools.internal.changelog.core.formatters.GNUFormat in project linuxtools by eclipse.

the class ChangeLogWriterTest method testGetSetFormatter.

@Test
public void testGetSetFormatter() {
    IFormatterChangeLogContrib formatter = new GNUFormat();
    clogWriter.setFormatter(formatter);
    assertEquals(formatter, clogWriter.getFormatter());
}
Also used : IFormatterChangeLogContrib(org.eclipse.linuxtools.changelog.core.IFormatterChangeLogContrib) GNUFormat(org.eclipse.linuxtools.internal.changelog.core.formatters.GNUFormat) Test(org.junit.Test)

Example 5 with GNUFormat

use of org.eclipse.linuxtools.internal.changelog.core.formatters.GNUFormat in project linuxtools by eclipse.

the class ChangeLogWriterTest method testGetSetDateLine.

@Test
public void testGetSetDateLine() {
    String authorName = "Test Author";
    String email = "spongebob@commedycentral.com";
    clogWriter.setDateLine(new GNUFormat().formatDateLine(authorName, email));
    // Today's date in ISO format
    Calendar c = new GregorianCalendar();
    String isoDate = String.format("%1$tY-%1$tm-%1$td", c);
    // expected date/author line
    String expectedDateLine = isoDate + "  " + authorName + "  <" + email + ">\n\n";
    assertEquals(expectedDateLine, clogWriter.getDateLine());
}
Also used : GregorianCalendar(java.util.GregorianCalendar) Calendar(java.util.Calendar) GNUFormat(org.eclipse.linuxtools.internal.changelog.core.formatters.GNUFormat) GregorianCalendar(java.util.GregorianCalendar) Test(org.junit.Test)

Aggregations

GNUFormat (org.eclipse.linuxtools.internal.changelog.core.formatters.GNUFormat)5 Test (org.junit.Test)4 BufferedReader (java.io.BufferedReader)2 FileInputStream (java.io.FileInputStream)2 InputStreamReader (java.io.InputStreamReader)2 Calendar (java.util.Calendar)2 GregorianCalendar (java.util.GregorianCalendar)2 IEditorPart (org.eclipse.ui.IEditorPart)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1 IFile (org.eclipse.core.resources.IFile)1 IFormatterChangeLogContrib (org.eclipse.linuxtools.changelog.core.IFormatterChangeLogContrib)1 ChangeLogTestProject (org.eclipse.linuxtools.changelog.tests.fixtures.ChangeLogTestProject)1 Before (org.junit.Before)1