1 11 package org.eclipse.jdt.internal.junit.ui; 12 13 14 import java.io.File ; 15 import java.io.IOException ; 16 import java.net.URL ; 17 18 import org.eclipse.core.runtime.Path; 19 import org.eclipse.core.runtime.Platform; 20 import org.eclipse.jdt.core.ClasspathVariableInitializer; 21 import org.eclipse.jdt.core.JavaCore; 22 import org.eclipse.jdt.core.JavaModelException; 23 import org.osgi.framework.Bundle; 24 25 public class JUnitHomeInitializer extends ClasspathVariableInitializer { 26 29 public void initialize(String variable) { 30 Bundle bundle= Platform.getBundle("org.junit"); if (bundle == null) { 32 JavaCore.removeClasspathVariable(JUnitPlugin.JUNIT_HOME, null); 33 return; 34 } 35 URL installLocation= bundle.getEntry("/"); URL local= null; 37 try { 38 local= Platform.asLocalURL(installLocation); 39 } catch (IOException e) { 40 JavaCore.removeClasspathVariable(JUnitPlugin.JUNIT_HOME, null); 41 return; 42 } 43 try { 44 String fullPath= new File (local.getPath()).getAbsolutePath(); 45 JavaCore.setClasspathVariable(JUnitPlugin.JUNIT_HOME, Path.fromOSString(fullPath), null); 46 } catch (JavaModelException e1) { 47 JavaCore.removeClasspathVariable(JUnitPlugin.JUNIT_HOME, null); 48 } 49 } 50 } 51 | Popular Tags |