|
Lines 1-5
Link Here
|
| 1 |
/******************************************************************************* |
1 |
/******************************************************************************* |
| 2 |
* Copyright (c) 2000, 2008 IBM Corporation and others. |
2 |
* Copyright (c) 2000, 2009 IBM Corporation and others. |
| 3 |
* All rights reserved. This program and the accompanying materials |
3 |
* All rights reserved. This program and the accompanying materials |
| 4 |
* are made available under the terms of the Eclipse Public License v1.0 |
4 |
* are made available under the terms of the Eclipse Public License v1.0 |
| 5 |
* which accompanies this distribution, and is available at |
5 |
* which accompanies this distribution, and is available at |
|
Lines 7-12
Link Here
|
| 7 |
* |
7 |
* |
| 8 |
* Contributors: |
8 |
* Contributors: |
| 9 |
* IBM Corporation - initial API and implementation |
9 |
* IBM Corporation - initial API and implementation |
|
|
10 |
* Martin Oberhuber (Wind River) - [235572] detect existing comments in bat files |
| 10 |
*******************************************************************************/ |
11 |
*******************************************************************************/ |
| 11 |
package org.eclipse.releng.tools; |
12 |
package org.eclipse.releng.tools; |
| 12 |
|
13 |
|
|
Lines 51-57
Link Here
|
| 51 |
return new CFile(file); |
52 |
return new CFile(file); |
| 52 |
} else if (extension.equals("properties")) { //$NON-NLS-1$ |
53 |
} else if (extension.equals("properties")) { //$NON-NLS-1$ |
| 53 |
return new PropertiesFile(file); |
54 |
return new PropertiesFile(file); |
| 54 |
} else if (extension.equals("sh") || extension.equals("csh") || extension.equals("mak")) { //$NON-NLS-1$ |
55 |
} else if (extension.equals("sh") || extension.equals("csh") || extension.equals("mak") || extension.equals("pl") || extension.equals("tcl")) { //$NON-NLS-1$ |
| 55 |
return new ShellMakeFile(file); |
56 |
return new ShellMakeFile(file); |
| 56 |
} else if (extension.equals("bat")) { //$NON-NLS-1$ |
57 |
} else if (extension.equals("bat")) { //$NON-NLS-1$ |
| 57 |
return new BatFile(file); |
58 |
return new BatFile(file); |
|
Lines 70-75
Link Here
|
| 70 |
initialize(); |
71 |
initialize(); |
| 71 |
} |
72 |
} |
| 72 |
|
73 |
|
|
|
74 |
/** |
| 75 |
* Test if the given line marks the start of a potential Copyright comment. |
| 76 |
* Can be overridden in subclasses to perform advanced detection. |
| 77 |
* @param aLine a line of text to check |
| 78 |
* @return <code>true</code> if the line can mark a copyright comment start. |
| 79 |
* @since 3.5 |
| 80 |
*/ |
| 81 |
public boolean isCommentStart(String aLine) { |
| 82 |
return aLine.trim().startsWith(getCommentStart()); |
| 83 |
} |
| 84 |
/** |
| 85 |
* Test if the given line marks the end of a potential Copyright comment. |
| 86 |
* Can be overridden in subclasses to perform advanced detection. |
| 87 |
* @param aLine a line of text to check |
| 88 |
* @param commentStartString the line which started the block comment |
| 89 |
* @return <code>true</code> if the line can mark a copyright comment end. |
| 90 |
* @since 3.5 |
| 91 |
*/ |
| 92 |
public boolean isCommentEnd(String aLine, String commentStartString) { |
| 93 |
return aLine.trim().endsWith(getCommentEnd()); |
| 94 |
} |
| 73 |
public abstract String getCommentStart(); |
95 |
public abstract String getCommentStart(); |
| 74 |
public abstract String getCommentEnd(); |
96 |
public abstract String getCommentEnd(); |
| 75 |
|
97 |
|
|
Lines 102-129
Link Here
|
| 102 |
int commentStart = 0; |
124 |
int commentStart = 0; |
| 103 |
int commentEnd = 0; |
125 |
int commentEnd = 0; |
| 104 |
boolean inComment = false; |
126 |
boolean inComment = false; |
|
|
127 |
String commentStartString = ""; //$NON-NLS-1$ |
| 105 |
|
128 |
|
| 106 |
while (aLine != null) { |
129 |
while (aLine != null) { |
| 107 |
contentsWriter.write(aLine); |
130 |
contentsWriter.write(aLine); |
| 108 |
contentsWriter.newLine(); |
131 |
contentsWriter.newLine(); |
| 109 |
if (!inComment && aLine.trim().startsWith(getCommentStart())) { |
132 |
if (!inComment && isCommentStart(aLine)) { |
| 110 |
// start saving comment |
133 |
// start saving comment |
| 111 |
inComment = true; |
134 |
inComment = true; |
| 112 |
commentStart = lineNumber; |
135 |
commentStart = lineNumber; |
|
|
136 |
commentStartString = aLine; |
| 113 |
} |
137 |
} |
| 114 |
|
138 |
|
| 115 |
if (inComment) { |
139 |
if (inComment) { |
| 116 |
comment = comment + aLine + newLine; |
140 |
comment = comment + aLine + newLine; |
| 117 |
|
141 |
|
| 118 |
if (aLine.trim().endsWith(getCommentEnd()) && commentStart != lineNumber) { |
142 |
if (isCommentEnd(aLine, commentStartString) && commentStart != lineNumber) { |
| 119 |
// stop saving comment |
143 |
// stop saving comment |
| 120 |
inComment = false; |
144 |
inComment = false; |
| 121 |
commentEnd = lineNumber; |
145 |
commentEnd = lineNumber; |
| 122 |
BlockComment aComment = new BlockComment(commentStart, commentEnd, comment.toString(), getCommentStart(), getCommentEnd()); |
146 |
String commentEndString = aLine.trim(); |
|
|
147 |
commentEndString = commentEndString.substring(commentEndString.length()-2); |
| 148 |
BlockComment aComment = new BlockComment(commentStart, commentEnd, comment.toString(), commentStartString, commentEndString); |
| 123 |
comments.add(aComment); |
149 |
comments.add(aComment); |
| 124 |
comment = ""; //$NON-NLS-1$ |
150 |
comment = ""; //$NON-NLS-1$ |
| 125 |
commentStart = 0; |
151 |
commentStart = 0; |
| 126 |
commentEnd = 0; |
152 |
commentEnd = 0; |
|
|
153 |
commentStartString = ""; //$NON-NLS-1$ |
| 127 |
} |
154 |
} |
| 128 |
} |
155 |
} |
| 129 |
|
156 |
|