Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 235572 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/releng/tools/ShellMakeFile.java (-3 / +19 lines)
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-15 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
14
import java.util.regex.Pattern;
15
13
import org.eclipse.core.resources.IFile;
16
import org.eclipse.core.resources.IFile;
14
17
15
public class ShellMakeFile extends SourceFile {
18
public class ShellMakeFile extends SourceFile {
Lines 18-29 Link Here
18
		super(file);
21
		super(file);
19
	}
22
	}
20
23
24
	//Optional Whitespace, #, optional whitespace, then at least 2 non-word chars repeated till EOL 
25
	private static Pattern p = Pattern.compile("\\s*#\\s*\\W{2,}\\s*");
26
	
27
	public boolean isCommentStart(String aLine) {
28
		return p.matcher(aLine).matches();
29
	}
30
31
	public boolean isCommentEnd(String aLine, String commentStartString) {
32
		String s = commentStartString.trim();
33
		s = s.substring(s.length()-2);
34
		return aLine.trim().endsWith(s);
35
	}
36
21
	public String getCommentStart() {
37
	public String getCommentStart() {
22
		return "#*";
38
		return "#*"; //unused, Pattern matcher above will be used instead
23
	}
39
	}
24
40
25
	public String getCommentEnd() {
41
	public String getCommentEnd() {
26
		return "**";
42
		return "**"; //unused, Pattern matcher above will be used instead
27
	}
43
	}
28
44
29
	public int getFileType() {
45
	public int getFileType() {
(-)src/org/eclipse/releng/tools/SourceFile.java (-5 / +32 lines)
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
				
(-)src/org/eclipse/releng/tools/BatFile.java (-3 / +19 lines)
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-15 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
14
import java.util.regex.Pattern;
15
13
import org.eclipse.core.resources.IFile;
16
import org.eclipse.core.resources.IFile;
14
17
15
public class BatFile extends SourceFile {
18
public class BatFile extends SourceFile {
Lines 18-29 Link Here
18
		super(file);
21
		super(file);
19
	}
22
	}
20
23
24
	//Optional Whitespace, #, optional whitespace, then at least 2 non-word chars repeated till EOL 
25
	private static Pattern p = Pattern.compile("\\s*@?[rR][eE][mM]\\s+\\W{2,}\\s*");
26
	
27
	public boolean isCommentStart(String aLine) {
28
		return p.matcher(aLine).matches();
29
	}
30
31
	public boolean isCommentEnd(String aLine, String commentStartString) {
32
		String s = commentStartString.trim();
33
		s = s.substring(s.length()-2);
34
		return aLine.trim().endsWith(s);
35
	}
36
21
	public String getCommentStart() {
37
	public String getCommentStart() {
22
		return "@rem **";
38
		return "@rem **";  //unused, Pattern matcher above will be used instead
23
	}
39
	}
24
40
25
	public String getCommentEnd() {
41
	public String getCommentEnd() {
26
		return "**";
42
		return "**";  //unused, Pattern matcher above will be used instead
27
	}
43
	}
28
	
44
	
29
	public int getFileType() {
45
	public int getFileType() {

Return to bug 235572