KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 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.buildpath;
12
13
14 import org.eclipse.core.runtime.IPath;
15
16 import org.eclipse.jdt.core.ClasspathVariableInitializer;
17 import org.eclipse.jdt.core.JavaCore;
18 import org.eclipse.jdt.core.JavaModelException;
19
20 import org.eclipse.jdt.internal.junit.ui.JUnitPlugin;
21
22 public class JUnitHomeInitializer extends ClasspathVariableInitializer {
23     
24     /*
25      * @see ClasspathVariableInitializer#initialize(String)
26      */

27     public void initialize(String JavaDoc variable) {
28         if (JUnitPlugin.JUNIT_HOME.equals(variable)) {
29             initializeHome();
30         } else if (JUnitPlugin.JUNIT_SRC_HOME.equals(variable)) {
31             initializeSource();
32         }
33     }
34
35     private void initializeHome() {
36         try {
37             IPath location= BuildPathSupport.getBundleLocation(BuildPathSupport.JUNIT3_PLUGIN);
38             if (location != null) {
39                 JavaCore.setClasspathVariable(JUnitPlugin.JUNIT_HOME, location, null);
40             } else {
41                 JavaCore.removeClasspathVariable(JUnitPlugin.JUNIT_HOME, null);
42             }
43         } catch (JavaModelException e1) {
44             JavaCore.removeClasspathVariable(JUnitPlugin.JUNIT_HOME, null);
45         }
46     }
47     
48     private void initializeSource() {
49         try {
50             IPath sourceLocation= BuildPathSupport.getSourceLocation(BuildPathSupport.JUNIT3_PLUGIN);
51             if (sourceLocation != null) {
52                 JavaCore.setClasspathVariable(JUnitPlugin.JUNIT_SRC_HOME, sourceLocation, null);
53             } else {
54                 JavaCore.removeClasspathVariable(JUnitPlugin.JUNIT_SRC_HOME, null);
55             }
56         } catch (JavaModelException e1) {
57             JavaCore.removeClasspathVariable(JUnitPlugin.JUNIT_SRC_HOME, null);
58         }
59     }
60 }
Popular Tags