Index: J2EEFlexProjDeployable.java =================================================================== RCS file: /cvsroot/webtools/jst/components/j2ee/plugins/org.eclipse.jst.j2ee/j2eeplugin/org/eclipse/jst/j2ee/internal/deployables/J2EEFlexProjDeployable.java,v retrieving revision 1.58 diff -u -r1.58 J2EEFlexProjDeployable.java --- J2EEFlexProjDeployable.java 15 May 2006 14:23:20 -0000 1.58 +++ J2EEFlexProjDeployable.java 30 Aug 2006 20:42:52 -0000 @@ -10,21 +10,30 @@ *******************************************************************************/ package org.eclipse.jst.j2ee.internal.deployables; +import java.io.File; import java.net.URL; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Properties; +import org.eclipse.core.commands.operations.IUndoableOperation; import org.eclipse.core.resources.IContainer; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.IWorkspaceRoot; +import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.Path; +import org.eclipse.jdt.core.IClasspathAttribute; +import org.eclipse.jdt.core.IClasspathEntry; import org.eclipse.jdt.core.IJavaProject; import org.eclipse.jdt.core.IPackageFragmentRoot; +import org.eclipse.jdt.core.JavaModelException; import org.eclipse.jem.workbench.utility.JemProjectUtilities; +import org.eclipse.jst.j2ee.application.internal.operations.ClasspathElement; import org.eclipse.jst.j2ee.componentcore.util.EARArtifactEdit; import org.eclipse.jst.j2ee.ejb.EJBJar; import org.eclipse.jst.j2ee.internal.EjbModuleExtensionHelper; @@ -46,6 +55,10 @@ import org.eclipse.wst.common.componentcore.resources.IVirtualFolder; import org.eclipse.wst.common.componentcore.resources.IVirtualReference; import org.eclipse.wst.server.core.IModule; +import org.eclipse.wst.server.core.ServerUtil; +import org.eclipse.wst.server.core.internal.Module; +import org.eclipse.wst.server.core.internal.ModuleFactory; +import org.eclipse.wst.server.core.internal.ModuleFile; import org.eclipse.wst.server.core.internal.ModuleFolder; import org.eclipse.wst.server.core.model.IModuleFolder; import org.eclipse.wst.server.core.model.IModuleResource; @@ -147,6 +160,42 @@ members.addAll(consumableMembers); } + if (J2EEProjectUtilities.isDynamicWebProject(getProject()) || J2EEProjectUtilities.isEARProject(getProject())) { + IJavaProject proj = JemProjectUtilities.getJavaProject(getProject()); + if (proj != null) { + IClasspathEntry[] classpathEntries = proj.getResolvedClasspath(true); + for (int i = 0; i < classpathEntries.length; i++) { + IClasspathEntry classpathEntry = classpathEntries[i]; + if (classpathEntry.getEntryKind() == IClasspathEntry.CPE_LIBRARY + && classpathEntry.getContentKind() == IPackageFragmentRoot.K_BINARY + && isDeployable(classpathEntry)) { + IPath archivePath = classpathEntry.getPath(); + File extFile = archivePath.toFile(); + if (extFile.exists()) { + IPath placementPath = Path.EMPTY; + if (J2EEProjectUtilities.isDynamicWebProject(getProject())) { + placementPath = new Path("WEB-INF/lib"); + } + ModuleFile mf = new ModuleFile(extFile, extFile.getName(), placementPath); + IModuleResource moduleParent = getExistingModuleResource(members, mf.getModuleRelativePath()); + + if (moduleParent != null && moduleParent instanceof ModuleFolder) + addMembersToModuleFolder((ModuleFolder)moduleParent, new IModuleResource[]{mf}); + else { + if (mf.getModuleRelativePath().isEmpty()) + members.add(mf); + else { + if (moduleParent == null) + moduleParent = ensureParentExists(mf.getModuleRelativePath(), (IContainer)vc.getRootFolder().getUnderlyingResource()); + addMembersToModuleFolder((ModuleFolder)moduleParent, new IModuleResource[] {mf}); + } + } + } + } + } + } + } + IModuleResource[] mr = new IModuleResource[members.size()]; members.toArray(mr); return mr; @@ -284,7 +333,11 @@ if (module != null && J2EEProjectUtilities.isUtilityProject(module.getProject())) { IVirtualComponent webComp = ComponentCore.createComponent(component.getProject()); IVirtualReference reference = webComp.getReference(module.getProject().getName()); - aURI = ComponentUtilities.getDeployUriOfUtilComponent(reference); + if (reference != null) { + aURI = ComponentUtilities.getDeployUriOfUtilComponent(reference); + } else { + aURI = "WEB-INF/lib/" + module.getProject().getName() + ".jar"; + } }else{ aURI = component.getDeployedName()+IJ2EEModuleConstants.WAR_EXT; } @@ -411,4 +464,64 @@ } return consumableMembers; } + + public IModule[] getModules() { + List modules = new ArrayList(Arrays.asList(super.getModules())); + + if (J2EEProjectUtilities.isDynamicWebProject(getProject()) || J2EEProjectUtilities.isEARProject(getProject())) { + IJavaProject proj = JemProjectUtilities.getJavaProject(getProject()); + if (proj != null) { + IClasspathEntry[] classpathEntries = new IClasspathEntry[0]; + try { + classpathEntries = proj.getResolvedClasspath(true); + for (int i = 0; i < classpathEntries.length; i++) { + IClasspathEntry classpathEntry = classpathEntries[i]; + if (classpathEntry.getEntryKind() == IClasspathEntry.CPE_PROJECT + && isDeployable(classpathEntry)) { + IWorkspaceRoot root= ResourcesPlugin.getWorkspace().getRoot(); + IProject project = (IProject) root.findMember(classpathEntry.getPath()); + if (!project.hasNature(IModuleConstants.MODULE_NATURE_ID)) { + IUndoableOperation op = J2EEProjectUtilities.createFlexJavaProjectForProjectOperation(project); + op.execute(null, null); + } + + IModule module = ServerUtil.getModule(project); + if (!modules.contains(module)) { + modules.add(module); + } + } + } + } catch (Exception e) { + // TODO: handle exception. Throwing it as I don't know what the standard is here, or even how to log it + throw new RuntimeException(e); + } + } + } + + IModule[] childModules = new IModule[modules.size()]; + return (IModule[]) modules.toArray(childModules); + } + + private IModule buildInMemoryModule(IProject project) { + // Add the necessary nature + + // Get the correct factory - this may not be necessary given we are adding the nature? + Module thisModule = (Module) getModule(); + J2EEDeployableFactory fact = (J2EEDeployableFactory) thisModule.getModuleFactory().getDelegate(null); + return fact.createModule(project); + } + + + private boolean isDeployable(IClasspathEntry classpathEntry) { + IClasspathAttribute[] attrs = classpathEntry.getExtraAttributes(); + boolean deploy = false; + for (int j = 0; j < attrs.length; j++) { + IClasspathAttribute attribute = attrs[j]; + if (attribute.getName().equals("org.eclipse.jst.j2ee.deployableArtifact") && attribute.getValue().equalsIgnoreCase("true")) { + deploy = true; + break; + } + } + return deploy; + } } \ No newline at end of file