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 188796 | Differences between
and this patch

Collapse All | Expand All

(-)a/org.eclipse.jdt.compiler.apt/src/org/eclipse/jdt/internal/compiler/apt/util/Archive.java (-7 / +26 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2006, 2007 IBM Corporation and others.
2
 * Copyright (c) 2006, 2015 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 14-21 Link Here
14
import java.io.IOException;
14
import java.io.IOException;
15
import java.nio.charset.Charset;
15
import java.nio.charset.Charset;
16
import java.util.ArrayList;
16
import java.util.ArrayList;
17
import java.util.Collections;
17
import java.util.Enumeration;
18
import java.util.Enumeration;
18
import java.util.Hashtable;
19
import java.util.Hashtable;
20
import java.util.List;
19
import java.util.Set;
21
import java.util.Set;
20
import java.util.zip.ZipEntry;
22
import java.util.zip.ZipEntry;
21
import java.util.zip.ZipException;
23
import java.util.zip.ZipException;
Lines 30-49 Link Here
30
	
32
	
31
	ZipFile zipFile;
33
	ZipFile zipFile;
32
	File file;
34
	File file;
35
33
	protected Hashtable<String, ArrayList<String>> packagesCache;
36
	protected Hashtable<String, ArrayList<String>> packagesCache;
34
	
37
	
35
	private Archive() {
38
	private Archive() {
39
		// used to construct UNKNOWN_ARCHIVE
36
	}
40
	}
37
41
38
	public Archive(File file) throws ZipException, IOException {
42
	public Archive(File file) throws ZipException, IOException {
39
		this.file = file;
43
		this.file = file;
40
		this.zipFile = new ZipFile(file);
44
		this.zipFile = new ZipFile(file);
41
		initialize();		
45
		initialize();
42
	}
46
	}
43
47
44
	private void initialize() {
48
	private void initialize() {
45
		// initialize packages
49
		// initialize packages
46
		this.packagesCache = new Hashtable<String, ArrayList<String>>();
50
		this.packagesCache = new Hashtable<>();
47
		nextEntry : for (Enumeration<? extends ZipEntry> e = this.zipFile.entries(); e.hasMoreElements(); ) {
51
		nextEntry : for (Enumeration<? extends ZipEntry> e = this.zipFile.entries(); e.hasMoreElements(); ) {
48
			String fileName = ((ZipEntry) e.nextElement()).getName();
52
			String fileName = ((ZipEntry) e.nextElement()).getName();
49
53
Lines 58-64 Link Here
58
				if (typeName.length() == 0) {
62
				if (typeName.length() == 0) {
59
					continue nextEntry;
63
					continue nextEntry;
60
				}
64
				}
61
				types = new ArrayList<String>();
65
				types = new ArrayList<>();
62
				types.add(typeName);
66
				types.add(typeName);
63
				this.packagesCache.put(packageName, types);
67
				this.packagesCache.put(packageName, types);
64
			} else {
68
			} else {
Lines 68-74 Link Here
68
	}
72
	}
69
	
73
	
70
	public ArchiveFileObject getArchiveFileObject(String entryName, Charset charset) {
74
	public ArchiveFileObject getArchiveFileObject(String entryName, Charset charset) {
71
		return new ArchiveFileObject(this.file, this.zipFile, entryName, charset);
75
		return new ArchiveFileObject(this.file, entryName, charset);
72
	}
76
	}
73
	
77
	
74
	public boolean contains(String entryName) {
78
	public boolean contains(String entryName) {
Lines 82-89 Link Here
82
		return this.packagesCache.keySet();
86
		return this.packagesCache.keySet();
83
	}
87
	}
84
	
88
	
85
	public ArrayList<String> getTypes(String packageName) {
89
	public List<String> getTypes(String packageName) {
86
		// package name is expected to ends with '/'
90
		// package name is expected to ends with '/'
91
		if (this.packagesCache == null) {
92
			try {
93
				this.zipFile = new ZipFile(this.file);
94
			} catch(IOException e) {
95
				return Collections.<String>emptyList();
96
			}
97
			this.initialize();
98
		}
87
		return this.packagesCache.get(packageName);
99
		return this.packagesCache.get(packageName);
88
	}
100
	}
89
	
101
	
Lines 93-102 Link Here
93
105
94
	public void close() {
106
	public void close() {
95
		try {
107
		try {
96
			if (this.zipFile != null) this.zipFile.close();
108
			if (this.zipFile != null) {
109
				this.zipFile.close();
110
			}
97
			this.packagesCache = null;
111
			this.packagesCache = null;
98
		} catch (IOException e) {
112
		} catch (IOException e) {
99
			// ignore
113
			// ignore
100
		}
114
		}
101
	}
115
	}
116
	
117
	@Override
118
	public String toString() {
119
		return "Archive: " + (this.file == null ? "UNKNOWN_ARCHIVE" : this.file.getAbsolutePath()); //$NON-NLS-1$ //$NON-NLS-2$
120
	}
102
}
121
}
(-)a/org.eclipse.jdt.compiler.apt/src/org/eclipse/jdt/internal/compiler/apt/util/ArchiveFileObject.java (-45 / +91 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2006, 2011 IBM Corporation and others.
2
 * Copyright (c) 2006, 2015 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 34-56 Link Here
34
 * Implementation of a Java file object that corresponds to an entry in a zip/jar file
34
 * Implementation of a Java file object that corresponds to an entry in a zip/jar file
35
 */
35
 */
36
public class ArchiveFileObject implements JavaFileObject {
36
public class ArchiveFileObject implements JavaFileObject {
37
	private ZipEntry zipEntry;
38
	private ZipFile zipFile;
39
	private String entryName;
37
	private String entryName;
40
	private File file;
38
	private File file;
39
	private ZipFile zipFile;
41
	private Charset charset;
40
	private Charset charset;
42
	
41
43
	public ArchiveFileObject(File file, ZipFile zipFile, String entryName, Charset charset) {
42
	public ArchiveFileObject(File file, String entryName, Charset charset) {
44
		this.zipFile = zipFile;
45
		this.zipEntry = zipFile.getEntry(entryName);
46
		this.entryName = entryName;
43
		this.entryName = entryName;
47
		this.file = file;
44
		this.file = file;
48
		this.charset = charset;
45
		this.charset = charset;
49
	}
46
	}
50
47
48
	@Override
49
	protected void finalize() throws Throwable {
50
		if (this.zipFile != null) {
51
			try {
52
				this.zipFile.close();
53
			} catch (IOException e) {
54
				// ignore
55
			}
56
		}
57
		super.finalize();
58
	}
59
51
	/* (non-Javadoc)
60
	/* (non-Javadoc)
52
	 * @see javax.tools.JavaFileObject#getAccessLevel()
61
	 * @see javax.tools.JavaFileObject#getAccessLevel()
53
	 */
62
	 */
63
	@Override
54
	public Modifier getAccessLevel() {
64
	public Modifier getAccessLevel() {
55
		// cannot express multiple modifier
65
		// cannot express multiple modifier
56
		if (getKind() != Kind.CLASS) {
66
		if (getKind() != Kind.CLASS) {
Lines 58-69 Link Here
58
		}
68
		}
59
		ClassFileReader reader = null;
69
		ClassFileReader reader = null;
60
		try {
70
		try {
61
			reader = ClassFileReader.read(this.zipFile, this.entryName);
71
			try (ZipFile zip = new ZipFile(this.file)) {
72
				reader = ClassFileReader.read(zip, this.entryName);
73
			}
62
		} catch (ClassFormatException e) {
74
		} catch (ClassFormatException e) {
63
			// ignore
75
			// ignore
64
		} catch (IOException e) {
76
		} catch (IOException e) {
65
			// ignore
77
			// ignore
66
		}
78
		}
79
67
		if (reader == null) {
80
		if (reader == null) {
68
			return null;
81
			return null;
69
		}
82
		}
Lines 83-88 Link Here
83
	/* (non-Javadoc)
96
	/* (non-Javadoc)
84
	 * @see javax.tools.JavaFileObject#getKind()
97
	 * @see javax.tools.JavaFileObject#getKind()
85
	 */
98
	 */
99
	@Override
86
	public Kind getKind() {
100
	public Kind getKind() {
87
		String name = this.entryName.toLowerCase();
101
		String name = this.entryName.toLowerCase();
88
		if (name.endsWith(Kind.CLASS.extension)) {
102
		if (name.endsWith(Kind.CLASS.extension)) {
Lines 98-148 Link Here
98
	/* (non-Javadoc)
112
	/* (non-Javadoc)
99
	 * @see javax.tools.JavaFileObject#getNestingKind()
113
	 * @see javax.tools.JavaFileObject#getNestingKind()
100
	 */
114
	 */
115
	@Override
101
	public NestingKind getNestingKind() {
116
	public NestingKind getNestingKind() {
102
		switch(getKind()) {
117
		switch(getKind()) {
103
			case SOURCE :
118
		case SOURCE :
104
				return NestingKind.TOP_LEVEL;
119
			return NestingKind.TOP_LEVEL;
105
			case CLASS :
120
		case CLASS :
106
        		ClassFileReader reader = null;
121
			ClassFileReader reader = null;
107
        		try {
122
			try {
108
        			reader = ClassFileReader.read(this.zipFile, this.entryName);
123
				try (ZipFile zip = new ZipFile(this.file)) {
109
        		} catch (ClassFormatException e) {
124
					reader = ClassFileReader.read(zip, this.entryName);
110
        			// ignore
125
				}
111
        		} catch (IOException e) {
126
			} catch (ClassFormatException e) {
112
        			// ignore
127
				// ignore
113
        		}
128
			} catch (IOException e) {
114
        		if (reader == null) {
129
				// ignore
115
        			return null;
130
			}
116
        		}
131
			if (reader == null) {
117
        		if (reader.isAnonymous()) {
132
				return null;
118
        			return NestingKind.ANONYMOUS;
133
			}
119
        		}
134
			if (reader.isAnonymous()) {
120
        		if (reader.isLocal()) {
135
				return NestingKind.ANONYMOUS;
121
        			return NestingKind.LOCAL;
136
			}
122
        		}
137
			if (reader.isLocal()) {
123
        		if (reader.isMember()) {
138
				return NestingKind.LOCAL;
124
        			return NestingKind.MEMBER;
139
			}
125
        		}
140
			if (reader.isMember()) {
126
        		return NestingKind.TOP_LEVEL;
141
				return NestingKind.MEMBER;
127
        	default:
142
			}
128
        		return null;
143
			return NestingKind.TOP_LEVEL;
144
		default:
145
			return null;
129
		}
146
		}
130
	}
147
	}
131
148
132
	/* (non-Javadoc)
149
	/* (non-Javadoc)
133
	 * @see javax.tools.JavaFileObject#isNameCompatible(java.lang.String, javax.tools.JavaFileObject.Kind)
150
	 * @see javax.tools.JavaFileObject#isNameCompatible(java.lang.String, javax.tools.JavaFileObject.Kind)
134
	 */
151
	 */
152
	@Override
135
	public boolean isNameCompatible(String simpleName, Kind kind) {
153
	public boolean isNameCompatible(String simpleName, Kind kind) {
136
		return this.zipEntry.getName().endsWith(simpleName + kind.extension);
154
		return this.entryName.endsWith(simpleName + kind.extension);
137
	}
155
	}
138
156
139
	/* (non-Javadoc)
157
	/* (non-Javadoc)
140
	 * @see javax.tools.FileObject#delete()
158
	 * @see javax.tools.FileObject#delete()
141
	 */
159
	 */
160
	@Override
142
	public boolean delete() {
161
	public boolean delete() {
143
		throw new UnsupportedOperationException();
162
		throw new UnsupportedOperationException();
144
	}
163
	}
145
164
165
	@Override
146
	public boolean equals(Object o) {
166
	public boolean equals(Object o) {
147
		if (!(o instanceof ArchiveFileObject)) {
167
		if (!(o instanceof ArchiveFileObject)) {
148
			return false;
168
			return false;
Lines 151-162 Link Here
151
		return archiveFileObject.toUri().equals(this.toUri());
171
		return archiveFileObject.toUri().equals(this.toUri());
152
	}
172
	}
153
173
174
	@Override
175
	public int hashCode() {
176
		return this.toUri().hashCode();
177
	}
178
154
	/* (non-Javadoc)
179
	/* (non-Javadoc)
155
	 * @see javax.tools.FileObject#getCharContent(boolean)
180
	 * @see javax.tools.FileObject#getCharContent(boolean)
156
	 */
181
	 */
182
	@Override
157
	public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException {
183
	public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException {
158
		if (getKind() == Kind.SOURCE) {
184
		if (getKind() == Kind.SOURCE) {
159
			return Util.getCharContents(this, ignoreEncodingErrors, org.eclipse.jdt.internal.compiler.util.Util.getZipEntryByteContent(this.zipEntry, this.zipFile), this.charset.name());
185
			try (ZipFile zipFile2 = new ZipFile(this.file)) {
186
				ZipEntry zipEntry = zipFile2.getEntry(this.entryName);
187
				return Util.getCharContents(this, ignoreEncodingErrors, org.eclipse.jdt.internal.compiler.util.Util.getZipEntryByteContent(zipEntry, zipFile2), this.charset.name());
188
			}
160
		}
189
		}
161
		return null;
190
		return null;
162
	}
191
	}
Lines 164-190 Link Here
164
	/* (non-Javadoc)
193
	/* (non-Javadoc)
165
	 * @see javax.tools.FileObject#getLastModified()
194
	 * @see javax.tools.FileObject#getLastModified()
166
	 */
195
	 */
196
	@Override
167
	public long getLastModified() {
197
	public long getLastModified() {
168
		return this.zipEntry.getTime(); // looks the closest from the last modification
198
		try (ZipFile zip = new ZipFile(this.file)) {
199
			ZipEntry zipEntry = zip.getEntry(this.entryName);
200
			return zipEntry.getTime(); // looks the closest from the last modification
201
		} catch(IOException e) {
202
			// ignore
203
		}
204
		return 0;
169
	}
205
	}
170
206
171
	/* (non-Javadoc)
207
	/* (non-Javadoc)
172
	 * @see javax.tools.FileObject#getName()
208
	 * @see javax.tools.FileObject#getName()
173
	 */
209
	 */
210
	@Override
174
	public String getName() {
211
	public String getName() {
175
		return this.zipEntry.getName();
212
		return this.entryName;
176
	}
213
	}
177
214
178
	/* (non-Javadoc)
215
	/* (non-Javadoc)
179
	 * @see javax.tools.FileObject#openInputStream()
216
	 * @see javax.tools.FileObject#openInputStream()
180
	 */
217
	 */
218
	@Override
181
	public InputStream openInputStream() throws IOException {
219
	public InputStream openInputStream() throws IOException {
182
		return this.zipFile.getInputStream(this.zipEntry);
220
		if (this.zipFile == null) {
221
			this.zipFile = new ZipFile(this.file);
222
		}
223
		ZipEntry zipEntry = this.zipFile.getEntry(this.entryName);
224
		return this.zipFile.getInputStream(zipEntry);
183
	}
225
	}
184
226
185
	/* (non-Javadoc)
227
	/* (non-Javadoc)
186
	 * @see javax.tools.FileObject#openOutputStream()
228
	 * @see javax.tools.FileObject#openOutputStream()
187
	 */
229
	 */
230
	@Override
188
	public OutputStream openOutputStream() throws IOException {
231
	public OutputStream openOutputStream() throws IOException {
189
		throw new UnsupportedOperationException();
232
		throw new UnsupportedOperationException();
190
	}
233
	}
Lines 192-197 Link Here
192
	/* (non-Javadoc)
235
	/* (non-Javadoc)
193
	 * @see javax.tools.FileObject#openReader(boolean)
236
	 * @see javax.tools.FileObject#openReader(boolean)
194
	 */
237
	 */
238
	@Override
195
	public Reader openReader(boolean ignoreEncodingErrors) throws IOException {
239
	public Reader openReader(boolean ignoreEncodingErrors) throws IOException {
196
		throw new UnsupportedOperationException();
240
		throw new UnsupportedOperationException();
197
	}
241
	}
Lines 199-204 Link Here
199
	/* (non-Javadoc)
243
	/* (non-Javadoc)
200
	 * @see javax.tools.FileObject#openWriter()
244
	 * @see javax.tools.FileObject#openWriter()
201
	 */
245
	 */
246
	@Override
202
	public Writer openWriter() throws IOException {
247
	public Writer openWriter() throws IOException {
203
		throw new UnsupportedOperationException();
248
		throw new UnsupportedOperationException();
204
	}
249
	}
Lines 206-222 Link Here
206
	/* (non-Javadoc)
251
	/* (non-Javadoc)
207
	 * @see javax.tools.FileObject#toUri()
252
	 * @see javax.tools.FileObject#toUri()
208
	 */
253
	 */
254
	@Override
209
	public URI toUri() {
255
	public URI toUri() {
210
		try {
256
		try {
211
			return new URI("jar:" + this.file.toURI().getPath() + "!" + this.zipEntry.getName()); //$NON-NLS-1$//$NON-NLS-2$
257
			return new URI("jar:" + this.file.toURI().getPath() + "!" + this.entryName); //$NON-NLS-1$//$NON-NLS-2$
212
		} catch (URISyntaxException e) {
258
		} catch (URISyntaxException e) {
213
			return null;
259
			return null;
214
		}
260
		}
215
	}
261
	}
216
	
217
262
218
    @Override
263
219
    public String toString() {
264
	@Override
220
        return this.file.getAbsolutePath() + "[" + this.zipEntry.getName() + "]";//$NON-NLS-1$//$NON-NLS-2$
265
	public String toString() {
221
    }	
266
		return this.file.getAbsolutePath() + "[" + this.entryName + "]";//$NON-NLS-1$//$NON-NLS-2$
267
	}	
222
}
268
}
(-)a/org.eclipse.jdt.compiler.apt/src/org/eclipse/jdt/internal/compiler/apt/util/EclipseFileManager.java (-125 / +69 lines)
Lines 23-28 Link Here
23
import java.util.Arrays;
23
import java.util.Arrays;
24
import java.util.HashMap;
24
import java.util.HashMap;
25
import java.util.Iterator;
25
import java.util.Iterator;
26
import java.util.List;
26
import java.util.Locale;
27
import java.util.Locale;
27
import java.util.Map;
28
import java.util.Map;
28
import java.util.MissingResourceException;
29
import java.util.MissingResourceException;
Lines 33-41 Link Here
33
34
34
import javax.tools.FileObject;
35
import javax.tools.FileObject;
35
import javax.tools.JavaFileObject;
36
import javax.tools.JavaFileObject;
37
import javax.tools.JavaFileObject.Kind;
36
import javax.tools.StandardJavaFileManager;
38
import javax.tools.StandardJavaFileManager;
37
import javax.tools.StandardLocation;
39
import javax.tools.StandardLocation;
38
import javax.tools.JavaFileObject.Kind;
39
40
40
import org.eclipse.jdt.core.compiler.IProblem;
41
import org.eclipse.jdt.core.compiler.IProblem;
41
import org.eclipse.jdt.internal.compiler.batch.FileSystem;
42
import org.eclipse.jdt.internal.compiler.batch.FileSystem;
Lines 67-74 Link Here
67
	public EclipseFileManager(Locale locale, Charset charset) {
68
	public EclipseFileManager(Locale locale, Charset charset) {
68
		this.locale = locale == null ? Locale.getDefault() : locale;
69
		this.locale = locale == null ? Locale.getDefault() : locale;
69
		this.charset = charset == null ? Charset.defaultCharset() : charset;
70
		this.charset = charset == null ? Charset.defaultCharset() : charset;
70
		this.locations = new HashMap<String, Iterable<? extends File>>();
71
		this.locations = new HashMap<>();
71
		this.archivesCache = new HashMap<File, Archive>();
72
		this.archivesCache = new HashMap<>();
72
		try {
73
		try {
73
			this.setLocation(StandardLocation.PLATFORM_CLASS_PATH, getDefaultBootclasspath());
74
			this.setLocation(StandardLocation.PLATFORM_CLASS_PATH, getDefaultBootclasspath());
74
			Iterable<? extends File> defaultClasspath = getDefaultClasspath();
75
			Iterable<? extends File> defaultClasspath = getDefaultClasspath();
Lines 84-138 Link Here
84
		}
85
		}
85
	}
86
	}
86
87
87
	private void addFiles(File[][] jars, ArrayList<File> files) {
88
		if (jars != null) {
89
			for (File[] currentJars : jars) {
90
				if (currentJars != null) {
91
					for (File currentJar : currentJars) {
92
						if (currentJar.exists()) {
93
							files.add(currentJar);
94
						}
95
					}
96
				}
97
			}
98
		}
99
	}
100
	
101
	
102
	private void addFilesFrom(File javaHome, String propertyName, String defaultPath, ArrayList<File> files) {
103
		String extdirsStr = System.getProperty(propertyName);
104
		File[] directoriesToCheck = null;
105
		if (extdirsStr == null) {
106
			if (javaHome != null) {
107
				directoriesToCheck = new File[] { new File(javaHome, defaultPath) };
108
			}
109
		} else {
110
			StringTokenizer tokenizer = new StringTokenizer(extdirsStr, File.pathSeparator);
111
			ArrayList<String> paths = new ArrayList<String>();
112
			while (tokenizer.hasMoreTokens()) {
113
				paths.add(tokenizer.nextToken());
114
			}
115
			if (paths.size() != 0) {
116
				directoriesToCheck = new File[paths.size()];
117
				for (int i = 0; i < directoriesToCheck.length; i++)  {
118
					directoriesToCheck[i] = new File(paths.get(i));
119
				}
120
			}
121
		}
122
		if (directoriesToCheck != null) {
123
			addFiles(Main.getLibrariesFiles(directoriesToCheck), files);
124
		}
125
		
126
	}
127
	
128
	/* (non-Javadoc)
88
	/* (non-Javadoc)
129
	 * @see javax.tools.JavaFileManager#close()
89
	 * @see javax.tools.JavaFileManager#close()
130
	 */
90
	 */
91
	@Override
131
	public void close() throws IOException {
92
	public void close() throws IOException {
132
		this.locations = null;
93
		if (this.locations != null) this.locations.clear();
133
		for (Archive archive : this.archivesCache.values()) {
94
		for (Archive archive : this.archivesCache.values()) {
134
			archive.close();
95
			archive.close();
135
		}
96
		}
97
		this.archivesCache.clear();
136
	}
98
	}
137
	
99
	
138
	private void collectAllMatchingFiles(File file, String normalizedPackageName, Set<Kind> kinds, boolean recurse, ArrayList<JavaFileObject> collector) {
100
	private void collectAllMatchingFiles(File file, String normalizedPackageName, Set<Kind> kinds, boolean recurse, ArrayList<JavaFileObject> collector) {
Lines 165-170 Link Here
165
			}
127
			}
166
		} else {
128
		} else {
167
			Archive archive = this.getArchive(file);
129
			Archive archive = this.getArchive(file);
130
			if (archive == Archive.UNKNOWN_ARCHIVE) return;
168
			String key = normalizedPackageName;
131
			String key = normalizedPackageName;
169
			if (!normalizedPackageName.endsWith("/")) {//$NON-NLS-1$
132
			if (!normalizedPackageName.endsWith("/")) {//$NON-NLS-1$
170
				key += '/';
133
				key += '/';
Lines 173-179 Link Here
173
			if (recurse) {
136
			if (recurse) {
174
				for (String packageName : archive.allPackages()) {
137
				for (String packageName : archive.allPackages()) {
175
					if (packageName.startsWith(key)) {
138
					if (packageName.startsWith(key)) {
176
						ArrayList<String> types = archive.getTypes(packageName);
139
						List<String> types = archive.getTypes(packageName);
177
						if (types != null) {
140
						if (types != null) {
178
							for (String typeName : types) {
141
							for (String typeName : types) {
179
								final Kind kind = getKind(getExtension(typeName));
142
								final Kind kind = getKind(getExtension(typeName));
Lines 185-196 Link Here
185
					}
148
					}
186
				}
149
				}
187
			} else {
150
			} else {
188
				ArrayList<String> types = archive.getTypes(key);
151
				List<String> types = archive.getTypes(key);
189
				if (types != null) {
152
				if (types != null) {
190
					for (String typeName : types) {
153
					for (String typeName : types) {
191
						final Kind kind = getKind(typeName);
154
						final Kind kind = getKind(getExtension(typeName));
192
						if (kinds.contains(kind)) {
155
						if (kinds.contains(kind)) {
193
							collector.add(archive.getArchiveFileObject(normalizedPackageName + typeName, this.charset));
156
							collector.add(archive.getArchiveFileObject(key + typeName, this.charset));
194
						}
157
						}
195
					}
158
					}
196
				}
159
				}
Lines 199-205 Link Here
199
	}
162
	}
200
163
201
	private Iterable<? extends File> concatFiles(Iterable<? extends File> iterable, Iterable<? extends File> iterable2) {
164
	private Iterable<? extends File> concatFiles(Iterable<? extends File> iterable, Iterable<? extends File> iterable2) {
202
		ArrayList<File> list = new ArrayList<File>();
165
		ArrayList<File> list = new ArrayList<>();
203
		if (iterable2 == null) return iterable;
166
		if (iterable2 == null) return iterable;
204
		for (Iterator<? extends File> iterator = iterable.iterator(); iterator.hasNext(); ) {
167
		for (Iterator<? extends File> iterator = iterable.iterator(); iterator.hasNext(); ) {
205
			list.add(iterator.next());
168
			list.add(iterator.next());
Lines 213-218 Link Here
213
	/* (non-Javadoc)
176
	/* (non-Javadoc)
214
	 * @see javax.tools.JavaFileManager#flush()
177
	 * @see javax.tools.JavaFileManager#flush()
215
	 */
178
	 */
179
	@Override
216
	public void flush() throws IOException {
180
	public void flush() throws IOException {
217
		for (Archive archive : this.archivesCache.values()) {
181
		for (Archive archive : this.archivesCache.values()) {
218
			archive.flush();
182
			archive.flush();
Lines 223-245 Link Here
223
		// check the archive (jar/zip) cache
187
		// check the archive (jar/zip) cache
224
		Archive archive = this.archivesCache.get(f);
188
		Archive archive = this.archivesCache.get(f);
225
		if (archive == null) {
189
		if (archive == null) {
190
			archive = Archive.UNKNOWN_ARCHIVE;
226
			// create a new archive
191
			// create a new archive
227
			if (f.exists()) {
192
			if (f.exists()) {
228
    			try {
193
				try {
229
    				archive = new Archive(f);
194
					archive = new Archive(f);
230
    			} catch (ZipException e) {
195
				} catch (ZipException e) {
231
    				// ignore
196
					// ignore
232
    			} catch (IOException e) {
197
				} catch (IOException e) {
233
    				// ignore
198
					// ignore
234
    			}
199
				}
235
    			if (archive != null) {
200
				if (archive != null) {
236
    				this.archivesCache.put(f, archive);
201
					this.archivesCache.put(f, archive);
237
    			} else {
202
				}
238
    				this.archivesCache.put(f, Archive.UNKNOWN_ARCHIVE);
239
    			}
240
			} else {
241
				this.archivesCache.put(f, Archive.UNKNOWN_ARCHIVE);
242
			}
203
			}
204
			this.archivesCache.put(f, archive);
243
		}
205
		}
244
		return archive;
206
		return archive;
245
	}
207
	}
Lines 247-259 Link Here
247
	/* (non-Javadoc)
209
	/* (non-Javadoc)
248
	 * @see javax.tools.JavaFileManager#getClassLoader(javax.tools.JavaFileManager.Location)
210
	 * @see javax.tools.JavaFileManager#getClassLoader(javax.tools.JavaFileManager.Location)
249
	 */
211
	 */
212
	@Override
250
	public ClassLoader getClassLoader(Location location) {
213
	public ClassLoader getClassLoader(Location location) {
251
		Iterable<? extends File> files = getLocation(location);
214
		Iterable<? extends File> files = getLocation(location);
252
		if (files == null) {
215
		if (files == null) {
253
			// location is unknown
216
			// location is unknown
254
			return null;
217
			return null;
255
		}
218
		}
256
		ArrayList<URL> allURLs = new ArrayList<URL>();
219
		ArrayList<URL> allURLs = new ArrayList<>();
257
		for (File f : files) {
220
		for (File f : files) {
258
			try {
221
			try {
259
				allURLs.add(f.toURI().toURL());
222
				allURLs.add(f.toURI().toURL());
Lines 267-274 Link Here
267
	}
230
	}
268
231
269
	private Iterable<? extends File> getPathsFrom(String path) {
232
	private Iterable<? extends File> getPathsFrom(String path) {
270
		ArrayList<FileSystem.Classpath> paths = new ArrayList<FileSystem.Classpath>();
233
		ArrayList<FileSystem.Classpath> paths = new ArrayList<>();
271
		ArrayList<File> files = new ArrayList<File>();
234
		ArrayList<File> files = new ArrayList<>();
272
		try {
235
		try {
273
			this.processPathEntries(Main.DEFAULT_SIZE_CLASSPATH, paths, path, this.charset.name(), false, false);
236
			this.processPathEntries(Main.DEFAULT_SIZE_CLASSPATH, paths, path, this.charset.name(), false, false);
274
		} catch (IllegalArgumentException e) {
237
		} catch (IllegalArgumentException e) {
Lines 281-287 Link Here
281
	}
244
	}
282
245
283
	Iterable<? extends File> getDefaultBootclasspath() {
246
	Iterable<? extends File> getDefaultBootclasspath() {
284
		ArrayList<File> files = new ArrayList<File>();
247
		List<File> files = new ArrayList<>();
285
		String javaversion = System.getProperty("java.version");//$NON-NLS-1$
248
		String javaversion = System.getProperty("java.version");//$NON-NLS-1$
286
		if(javaversion.length() > 3)
249
		if(javaversion.length() > 3)
287
			javaversion = javaversion.substring(0, 3);
250
			javaversion = javaversion.substring(0, 3);
Lines 291-322 Link Here
291
			return null;
254
			return null;
292
		}
255
		}
293
256
294
		/*
257
		for (String fileName : org.eclipse.jdt.internal.compiler.util.Util.collectFilesNames()) {
295
		 * Handle >= JDK 1.6
258
			files.add(new File(fileName));
296
		 */
297
		String javaHome = System.getProperty("java.home"); //$NON-NLS-1$
298
		File javaHomeFile = null;
299
		if (javaHome != null) {
300
			javaHomeFile = new File(javaHome);
301
			if (!javaHomeFile.exists())
302
				javaHomeFile = null;
303
		}
259
		}
304
305
		addFilesFrom(javaHomeFile, "java.endorsed.dirs", "/lib/endorsed", files);//$NON-NLS-1$//$NON-NLS-2$
306
		if (javaHomeFile != null) {
307
			File[] directoriesToCheck = null;
308
			String libs = System.getProperty("os.name").startsWith("Mac") && jdkLevel == ClassFileConstants.JDK1_6 ? "../Classes" : "lib";//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
309
			directoriesToCheck = new File[] { new File(javaHomeFile, libs)};
310
			File[][] jars = Main.getLibrariesFiles(directoriesToCheck);
311
			addFiles(jars, files);
312
		}
313
		addFilesFrom(javaHomeFile, "java.ext.dirs", "/lib/ext", files);//$NON-NLS-1$//$NON-NLS-2$
314
		return files;
260
		return files;
315
	}
261
	}
316
262
317
	Iterable<? extends File> getDefaultClasspath() {
263
	Iterable<? extends File> getDefaultClasspath() {
318
		// default classpath
264
		// default classpath
319
		ArrayList<File> files = new ArrayList<File>();
265
		ArrayList<File> files = new ArrayList<>();
320
		String classProp = System.getProperty("java.class.path"); //$NON-NLS-1$
266
		String classProp = System.getProperty("java.class.path"); //$NON-NLS-1$
321
		if ((classProp == null) || (classProp.length() == 0)) {
267
		if ((classProp == null) || (classProp.length() == 0)) {
322
			return null;
268
			return null;
Lines 335-342 Link Here
335
	}
281
	}
336
282
337
	private Iterable<? extends File> getEndorsedDirsFrom(String path) {
283
	private Iterable<? extends File> getEndorsedDirsFrom(String path) {
338
		ArrayList<FileSystem.Classpath> paths = new ArrayList<FileSystem.Classpath>();
284
		ArrayList<FileSystem.Classpath> paths = new ArrayList<>();
339
		ArrayList<File> files = new ArrayList<File>();
285
		ArrayList<File> files = new ArrayList<>();
340
		try {
286
		try {
341
			this.processPathEntries(Main.DEFAULT_SIZE_CLASSPATH, paths, path, this.charset.name(), false, false);
287
			this.processPathEntries(Main.DEFAULT_SIZE_CLASSPATH, paths, path, this.charset.name(), false, false);
342
		} catch (IllegalArgumentException e) {
288
		} catch (IllegalArgumentException e) {
Lines 349-356 Link Here
349
	}
295
	}
350
296
351
	private Iterable<? extends File> getExtdirsFrom(String path) {
297
	private Iterable<? extends File> getExtdirsFrom(String path) {
352
		ArrayList<FileSystem.Classpath> paths = new ArrayList<FileSystem.Classpath>();
298
		ArrayList<FileSystem.Classpath> paths = new ArrayList<>();
353
		ArrayList<File> files = new ArrayList<File>();
299
		ArrayList<File> files = new ArrayList<>();
354
		try {
300
		try {
355
			this.processPathEntries(Main.DEFAULT_SIZE_CLASSPATH, paths, path, this.charset.name(), false, false);
301
			this.processPathEntries(Main.DEFAULT_SIZE_CLASSPATH, paths, path, this.charset.name(), false, false);
356
		} catch (IllegalArgumentException e) {
302
		} catch (IllegalArgumentException e) {
Lines 377-382 Link Here
377
	/* (non-Javadoc)
323
	/* (non-Javadoc)
378
	 * @see javax.tools.JavaFileManager#getFileForInput(javax.tools.JavaFileManager.Location, java.lang.String, java.lang.String)
324
	 * @see javax.tools.JavaFileManager#getFileForInput(javax.tools.JavaFileManager.Location, java.lang.String, java.lang.String)
379
	 */
325
	 */
326
	@Override
380
	public FileObject getFileForInput(Location location, String packageName, String relativeName) throws IOException {
327
	public FileObject getFileForInput(Location location, String packageName, String relativeName) throws IOException {
381
		Iterable<? extends File> files = getLocation(location);
328
		Iterable<? extends File> files = getLocation(location);
382
		if (files == null) {
329
		if (files == null) {
Lines 408-413 Link Here
408
	/* (non-Javadoc)
355
	/* (non-Javadoc)
409
	 * @see javax.tools.JavaFileManager#getFileForOutput(javax.tools.JavaFileManager.Location, java.lang.String, java.lang.String, javax.tools.FileObject)
356
	 * @see javax.tools.JavaFileManager#getFileForOutput(javax.tools.JavaFileManager.Location, java.lang.String, java.lang.String, javax.tools.FileObject)
410
	 */
357
	 */
358
	@Override
411
	public FileObject getFileForOutput(Location location, String packageName, String relativeName, FileObject sibling)
359
	public FileObject getFileForOutput(Location location, String packageName, String relativeName, FileObject sibling)
412
			throws IOException {
360
			throws IOException {
413
		Iterable<? extends File> files = getLocation(location);
361
		Iterable<? extends File> files = getLocation(location);
Lines 428-433 Link Here
428
	/* (non-Javadoc)
376
	/* (non-Javadoc)
429
	 * @see javax.tools.JavaFileManager#getJavaFileForInput(javax.tools.JavaFileManager.Location, java.lang.String, javax.tools.JavaFileObject.Kind)
377
	 * @see javax.tools.JavaFileManager#getJavaFileForInput(javax.tools.JavaFileManager.Location, java.lang.String, javax.tools.JavaFileObject.Kind)
430
	 */
378
	 */
379
	@Override
431
	public JavaFileObject getJavaFileForInput(Location location, String className, Kind kind) throws IOException {
380
	public JavaFileObject getJavaFileForInput(Location location, String className, Kind kind) throws IOException {
432
		if (kind != Kind.CLASS && kind != Kind.SOURCE) {
381
		if (kind != Kind.CLASS && kind != Kind.SOURCE) {
433
			throw new IllegalArgumentException("Invalid kind : " + kind);//$NON-NLS-1$
382
			throw new IllegalArgumentException("Invalid kind : " + kind);//$NON-NLS-1$
Lines 463-468 Link Here
463
	/* (non-Javadoc)
412
	/* (non-Javadoc)
464
	 * @see javax.tools.JavaFileManager#getJavaFileForOutput(javax.tools.JavaFileManager.Location, java.lang.String, javax.tools.JavaFileObject.Kind, javax.tools.FileObject)
413
	 * @see javax.tools.JavaFileManager#getJavaFileForOutput(javax.tools.JavaFileManager.Location, java.lang.String, javax.tools.JavaFileObject.Kind, javax.tools.FileObject)
465
	 */
414
	 */
415
	@Override
466
	public JavaFileObject getJavaFileForOutput(Location location, String className, Kind kind, FileObject sibling)
416
	public JavaFileObject getJavaFileForOutput(Location location, String className, Kind kind, FileObject sibling)
467
			throws IOException {
417
			throws IOException {
468
		if (kind != Kind.CLASS && kind != Kind.SOURCE) {
418
		if (kind != Kind.CLASS && kind != Kind.SOURCE) {
Lines 517-522 Link Here
517
	/* (non-Javadoc)
467
	/* (non-Javadoc)
518
	 * @see javax.tools.StandardJavaFileManager#getJavaFileObjects(java.io.File[])
468
	 * @see javax.tools.StandardJavaFileManager#getJavaFileObjects(java.io.File[])
519
	 */
469
	 */
470
	@Override
520
	public Iterable<? extends JavaFileObject> getJavaFileObjects(File... files) {
471
	public Iterable<? extends JavaFileObject> getJavaFileObjects(File... files) {
521
		return getJavaFileObjectsFromFiles(Arrays.asList(files));
472
		return getJavaFileObjectsFromFiles(Arrays.asList(files));
522
	}
473
	}
Lines 524-529 Link Here
524
	/* (non-Javadoc)
475
	/* (non-Javadoc)
525
	 * @see javax.tools.StandardJavaFileManager#getJavaFileObjects(java.lang.String[])
476
	 * @see javax.tools.StandardJavaFileManager#getJavaFileObjects(java.lang.String[])
526
	 */
477
	 */
478
	@Override
527
	public Iterable<? extends JavaFileObject> getJavaFileObjects(String... names) {
479
	public Iterable<? extends JavaFileObject> getJavaFileObjects(String... names) {
528
		return getJavaFileObjectsFromStrings(Arrays.asList(names));
480
		return getJavaFileObjectsFromStrings(Arrays.asList(names));
529
	}
481
	}
Lines 531-538 Link Here
531
	/* (non-Javadoc)
483
	/* (non-Javadoc)
532
	 * @see javax.tools.StandardJavaFileManager#getJavaFileObjectsFromFiles(java.lang.Iterable)
484
	 * @see javax.tools.StandardJavaFileManager#getJavaFileObjectsFromFiles(java.lang.Iterable)
533
	 */
485
	 */
486
	@Override
534
	public Iterable<? extends JavaFileObject> getJavaFileObjectsFromFiles(Iterable<? extends File> files) {
487
	public Iterable<? extends JavaFileObject> getJavaFileObjectsFromFiles(Iterable<? extends File> files) {
535
		ArrayList<JavaFileObject> javaFileArrayList = new ArrayList<JavaFileObject>();
488
		ArrayList<JavaFileObject> javaFileArrayList = new ArrayList<>();
536
		for (File f : files) {
489
		for (File f : files) {
537
			if (f.isDirectory()) {
490
			if (f.isDirectory()) {
538
				throw new IllegalArgumentException("file : " + f.getAbsolutePath() + " is a directory"); //$NON-NLS-1$ //$NON-NLS-2$
491
				throw new IllegalArgumentException("file : " + f.getAbsolutePath() + " is a directory"); //$NON-NLS-1$ //$NON-NLS-2$
Lines 545-552 Link Here
545
	/* (non-Javadoc)
498
	/* (non-Javadoc)
546
	 * @see javax.tools.StandardJavaFileManager#getJavaFileObjectsFromStrings(java.lang.Iterable)
499
	 * @see javax.tools.StandardJavaFileManager#getJavaFileObjectsFromStrings(java.lang.Iterable)
547
	 */
500
	 */
501
	@Override
548
	public Iterable<? extends JavaFileObject> getJavaFileObjectsFromStrings(Iterable<String> names) {
502
	public Iterable<? extends JavaFileObject> getJavaFileObjectsFromStrings(Iterable<String> names) {
549
		ArrayList<File> files = new ArrayList<File>();
503
		ArrayList<File> files = new ArrayList<>();
550
		for (String name : names) {
504
		for (String name : names) {
551
			files.add(new File(name));
505
			files.add(new File(name));
552
		}
506
		}
Lines 571-576 Link Here
571
	/* (non-Javadoc)
525
	/* (non-Javadoc)
572
	 * @see javax.tools.StandardJavaFileManager#getLocation(javax.tools.JavaFileManager.Location)
526
	 * @see javax.tools.StandardJavaFileManager#getLocation(javax.tools.JavaFileManager.Location)
573
	 */
527
	 */
528
	@Override
574
	public Iterable<? extends File> getLocation(Location location) {
529
	public Iterable<? extends File> getLocation(Location location) {
575
		if (this.locations == null) return null;
530
		if (this.locations == null) return null;
576
		return this.locations.get(location.getName());
531
		return this.locations.get(location.getName());
Lines 584-590 Link Here
584
		if (file.exists() && !file.isDirectory()) {
539
		if (file.exists() && !file.isDirectory()) {
585
			throw new IllegalArgumentException("file : " + file.getAbsolutePath() + " is not a directory");//$NON-NLS-1$//$NON-NLS-2$
540
			throw new IllegalArgumentException("file : " + file.getAbsolutePath() + " is not a directory");//$NON-NLS-1$//$NON-NLS-2$
586
		}
541
		}
587
		ArrayList<File> list = new ArrayList<File>(1);
542
		ArrayList<File> list = new ArrayList<>(1);
588
		list.add(file);
543
		list.add(file);
589
		return list;
544
		return list;
590
	}
545
	}
Lines 592-610 Link Here
592
	/* (non-Javadoc)
547
	/* (non-Javadoc)
593
	 * @see javax.tools.JavaFileManager#handleOption(java.lang.String, java.util.Iterator)
548
	 * @see javax.tools.JavaFileManager#handleOption(java.lang.String, java.util.Iterator)
594
	 */
549
	 */
550
	@Override
595
	public boolean handleOption(String current, Iterator<String> remaining) {
551
	public boolean handleOption(String current, Iterator<String> remaining) {
596
		try {
552
		try {
597
			if ("-bootclasspath".equals(current)) {//$NON-NLS-1$
553
			if ("-bootclasspath".equals(current)) {//$NON-NLS-1$
598
				remaining.remove(); // remove the current option
599
				if (remaining.hasNext()) {
554
				if (remaining.hasNext()) {
600
					final Iterable<? extends File> bootclasspaths = getPathsFrom(remaining.next());
555
					final Iterable<? extends File> bootclasspaths = getPathsFrom(remaining.next());
601
					if (bootclasspaths != null) {
556
					if (bootclasspaths != null) {
602
						Iterable<? extends File> iterable = getLocation(StandardLocation.PLATFORM_CLASS_PATH);
557
						Iterable<? extends File> iterable = getLocation(StandardLocation.PLATFORM_CLASS_PATH);
603
						if ((this.flags & HAS_ENDORSED_DIRS) == 0
558
						if ((this.flags & EclipseFileManager.HAS_ENDORSED_DIRS) == 0
604
								&& (this.flags & HAS_EXT_DIRS) == 0) {
559
								&& (this.flags & EclipseFileManager.HAS_EXT_DIRS) == 0) {
605
							// override default bootclasspath
560
							// override default bootclasspath
606
							setLocation(StandardLocation.PLATFORM_CLASS_PATH, bootclasspaths);
561
							setLocation(StandardLocation.PLATFORM_CLASS_PATH, bootclasspaths);
607
						} else if ((this.flags & HAS_ENDORSED_DIRS) != 0) {
562
						} else if ((this.flags & EclipseFileManager.HAS_ENDORSED_DIRS) != 0) {
608
							// endorseddirs have been processed first
563
							// endorseddirs have been processed first
609
							setLocation(StandardLocation.PLATFORM_CLASS_PATH, 
564
							setLocation(StandardLocation.PLATFORM_CLASS_PATH, 
610
									concatFiles(iterable, bootclasspaths));
565
									concatFiles(iterable, bootclasspaths));
Lines 614-628 Link Here
614
									prependFiles(iterable, bootclasspaths));
569
									prependFiles(iterable, bootclasspaths));
615
						}
570
						}
616
					}
571
					}
617
					remaining.remove();
572
					this.flags |= EclipseFileManager.HAS_BOOTCLASSPATH;
618
					this.flags |= HAS_BOOTCLASSPATH;
619
					return true;
573
					return true;
620
				} else {
574
				} else {
621
					throw new IllegalArgumentException();
575
					throw new IllegalArgumentException();
622
				}
576
				}
623
			}
577
			}
624
			if ("-classpath".equals(current) || "-cp".equals(current)) {//$NON-NLS-1$//$NON-NLS-2$
578
			if ("-classpath".equals(current) || "-cp".equals(current)) {//$NON-NLS-1$//$NON-NLS-2$
625
				remaining.remove(); // remove the current option
626
				if (remaining.hasNext()) {
579
				if (remaining.hasNext()) {
627
					final Iterable<? extends File> classpaths = getPathsFrom(remaining.next());
580
					final Iterable<? extends File> classpaths = getPathsFrom(remaining.next());
628
					if (classpaths != null) {
581
					if (classpaths != null) {
Lines 633-730 Link Here
633
						} else {
586
						} else {
634
							setLocation(StandardLocation.CLASS_PATH, classpaths);
587
							setLocation(StandardLocation.CLASS_PATH, classpaths);
635
						}
588
						}
636
						if ((this.flags & HAS_PROCESSORPATH) == 0) {
589
						if ((this.flags & EclipseFileManager.HAS_PROCESSORPATH) == 0) {
637
							setLocation(StandardLocation.ANNOTATION_PROCESSOR_PATH, classpaths);
590
							setLocation(StandardLocation.ANNOTATION_PROCESSOR_PATH, classpaths);
638
						}
591
						}
639
					}
592
					}
640
					remaining.remove();
641
					return true;
593
					return true;
642
				} else {
594
				} else {
643
					throw new IllegalArgumentException();
595
					throw new IllegalArgumentException();
644
				}
596
				}
645
			}
597
			}
646
			if ("-encoding".equals(current)) {//$NON-NLS-1$
598
			if ("-encoding".equals(current)) {//$NON-NLS-1$
647
				remaining.remove(); // remove the current option
648
				if (remaining.hasNext()) {
599
				if (remaining.hasNext()) {
649
					this.charset = Charset.forName(remaining.next());
600
					this.charset = Charset.forName(remaining.next());
650
					remaining.remove();
651
					return true;
601
					return true;
652
				} else {
602
				} else {
653
					throw new IllegalArgumentException();
603
					throw new IllegalArgumentException();
654
				}
604
				}
655
			}
605
			}
656
			if ("-sourcepath".equals(current)) {//$NON-NLS-1$
606
			if ("-sourcepath".equals(current)) {//$NON-NLS-1$
657
				remaining.remove(); // remove the current option
658
				if (remaining.hasNext()) {
607
				if (remaining.hasNext()) {
659
					final Iterable<? extends File> sourcepaths = getPathsFrom(remaining.next());
608
					final Iterable<? extends File> sourcepaths = getPathsFrom(remaining.next());
660
					if (sourcepaths != null) setLocation(StandardLocation.SOURCE_PATH, sourcepaths);
609
					if (sourcepaths != null) setLocation(StandardLocation.SOURCE_PATH, sourcepaths);
661
					remaining.remove();
662
					return true;
610
					return true;
663
				} else {
611
				} else {
664
					throw new IllegalArgumentException();
612
					throw new IllegalArgumentException();
665
				}
613
				}
666
			}
614
			}
667
			if ("-extdirs".equals(current)) {//$NON-NLS-1$
615
			if ("-extdirs".equals(current)) {//$NON-NLS-1$
668
				remaining.remove(); // remove the current option
669
				if (remaining.hasNext()) {
616
				if (remaining.hasNext()) {
670
					Iterable<? extends File> iterable = getLocation(StandardLocation.PLATFORM_CLASS_PATH);
617
					Iterable<? extends File> iterable = getLocation(StandardLocation.PLATFORM_CLASS_PATH);
671
					setLocation(StandardLocation.PLATFORM_CLASS_PATH, 
618
					setLocation(StandardLocation.PLATFORM_CLASS_PATH, 
672
							concatFiles(iterable, getExtdirsFrom(remaining.next())));
619
							concatFiles(iterable, getExtdirsFrom(remaining.next())));
673
					remaining.remove();
620
					this.flags |= EclipseFileManager.HAS_EXT_DIRS;
674
					this.flags |= HAS_EXT_DIRS;
675
					return true;
621
					return true;
676
				} else {
622
				} else {
677
					throw new IllegalArgumentException();
623
					throw new IllegalArgumentException();
678
				}
624
				}
679
			}
625
			}
680
			if ("-endorseddirs".equals(current)) {//$NON-NLS-1$
626
			if ("-endorseddirs".equals(current)) {//$NON-NLS-1$
681
				remaining.remove(); // remove the current option
682
				if (remaining.hasNext()) {
627
				if (remaining.hasNext()) {
683
					Iterable<? extends File> iterable = getLocation(StandardLocation.PLATFORM_CLASS_PATH);
628
					Iterable<? extends File> iterable = getLocation(StandardLocation.PLATFORM_CLASS_PATH);
684
					setLocation(StandardLocation.PLATFORM_CLASS_PATH, 
629
					setLocation(StandardLocation.PLATFORM_CLASS_PATH, 
685
							prependFiles(iterable, getEndorsedDirsFrom(remaining.next())));
630
							prependFiles(iterable, getEndorsedDirsFrom(remaining.next())));
686
					remaining.remove();
631
					this.flags |= EclipseFileManager.HAS_ENDORSED_DIRS;
687
					this.flags |= HAS_ENDORSED_DIRS;
688
					return true;
632
					return true;
689
				} else {
633
				} else {
690
					throw new IllegalArgumentException();
634
					throw new IllegalArgumentException();
691
				}
635
				}
692
			}
636
			}
693
			if ("-d".equals(current)) { //$NON-NLS-1$
637
			if ("-d".equals(current)) { //$NON-NLS-1$
694
				remaining.remove(); // remove the current option
695
				if (remaining.hasNext()) {
638
				if (remaining.hasNext()) {
696
					final Iterable<? extends File> outputDir = getOutputDir(remaining.next());
639
					final Iterable<? extends File> outputDir = getOutputDir(remaining.next());
697
					if (outputDir != null) {
640
					if (outputDir != null) {
698
						setLocation(StandardLocation.CLASS_OUTPUT, outputDir);
641
						setLocation(StandardLocation.CLASS_OUTPUT, outputDir);
699
					}
642
					}
700
					remaining.remove();
701
					return true;
643
					return true;
702
				} else {
644
				} else {
703
					throw new IllegalArgumentException();
645
					throw new IllegalArgumentException();
704
				}
646
				}
705
			}
647
			}
706
			if ("-s".equals(current)) { //$NON-NLS-1$
648
			if ("-s".equals(current)) { //$NON-NLS-1$
707
				remaining.remove(); // remove the current option
708
				if (remaining.hasNext()) {
649
				if (remaining.hasNext()) {
709
					final Iterable<? extends File> outputDir = getOutputDir(remaining.next());
650
					final Iterable<? extends File> outputDir = getOutputDir(remaining.next());
710
					if (outputDir != null) {
651
					if (outputDir != null) {
711
						setLocation(StandardLocation.SOURCE_OUTPUT, outputDir);
652
						setLocation(StandardLocation.SOURCE_OUTPUT, outputDir);
712
					}
653
					}
713
					remaining.remove();
714
					return true;
654
					return true;
715
				} else {
655
				} else {
716
					throw new IllegalArgumentException();
656
					throw new IllegalArgumentException();
717
				}				
657
				}				
718
			}
658
			}
719
			if ("-processorpath".equals(current)) {//$NON-NLS-1$
659
			if ("-processorpath".equals(current)) {//$NON-NLS-1$
720
				remaining.remove(); // remove the current option
721
				if (remaining.hasNext()) {
660
				if (remaining.hasNext()) {
722
					final Iterable<? extends File> processorpaths = getPathsFrom(remaining.next());
661
					final Iterable<? extends File> processorpaths = getPathsFrom(remaining.next());
723
					if (processorpaths != null) {
662
					if (processorpaths != null) {
724
						setLocation(StandardLocation.ANNOTATION_PROCESSOR_PATH, processorpaths);
663
						setLocation(StandardLocation.ANNOTATION_PROCESSOR_PATH, processorpaths);
725
					}
664
					}
726
					remaining.remove();
665
					this.flags |= EclipseFileManager.HAS_PROCESSORPATH;
727
					this.flags |= HAS_PROCESSORPATH;
728
					return true;
666
					return true;
729
				} else {
667
				} else {
730
					throw new IllegalArgumentException();
668
					throw new IllegalArgumentException();
Lines 739-744 Link Here
739
	/* (non-Javadoc)
677
	/* (non-Javadoc)
740
	 * @see javax.tools.JavaFileManager#hasLocation(javax.tools.JavaFileManager.Location)
678
	 * @see javax.tools.JavaFileManager#hasLocation(javax.tools.JavaFileManager.Location)
741
	 */
679
	 */
680
	@Override
742
	public boolean hasLocation(Location location) {
681
	public boolean hasLocation(Location location) {
743
		return this.locations != null && this.locations.containsKey(location.getName());
682
		return this.locations != null && this.locations.containsKey(location.getName());
744
	}
683
	}
Lines 746-751 Link Here
746
	/* (non-Javadoc)
685
	/* (non-Javadoc)
747
	 * @see javax.tools.JavaFileManager#inferBinaryName(javax.tools.JavaFileManager.Location, javax.tools.JavaFileObject)
686
	 * @see javax.tools.JavaFileManager#inferBinaryName(javax.tools.JavaFileManager.Location, javax.tools.JavaFileObject)
748
	 */
687
	 */
688
	@Override
749
	public String inferBinaryName(Location location, JavaFileObject file) {
689
	public String inferBinaryName(Location location, JavaFileObject file) {
750
		String name = file.getName();
690
		String name = file.getName();
751
		JavaFileObject javaFileObject = null;
691
		JavaFileObject javaFileObject = null;
Lines 763-769 Link Here
763
		if (javaFileObject == null) {
703
		if (javaFileObject == null) {
764
			return null;
704
			return null;
765
		}
705
		}
766
		return normalized(name);
706
		return name.replace('/', '.');
767
	}
707
	}
768
708
769
	private boolean isArchive(File f) {
709
	private boolean isArchive(File f) {
Lines 774-779 Link Here
774
	/* (non-Javadoc)
714
	/* (non-Javadoc)
775
	 * @see javax.tools.StandardJavaFileManager#isSameFile(javax.tools.FileObject, javax.tools.FileObject)
715
	 * @see javax.tools.StandardJavaFileManager#isSameFile(javax.tools.FileObject, javax.tools.FileObject)
776
	 */
716
	 */
717
	@Override
777
	public boolean isSameFile(FileObject fileObject1, FileObject fileObject2) {
718
	public boolean isSameFile(FileObject fileObject1, FileObject fileObject2) {
778
		// EclipseFileManager creates only EcliseFileObject
719
		// EclipseFileManager creates only EcliseFileObject
779
		if (!(fileObject1 instanceof EclipseFileObject)) throw new IllegalArgumentException("Unsupported file object class : " + fileObject1.getClass());//$NON-NLS-1$
720
		if (!(fileObject1 instanceof EclipseFileObject)) throw new IllegalArgumentException("Unsupported file object class : " + fileObject1.getClass());//$NON-NLS-1$
Lines 783-788 Link Here
783
	/* (non-Javadoc)
724
	/* (non-Javadoc)
784
	 * @see javax.tools.OptionChecker#isSupportedOption(java.lang.String)
725
	 * @see javax.tools.OptionChecker#isSupportedOption(java.lang.String)
785
	 */
726
	 */
727
	@Override
786
	public int isSupportedOption(String option) {
728
	public int isSupportedOption(String option) {
787
		return Options.processOptionsFileManager(option);
729
		return Options.processOptionsFileManager(option);
788
	}
730
	}
Lines 790-795 Link Here
790
	/* (non-Javadoc)
732
	/* (non-Javadoc)
791
	 * @see javax.tools.JavaFileManager#list(javax.tools.JavaFileManager.Location, java.lang.String, java.util.Set, boolean)
733
	 * @see javax.tools.JavaFileManager#list(javax.tools.JavaFileManager.Location, java.lang.String, java.util.Set, boolean)
792
	 */
734
	 */
735
	@Override
793
	public Iterable<JavaFileObject> list(Location location, String packageName, Set<Kind> kinds, boolean recurse)
736
	public Iterable<JavaFileObject> list(Location location, String packageName, Set<Kind> kinds, boolean recurse)
794
			throws IOException {
737
			throws IOException {
795
		
738
		
Lines 798-804 Link Here
798
			throw new IllegalArgumentException("Unknown location : " + location);//$NON-NLS-1$
741
			throw new IllegalArgumentException("Unknown location : " + location);//$NON-NLS-1$
799
		}
742
		}
800
		
743
		
801
		ArrayList<JavaFileObject> collector = new ArrayList<JavaFileObject>();
744
		ArrayList<JavaFileObject> collector = new ArrayList<>();
802
		String normalizedPackageName = normalized(packageName);
745
		String normalizedPackageName = normalized(packageName);
803
		for (File file : allFilesInLocations) {
746
		for (File file : allFilesInLocations) {
804
			collectAllMatchingFiles(file, normalizedPackageName, kinds, recurse, collector);
747
			collectAllMatchingFiles(file, normalizedPackageName, kinds, recurse, collector);
Lines 823-829 Link Here
823
	private Iterable<? extends File> prependFiles(Iterable<? extends File> iterable,
766
	private Iterable<? extends File> prependFiles(Iterable<? extends File> iterable,
824
			Iterable<? extends File> iterable2) {
767
			Iterable<? extends File> iterable2) {
825
		if (iterable2 == null) return iterable;
768
		if (iterable2 == null) return iterable;
826
		ArrayList<File> list = new ArrayList<File>();
769
		ArrayList<File> list = new ArrayList<>();
827
		for (Iterator<? extends File> iterator = iterable2.iterator(); iterator.hasNext(); ) {
770
		for (Iterator<? extends File> iterator = iterable2.iterator(); iterator.hasNext(); ) {
828
			list.add(iterator.next());
771
			list.add(iterator.next());
829
		}
772
		}
Lines 836-841 Link Here
836
	/* (non-Javadoc)
779
	/* (non-Javadoc)
837
	 * @see javax.tools.StandardJavaFileManager#setLocation(javax.tools.JavaFileManager.Location, java.lang.Iterable)
780
	 * @see javax.tools.StandardJavaFileManager#setLocation(javax.tools.JavaFileManager.Location, java.lang.Iterable)
838
	 */
781
	 */
782
	@Override
839
	public void setLocation(Location location, Iterable<? extends File> path) throws IOException {
783
	public void setLocation(Location location, Iterable<? extends File> path) throws IOException {
840
		if (path != null) {
784
		if (path != null) {
841
			if (location.isOutputLocation()) {
785
			if (location.isOutputLocation()) {
Lines 863-869 Link Here
863
		}
807
		}
864
	}
808
	}
865
809
866
	@SuppressWarnings({"rawtypes", "unchecked"})
810
	@SuppressWarnings({"unchecked", "rawtypes"})
867
	public void processPathEntries(final int defaultSize, final ArrayList paths,
811
	public void processPathEntries(final int defaultSize, final ArrayList paths,
868
			final String currentPath, String customEncoding, boolean isSourceOnly,
812
			final String currentPath, String customEncoding, boolean isSourceOnly,
869
			boolean rejectDestinationPathOnJars) {
813
			boolean rejectDestinationPathOnJars) {
(-)a/org.eclipse.jdt.compiler.apt/src/org/eclipse/jdt/internal/compiler/apt/util/Options.java (-131 / +175 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2006, 2007 IBM Corporation and others.
2
 * Copyright (c) 2006, 2015 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 22-90 Link Here
22
	private static final Set<String> ONE_ARGUMENT_OPTIONS;
22
	private static final Set<String> ONE_ARGUMENT_OPTIONS;
23
	private static final Set<String> FILE_MANAGER_OPTIONS;
23
	private static final Set<String> FILE_MANAGER_OPTIONS;
24
	static {
24
	static {
25
		ZERO_ARGUMENT_OPTIONS = new HashSet<String>();
25
		ZERO_ARGUMENT_OPTIONS = new HashSet<>();
26
		ZERO_ARGUMENT_OPTIONS.add("-progress");//$NON-NLS-1$
26
		Options.ZERO_ARGUMENT_OPTIONS.add("-progress");//$NON-NLS-1$
27
		ZERO_ARGUMENT_OPTIONS.add("-proceedOnError");//$NON-NLS-1$
27
		Options.ZERO_ARGUMENT_OPTIONS.add("-proceedOnError");//$NON-NLS-1$
28
		ZERO_ARGUMENT_OPTIONS.add("-time");//$NON-NLS-1$
28
		Options.ZERO_ARGUMENT_OPTIONS.add("-proceedOnError:Fatal");//$NON-NLS-1$
29
		ZERO_ARGUMENT_OPTIONS.add("-v");//$NON-NLS-1$
29
		Options.ZERO_ARGUMENT_OPTIONS.add("-time");//$NON-NLS-1$
30
		ZERO_ARGUMENT_OPTIONS.add("-version");//$NON-NLS-1$
30
		Options.ZERO_ARGUMENT_OPTIONS.add("-v");//$NON-NLS-1$
31
		ZERO_ARGUMENT_OPTIONS.add("-showversion");//$NON-NLS-1$
31
		Options.ZERO_ARGUMENT_OPTIONS.add("-version");//$NON-NLS-1$
32
		ZERO_ARGUMENT_OPTIONS.add("-deprecation");//$NON-NLS-1$
32
		Options.ZERO_ARGUMENT_OPTIONS.add("-showversion");//$NON-NLS-1$
33
		ZERO_ARGUMENT_OPTIONS.add("-help");//$NON-NLS-1$
33
		Options.ZERO_ARGUMENT_OPTIONS.add("-deprecation");//$NON-NLS-1$
34
		ZERO_ARGUMENT_OPTIONS.add("-?");//$NON-NLS-1$
34
		Options.ZERO_ARGUMENT_OPTIONS.add("-help");//$NON-NLS-1$
35
		ZERO_ARGUMENT_OPTIONS.add("-help:warn");//$NON-NLS-1$
35
		Options.ZERO_ARGUMENT_OPTIONS.add("-?");//$NON-NLS-1$
36
		ZERO_ARGUMENT_OPTIONS.add("-?:warn");//$NON-NLS-1$
36
		Options.ZERO_ARGUMENT_OPTIONS.add("-help:warn");//$NON-NLS-1$
37
		ZERO_ARGUMENT_OPTIONS.add("-noExit");//$NON-NLS-1$
37
		Options.ZERO_ARGUMENT_OPTIONS.add("-?:warn");//$NON-NLS-1$
38
		ZERO_ARGUMENT_OPTIONS.add("-verbose");//$NON-NLS-1$
38
		Options.ZERO_ARGUMENT_OPTIONS.add("-noExit");//$NON-NLS-1$
39
		ZERO_ARGUMENT_OPTIONS.add("-referenceInfo");//$NON-NLS-1$
39
		Options.ZERO_ARGUMENT_OPTIONS.add("-verbose");//$NON-NLS-1$
40
		ZERO_ARGUMENT_OPTIONS.add("-inlineJSR");//$NON-NLS-1$
40
		Options.ZERO_ARGUMENT_OPTIONS.add("-referenceInfo");//$NON-NLS-1$
41
		ZERO_ARGUMENT_OPTIONS.add("-g");//$NON-NLS-1$
41
		Options.ZERO_ARGUMENT_OPTIONS.add("-inlineJSR");//$NON-NLS-1$
42
		ZERO_ARGUMENT_OPTIONS.add("-g:none");//$NON-NLS-1$
42
		Options.ZERO_ARGUMENT_OPTIONS.add("-g");//$NON-NLS-1$
43
		ZERO_ARGUMENT_OPTIONS.add("-nowarn");//$NON-NLS-1$
43
		Options.ZERO_ARGUMENT_OPTIONS.add("-g:none");//$NON-NLS-1$
44
		ZERO_ARGUMENT_OPTIONS.add("-warn:none");//$NON-NLS-1$
44
		Options.ZERO_ARGUMENT_OPTIONS.add("-warn:none");//$NON-NLS-1$
45
		ZERO_ARGUMENT_OPTIONS.add("-preserveAllLocals");//$NON-NLS-1$
45
		Options.ZERO_ARGUMENT_OPTIONS.add("-preserveAllLocals");//$NON-NLS-1$
46
		ZERO_ARGUMENT_OPTIONS.add("-enableJavadoc");//$NON-NLS-1$
46
		Options.ZERO_ARGUMENT_OPTIONS.add("-enableJavadoc");//$NON-NLS-1$
47
		ZERO_ARGUMENT_OPTIONS.add("-Xemacs");//$NON-NLS-1$
47
		Options.ZERO_ARGUMENT_OPTIONS.add("-Xemacs");//$NON-NLS-1$
48
		ZERO_ARGUMENT_OPTIONS.add("-X");//$NON-NLS-1$
48
		Options.ZERO_ARGUMENT_OPTIONS.add("-X");//$NON-NLS-1$
49
		ZERO_ARGUMENT_OPTIONS.add("-O");//$NON-NLS-1$
49
		Options.ZERO_ARGUMENT_OPTIONS.add("-O");//$NON-NLS-1$
50
		ZERO_ARGUMENT_OPTIONS.add("-1.3");//$NON-NLS-1$
50
		Options.ZERO_ARGUMENT_OPTIONS.add("-1.3");//$NON-NLS-1$
51
		ZERO_ARGUMENT_OPTIONS.add("-1.4");//$NON-NLS-1$
51
		Options.ZERO_ARGUMENT_OPTIONS.add("-1.4");//$NON-NLS-1$
52
		ZERO_ARGUMENT_OPTIONS.add("-1.5");//$NON-NLS-1$
52
		Options.ZERO_ARGUMENT_OPTIONS.add("-1.5");//$NON-NLS-1$
53
		ZERO_ARGUMENT_OPTIONS.add("-5");//$NON-NLS-1$
53
		Options.ZERO_ARGUMENT_OPTIONS.add("-5");//$NON-NLS-1$
54
		ZERO_ARGUMENT_OPTIONS.add("-5.0");//$NON-NLS-1$
54
		Options.ZERO_ARGUMENT_OPTIONS.add("-5.0");//$NON-NLS-1$
55
		ZERO_ARGUMENT_OPTIONS.add("-1.6");//$NON-NLS-1$
55
		Options.ZERO_ARGUMENT_OPTIONS.add("-1.6");//$NON-NLS-1$
56
		ZERO_ARGUMENT_OPTIONS.add("-6");//$NON-NLS-1$
56
		Options.ZERO_ARGUMENT_OPTIONS.add("-6");//$NON-NLS-1$
57
		ZERO_ARGUMENT_OPTIONS.add("-6.0");//$NON-NLS-1$
57
		Options.ZERO_ARGUMENT_OPTIONS.add("-6.0");//$NON-NLS-1$
58
		ZERO_ARGUMENT_OPTIONS.add("-proc:only");//$NON-NLS-1$
58
		Options.ZERO_ARGUMENT_OPTIONS.add("-1.7");//$NON-NLS-1$
59
		ZERO_ARGUMENT_OPTIONS.add("-proc:none");//$NON-NLS-1$
59
		Options.ZERO_ARGUMENT_OPTIONS.add("-7");//$NON-NLS-1$
60
		ZERO_ARGUMENT_OPTIONS.add("-XprintProcessorInfo");//$NON-NLS-1$
60
		Options.ZERO_ARGUMENT_OPTIONS.add("-7.0");//$NON-NLS-1$
61
		ZERO_ARGUMENT_OPTIONS.add("-XprintRounds");//$NON-NLS-1$
61
		Options.ZERO_ARGUMENT_OPTIONS.add("-1.8");//$NON-NLS-1$
62
		Options.ZERO_ARGUMENT_OPTIONS.add("-8");//$NON-NLS-1$
63
		Options.ZERO_ARGUMENT_OPTIONS.add("-8.0");//$NON-NLS-1$
64
		Options.ZERO_ARGUMENT_OPTIONS.add("-proc:only");//$NON-NLS-1$
65
		Options.ZERO_ARGUMENT_OPTIONS.add("-proc:none");//$NON-NLS-1$
66
		Options.ZERO_ARGUMENT_OPTIONS.add("-XprintProcessorInfo");//$NON-NLS-1$
67
		Options.ZERO_ARGUMENT_OPTIONS.add("-XprintRounds");//$NON-NLS-1$
68
		Options.ZERO_ARGUMENT_OPTIONS.add("-parameters");//$NON-NLS-1$
69
		Options.ZERO_ARGUMENT_OPTIONS.add("-genericsignature");//$NON-NLS-1$
62
70
63
		FILE_MANAGER_OPTIONS = new HashSet<String>();
71
		FILE_MANAGER_OPTIONS = new HashSet<>();
64
		FILE_MANAGER_OPTIONS.add("-bootclasspath");//$NON-NLS-1$
72
		Options.FILE_MANAGER_OPTIONS.add("-bootclasspath");//$NON-NLS-1$
65
		FILE_MANAGER_OPTIONS.add("-encoding");//$NON-NLS-1$
73
		Options.FILE_MANAGER_OPTIONS.add("-encoding");//$NON-NLS-1$
66
		FILE_MANAGER_OPTIONS.add("-d");//$NON-NLS-1$
74
		Options.FILE_MANAGER_OPTIONS.add("-d");//$NON-NLS-1$
67
		FILE_MANAGER_OPTIONS.add("-classpath");//$NON-NLS-1$
75
		Options.FILE_MANAGER_OPTIONS.add("-classpath");//$NON-NLS-1$
68
		FILE_MANAGER_OPTIONS.add("-cp");//$NON-NLS-1$
76
		Options.FILE_MANAGER_OPTIONS.add("-cp");//$NON-NLS-1$
69
		FILE_MANAGER_OPTIONS.add("-sourcepath");//$NON-NLS-1$
77
		Options.FILE_MANAGER_OPTIONS.add("-sourcepath");//$NON-NLS-1$
70
		FILE_MANAGER_OPTIONS.add("-extdirs");//$NON-NLS-1$
78
		Options.FILE_MANAGER_OPTIONS.add("-extdirs");//$NON-NLS-1$
71
		FILE_MANAGER_OPTIONS.add("-endorseddirs");//$NON-NLS-1$
79
		Options.FILE_MANAGER_OPTIONS.add("-endorseddirs");//$NON-NLS-1$
72
		FILE_MANAGER_OPTIONS.add("-s");//$NON-NLS-1$
80
		Options.FILE_MANAGER_OPTIONS.add("-s");//$NON-NLS-1$
73
		FILE_MANAGER_OPTIONS.add("-processorpath");//$NON-NLS-1$
81
		Options.FILE_MANAGER_OPTIONS.add("-processorpath");//$NON-NLS-1$
74
82
75
		ONE_ARGUMENT_OPTIONS = new HashSet<String>();
83
		ONE_ARGUMENT_OPTIONS = new HashSet<>();
76
		ONE_ARGUMENT_OPTIONS.addAll(FILE_MANAGER_OPTIONS);
84
		Options.ONE_ARGUMENT_OPTIONS.addAll(Options.FILE_MANAGER_OPTIONS);
77
		ONE_ARGUMENT_OPTIONS.add("-log");//$NON-NLS-1$
85
		Options.ONE_ARGUMENT_OPTIONS.add("-log");//$NON-NLS-1$
78
		ONE_ARGUMENT_OPTIONS.add("-repeat");//$NON-NLS-1$
86
		Options.ONE_ARGUMENT_OPTIONS.add("-repeat");//$NON-NLS-1$
79
		ONE_ARGUMENT_OPTIONS.add("-maxProblems");//$NON-NLS-1$
87
		Options.ONE_ARGUMENT_OPTIONS.add("-maxProblems");//$NON-NLS-1$
80
		ONE_ARGUMENT_OPTIONS.add("-source");//$NON-NLS-1$
88
		Options.ONE_ARGUMENT_OPTIONS.add("-source");//$NON-NLS-1$
81
		ONE_ARGUMENT_OPTIONS.add("-target");//$NON-NLS-1$
89
		Options.ONE_ARGUMENT_OPTIONS.add("-target");//$NON-NLS-1$
82
		ONE_ARGUMENT_OPTIONS.add("-processor");//$NON-NLS-1$
90
		Options.ONE_ARGUMENT_OPTIONS.add("-processor");//$NON-NLS-1$
83
		ONE_ARGUMENT_OPTIONS.add("-classNames");//$NON-NLS-1$
91
		Options.ONE_ARGUMENT_OPTIONS.add("-classNames");//$NON-NLS-1$
92
		Options.ONE_ARGUMENT_OPTIONS.add("-properties");//$NON-NLS-1$
93
	
84
	}
94
	}
85
	public static int processOptionsFileManager(String option) {
95
	public static int processOptionsFileManager(String option) {
86
		if (option == null) return -1;
96
		if (option == null) return -1;
87
		if (FILE_MANAGER_OPTIONS.contains(option)) {
97
		if (Options.FILE_MANAGER_OPTIONS.contains(option)) {
88
			return 1;
98
			return 1;
89
		}
99
		}
90
		return -1;
100
		return -1;
Lines 92-101 Link Here
92
102
93
	public static int processOptions(String option) {
103
	public static int processOptions(String option) {
94
		if (option == null) return -1;
104
		if (option == null) return -1;
95
		if (ZERO_ARGUMENT_OPTIONS.contains(option)) {
105
		if (Options.ZERO_ARGUMENT_OPTIONS.contains(option)) {
96
			return 0;
106
			return 0;
97
		}
107
		}
98
		if (ONE_ARGUMENT_OPTIONS.contains(option)) {
108
		if (Options.ONE_ARGUMENT_OPTIONS.contains(option)) {
99
			return 1;
109
			return 1;
100
		}
110
		}
101
		if (option.startsWith("-g")) { //$NON-NLS-1$
111
		if (option.startsWith("-g")) { //$NON-NLS-1$
Lines 138-223 Link Here
138
			while (tokenizer.hasMoreTokens()) {
148
			while (tokenizer.hasMoreTokens()) {
139
				String token = tokenizer.nextToken();
149
				String token = tokenizer.nextToken();
140
				tokenCounter++;
150
				tokenCounter++;
141
				if ("constructorName".equals(token)//$NON-NLS-1$
151
				if (token.equals("allDeadCode")//$NON-NLS-1$
142
						|| token.equals("pkgDefaultMethod")//$NON-NLS-1$
152
						|| token.equals("allDeprecation")//$NON-NLS-1$
143
						|| token.equals("packageDefaultMethod")//$NON-NLS-1$
153
						|| token.equals("allJavadoc")//$NON-NLS-1$
154
						|| token.equals("allOver-ann")//$NON-NLS-1$
155
						|| token.equals("assertIdentifier")//$NON-NLS-1$
156
						|| token.equals("boxing")//$NON-NLS-1$
157
						|| token.equals("charConcat")//$NON-NLS-1$
158
						|| token.equals("compareIdentical")//$NON-NLS-1$
159
						|| token.equals("conditionAssign")//$NON-NLS-1$
160
						|| token.equals("constructorName")//$NON-NLS-1$
161
						|| token.equals("deadCode")//$NON-NLS-1$
162
						|| token.equals("dep-ann")//$NON-NLS-1$
163
						|| token.equals("deprecation")//$NON-NLS-1$
164
						|| token.equals("discouraged")//$NON-NLS-1$
165
						|| token.equals("emptyBlock")//$NON-NLS-1$
166
						|| token.equals("enumIdentifier")//$NON-NLS-1$
167
						|| token.equals("enumSwitch")//$NON-NLS-1$
168
						|| token.equals("fallthrough")//$NON-NLS-1$
169
						|| token.equals("fieldHiding")//$NON-NLS-1$
170
						|| token.equals("finalBound")//$NON-NLS-1$
171
						|| token.equals("finally")//$NON-NLS-1$
172
						|| token.equals("forbidden")//$NON-NLS-1$
173
						|| token.equals("hashCode")//$NON-NLS-1$
174
						|| token.equals("hiding")//$NON-NLS-1$
175
						|| token.equals("includeAssertNull")//$NON-NLS-1$
176
						|| token.equals("incomplete-switch")//$NON-NLS-1$
177
						|| token.equals("indirectStatic")//$NON-NLS-1$
178
						|| token.equals("interfaceNonInherited")//$NON-NLS-1$
179
						|| token.equals("intfAnnotation")//$NON-NLS-1$
180
						|| token.equals("intfNonInherited")//$NON-NLS-1$
181
						|| token.equals("intfRedundant")//$NON-NLS-1$
182
						|| token.equals("javadoc")//$NON-NLS-1$
183
						|| token.equals("localHiding")//$NON-NLS-1$
144
						|| token.equals("maskedCatchBlock")//$NON-NLS-1$
184
						|| token.equals("maskedCatchBlock")//$NON-NLS-1$
145
						|| token.equals("maskedCatchBlocks")//$NON-NLS-1$
185
						|| token.equals("maskedCatchBlocks")//$NON-NLS-1$
146
						|| token.equals("deprecation")//$NON-NLS-1$
186
						|| token.equals("nls")//$NON-NLS-1$
147
						|| token.equals("allDeprecation")//$NON-NLS-1$
187
						|| token.equals("noEffectAssign")//$NON-NLS-1$
148
						|| token.equals("unusedLocal")//$NON-NLS-1$
188
						|| token.equals("noImplicitStringConversion")//$NON-NLS-1$
149
						|| token.equals("unusedLocals")//$NON-NLS-1$
189
						|| token.equals("null")//$NON-NLS-1$
190
						|| token.equals("nullDereference")//$NON-NLS-1$
191
						|| token.equals("over-ann")//$NON-NLS-1$
192
						|| token.equals("packageDefaultMethod")//$NON-NLS-1$
193
						|| token.equals("paramAssign")//$NON-NLS-1$
194
						|| token.equals("pkgDefaultMethod")//$NON-NLS-1$
195
						|| token.equals("raw")//$NON-NLS-1$
196
						|| token.equals("semicolon")//$NON-NLS-1$
197
						|| token.equals("serial")//$NON-NLS-1$
198
						|| token.equals("specialParamHiding")//$NON-NLS-1$
199
						|| token.equals("static-access")//$NON-NLS-1$
200
						|| token.equals("staticReceiver")//$NON-NLS-1$
201
						|| token.equals("super")//$NON-NLS-1$
202
						|| token.equals("suppress")//$NON-NLS-1$
203
						|| token.equals("syncOverride")//$NON-NLS-1$
204
						|| token.equals("synthetic-access")//$NON-NLS-1$
205
						|| token.equals("syntheticAccess")//$NON-NLS-1$
206
						|| token.equals("typeHiding")//$NON-NLS-1$
207
						|| token.equals("unchecked")//$NON-NLS-1$
208
						|| token.equals("unnecessaryElse")//$NON-NLS-1$
209
						|| token.equals("unnecessaryOperator")//$NON-NLS-1$
210
						|| token.equals("unqualified-field-access")//$NON-NLS-1$
211
						|| token.equals("unqualifiedField")//$NON-NLS-1$
212
						|| token.equals("unsafe")//$NON-NLS-1$
213
						|| token.equals("unused")//$NON-NLS-1$
150
						|| token.equals("unusedArgument")//$NON-NLS-1$
214
						|| token.equals("unusedArgument")//$NON-NLS-1$
151
						|| token.equals("unusedArguments")//$NON-NLS-1$
215
						|| token.equals("unusedArguments")//$NON-NLS-1$
152
						|| token.equals("unusedImport")//$NON-NLS-1$
216
						|| token.equals("unusedImport")//$NON-NLS-1$
153
						|| token.equals("unusedImports")//$NON-NLS-1$
217
						|| token.equals("unusedImports")//$NON-NLS-1$
154
						|| token.equals("unusedPrivate")//$NON-NLS-1$
155
						|| token.equals("unusedLabel")//$NON-NLS-1$
218
						|| token.equals("unusedLabel")//$NON-NLS-1$
156
						|| token.equals("localHiding")//$NON-NLS-1$
219
						|| token.equals("unusedLocal")//$NON-NLS-1$
157
						|| token.equals("fieldHiding")//$NON-NLS-1$
220
						|| token.equals("unusedLocals")//$NON-NLS-1$
158
						|| token.equals("specialParamHiding")//$NON-NLS-1$
221
						|| token.equals("unusedPrivate")//$NON-NLS-1$
159
						|| token.equals("conditionAssign")//$NON-NLS-1$
160
						|| token.equals("syntheticAccess")//$NON-NLS-1$
161
						|| token.equals("synthetic-access")//$NON-NLS-1$
162
						|| token.equals("nls")//$NON-NLS-1$
163
						|| token.equals("staticReceiver")//$NON-NLS-1$
164
						|| token.equals("indirectStatic")//$NON-NLS-1$
165
						|| token.equals("noEffectAssign")//$NON-NLS-1$
166
						|| token.equals("intfNonInherited")//$NON-NLS-1$
167
						|| token.equals("interfaceNonInherited")//$NON-NLS-1$
168
						|| token.equals("charConcat")//$NON-NLS-1$
169
						|| token.equals("noImplicitStringConversion")//$NON-NLS-1$
170
						|| token.equals("semicolon")//$NON-NLS-1$
171
						|| token.equals("serial")//$NON-NLS-1$
172
						|| token.equals("emptyBlock")//$NON-NLS-1$
173
						|| token.equals("uselessTypeCheck")//$NON-NLS-1$
174
						|| token.equals("unchecked")//$NON-NLS-1$
175
						|| token.equals("unsafe")//$NON-NLS-1$
176
						|| token.equals("raw")//$NON-NLS-1$
177
						|| token.equals("finalBound")//$NON-NLS-1$
178
						|| token.equals("suppress")//$NON-NLS-1$
179
						|| token.equals("warningToken")//$NON-NLS-1$
180
						|| token.equals("unnecessaryElse")//$NON-NLS-1$
181
						|| token.equals("javadoc")//$NON-NLS-1$
182
						|| token.equals("allJavadoc")//$NON-NLS-1$
183
						|| token.equals("assertIdentifier")//$NON-NLS-1$
184
						|| token.equals("enumIdentifier")//$NON-NLS-1$
185
						|| token.equals("finally")//$NON-NLS-1$
186
						|| token.equals("unusedThrown")//$NON-NLS-1$
222
						|| token.equals("unusedThrown")//$NON-NLS-1$
187
						|| token.equals("unqualifiedField")//$NON-NLS-1$
223
						|| token.equals("unusedTypeArgs")//$NON-NLS-1$
188
						|| token.equals("unqualified-field-access")//$NON-NLS-1$
224
						|| token.equals("uselessTypeCheck")//$NON-NLS-1$
189
						|| token.equals("typeHiding")//$NON-NLS-1$
190
						|| token.equals("varargsCast")//$NON-NLS-1$
225
						|| token.equals("varargsCast")//$NON-NLS-1$
191
						|| token.equals("null")//$NON-NLS-1$
226
						|| token.equals("warningToken")) {//$NON-NLS-1$
192
						|| token.equals("boxing")//$NON-NLS-1$
193
						|| token.equals("over-ann")//$NON-NLS-1$
194
						|| token.equals("dep-ann")//$NON-NLS-1$
195
						|| token.equals("intfAnnotation")//$NON-NLS-1$
196
						|| token.equals("enumSwitch")//$NON-NLS-1$
197
						|| token.equals("incomplete-switch")//$NON-NLS-1$
198
						|| token.equals("hiding")//$NON-NLS-1$
199
						|| token.equals("static-access")//$NON-NLS-1$
200
						|| token.equals("unused")//$NON-NLS-1$
201
						|| token.equals("paramAssign")//$NON-NLS-1$
202
						|| token.equals("discouraged")//$NON-NLS-1$
203
						|| token.equals("forbidden")//$NON-NLS-1$
204
						|| token.equals("fallthrough")) {//$NON-NLS-1$
205
					continue;
227
					continue;
206
    			} else if (token.equals("tasks")) {//$NON-NLS-1$
228
				} else if (token.equals("tasks")) {//$NON-NLS-1$
207
    				String taskTags = "";//$NON-NLS-1$
229
					String taskTags = "";//$NON-NLS-1$
208
    				int start = token.indexOf('(');
230
					int start = token.indexOf('(');
209
    				int end = token.indexOf(')');
231
					int end = token.indexOf(')');
210
    				if (start >= 0 && end >= 0 && start < end){
232
					if (start >= 0 && end >= 0 && start < end){
211
    					taskTags = token.substring(start+1, end).trim();
233
						taskTags = token.substring(start+1, end).trim();
212
    					taskTags = taskTags.replace('|',',');
234
						taskTags = taskTags.replace('|',',');
213
    				}
235
					}
214
    				if (taskTags.length() == 0){
236
					if (taskTags.length() == 0){
215
    					return -1;
237
						return -1;
216
    				}
238
					}
217
    				continue;
239
					continue;
218
    			} else {
240
				} else {
219
    				return -1;
241
					return -1;
220
    			}
242
				}
221
			}
243
			}
222
			if (tokenCounter == 0) {
244
			if (tokenCounter == 0) {
223
				return -1;
245
				return -1;
Lines 225-230 Link Here
225
				return 0;
247
				return 0;
226
			}
248
			}
227
		}
249
		}
250
		if (option.startsWith("-nowarn")) {//$NON-NLS-1$
251
			switch (option.length()) {
252
				case 7:
253
					return 0;
254
				case 8:
255
					return -1;
256
				default:
257
					int foldersStart = option.indexOf('[') + 1;
258
					int foldersEnd = option.lastIndexOf(']');
259
					if (foldersStart <= 8 || foldersEnd == -1
260
							|| foldersStart > foldersEnd
261
							|| foldersEnd < option.length() - 1) {
262
						return -1;
263
					}
264
					String folders = option.substring(foldersStart, foldersEnd);
265
					if (folders.length() > 0) {
266
						return 0;
267
					} else {
268
						return -1;
269
					}
270
			}
271
		}
228
		if (option.startsWith("-J")//$NON-NLS-1$
272
		if (option.startsWith("-J")//$NON-NLS-1$
229
				|| option.startsWith("-X")//$NON-NLS-1$
273
				|| option.startsWith("-X")//$NON-NLS-1$
230
				|| option.startsWith("-A")) {//$NON-NLS-1$
274
				|| option.startsWith("-A")) {//$NON-NLS-1$
(-)a/org.eclipse.jdt.compiler.apt/src/org/eclipse/jdt/internal/compiler/apt/util/Util.java (-15 / +15 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2006, 2007 IBM Corporation and others.
2
 * Copyright (c) 2006, 2015 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 38-44 Link Here
38
			this.position = position;
38
			this.position = position;
39
			this.length = length;
39
			this.length = length;
40
		}
40
		}
41
		
41
42
		public String getSource(char[] unitSource) {
42
		public String getSource(char[] unitSource) {
43
			//extra from the source the innacurate     token
43
			//extra from the source the innacurate     token
44
			//and "highlight" it using some underneath ^^^^^
44
			//and "highlight" it using some underneath ^^^^^
Lines 49-55 Link Here
49
			//sanity .....
49
			//sanity .....
50
			int startPosition = this.position;
50
			int startPosition = this.position;
51
			int endPosition = this.position + this.length - 1;
51
			int endPosition = this.position + this.length - 1;
52
			
52
53
			if ((startPosition > endPosition)
53
			if ((startPosition > endPosition)
54
				|| ((startPosition < 0) && (endPosition < 0))
54
				|| ((startPosition < 0) && (endPosition < 0))
55
				|| unitSource.length == 0)
55
				|| unitSource.length == 0)
Lines 57-85 Link Here
57
57
58
			StringBuffer errorBuffer = new StringBuffer();
58
			StringBuffer errorBuffer = new StringBuffer();
59
			errorBuffer.append('\t');
59
			errorBuffer.append('\t');
60
			
60
61
			char c;
61
			char c;
62
			final char SPACE = ' ';
62
			final char SPACE = ' ';
63
			final char MARK = '^';
63
			final char MARK = '^';
64
			final char TAB = '\t';
64
			final char TAB = '\t';
65
			//the next code tries to underline the token.....
65
			//the next code tries to underline the token.....
66
			//it assumes (for a good display) that token source does not
66
			//it assumes (for a good display) that token source does not
67
			//contain any \r \n. This is false on statements ! 
67
			//contain any \r \n. This is false on statements !
68
			//(the code still works but the display is not optimal !)
68
			//(the code still works but the display is not optimal !)
69
69
70
			// expand to line limits
70
			// expand to line limits
71
			int length = unitSource.length, begin, end;
71
			int sourceLength = unitSource.length, begin, end;
72
			for (begin = startPosition >= length ? length - 1 : startPosition; begin > 0; begin--) {
72
			for (begin = startPosition >= sourceLength ? sourceLength - 1 : startPosition; begin > 0; begin--) {
73
				if ((c = unitSource[begin - 1]) == '\n' || c == '\r') break;
73
				if ((c = unitSource[begin - 1]) == '\n' || c == '\r') break;
74
			}
74
			}
75
			for (end = endPosition >= length ? length - 1 : endPosition ; end+1 < length; end++) {
75
			for (end = endPosition >= sourceLength ? sourceLength - 1 : endPosition ; end+1 < sourceLength; end++) {
76
				if ((c = unitSource[end + 1]) == '\r' || c == '\n') break;
76
				if ((c = unitSource[end + 1]) == '\r' || c == '\n') break;
77
			}
77
			}
78
			
78
79
			// trim left and right spaces/tabs
79
			// trim left and right spaces/tabs
80
			while ((c = unitSource[begin]) == ' ' || c == '\t') begin++;
80
			while ((c = unitSource[begin]) == ' ' || c == '\t') begin++;
81
			//while ((c = unitSource[end]) == ' ' || c == '\t') end--; TODO (philippe) should also trim right, but all tests are to be updated
81
			//while ((c = unitSource[end]) == ' ' || c == '\t') end--; TODO (philippe) should also trim right, but all tests are to be updated
82
			
82
83
			// copy source
83
			// copy source
84
			errorBuffer.append(unitSource, begin, end-begin+1);
84
			errorBuffer.append(unitSource, begin, end-begin+1);
85
			errorBuffer.append(Util.LINE_SEPARATOR).append("\t"); //$NON-NLS-1$
85
			errorBuffer.append(Util.LINE_SEPARATOR).append("\t"); //$NON-NLS-1$
Lines 88-104 Link Here
88
			for (int i = begin; i <startPosition; i++) {
88
			for (int i = begin; i <startPosition; i++) {
89
				errorBuffer.append((unitSource[i] == TAB) ? TAB : SPACE);
89
				errorBuffer.append((unitSource[i] == TAB) ? TAB : SPACE);
90
			}
90
			}
91
			for (int i = startPosition; i <= (endPosition >= length ? length - 1 : endPosition); i++) {
91
			for (int i = startPosition; i <= (endPosition >= sourceLength ? sourceLength - 1 : endPosition); i++) {
92
				errorBuffer.append(MARK);
92
				errorBuffer.append(MARK);
93
			}
93
			}
94
			return errorBuffer.toString();
94
			return errorBuffer.toString();
95
		}
95
		}
96
	}
96
	}
97
	public static class EncodingErrorCollector {
97
	public static class EncodingErrorCollector {
98
		ArrayList<EncodingError> encodingErrors = new ArrayList<EncodingError>();
98
		ArrayList<EncodingError> encodingErrors = new ArrayList<>();
99
		FileObject fileObject;
99
		FileObject fileObject;
100
		String encoding;
100
		String encoding;
101
		
101
102
		public EncodingErrorCollector(FileObject fileObject, String encoding) {
102
		public EncodingErrorCollector(FileObject fileObject, String encoding) {
103
			this.fileObject = fileObject;
103
			this.fileObject = fileObject;
104
			this.encoding = encoding;
104
			this.encoding = encoding;
Lines 135-141 Link Here
135
		byteBuffer.flip();
135
		byteBuffer.flip();
136
		return charsetDecoder.decode(byteBuffer).array();
136
		return charsetDecoder.decode(byteBuffer).array();
137
	}
137
	}
138
	
138
139
	public static CharSequence getCharContents(FileObject fileObject, boolean ignoreEncodingErrors, byte[] contents, String encoding) throws IOException {
139
	public static CharSequence getCharContents(FileObject fileObject, boolean ignoreEncodingErrors, byte[] contents, String encoding) throws IOException {
140
		if (contents == null) return null;
140
		if (contents == null) return null;
141
		Charset charset = null;
141
		Charset charset = null;
Lines 199-205 Link Here
199
			return out;
199
			return out;
200
		}
200
		}
201
	}
201
	}
202
	
202
203
	private static void reportEncodingError(EncodingErrorCollector collector, int position, int length) {
203
	private static void reportEncodingError(EncodingErrorCollector collector, int position, int length) {
204
		collector.collect(position, -length);
204
		collector.collect(position, -length);
205
	}
205
	}
(-)a/org.eclipse.jdt.compiler.tool.tests/src/org/eclipse/jdt/compiler/tool/tests/AllTests.java (-1 / +1 lines)
Added Link Here
21
	// run all tests
21
	// run all tests
22
	public static Test suite() {
22
	public static Test suite() {
23
		TestSuite suite = new TestSuite();
23
		TestSuite suite = new TestSuite();
24
		suite.addTest(CompilerToolTests.suite());
24
		suite.addTestSuite(CompilerToolTests.class);
25
		suite.addTest(CompilerInvocationTests.suite());
25
		suite.addTest(CompilerInvocationTests.suite());
26
		return suite;
26
		return suite;
27
	}
27
	}
(-)a/org.eclipse.jdt.compiler.tool.tests/src/org/eclipse/jdt/compiler/tool/tests/CompilerToolTests.java (-59 / +81 lines)
Lines 33-48 Link Here
33
import javax.tools.FileObject;
33
import javax.tools.FileObject;
34
import javax.tools.ForwardingJavaFileManager;
34
import javax.tools.ForwardingJavaFileManager;
35
import javax.tools.JavaCompiler;
35
import javax.tools.JavaCompiler;
36
import javax.tools.JavaCompiler.CompilationTask;
36
import javax.tools.JavaFileManager;
37
import javax.tools.JavaFileManager;
37
import javax.tools.JavaFileObject;
38
import javax.tools.JavaFileObject;
39
import javax.tools.JavaFileObject.Kind;
38
import javax.tools.StandardJavaFileManager;
40
import javax.tools.StandardJavaFileManager;
39
import javax.tools.StandardLocation;
41
import javax.tools.StandardLocation;
40
import javax.tools.ToolProvider;
42
import javax.tools.ToolProvider;
41
import javax.tools.JavaCompiler.CompilationTask;
42
import javax.tools.JavaFileObject.Kind;
43
43
44
import junit.framework.TestCase;
44
import junit.framework.TestCase;
45
import junit.framework.TestSuite;
46
45
47
import org.eclipse.jdt.compiler.tool.tests.AbstractCompilerToolTest.CompilerInvocationDiagnosticListener;
46
import org.eclipse.jdt.compiler.tool.tests.AbstractCompilerToolTest.CompilerInvocationDiagnosticListener;
48
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
47
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
Lines 56-82 Link Here
56
	public CompilerToolTests(String name) {
55
	public CompilerToolTests(String name) {
57
		super(name);
56
		super(name);
58
	}
57
	}
59
	public static TestSuite suite() {
60
		TestSuite suite = new TestSuite();
61
		suite.addTest(new CompilerToolTests("testInitializeJavaCompiler"));
62
		suite.addTest(new CompilerToolTests("testFileManager"));
63
		suite.addTest(new CompilerToolTests("testFileManager2"));
64
		suite.addTest(new CompilerToolTests("testInferBinaryName"));
65
		suite.addTest(new CompilerToolTests("testCheckOptions"));
66
		suite.addTest(new CompilerToolTests("testCompilerOneClassWithSystemCompiler"));
67
//		suite.addTest(new CompilerToolTests("testCompilerOneClassWithSystemCompiler2"));
68
		suite.addTest(new CompilerToolTests("testCompilerOneClassWithEclipseCompiler"));
69
		suite.addTest(new CompilerToolTests("testCompilerOneClassWithEclipseCompiler2"));
70
		suite.addTest(new CompilerToolTests("testCompilerOneClassWithEclipseCompiler3"));
71
		suite.addTest(new CompilerToolTests("testCompilerOneClassWithEclipseCompiler4"));
72
		suite.addTest(new CompilerToolTests("testCompilerOneClassWithEclipseCompiler5"));
73
		suite.addTest(new CompilerToolTests("testCompilerOneClassWithEclipseCompiler6"));
74
		suite.addTest(new CompilerToolTests("testCompilerOneClassWithEclipseCompiler7"));
75
		suite.addTest(new CompilerToolTests("testCleanUp"));
76
		return suite;
77
	}
78
58
79
	private static JavaCompiler Compiler;
59
	private JavaCompiler compiler;
80
	static final String[] ONE_ARG_OPTIONS = {
60
	static final String[] ONE_ARG_OPTIONS = {
81
		"-cp",
61
		"-cp",
82
		"-classpath",
62
		"-classpath",
Lines 102-107 Link Here
102
		"-1.5",
82
		"-1.5",
103
		"-1.6",
83
		"-1.6",
104
		"-1.7",
84
		"-1.7",
85
		"-1.8",
86
		"-8",
87
		"-8.0",
105
		"-7",
88
		"-7",
106
		"-7.0",
89
		"-7.0",
107
		"-6",
90
		"-6",
Lines 160-190 Link Here
160
		}
143
		}
161
	}
144
	}
162
145
163
	/*
146
	@Override
164
	 * Initialize the compiler for all the tests
147
	protected void setUp() throws Exception {
165
	 */
166
	public void testInitializeJavaCompiler() {
167
		ServiceLoader<JavaCompiler> javaCompilerLoader = ServiceLoader.load(JavaCompiler.class);//, EclipseCompiler.class.getClassLoader());
148
		ServiceLoader<JavaCompiler> javaCompilerLoader = ServiceLoader.load(JavaCompiler.class);//, EclipseCompiler.class.getClassLoader());
168
		int compilerCounter = 0;
149
		int compilerCounter = 0;
169
		for (JavaCompiler javaCompiler : javaCompilerLoader) {
150
		for (JavaCompiler javaCompiler : javaCompilerLoader) {
170
			compilerCounter++;
151
			compilerCounter++;
171
			if (javaCompiler instanceof EclipseCompiler) {
152
			if (javaCompiler instanceof EclipseCompiler) {
172
				Compiler = javaCompiler;
153
				compiler = javaCompiler;
173
			}
154
			}
174
		}
155
		}
175
		assertEquals("Only one compiler available", 1, compilerCounter);
156
		assertEquals("Only one compiler available", 1, compilerCounter);
176
	}
157
	}
177
158
159
	@Override
160
	protected void tearDown() throws Exception {
161
		compiler = null;
162
	}
163
178
	public void testCheckOptions() {
164
	public void testCheckOptions() {
179
		assertNotNull("No compiler found", Compiler);
165
		assertNotNull("No compiler found", compiler);
180
		for (String option : ONE_ARG_OPTIONS) {
166
		for (String option : ONE_ARG_OPTIONS) {
181
			assertEquals(option + " requires 1 argument", 1, Compiler.isSupportedOption(option));
167
			assertEquals(option + " requires 1 argument", 1, compiler.isSupportedOption(option));
182
		}
168
		}
183
		for (String option : ZERO_ARG_OPTIONS) {
169
		for (String option : ZERO_ARG_OPTIONS) {
184
			assertEquals(option + " requires no argument", 0, Compiler.isSupportedOption(option));
170
			assertEquals(option + " requires no argument", 0, compiler.isSupportedOption(option));
185
		}
171
		}
186
		for (String option : FAKE_ZERO_ARG_OPTIONS) {
172
		for (String option : FAKE_ZERO_ARG_OPTIONS) {
187
			assertEquals(option + " requires no argument", 0, Compiler.isSupportedOption(option));
173
			assertEquals(option + " requires no argument", 0, compiler.isSupportedOption(option));
188
		}
174
		}
189
	}
175
	}
190
176
Lines 218-224 Link Here
218
		// System compiler
204
		// System compiler
219
		StandardJavaFileManager manager = systemCompiler.getStandardFileManager(null, Locale.getDefault(), Charset.defaultCharset());
205
		StandardJavaFileManager manager = systemCompiler.getStandardFileManager(null, Locale.getDefault(), Charset.defaultCharset());
220
206
221
		ForwardingJavaFileManager<StandardJavaFileManager> forwardingJavaFileManager = new ForwardingJavaFileManager<StandardJavaFileManager>(manager) {
207
		ForwardingJavaFileManager<JavaFileManager> forwardingJavaFileManager = new ForwardingJavaFileManager<JavaFileManager>(manager) {
222
			@Override
208
			@Override
223
			public FileObject getFileForInput(Location location, String packageName, String relativeName)
209
			public FileObject getFileForInput(Location location, String packageName, String relativeName)
224
					throws IOException {
210
					throws IOException {
Lines 277-283 Link Here
277
	 * Run the system compiler using the Eclipse java file manager
263
	 * Run the system compiler using the Eclipse java file manager
278
	 * TODO need to investigate why rt.jar gets removed from the PLATFORM_CLASSPATH location
264
	 * TODO need to investigate why rt.jar gets removed from the PLATFORM_CLASSPATH location
279
	 */
265
	 */
280
	public void _testCompilerOneClassWithSystemCompiler2() {
266
	public void testCompilerOneClassWithSystemCompiler2() {
281
		// System compiler
267
		// System compiler
282
		JavaCompiler systemCompiler = ToolProvider.getSystemJavaCompiler();
268
		JavaCompiler systemCompiler = ToolProvider.getSystemJavaCompiler();
283
		if (systemCompiler == null) {
269
		if (systemCompiler == null) {
Lines 305-314 Link Here
305
				}
291
				}
306
			}
292
			}
307
		}
293
		}
308
		StandardJavaFileManager manager = Compiler.getStandardFileManager(null, Locale.getDefault(), Charset.defaultCharset());
294
		StandardJavaFileManager manager = compiler.getStandardFileManager(null, Locale.getDefault(), Charset.defaultCharset());
309
295
310
		@SuppressWarnings("resource")
296
		ForwardingJavaFileManager<JavaFileManager> forwardingJavaFileManager = new ForwardingJavaFileManager<JavaFileManager>(manager) {
311
		ForwardingJavaFileManager<StandardJavaFileManager> forwardingJavaFileManager = new ForwardingJavaFileManager<StandardJavaFileManager>(manager) {
312
			@Override
297
			@Override
313
			public FileObject getFileForInput(Location location, String packageName, String relativeName)
298
			public FileObject getFileForInput(Location location, String packageName, String relativeName)
314
					throws IOException {
299
					throws IOException {
Lines 340-347 Link Here
340
				}
325
				}
341
				return javaFileForOutput;
326
				return javaFileForOutput;
342
			}
327
			}
328
			@Override
329
			public String inferBinaryName(Location location, JavaFileObject file) {
330
				String binaryName = super.inferBinaryName(location, file);
331
				if (DEBUG) {
332
					System.out.println("binary name: " + binaryName);
333
				}
334
				return binaryName;
335
			}
336
			@Override
337
			public Iterable<JavaFileObject> list(Location location, String packageName, Set<Kind> kinds, boolean recurse)
338
					throws IOException {
339
				Iterable<JavaFileObject> list = super.list(location, packageName, kinds, recurse);
340
				if (DEBUG) {
341
					System.out.println("start list: ");
342
					for (JavaFileObject fileObject : list) {
343
						System.out.println(fileObject.getName());
344
					}
345
					System.out.println("end   list: ");
346
				}
347
				return list;
348
			}
343
		};
349
		};
344
		// create new list containing inputfile
350
		// create new list containing input file
345
		List<File> files = new ArrayList<File>();
351
		List<File> files = new ArrayList<File>();
346
		files.add(inputFile);
352
		files.add(inputFile);
347
		Iterable<? extends JavaFileObject> units = manager.getJavaFileObjectsFromFiles(files);
353
		Iterable<? extends JavaFileObject> units = manager.getJavaFileObjectsFromFiles(files);
Lines 351-357 Link Here
351
		List<String> options = new ArrayList<String>();
357
		List<String> options = new ArrayList<String>();
352
		options.add("-d");
358
		options.add("-d");
353
		options.add(tmpFolder);
359
		options.add(tmpFolder);
354
		CompilationTask task = systemCompiler.getTask(printWriter, manager, null, options, null, units);
360
		CompilationTask task = systemCompiler.getTask(printWriter, forwardingJavaFileManager, null, options, null, units);
355
361
356
		if (DEBUG) {
362
		if (DEBUG) {
357
			System.out.println("Has location CLASS_OUPUT : " + forwardingJavaFileManager.hasLocation(StandardLocation.CLASS_OUTPUT));
363
			System.out.println("Has location CLASS_OUPUT : " + forwardingJavaFileManager.hasLocation(StandardLocation.CLASS_OUTPUT));
Lines 392-400 Link Here
392
			}
398
			}
393
		}
399
		}
394
		// System compiler
400
		// System compiler
395
		StandardJavaFileManager manager = Compiler.getStandardFileManager(null, Locale.getDefault(), Charset.defaultCharset());
401
		StandardJavaFileManager manager = compiler.getStandardFileManager(null, Locale.getDefault(), Charset.defaultCharset());
396
402
397
		ForwardingJavaFileManager<StandardJavaFileManager> forwardingJavaFileManager = new ForwardingJavaFileManager<StandardJavaFileManager>(manager) {
403
		ForwardingJavaFileManager<StandardJavaFileManager> forwardingJavaFileManager = new ForwardingJavaFileManager<StandardJavaFileManager>(manager) {
404
			@Override
405
			public FileObject getFileForInput(Location location, String packageName, String relativeName)
406
					throws IOException {
407
				if (DEBUG) {
408
					System.out.println("Create file for input : " + packageName + " " + relativeName + " in location " + location);
409
				}
410
				return super.getFileForInput(location, packageName, relativeName);
411
			}
412
			@Override
413
			public JavaFileObject getJavaFileForInput(Location location, String className, Kind kind)
414
					throws IOException {
415
				if (DEBUG) {
416
					System.out.println("Create java file for input : " + className + " in location " + location);
417
				}
418
				return super.getJavaFileForInput(location, className, kind);
419
			}
398
			@Override
420
			@Override
399
			public JavaFileObject getJavaFileForOutput(Location location,
421
			public JavaFileObject getJavaFileForOutput(Location location,
400
					String className,
422
					String className,
Lines 402-408 Link Here
402
					FileObject sibling) throws IOException {
424
					FileObject sibling) throws IOException {
403
425
404
				if (DEBUG) {
426
				if (DEBUG) {
405
					System.out.println("EC: Create .class file for " + className + " in location " + location + " with sibling " + sibling.toUri());
427
					System.out.println("Create .class file for " + className + " in location " + location + " with sibling " + sibling.toUri());
406
				}
428
				}
407
				JavaFileObject javaFileForOutput = super.getJavaFileForOutput(location, className, kind, sibling);
429
				JavaFileObject javaFileForOutput = super.getJavaFileForOutput(location, className, kind, sibling);
408
				if (DEBUG) {
430
				if (DEBUG) {
Lines 411-417 Link Here
411
				return javaFileForOutput;
433
				return javaFileForOutput;
412
			}
434
			}
413
		};
435
		};
414
		// create new list containing inputfile
436
		// create new list containing input file
415
		List<File> files = new ArrayList<File>();
437
		List<File> files = new ArrayList<File>();
416
		files.add(inputFile);
438
		files.add(inputFile);
417
		Iterable<? extends JavaFileObject> units = manager.getJavaFileObjectsFromFiles(files);
439
		Iterable<? extends JavaFileObject> units = manager.getJavaFileObjectsFromFiles(files);
Lines 421-427 Link Here
421
		List<String> options = new ArrayList<String>();
443
		List<String> options = new ArrayList<String>();
422
		options.add("-d");
444
		options.add("-d");
423
		options.add(tmpFolder);
445
		options.add(tmpFolder);
424
 		CompilationTask task = Compiler.getTask(printWriter, forwardingJavaFileManager, null, options, null, units);
446
 		CompilationTask task = compiler.getTask(printWriter, forwardingJavaFileManager, null, options, null, units);
425
 		// check the classpath location
447
 		// check the classpath location
426
 		assertTrue("Has no location CLASS_OUPUT", forwardingJavaFileManager.hasLocation(StandardLocation.CLASS_OUTPUT));
448
 		assertTrue("Has no location CLASS_OUPUT", forwardingJavaFileManager.hasLocation(StandardLocation.CLASS_OUTPUT));
427
		Boolean result = task.call();
449
		Boolean result = task.call();
Lines 468-474 Link Here
468
			}
490
			}
469
		}
491
		}
470
		// System compiler
492
		// System compiler
471
		StandardJavaFileManager manager = Compiler.getStandardFileManager(null, Locale.getDefault(), Charset.defaultCharset());
493
		StandardJavaFileManager manager = compiler.getStandardFileManager(null, Locale.getDefault(), Charset.defaultCharset());
472
494
473
		ForwardingJavaFileManager<StandardJavaFileManager> forwardingJavaFileManager = new ForwardingJavaFileManager<StandardJavaFileManager>(manager) {
495
		ForwardingJavaFileManager<StandardJavaFileManager> forwardingJavaFileManager = new ForwardingJavaFileManager<StandardJavaFileManager>(manager) {
474
			@Override
496
			@Override
Lines 498-504 Link Here
498
		options.add("-d");
520
		options.add("-d");
499
		options.add(tmpFolder);
521
		options.add(tmpFolder);
500
		options.add("-1.5");
522
		options.add("-1.5");
501
 		CompilationTask task = Compiler.getTask(printWriter, forwardingJavaFileManager, null, options, null, units);
523
 		CompilationTask task = compiler.getTask(printWriter, forwardingJavaFileManager, null, options, null, units);
502
 		// check the classpath location
524
 		// check the classpath location
503
 		assertTrue("Has no location CLASS_OUPUT", forwardingJavaFileManager.hasLocation(StandardLocation.CLASS_OUTPUT));
525
 		assertTrue("Has no location CLASS_OUPUT", forwardingJavaFileManager.hasLocation(StandardLocation.CLASS_OUTPUT));
504
		Boolean result = task.call();
526
		Boolean result = task.call();
Lines 523-529 Link Here
523
545
524
		stringWriter = new StringWriter();
546
		stringWriter = new StringWriter();
525
		printWriter = new PrintWriter(stringWriter);
547
		printWriter = new PrintWriter(stringWriter);
526
		task = Compiler.getTask(printWriter, forwardingJavaFileManager, null, options, null, units);
548
		task = compiler.getTask(printWriter, forwardingJavaFileManager, null, options, null, units);
527
		// check the classpath location
549
		// check the classpath location
528
		assertTrue("Has no location CLASS_OUPUT", forwardingJavaFileManager.hasLocation(StandardLocation.CLASS_OUTPUT));
550
		assertTrue("Has no location CLASS_OUPUT", forwardingJavaFileManager.hasLocation(StandardLocation.CLASS_OUTPUT));
529
		result = task.call();
551
		result = task.call();
Lines 560-566 Link Here
560
			}
582
			}
561
		}
583
		}
562
		// System compiler
584
		// System compiler
563
		StandardJavaFileManager manager = Compiler.getStandardFileManager(null, Locale.getDefault(), Charset.defaultCharset());
585
		StandardJavaFileManager manager = compiler.getStandardFileManager(null, Locale.getDefault(), Charset.defaultCharset());
564
586
565
		@SuppressWarnings("resource")
587
		@SuppressWarnings("resource")
566
		ForwardingJavaFileManager<StandardJavaFileManager> forwardingJavaFileManager = new ForwardingJavaFileManager<StandardJavaFileManager>(manager) {
588
		ForwardingJavaFileManager<StandardJavaFileManager> forwardingJavaFileManager = new ForwardingJavaFileManager<StandardJavaFileManager>(manager) {
Lines 590-596 Link Here
590
		List<String> options = new ArrayList<String>();
612
		List<String> options = new ArrayList<String>();
591
		options.add("-d");
613
		options.add("-d");
592
		options.add(tmpFolder);
614
		options.add(tmpFolder);
593
 		CompilationTask task = Compiler.getTask(printWriter, manager, null, options, null, units);
615
 		CompilationTask task = compiler.getTask(printWriter, manager, null, options, null, units);
594
 		// check the classpath location
616
 		// check the classpath location
595
 		assertTrue("Has no location CLASS_OUPUT", forwardingJavaFileManager.hasLocation(StandardLocation.CLASS_OUTPUT));
617
 		assertTrue("Has no location CLASS_OUPUT", forwardingJavaFileManager.hasLocation(StandardLocation.CLASS_OUTPUT));
596
		Boolean result = task.call();
618
		Boolean result = task.call();
Lines 650-656 Link Here
650
		List<String> options = new ArrayList<String>();
672
		List<String> options = new ArrayList<String>();
651
		options.add("-d");
673
		options.add("-d");
652
		options.add(tmpFolder);
674
		options.add(tmpFolder);
653
		CompilationTask task = Compiler.getTask(null, null, null, options, null, units);
675
		CompilationTask task = compiler.getTask(null, null, null, options, null, units);
654
		// check the classpath location
676
		// check the classpath location
655
		Boolean result = task.call();
677
		Boolean result = task.call();
656
		printWriter.flush();
678
		printWriter.flush();
Lines 687-693 Link Here
687
			}
709
			}
688
		}
710
		}
689
		// System compiler
711
		// System compiler
690
		StandardJavaFileManager manager = Compiler.getStandardFileManager(null, Locale.getDefault(), Charset.defaultCharset());
712
		StandardJavaFileManager manager = compiler.getStandardFileManager(null, Locale.getDefault(), Charset.defaultCharset());
691
		List<File> files = new ArrayList<File>();
713
		List<File> files = new ArrayList<File>();
692
		files.add(inputFile);
714
		files.add(inputFile);
693
		Iterable<? extends JavaFileObject> units = manager.getJavaFileObjectsFromFiles(files);
715
		Iterable<? extends JavaFileObject> units = manager.getJavaFileObjectsFromFiles(files);
Lines 698-704 Link Here
698
		ByteArrayOutputStream errBuffer = new ByteArrayOutputStream();
720
		ByteArrayOutputStream errBuffer = new ByteArrayOutputStream();
699
		PrintWriter err = new PrintWriter(errBuffer);
721
		PrintWriter err = new PrintWriter(errBuffer);
700
		CompilerInvocationDiagnosticListener compilerInvocationDiagnosticListener = new CompilerInvocationDiagnosticListener(err);
722
		CompilerInvocationDiagnosticListener compilerInvocationDiagnosticListener = new CompilerInvocationDiagnosticListener(err);
701
		CompilationTask task = Compiler.getTask(null, manager, compilerInvocationDiagnosticListener, options, null, units);
723
		CompilationTask task = compiler.getTask(null, manager, compilerInvocationDiagnosticListener, options, null, units);
702
		// check the classpath location
724
		// check the classpath location
703
		Boolean result = task.call();
725
		Boolean result = task.call();
704
		err.flush();
726
		err.flush();
Lines 739-745 Link Here
739
			}
761
			}
740
		}
762
		}
741
		// System compiler
763
		// System compiler
742
		StandardJavaFileManager manager = Compiler.getStandardFileManager(null, Locale.getDefault(), Charset.defaultCharset());
764
		StandardJavaFileManager manager = compiler.getStandardFileManager(null, Locale.getDefault(), Charset.defaultCharset());
743
		List<File> files = new ArrayList<File>();
765
		List<File> files = new ArrayList<File>();
744
		files.add(inputFile);
766
		files.add(inputFile);
745
		Iterable<? extends JavaFileObject> units = manager.getJavaFileObjectsFromFiles(files);
767
		Iterable<? extends JavaFileObject> units = manager.getJavaFileObjectsFromFiles(files);
Lines 759-765 Link Here
759
				super.report(diagnostic);
781
				super.report(diagnostic);
760
			}
782
			}
761
		};
783
		};
762
		CompilationTask task = Compiler.getTask(null, manager, compilerInvocationDiagnosticListener, options, null, units);
784
		CompilationTask task = compiler.getTask(null, manager, compilerInvocationDiagnosticListener, options, null, units);
763
		// check the classpath location
785
		// check the classpath location
764
		Boolean result = task.call();
786
		Boolean result = task.call();
765
		err.flush();
787
		err.flush();
Lines 797-803 Link Here
797
			}
819
			}
798
		}
820
		}
799
		// System compiler
821
		// System compiler
800
		StandardJavaFileManager manager = Compiler.getStandardFileManager(null, Locale.getDefault(), Charset.defaultCharset());
822
		StandardJavaFileManager manager = compiler.getStandardFileManager(null, Locale.getDefault(), Charset.defaultCharset());
801
		List<File> files = new ArrayList<File>();
823
		List<File> files = new ArrayList<File>();
802
		files.add(inputFile);
824
		files.add(inputFile);
803
		Iterable<? extends JavaFileObject> units = manager.getJavaFileObjectsFromFiles(files);
825
		Iterable<? extends JavaFileObject> units = manager.getJavaFileObjectsFromFiles(files);
Lines 817-823 Link Here
817
				super.report(diagnostic);
839
				super.report(diagnostic);
818
			}
840
			}
819
		};
841
		};
820
		CompilationTask task = Compiler.getTask(null, manager, compilerInvocationDiagnosticListener, options, null, units);
842
		CompilationTask task = compiler.getTask(null, manager, compilerInvocationDiagnosticListener, options, null, units);
821
		// check the classpath location
843
		// check the classpath location
822
		Boolean result = task.call();
844
		Boolean result = task.call();
823
		err.flush();
845
		err.flush();
Lines 853-859 Link Here
853
			}
875
			}
854
		}
876
		}
855
		try {
877
		try {
856
			StandardJavaFileManager fileManager = Compiler.getStandardFileManager(null, Locale.getDefault(), Charset.defaultCharset());
878
			StandardJavaFileManager fileManager = compiler.getStandardFileManager(null, Locale.getDefault(), Charset.defaultCharset());
857
	
879
	
858
			List<File> fins = new ArrayList<File>();
880
			List<File> fins = new ArrayList<File>();
859
			fins.add(dir);
881
			fins.add(dir);
Lines 902-908 Link Here
902
		}
924
		}
903
		try {
925
		try {
904
			//JavaCompiler systemCompiler = ToolProvider.getSystemJavaCompiler();
926
			//JavaCompiler systemCompiler = ToolProvider.getSystemJavaCompiler();
905
			StandardJavaFileManager fileManager = Compiler.getStandardFileManager(null, Locale.getDefault(), Charset.defaultCharset());
927
			StandardJavaFileManager fileManager = compiler.getStandardFileManager(null, Locale.getDefault(), Charset.defaultCharset());
906
	
928
	
907
			List<File> fins = new ArrayList<File>();
929
			List<File> fins = new ArrayList<File>();
908
			fins.add(dir);
930
			fins.add(dir);
Lines 987-993 Link Here
987
		}
1009
		}
988
		try {
1010
		try {
989
			//JavaCompiler systemCompiler = ToolProvider.getSystemJavaCompiler();
1011
			//JavaCompiler systemCompiler = ToolProvider.getSystemJavaCompiler();
990
			StandardJavaFileManager fileManager = Compiler.getStandardFileManager(null, Locale.getDefault(), Charset.defaultCharset());
1012
			StandardJavaFileManager fileManager = compiler.getStandardFileManager(null, Locale.getDefault(), Charset.defaultCharset());
991
	
1013
	
992
			List<File> fins = new ArrayList<File>();
1014
			List<File> fins = new ArrayList<File>();
993
			fins.add(dir);
1015
			fins.add(dir);
Lines 1025-1030 Link Here
1025
	 * Clean up the compiler
1047
	 * Clean up the compiler
1026
	 */
1048
	 */
1027
	public void testCleanUp() {
1049
	public void testCleanUp() {
1028
		Compiler = null;
1050
		compiler = null;
1029
	}
1051
	}
1030
}
1052
}
(-)a/org.eclipse.jdt.compiler.tool/src/org/eclipse/jdt/internal/compiler/batch/ClasspathJsr199.java (+203 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2015 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
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.jdt.internal.compiler.batch;
12
13
import java.io.File;
14
import java.io.IOException;
15
import java.io.InputStream;
16
import java.util.ArrayList;
17
import java.util.HashSet;
18
import java.util.Iterator;
19
import java.util.List;
20
import java.util.Set;
21
22
import javax.tools.JavaFileManager;
23
import javax.tools.JavaFileObject;
24
25
import org.eclipse.jdt.core.compiler.CharOperation;
26
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader;
27
import org.eclipse.jdt.internal.compiler.classfmt.ClassFormatException;
28
import org.eclipse.jdt.internal.compiler.env.NameEnvironmentAnswer;
29
30
@SuppressWarnings({ "rawtypes", "unchecked" })
31
public class ClasspathJsr199 extends ClasspathLocation {
32
	private static final Set<JavaFileObject.Kind> fileTypes = new HashSet<>();
33
34
	static {
35
		fileTypes.add(JavaFileObject.Kind.CLASS);
36
	}
37
38
	private JavaFileManager fileManager;
39
	private JavaFileManager.Location location;
40
41
	public ClasspathJsr199(JavaFileManager file, JavaFileManager.Location location) {
42
		super(null, null);
43
		this.fileManager = file;
44
		this.location = location;
45
	}
46
47
	@Override
48
	public List fetchLinkedJars(FileSystem.ClasspathSectionProblemReporter problemReporter) {
49
		// Assume no linked jars
50
		return null;
51
	}
52
53
	@Override
54
	public NameEnvironmentAnswer findClass(char[] typeName, String qualifiedPackageName, String qualifiedBinaryFileName) {
55
		return findClass(typeName, qualifiedPackageName, qualifiedBinaryFileName, false);
56
	}
57
58
	@Override
59
	public NameEnvironmentAnswer findClass(char[] typeName, String qualifiedPackageName, String aQualifiedBinaryFileName,
60
			boolean asBinaryOnly) {
61
62
		String qualifiedBinaryFileName = File.separatorChar == '/'
63
				? aQualifiedBinaryFileName
64
				: aQualifiedBinaryFileName.replace(File.separatorChar, '/');
65
66
		try {
67
			int lastDot = qualifiedBinaryFileName.lastIndexOf('.');
68
			String className = lastDot < 0 ? qualifiedBinaryFileName : qualifiedBinaryFileName.substring(0, lastDot);
69
			JavaFileObject jfo = null;
70
			try {
71
				jfo = this.fileManager.getJavaFileForInput(this.location, className, JavaFileObject.Kind.CLASS);
72
			} catch (IOException e) {
73
				// treat as if class file is missing
74
			}
75
76
			if (jfo == null)
77
				return null; // most common case
78
	
79
			try (InputStream inputStream = jfo.openInputStream()) {
80
				ClassFileReader reader = ClassFileReader.read(inputStream, qualifiedBinaryFileName);
81
				if (reader != null) {
82
					return new NameEnvironmentAnswer(reader, fetchAccessRestriction(qualifiedBinaryFileName));
83
				}
84
			}
85
		} catch (ClassFormatException e) {
86
			// treat as if class file is missing
87
		} catch (IOException e) {
88
			// treat as if class file is missing
89
		}
90
		return null;
91
	}
92
93
	@Override
94
	public char[][][] findTypeNames(String aQualifiedPackageName) {
95
		String qualifiedPackageName = File.separatorChar == '/' ? aQualifiedPackageName : aQualifiedPackageName.replace(
96
				File.separatorChar, '/');
97
98
		Iterable<JavaFileObject> files = null;
99
		try {
100
			files = this.fileManager.list(this.location, qualifiedPackageName, fileTypes, false);
101
		} catch (IOException e) {
102
			// treat as if empty
103
		}
104
		if (files == null) {
105
			return null;
106
		}
107
		ArrayList answers = new ArrayList();
108
		char[][] packageName = CharOperation.splitOn(File.separatorChar, qualifiedPackageName.toCharArray());
109
110
		for (JavaFileObject file : files) {
111
			String fileName = file.toUri().getPath();
112
113
			int last = fileName.lastIndexOf('/');
114
			if (last > 0) {
115
				int indexOfDot = fileName.lastIndexOf('.');
116
				if (indexOfDot != -1) {
117
					String typeName = fileName.substring(last + 1, indexOfDot);
118
					answers.add(CharOperation.arrayConcat(packageName, typeName.toCharArray()));
119
				}
120
			}
121
		}
122
		int size = answers.size();
123
		if (size != 0) {
124
			char[][][] result = new char[size][][];
125
			answers.toArray(result);
126
			return result;
127
		}
128
		return null;
129
	}
130
131
	@Override
132
	public void initialize() throws IOException {
133
		// nothing to do
134
	}
135
136
	@Override
137
	public boolean isPackage(String aQualifiedPackageName) {
138
		String qualifiedPackageName = File.separatorChar == '/' ? aQualifiedPackageName : aQualifiedPackageName.replace(
139
				File.separatorChar, '/');
140
141
		boolean result = false;
142
		try {
143
			Iterable<JavaFileObject> files = this.fileManager.list(this.location, qualifiedPackageName, fileTypes, false);
144
			Iterator f = files.iterator();
145
			// if there is any content, assume a package
146
			if (f.hasNext()) {
147
				result = true;
148
			} else {
149
				// I hate to do this since it is expensive and will throw off garbage
150
				// but can't think of an alternative now
151
				files = this.fileManager.list(this.location, qualifiedPackageName, fileTypes, true);
152
				f = files.iterator();
153
				// if there is any content, assume a package
154
				if (f.hasNext()) {
155
					result = true;
156
				}
157
			}
158
		} catch (IOException e) {
159
			// treat as if missing
160
		}
161
		return result;
162
	}
163
164
	@Override
165
	public void reset() {
166
		try {
167
			this.fileManager.flush();
168
		} catch (IOException e) {
169
			// ignore
170
		}
171
	}
172
173
	@Override
174
	public String toString() {
175
		return "Classpath for Jsr 199 JavaFileManager: " + this.location; //$NON-NLS-1$
176
	}
177
178
	@Override
179
	public char[] normalizedPath() {
180
		if (this.normalizedPath == null) {
181
			this.normalizedPath = this.path.toCharArray();
182
		}
183
		return this.normalizedPath;
184
	}
185
186
	@Override
187
	public String getPath() {
188
		if (this.path == null) {
189
			this.path = this.location.getName();
190
		}
191
		return this.path;
192
	}
193
194
	@Override
195
	public int getMode() {
196
		return BINARY;
197
	}
198
	
199
	@Override
200
	public boolean hasAnnotationFileFor(String qualifiedTypeName) {
201
		return false;
202
	}
203
}
(-)a/org.eclipse.jdt.compiler.tool/src/org/eclipse/jdt/internal/compiler/tool/Archive.java (-7 / +25 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2006, 2009 IBM Corporation and others.
2
 * Copyright (c) 2006, 2015 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 14-21 Link Here
14
import java.io.IOException;
14
import java.io.IOException;
15
import java.nio.charset.Charset;
15
import java.nio.charset.Charset;
16
import java.util.ArrayList;
16
import java.util.ArrayList;
17
import java.util.Collections;
17
import java.util.Enumeration;
18
import java.util.Enumeration;
18
import java.util.Hashtable;
19
import java.util.Hashtable;
20
import java.util.List;
19
import java.util.Set;
21
import java.util.Set;
20
import java.util.zip.ZipEntry;
22
import java.util.zip.ZipEntry;
21
import java.util.zip.ZipException;
23
import java.util.zip.ZipException;
Lines 30-35 Link Here
30
	
32
	
31
	ZipFile zipFile;
33
	ZipFile zipFile;
32
	File file;
34
	File file;
35
33
	protected Hashtable<String, ArrayList<String>> packagesCache;
36
	protected Hashtable<String, ArrayList<String>> packagesCache;
34
	
37
	
35
	private Archive() {
38
	private Archive() {
Lines 39-50 Link Here
39
	public Archive(File file) throws ZipException, IOException {
42
	public Archive(File file) throws ZipException, IOException {
40
		this.file = file;
43
		this.file = file;
41
		this.zipFile = new ZipFile(file);
44
		this.zipFile = new ZipFile(file);
42
		initialize();		
45
		initialize();
43
	}
46
	}
44
47
45
	private void initialize() {
48
	private void initialize() {
46
		// initialize packages
49
		// initialize packages
47
		this.packagesCache = new Hashtable<String, ArrayList<String>>();
50
		this.packagesCache = new Hashtable<>();
48
		nextEntry : for (Enumeration<? extends ZipEntry> e = this.zipFile.entries(); e.hasMoreElements(); ) {
51
		nextEntry : for (Enumeration<? extends ZipEntry> e = this.zipFile.entries(); e.hasMoreElements(); ) {
49
			String fileName = ((ZipEntry) e.nextElement()).getName();
52
			String fileName = ((ZipEntry) e.nextElement()).getName();
50
53
Lines 59-65 Link Here
59
				if (typeName.length() == 0) {
62
				if (typeName.length() == 0) {
60
					continue nextEntry;
63
					continue nextEntry;
61
				}
64
				}
62
				types = new ArrayList<String>();
65
				types = new ArrayList<>();
63
				types.add(typeName);
66
				types.add(typeName);
64
				this.packagesCache.put(packageName, types);
67
				this.packagesCache.put(packageName, types);
65
			} else {
68
			} else {
Lines 69-75 Link Here
69
	}
72
	}
70
	
73
	
71
	public ArchiveFileObject getArchiveFileObject(String entryName, Charset charset) {
74
	public ArchiveFileObject getArchiveFileObject(String entryName, Charset charset) {
72
		return new ArchiveFileObject(this.file, this.zipFile, entryName, charset);
75
		return new ArchiveFileObject(this.file, entryName, charset);
73
	}
76
	}
74
	
77
	
75
	public boolean contains(String entryName) {
78
	public boolean contains(String entryName) {
Lines 83-90 Link Here
83
		return this.packagesCache.keySet();
86
		return this.packagesCache.keySet();
84
	}
87
	}
85
	
88
	
86
	public ArrayList<String> getTypes(String packageName) {
89
	public List<String> getTypes(String packageName) {
87
		// package name is expected to ends with '/'
90
		// package name is expected to ends with '/'
91
		if (this.packagesCache == null) {
92
			try {
93
				this.zipFile = new ZipFile(this.file);
94
			} catch(IOException e) {
95
				return Collections.<String>emptyList();
96
			}
97
			this.initialize();
98
		}
88
		return this.packagesCache.get(packageName);
99
		return this.packagesCache.get(packageName);
89
	}
100
	}
90
	
101
	
Lines 94-103 Link Here
94
105
95
	public void close() {
106
	public void close() {
96
		try {
107
		try {
97
			if (this.zipFile != null) this.zipFile.close();
108
			if (this.zipFile != null) {
109
				this.zipFile.close();
110
			}
98
			this.packagesCache = null;
111
			this.packagesCache = null;
99
		} catch (IOException e) {
112
		} catch (IOException e) {
100
			// ignore
113
			// ignore
101
		}
114
		}
102
	}
115
	}
116
	
117
	@Override
118
	public String toString() {
119
		return "Archive: " + (this.file == null ? "UNKNOWN_ARCHIVE" : this.file.getAbsolutePath()); //$NON-NLS-1$ //$NON-NLS-2$
120
	}
103
}
121
}
(-)a/org.eclipse.jdt.compiler.tool/src/org/eclipse/jdt/internal/compiler/tool/ArchiveFileObject.java (-46 / +73 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2006, 2013 IBM Corporation and others.
2
 * Copyright (c) 2006, 2015 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 34-51 Link Here
34
 * Implementation of a Java file object that corresponds to an entry in a zip/jar file
34
 * Implementation of a Java file object that corresponds to an entry in a zip/jar file
35
 */
35
 */
36
public class ArchiveFileObject implements JavaFileObject {
36
public class ArchiveFileObject implements JavaFileObject {
37
	private ZipEntry zipEntry;
38
	private ZipFile zipFile;
39
	private String entryName;
37
	private String entryName;
40
	private File file;
38
	private File file;
39
	private ZipFile zipFile;
41
	private Charset charset;
40
	private Charset charset;
42
	
41
43
	public ArchiveFileObject(File file, ZipFile zipFile, String entryName, Charset charset) {
42
	public ArchiveFileObject(File file, String entryName, Charset charset) {
44
		this.zipFile = zipFile;
45
		this.zipEntry = zipFile.getEntry(entryName);
46
		this.entryName = entryName;
43
		this.entryName = entryName;
47
		this.file = file;
44
		this.file = file;
48
		this.charset = charset;
45
		this.charset = charset;
46
	}
47
48
	@Override
49
	protected void finalize() throws Throwable {
50
		if (this.zipFile != null) {
51
			try {
52
				this.zipFile.close();
53
			} catch (IOException e) {
54
				// ignore
55
			}
56
		}
57
		super.finalize();
49
	}
58
	}
50
59
51
	/* (non-Javadoc)
60
	/* (non-Javadoc)
Lines 59-70 Link Here
59
		}
68
		}
60
		ClassFileReader reader = null;
69
		ClassFileReader reader = null;
61
		try {
70
		try {
62
			reader = ClassFileReader.read(this.zipFile, this.entryName);
71
			try (ZipFile zip = new ZipFile(this.file)) {
72
				reader = ClassFileReader.read(zip, this.entryName);
73
			}
63
		} catch (ClassFormatException e) {
74
		} catch (ClassFormatException e) {
64
			// ignore
75
			// ignore
65
		} catch (IOException e) {
76
		} catch (IOException e) {
66
			// ignore
77
			// ignore
67
		}
78
		}
79
68
		if (reader == null) {
80
		if (reader == null) {
69
			return null;
81
			return null;
70
		}
82
		}
Lines 103-134 Link Here
103
	@Override
115
	@Override
104
	public NestingKind getNestingKind() {
116
	public NestingKind getNestingKind() {
105
		switch(getKind()) {
117
		switch(getKind()) {
106
			case SOURCE :
118
		case SOURCE :
107
				return NestingKind.TOP_LEVEL;
119
			return NestingKind.TOP_LEVEL;
108
			case CLASS :
120
		case CLASS :
109
        		ClassFileReader reader = null;
121
			ClassFileReader reader = null;
110
        		try {
122
			try {
111
        			reader = ClassFileReader.read(this.zipFile, this.entryName);
123
				try (ZipFile zip = new ZipFile(this.file)) {
112
        		} catch (ClassFormatException e) {
124
					reader = ClassFileReader.read(zip, this.entryName);
113
        			// ignore
125
				}
114
        		} catch (IOException e) {
126
			} catch (ClassFormatException e) {
115
        			// ignore
127
				// ignore
116
        		}
128
			} catch (IOException e) {
117
        		if (reader == null) {
129
				// ignore
118
        			return null;
130
			}
119
        		}
131
			if (reader == null) {
120
        		if (reader.isAnonymous()) {
132
				return null;
121
        			return NestingKind.ANONYMOUS;
133
			}
122
        		}
134
			if (reader.isAnonymous()) {
123
        		if (reader.isLocal()) {
135
				return NestingKind.ANONYMOUS;
124
        			return NestingKind.LOCAL;
136
			}
125
        		}
137
			if (reader.isLocal()) {
126
        		if (reader.isMember()) {
138
				return NestingKind.LOCAL;
127
        			return NestingKind.MEMBER;
139
			}
128
        		}
140
			if (reader.isMember()) {
129
        		return NestingKind.TOP_LEVEL;
141
				return NestingKind.MEMBER;
130
        	default:
142
			}
131
        		return null;
143
			return NestingKind.TOP_LEVEL;
144
		default:
145
			return null;
132
		}
146
		}
133
	}
147
	}
134
148
Lines 137-143 Link Here
137
	 */
151
	 */
138
	@Override
152
	@Override
139
	public boolean isNameCompatible(String simpleName, Kind kind) {
153
	public boolean isNameCompatible(String simpleName, Kind kind) {
140
		return this.zipEntry.getName().endsWith(simpleName + kind.extension);
154
		return this.entryName.endsWith(simpleName + kind.extension);
141
	}
155
	}
142
156
143
	/* (non-Javadoc)
157
	/* (non-Javadoc)
Lines 156-162 Link Here
156
		ArchiveFileObject archiveFileObject = (ArchiveFileObject) o;
170
		ArchiveFileObject archiveFileObject = (ArchiveFileObject) o;
157
		return archiveFileObject.toUri().equals(this.toUri());
171
		return archiveFileObject.toUri().equals(this.toUri());
158
	}
172
	}
159
	
173
160
	@Override
174
	@Override
161
	public int hashCode() {
175
	public int hashCode() {
162
		return this.toUri().hashCode();
176
		return this.toUri().hashCode();
Lines 168-174 Link Here
168
	@Override
182
	@Override
169
	public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException {
183
	public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException {
170
		if (getKind() == Kind.SOURCE) {
184
		if (getKind() == Kind.SOURCE) {
171
			return Util.getCharContents(this, ignoreEncodingErrors, org.eclipse.jdt.internal.compiler.util.Util.getZipEntryByteContent(this.zipEntry, this.zipFile), this.charset.name());
185
			try (ZipFile zipFile2 = new ZipFile(this.file)) {
186
				ZipEntry zipEntry = zipFile2.getEntry(this.entryName);
187
				return Util.getCharContents(this, ignoreEncodingErrors, org.eclipse.jdt.internal.compiler.util.Util.getZipEntryByteContent(zipEntry, zipFile2), this.charset.name());
188
			}
172
		}
189
		}
173
		return null;
190
		return null;
174
	}
191
	}
Lines 178-184 Link Here
178
	 */
195
	 */
179
	@Override
196
	@Override
180
	public long getLastModified() {
197
	public long getLastModified() {
181
		return this.zipEntry.getTime(); // looks the closest from the last modification
198
		try (ZipFile zip = new ZipFile(this.file)) {
199
			ZipEntry zipEntry = zip.getEntry(this.entryName);
200
			return zipEntry.getTime(); // looks the closest from the last modification
201
		} catch(IOException e) {
202
			// ignore
203
		}
204
		return 0;
182
	}
205
	}
183
206
184
	/* (non-Javadoc)
207
	/* (non-Javadoc)
Lines 186-192 Link Here
186
	 */
209
	 */
187
	@Override
210
	@Override
188
	public String getName() {
211
	public String getName() {
189
		return this.zipEntry.getName();
212
		return this.entryName;
190
	}
213
	}
191
214
192
	/* (non-Javadoc)
215
	/* (non-Javadoc)
Lines 194-200 Link Here
194
	 */
217
	 */
195
	@Override
218
	@Override
196
	public InputStream openInputStream() throws IOException {
219
	public InputStream openInputStream() throws IOException {
197
		return this.zipFile.getInputStream(this.zipEntry);
220
		if (this.zipFile == null) {
221
			this.zipFile = new ZipFile(this.file);
222
		}
223
		ZipEntry zipEntry = this.zipFile.getEntry(this.entryName);
224
		return this.zipFile.getInputStream(zipEntry);
198
	}
225
	}
199
226
200
	/* (non-Javadoc)
227
	/* (non-Javadoc)
Lines 227-241 Link Here
227
	@Override
254
	@Override
228
	public URI toUri() {
255
	public URI toUri() {
229
		try {
256
		try {
230
			return new URI("jar:" + this.file.toURI().getPath() + "!" + this.zipEntry.getName()); //$NON-NLS-1$//$NON-NLS-2$
257
			return new URI("jar:" + this.file.toURI().getPath() + "!" + this.entryName); //$NON-NLS-1$//$NON-NLS-2$
231
		} catch (URISyntaxException e) {
258
		} catch (URISyntaxException e) {
232
			return null;
259
			return null;
233
		}
260
		}
234
	}
261
	}
235
	
236
262
237
    @Override
263
238
    public String toString() {
264
	@Override
239
        return this.file.getAbsolutePath() + "[" + this.zipEntry.getName() + "]";//$NON-NLS-1$//$NON-NLS-2$
265
	public String toString() {
240
    }	
266
		return this.file.getAbsolutePath() + "[" + this.entryName + "]";//$NON-NLS-1$//$NON-NLS-2$
267
	}	
241
}
268
}
(-)a/org.eclipse.jdt.compiler.tool/src/org/eclipse/jdt/internal/compiler/tool/EclipseCompiler.java (-5 / +9 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2006, 2014 IBM Corporation and others.
2
 * Copyright (c) 2006, 2015 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 57-63 Link Here
57
	public DiagnosticListener<? super JavaFileObject> diagnosticListener;
57
	public DiagnosticListener<? super JavaFileObject> diagnosticListener;
58
58
59
	public EclipseCompiler() {
59
	public EclipseCompiler() {
60
		this.threadCache = new WeakHashMap<Thread, EclipseCompilerImpl>();
60
		this.threadCache = new WeakHashMap<>();
61
	}
61
	}
62
	/*
62
	/*
63
	 * (non-Javadoc)
63
	 * (non-Javadoc)
Lines 119-125 Link Here
119
		eclipseCompiler2.options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_6);
119
		eclipseCompiler2.options.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_6);
120
		eclipseCompiler2.options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_6);
120
		eclipseCompiler2.options.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_6);
121
121
122
		ArrayList<String> allOptions = new ArrayList<String>();
122
		ArrayList<String> allOptions = new ArrayList<>();
123
		if (options != null) {
123
		if (options != null) {
124
			for (Iterator<String> iterator = options.iterator(); iterator.hasNext(); ) {
124
			for (Iterator<String> iterator = options.iterator(); iterator.hasNext(); ) {
125
				eclipseCompiler2.fileManager.handleOption(iterator.next(), iterator);
125
				eclipseCompiler2.fileManager.handleOption(iterator.next(), iterator);
Lines 139-145 Link Here
139
				if (!uri.isAbsolute()) {
139
				if (!uri.isAbsolute()) {
140
					uri = URI.create("file://" + uri.toString()); //$NON-NLS-1$
140
					uri = URI.create("file://" + uri.toString()); //$NON-NLS-1$
141
				}
141
				}
142
				allOptions.add(new File(uri).getAbsolutePath());
142
				if (uri.getScheme().equals("file")) { //$NON-NLS-1$
143
					allOptions.add(new File(uri).getAbsolutePath());
144
				} else {
145
					allOptions.add(uri.toString());
146
				}
143
			}
147
			}
144
		}
148
		}
145
149
Lines 192-198 Link Here
192
			}
196
			}
193
			@Override
197
			@Override
194
			public void setProcessors(Iterable<? extends Processor> processors) {
198
			public void setProcessors(Iterable<? extends Processor> processors) {
195
				ArrayList<Processor> temp = new ArrayList<Processor>();
199
				ArrayList<Processor> temp = new ArrayList<>();
196
				for (Processor processor : processors) {
200
				for (Processor processor : processors) {
197
					temp.add(processor);
201
					temp.add(processor);
198
				}
202
				}
(-)a/org.eclipse.jdt.compiler.tool/src/org/eclipse/jdt/internal/compiler/tool/EclipseCompilerImpl.java (-61 / +223 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2007, 2013 IBM Corporation and others.
2
 * Copyright (c) 2007, 2015 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 35-42 Link Here
35
import org.eclipse.jdt.core.compiler.CompilationProgress;
35
import org.eclipse.jdt.core.compiler.CompilationProgress;
36
import org.eclipse.jdt.internal.compiler.ClassFile;
36
import org.eclipse.jdt.internal.compiler.ClassFile;
37
import org.eclipse.jdt.internal.compiler.CompilationResult;
37
import org.eclipse.jdt.internal.compiler.CompilationResult;
38
import org.eclipse.jdt.internal.compiler.ICompilerRequestor;
39
import org.eclipse.jdt.internal.compiler.IErrorHandlingPolicy;
38
import org.eclipse.jdt.internal.compiler.IErrorHandlingPolicy;
39
import org.eclipse.jdt.internal.compiler.IProblemFactory;
40
import org.eclipse.jdt.internal.compiler.batch.ClasspathJsr199;
40
import org.eclipse.jdt.internal.compiler.batch.CompilationUnit;
41
import org.eclipse.jdt.internal.compiler.batch.CompilationUnit;
41
import org.eclipse.jdt.internal.compiler.batch.FileSystem;
42
import org.eclipse.jdt.internal.compiler.batch.FileSystem;
42
import org.eclipse.jdt.internal.compiler.batch.FileSystem.Classpath;
43
import org.eclipse.jdt.internal.compiler.batch.FileSystem.Classpath;
Lines 44-49 Link Here
44
import org.eclipse.jdt.internal.compiler.problem.AbortCompilationUnit;
45
import org.eclipse.jdt.internal.compiler.problem.AbortCompilationUnit;
45
import org.eclipse.jdt.internal.compiler.problem.DefaultProblem;
46
import org.eclipse.jdt.internal.compiler.problem.DefaultProblem;
46
import org.eclipse.jdt.internal.compiler.problem.DefaultProblemFactory;
47
import org.eclipse.jdt.internal.compiler.problem.DefaultProblemFactory;
48
import org.eclipse.jdt.internal.compiler.problem.ProblemSeverities;
47
import org.eclipse.jdt.internal.compiler.util.Messages;
49
import org.eclipse.jdt.internal.compiler.util.Messages;
48
import org.eclipse.jdt.internal.compiler.util.SuffixConstants;
50
import org.eclipse.jdt.internal.compiler.util.SuffixConstants;
49
51
Lines 104-110 Link Here
104
	@Override
106
	@Override
105
	public CompilationUnit[] getCompilationUnits() {
107
	public CompilationUnit[] getCompilationUnits() {
106
		if (this.compilationUnits == null) return EclipseCompilerImpl.NO_UNITS;
108
		if (this.compilationUnits == null) return EclipseCompilerImpl.NO_UNITS;
107
		ArrayList<CompilationUnit> units = new ArrayList<CompilationUnit>();
109
		ArrayList<CompilationUnit> units = new ArrayList<>();
108
		for (final JavaFileObject javaFileObject : this.compilationUnits) {
110
		for (final JavaFileObject javaFileObject : this.compilationUnits) {
109
			if (javaFileObject.getKind() != JavaFileObject.Kind.SOURCE) {
111
			if (javaFileObject.getKind() != JavaFileObject.Kind.SOURCE) {
110
				throw new IllegalArgumentException();
112
				throw new IllegalArgumentException();
Lines 155-168 Link Here
155
	}
157
	}
156
158
157
	@Override
159
	@Override
158
    public ICompilerRequestor getBatchRequestor() {
160
	public IProblemFactory getProblemFactory() {
159
        return new EclipseCompilerRequestor(this, this.diagnosticListener, (DefaultProblemFactory) getProblemFactory());
161
		return new DefaultProblemFactory() {
162
			@Override
163
			public CategorizedProblem createProblem(
164
					final char[] originatingFileName,
165
					final int problemId,
166
					final String[] problemArguments,
167
					final String[] messageArguments,
168
					final int severity,
169
					final int startPosition,
170
					final int endPosition,
171
					final int lineNumber,
172
					final int columnNumber) {
173
174
				DiagnosticListener<? super JavaFileObject> diagListener = EclipseCompilerImpl.this.diagnosticListener;
175
				if (diagListener != null) {
176
					diagListener.report(new Diagnostic<JavaFileObject>() {
177
						@Override
178
						public String getCode() {
179
							return Integer.toString(problemId);
180
						}
181
						@Override
182
						public long getColumnNumber() {
183
							return columnNumber;
184
						}
185
						@Override
186
						public long getEndPosition() {
187
							return endPosition;
188
						}
189
						@Override
190
						public Kind getKind() {
191
							if ((severity & ProblemSeverities.Error) != 0) {
192
								return Diagnostic.Kind.ERROR;
193
							}
194
							if ((severity & ProblemSeverities.Optional) != 0) {
195
								return Diagnostic.Kind.WARNING;
196
							}
197
							if ((severity & ProblemSeverities.Warning) != 0) {
198
								return Diagnostic.Kind.MANDATORY_WARNING;
199
							}
200
							return Diagnostic.Kind.OTHER;
201
						}
202
						@Override
203
						public long getLineNumber() {
204
							return lineNumber;
205
						}
206
						@Override
207
						public String getMessage(Locale locale) {
208
							if (locale != null) {
209
								setLocale(locale);
210
							}
211
							return getLocalizedMessage(problemId, problemArguments);
212
						}
213
						@Override
214
						public long getPosition() {
215
							return startPosition;
216
						}
217
						@Override
218
						public JavaFileObject getSource() {
219
							File f = new File(new String(originatingFileName));
220
							if (f.exists()) {
221
								return new EclipseFileObject(null, f.toURI(), JavaFileObject.Kind.SOURCE, null);
222
							}
223
							return null;
224
						}
225
						@Override
226
						public long getStartPosition() {
227
							return startPosition;
228
						}
229
					});
230
				}
231
				return super.createProblem(originatingFileName, problemId, problemArguments, messageArguments, severity, startPosition, endPosition, lineNumber, columnNumber);
232
			}
233
			@Override
234
			public CategorizedProblem createProblem(
235
					final char[] originatingFileName,
236
					final int problemId,
237
					final String[] problemArguments,
238
					final int elaborationID,
239
					final String[] messageArguments,
240
					final int severity,
241
					final int startPosition,
242
					final int endPosition,
243
					final int lineNumber,
244
					final int columnNumber) {
245
246
				DiagnosticListener<? super JavaFileObject> diagListener = EclipseCompilerImpl.this.diagnosticListener;
247
				if (diagListener != null) {
248
					diagListener.report(new Diagnostic<JavaFileObject>() {
249
						@Override
250
						public String getCode() {
251
							return Integer.toString(problemId);
252
						}
253
						@Override
254
						public long getColumnNumber() {
255
							return columnNumber;
256
						}
257
						@Override
258
						public long getEndPosition() {
259
							return endPosition;
260
						}
261
						@Override
262
						public Kind getKind() {
263
							if ((severity & ProblemSeverities.Error) != 0) {
264
								return Diagnostic.Kind.ERROR;
265
							}
266
							if ((severity & ProblemSeverities.Optional) != 0) {
267
								return Diagnostic.Kind.WARNING;
268
							}
269
							if ((severity & ProblemSeverities.Warning) != 0) {
270
								return Diagnostic.Kind.MANDATORY_WARNING;
271
							}
272
							return Diagnostic.Kind.OTHER;
273
						}
274
						@Override
275
						public long getLineNumber() {
276
							return lineNumber;
277
						}
278
						@Override
279
						public String getMessage(Locale locale) {
280
							if (locale != null) {
281
								setLocale(locale);
282
							}
283
							return getLocalizedMessage(problemId, problemArguments);
284
						}
285
						@Override
286
						public long getPosition() {
287
							return startPosition;
288
						}
289
						@Override
290
						public JavaFileObject getSource() {
291
							File f = new File(new String(originatingFileName));
292
							if (f.exists()) {
293
								return new EclipseFileObject(null, f.toURI(), JavaFileObject.Kind.SOURCE, null);
294
							}
295
							return null;
296
						}
297
						@Override
298
						public long getStartPosition() {
299
							return startPosition;
300
						}
301
					});
302
				}
303
				return super.createProblem(originatingFileName, problemId, problemArguments, elaborationID, messageArguments, severity, startPosition, endPosition, lineNumber, columnNumber);
304
			}
305
		};
160
	}
306
	}
161
307
162
						@Override
308
	@Override
163
	protected void initialize(PrintWriter outWriter, PrintWriter errWriter, boolean systemExit, Map customDefaultOptions, CompilationProgress compilationProgress) {
309
	protected void initialize(PrintWriter outWriter, PrintWriter errWriter, boolean systemExit, Map customDefaultOptions, CompilationProgress compilationProgress) {
164
		super.initialize(outWriter, errWriter, systemExit, customDefaultOptions, compilationProgress);
310
		super.initialize(outWriter, errWriter, systemExit, customDefaultOptions, compilationProgress);
165
		this.javaFileObjectMap = new HashMap<CompilationUnit, JavaFileObject>();
311
		this.javaFileObjectMap = new HashMap<>();
166
	}
312
	}
167
313
168
	@Override
314
	@Override
Lines 209-219 Link Here
209
				}
355
				}
210
				try {
356
				try {
211
					JavaFileObject javaFileForOutput =
357
					JavaFileObject javaFileForOutput =
212
					this.fileManager.getJavaFileForOutput(
358
						this.fileManager.getJavaFileForOutput(
213
							StandardLocation.CLASS_OUTPUT,
359
								StandardLocation.CLASS_OUTPUT,
214
							new String(filename),
360
								new String(filename),
215
							JavaFileObject.Kind.CLASS,
361
								JavaFileObject.Kind.CLASS,
216
							this.javaFileObjectMap.get(unitResult.compilationUnit));
362
								this.javaFileObjectMap.get(unitResult.compilationUnit));
217
363
218
					if (generateClasspathStructure) {
364
					if (generateClasspathStructure) {
219
						if (currentDestinationPath != null) {
365
						if (currentDestinationPath != null) {
Lines 234-245 Link Here
234
						}
380
						}
235
					}
381
					}
236
382
237
					OutputStream openOutputStream = javaFileForOutput.openOutputStream();
383
					try (OutputStream openOutputStream = javaFileForOutput.openOutputStream(); BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(openOutputStream)) {
238
					BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(openOutputStream);
384
						bufferedOutputStream.write(classFile.header, 0, classFile.headerOffset);
239
					bufferedOutputStream.write(classFile.header, 0, classFile.headerOffset);
385
						bufferedOutputStream.write(classFile.contents, 0, classFile.contentsOffset);
240
					bufferedOutputStream.write(classFile.contents, 0, classFile.contentsOffset);
386
						bufferedOutputStream.flush();
241
					bufferedOutputStream.flush();
387
					}
242
					bufferedOutputStream.close();
243
				} catch (IOException e) {
388
				} catch (IOException e) {
244
					this.logger.logNoClassFileCreated(currentDestinationPath, relativeStringName, e);
389
					this.logger.logNoClassFileCreated(currentDestinationPath, relativeStringName, e);
245
				}
390
				}
Lines 262-339 Link Here
262
			ArrayList endorsedDirClasspaths,
407
			ArrayList endorsedDirClasspaths,
263
			String customEncoding) {
408
			String customEncoding) {
264
409
265
		ArrayList<FileSystem.Classpath> fileSystemClasspaths = new ArrayList<FileSystem.Classpath>();
410
		ArrayList<FileSystem.Classpath> fileSystemClasspaths = new ArrayList<>();
266
		EclipseFileManager javaFileManager = null;
411
		EclipseFileManager eclipseJavaFileManager = null;
267
		StandardJavaFileManager standardJavaFileManager = null;
412
		StandardJavaFileManager standardJavaFileManager = null;
413
		JavaFileManager javaFileManager = null;
414
		boolean havePlatformPaths = false;
415
		boolean haveClassPaths = false;
268
		if (this.fileManager instanceof EclipseFileManager) {
416
		if (this.fileManager instanceof EclipseFileManager) {
269
			javaFileManager = (EclipseFileManager) this.fileManager;
417
			eclipseJavaFileManager = (EclipseFileManager) this.fileManager;
270
		}
418
		}
271
		if (this.fileManager instanceof StandardJavaFileManager) {
419
		if (this.fileManager instanceof StandardJavaFileManager) {
272
			standardJavaFileManager = (StandardJavaFileManager) this.fileManager;
420
			standardJavaFileManager = (StandardJavaFileManager) this.fileManager;
273
		}
421
		}
422
		javaFileManager = this.fileManager;
274
423
275
		if (javaFileManager != null) {
424
		if (eclipseJavaFileManager != null) {
276
			if ((javaFileManager.flags & EclipseFileManager.HAS_ENDORSED_DIRS) == 0
425
			if ((eclipseJavaFileManager.flags & EclipseFileManager.HAS_ENDORSED_DIRS) == 0
277
					&& (javaFileManager.flags & EclipseFileManager.HAS_BOOTCLASSPATH) != 0) {
426
					&& (eclipseJavaFileManager.flags & EclipseFileManager.HAS_BOOTCLASSPATH) != 0) {
278
				fileSystemClasspaths.addAll(this.handleEndorseddirs(null));
427
				fileSystemClasspaths.addAll(this.handleEndorseddirs(null));
279
			}
428
			}
280
		}
429
		}
281
		Iterable<? extends File> location = null;
430
		Iterable<? extends File> location = null;
282
		if (standardJavaFileManager != null) {
431
		if (standardJavaFileManager != null) {
283
			location = standardJavaFileManager.getLocation(StandardLocation.PLATFORM_CLASS_PATH);
432
			location = standardJavaFileManager.getLocation(StandardLocation.PLATFORM_CLASS_PATH);
284
		}
433
			if (location != null) {
285
		if (location != null) {
434
				for (File file : location) {
286
			for (File file : location) {
435
					Classpath classpath = FileSystem.getClasspath(
287
				Classpath classpath = FileSystem.getClasspath(
436
						file.getAbsolutePath(),
288
					file.getAbsolutePath(),
437
						null,
289
					null,
438
						null);
290
					null);
439
					if (classpath != null) {
291
				if (classpath != null) {
440
						fileSystemClasspaths.add(classpath);
292
					fileSystemClasspaths.add(classpath);
441
						havePlatformPaths = true;
442
					}
293
				}
443
				}
294
			}
444
			}
445
		} else if (javaFileManager != null) {
446
			Classpath classpath = new ClasspathJsr199(this.fileManager, StandardLocation.PLATFORM_CLASS_PATH);
447
			fileSystemClasspaths.add(classpath);
448
			havePlatformPaths = true;
295
		}
449
		}
296
		if (javaFileManager != null) {
450
		if (eclipseJavaFileManager != null) {
297
			if ((javaFileManager.flags & EclipseFileManager.HAS_EXT_DIRS) == 0
451
			if ((eclipseJavaFileManager.flags & EclipseFileManager.HAS_EXT_DIRS) == 0
298
					&& (javaFileManager.flags & EclipseFileManager.HAS_BOOTCLASSPATH) != 0) {
452
					&& (eclipseJavaFileManager.flags & EclipseFileManager.HAS_BOOTCLASSPATH) != 0) {
299
				fileSystemClasspaths.addAll(this.handleExtdirs(null));
453
				fileSystemClasspaths.addAll(this.handleExtdirs(null));
300
			}
454
			}
301
		}
455
		}
302
		if (standardJavaFileManager != null) {
456
		if (standardJavaFileManager != null) {
303
			location = standardJavaFileManager.getLocation(StandardLocation.SOURCE_PATH);
457
			location = standardJavaFileManager.getLocation(StandardLocation.SOURCE_PATH);
304
		} else {
458
			if (location != null) {
305
			location = null;
459
				for (File file : location) {
306
		}
460
					Classpath classpath = FileSystem.getClasspath(
307
		if (location != null) {
461
							file.getAbsolutePath(),
308
			for (File file : location) {
462
							null,
309
				Classpath classpath = FileSystem.getClasspath(
463
							null);
464
					if (classpath != null) {
465
						fileSystemClasspaths.add(classpath);
466
					}
467
				}
468
			}
469
			location = standardJavaFileManager.getLocation(StandardLocation.CLASS_PATH);
470
			if (location != null) {
471
				for (File file : location) {
472
					Classpath classpath = FileSystem.getClasspath(
310
						file.getAbsolutePath(),
473
						file.getAbsolutePath(),
311
						null,
474
						null,
312
						null);
475
						null);
313
				if (classpath != null) {
476
					if (classpath != null) {
314
					fileSystemClasspaths.add(classpath);
477
						fileSystemClasspaths.add(classpath);
478
						haveClassPaths = true;
479
					}
315
				}
480
				}
316
			}
481
			}
317
		}
482
		} else if (javaFileManager != null) {
318
		if (standardJavaFileManager != null) {
483
			Classpath classpath = null;
319
			location = standardJavaFileManager.getLocation(StandardLocation.CLASS_PATH);
484
			if (this.fileManager.hasLocation(StandardLocation.SOURCE_PATH)) {
320
		} else {
485
				classpath = new ClasspathJsr199(this.fileManager, StandardLocation.SOURCE_PATH);
321
			location = null;
486
				fileSystemClasspaths.add(classpath);
322
		}
323
		if (location != null) {
324
			for (File file : location) {
325
				Classpath classpath = FileSystem.getClasspath(
326
					file.getAbsolutePath(),
327
					null,
328
					null);
329
				if (classpath != null) {
330
					fileSystemClasspaths.add(classpath);
331
				}
332
			}
487
			}
488
			classpath = new ClasspathJsr199(this.fileManager, StandardLocation.CLASS_PATH);
489
			fileSystemClasspaths.add(classpath);
490
			haveClassPaths = true;
333
		}
491
		}
334
		if (this.checkedClasspaths == null) {
492
		if (this.checkedClasspaths == null) {
335
			fileSystemClasspaths.addAll(this.handleBootclasspath(null, null));
493
			// It appears to be necessary to handleBootclasspath() for IBM JVMs
336
			fileSystemClasspaths.addAll(this.handleClasspath(null, null));
494
			// in order to have visibility to java.lang.String (not present in rt.jar).
495
			// The jars returned by StandardFileManager.getLocation(PLATFORM_CLASS_PATH) are
496
			// not sufficient to resolve all standard classes.
497
			if (!havePlatformPaths) fileSystemClasspaths.addAll(this.handleBootclasspath(null, null));
498
			if (!haveClassPaths) fileSystemClasspaths.addAll(this.handleClasspath(null, null));
337
		}
499
		}
338
		fileSystemClasspaths = FileSystem.ClasspathNormalizer.normalize(fileSystemClasspaths);
500
		fileSystemClasspaths = FileSystem.ClasspathNormalizer.normalize(fileSystemClasspaths);
339
		final int size = fileSystemClasspaths.size();
501
		final int size = fileSystemClasspaths.size();
(-)a/org.eclipse.jdt.compiler.tool/src/org/eclipse/jdt/internal/compiler/tool/EclipseFileManager.java (-104 / +42 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2006, 2014 IBM Corporation and others.
2
 * Copyright (c) 2006, 2015 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 23-28 Link Here
23
import java.util.Arrays;
23
import java.util.Arrays;
24
import java.util.HashMap;
24
import java.util.HashMap;
25
import java.util.Iterator;
25
import java.util.Iterator;
26
import java.util.List;
26
import java.util.Locale;
27
import java.util.Locale;
27
import java.util.Map;
28
import java.util.Map;
28
import java.util.MissingResourceException;
29
import java.util.MissingResourceException;
Lines 33-41 Link Here
33
34
34
import javax.tools.FileObject;
35
import javax.tools.FileObject;
35
import javax.tools.JavaFileObject;
36
import javax.tools.JavaFileObject;
37
import javax.tools.JavaFileObject.Kind;
36
import javax.tools.StandardJavaFileManager;
38
import javax.tools.StandardJavaFileManager;
37
import javax.tools.StandardLocation;
39
import javax.tools.StandardLocation;
38
import javax.tools.JavaFileObject.Kind;
39
40
40
import org.eclipse.jdt.core.compiler.IProblem;
41
import org.eclipse.jdt.core.compiler.IProblem;
41
import org.eclipse.jdt.internal.compiler.batch.FileSystem;
42
import org.eclipse.jdt.internal.compiler.batch.FileSystem;
Lines 67-74 Link Here
67
	public EclipseFileManager(Locale locale, Charset charset) {
68
	public EclipseFileManager(Locale locale, Charset charset) {
68
		this.locale = locale == null ? Locale.getDefault() : locale;
69
		this.locale = locale == null ? Locale.getDefault() : locale;
69
		this.charset = charset == null ? Charset.defaultCharset() : charset;
70
		this.charset = charset == null ? Charset.defaultCharset() : charset;
70
		this.locations = new HashMap<String, Iterable<? extends File>>();
71
		this.locations = new HashMap<>();
71
		this.archivesCache = new HashMap<File, Archive>();
72
		this.archivesCache = new HashMap<>();
72
		try {
73
		try {
73
			this.setLocation(StandardLocation.PLATFORM_CLASS_PATH, getDefaultBootclasspath());
74
			this.setLocation(StandardLocation.PLATFORM_CLASS_PATH, getDefaultBootclasspath());
74
			Iterable<? extends File> defaultClasspath = getDefaultClasspath();
75
			Iterable<? extends File> defaultClasspath = getDefaultClasspath();
Lines 84-139 Link Here
84
		}
85
		}
85
	}
86
	}
86
87
87
	private void addFiles(File[][] jars, ArrayList<File> files) {
88
		if (jars != null) {
89
			for (File[] currentJars : jars) {
90
				if (currentJars != null) {
91
					for (File currentJar : currentJars) {
92
						if (currentJar.exists()) {
93
							files.add(currentJar);
94
						}
95
					}
96
				}
97
			}
98
		}
99
	}
100
	
101
	
102
	private void addFilesFrom(File javaHome, String propertyName, String defaultPath, ArrayList<File> files) {
103
		String extdirsStr = System.getProperty(propertyName);
104
		File[] directoriesToCheck = null;
105
		if (extdirsStr == null) {
106
			if (javaHome != null) {
107
				directoriesToCheck = new File[] { new File(javaHome, defaultPath) };
108
			}
109
		} else {
110
			StringTokenizer tokenizer = new StringTokenizer(extdirsStr, File.pathSeparator);
111
			ArrayList<String> paths = new ArrayList<String>();
112
			while (tokenizer.hasMoreTokens()) {
113
				paths.add(tokenizer.nextToken());
114
			}
115
			if (paths.size() != 0) {
116
				directoriesToCheck = new File[paths.size()];
117
				for (int i = 0; i < directoriesToCheck.length; i++)  {
118
					directoriesToCheck[i] = new File(paths.get(i));
119
				}
120
			}
121
		}
122
		if (directoriesToCheck != null) {
123
			addFiles(Main.getLibrariesFiles(directoriesToCheck), files);
124
		}
125
		
126
	}
127
	
128
	/* (non-Javadoc)
88
	/* (non-Javadoc)
129
	 * @see javax.tools.JavaFileManager#close()
89
	 * @see javax.tools.JavaFileManager#close()
130
	 */
90
	 */
131
	@Override
91
	@Override
132
	public void close() throws IOException {
92
	public void close() throws IOException {
133
		this.locations = null;
93
		if (this.locations != null) this.locations.clear();
134
		for (Archive archive : this.archivesCache.values()) {
94
		for (Archive archive : this.archivesCache.values()) {
135
			archive.close();
95
			archive.close();
136
		}
96
		}
97
		this.archivesCache.clear();
137
	}
98
	}
138
	
99
	
139
	private void collectAllMatchingFiles(File file, String normalizedPackageName, Set<Kind> kinds, boolean recurse, ArrayList<JavaFileObject> collector) {
100
	private void collectAllMatchingFiles(File file, String normalizedPackageName, Set<Kind> kinds, boolean recurse, ArrayList<JavaFileObject> collector) {
Lines 166-171 Link Here
166
			}
127
			}
167
		} else {
128
		} else {
168
			Archive archive = this.getArchive(file);
129
			Archive archive = this.getArchive(file);
130
			if (archive == Archive.UNKNOWN_ARCHIVE) return;
169
			String key = normalizedPackageName;
131
			String key = normalizedPackageName;
170
			if (!normalizedPackageName.endsWith("/")) {//$NON-NLS-1$
132
			if (!normalizedPackageName.endsWith("/")) {//$NON-NLS-1$
171
				key += '/';
133
				key += '/';
Lines 174-180 Link Here
174
			if (recurse) {
136
			if (recurse) {
175
				for (String packageName : archive.allPackages()) {
137
				for (String packageName : archive.allPackages()) {
176
					if (packageName.startsWith(key)) {
138
					if (packageName.startsWith(key)) {
177
						ArrayList<String> types = archive.getTypes(packageName);
139
						List<String> types = archive.getTypes(packageName);
178
						if (types != null) {
140
						if (types != null) {
179
							for (String typeName : types) {
141
							for (String typeName : types) {
180
								final Kind kind = getKind(getExtension(typeName));
142
								final Kind kind = getKind(getExtension(typeName));
Lines 186-197 Link Here
186
					}
148
					}
187
				}
149
				}
188
			} else {
150
			} else {
189
				ArrayList<String> types = archive.getTypes(key);
151
				List<String> types = archive.getTypes(key);
190
				if (types != null) {
152
				if (types != null) {
191
					for (String typeName : types) {
153
					for (String typeName : types) {
192
						final Kind kind = getKind(typeName);
154
						final Kind kind = getKind(getExtension(typeName));
193
						if (kinds.contains(kind)) {
155
						if (kinds.contains(kind)) {
194
							collector.add(archive.getArchiveFileObject(normalizedPackageName + typeName, this.charset));
156
							collector.add(archive.getArchiveFileObject(key + typeName, this.charset));
195
						}
157
						}
196
					}
158
					}
197
				}
159
				}
Lines 200-206 Link Here
200
	}
162
	}
201
163
202
	private Iterable<? extends File> concatFiles(Iterable<? extends File> iterable, Iterable<? extends File> iterable2) {
164
	private Iterable<? extends File> concatFiles(Iterable<? extends File> iterable, Iterable<? extends File> iterable2) {
203
		ArrayList<File> list = new ArrayList<File>();
165
		ArrayList<File> list = new ArrayList<>();
204
		if (iterable2 == null) return iterable;
166
		if (iterable2 == null) return iterable;
205
		for (Iterator<? extends File> iterator = iterable.iterator(); iterator.hasNext(); ) {
167
		for (Iterator<? extends File> iterator = iterable.iterator(); iterator.hasNext(); ) {
206
			list.add(iterator.next());
168
			list.add(iterator.next());
Lines 225-247 Link Here
225
		// check the archive (jar/zip) cache
187
		// check the archive (jar/zip) cache
226
		Archive archive = this.archivesCache.get(f);
188
		Archive archive = this.archivesCache.get(f);
227
		if (archive == null) {
189
		if (archive == null) {
190
			archive = Archive.UNKNOWN_ARCHIVE;
228
			// create a new archive
191
			// create a new archive
229
			if (f.exists()) {
192
			if (f.exists()) {
230
    			try {
193
				try {
231
    				archive = new Archive(f);
194
					archive = new Archive(f);
232
    			} catch (ZipException e) {
195
				} catch (ZipException e) {
233
    				// ignore
196
					// ignore
234
    			} catch (IOException e) {
197
				} catch (IOException e) {
235
    				// ignore
198
					// ignore
236
    			}
199
				}
237
    			if (archive != null) {
200
				if (archive != null) {
238
    				this.archivesCache.put(f, archive);
201
					this.archivesCache.put(f, archive);
239
    			} else {
202
				}
240
    				this.archivesCache.put(f, Archive.UNKNOWN_ARCHIVE);
241
    			}
242
			} else {
243
				this.archivesCache.put(f, Archive.UNKNOWN_ARCHIVE);
244
			}
203
			}
204
			this.archivesCache.put(f, archive);
245
		}
205
		}
246
		return archive;
206
		return archive;
247
	}
207
	}
Lines 256-262 Link Here
256
			// location is unknown
216
			// location is unknown
257
			return null;
217
			return null;
258
		}
218
		}
259
		ArrayList<URL> allURLs = new ArrayList<URL>();
219
		ArrayList<URL> allURLs = new ArrayList<>();
260
		for (File f : files) {
220
		for (File f : files) {
261
			try {
221
			try {
262
				allURLs.add(f.toURI().toURL());
222
				allURLs.add(f.toURI().toURL());
Lines 270-277 Link Here
270
	}
230
	}
271
231
272
	private Iterable<? extends File> getPathsFrom(String path) {
232
	private Iterable<? extends File> getPathsFrom(String path) {
273
		ArrayList<FileSystem.Classpath> paths = new ArrayList<FileSystem.Classpath>();
233
		ArrayList<FileSystem.Classpath> paths = new ArrayList<>();
274
		ArrayList<File> files = new ArrayList<File>();
234
		ArrayList<File> files = new ArrayList<>();
275
		try {
235
		try {
276
			this.processPathEntries(Main.DEFAULT_SIZE_CLASSPATH, paths, path, this.charset.name(), false, false);
236
			this.processPathEntries(Main.DEFAULT_SIZE_CLASSPATH, paths, path, this.charset.name(), false, false);
277
		} catch (IllegalArgumentException e) {
237
		} catch (IllegalArgumentException e) {
Lines 284-290 Link Here
284
	}
244
	}
285
245
286
	Iterable<? extends File> getDefaultBootclasspath() {
246
	Iterable<? extends File> getDefaultBootclasspath() {
287
		ArrayList<File> files = new ArrayList<File>();
247
		List<File> files = new ArrayList<>();
288
		String javaversion = System.getProperty("java.version");//$NON-NLS-1$
248
		String javaversion = System.getProperty("java.version");//$NON-NLS-1$
289
		if(javaversion.length() > 3)
249
		if(javaversion.length() > 3)
290
			javaversion = javaversion.substring(0, 3);
250
			javaversion = javaversion.substring(0, 3);
Lines 294-330 Link Here
294
			return null;
254
			return null;
295
		}
255
		}
296
256
297
		/*
257
		for (String fileName : org.eclipse.jdt.internal.compiler.util.Util.collectFilesNames()) {
298
		 * Handle >= JDK 1.6
258
			files.add(new File(fileName));
299
		 */
300
		String javaHome = System.getProperty("java.home"); //$NON-NLS-1$
301
		File javaHomeFile = null;
302
		if (javaHome != null) {
303
			javaHomeFile = new File(javaHome);
304
			if (!javaHomeFile.exists())
305
				javaHomeFile = null;
306
		}
259
		}
307
308
		addFilesFrom(javaHomeFile, "java.endorsed.dirs", "/lib/endorsed", files);//$NON-NLS-1$//$NON-NLS-2$
309
		if (javaHomeFile != null) {
310
			File[] directoriesToCheck = null;
311
			if (System.getProperty("os.name").startsWith("Mac")) {//$NON-NLS-1$//$NON-NLS-2$
312
				directoriesToCheck = new File[] { new File(javaHomeFile, "../Classes"), //$NON-NLS-1$
313
				};
314
			} else {
315
				directoriesToCheck = new File[] { new File(javaHomeFile, "lib") //$NON-NLS-1$
316
				};
317
			}
318
			File[][] jars = Main.getLibrariesFiles(directoriesToCheck);
319
			addFiles(jars, files);
320
		}
321
		addFilesFrom(javaHomeFile, "java.ext.dirs", "/lib/ext", files);//$NON-NLS-1$//$NON-NLS-2$
322
		return files;
260
		return files;
323
	}
261
	}
324
262
325
	Iterable<? extends File> getDefaultClasspath() {
263
	Iterable<? extends File> getDefaultClasspath() {
326
		// default classpath
264
		// default classpath
327
		ArrayList<File> files = new ArrayList<File>();
265
		ArrayList<File> files = new ArrayList<>();
328
		String classProp = System.getProperty("java.class.path"); //$NON-NLS-1$
266
		String classProp = System.getProperty("java.class.path"); //$NON-NLS-1$
329
		if ((classProp == null) || (classProp.length() == 0)) {
267
		if ((classProp == null) || (classProp.length() == 0)) {
330
			return null;
268
			return null;
Lines 343-350 Link Here
343
	}
281
	}
344
282
345
	private Iterable<? extends File> getEndorsedDirsFrom(String path) {
283
	private Iterable<? extends File> getEndorsedDirsFrom(String path) {
346
		ArrayList<FileSystem.Classpath> paths = new ArrayList<FileSystem.Classpath>();
284
		ArrayList<FileSystem.Classpath> paths = new ArrayList<>();
347
		ArrayList<File> files = new ArrayList<File>();
285
		ArrayList<File> files = new ArrayList<>();
348
		try {
286
		try {
349
			this.processPathEntries(Main.DEFAULT_SIZE_CLASSPATH, paths, path, this.charset.name(), false, false);
287
			this.processPathEntries(Main.DEFAULT_SIZE_CLASSPATH, paths, path, this.charset.name(), false, false);
350
		} catch (IllegalArgumentException e) {
288
		} catch (IllegalArgumentException e) {
Lines 357-364 Link Here
357
	}
295
	}
358
296
359
	private Iterable<? extends File> getExtdirsFrom(String path) {
297
	private Iterable<? extends File> getExtdirsFrom(String path) {
360
		ArrayList<FileSystem.Classpath> paths = new ArrayList<FileSystem.Classpath>();
298
		ArrayList<FileSystem.Classpath> paths = new ArrayList<>();
361
		ArrayList<File> files = new ArrayList<File>();
299
		ArrayList<File> files = new ArrayList<>();
362
		try {
300
		try {
363
			this.processPathEntries(Main.DEFAULT_SIZE_CLASSPATH, paths, path, this.charset.name(), false, false);
301
			this.processPathEntries(Main.DEFAULT_SIZE_CLASSPATH, paths, path, this.charset.name(), false, false);
364
		} catch (IllegalArgumentException e) {
302
		} catch (IllegalArgumentException e) {
Lines 547-553 Link Here
547
	 */
485
	 */
548
	@Override
486
	@Override
549
	public Iterable<? extends JavaFileObject> getJavaFileObjectsFromFiles(Iterable<? extends File> files) {
487
	public Iterable<? extends JavaFileObject> getJavaFileObjectsFromFiles(Iterable<? extends File> files) {
550
		ArrayList<JavaFileObject> javaFileArrayList = new ArrayList<JavaFileObject>();
488
		ArrayList<JavaFileObject> javaFileArrayList = new ArrayList<>();
551
		for (File f : files) {
489
		for (File f : files) {
552
			if (f.isDirectory()) {
490
			if (f.isDirectory()) {
553
				throw new IllegalArgumentException("file : " + f.getAbsolutePath() + " is a directory"); //$NON-NLS-1$ //$NON-NLS-2$
491
				throw new IllegalArgumentException("file : " + f.getAbsolutePath() + " is a directory"); //$NON-NLS-1$ //$NON-NLS-2$
Lines 562-568 Link Here
562
	 */
500
	 */
563
	@Override
501
	@Override
564
	public Iterable<? extends JavaFileObject> getJavaFileObjectsFromStrings(Iterable<String> names) {
502
	public Iterable<? extends JavaFileObject> getJavaFileObjectsFromStrings(Iterable<String> names) {
565
		ArrayList<File> files = new ArrayList<File>();
503
		ArrayList<File> files = new ArrayList<>();
566
		for (String name : names) {
504
		for (String name : names) {
567
			files.add(new File(name));
505
			files.add(new File(name));
568
		}
506
		}
Lines 601-607 Link Here
601
		if (file.exists() && !file.isDirectory()) {
539
		if (file.exists() && !file.isDirectory()) {
602
			throw new IllegalArgumentException("file : " + file.getAbsolutePath() + " is not a directory");//$NON-NLS-1$//$NON-NLS-2$
540
			throw new IllegalArgumentException("file : " + file.getAbsolutePath() + " is not a directory");//$NON-NLS-1$//$NON-NLS-2$
603
		}
541
		}
604
		ArrayList<File> list = new ArrayList<File>(1);
542
		ArrayList<File> list = new ArrayList<>(1);
605
		list.add(file);
543
		list.add(file);
606
		return list;
544
		return list;
607
	}
545
	}
Lines 765-771 Link Here
765
		if (javaFileObject == null) {
703
		if (javaFileObject == null) {
766
			return null;
704
			return null;
767
		}
705
		}
768
		return normalized(name);
706
		return name.replace('/', '.');
769
	}
707
	}
770
708
771
	private boolean isArchive(File f) {
709
	private boolean isArchive(File f) {
Lines 803-809 Link Here
803
			throw new IllegalArgumentException("Unknown location : " + location);//$NON-NLS-1$
741
			throw new IllegalArgumentException("Unknown location : " + location);//$NON-NLS-1$
804
		}
742
		}
805
		
743
		
806
		ArrayList<JavaFileObject> collector = new ArrayList<JavaFileObject>();
744
		ArrayList<JavaFileObject> collector = new ArrayList<>();
807
		String normalizedPackageName = normalized(packageName);
745
		String normalizedPackageName = normalized(packageName);
808
		for (File file : allFilesInLocations) {
746
		for (File file : allFilesInLocations) {
809
			collectAllMatchingFiles(file, normalizedPackageName, kinds, recurse, collector);
747
			collectAllMatchingFiles(file, normalizedPackageName, kinds, recurse, collector);
Lines 828-834 Link Here
828
	private Iterable<? extends File> prependFiles(Iterable<? extends File> iterable,
766
	private Iterable<? extends File> prependFiles(Iterable<? extends File> iterable,
829
			Iterable<? extends File> iterable2) {
767
			Iterable<? extends File> iterable2) {
830
		if (iterable2 == null) return iterable;
768
		if (iterable2 == null) return iterable;
831
		ArrayList<File> list = new ArrayList<File>();
769
		ArrayList<File> list = new ArrayList<>();
832
		for (Iterator<? extends File> iterator = iterable2.iterator(); iterator.hasNext(); ) {
770
		for (Iterator<? extends File> iterator = iterable2.iterator(); iterator.hasNext(); ) {
833
			list.add(iterator.next());
771
			list.add(iterator.next());
834
		}
772
		}
(-)a/org.eclipse.jdt.compiler.tool/src/org/eclipse/jdt/internal/compiler/tool/EclipseFileObject.java (-6 / +9 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2006, 2011 IBM Corporation and others.
2
 * Copyright (c) 2006, 2015 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 12-17 Link Here
12
12
13
package org.eclipse.jdt.internal.compiler.tool;
13
package org.eclipse.jdt.internal.compiler.tool;
14
14
15
import java.io.BufferedInputStream;
16
import java.io.BufferedOutputStream;
17
import java.io.BufferedReader;
18
import java.io.BufferedWriter;
15
import java.io.File;
19
import java.io.File;
16
import java.io.FileInputStream;
20
import java.io.FileInputStream;
17
import java.io.FileOutputStream;
21
import java.io.FileOutputStream;
Lines 164-171 Link Here
164
	 */
168
	 */
165
	@Override
169
	@Override
166
	public InputStream openInputStream() throws IOException {
170
	public InputStream openInputStream() throws IOException {
167
		// TODO (olivier) should use buffered input stream
171
		return new BufferedInputStream(new FileInputStream(this.f));
168
		return new FileInputStream(this.f);
169
	}
172
	}
170
173
171
	/**
174
	/**
Lines 174-180 Link Here
174
	@Override
177
	@Override
175
	public OutputStream openOutputStream() throws IOException {
178
	public OutputStream openOutputStream() throws IOException {
176
		ensureParentDirectoriesExist();
179
		ensureParentDirectoriesExist();
177
		return new FileOutputStream(this.f);
180
		return new BufferedOutputStream(new FileOutputStream(this.f));
178
	}
181
	}
179
182
180
	/**
183
	/**
Lines 182-188 Link Here
182
	 */
185
	 */
183
	@Override
186
	@Override
184
	public Reader openReader(boolean ignoreEncodingErrors) throws IOException {
187
	public Reader openReader(boolean ignoreEncodingErrors) throws IOException {
185
		return new FileReader(this.f);
188
		return new BufferedReader(new FileReader(this.f));
186
	}
189
	}
187
190
188
	/**
191
	/**
Lines 191-197 Link Here
191
	@Override
194
	@Override
192
	public Writer openWriter() throws IOException {
195
	public Writer openWriter() throws IOException {
193
		ensureParentDirectoriesExist();
196
		ensureParentDirectoriesExist();
194
		return new FileWriter(this.f);
197
		return new BufferedWriter(new FileWriter(this.f));
195
	}
198
	}
196
	
199
	
197
	@Override
200
	@Override
(-)a/org.eclipse.jdt.compiler.tool/src/org/eclipse/jdt/internal/compiler/tool/Options.java (-4 / +7 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2006, 2014 IBM Corporation and others.
2
 * Copyright (c) 2006, 2015 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 24-30 Link Here
24
	private static final Set<String> ONE_ARGUMENT_OPTIONS;
24
	private static final Set<String> ONE_ARGUMENT_OPTIONS;
25
	private static final Set<String> FILE_MANAGER_OPTIONS;
25
	private static final Set<String> FILE_MANAGER_OPTIONS;
26
	static {
26
	static {
27
		ZERO_ARGUMENT_OPTIONS = new HashSet<String>();
27
		ZERO_ARGUMENT_OPTIONS = new HashSet<>();
28
		Options.ZERO_ARGUMENT_OPTIONS.add("-progress");//$NON-NLS-1$
28
		Options.ZERO_ARGUMENT_OPTIONS.add("-progress");//$NON-NLS-1$
29
		Options.ZERO_ARGUMENT_OPTIONS.add("-proceedOnError");//$NON-NLS-1$
29
		Options.ZERO_ARGUMENT_OPTIONS.add("-proceedOnError");//$NON-NLS-1$
30
		Options.ZERO_ARGUMENT_OPTIONS.add("-proceedOnError:Fatal");//$NON-NLS-1$
30
		Options.ZERO_ARGUMENT_OPTIONS.add("-proceedOnError:Fatal");//$NON-NLS-1$
Lines 60-65 Link Here
60
		Options.ZERO_ARGUMENT_OPTIONS.add("-1.7");//$NON-NLS-1$
60
		Options.ZERO_ARGUMENT_OPTIONS.add("-1.7");//$NON-NLS-1$
61
		Options.ZERO_ARGUMENT_OPTIONS.add("-7");//$NON-NLS-1$
61
		Options.ZERO_ARGUMENT_OPTIONS.add("-7");//$NON-NLS-1$
62
		Options.ZERO_ARGUMENT_OPTIONS.add("-7.0");//$NON-NLS-1$
62
		Options.ZERO_ARGUMENT_OPTIONS.add("-7.0");//$NON-NLS-1$
63
		Options.ZERO_ARGUMENT_OPTIONS.add("-1.8");//$NON-NLS-1$
64
		Options.ZERO_ARGUMENT_OPTIONS.add("-8");//$NON-NLS-1$
65
		Options.ZERO_ARGUMENT_OPTIONS.add("-8.0");//$NON-NLS-1$
63
		Options.ZERO_ARGUMENT_OPTIONS.add("-proc:only");//$NON-NLS-1$
66
		Options.ZERO_ARGUMENT_OPTIONS.add("-proc:only");//$NON-NLS-1$
64
		Options.ZERO_ARGUMENT_OPTIONS.add("-proc:none");//$NON-NLS-1$
67
		Options.ZERO_ARGUMENT_OPTIONS.add("-proc:none");//$NON-NLS-1$
65
		Options.ZERO_ARGUMENT_OPTIONS.add("-XprintProcessorInfo");//$NON-NLS-1$
68
		Options.ZERO_ARGUMENT_OPTIONS.add("-XprintProcessorInfo");//$NON-NLS-1$
Lines 67-73 Link Here
67
		Options.ZERO_ARGUMENT_OPTIONS.add("-parameters");//$NON-NLS-1$
70
		Options.ZERO_ARGUMENT_OPTIONS.add("-parameters");//$NON-NLS-1$
68
		Options.ZERO_ARGUMENT_OPTIONS.add("-genericsignature");//$NON-NLS-1$
71
		Options.ZERO_ARGUMENT_OPTIONS.add("-genericsignature");//$NON-NLS-1$
69
72
70
		FILE_MANAGER_OPTIONS = new HashSet<String>();
73
		FILE_MANAGER_OPTIONS = new HashSet<>();
71
		Options.FILE_MANAGER_OPTIONS.add("-bootclasspath");//$NON-NLS-1$
74
		Options.FILE_MANAGER_OPTIONS.add("-bootclasspath");//$NON-NLS-1$
72
		Options.FILE_MANAGER_OPTIONS.add("-encoding");//$NON-NLS-1$
75
		Options.FILE_MANAGER_OPTIONS.add("-encoding");//$NON-NLS-1$
73
		Options.FILE_MANAGER_OPTIONS.add("-d");//$NON-NLS-1$
76
		Options.FILE_MANAGER_OPTIONS.add("-d");//$NON-NLS-1$
Lines 79-85 Link Here
79
		Options.FILE_MANAGER_OPTIONS.add("-s");//$NON-NLS-1$
82
		Options.FILE_MANAGER_OPTIONS.add("-s");//$NON-NLS-1$
80
		Options.FILE_MANAGER_OPTIONS.add("-processorpath");//$NON-NLS-1$
83
		Options.FILE_MANAGER_OPTIONS.add("-processorpath");//$NON-NLS-1$
81
84
82
		ONE_ARGUMENT_OPTIONS = new HashSet<String>();
85
		ONE_ARGUMENT_OPTIONS = new HashSet<>();
83
		Options.ONE_ARGUMENT_OPTIONS.addAll(Options.FILE_MANAGER_OPTIONS);
86
		Options.ONE_ARGUMENT_OPTIONS.addAll(Options.FILE_MANAGER_OPTIONS);
84
		Options.ONE_ARGUMENT_OPTIONS.add("-log");//$NON-NLS-1$
87
		Options.ONE_ARGUMENT_OPTIONS.add("-log");//$NON-NLS-1$
85
		Options.ONE_ARGUMENT_OPTIONS.add("-repeat");//$NON-NLS-1$
88
		Options.ONE_ARGUMENT_OPTIONS.add("-repeat");//$NON-NLS-1$
(-)a/org.eclipse.jdt.compiler.tool/src/org/eclipse/jdt/internal/compiler/tool/Util.java (-2 / +2 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2006, 2009 IBM Corporation and others.
2
 * Copyright (c) 2006, 2015 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 95-101 Link Here
95
		}
95
		}
96
	}
96
	}
97
	public static class EncodingErrorCollector {
97
	public static class EncodingErrorCollector {
98
		ArrayList<EncodingError> encodingErrors = new ArrayList<EncodingError>();
98
		ArrayList<EncodingError> encodingErrors = new ArrayList<>();
99
		FileObject fileObject;
99
		FileObject fileObject;
100
		String encoding;
100
		String encoding;
101
101
(-)a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/util/Util.java (-13 / +15 lines)
Lines 24-29 Link Here
24
import java.io.PrintWriter;
24
import java.io.PrintWriter;
25
import java.io.StringWriter;
25
import java.io.StringWriter;
26
import java.io.UnsupportedEncodingException;
26
import java.io.UnsupportedEncodingException;
27
import java.util.ArrayList;
27
import java.util.HashSet;
28
import java.util.HashSet;
28
import java.util.List;
29
import java.util.List;
29
import java.util.StringTokenizer;
30
import java.util.StringTokenizer;
Lines 677-683 Link Here
677
	}
678
	}
678
	/**
679
	/**
679
	 * Returns the contents of the given zip entry as a byte array.
680
	 * Returns the contents of the given zip entry as a byte array.
680
	 * @throws IOException if a problem occured reading the zip entry.
681
	 * @throws IOException if a problem occurred reading the zip entry.
681
	 */
682
	 */
682
	public static byte[] getZipEntryByteContent(ZipEntry ze, ZipFile zip)
683
	public static byte[] getZipEntryByteContent(ZipEntry ze, ZipFile zip)
683
		throws IOException {
684
		throws IOException {
Lines 1086-1091 Link Here
1086
	}
1087
	}
1087
1088
1088
	public static void collectRunningVMBootclasspath(List bootclasspaths) {
1089
	public static void collectRunningVMBootclasspath(List bootclasspaths) {
1090
		for (String filePath : collectFilesNames()) {
1091
			FileSystem.Classpath currentClasspath = FileSystem.getClasspath(filePath, null, null);
1092
			if (currentClasspath != null) {
1093
				bootclasspaths.add(currentClasspath);
1094
			}
1095
		}
1096
	}
1097
1098
	public static List<String> collectFilesNames() {
1089
		/* no bootclasspath specified
1099
		/* no bootclasspath specified
1090
		 * we can try to retrieve the default librairies of the VM used to run
1100
		 * we can try to retrieve the default librairies of the VM used to run
1091
		 * the batch compiler
1101
		 * the batch compiler
Lines 1108-1122 Link Here
1108
				bootclasspathProperty = System.getProperty("org.apache.harmony.boot.class.path"); //$NON-NLS-1$
1118
				bootclasspathProperty = System.getProperty("org.apache.harmony.boot.class.path"); //$NON-NLS-1$
1109
			}
1119
			}
1110
		}
1120
		}
1121
		List<String> filePaths = new ArrayList<>();
1111
		if ((bootclasspathProperty != null) && (bootclasspathProperty.length() != 0)) {
1122
		if ((bootclasspathProperty != null) && (bootclasspathProperty.length() != 0)) {
1112
			StringTokenizer tokenizer = new StringTokenizer(bootclasspathProperty, File.pathSeparator);
1123
			StringTokenizer tokenizer = new StringTokenizer(bootclasspathProperty, File.pathSeparator);
1113
			String token;
1114
			while (tokenizer.hasMoreTokens()) {
1124
			while (tokenizer.hasMoreTokens()) {
1115
				token = tokenizer.nextToken();
1125
				filePaths.add(tokenizer.nextToken());
1116
				FileSystem.Classpath currentClasspath = FileSystem.getClasspath(token, null, null);
1117
				if (currentClasspath != null) {
1118
					bootclasspaths.add(currentClasspath);
1119
				}
1120
			}
1126
			}
1121
		} else {
1127
		} else {
1122
			// try to get all jars inside the lib folder of the java home
1128
			// try to get all jars inside the lib folder of the java home
Lines 1139-1156 Link Here
1139
						File[] current = systemLibrariesJars[i];
1145
						File[] current = systemLibrariesJars[i];
1140
						if (current != null) {
1146
						if (current != null) {
1141
							for (int j = 0, max2 = current.length; j < max2; j++) {
1147
							for (int j = 0, max2 = current.length; j < max2; j++) {
1142
								FileSystem.Classpath classpath =
1148
								filePaths.add(current[j].getAbsolutePath());
1143
									FileSystem.getClasspath(current[j].getAbsolutePath(),
1144
										null, false, null, null);
1145
								if (classpath != null) {
1146
									bootclasspaths.add(classpath);
1147
								}
1148
							}
1149
							}
1149
						}
1150
						}
1150
					}
1151
					}
1151
				}
1152
				}
1152
			}
1153
			}
1153
		}
1154
		}
1155
		return filePaths;
1154
	}
1156
	}
1155
	public static int getParameterCount(char[] methodSignature) {
1157
	public static int getParameterCount(char[] methodSignature) {
1156
		try {
1158
		try {

Return to bug 188796