1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.seasar.eclipse.common.variable;
17
18 import java.io.File;
19 import java.io.IOException;
20 import java.net.URL;
21
22 import org.eclipse.core.runtime.FileLocator;
23 import org.eclipse.core.runtime.Path;
24 import org.eclipse.jdt.core.ClasspathVariableInitializer;
25 import org.eclipse.jdt.core.JavaCore;
26 import org.eclipse.jdt.core.JavaModelException;
27
28
29
30
31
32 public abstract class AbstractVariable extends ClasspathVariableInitializer {
33
34
35
36
37 public AbstractVariable() {
38 super();
39 }
40
41
42
43
44
45
46 @Override
47 public void initialize(String variable) {
48 URL installLocation = getInstallLocation();
49 URL local = null;
50 try {
51 local = FileLocator.toFileURL(installLocation);
52 } catch (IOException e) {
53 JavaCore.removeClasspathVariable(variable, null);
54 return;
55 }
56 try {
57 String fullPath = new File(local.getPath()).getAbsolutePath();
58 JavaCore.setClasspathVariable(variable,
59 Path.fromOSString(fullPath), null);
60 } catch (JavaModelException e1) {
61 JavaCore.removeClasspathVariable(variable, null);
62 }
63
64 }
65
66 protected abstract URL getInstallLocation();
67 }