Lines 1-5
Link Here
|
1 |
/******************************************************************************* |
1 |
/******************************************************************************* |
2 |
* Copyright (c) 2000, 2011 IBM Corporation and others. |
2 |
* Copyright (c) 2000, 2013 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 10-21
Link Here
|
10 |
*******************************************************************************/ |
10 |
*******************************************************************************/ |
11 |
package org.eclipse.jdt.debug.tests.core; |
11 |
package org.eclipse.jdt.debug.tests.core; |
12 |
|
12 |
|
|
|
13 |
import java.io.File; |
14 |
import java.io.IOException; |
15 |
import java.net.MalformedURLException; |
16 |
import java.net.URL; |
17 |
|
13 |
import org.eclipse.core.runtime.CoreException; |
18 |
import org.eclipse.core.runtime.CoreException; |
14 |
import org.eclipse.core.runtime.IPath; |
19 |
import org.eclipse.core.runtime.IPath; |
15 |
import org.eclipse.core.runtime.Path; |
20 |
import org.eclipse.core.runtime.Path; |
16 |
import org.eclipse.core.runtime.Platform; |
21 |
import org.eclipse.core.runtime.Platform; |
|
|
22 |
import org.eclipse.jdt.core.IClasspathAttribute; |
17 |
import org.eclipse.jdt.core.IClasspathContainer; |
23 |
import org.eclipse.jdt.core.IClasspathContainer; |
18 |
import org.eclipse.jdt.core.IClasspathEntry; |
24 |
import org.eclipse.jdt.core.IClasspathEntry; |
|
|
25 |
import org.eclipse.jdt.core.index.JavaIndexer; |
26 |
import org.eclipse.jdt.debug.testplugin.JavaTestPlugin; |
19 |
import org.eclipse.jdt.debug.tests.AbstractDebugTest; |
27 |
import org.eclipse.jdt.debug.tests.AbstractDebugTest; |
20 |
import org.eclipse.jdt.internal.launching.JREContainer; |
28 |
import org.eclipse.jdt.internal.launching.JREContainer; |
21 |
import org.eclipse.jdt.internal.launching.JREContainerInitializer; |
29 |
import org.eclipse.jdt.internal.launching.JREContainerInitializer; |
Lines 162-165
Link Here
|
162 |
} |
170 |
} |
163 |
} |
171 |
} |
164 |
|
172 |
|
165 |
} |
173 |
public void testJREContainerIndex() { |
|
|
174 |
|
175 |
// get the current VM |
176 |
IVMInstall def = JavaRuntime.getDefaultVMInstall(); |
177 |
LibraryLocation[] libs = JavaRuntime.getLibraryLocations(def); |
178 |
// generate an index for the first library location only (to save time - do not need an index for all libraries) |
179 |
URL indexURL = null; |
180 |
try { |
181 |
indexURL = this.getIndexForLibrary(libs[0]); |
182 |
} |
183 |
catch (Exception ex) { |
184 |
fail(ex.getMessage()); |
185 |
} |
186 |
// clone the current VM, but only add the one library that was indexed |
187 |
VMStandin newVMStandin = new VMStandin(def.getVMInstallType(), "index.jre"); |
188 |
newVMStandin.setName("JRE with pre-built index"); |
189 |
newVMStandin.setInstallLocation(def.getInstallLocation()); |
190 |
final LibraryLocation[] newLibs = new LibraryLocation[1]; |
191 |
newLibs[0] = new LibraryLocation(libs[0].getSystemLibraryPath(), libs[0].getSystemLibrarySourcePath(), libs[0].getPackageRootPath(), libs[0].getJavadocLocation(), indexURL); |
192 |
newVMStandin.setLibraryLocations(newLibs); |
193 |
IVMInstall newVM = newVMStandin.convertToRealVM(); |
194 |
// make sure the index URL is correct |
195 |
assertEquals(indexURL, newVM.getLibraryLocations()[0].getIndexLocation()); |
196 |
// create the JRE container |
197 |
IPath containerPath = new Path(JavaRuntime.JRE_CONTAINER); |
198 |
JREContainer container = new JREContainer(newVM, containerPath, get14Project()); |
199 |
IClasspathEntry[] originalEntries = container.getClasspathEntries(); |
200 |
// There should only be 1 classpath entry (the 1 library added) |
201 |
assertEquals(1, originalEntries.length); |
202 |
IClasspathAttribute[] cpAttributes = originalEntries[0].getExtraAttributes(); |
203 |
// There should only be 1 classpath attribute for this entry |
204 |
assertEquals(1, cpAttributes.length); |
205 |
// and that 1 classpath attribute should be the index location |
206 |
assertEquals(IClasspathAttribute.INDEX_LOCATION_ATTRIBUTE_NAME, cpAttributes[0].getName()); |
207 |
// and it should have a value of the original indexURL in its string form. |
208 |
assertEquals(indexURL.toString(), cpAttributes[0].getValue()); |
209 |
} |
210 |
|
211 |
/** |
212 |
* Generates and returns a {@link URL} to the index file for a given {@link LibraryLocation} into the state location |
213 |
*/ |
214 |
private URL getIndexForLibrary(final LibraryLocation library) throws IOException, MalformedURLException { |
215 |
|
216 |
// construct the path to the index file |
217 |
File libraryFile = library.getSystemLibraryPath().toFile(); |
218 |
String indexName = libraryFile.getName() + ".index"; |
219 |
IPath indexPath = JavaTestPlugin.getDefault().getStateLocation().append(indexName); |
220 |
// generate the index using JDT Core API |
221 |
JavaIndexer.generateIndexForJar(libraryFile.getAbsolutePath(), indexPath.toOSString()); |
222 |
// return the index URL |
223 |
URL indexURL = indexPath.toFile().toURI().toURL(); |
224 |
return indexURL; |
225 |
} |
226 |
} |