|
Lines 12-40
Link Here
|
| 12 |
* 20060324 122799 rsinha@ca.ibm.com - Rupam Kuehner |
12 |
* 20060324 122799 rsinha@ca.ibm.com - Rupam Kuehner |
| 13 |
* 20060503 138478 rsinha@ca.ibm.com - Rupam Kuehner |
13 |
* 20060503 138478 rsinha@ca.ibm.com - Rupam Kuehner |
| 14 |
* 20060510 141115 rsinha@ca.ibm.com - Rupam Kuehner |
14 |
* 20060510 141115 rsinha@ca.ibm.com - Rupam Kuehner |
|
|
15 |
* 20071212 200193 gilberta@ca.ibm.com - Gilbert Andrews |
| 15 |
*******************************************************************************/ |
16 |
*******************************************************************************/ |
| 16 |
package org.eclipse.jst.ws.internal.consumption.ui.widgets.test.wssample; |
17 |
package org.eclipse.jst.ws.internal.consumption.ui.widgets.test.wssample; |
| 17 |
|
18 |
|
| 18 |
import java.io.IOException; |
19 |
import java.io.IOException; |
| 19 |
import java.util.List; |
|
|
| 20 |
|
20 |
|
| 21 |
import org.eclipse.core.resources.IProject; |
21 |
import org.eclipse.core.resources.IProject; |
| 22 |
import org.eclipse.core.runtime.CoreException; |
22 |
import org.eclipse.core.runtime.CoreException; |
| 23 |
import org.eclipse.core.runtime.IAdaptable; |
23 |
import org.eclipse.core.runtime.IAdaptable; |
| 24 |
import org.eclipse.core.runtime.IProgressMonitor; |
24 |
import org.eclipse.core.runtime.IProgressMonitor; |
| 25 |
import org.eclipse.core.runtime.IStatus; |
25 |
import org.eclipse.core.runtime.IStatus; |
| 26 |
import org.eclipse.core.runtime.NullProgressMonitor; |
|
|
| 27 |
import org.eclipse.core.runtime.Status; |
26 |
import org.eclipse.core.runtime.Status; |
| 28 |
import org.eclipse.jdt.core.IClasspathEntry; |
|
|
| 29 |
import org.eclipse.jdt.core.IJavaProject; |
| 30 |
import org.eclipse.jdt.core.JavaCore; |
| 31 |
import org.eclipse.jdt.core.JavaModelException; |
| 32 |
import org.eclipse.jem.util.emf.workbench.ProjectUtilities; |
27 |
import org.eclipse.jem.util.emf.workbench.ProjectUtilities; |
| 33 |
import org.eclipse.jst.j2ee.commonarchivecore.internal.helpers.ArchiveManifest; |
|
|
| 34 |
import org.eclipse.jst.j2ee.internal.plugin.IJ2EEModuleConstants; |
28 |
import org.eclipse.jst.j2ee.internal.plugin.IJ2EEModuleConstants; |
| 35 |
import org.eclipse.jst.j2ee.internal.project.J2EEProjectUtilities; |
|
|
| 36 |
import org.eclipse.jst.j2ee.project.facet.IJavaProjectMigrationDataModelProperties; |
| 37 |
import org.eclipse.jst.j2ee.project.facet.JavaProjectMigrationDataModelProvider; |
| 38 |
import org.eclipse.jst.ws.internal.common.J2EEUtils; |
29 |
import org.eclipse.jst.ws.internal.common.J2EEUtils; |
| 39 |
import org.eclipse.jst.ws.internal.consumption.command.common.AddModuleToServerCommand; |
30 |
import org.eclipse.jst.ws.internal.consumption.command.common.AddModuleToServerCommand; |
| 40 |
import org.eclipse.jst.ws.internal.consumption.command.common.AssociateModuleWithEARCommand; |
31 |
import org.eclipse.jst.ws.internal.consumption.command.common.AssociateModuleWithEARCommand; |
|
Lines 45-59
Link Here
|
| 45 |
import org.eclipse.jst.ws.internal.consumption.ui.common.ValidationUtils; |
36 |
import org.eclipse.jst.ws.internal.consumption.ui.common.ValidationUtils; |
| 46 |
import org.eclipse.osgi.util.NLS; |
37 |
import org.eclipse.osgi.util.NLS; |
| 47 |
import org.eclipse.wst.command.internal.env.core.common.StatusUtils; |
38 |
import org.eclipse.wst.command.internal.env.core.common.StatusUtils; |
| 48 |
import org.eclipse.wst.common.componentcore.ComponentCore; |
|
|
| 49 |
import org.eclipse.wst.common.componentcore.datamodel.properties.ICreateReferenceComponentsDataModelProperties; |
| 50 |
import org.eclipse.wst.common.componentcore.internal.operation.CreateReferenceComponentsDataModelProvider; |
| 51 |
import org.eclipse.wst.common.componentcore.internal.util.ComponentUtilities; |
| 52 |
import org.eclipse.wst.common.componentcore.resources.IVirtualComponent; |
| 53 |
import org.eclipse.wst.common.environment.IEnvironment; |
39 |
import org.eclipse.wst.common.environment.IEnvironment; |
| 54 |
import org.eclipse.wst.common.frameworks.datamodel.AbstractDataModelOperation; |
40 |
import org.eclipse.wst.common.frameworks.datamodel.AbstractDataModelOperation; |
| 55 |
import org.eclipse.wst.common.frameworks.datamodel.DataModelFactory; |
|
|
| 56 |
import org.eclipse.wst.common.frameworks.datamodel.IDataModel; |
| 57 |
import org.eclipse.wst.ws.internal.wsrt.TestInfo; |
41 |
import org.eclipse.wst.ws.internal.wsrt.TestInfo; |
| 58 |
|
42 |
|
| 59 |
public class AddModuleDependenciesCommand extends AbstractDataModelOperation |
43 |
public class AddModuleDependenciesCommand extends AbstractDataModelOperation |
|
Lines 203-216
Link Here
|
| 203 |
|
187 |
|
| 204 |
if (clientIProject != null && !J2EEUtils.isWebComponent(clientIProject)) { |
188 |
if (clientIProject != null && !J2EEUtils.isWebComponent(clientIProject)) { |
| 205 |
if (J2EEUtils.isJavaComponent(clientIProject)) { |
189 |
if (J2EEUtils.isJavaComponent(clientIProject)) { |
| 206 |
addJavaProjectAsUtilityJar(clientIProject, sampleEARIProject, monitor); |
190 |
J2EEUtils.addJavaProjectAsUtilityJar(clientIProject, sampleEARIProject, monitor); |
| 207 |
addJavaProjectAsUtilityJar(clientIProject, sampleIProject,monitor); |
191 |
J2EEUtils.addJavaProjectAsUtilityJar(clientIProject, sampleIProject,monitor); |
| 208 |
} |
192 |
} |
| 209 |
|
193 |
|
| 210 |
try |
194 |
try |
| 211 |
{ |
195 |
{ |
| 212 |
String uri = clientIProject.getName() + ".jar"; |
196 |
String uri = clientIProject.getName() + ".jar"; |
| 213 |
addJAROrModuleDependency(sampleIProject, uri); |
197 |
J2EEUtils.addJAROrModuleDependency(sampleIProject, uri); |
| 214 |
} catch (CoreException ce) |
198 |
} catch (CoreException ce) |
| 215 |
{ |
199 |
{ |
| 216 |
String errorMessage = NLS.bind(ConsumptionUIMessages.MSG_ERROR_MODULE_DEPENDENCY, new String[]{sampleIProject.getName(), clientIProject.getName()}); |
200 |
String errorMessage = NLS.bind(ConsumptionUIMessages.MSG_ERROR_MODULE_DEPENDENCY, new String[]{sampleIProject.getName(), clientIProject.getName()}); |
|
Lines 223-292
Link Here
|
| 223 |
env.getStatusHandler().reportError(errorStatus); |
207 |
env.getStatusHandler().reportError(errorStatus); |
| 224 |
} |
208 |
} |
| 225 |
|
209 |
|
| 226 |
try { |
210 |
|
| 227 |
addBuildPath(sampleIProject, clientIProject); |
|
|
| 228 |
} catch (JavaModelException jme) { |
| 229 |
// Do nothing in this catch block. The worst that |
| 230 |
// will happen is that the sample Web project |
| 231 |
// will show some compile errors. The sample will |
| 232 |
// likely still launch successfully on the server |
| 233 |
// and the user will be able to use it. |
| 234 |
} |
| 235 |
} |
211 |
} |
| 236 |
|
212 |
|
| 237 |
return Status.OK_STATUS; |
213 |
return Status.OK_STATUS; |
| 238 |
} |
214 |
} |
| 239 |
|
215 |
|
| 240 |
private void addJAROrModuleDependency(IProject project, String uri) throws IOException, CoreException |
|
|
| 241 |
{ |
| 242 |
if (J2EEUtils.isWebComponent(project)) |
| 243 |
{ |
| 244 |
ArchiveManifest manifest = J2EEProjectUtilities.readManifest(project); |
| 245 |
manifest.mergeClassPath(new String[]{uri}); |
| 246 |
J2EEProjectUtilities.writeManifest(project, manifest); |
| 247 |
} |
| 248 |
} |
| 249 |
|
| 250 |
private void addJavaProjectAsUtilityJar(IProject javaProject, IProject earProject,IProgressMonitor monitor) |
| 251 |
{ |
| 252 |
try { |
| 253 |
IDataModel migrationdm = DataModelFactory.createDataModel(new JavaProjectMigrationDataModelProvider()); |
| 254 |
migrationdm.setProperty(IJavaProjectMigrationDataModelProperties.PROJECT_NAME, javaProject.getName()); |
| 255 |
migrationdm.getDefaultOperation().execute(monitor, null); |
| 256 |
|
| 257 |
|
| 258 |
IDataModel refdm = DataModelFactory.createDataModel(new CreateReferenceComponentsDataModelProvider()); |
| 259 |
List targetCompList = (List) refdm.getProperty(ICreateReferenceComponentsDataModelProperties.TARGET_COMPONENT_LIST); |
| 260 |
|
216 |
|
| 261 |
IVirtualComponent targetcomponent = ComponentCore.createComponent(javaProject); |
|
|
| 262 |
IVirtualComponent sourcecomponent = ComponentUtilities.getComponent(earProject.getName()); |
| 263 |
targetCompList.add(targetcomponent); |
| 264 |
|
| 265 |
refdm.setProperty(ICreateReferenceComponentsDataModelProperties.SOURCE_COMPONENT,sourcecomponent ); |
| 266 |
refdm.setProperty(ICreateReferenceComponentsDataModelProperties.TARGET_COMPONENT_LIST, targetCompList); |
| 267 |
refdm.setProperty(ICreateReferenceComponentsDataModelProperties.TARGET_COMPONENTS_DEPLOY_PATH, "/WEB-INF/lib"); |
| 268 |
refdm.getDefaultOperation().execute(monitor, null); |
| 269 |
}catch (Exception e) { |
| 270 |
|
| 271 |
} |
| 272 |
} |
| 273 |
|
217 |
|
| 274 |
|
218 |
|
| 275 |
private void addBuildPath(IProject referencingProject, IProject referencedProject) throws JavaModelException |
|
|
| 276 |
{ |
| 277 |
IJavaProject javaProject = JavaCore.create(referencingProject); |
| 278 |
if (javaProject != null) |
| 279 |
{ |
| 280 |
IClasspathEntry[] oldCp = javaProject.getRawClasspath(); |
| 281 |
IClasspathEntry[] newCp = new IClasspathEntry[oldCp.length + 1]; |
| 282 |
for (int i = 0; i < oldCp.length; i++) |
| 283 |
newCp[i] = oldCp[i]; |
| 284 |
newCp[newCp.length - 1] = JavaCore.newProjectEntry(referencedProject.getFullPath()); |
| 285 |
javaProject.setRawClasspath(newCp, new NullProgressMonitor()); |
| 286 |
} |
| 287 |
} |
| 288 |
|
| 289 |
|
| 290 |
public static final String DEFAULT_SAMPLE_EAR_PROJECT_EXT = "EAR"; |
219 |
public static final String DEFAULT_SAMPLE_EAR_PROJECT_EXT = "EAR"; |
| 291 |
|
220 |
|
| 292 |
} |
221 |
} |