|
Lines 11-34
Link Here
|
| 11 |
package org.eclipse.jst.ws.internal.axis.consumption.ui.task; |
11 |
package org.eclipse.jst.ws.internal.axis.consumption.ui.task; |
| 12 |
|
12 |
|
| 13 |
|
13 |
|
|
|
14 |
import java.io.File; |
| 15 |
import java.io.IOException; |
| 16 |
import java.net.MalformedURLException; |
| 17 |
import java.net.URL; |
| 18 |
|
| 14 |
import org.eclipse.core.resources.IFile; |
19 |
import org.eclipse.core.resources.IFile; |
| 15 |
import org.eclipse.core.resources.IProject; |
20 |
import org.eclipse.core.resources.IProject; |
|
|
21 |
import org.eclipse.core.runtime.CoreException; |
| 16 |
import org.eclipse.core.runtime.IPath; |
22 |
import org.eclipse.core.runtime.IPath; |
| 17 |
import org.eclipse.core.runtime.IPluginDescriptor; |
23 |
import org.eclipse.core.runtime.IPluginDescriptor; |
| 18 |
import org.eclipse.core.runtime.IPluginRegistry; |
24 |
import org.eclipse.core.runtime.IPluginRegistry; |
|
|
25 |
import org.eclipse.core.runtime.IProgressMonitor; |
| 26 |
import org.eclipse.core.runtime.IStatus; |
| 19 |
import org.eclipse.core.runtime.Path; |
27 |
import org.eclipse.core.runtime.Path; |
| 20 |
import org.eclipse.core.runtime.Platform; |
28 |
import org.eclipse.core.runtime.Platform; |
| 21 |
import org.eclipse.core.runtime.Plugin; |
29 |
import org.eclipse.core.runtime.Plugin; |
|
|
30 |
import org.eclipse.jdt.core.IClasspathEntry; |
| 31 |
import org.eclipse.jdt.core.IJavaProject; |
| 32 |
import org.eclipse.jdt.core.JavaCore; |
| 33 |
import org.eclipse.jdt.core.JavaModelException; |
| 34 |
import org.eclipse.jst.ws.internal.axis.consumption.ui.plugin.WebServiceAxisConsumptionUIPlugin; |
| 22 |
import org.eclipse.jst.ws.internal.common.J2EEUtils; |
35 |
import org.eclipse.jst.ws.internal.common.J2EEUtils; |
| 23 |
import org.eclipse.jst.ws.internal.common.ResourceUtils; |
36 |
import org.eclipse.jst.ws.internal.common.ResourceUtils; |
| 24 |
import org.eclipse.wst.command.internal.env.common.FileResourceUtils; |
37 |
import org.eclipse.wst.command.internal.env.common.FileResourceUtils; |
|
|
38 |
import org.eclipse.wst.command.internal.env.ui.eclipse.EclipseProgressMonitor; |
| 25 |
import org.eclipse.wst.command.internal.provisional.env.core.SimpleCommand; |
39 |
import org.eclipse.wst.command.internal.provisional.env.core.SimpleCommand; |
| 26 |
import org.eclipse.wst.command.internal.provisional.env.core.common.Environment; |
40 |
import org.eclipse.wst.command.internal.provisional.env.core.common.Environment; |
| 27 |
import org.eclipse.wst.command.internal.provisional.env.core.common.MessageUtils; |
41 |
import org.eclipse.wst.command.internal.provisional.env.core.common.MessageUtils; |
|
|
42 |
import org.eclipse.wst.command.internal.provisional.env.core.common.ProgressMonitor; |
| 28 |
import org.eclipse.wst.command.internal.provisional.env.core.common.SimpleStatus; |
43 |
import org.eclipse.wst.command.internal.provisional.env.core.common.SimpleStatus; |
| 29 |
import org.eclipse.wst.command.internal.provisional.env.core.common.Status; |
44 |
import org.eclipse.wst.command.internal.provisional.env.core.common.Status; |
|
|
45 |
import org.eclipse.wst.command.internal.provisional.env.core.common.StatusException; |
| 30 |
import org.eclipse.wst.command.internal.provisional.env.core.context.ResourceContext; |
46 |
import org.eclipse.wst.command.internal.provisional.env.core.context.ResourceContext; |
| 31 |
import org.eclipse.wst.command.internal.provisional.env.core.context.TransientResourceContext; |
47 |
import org.eclipse.wst.command.internal.provisional.env.core.context.TransientResourceContext; |
|
|
48 |
import org.eclipse.wst.common.componentcore.ModuleCoreNature; |
| 32 |
|
49 |
|
| 33 |
|
50 |
|
| 34 |
public class CopyAxisJarCommand extends SimpleCommand { |
51 |
public class CopyAxisJarCommand extends SimpleCommand { |
|
Lines 44-49
Link Here
|
| 44 |
"saaj.jar", |
61 |
"saaj.jar", |
| 45 |
"wsdl4j-1.5.1.jar" |
62 |
"wsdl4j-1.5.1.jar" |
| 46 |
}; |
63 |
}; |
|
|
64 |
public static String PATH_TO_JARS_IN_PLUGIN = "lib/"; |
| 47 |
|
65 |
|
| 48 |
private String DESCRIPTION = "TASK_DESC_COPY_JARS_TO_PROJECT"; |
66 |
private String DESCRIPTION = "TASK_DESC_COPY_JARS_TO_PROJECT"; |
| 49 |
private String LABEL = "TASK_LABEL_COPY_JARS_TO_PROJECT"; |
67 |
private String LABEL = "TASK_LABEL_COPY_JARS_TO_PROJECT"; |
|
Lines 73-79
Link Here
|
| 73 |
public Status execute(Environment env) { |
91 |
public Status execute(Environment env) { |
| 74 |
Status status = new SimpleStatus(""); |
92 |
Status status = new SimpleStatus(""); |
| 75 |
env.getProgressMonitor().report(msgUtils_.getMessage("PROGRESS_INFO_COPY_AXIS_CFG")); |
93 |
env.getProgressMonitor().report(msgUtils_.getMessage("PROGRESS_INFO_COPY_AXIS_CFG")); |
| 76 |
copyAxisJarsToProject(project, status, env); |
94 |
|
|
|
95 |
ModuleCoreNature mn = ModuleCoreNature.getModuleCoreNature(project); |
| 96 |
if (mn!=null) |
| 97 |
{ |
| 98 |
copyAxisJarsToProject(project, status, env); |
| 99 |
} |
| 100 |
else |
| 101 |
{ |
| 102 |
//Check if it's a plain old Java project |
| 103 |
IJavaProject javaProject = null; |
| 104 |
|
| 105 |
javaProject = JavaCore.create(project); |
| 106 |
if (javaProject != null) |
| 107 |
{ |
| 108 |
status = addAxisJarsToBuildPath(project, env); |
| 109 |
if (status.getSeverity()==Status.ERROR) |
| 110 |
{ |
| 111 |
env.getStatusHandler().reportError(status); |
| 112 |
return status; |
| 113 |
} |
| 114 |
} |
| 115 |
else |
| 116 |
{ |
| 117 |
status = new SimpleStatus("", msgUtils_.getMessage("MSG_WARN_NO_JAVA_NATURE"), Status.ERROR); |
| 118 |
env.getStatusHandler().reportError(status); |
| 119 |
return status; |
| 120 |
} |
| 121 |
|
| 122 |
} |
| 123 |
|
| 77 |
return status; |
124 |
return status; |
| 78 |
|
125 |
|
| 79 |
} |
126 |
} |
|
Lines 127-132
Link Here
|
| 127 |
} |
174 |
} |
| 128 |
} |
175 |
} |
| 129 |
|
176 |
|
|
|
177 |
public Status addAxisJarsToBuildPath(IProject p, Environment env) |
| 178 |
{ |
| 179 |
for (int i=0; i<JARLIST.length; i++) |
| 180 |
{ |
| 181 |
StringBuffer sb = new StringBuffer(); |
| 182 |
sb.append(PATH_TO_JARS_IN_PLUGIN); |
| 183 |
sb.append(JARLIST[i]); |
| 184 |
String jarName = sb.toString(); |
| 185 |
Status status = AddJar(p, AXIS_RUNTIME_PLUGIN_ID, jarName, env); |
| 186 |
if (status.getSeverity()==Status.ERROR) |
| 187 |
{ |
| 188 |
return status; |
| 189 |
} |
| 190 |
} |
| 191 |
return new SimpleStatus(""); |
| 192 |
} |
| 193 |
|
| 194 |
private Status AddJar(IProject webProject, String pluginId, String jarName, Environment env) { |
| 195 |
|
| 196 |
Status status = new SimpleStatus(""); |
| 197 |
// |
| 198 |
// Get the current classpath. |
| 199 |
// |
| 200 |
IJavaProject javaProject_ = null; |
| 201 |
IClasspathEntry[] oldClasspath = null; |
| 202 |
javaProject_ = JavaCore.create(webProject); |
| 203 |
try |
| 204 |
{ |
| 205 |
oldClasspath = javaProject_.getRawClasspath(); |
| 206 |
} |
| 207 |
catch(JavaModelException jme) |
| 208 |
{ |
| 209 |
status = new SimpleStatus("", msgUtils_.getMessage("MSG_ERROR_BAD_BUILDPATH"), Status.ERROR, jme); |
| 210 |
//env.getStatusHandler().reportError(status); |
| 211 |
return status; |
| 212 |
} |
| 213 |
|
| 214 |
|
| 215 |
boolean found = false; |
| 216 |
for (int i=0; i<oldClasspath.length; i++) |
| 217 |
{ |
| 218 |
found = found || oldClasspath[i].getPath().toString().toLowerCase().endsWith(jarName.toLowerCase()); |
| 219 |
} |
| 220 |
|
| 221 |
if (found) |
| 222 |
{ |
| 223 |
return status; |
| 224 |
} |
| 225 |
|
| 226 |
IClasspathEntry[] newClasspath = new IClasspathEntry[oldClasspath.length + 1]; |
| 227 |
int i=0; |
| 228 |
while (i<oldClasspath.length) |
| 229 |
{ |
| 230 |
newClasspath[i] = oldClasspath[i]; |
| 231 |
i++; |
| 232 |
} |
| 233 |
|
| 234 |
try |
| 235 |
{ |
| 236 |
|
| 237 |
newClasspath[i++] = JavaCore.newLibraryEntry(getTheJarPath(pluginId,jarName), null, null); |
| 238 |
|
| 239 |
} |
| 240 |
catch (CoreException e) |
| 241 |
{ |
| 242 |
status = new SimpleStatus("", msgUtils_.getMessage("MSG_ERROR_BAD_BUILDPATH"), Status.ERROR, e); |
| 243 |
return status; |
| 244 |
} |
| 245 |
|
| 246 |
// |
| 247 |
// Then update the project classpath. |
| 248 |
// |
| 249 |
try |
| 250 |
{ |
| 251 |
ProgressMonitor monitor = env.getProgressMonitor(); |
| 252 |
IProgressMonitor eclipseMonitor = null; |
| 253 |
if (monitor instanceof EclipseProgressMonitor) |
| 254 |
{ |
| 255 |
eclipseMonitor = ((EclipseProgressMonitor)monitor).getMonitor(); |
| 256 |
} |
| 257 |
javaProject_.setRawClasspath(newClasspath,eclipseMonitor); |
| 258 |
} |
| 259 |
catch (JavaModelException e) |
| 260 |
{ |
| 261 |
status = new SimpleStatus("", msgUtils_.getMessage("MSG_ERROR_BAD_BUILDPATH"), Status.ERROR, e); |
| 262 |
return status; |
| 263 |
} |
| 264 |
|
| 265 |
return status; |
| 266 |
} |
| 267 |
|
| 268 |
// |
| 269 |
// Returns the local native pathname of the jar. |
| 270 |
// |
| 271 |
private IPath getTheJarPath(String pluginId, String theJar) |
| 272 |
throws CoreException { |
| 273 |
try { |
| 274 |
if (pluginId != null) { |
| 275 |
IPluginRegistry pluginRegistry = Platform.getPluginRegistry(); |
| 276 |
IPluginDescriptor pluginDescriptor = |
| 277 |
pluginRegistry.getPluginDescriptor(pluginId); |
| 278 |
URL localURL = |
| 279 |
Platform.asLocalURL( |
| 280 |
new URL(pluginDescriptor.getInstallURL(), theJar)); |
| 281 |
return new Path(localURL.getFile()); |
| 282 |
} else { |
| 283 |
return new Path(theJar); |
| 284 |
} |
| 285 |
} catch (MalformedURLException e) { |
| 286 |
throw new CoreException( |
| 287 |
new org.eclipse.core.runtime.Status( |
| 288 |
IStatus.WARNING, |
| 289 |
WebServiceAxisConsumptionUIPlugin.ID, |
| 290 |
0, |
| 291 |
msgUtils_.getMessage("MSG_BAD_AXIS_JAR_URL"), |
| 292 |
e)); |
| 293 |
} catch (IOException e) { |
| 294 |
throw new CoreException( |
| 295 |
new org.eclipse.core.runtime.Status( |
| 296 |
IStatus.WARNING, |
| 297 |
WebServiceAxisConsumptionUIPlugin.ID, |
| 298 |
0, |
| 299 |
msgUtils_.getMessage("MSG_BAD_AXIS_JAR_URL"), |
| 300 |
e)); |
| 301 |
} |
| 302 |
} |
| 303 |
|
| 130 |
public void setProject(IProject project) { |
304 |
public void setProject(IProject project) { |
| 131 |
this.project = project; |
305 |
this.project = project; |
| 132 |
} |
306 |
} |