View | Details | Raw Unified | Return to bug 265103 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/jdt/core/tests/compiler/regression/TestAll.java (+1 lines)
Lines 59-64 Link Here
59
	standardTests.add(RuntimeTests.class);
59
	standardTests.add(RuntimeTests.class);
60
	standardTests.add(DebugAttributeTest.class);
60
	standardTests.add(DebugAttributeTest.class);
61
	standardTests.add(NullReferenceTest.class);
61
	standardTests.add(NullReferenceTest.class);
62
	standardTests.add(ManifestAnalyzerTest.class);
62
	if (UnconditionalFlowInfo.coverageTestFlag) {
63
	if (UnconditionalFlowInfo.coverageTestFlag) {
63
		standardTests.add(NullReferenceImplTests.class);
64
		standardTests.add(NullReferenceImplTests.class);
64
	}
65
	}
(-)src/org/eclipse/jdt/core/tests/compiler/regression/ManifestAnalyzerTest.java (+155 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     Fabrice Matrat - initial contribution
10
 *     IBM Corporation - code review and integration
11
 *******************************************************************************/
12
package org.eclipse.jdt.core.tests.compiler.regression;
13
import java.io.IOException;
14
import java.io.StringReader;
15
import java.util.List;
16
17
import org.eclipse.jdt.internal.compiler.batch.ClasspathJar.ManifestAnalyzer;
18
19
public class ManifestAnalyzerTest extends AbstractRegressionTest {
20
21
	private static final String FIRST_JAR = "firstJar.jar";
22
	private static final String SECOND_JAR = "secondJar.jar";
23
	private static final String WHITESPACE = " ";
24
25
	ManifestAnalyzer manifestAnalyzer = new ManifestAnalyzer();
26
27
	public ManifestAnalyzerTest(String name) {
28
		super(name);
29
	}
30
	public void testWithOneJar() throws IOException {
31
		String testWithOneJar = "Manifest-Version: 1.0\nAnt-Version: Apache Ant 1.6.5\nCreated-By: 1.5.0_14-b03 (Sun Microsystems Inc.)\nClass-Path: " + FIRST_JAR + "\nBuild-Reference: Version toto";
32
		StringReader reader = new StringReader(testWithOneJar);
33
		this.manifestAnalyzer.analyzeManifestContents(reader);
34
		List jars = this.manifestAnalyzer.getCalledFileNames();
35
		assertEquals("Wrong size", 1, jars.size());
36
		assertEquals(FIRST_JAR, jars.get(0));
37
	}
38
39
	public void testWithOneJarWithWiteSpace() throws IOException {
40
		String testWithOneJarWithWiteSpace = "Manifest-Version: 1.0\nAnt-Version: Apache Ant 1.6.5\nCreated-By: 1.5.0_14-b03 (Sun Microsystems Inc.)\nClass-Path: " + FIRST_JAR + WHITESPACE + "\nBuild-Reference: Version toto";
41
		StringReader reader = new StringReader(testWithOneJarWithWiteSpace);
42
		this.manifestAnalyzer.analyzeManifestContents(reader);
43
		List jars = this.manifestAnalyzer.getCalledFileNames();
44
		assertEquals("Wrong size", 1, jars.size());
45
		assertEquals(FIRST_JAR, jars.get(0));
46
	}
47
48
	public void testWithSecondJarOnNextLine() throws IOException {
49
		String testWithSecondJarOnNextLine = "Manifest-Version: 1.0\nAnt-Version: Apache Ant 1.6.5\nCreated-By: 1.5.0_14-b03 (Sun Microsystems Inc.)\nClass-Path: " + FIRST_JAR + "\n"+ WHITESPACE + WHITESPACE +"secondJar.jar\nBuild-Reference: Version toto";
50
		StringReader reader = new StringReader(testWithSecondJarOnNextLine);
51
		this.manifestAnalyzer.analyzeManifestContents(reader);
52
		List jars = this.manifestAnalyzer.getCalledFileNames();
53
		assertEquals("Wrong size", 2, jars.size());
54
		assertEquals(FIRST_JAR, jars.get(0));
55
		assertEquals(SECOND_JAR, jars.get(1));
56
	}
57
58
	public void testWithSecondJarOnTwoLine() throws IOException {
59
		String testWithSecondJarOnTwoLine = "Manifest-Version: 1.0\nAnt-Version: Apache Ant 1.6.5\nCreated-By: 1.5.0_14-b03 (Sun Microsystems Inc.)\nClass-Path: " + FIRST_JAR + WHITESPACE + "second\n" + WHITESPACE + "Jar.jar\nBuild-Reference: Version toto";
60
		StringReader reader = new StringReader(testWithSecondJarOnTwoLine);
61
		this.manifestAnalyzer.analyzeManifestContents(reader);
62
		List jars = this.manifestAnalyzer.getCalledFileNames();
63
		assertEquals("Wrong size", 2, jars.size());
64
		assertEquals(FIRST_JAR, jars.get(0));
65
		assertEquals(SECOND_JAR, jars.get(1));
66
	}
67
68
	public void testWithSecondJarOnTwoLine2() throws IOException {
69
		String testWithSecondJarOnTwoLine = "Manifest-Version: 1.0\nAnt-Version: Apache Ant 1.6.5\nCreated-By: 1.5.0_14-b03 (Sun Microsystems Inc.)\nClass-Path: " + FIRST_JAR + WHITESPACE + "second\n" + WHITESPACE + WHITESPACE + "Jar.jar\nBuild-Reference: Version toto";
70
		StringReader reader = new StringReader(testWithSecondJarOnTwoLine);
71
		this.manifestAnalyzer.analyzeManifestContents(reader);
72
		List jars = this.manifestAnalyzer.getCalledFileNames();
73
		assertEquals("Wrong size", 3, jars.size());
74
		assertEquals(FIRST_JAR, jars.get(0));
75
		assertEquals("second", jars.get(1));
76
		assertEquals("Jar.jar", jars.get(2));
77
	}
78
79
	public void testWithSecondJarOnTwoLine3() throws IOException {
80
		String testWithSecondJarOnTwoLine = "Manifest-Version: 1.0\nAnt-Version: Apache Ant 1.6.5\nCreated-By: 1.5.0_14-b03 (Sun Microsystems Inc.)\nClass-Path: " + FIRST_JAR + WHITESPACE + "second\n" + "Jar.jar\nBuild-Reference: Version toto";
81
		StringReader reader = new StringReader(testWithSecondJarOnTwoLine);
82
		this.manifestAnalyzer.analyzeManifestContents(reader);
83
		List jars = this.manifestAnalyzer.getCalledFileNames();
84
		assertEquals("Wrong size", 2, jars.size());
85
		assertEquals(FIRST_JAR, jars.get(0));
86
		assertEquals("second", jars.get(1));
87
	}
88
89
	public void testWithSecondJarOnTwoLine4() throws IOException {
90
		String testWithSecondJarOnTwoLine = "Manifest-Version: 1.0\nAnt-Version: Apache Ant 1.6.5\nCreated-By: 1.5.0_14-b03 (Sun Microsystems Inc.)\nClass-Path: " + FIRST_JAR + "\n" + "second\n" + WHITESPACE + "Jar.jar\nBuild-Reference: Version toto";
91
		StringReader reader = new StringReader(testWithSecondJarOnTwoLine);
92
		this.manifestAnalyzer.analyzeManifestContents(reader);
93
		List jars = this.manifestAnalyzer.getCalledFileNames();
94
		assertEquals("Wrong size", 1, jars.size());
95
		assertEquals(FIRST_JAR, jars.get(0));
96
	}
97
98
	public void testWithSecondJarOnNextLine5() throws IOException {
99
		String testWithSecondJarOnNextLine = "Manifest-Version: 1.0\nAnt-Version: Apache Ant 1.6.5\nCreated-By: 1.5.0_14-b03 (Sun Microsystems Inc.)\nClass-Path: " + FIRST_JAR + "\n"+ WHITESPACE + "secondJar.jar\nBuild-Reference: Version toto";
100
		StringReader reader = new StringReader(testWithSecondJarOnNextLine);
101
		this.manifestAnalyzer.analyzeManifestContents(reader);
102
		List jars = this.manifestAnalyzer.getCalledFileNames();
103
		assertEquals("Wrong size", 1, jars.size());
104
		assertEquals(FIRST_JAR + SECOND_JAR, jars.get(0));
105
	}
106
107
	public void testWithSecondJarOnTwoLineEndedWithEOF() throws IOException {
108
		String testWithSecondJarOnTwoLineEndedWithEOF = "Manifest-Version: 1.0\nAnt-Version: Apache Ant 1.6.5\nCreated-By: 1.5.0_14-b03 (Sun Microsystems Inc.)\nClass-Path: " + FIRST_JAR + " second\n Jar.jar";
109
		StringReader reader = new StringReader(testWithSecondJarOnTwoLineEndedWithEOF);
110
		this.manifestAnalyzer.analyzeManifestContents(reader);
111
		List jars = this.manifestAnalyzer.getCalledFileNames();
112
		assertEquals("Wrong size", 1, jars.size());
113
		assertEquals(FIRST_JAR, jars.get(0));
114
	}
115
116
	public void testWithSecondJarOnTwoLineEndedWithEOF2() throws IOException {
117
		String testWithSecondJarOnTwoLineEndedWithEOF = "Manifest-Version: 1.0\nAnt-Version: Apache Ant 1.6.5\nCreated-By: 1.5.0_14-b03 (Sun Microsystems Inc.)\nClass-Path: " + FIRST_JAR + " second\n Jar.jar\n";
118
		StringReader reader = new StringReader(testWithSecondJarOnTwoLineEndedWithEOF);
119
		this.manifestAnalyzer.analyzeManifestContents(reader);
120
		List jars = this.manifestAnalyzer.getCalledFileNames();
121
		assertEquals("Wrong size", 2, jars.size());
122
		assertEquals(FIRST_JAR, jars.get(0));
123
		assertEquals(SECOND_JAR, jars.get(1));
124
	}
125
126
	public void testWithSecondJarOnTwoLineEndedWithWhiteSpaceEOF() throws IOException {
127
		String testWithSecondJarOnTwoLineEndedWithWhiteSpaceEOF = "Manifest-Version: 1.0\nAnt-Version: Apache Ant 1.6.5\nCreated-By: 1.5.0_14-b03 (Sun Microsystems Inc.)\nClass-Path: " + FIRST_JAR + " second\n Jar.jar ";
128
		StringReader reader = new StringReader(testWithSecondJarOnTwoLineEndedWithWhiteSpaceEOF);
129
		this.manifestAnalyzer.analyzeManifestContents(reader);
130
		List jars = this.manifestAnalyzer.getCalledFileNames();
131
		assertEquals("Wrong size", 2, jars.size());
132
		assertEquals(FIRST_JAR, jars.get(0));
133
		assertEquals(SECOND_JAR, jars.get(1));
134
	}
135
136
	public void testWithSecondJarOnTwoLineEndedWithWhiteSpaceNewLineEOF() throws IOException {
137
		String testWithSecondJarOnTwoLineEndedWithWhiteSpaceNewLineEOF = "Manifest-Version: 1.0\nAnt-Version: Apache Ant 1.6.5\nCreated-By: 1.5.0_14-b03 (Sun Microsystems Inc.)\nClass-Path: " + FIRST_JAR + " second\n Jar.jar \n";
138
		StringReader reader = new StringReader(testWithSecondJarOnTwoLineEndedWithWhiteSpaceNewLineEOF);
139
		this.manifestAnalyzer.analyzeManifestContents(reader);
140
		List jars = this.manifestAnalyzer.getCalledFileNames();
141
		assertEquals("Wrong size", 2, jars.size());
142
		assertEquals(FIRST_JAR, jars.get(0));
143
		assertEquals(SECOND_JAR, jars.get(1));
144
	}
145
146
	public void testWithSecondJarOnTwoLineEndedWithNewLineEOF() throws IOException {
147
		String testWithSecondJarOnTwoLineEndedWithNewLineEOF = "Manifest-Version: 1.0\nAnt-Version: Apache Ant 1.6.5\nCreated-By: 1.5.0_14-b03 (Sun Microsystems Inc.)\nClass-Path: " + FIRST_JAR + " second\n Jar.jar\n";
148
		StringReader reader = new StringReader(testWithSecondJarOnTwoLineEndedWithNewLineEOF);
149
		this.manifestAnalyzer.analyzeManifestContents(reader);
150
		List jars = this.manifestAnalyzer.getCalledFileNames();
151
		assertEquals("Wrong size", 2, jars.size());
152
		assertEquals(FIRST_JAR, jars.get(0));
153
		assertEquals(SECOND_JAR, jars.get(1));
154
	}
155
}
(-)batch/org/eclipse/jdt/internal/compiler/batch/ClasspathJar.java (-14 / +50 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
 *     Fabrice Matrat - fix for 265103
10
 *******************************************************************************/
11
 *******************************************************************************/
11
package org.eclipse.jdt.internal.compiler.batch;
12
package org.eclipse.jdt.internal.compiler.batch;
12
13
Lines 54-71 Link Here
54
		READING_JAR = 4,
55
		READING_JAR = 4,
55
		CONTINUING = 5,
56
		CONTINUING = 5,
56
		SKIP_LINE = 6;
57
		SKIP_LINE = 6;
57
	private static final char[] CLASSPATH_HEADER_TOKEN = 
58
	private static final char[] CLASSPATH_HEADER_TOKEN =
58
		"Class-Path:".toCharArray(); //$NON-NLS-1$
59
		"Class-Path:".toCharArray(); //$NON-NLS-1$
59
	private int ClasspathSectionsCount;
60
	private int classpathSectionsCount;
60
	private ArrayList calledFilesNames;
61
	private ArrayList calledFilesNames;
61
	public boolean analyzeManifestContents(Reader reader) throws IOException {
62
	public boolean analyzeManifestContents(Reader reader) throws IOException {
62
		int state = START, substate = 0;
63
		int state = START, substate = 0;
63
		StringBuffer currentJarToken = new StringBuffer();
64
		StringBuffer currentJarToken = new StringBuffer();
64
		int currentChar;
65
		int currentChar;
65
		this.ClasspathSectionsCount = 0;
66
		this.classpathSectionsCount = 0;
66
		this.calledFilesNames = null;
67
		this.calledFilesNames = null;
67
		for (;;) {
68
		for (;;) {
68
			currentChar = reader.read();
69
			currentChar = reader.read();
70
			if (currentChar == '\r')  // skip \r, will consider \n later (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=251079 )
71
				currentChar = reader.read();
69
			switch (state) {
72
			switch (state) {
70
				case START:
73
				case START:
71
					if (currentChar == -1) {
74
					if (currentChar == -1) {
Lines 91-140 Link Here
91
				case PAST_CLASSPATH_HEADER:
94
				case PAST_CLASSPATH_HEADER:
92
					if (currentChar == ' ') {
95
					if (currentChar == ' ') {
93
						state = SKIPPING_WHITESPACE;
96
						state = SKIPPING_WHITESPACE;
94
						this.ClasspathSectionsCount++;
97
						this.classpathSectionsCount++;
95
					} else {
98
					} else {
96
						return false;
99
						return false;
97
					}
100
					}
98
					break;
101
					break;
99
				case SKIPPING_WHITESPACE:
102
				case SKIPPING_WHITESPACE:
100
					if (currentChar == -1) {
103
					if (currentChar == -1) {
104
						// >>>>>>>>>>>>>>>>>> Add the latest jar read
105
						addCurrentTokenJarWhenNecessary(currentJarToken);
101
						return true;
106
						return true;
102
					} else if (currentChar == '\n') {
107
					} else if (currentChar == '\n') {
103
						state = CONTINUING;
108
						state = CONTINUING;
104
					} else if (currentChar != ' ') {
109
					} else if (currentChar != ' ') {
105
						currentJarToken.append((char) currentChar);
110
						currentJarToken.append((char) currentChar);
106
						state = READING_JAR;
111
						state = READING_JAR;
112
					} else {
113
						// >>>>>>>>>>>>>>>>>> Add the latest jar read
114
						addCurrentTokenJarWhenNecessary(currentJarToken);
107
					}
115
					}
108
					break;
116
					break;
109
				case CONTINUING:
117
				case CONTINUING:
110
					if (currentChar == -1) {
118
					if (currentChar == -1) {
119
						// >>>>>>>>>>>>>>>>>> Add the latest jar read
120
						addCurrentTokenJarWhenNecessary(currentJarToken);
111
						return true;
121
						return true;
112
					} else if (currentChar == '\n') {
122
					} else if (currentChar == '\n') {
123
						addCurrentTokenJarWhenNecessary(currentJarToken);
113
						state = START;
124
						state = START;
114
					} else if (currentChar == ' ') {
125
					} else if (currentChar == ' ') {
115
						state = SKIPPING_WHITESPACE;
126
						state = SKIPPING_WHITESPACE;
116
					} else if (currentChar == CLASSPATH_HEADER_TOKEN[0]) {
127
					} else if (currentChar == CLASSPATH_HEADER_TOKEN[0]) {
128
						addCurrentTokenJarWhenNecessary(currentJarToken);
117
						state = IN_CLASSPATH_HEADER;
129
						state = IN_CLASSPATH_HEADER;
118
						substate = 1;
130
						substate = 1;
119
					} else if (this.calledFilesNames == null) {
131
					} else if (this.calledFilesNames == null) {
120
						return false;
132
						// >>>>>>>>>>>>>>>>>> Add the latest jar read
133
						addCurrentTokenJarWhenNecessary(currentJarToken);
134
						state = START;
121
					} else {
135
					} else {
136
						// >>>>>>>>>>>>>>>>>> Add the latest jar read
137
						addCurrentTokenJarWhenNecessary(currentJarToken);
122
						state = SKIP_LINE;
138
						state = SKIP_LINE;
123
					}
139
					}
124
					break;
140
					break;
125
				case SKIP_LINE:
141
				case SKIP_LINE:
126
					if (currentChar == -1) {
142
					if (currentChar == -1) {
143
						if (this.classpathSectionsCount != 0) {
144
							if (this.calledFilesNames == null) {
145
								return false;
146
							}
147
						}
127
						return true;
148
						return true;
128
					} else if (currentChar == '\n') {
149
					} else if (currentChar == '\n') {
129
						state = START;
150
						state = START;
130
					}
151
					}
131
					break;
152
					break;
132
				case READING_JAR:	
153
				case READING_JAR:
133
					if (currentChar == -1) {
154
					if (currentChar == -1) {
155
						// >>>>>>>>>>>>>>>>>> Add the latest jar read
134
						return false;
156
						return false;
135
					} else if (currentChar == '\n') {
157
					} else if (currentChar == '\n') {
136
						// appends token below
158
						// appends token below
137
						state = CONTINUING;
159
						state = CONTINUING;
160
						// >>>>>>>>>>> Add a break to not add the jar yet as it can continue on the next line
161
						break;
138
					} else if (currentChar == ' ') {
162
					} else if (currentChar == ' ') {
139
						// appends token below
163
						// appends token below
140
						state = SKIPPING_WHITESPACE;
164
						state = SKIPPING_WHITESPACE;
Lines 142-158 Link Here
142
						currentJarToken.append((char) currentChar);
166
						currentJarToken.append((char) currentChar);
143
						break;
167
						break;
144
					}
168
					}
145
					if (this.calledFilesNames == null) {
169
					addCurrentTokenJarWhenNecessary(currentJarToken);
146
						this.calledFilesNames = new ArrayList();
147
					}
148
					this.calledFilesNames.add(currentJarToken.toString());
149
					currentJarToken.setLength(0);
150
					break;
170
					break;
151
			}
171
			}
152
		}	
172
		}
173
	}	
174
	
175
	// >>>>>>>>>>>>>>>> Method Extracted from analyzeManifestContents in the READING_JAR Block
176
	private boolean addCurrentTokenJarWhenNecessary(StringBuffer currentJarToken) {
177
		if (currentJarToken != null && currentJarToken.length() > 0) {
178
			if (this.calledFilesNames == null) {
179
				this.calledFilesNames = new ArrayList();
180
			}
181
			this.calledFilesNames.add(currentJarToken.toString());
182
			currentJarToken.setLength(0);
183
			return true;
184
		}
185
		return false;
153
	}
186
	}
187
	// <<<<<<<<<<<<<<<<<<<<<<
188
	
189
	
154
	public int getClasspathSectionsCount() {
190
	public int getClasspathSectionsCount() {
155
		return this.ClasspathSectionsCount;
191
		return this.classpathSectionsCount;
156
	}
192
	}
157
	public List getCalledFileNames() {
193
	public List getCalledFileNames() {
158
		return this.calledFilesNames;
194
		return this.calledFilesNames;

Return to bug 265103