2011/08/05 - Jakarta Cactus has been retired.
For more information, please explore the Attic.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.apache.cactus.eclipse.runner.common;
22
23 import java.io.File;
24 import java.io.IOException;
25
26 import org.apache.cactus.eclipse.runner.ui.CactusPlugin;
27 import org.eclipse.core.runtime.IPath;
28 import org.eclipse.core.runtime.Path;
29 import org.eclipse.core.runtime.Platform;
30 import org.eclipse.jdt.core.IClasspathEntry;
31 import org.eclipse.jdt.core.JavaCore;
32
33
34
35
36
37
38 public class LibraryHelper
39 {
40
41
42
43
44
45
46 private static IPath[] getJarPathArray(File theDirectory)
47 {
48 File[] files = theDirectory.listFiles(new JarFilenameFilter());
49 IPath[] result = new IPath[files.length];
50 for (int i = 0; i < files.length; i++)
51 {
52 result[i] = new Path(files[i].getAbsolutePath());
53 }
54 return result;
55 }
56
57
58
59
60 private static IPath[] getClientJarPathArray()
61 {
62 File clientLibDir = getClientLibPath().toFile();
63 return getJarPathArray(clientLibDir);
64 }
65
66
67
68
69 private static IPath[] getCommonJarPathArray()
70 {
71 File commmonLibDir = getCommonLibPath().toFile();
72 return getJarPathArray(commmonLibDir);
73 }
74
75
76
77
78 public static IClasspathEntry[] getClientEntries()
79 {
80 IPath[] clientJars = getClientJarPathArray();
81 IClasspathEntry[] result = new IClasspathEntry[clientJars.length];
82 for (int i = 0; i < clientJars.length; i++)
83 {
84 result[i] = getIClasspathEntry(clientJars[i]);
85 }
86 return result;
87 }
88
89
90
91
92 public static IClasspathEntry[] getCommonEntries()
93 {
94 IPath[] commonJars = getCommonJarPathArray();
95 IClasspathEntry[] result = new IClasspathEntry[commonJars.length];
96 for (int i = 0; i < commonJars.length; i++)
97 {
98 result[i] = getIClasspathEntry(commonJars[i]);
99 }
100 return result;
101 }
102
103
104
105
106 public static IClasspathEntry[] getClientSideEntries()
107 {
108 IClasspathEntry[] clientEntries = getClientEntries();
109 IClasspathEntry[] commonEntries = getCommonEntries();
110 return concatenateEntries(clientEntries, commonEntries);
111 }
112
113
114
115
116
117
118
119
120
121 public static IClasspathEntry[] concatenateEntries(
122 IClasspathEntry[] theArray1, IClasspathEntry[] theArray2)
123 {
124 IClasspathEntry[] newArray =
125 new IClasspathEntry[theArray1.length + theArray2.length];
126 System.arraycopy(theArray1, 0, newArray, 0, theArray1.length);
127 System.arraycopy(
128 theArray2,
129 0,
130 newArray,
131 theArray1.length,
132 theArray2.length);
133 return newArray;
134 }
135
136
137
138
139 public static IPath getLibPath()
140 {
141 CactusPlugin thePlugin = CactusPlugin.getDefault();
142
143 try {
144 return new Path(Platform.asLocalURL(thePlugin.getBundle().getEntry("/" +CactusPlugin.CACTUS_LIBRARY_PATH)).getPath());
145 } catch(IOException ex) {
146 CactusPlugin.log(ex);
147 }
148 return new Path(CactusPlugin.CACTUS_LIBRARY_PATH);
149 }
150
151
152
153
154 private static IPath getClientLibPath()
155 {
156 return getLibPath().append(CactusPlugin.CACTUS_CLIENT_LIBRARY_PATH);
157 }
158
159
160
161
162 private static IPath getCommonLibPath()
163 {
164 return getLibPath().append(CactusPlugin.CACTUS_COMMON_LIBRARY_PATH);
165 }
166
167
168
169
170
171 public static IClasspathEntry getIClasspathEntry(IPath thePath)
172 {
173 return JavaCore.newLibraryEntry(thePath, null, null);
174 }
175
176
177
178
179
180 public static IClasspathEntry getIClasspathEntry(String thePath)
181 {
182 return getIClasspathEntry(new Path(thePath));
183 }
184 }