diff options
author | cbridgha | 2006-06-06 20:35:39 +0000 |
---|---|---|
committer | cbridgha | 2006-06-06 20:35:39 +0000 |
commit | 55a5a1d39e6d8cbf491bd449fd33116706e1ead8 (patch) | |
tree | 2906aba5390b2e8c057280565c5ca3779cb72c09 /plugins/org.eclipse.jst.j2ee/earproject/org/eclipse/jst/j2ee | |
parent | ad27b650b09d77e61ad6c40784679bb25a8a2ee0 (diff) | |
download | webtools.javaee-55a5a1d39e6d8cbf491bd449fd33116706e1ead8.tar.gz webtools.javaee-55a5a1d39e6d8cbf491bd449fd33116706e1ead8.tar.xz webtools.javaee-55a5a1d39e6d8cbf491bd449fd33116706e1ead8.zip |
[144023] JS classpath improvements.
Diffstat (limited to 'plugins/org.eclipse.jst.j2ee/earproject/org/eclipse/jst/j2ee')
3 files changed, 195 insertions, 90 deletions
diff --git a/plugins/org.eclipse.jst.j2ee/earproject/org/eclipse/jst/j2ee/application/internal/operations/AddComponentToEnterpriseApplicationOp.java b/plugins/org.eclipse.jst.j2ee/earproject/org/eclipse/jst/j2ee/application/internal/operations/AddComponentToEnterpriseApplicationOp.java index 279a1cf4a..9c8a89290 100644 --- a/plugins/org.eclipse.jst.j2ee/earproject/org/eclipse/jst/j2ee/application/internal/operations/AddComponentToEnterpriseApplicationOp.java +++ b/plugins/org.eclipse.jst.j2ee/earproject/org/eclipse/jst/j2ee/application/internal/operations/AddComponentToEnterpriseApplicationOp.java @@ -34,7 +34,6 @@ import org.eclipse.jst.j2ee.application.WebModule; import org.eclipse.jst.j2ee.componentcore.util.EARArtifactEdit; import org.eclipse.jst.j2ee.internal.J2EEConstants; import org.eclipse.jst.j2ee.internal.common.classpath.J2EEComponentClasspathUpdater; -import org.eclipse.jst.j2ee.internal.common.classpath.J2EEComponentReferenceUpdater; import org.eclipse.jst.j2ee.internal.project.J2EEProjectUtilities; import org.eclipse.jst.j2ee.project.facet.EarFacetRuntimeHandler; import org.eclipse.wst.common.componentcore.datamodel.properties.ICreateReferenceComponentsDataModelProperties; @@ -45,6 +44,7 @@ import org.eclipse.wst.common.componentcore.internal.operation.CreateReferenceCo import org.eclipse.wst.common.componentcore.internal.util.IModuleConstants; import org.eclipse.wst.common.componentcore.resources.IVirtualComponent; import org.eclipse.wst.common.frameworks.datamodel.IDataModel; +import org.eclipse.wst.common.frameworks.internal.DoNotUseMeThisWillBeDeletedPost15; import org.eclipse.wst.common.project.facet.core.IFacetedProject; import org.eclipse.wst.common.project.facet.core.IProjectFacet; import org.eclipse.wst.common.project.facet.core.ProjectFacetsManager; @@ -58,7 +58,7 @@ public class AddComponentToEnterpriseApplicationOp extends CreateReferenceCompon public IStatus execute(IProgressMonitor monitor, IAdaptable info) throws ExecutionException { if (monitor != null) { - monitor.beginTask("", 4); + monitor.beginTask("", 3); } try { @@ -68,7 +68,6 @@ public class AddComponentToEnterpriseApplicationOp extends CreateReferenceCompon return Status.CANCEL_STATUS; updateEARDD(submon(monitor, 1)); updateModuleRuntimes(submon(monitor, 1)); - updateManifestReferences(submon(monitor, 1)); return OK_STATUS; } finally { if (monitor != null) { @@ -99,14 +98,12 @@ public class AddComponentToEnterpriseApplicationOp extends CreateReferenceCompon /** + * {@link DoNotUseMeThisWillBeDeletedPost15} * For each module component added to the ear, references are created for every manifest entry. * * @param monitor */ protected void updateManifestReferences(IProgressMonitor monitor) { - IVirtualComponent earComponent = (IVirtualComponent) model.getProperty(ICreateReferenceComponentsDataModelProperties.SOURCE_COMPONENT); - IProject earProject = earComponent.getProject(); - J2EEComponentReferenceUpdater.updateReferences(earProject); } protected void updateEARDD(IProgressMonitor monitor) { diff --git a/plugins/org.eclipse.jst.j2ee/earproject/org/eclipse/jst/j2ee/componentcore/util/EARArtifactEdit.java b/plugins/org.eclipse.jst.j2ee/earproject/org/eclipse/jst/j2ee/componentcore/util/EARArtifactEdit.java index dcd6ab328..ad7eab8e8 100644 --- a/plugins/org.eclipse.jst.j2ee/earproject/org/eclipse/jst/j2ee/componentcore/util/EARArtifactEdit.java +++ b/plugins/org.eclipse.jst.j2ee/earproject/org/eclipse/jst/j2ee/componentcore/util/EARArtifactEdit.java @@ -21,7 +21,6 @@ import org.eclipse.core.resources.IProject; import org.eclipse.emf.common.util.URI; import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.ecore.resource.Resource; -import org.eclipse.jem.util.logger.proxy.Logger; import org.eclipse.jst.j2ee.application.Application; import org.eclipse.jst.j2ee.application.ApplicationFactory; import org.eclipse.jst.j2ee.application.ApplicationResource; @@ -43,9 +42,7 @@ import org.eclipse.wst.common.componentcore.UnresolveableURIException; import org.eclipse.wst.common.componentcore.internal.ArtifactEditModel; import org.eclipse.wst.common.componentcore.internal.ReferencedComponent; import org.eclipse.wst.common.componentcore.internal.StructureEdit; -import org.eclipse.wst.common.componentcore.internal.WorkbenchComponent; import org.eclipse.wst.common.componentcore.internal.impl.ModuleURIUtil; -import org.eclipse.wst.common.componentcore.internal.resources.VirtualArchiveComponent; import org.eclipse.wst.common.componentcore.internal.util.IArtifactEditFactory; import org.eclipse.wst.common.componentcore.internal.util.IModuleConstants; import org.eclipse.wst.common.componentcore.resources.IVirtualComponent; @@ -435,46 +432,13 @@ public class EARArtifactEdit extends EnterpriseArtifactEdit implements IArtifact } public String getModuleURI(IVirtualComponent moduleComp) { - - StructureEdit core = null; - try { - core = StructureEdit.getStructureEditForRead(getProject()); - WorkbenchComponent component = core.getComponent(); - List referencedComponents = component.getReferencedComponents(); - - for (int i = 0; i < referencedComponents.size(); i++) { - ReferencedComponent ref = (ReferencedComponent) referencedComponents.get(i); - if (!moduleComp.isBinary()) { - if (ref.getHandle().equals(ModuleURIUtil.fullyQualifyURI(moduleComp.getProject()))) { - if (ref.getDependentObject() != null) - return ((Module) ref.getDependentObject()).getUri(); - //If dependent object is not set, assume compname is module name + proper extension - if (J2EEProjectUtilities.isDynamicWebProject(moduleComp.getProject()) || J2EEProjectUtilities.isStaticWebProject(moduleComp.getProject())) - return moduleComp.getName() + IJ2EEModuleConstants.WAR_EXT; - if (J2EEProjectUtilities.isJCAProject(moduleComp.getProject())) - return moduleComp.getName() + IJ2EEModuleConstants.RAR_EXT; - if (J2EEProjectUtilities.isUtilityProject(moduleComp.getProject())) { - return getJarURI(ref, moduleComp); - } - return moduleComp.getName() + IJ2EEModuleConstants.JAR_EXT; - } - - } - else if (moduleComp.isBinary()) { - if (ref.getHandle().equals(ModuleURIUtil.archiveComponentfullyQualifyURI(moduleComp.getName()))) { - if (ref.getDependentObject()!=null) { - return ((Module) ref.getDependentObject()).getUri(); - } else { - return getJarURI(ref, moduleComp); - } - } - } + IVirtualReference [] refs = getComponent().getReferences(); + for(int i=0; i<refs.length; i++){ + if(refs[i].getReferencedComponent().equals(moduleComp)){ + return refs[i].getArchiveName(); } - } finally { - if (core != null) - core.dispose(); } - return null; + return null; } private String getJarURI(final ReferencedComponent ref, final IVirtualComponent moduleComp) { @@ -491,50 +455,13 @@ public class EARArtifactEdit extends EnterpriseArtifactEdit implements IArtifact } public IVirtualComponent getModuleByManifestURI(final String uri) { - StructureEdit core = null; - try { - core = StructureEdit.getStructureEditForRead(getProject()); - WorkbenchComponent component = core.getComponent(); - List referencedComponents = component.getReferencedComponents(); - - for (int i = 0; i < referencedComponents.size(); i++) { - ReferencedComponent ref = (ReferencedComponent) referencedComponents.get(i); - if (ref.getDependentObject() != null) { - Module module = (Module) ref.getDependentObject(); - if (uri.equals(module.getUri())) { - String componentName; - try { - componentName = ModuleURIUtil.getArchiveName(ref.getHandle()); - return getModule(componentName); - } catch (UnresolveableURIException e) { - Logger.getLogger().logError(e); - } - } - } else if (ref.getArchiveName().equals(uri)) { - String baseComponentName; - String archiveComponentNamme; - try { - baseComponentName = ModuleURIUtil.getArchiveName(ref.getHandle()); - archiveComponentNamme = VirtualArchiveComponent.LIBARCHIVETYPE + "/" + baseComponentName; - IVirtualReference[] references = getComponentReferences(); - IVirtualComponent comp = null; - String compName = null; - for (int j = 0; j < references.length; j++) { - comp = references[j].getReferencedComponent(); - compName = comp.getName(); - if (compName.equals(baseComponentName) || compName.equals(archiveComponentNamme)) { - return comp; - } - } - return null; - } catch (UnresolveableURIException e) { - Logger.getLogger().logError(e); - } - } + IVirtualComponent earComponent = ComponentCore.createComponent(getProject()); + IVirtualReference [] refs = earComponent.getReferences(); + + for(int i=0;i<refs.length; i++){ + if(refs[i].getArchiveName().equals(uri)){ + return refs[i].getReferencedComponent(); } - } finally { - if (core != null) - core.dispose(); } return null; } diff --git a/plugins/org.eclipse.jst.j2ee/earproject/org/eclipse/jst/j2ee/componentcore/util/EARVirtualComponent.java b/plugins/org.eclipse.jst.j2ee/earproject/org/eclipse/jst/j2ee/componentcore/util/EARVirtualComponent.java new file mode 100644 index 000000000..f45816543 --- /dev/null +++ b/plugins/org.eclipse.jst.j2ee/earproject/org/eclipse/jst/j2ee/componentcore/util/EARVirtualComponent.java @@ -0,0 +1,181 @@ +/******************************************************************************* + * Copyright (c) 2003, 2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jst.j2ee.componentcore.util; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.IResourceChangeEvent; +import org.eclipse.core.resources.IResourceChangeListener; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.Path; +import org.eclipse.jem.util.logger.proxy.Logger; +import org.eclipse.jst.j2ee.application.Module; +import org.eclipse.jst.j2ee.internal.common.classpath.J2EEComponentClasspathUpdater; +import org.eclipse.jst.j2ee.internal.plugin.IJ2EEModuleConstants; +import org.eclipse.jst.j2ee.internal.project.J2EEProjectUtilities; +import org.eclipse.wst.common.componentcore.ComponentCore; +import org.eclipse.wst.common.componentcore.internal.ReferencedComponent; +import org.eclipse.wst.common.componentcore.internal.StructureEdit; +import org.eclipse.wst.common.componentcore.internal.WorkbenchComponent; +import org.eclipse.wst.common.componentcore.internal.resources.VirtualArchiveComponent; +import org.eclipse.wst.common.componentcore.internal.resources.VirtualComponent; +import org.eclipse.wst.common.componentcore.internal.util.IComponentImplFactory; +import org.eclipse.wst.common.componentcore.resources.IVirtualComponent; +import org.eclipse.wst.common.componentcore.resources.IVirtualFolder; +import org.eclipse.wst.common.componentcore.resources.IVirtualReference; +import org.eclipse.wst.common.componentcore.resources.IVirtualResource; + +public class EARVirtualComponent extends VirtualComponent implements IComponentImplFactory { + + public EARVirtualComponent() { + super(); + } + + public EARVirtualComponent(IProject aProject, IPath aRuntimePath) { + super(aProject, aRuntimePath); + } + + public IVirtualComponent createComponent(IProject aProject) { + return new EARVirtualComponent(aProject, new Path("/")); //$NON-NLS-1$ + } + + private static String getJarURI(final ReferencedComponent ref, final IVirtualComponent moduleComp) { + String uri = ref.getArchiveName(); + if (uri == null || uri.length() < 0) { + uri = moduleComp.getName() + IJ2EEModuleConstants.JAR_EXT; + } else { + String prefix = ref.getRuntimePath().makeRelative().toString(); + if (prefix.length() > 0) { + uri = prefix + "/" + uri; //$NON-NLS-1$ + } + } + return uri; + } + + private static List getHardReferences(IVirtualComponent earComponent) { + StructureEdit core = null; + List hardReferences = new ArrayList(); + try { + core = StructureEdit.getStructureEditForRead(earComponent.getProject()); + if (core != null && core.getComponent() != null) { + WorkbenchComponent component = core.getComponent(); + if (component != null) { + List referencedComponents = component.getReferencedComponents(); + for (Iterator iter = referencedComponents.iterator(); iter.hasNext();) { + ReferencedComponent referencedComponent = (ReferencedComponent) iter.next(); + if (referencedComponent == null) + continue; + IVirtualReference vReference = StructureEdit.createVirtualReference(earComponent, referencedComponent); + if (vReference != null) { + IVirtualComponent referencedIVirtualComponent = vReference.getReferencedComponent(); + if (referencedIVirtualComponent != null && referencedIVirtualComponent.exists()) { + String archiveName = null; + if (referencedComponent.getDependentObject() != null) { + archiveName = ((Module) referencedComponent.getDependentObject()).getUri(); + } else { + if (referencedIVirtualComponent.isBinary()) { + archiveName = getJarURI(referencedComponent, referencedIVirtualComponent); + } else { + IProject referencedProject = referencedIVirtualComponent.getProject(); + // If dependent object is not set, assume + // compname is module name + proper + // extension + if (J2EEProjectUtilities.isDynamicWebProject(referencedProject) || J2EEProjectUtilities.isStaticWebProject(referencedProject)) { + archiveName = referencedIVirtualComponent.getName() + IJ2EEModuleConstants.WAR_EXT; + } else if (J2EEProjectUtilities.isJCAProject(referencedProject)) { + archiveName = referencedIVirtualComponent.getName() + IJ2EEModuleConstants.RAR_EXT; + } else if (J2EEProjectUtilities.isUtilityProject(referencedProject)) { + archiveName = getJarURI(referencedComponent, referencedIVirtualComponent); + } else { + archiveName = referencedIVirtualComponent.getName() + IJ2EEModuleConstants.JAR_EXT; + } + } + } + vReference.setArchiveName(archiveName); + hardReferences.add(vReference); + } + } + } + } + } + } finally { + if (core != null) + core.dispose(); + } + return hardReferences; + } + + private static List getLooseArchiveReferences(IVirtualComponent earComponent, List hardReferences) { + List dynamicReferences = null; + IVirtualFolder rootFolder = earComponent.getRootFolder(); + try { + IVirtualResource[] members = rootFolder.members(); + for (int i = 0; i < members.length; i++) { + if (IVirtualResource.FILE == members[i].getType()) { + String archiveName = members[i].getName(); + if (archiveName.toLowerCase().endsWith(".jar")) { + boolean shouldInclude = true; + for (int j = 0; j < hardReferences.size() && shouldInclude; j++) { + String tempArchiveName = ((IVirtualReference) hardReferences.get(j)).getArchiveName(); + if (null != tempArchiveName && tempArchiveName.equals(archiveName)) { + shouldInclude = false; + } + } + if (shouldInclude) { + IResource iResource = members[i].getUnderlyingResource(); + IVirtualComponent dynamicComponent = ComponentCore.createArchiveComponent(earComponent.getProject(), VirtualArchiveComponent.LIBARCHIVETYPE + iResource.getFullPath().toString()); + IVirtualReference dynamicRef = ComponentCore.createReference(earComponent, dynamicComponent); + dynamicRef.setArchiveName(archiveName); + if (null == dynamicReferences) { + dynamicReferences = new ArrayList(); + } + dynamicReferences.add(dynamicRef); + } + } + } + } + } catch (CoreException e) { + Logger.getLogger().logError(e); + } + return dynamicReferences; + } + + + public IVirtualReference[] getReferences() { + J2EEComponentClasspathUpdater.getInstance().trackEAR(getProject()); + List hardReferences = getHardReferences(this); + List dynamicReferences = getLooseArchiveReferences(this, hardReferences); + + if (dynamicReferences != null) { + hardReferences.addAll(dynamicReferences); + } + + return (IVirtualReference[]) hardReferences.toArray(new IVirtualReference[hardReferences.size()]); + } + + public IVirtualReference[] getAllReferences() { + // TODO Auto-generated method stub + return super.getAllReferences(); + } + + public void setReferences(IVirtualReference[] references) { + // TODO Auto-generated method stub + super.setReferences(references); + } + +} |