View | Details | Raw Unified | Return to bug 273157
Collapse All | Expand All

(-)compiler/org/eclipse/jdt/internal/compiler/util/ManifestAnalyzer.java (-115 / +118 lines)
Lines 10-19 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.jdt.internal.compiler.util;
11
package org.eclipse.jdt.internal.compiler.util;
12
12
13
import java.io.BufferedReader;
14
import java.io.IOException;
13
import java.io.IOException;
15
import java.io.InputStream;
14
import java.io.InputStream;
16
import java.io.InputStreamReader;
17
import java.util.ArrayList;
15
import java.util.ArrayList;
18
import java.util.List;
16
import java.util.List;
19
17
Lines 41-162 Link Here
41
	 * @throws IOException if an exception occurs while analyzing the file
39
	 * @throws IOException if an exception occurs while analyzing the file
42
	 */
40
	 */
43
	public boolean analyzeManifestContents(InputStream inputStream) throws IOException {
41
	public boolean analyzeManifestContents(InputStream inputStream) throws IOException {
44
		BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, Util.UTF_8));
42
		char[] chars = Util.getInputStreamAsCharArray(inputStream, -1, Util.UTF_8);
45
		try {
43
		int state = START, substate = 0;
46
			int state = START, substate = 0;
44
		StringBuffer currentJarToken = new StringBuffer();
47
			StringBuffer currentJarToken = new StringBuffer();
45
		int currentChar;
48
			int currentChar;
46
		this.classpathSectionsCount = 0;
49
			this.classpathSectionsCount = 0;
47
		this.calledFilesNames = null;
50
			this.calledFilesNames = null;
48
		for (int i = 0, max = chars.length; i < max;) {
51
			for (;;) {
49
			currentChar = chars[i++];
52
				currentChar = reader.read();
50
			if (currentChar == '\r') {
53
				if (currentChar == '\r')  // skip \r, will consider \n later (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=251079 )
51
				// skip \r, will consider \n later (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=251079 )
54
					currentChar = reader.read();
52
				if (i < max) {
55
				switch (state) {
53
					currentChar = chars[i++];
56
					case START:
57
						if (currentChar == -1) {
58
							return true;
59
						} else if (currentChar == CLASSPATH_HEADER_TOKEN[0]) {
60
							state = IN_CLASSPATH_HEADER;
61
							substate = 1;
62
						} else {
63
							state = SKIP_LINE;
64
						}
65
						break;
66
					case IN_CLASSPATH_HEADER:
67
						if (currentChar == -1) {
68
							return true;
69
						} else if (currentChar == '\n') {
70
							state = START;
71
						} else if (currentChar != CLASSPATH_HEADER_TOKEN[substate++]) {
72
							state = SKIP_LINE;
73
						} else if (substate == CLASSPATH_HEADER_TOKEN.length) {
74
							state = PAST_CLASSPATH_HEADER;
75
						}
76
						break;
77
					case PAST_CLASSPATH_HEADER:
78
						if (currentChar == ' ') {
79
							state = SKIPPING_WHITESPACE;
80
							this.classpathSectionsCount++;
81
						} else {
82
							return false;
83
						}
84
						break;
85
					case SKIPPING_WHITESPACE:
86
						if (currentChar == -1) {
87
							// >>>>>>>>>>>>>>>>>> Add the latest jar read
88
							addCurrentTokenJarWhenNecessary(currentJarToken);
89
							return true;
90
						} else if (currentChar == '\n') {
91
							state = CONTINUING;
92
						} else if (currentChar != ' ') {
93
							currentJarToken.append((char) currentChar);
94
							state = READING_JAR;
95
						} else {
96
							// >>>>>>>>>>>>>>>>>> Add the latest jar read
97
							addCurrentTokenJarWhenNecessary(currentJarToken);
98
						}
99
						break;
100
					case CONTINUING:
101
						if (currentChar == -1) {
102
							// >>>>>>>>>>>>>>>>>> Add the latest jar read
103
							addCurrentTokenJarWhenNecessary(currentJarToken);
104
							return true;
105
						} else if (currentChar == '\n') {
106
							addCurrentTokenJarWhenNecessary(currentJarToken);
107
							state = START;
108
						} else if (currentChar == ' ') {
109
							state = SKIPPING_WHITESPACE;
110
						} else if (currentChar == CLASSPATH_HEADER_TOKEN[0]) {
111
							addCurrentTokenJarWhenNecessary(currentJarToken);
112
							state = IN_CLASSPATH_HEADER;
113
							substate = 1;
114
						} else if (this.calledFilesNames == null) {
115
							// >>>>>>>>>>>>>>>>>> Add the latest jar read
116
							addCurrentTokenJarWhenNecessary(currentJarToken);
117
							state = START;
118
						} else {
119
							// >>>>>>>>>>>>>>>>>> Add the latest jar read
120
							addCurrentTokenJarWhenNecessary(currentJarToken);
121
							state = SKIP_LINE;
122
						}
123
						break;
124
					case SKIP_LINE:
125
						if (currentChar == -1) {
126
							if (this.classpathSectionsCount != 0) {
127
								if (this.calledFilesNames == null) {
128
									return false;
129
								}
130
							}
131
							return true;
132
						} else if (currentChar == '\n') {
133
							state = START;
134
						}
135
						break;
136
					case READING_JAR:
137
						if (currentChar == -1) {
138
							// >>>>>>>>>>>>>>>>>> Add the latest jar read
139
							return false;
140
						} else if (currentChar == '\n') {
141
							// appends token below
142
							state = CONTINUING;
143
							// >>>>>>>>>>> Add a break to not add the jar yet as it can continue on the next line
144
							break;
145
						} else if (currentChar == ' ') {
146
							// appends token below
147
							state = SKIPPING_WHITESPACE;
148
						} else {
149
							currentJarToken.append((char) currentChar);
150
							break;
151
						}
152
						addCurrentTokenJarWhenNecessary(currentJarToken);
153
						break;
154
				}
54
				}
155
			}
55
			}
156
		} finally {
56
			switch (state) {
157
			reader.close();
57
				case START:
58
					if (currentChar == CLASSPATH_HEADER_TOKEN[0]) {
59
						state = IN_CLASSPATH_HEADER;
60
						substate = 1;
61
					} else {
62
						state = SKIP_LINE;
63
					}
64
					break;
65
				case IN_CLASSPATH_HEADER:
66
					if (currentChar == '\n') {
67
						state = START;
68
					} else if (currentChar != CLASSPATH_HEADER_TOKEN[substate++]) {
69
						state = SKIP_LINE;
70
					} else if (substate == CLASSPATH_HEADER_TOKEN.length) {
71
						state = PAST_CLASSPATH_HEADER;
72
					}
73
					break;
74
				case PAST_CLASSPATH_HEADER:
75
					if (currentChar == ' ') {
76
						state = SKIPPING_WHITESPACE;
77
						this.classpathSectionsCount++;
78
					} else {
79
						return false;
80
					}
81
					break;
82
				case SKIPPING_WHITESPACE:
83
					if (currentChar == '\n') {
84
						state = CONTINUING;
85
					} else if (currentChar != ' ') {
86
						currentJarToken.append((char) currentChar);
87
						state = READING_JAR;
88
					} else {
89
						// >>>>>>>>>>>>>>>>>> Add the latest jar read
90
						addCurrentTokenJarWhenNecessary(currentJarToken);
91
					}
92
					break;
93
				case CONTINUING:
94
					if (currentChar == '\n') {
95
						addCurrentTokenJarWhenNecessary(currentJarToken);
96
						state = START;
97
					} else if (currentChar == ' ') {
98
						state = SKIPPING_WHITESPACE;
99
					} else if (currentChar == CLASSPATH_HEADER_TOKEN[0]) {
100
						addCurrentTokenJarWhenNecessary(currentJarToken);
101
						state = IN_CLASSPATH_HEADER;
102
						substate = 1;
103
					} else if (this.calledFilesNames == null) {
104
						// >>>>>>>>>>>>>>>>>> Add the latest jar read
105
						addCurrentTokenJarWhenNecessary(currentJarToken);
106
						state = START;
107
					} else {
108
						// >>>>>>>>>>>>>>>>>> Add the latest jar read
109
						addCurrentTokenJarWhenNecessary(currentJarToken);
110
						state = SKIP_LINE;
111
					}
112
					break;
113
				case SKIP_LINE:
114
					if (currentChar == '\n') {
115
						state = START;
116
					}
117
					break;
118
				case READING_JAR:
119
					if (currentChar == '\n') {
120
						// appends token below
121
						state = CONTINUING;
122
						// >>>>>>>>>>> Add a break to not add the jar yet as it can continue on the next line
123
						break;
124
					} else if (currentChar == ' ') {
125
						// appends token below
126
						state = SKIPPING_WHITESPACE;
127
					} else {
128
						currentJarToken.append((char) currentChar);
129
						break;
130
					}
131
					addCurrentTokenJarWhenNecessary(currentJarToken);
132
					break;
133
			}
134
		}
135
		switch (state) {
136
			case START:
137
				return true;
138
			case IN_CLASSPATH_HEADER:
139
				return true;
140
			case PAST_CLASSPATH_HEADER:
141
				return false;
142
			case SKIPPING_WHITESPACE:
143
				// >>>>>>>>>>>>>>>>>> Add the latest jar read
144
				addCurrentTokenJarWhenNecessary(currentJarToken);
145
				return true;
146
			case CONTINUING:
147
				// >>>>>>>>>>>>>>>>>> Add the latest jar read
148
				addCurrentTokenJarWhenNecessary(currentJarToken);
149
				return true;
150
			case SKIP_LINE:
151
				if (this.classpathSectionsCount != 0) {
152
					if (this.calledFilesNames == null) {
153
						return false;
154
					}
155
				}
156
				return true;
157
			case READING_JAR:
158
				// >>>>>>>>>>>>>>>>>> Add the latest jar read
159
				return false;
158
		}
160
		}
159
	}	
161
		return true;
162
	}
160
163
161
	// >>>>>>>>>>>>>>>> Method Extracted from analyzeManifestContents in the READING_JAR Block
164
	// >>>>>>>>>>>>>>>> Method Extracted from analyzeManifestContents in the READING_JAR Block
162
	private boolean addCurrentTokenJarWhenNecessary(StringBuffer currentJarToken) {
165
	private boolean addCurrentTokenJarWhenNecessary(StringBuffer currentJarToken) {

Return to bug 273157