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.launcher;
22
23 import java.io.File;
24 import java.io.IOException;
25 import java.net.MalformedURLException;
26 import java.net.URL;
27 import java.util.Vector;
28
29 import org.apache.cactus.eclipse.runner.common.JarFilenameFilter;
30 import org.apache.cactus.eclipse.runner.common.LibraryHelper;
31 import org.apache.cactus.eclipse.runner.containers.jetty.JettyContainerManager;
32 import org.apache.cactus.eclipse.runner.ui.CactusPlugin;
33 import org.apache.cactus.eclipse.runner.ui.CactusPreferences;
34 import org.eclipse.core.runtime.CoreException;
35 import org.eclipse.core.runtime.ILibrary;
36 import org.eclipse.core.runtime.IPath;
37 import org.eclipse.core.runtime.IPluginDescriptor;
38 import org.eclipse.core.runtime.Path;
39 import org.eclipse.core.runtime.Platform;
40 import org.eclipse.core.runtime.Plugin;
41 import org.eclipse.jdt.core.IClasspathEntry;
42 import org.eclipse.jdt.core.IJavaProject;
43 import org.eclipse.jdt.core.JavaCore;
44
45
46
47
48
49
50
51
52
53
54
55 public class JettyCactusLaunchConfiguration
56 extends CactusLaunchConfiguration
57 {
58
59
60
61 public static final String ID_CACTUS_APPLICATION_JETTY =
62 "org.apache.cactus.eclipse.runner.launchconfig.jetty";
63
64
65
66
67
68 private static final String JETTY_LIBRARY_PATH = "./lib/";
69
70
71
72
73
74
75 protected IClasspathEntry[] getCactusClasspath() throws CoreException
76 {
77 IClasspathEntry[] cactusClasspath = super.getCactusClasspath();
78 try {
79 cactusClasspath =
80 LibraryHelper.concatenateEntries(
81 cactusClasspath,
82 getJettyClasspath());
83 } catch (MalformedURLException me) {
84 throw CactusPlugin.createCoreException(
85 "CactusLaunch.message.prepare.error.plugin.file",
86 " : " + me.toString(),
87 null);
88 }
89 return cactusClasspath;
90 }
91
92
93
94
95
96
97 private IClasspathEntry[] getJettyClasspath() throws CoreException, MalformedURLException
98 {
99 CactusPlugin thePlugin = CactusPlugin.getDefault();
100
101 IPath libURL = LibraryHelper.getLibPath();
102
103 if (libURL == null)
104 {
105 throw CactusPlugin.createCoreException(
106 "CactusLaunch.message.prepare.error.plugin.file",
107 " : " + libURL.toString(),
108 null);
109 }
110 File libDir = new File(libURL.toString());
111 IClasspathEntry[] jettyJarPaths = getJarPaths(libDir);
112 IClasspathEntry[] apacheJarPaths = new IClasspathEntry[0];
113 Plugin tomcatPlugin = Platform.getPlugin("org.eclipse.tomcat");
114 if (tomcatPlugin != null)
115 {
116 IPluginDescriptor descriptor = tomcatPlugin.getDescriptor();
117 apacheJarPaths = getLibrariesPaths(descriptor, "org.apache.jasper");
118 }
119 return LibraryHelper.concatenateEntries(jettyJarPaths, apacheJarPaths);
120 }
121
122
123
124
125
126 protected String getCactusVMArgs(IJavaProject theJavaProject)
127 {
128 String cactusVMArgs = super.getCactusVMArgs(theJavaProject);
129 String jettyResourcePath =
130 CactusPreferences.getTempDir()
131 + File.separator
132 + JettyContainerManager.getJettyWebappPath();
133 cactusVMArgs += "-Dcactus.jetty.resourceDir="
134 + jettyResourcePath
135 + VM_ARG_SEPARATOR;
136 IPath projectLocation = theJavaProject.getProject().getLocation();
137 File jettyXML =
138 projectLocation.append(CactusPreferences.getJettyXML()).toFile();
139 if (jettyXML.exists())
140 {
141 cactusVMArgs += "-Dcactus.jetty.config="
142 + jettyXML.getAbsolutePath()
143 + VM_ARG_SEPARATOR;
144 }
145 cactusVMArgs += "-Dcactus.initializer="
146 + "org.apache.cactus.extension.jetty.JettyTestSetup";
147 return cactusVMArgs;
148 }
149
150
151
152
153
154 private IClasspathEntry[] getJarPaths(File theDirectory)
155 {
156 File[] jars = theDirectory.listFiles(new JarFilenameFilter());
157 IClasspathEntry[] jarPaths = new IClasspathEntry[jars.length];
158 for (int i = 0; i < jarPaths.length; i++)
159 {
160 jarPaths[i] =
161 LibraryHelper.getIClasspathEntry(jars[i].getAbsolutePath());
162 }
163 return jarPaths;
164 }
165
166
167
168
169
170
171
172 private IClasspathEntry[] getLibrariesPaths(
173 IPluginDescriptor theDescriptor, String thePackagePrefix) throws MalformedURLException
174 {
175 Vector result = new Vector();
176 URL root = new URL(("file://"+JavaCore.getClasspathVariable("ECLIPSE_HOME").toFile().toURL().getPath()+theDescriptor.getInstallURL().getPath()).replaceAll("plugin","plugins"));
177 ILibrary[] libraries = theDescriptor.getRuntimeLibraries();
178
179 for (int i = 0; i < libraries.length; i++)
180 {
181
182 ILibrary currentLib = libraries[i];
183
184 if (thePackagePrefix == null
185 || isContained(thePackagePrefix, currentLib))
186 {
187 try
188 {
189 URL url = new URL(root, currentLib.getPath().toString());
190 result.add(
191 LibraryHelper.getIClasspathEntry(
192 Platform.asLocalURL(url).getPath()));
193 }
194 catch (IOException e)
195 {
196
197 CactusPlugin.log(e);
198 continue;
199 }
200 }
201 }
202 return (IClasspathEntry[]) result.toArray(
203 new IClasspathEntry[result.size()]);
204 }
205
206
207
208
209
210
211 private boolean isContained(String thePackagePrefix, ILibrary theCurrentLib)
212 {
213 String[] prefixes = theCurrentLib.getPackagePrefixes();
214 if(prefixes==null || prefixes.length==0) {
215
216 return false;
217 }
218 for (int i = 0; i < prefixes.length; i++)
219 {
220 if (prefixes[i].equals(thePackagePrefix))
221 {
222 return true;
223 }
224 }
225 return false;
226 }
227 }