Search in sources :

Example 1 with ChangeLogWriter

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

the class PrepareChangeLogAction method outputMultipleEntryChangeLog.

private void outputMultipleEntryChangeLog(PatchFile pf, String[] functionGuess) {
    String defaultContent = null;
    if (pf.isNewfile())
        // $NON-NLS-1$
        defaultContent = Messages.getString("ChangeLog.NewFile");
    else if (pf.isRemovedFile())
        // $NON-NLS-1$
        defaultContent = Messages.getString("ChangeLog.RemovedFile");
    IPath entryPath = pf.getPath();
    String entryFileName = entryPath.toOSString();
    ChangeLogWriter clw = new ChangeLogWriter();
    // load settings from extensions + user pref.
    loadPreferences();
    // get file path from target file
    clw.setEntryFilePath(entryPath.toOSString());
    if (defaultContent != null)
        clw.setDefaultContent(defaultContent);
    // err check. do nothing if no file is being open/edited
    if (clw.getEntryFilePath() == "") {
        return;
    }
    // Check if formatter is internal or inline..if inline, use the
    // current active editor part, otherwise, we must find the external
    // ChangeLog file.
    IEditorPart changelog = null;
    // Before accessing the getFormatterConfigElement, the getFormatContibutor
    // method must be called to initialize.
    extensionManager.getFormatterContributor(clw.getEntryFilePath(), pref_Formatter);
    IConfigurationElement formatterConfigElement = extensionManager.getFormatterConfigElement();
    if (// $NON-NLS-1$
    formatterConfigElement.getAttribute("inFile").equalsIgnoreCase("true")) {
        // $NON-NLS-1$
        try {
            changelog = openEditor((IFile) pf.getResource());
            clw.setFormatter(extensionManager.getFormatterContributor(clw.getEntryFilePath(), pref_Formatter));
        } catch (Exception e) {
        // do nothing changelog will be null
        }
    } else {
        // external changelog
        // get formatter
        clw.setFormatter(extensionManager.getFormatterContributor(entryFileName, pref_Formatter));
        if (pf.isRemovedFile())
            changelog = getChangelogForRemovePath(entryPath);
        else
            changelog = getChangelog(entryFileName);
        // one.
        if (createChangeLog && changelog == null)
            changelog = askChangeLogLocation(entryPath.toOSString());
        if (changelog == null) {
            createChangeLog = false;
            return;
        }
    }
    if ((changelog instanceof ChangeLogEditor) && (!this.newEntryWritten)) {
        ChangeLogEditor editor = (ChangeLogEditor) changelog;
        // saving), treat it as a change log modification
        if (editor.isDirty())
            this.changeLogModified = true;
        editor.setForceNewLogEntry(!this.changeLogModified);
        this.newEntryWritten = true;
    }
    // select changelog
    clw.setChangelog(changelog);
    // write to changelog
    IFormatterChangeLogContrib formatter = clw.getFormatter();
    clw.setDateLine(formatter.formatDateLine(pref_AuthorName, pref_AuthorEmail));
    clw.setChangelogLocation(getDocumentLocation(clw.getChangelog(), true));
    // print multiple changelog entries with different
    // function guess names.  We default to an empty guessed name
    // if we have zero function guess names.
    int numFuncs = 0;
    // $NON-NLS-1$
    clw.setGuessedFName("");
    if (functionGuess.length > 0) {
        for (String guess : functionGuess) {
            if (!guess.trim().equals("")) {
                // $NON-NLS-1$
                ++numFuncs;
                clw.setGuessedFName(guess);
                clw.writeChangeLog();
            }
        }
    }
    // function guesses.
    if (numFuncs == 0) {
        clw.writeChangeLog();
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) ChangeLogEditor(org.eclipse.linuxtools.internal.changelog.core.editors.ChangeLogEditor) ChangeLogWriter(org.eclipse.linuxtools.internal.changelog.core.ChangeLogWriter) IFormatterChangeLogContrib(org.eclipse.linuxtools.changelog.core.IFormatterChangeLogContrib) IEditorPart(org.eclipse.ui.IEditorPart) IConfigurationElement(org.eclipse.core.runtime.IConfigurationElement) CoreException(org.eclipse.core.runtime.CoreException) PartInitException(org.eclipse.ui.PartInitException) InvocationTargetException(java.lang.reflect.InvocationTargetException) TeamException(org.eclipse.team.core.TeamException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 2 with ChangeLogWriter

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

the class InsertChangeLogKeyHandler method execute.

@Override
public Object execute(ExecutionEvent event) {
    currentEditor = HandlerUtil.getActiveEditor(event);
    // make sure an editor is selected.
    if (currentEditor == null) {
        return null;
    }
    ChangeLogWriter clw = new ChangeLogWriter();
    // load settings from extensions + user pref.
    loadPreferences();
    // get file path from target file
    clw.setEntryFilePath(getEntryFilePath());
    // err check. do nothing if no file is being open/edited
    if (clw.getEntryFilePath() == "") {
        return null;
    }
    String editorName = getEditorName();
    // get a parser for this file
    IParserChangeLogContrib parser = extensionManager.getParserContributor(editorName);
    // and set it as "".
    if (parser == null) {
        clw.setGuessedFName("");
    } else {
        // guess function name
        clw.setGuessedFName(parseFunctionName(parser));
    }
    // get formatter
    clw.setFormatter(extensionManager.getFormatterContributor(clw.getEntryFilePath(), pref_Formatter));
    // select changelog
    clw.setChangelog(getChangelog());
    if (clw.getChangelog() == null)
        return null;
    // write to changelog
    clw.setDateLine(clw.getFormatter().formatDateLine(pref_AuthorName, pref_AuthorEmail));
    clw.setChangelogLocation(getDocumentLocation(clw.getChangelog(), true));
    clw.writeChangeLog();
    return null;
}
Also used : IParserChangeLogContrib(org.eclipse.linuxtools.changelog.core.IParserChangeLogContrib) ChangeLogWriter(org.eclipse.linuxtools.internal.changelog.core.ChangeLogWriter)

Example 3 with ChangeLogWriter

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

the class ChangeLogWriterTest method setUp.

/**
 * @throws java.lang.Exception
 */
@Before
public void setUp() throws Exception {
    clogWriter = new ChangeLogWriter();
    // create a testproject and add a file to it
    project = new ChangeLogTestProject("changelogWriterProject");
    // Generate full path to ChangeLog file
    changelogFilePath = CHANGELOG_FILE_PATH + CHANGELOG_FILE_NAME;
    // add a ChangeLog file to the project at the path specified by
    // CHANGELOG_FILE_PATH_SEGMENTS
    InputStream newFileInputStream = new ByteArrayInputStream(changeLogContent.getBytes());
    changelogFile = project.addFileToProject(CHANGELOG_FILE_PATH + CHANGELOG_FILE_NAME, CHANGELOG_FILE_NAME, newFileInputStream);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ChangeLogWriter(org.eclipse.linuxtools.internal.changelog.core.ChangeLogWriter) FileInputStream(java.io.FileInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ChangeLogTestProject(org.eclipse.linuxtools.changelog.tests.fixtures.ChangeLogTestProject) Before(org.junit.Before)

Aggregations

ChangeLogWriter (org.eclipse.linuxtools.internal.changelog.core.ChangeLogWriter)3 ByteArrayInputStream (java.io.ByteArrayInputStream)1 FileInputStream (java.io.FileInputStream)1 InputStream (java.io.InputStream)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 IFile (org.eclipse.core.resources.IFile)1 CoreException (org.eclipse.core.runtime.CoreException)1 IConfigurationElement (org.eclipse.core.runtime.IConfigurationElement)1 IPath (org.eclipse.core.runtime.IPath)1 BadLocationException (org.eclipse.jface.text.BadLocationException)1 IFormatterChangeLogContrib (org.eclipse.linuxtools.changelog.core.IFormatterChangeLogContrib)1 IParserChangeLogContrib (org.eclipse.linuxtools.changelog.core.IParserChangeLogContrib)1 ChangeLogTestProject (org.eclipse.linuxtools.changelog.tests.fixtures.ChangeLogTestProject)1 ChangeLogEditor (org.eclipse.linuxtools.internal.changelog.core.editors.ChangeLogEditor)1 TeamException (org.eclipse.team.core.TeamException)1 IEditorPart (org.eclipse.ui.IEditorPart)1 PartInitException (org.eclipse.ui.PartInitException)1 Before (org.junit.Before)1