Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew Ferrazzutti2015-05-25 20:30:17 +0000
committerJeff Johnston2015-06-01 19:56:05 +0000
commitb79e23a6a8a8b72257c945e02b9d705d48a21284 (patch)
tree353606c20b91e298c88d32e1bf4a796a4690b3ba
parent9f3ab39067cba5ba170eaff193f8b09b612efb72 (diff)
downloadorg.eclipse.linuxtools-b79e23a6a8a8b72257c945e02b9d705d48a21284.tar.gz
org.eclipse.linuxtools-b79e23a6a8a8b72257c945e02b9d705d48a21284.tar.xz
org.eclipse.linuxtools-b79e23a6a8a8b72257c945e02b9d705d48a21284.zip
Bug 350072 - ChangeLog is not merging function names.
Change-Id: I54449588272067aebde1de8e808c79b08a5ed997 Signed-off-by: Andrew Ferrazzutti <aferrazz@redhat.com> Reviewed-on: https://git.eclipse.org/r/48566 Tested-by: Hudson CI Reviewed-by: Jeff Johnston <jjohnstn@redhat.com> Tested-by: Jeff Johnston <jjohnstn@redhat.com> (cherry picked from commit d7661e42a2e7a8f59318b57ba9aa4f9d2685e951) Reviewed-on: https://git.eclipse.org/r/49127
-rw-r--r--changelog/org.eclipse.linuxtools.changelog.core/src/org/eclipse/linuxtools/internal/changelog/core/formatters/GNUFormat.java105
1 files changed, 57 insertions, 48 deletions
diff --git a/changelog/org.eclipse.linuxtools.changelog.core/src/org/eclipse/linuxtools/internal/changelog/core/formatters/GNUFormat.java b/changelog/org.eclipse.linuxtools.changelog.core/src/org/eclipse/linuxtools/internal/changelog/core/formatters/GNUFormat.java
index dd8c22f580..e3cf30adc5 100644
--- a/changelog/org.eclipse.linuxtools.changelog.core/src/org/eclipse/linuxtools/internal/changelog/core/formatters/GNUFormat.java
+++ b/changelog/org.eclipse.linuxtools.changelog.core/src/org/eclipse/linuxtools/internal/changelog/core/formatters/GNUFormat.java
@@ -14,6 +14,7 @@ import java.io.File;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
+import java.util.regex.Pattern;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.ResourcesPlugin;
@@ -82,71 +83,71 @@ public class GNUFormat implements IFormatterChangeLogContrib {
//a new entry by changing the offset_start and change the corresponding field
//of the editor back to false to prevent subsequent function change log being
//written to a new entry again.
- if (forceNewEntry)
+ if (forceNewEntry) {
offset_start = -1;
+ }
if (offset_start != -1) {
int nextChangeEntry = findChangeLogPattern(changelog_doc,
offset_start + dateLine.length());
int functLogEntry = offset_start + dateLine.length();
+ final int numLines = changelog_doc.getNumberOfLines();
while (functLogEntry < nextChangeEntry) {
- int line_length = 0;
+ int lineNum = 0;
String entry = ""; // $NON-NLS-1$
try {
- line_length = changelog_doc
- .getLineOfOffset(functLogEntry);
- entry = changelog_doc.get(functLogEntry, changelog_doc
- .getLineLength(line_length));
+ lineNum = changelog_doc.getLineOfOffset(functLogEntry);
+ entry = changelog_doc.get(functLogEntry,
+ changelog_doc.getLineLength(lineNum));
} catch (BadLocationException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
+ // Should never get here
}
// Look to see if entry already exists for file (will be preceded by "*")
- if (entry.lastIndexOf("* " + fileDetail) > 0) {
+ final int entryStart = entry.indexOf("* " + fileDetail);
+ if (entryStart >= 0) {
+ foundFunction = true;
+ } else if (foundFunction && isFileLine(entry)) {
+ functLogEntry--;
+ break;
+ }
+
+ if (foundFunction) {
foundFunction = true;
// Check for the case where the default content (e.g. new or removed file)
// is being caught again because user has prepared the ChangeLog more than once.
// In such a case, just return. We don't need to repeat ourselves.
if (defaultContent.length() > 0 && entry.lastIndexOf(defaultContent) > 0) {
- return ""; // $NON-NLS-1$
+ return ""; // $NON-NLS-1$
+ }
+ final int nextFunctLoc;
+ if (entryStart > 0) {
+ nextFunctLoc = functLogEntry + entryStart + fileDetail.length() + 2;
+ } else {
+ nextFunctLoc = functLogEntry;
}
- int nextFunctLoc = functLogEntry + fileDetail.length() + 2;
String nextFunc = ""; // $NON-NLS-1$
try {
+ final int lineEnd;
+ if (lineNum < numLines - 1) {
+ lineEnd = changelog_doc.getLineOffset(lineNum+1)-1;
+ } else {
+ lineEnd = changelog_doc.getLength();
+ }
nextFunc = changelog_doc.get(nextFunctLoc,
- nextChangeEntry - nextFunctLoc);
+ lineEnd - nextFunctLoc);
} catch (BadLocationException e1) {
- // TODO Auto-generated catch block
- e1.printStackTrace();
+ // Should never get here
}
- int foundFunc = nextFunc.indexOf("* "); // $NON-NLS-1$
- if (foundFunc > 0) {
- foundFunc--;
- try {
- while (changelog_doc.get(
- nextFunctLoc + foundFunc, 1).equals(
- "\t") // $NON-NLS-1$
- || changelog_doc.get(
- nextFunctLoc + foundFunc, 1)
- .equals("\n")) { // $NON-NLS-1$
- foundFunc--;
- }
- } catch (BadLocationException e2) {
- // TODO Auto-generated catch block
- e2.printStackTrace();
- }
- functLogEntry = nextFunctLoc + foundFunc + 1;
- break;
+ if (nextFunc.trim().startsWith(function)) {
+ return ""; // $NON-NLS-1$
}
-
}
+
try {
- functLogEntry += changelog_doc
- .getLineLength(line_length);
+ functLogEntry += changelog_doc.getLineLength(lineNum);
} catch (BadLocationException e1) {
- // TODO Auto-generated catch block
- e1.printStackTrace();
+ // Should never get here
}
}
if (functLogEntry >= nextChangeEntry) {
@@ -206,8 +207,9 @@ public class GNUFormat implements IFormatterChangeLogContrib {
if (!multipleEntrySuccess) {
try {
- if (changelog_doc.getLength() > 0)
+ if (changelog_doc.getLength() > 0) {
changelog_doc.replace(0, 0, "\n\n"); //$NON-NLS-1$
+ }
changelog_doc.replace(0, 0, dateLine + TAB + "* " + fileDetail // $NON-NLS-1$
+ functionSpacer+function+functionSpacer+defaultContent);
@@ -225,6 +227,10 @@ public class GNUFormat implements IFormatterChangeLogContrib {
}
+ private boolean isFileLine(String entry) {
+ return Pattern.matches("\\s*\\* \\S+:.*", entry.trim());
+ }
+
/**
* Remove any empty lines (i.e. lines only containing whitespace) between
* <code>offset</code> and index backed-up until a '\n' preceded by some non-whitespace
@@ -302,14 +308,16 @@ public class GNUFormat implements IFormatterChangeLogContrib {
String reversePathb = ""; // $NON-NLS-1$
while (reversePath.getParentFile() != null) {
- if (reversePath.compareTo(changelogLocation.getParentFile()) == 0)
+ if (reversePath.compareTo(changelogLocation.getParentFile()) == 0) {
break;
+ }
reversePath = reversePath.getParentFile();
}
- if (reversePath != null)
+ if (reversePath != null) {
reversePathb = fileLocation.toString().substring(
reversePath.toString().length() + 1,
fileLocation.toString().length());
+ }
return reversePathb;
}
@@ -317,21 +325,21 @@ public class GNUFormat implements IFormatterChangeLogContrib {
// find the "pattern" of a changelog entry. Not a specific one,
// but one that "looks" like an entry
int nextEntry = startOffset;
- int line_length = 0;
+ int lineNum = 0;
String entry = ""; // $NON-NLS-1$
while (nextEntry < changelogDoc.getLength()) {
try {
// Get the line of interest in the changelog document
- line_length = changelogDoc.getLineOfOffset(nextEntry);
+ lineNum = changelogDoc.getLineOfOffset(nextEntry);
entry = changelogDoc.get(nextEntry, changelogDoc
- .getLineLength(line_length));
+ .getLineLength(lineNum));
// Attempt to find date pattern on line
if (matchDatePattern(entry)) {
//nextDate -= entry.length()+1;
break;
}
// If no date matches, move to the next line
- nextEntry += changelogDoc.getLineLength(line_length);
+ nextEntry += changelogDoc.getLineLength(lineNum);
} catch (BadLocationException e) {
ChangelogPlugin.getDefault().getLog().log(
new Status(IStatus.ERROR, ChangelogPlugin.PLUGIN_ID, IStatus.ERROR, e
@@ -353,8 +361,9 @@ public class GNUFormat implements IFormatterChangeLogContrib {
// First start with an ISO date
try {
Date ad = isoDate.parse(text);
- if (ad != null)
+ if (ad != null) {
return true;
+ }
} catch (ParseException e) {
// We don't really care on exception; it just means it could not parse a date on that line
}
@@ -388,11 +397,11 @@ public class GNUFormat implements IFormatterChangeLogContrib {
private String formatFunction(String function) {
// If Function Guess is true, and Function Guess has found something
- if (function.length() > 0)
+ if (function.length() > 0) {
return "(" + function + "):"; // $NON-NLS-1$ // $NON-NLS-2$
- else
+ } else {
return ": "; //$NON-NLS-1$
-
+ }
}
public IDocument getDocument(IEditorPart currentEditor) {

Back to the top