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();
}
}
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;
}
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);
}
Aggregations