Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 137702 Details for
Bug 235572
[relengtool] "Fix copyrights" doesnt detect existing Copyright in Windows .bat files
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
Improved patch with pattern matching
bug235572_detectRem.diff.txt (text/plain), 8.34 KB, created by
Martin Oberhuber
on 2009-05-29 15:13:35 EDT
(
hide
)
Description:
Improved patch with pattern matching
Filename:
MIME Type:
Creator:
Martin Oberhuber
Created:
2009-05-29 15:13:35 EDT
Size:
8.34 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.releng.tools >Index: src/org/eclipse/releng/tools/ShellMakeFile.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.releng.tools/src/org/eclipse/releng/tools/ShellMakeFile.java,v >retrieving revision 1.5 >diff -u -r1.5 ShellMakeFile.java >--- src/org/eclipse/releng/tools/ShellMakeFile.java 20 May 2009 19:07:04 -0000 1.5 >+++ src/org/eclipse/releng/tools/ShellMakeFile.java 29 May 2009 19:12:35 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2000, 2008 IBM Corporation and others. >+ * Copyright (c) 2000, 2009 IBM Corporation and others. > * All rights reserved. This program and the accompanying materials > * are made available under the terms of the Eclipse Public License v1.0 > * which accompanies this distribution, and is available at >@@ -7,9 +7,12 @@ > * > * Contributors: > * IBM Corporation - initial API and implementation >+ * Martin Oberhuber (Wind River) - [235572] detect existing comments in bat files > *******************************************************************************/ > package org.eclipse.releng.tools; > >+import java.util.regex.Pattern; >+ > import org.eclipse.core.resources.IFile; > > public class ShellMakeFile extends SourceFile { >@@ -18,12 +21,25 @@ > super(file); > } > >+ //Optional Whitespace, #, optional whitespace, then at least 2 non-word chars repeated till EOL >+ private static Pattern p = Pattern.compile("\\s*#\\s*\\W{2,}\\s*"); >+ >+ public boolean isCommentStart(String aLine) { >+ return p.matcher(aLine).matches(); >+ } >+ >+ public boolean isCommentEnd(String aLine, String commentStartString) { >+ String s = commentStartString.trim(); >+ s = s.substring(s.length()-2); >+ return aLine.trim().endsWith(s); >+ } >+ > public String getCommentStart() { >- return "#*"; >+ return "#*"; //unused, Pattern matcher above will be used instead > } > > public String getCommentEnd() { >- return "**"; >+ return "**"; //unused, Pattern matcher above will be used instead > } > > public int getFileType() { >Index: src/org/eclipse/releng/tools/SourceFile.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.releng.tools/src/org/eclipse/releng/tools/SourceFile.java,v >retrieving revision 1.8 >diff -u -r1.8 SourceFile.java >--- src/org/eclipse/releng/tools/SourceFile.java 31 Dec 2008 14:56:41 -0000 1.8 >+++ src/org/eclipse/releng/tools/SourceFile.java 29 May 2009 19:12:35 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2000, 2008 IBM Corporation and others. >+ * Copyright (c) 2000, 2009 IBM Corporation and others. > * All rights reserved. This program and the accompanying materials > * are made available under the terms of the Eclipse Public License v1.0 > * which accompanies this distribution, and is available at >@@ -7,6 +7,7 @@ > * > * Contributors: > * IBM Corporation - initial API and implementation >+ * Martin Oberhuber (Wind River) - [235572] detect existing comments in bat files > *******************************************************************************/ > package org.eclipse.releng.tools; > >@@ -51,7 +52,7 @@ > return new CFile(file); > } else if (extension.equals("properties")) { //$NON-NLS-1$ > return new PropertiesFile(file); >- } else if (extension.equals("sh") || extension.equals("csh") || extension.equals("mak")) { //$NON-NLS-1$ >+ } else if (extension.equals("sh") || extension.equals("csh") || extension.equals("mak") || extension.equals("pl") || extension.equals("tcl")) { //$NON-NLS-1$ > return new ShellMakeFile(file); > } else if (extension.equals("bat")) { //$NON-NLS-1$ > return new BatFile(file); >@@ -70,6 +71,27 @@ > initialize(); > } > >+ /** >+ * Test if the given line marks the start of a potential Copyright comment. >+ * Can be overridden in subclasses to perform advanced detection. >+ * @param aLine a line of text to check >+ * @return <code>true</code> if the line can mark a copyright comment start. >+ * @since 3.5 >+ */ >+ public boolean isCommentStart(String aLine) { >+ return aLine.trim().startsWith(getCommentStart()); >+ } >+ /** >+ * Test if the given line marks the end of a potential Copyright comment. >+ * Can be overridden in subclasses to perform advanced detection. >+ * @param aLine a line of text to check >+ * @param commentStartString the line which started the block comment >+ * @return <code>true</code> if the line can mark a copyright comment end. >+ * @since 3.5 >+ */ >+ public boolean isCommentEnd(String aLine, String commentStartString) { >+ return aLine.trim().endsWith(getCommentEnd()); >+ } > public abstract String getCommentStart(); > public abstract String getCommentEnd(); > >@@ -102,28 +124,33 @@ > int commentStart = 0; > int commentEnd = 0; > boolean inComment = false; >+ String commentStartString = ""; //$NON-NLS-1$ > > while (aLine != null) { > contentsWriter.write(aLine); > contentsWriter.newLine(); >- if (!inComment && aLine.trim().startsWith(getCommentStart())) { >+ if (!inComment && isCommentStart(aLine)) { > // start saving comment > inComment = true; > commentStart = lineNumber; >+ commentStartString = aLine; > } > > if (inComment) { > comment = comment + aLine + newLine; > >- if (aLine.trim().endsWith(getCommentEnd()) && commentStart != lineNumber) { >+ if (isCommentEnd(aLine, commentStartString) && commentStart != lineNumber) { > // stop saving comment > inComment = false; > commentEnd = lineNumber; >- BlockComment aComment = new BlockComment(commentStart, commentEnd, comment.toString(), getCommentStart(), getCommentEnd()); >+ String commentEndString = aLine.trim(); >+ commentEndString = commentEndString.substring(commentEndString.length()-2); >+ BlockComment aComment = new BlockComment(commentStart, commentEnd, comment.toString(), commentStartString, commentEndString); > comments.add(aComment); > comment = ""; //$NON-NLS-1$ > commentStart = 0; > commentEnd = 0; >+ commentStartString = ""; //$NON-NLS-1$ > } > } > >Index: src/org/eclipse/releng/tools/BatFile.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.releng.tools/src/org/eclipse/releng/tools/BatFile.java,v >retrieving revision 1.5 >diff -u -r1.5 BatFile.java >--- src/org/eclipse/releng/tools/BatFile.java 20 May 2009 19:07:04 -0000 1.5 >+++ src/org/eclipse/releng/tools/BatFile.java 29 May 2009 19:12:35 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2000, 2008 IBM Corporation and others. >+ * Copyright (c) 2000, 2009 IBM Corporation and others. > * All rights reserved. This program and the accompanying materials > * are made available under the terms of the Eclipse Public License v1.0 > * which accompanies this distribution, and is available at >@@ -7,9 +7,12 @@ > * > * Contributors: > * IBM Corporation - initial API and implementation >+ * Martin Oberhuber (Wind River) - [235572] detect existing comments in bat files > *******************************************************************************/ > package org.eclipse.releng.tools; > >+import java.util.regex.Pattern; >+ > import org.eclipse.core.resources.IFile; > > public class BatFile extends SourceFile { >@@ -18,12 +21,25 @@ > super(file); > } > >+ //Optional Whitespace, #, optional whitespace, then at least 2 non-word chars repeated till EOL >+ private static Pattern p = Pattern.compile("\\s*@?[rR][eE][mM]\\s+\\W{2,}\\s*"); >+ >+ public boolean isCommentStart(String aLine) { >+ return p.matcher(aLine).matches(); >+ } >+ >+ public boolean isCommentEnd(String aLine, String commentStartString) { >+ String s = commentStartString.trim(); >+ s = s.substring(s.length()-2); >+ return aLine.trim().endsWith(s); >+ } >+ > public String getCommentStart() { >- return "@rem **"; >+ return "@rem **"; //unused, Pattern matcher above will be used instead > } > > public String getCommentEnd() { >- return "**"; >+ return "**"; //unused, Pattern matcher above will be used instead > } > > public int getFileType() {
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 235572
:
137691
| 137702