KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > junit > ui > JUnitHomeInitializer


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 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.junit.ui;
12
13
14 import java.io.File JavaDoc;
15 import java.io.IOException JavaDoc;
16 import java.net.URL JavaDoc;
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     /**
27      * @see ClasspathVariableInitializer#initialize(String)
28      */

29     public void initialize(String JavaDoc variable) {
30         Bundle bundle= Platform.getBundle("org.junit"); //$NON-NLS-1$
31
if (bundle == null) {
32             JavaCore.removeClasspathVariable(JUnitPlugin.JUNIT_HOME, null);
33             return;
34         }
35         URL JavaDoc installLocation= bundle.getEntry("/"); //$NON-NLS-1$
36
URL JavaDoc local= null;
37         try {
38             local= Platform.asLocalURL(installLocation);
39         } catch (IOException JavaDoc e) {
40             JavaCore.removeClasspathVariable(JUnitPlugin.JUNIT_HOME, null);
41             return;
42         }
43         try {
44             String JavaDoc fullPath= new File JavaDoc(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