diff options
Diffstat (limited to 'plugins/org.eclipse.jst.j2ee/j2eecreation/org')
47 files changed, 0 insertions, 8993 deletions
diff --git a/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/componentcore/EnterpriseArtifactEdit.java b/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/componentcore/EnterpriseArtifactEdit.java deleted file mode 100644 index e90bf472a..000000000 --- a/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/componentcore/EnterpriseArtifactEdit.java +++ /dev/null @@ -1,359 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2003, 2007 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; - -import org.eclipse.core.resources.IProject; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.emf.common.util.URI; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.ecore.resource.Resource; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jst.common.jdt.internal.integration.JavaArtifactEditModel; -import org.eclipse.jst.common.jdt.internal.integration.WorkingCopyManager; -import org.eclipse.jst.common.jdt.internal.integration.WorkingCopyProvider; -import org.eclipse.jst.j2ee.commonarchivecore.internal.Archive; -import org.eclipse.jst.j2ee.commonarchivecore.internal.exception.OpenFailureException; -import org.eclipse.jst.j2ee.internal.project.J2EEProjectUtilities; -import org.eclipse.jst.j2ee.model.IModelProvider; -import org.eclipse.jst.j2ee.model.IModelProviderFactory; -import org.eclipse.jst.j2ee.model.IModelProviderListener; -import org.eclipse.wst.common.componentcore.ArtifactEdit; -import org.eclipse.wst.common.componentcore.ModuleCoreNature; -import org.eclipse.wst.common.componentcore.internal.ArtifactEditModel; -import org.eclipse.wst.common.componentcore.internal.impl.ModuleURIUtil; -import org.eclipse.wst.common.componentcore.resources.IVirtualComponent; -import org.eclipse.wst.common.internal.emfworkbench.integration.EditModelListener; -import org.eclipse.wst.common.project.facet.core.IFacetedProject; -import org.eclipse.wst.common.project.facet.core.ProjectFacetsManager; - -/** - * <p> - * EnterpriseArtifactEdit obtains a type-specific J2EE metamodel from the managed - * {@see org.eclipse.wst.common.modulecore.ArtifactEditModel}. The underlying EditModel maintains - * {@see org.eclipse.emf.ecore.resource.Resource}s, such as the J2EE deployment descriptor - * resource. The defined methods extract data or manipulate the contents of the underlying resource. - * </p> - * - * <p> - * This class is an abstract class, and clients are intended to subclass and own their - * implementation. - * </p> - */ -public abstract class EnterpriseArtifactEdit extends ArtifactEdit implements WorkingCopyProvider, IModelProvider, IModelProviderFactory { - - public static boolean SUPPORT_LEGACY_PROJECTS = true; - private ArtifactEdit writableEdit = null; - - /** - * - */ - protected EnterpriseArtifactEdit() { - super(); - } - - public EnterpriseArtifactEdit(IVirtualComponent aModule){ - super(aModule); - } - - - /** - * @param aHandle - * @param toAccessAsReadOnly - * @throws IllegalArgumentException - */ - public EnterpriseArtifactEdit(IProject aProject, boolean toAccessAsReadOnly) throws IllegalArgumentException { - super(aProject, toAccessAsReadOnly); - } - - /** - * @param aHandle - * @param toAccessAsReadOnly - * @throws IllegalArgumentException - */ - protected EnterpriseArtifactEdit(IProject aProject, boolean toAccessAsReadOnly, boolean forCreate, String projectType) throws IllegalArgumentException { - super(aProject, toAccessAsReadOnly, forCreate, projectType); - } - - /** - * <p> - * Creates an instance facade for the given {@see ArtifactEditModel}. - * </p> - * <p> - * Clients that use this constructor are required to release their access of the EditModel when - * finished. Calling {@see ArtifactEdit#dispose()}will not touch the supplied EditModel. - * </p> - * - * @param anArtifactEditModel - * A valid, properly-accessed EditModel - */ - public EnterpriseArtifactEdit(ArtifactEditModel model) { - super(model); - } - - /** - * <p> - * Creates an instance facade for the given {@see WorkbenchComponent}. - * </p> - * <p> - * Instances of EnterpriseArtifactEdit that are returned through this method must be - * {@see #dispose()}ed of when no longer in use. - * </p> - * <p> - * Note: This method is for internal use only. Clients should not call this method. - * </p> - * - * @param aNature - * A non-null {@see ModuleCoreNature} for an accessible project - * @param aModule - * A non-null {@see WorkbenchComponent} pointing to a module from the given - * {@see ModuleCoreNature} - */ - - protected EnterpriseArtifactEdit(ModuleCoreNature aNature, IVirtualComponent aModule, boolean toAccessAsReadOnly) { - super(aNature, aModule, toAccessAsReadOnly); - } - - /** - * <p> - * Retrieves J2EE version information from deployment descriptor resource. - * </p> - * - * @return An the J2EE Specification version of the underlying {@see WorkbenchComponent} - * - */ - public abstract int getJ2EEVersion(); - - /** - * <p> - * Retrieves a deployment descriptor resource from {@see ArtifactEditModel}using a defined URI. - * </p> - * - * @return The correct deployment descriptor resource for the underlying - * {@see WorkbenchComponent} - * - */ - public abstract Resource getDeploymentDescriptorResource(); - - /** - * <p> - * Obtains the root object from a deployment descriptor resource, the root object contains all - * other resource defined objects. Examples of a deployment descriptor root include: - * {@see org.eclipse.jst.j2ee.webapplication.WebApp}, - * {@see org.eclipse.jst.j2ee.application.Application}, and - * {@see org.eclipse.jst.j2ee.ejb.EJBJar} - * </p> - * <p> - * Subclasses may extend this method to perform their own deployment descriptor creataion/ - * retrieval. - * </p> - * - * @return An EMF metamodel object representing the J2EE deployment descriptor - * - */ - - public EObject getDeploymentDescriptorRoot() { - Resource res = getDeploymentDescriptorResource(); - if (!res.getContents().isEmpty()) - return (EObject) res.getContents().get(0); - return null; - } - - /** - * Returns a working copy managet - * - * @return - */ - - public WorkingCopyManager getWorkingCopyManager() { - if(isBinary()){ - throwAttemptedBinaryEditModelAccess(); - } - return ((JavaArtifactEditModel)getArtifactEditModel()).getWorkingCopyManager(); - } - - /** - * Returns the working copy remembered for the compilation unit. - * - * @param input - * ICompilationUnit - * @return the working copy of the compilation unit, or <code>null</code> if there is no - * remembered working copy for this compilation unit - */ - public ICompilationUnit getWorkingCopy(ICompilationUnit cu, boolean forNewCU) throws org.eclipse.core.runtime.CoreException { - if (isReadOnly()) - return null; - return getWorkingCopyManager().getWorkingCopy(cu, forNewCU); - } - protected boolean validProjectVersion(IProject project) { - - return EnterpriseArtifactEdit.SUPPORT_LEGACY_PROJECTS || primValidProjectVersion(project); - } -protected boolean primValidProjectVersion(IProject project) { - - // Return true if project is being created - if (!project.exists()) return true; - IFacetedProject facetedProject = null; - try { - facetedProject = ProjectFacetsManager.create(project); - } catch (CoreException e) { - // Do Nothing - } - if (facetedProject == null) - // Return true if project facet is being created - return true; - //return true for legacy projects, or use preference. - return !J2EEProjectUtilities.isJEEProject(project); - } - - /** - * Returns the working copy remembered for the compilation unit encoded in the given editor - * input. Does not connect the edit model to the working copy. - * - * @param input - * ICompilationUnit - * @return the working copy of the compilation unit, or <code>null</code> if the input does - * not encode an editor input, or if there is no remembered working copy for this - * compilation unit - */ - public ICompilationUnit getExistingWorkingCopy(ICompilationUnit cu) throws org.eclipse.core.runtime.CoreException { - return getWorkingCopyManager().getExistingWorkingCopy(cu); - } - - public URI getModuleLocation(String moduleName) { - if (getProject()!=null) - return ModuleURIUtil.fullyQualifyURI(getProject()); - return null; - } - - /** - * This will delete - * - * @cu from the workbench and fix the internal references for this working copy manager. - */ - public void delete(org.eclipse.jdt.core.ICompilationUnit cu, org.eclipse.core.runtime.IProgressMonitor monitor) { - getWorkingCopyManager().delete(cu, monitor); - } - - /** - * <p> - * Create an deployment descriptor resource if one does not get and return it. Subclasses should - * overwrite this method to create their own type of deployment descriptor - * </p> - * - * @return an EObject - */ - - public abstract EObject createModelRoot(); - - /** - * <p> - * Create an deployment descriptor resource if one does not get and return it. Subclasses should - * overwrite this method to create their own type of deployment descriptor - * </p> - * - * @param int - * version of the component - * @return an EObject - */ - - public abstract EObject createModelRoot(int version); - - public Archive asArchive(boolean includeSource) throws OpenFailureException{ - return asArchive(includeSource, true); - } - - public Archive asArchive(boolean includeSource, boolean includeClasspathComponents) throws OpenFailureException { - return null; - } - - /* (non-Javadoc) - * @see org.eclipse.jst.j2ee.model.IModelProvider#getModelObject() - */ - public Object getModelObject() { - if ( getWritableEdit() != null) - return getWritableEdit().getContentModelRoot(); - return getContentModelRoot(); - } - - /* (non-Javadoc) - * @see org.eclipse.jst.j2ee.model.IModelProvider#getModelObject(org.eclipse.core.runtime.IPath) - */ - public Object getModelObject(IPath modelPath) { - if ( getWritableEdit() != null) { - Resource res = ((ArtifactEditModel)getWritableEdit().getAdapter(ArtifactEditModel.ADAPTER_TYPE)).getResource(URI.createURI(modelPath.toString())); - if (res != null && !res.getContents().isEmpty()) - return res.getContents().get(0); - else return null; - } - return getContentModelRoot(); - } - - public IModelProvider create(IProject project) { - return (IModelProvider)getArtifactEditForRead(project); - } - - public IModelProvider create(IVirtualComponent component) { - return (IModelProvider)getArtifactEditForRead(component); - } - - /* (non-Javadoc) - * @see org.eclipse.jst.j2ee.model.IModelProvider#modify(java.lang.Runnable, org.eclipse.core.runtime.IPath) - */ - public void modify(Runnable runnable, IPath modelPath) { - //About to modify and save this model - - // access model (write count) - // cache writable model (setWriteableEdit()) - // run runnable - // save model - // release access count - // null Writable Edit - - } - - public IStatus validateEdit(IPath modelPath, Object context) { - // ArtifactEdit will validate all files it manages, and uses its own context mechanism - return validateEdit(); - } - - /** - * @param writableEdit the writableEdit to set - */ - protected void setWritableEdit(ArtifactEdit writableEdit) { - this.writableEdit = writableEdit; - } - - /** - * @return the writableEdit - */ - protected ArtifactEdit getWritableEdit() { - return writableEdit; - } - - public void addListener(IModelProviderListener listener) - { - if (listener instanceof EditModelListener) - { - addListener((EditModelListener)listener); - } - } - - public void removeListener(IModelProviderListener listener) - { - if (listener instanceof EditModelListener) - { - removeListener((EditModelListener)listener); - } - } -} diff --git a/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/componentcore/J2EEModuleVirtualArchiveComponent.java b/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/componentcore/J2EEModuleVirtualArchiveComponent.java deleted file mode 100644 index 1c31884a5..000000000 --- a/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/componentcore/J2EEModuleVirtualArchiveComponent.java +++ /dev/null @@ -1,64 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2006 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; - -import java.util.List; - -import org.eclipse.core.resources.IProject; -import org.eclipse.core.runtime.IPath; -import org.eclipse.jst.j2ee.commonarchivecore.internal.helpers.ArchiveManifest; -import org.eclipse.jst.j2ee.internal.project.J2EEProjectUtilities; -import org.eclipse.wst.common.componentcore.internal.resources.VirtualArchiveComponent; -import org.eclipse.wst.common.componentcore.internal.resources.VirtualReference; -import org.eclipse.wst.common.componentcore.resources.IVirtualReference; - -public class J2EEModuleVirtualArchiveComponent extends VirtualArchiveComponent { - - protected static final IVirtualReference[] NO_REFERENCES = new VirtualReference[0]; - - private boolean linkedToEAR = true; - - protected String[] manifestClasspath; - - public J2EEModuleVirtualArchiveComponent(IProject aComponentProject, String archiveLocation, IPath aRuntimePath) { - super(aComponentProject, archiveLocation, aRuntimePath); - } - - public IVirtualReference[] getReferences() { - List dynamicReferences = J2EEModuleVirtualComponent.getManifestReferences(this, null); - if (null == dynamicReferences) { - return NO_REFERENCES; - } - return (IVirtualReference[]) dynamicReferences.toArray(new IVirtualReference[dynamicReferences.size()]); - } - - public String[] getManifestClasspath() { - if (null == manifestClasspath) { - ArchiveManifest manifest = J2EEProjectUtilities.readManifest(this); - if (manifest != null) { - manifestClasspath = manifest.getClassPathTokenized(); - } - if (manifestClasspath == null) { - manifestClasspath = new String[0]; - } - } - return manifestClasspath; - } - - public void setLinkedToEAR(boolean linkedToEAR) { - this.linkedToEAR = linkedToEAR; - } - - public boolean isLinkedToEAR() { - return linkedToEAR; - } - -} diff --git a/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/componentcore/J2EEModuleVirtualComponent.java b/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/componentcore/J2EEModuleVirtualComponent.java deleted file mode 100644 index 948d65eee..000000000 --- a/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/componentcore/J2EEModuleVirtualComponent.java +++ /dev/null @@ -1,389 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2003, 2007 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; - -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.Map; - -import org.eclipse.core.resources.IContainer; -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IProject; -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.JavaCore; -import org.eclipse.jem.util.logger.proxy.Logger; -import org.eclipse.jst.j2ee.classpathdep.ClasspathDependencyUtil; -import org.eclipse.jst.j2ee.commonarchivecore.internal.helpers.ArchiveManifest; -import org.eclipse.jst.j2ee.commonarchivecore.internal.helpers.ArchiveManifestImpl; -import org.eclipse.jst.j2ee.commonarchivecore.internal.util.ArchiveUtil; -import org.eclipse.jst.j2ee.internal.J2EEConstants; -import org.eclipse.jst.j2ee.internal.classpathdep.ClasspathDependencyVirtualComponent; -import org.eclipse.jst.j2ee.internal.project.J2EEProjectUtilities; -import org.eclipse.jst.j2ee.project.EarUtilities; -import org.eclipse.jst.j2ee.project.JavaEEProjectUtilities; -import org.eclipse.wst.common.componentcore.ComponentCore; -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.resources.VirtualFolder; -import org.eclipse.wst.common.componentcore.internal.util.IComponentImplFactory; -import org.eclipse.wst.common.componentcore.resources.IVirtualComponent; -import org.eclipse.wst.common.componentcore.resources.IVirtualFile; -import org.eclipse.wst.common.componentcore.resources.IVirtualFolder; -import org.eclipse.wst.common.componentcore.resources.IVirtualReference; - -public class J2EEModuleVirtualComponent extends VirtualComponent implements IComponentImplFactory { - - public static String GET_JAVA_REFS = "GET_JAVA_REFS"; - public static String GET_FUZZY_EAR_REFS = "GET_FUZZY_EAR_REFS"; - - public J2EEModuleVirtualComponent() { - super(); - } - - public J2EEModuleVirtualComponent(IProject aProject, IPath aRuntimePath) { - super(aProject, aRuntimePath); - } - - public IVirtualComponent createComponent(IProject aProject) { - return new J2EEModuleVirtualComponent(aProject, new Path("/")); //$NON-NLS-1$ - } - - public IVirtualComponent createArchiveComponent(IProject aProject, String archiveLocation, IPath aRuntimePath) { - return new J2EEModuleVirtualArchiveComponent(aProject, archiveLocation, aRuntimePath); - } - - public IVirtualFolder createFolder(IProject aProject, IPath aRuntimePath) { - return new VirtualFolder(aProject, aRuntimePath); - } - - /** - * Retrieves all references except those computed dynamically from - * tagged Java classpath entries. - * @return IVirtualReferences for all non-Java classpath entry references. - */ - public IVirtualReference[] getNonJavaReferences() { - return getReferences(false, false); - } - - @Override - public IVirtualReference[] getReferences(Map<String, Object> options) { - Object objGetJavaRefs = options.get(GET_JAVA_REFS); - Object objGetFuzzyEarRefs = options.get(GET_FUZZY_EAR_REFS); - boolean getJavaRefs = objGetJavaRefs != null ? ((Boolean)objGetJavaRefs).booleanValue() : true; - boolean findFuzzyEARRefs = objGetFuzzyEarRefs != null ? ((Boolean)objGetFuzzyEarRefs).booleanValue() : false; - return getReferences(getJavaRefs, findFuzzyEARRefs); - } - - public IVirtualReference[] getReferences() { - return getReferences(true, false); - } - - public IVirtualReference[] getReferences(final boolean getJavaRefs, final boolean findFuzzyEARRefs) { - IVirtualReference[] hardReferences = getNonManifestReferences(getJavaRefs); - - // retrieve the dynamic references specified via the MANIFEST.MF classpath - List dynamicReferences = J2EEModuleVirtualComponent.getManifestReferences(this, hardReferences, findFuzzyEARRefs); - - IVirtualReference[] references = null; - if (dynamicReferences == null) { - references = hardReferences; - } else { - references = new IVirtualReference[hardReferences.length + dynamicReferences.size()]; - System.arraycopy(hardReferences, 0, references, 0, hardReferences.length); - for (int i = 0; i < dynamicReferences.size(); i++) { - references[hardReferences.length + i] = (IVirtualReference) dynamicReferences.get(i); - } - } - return references; - } - - public IVirtualReference[] getNonManifestReferences() { - return getNonManifestReferences(true); - } - - public IVirtualReference[] getNonManifestReferences(final boolean getJavaRefs) { - final List allRefs = new ArrayList(); - - // add component file references - IVirtualReference[] hardReferences = super.getReferences(); - for (int i = 0; i < hardReferences.length; i++) { - allRefs.add(hardReferences[i]); - } - - // add the dynamic references specified via specially tagged JDT classpath entries - if (getJavaRefs) { - IVirtualReference[] cpRefs = getJavaClasspathReferences(hardReferences); - for (int i = 0; i < cpRefs.length; i++) { - allRefs.add(cpRefs[i]); - } - } - - return (IVirtualReference[]) allRefs.toArray(new IVirtualReference[allRefs.size()]); - } - - public static String [] getManifestClasspath(IVirtualComponent moduleComponent) { - String[] manifestClasspath = null; - if(!moduleComponent.isBinary()){ - IVirtualFile vManifest = moduleComponent.getRootFolder().getFile(J2EEConstants.MANIFEST_URI); - if (vManifest.exists()) { - IFile manifestFile = vManifest.getUnderlyingFile(); - InputStream in = null; - try { - in = manifestFile.getContents(); - ArchiveManifest manifest = new ArchiveManifestImpl(in); - manifestClasspath = manifest.getClassPathTokenized(); - } catch (IOException e) { - Logger.getLogger().logError(e); - } catch (CoreException e) { - Logger.getLogger().logError(e); - } finally { - if (in != null) { - try { - in.close(); - in = null; - } catch (IOException e) { - Logger.getLogger().logError(e); - } - } - } - } - } else { - manifestClasspath = ((J2EEModuleVirtualArchiveComponent)moduleComponent).getManifestClasspath(); - } - - return manifestClasspath; - - } - - public IVirtualReference[] getJavaClasspathReferences() { - return getJavaClasspathReferences(null); - } - - private IVirtualReference[] getJavaClasspathReferences(IVirtualReference[] hardReferences) { - final IProject project = getProject(); - final List cpRefs = new ArrayList(); - final boolean isWebApp = J2EEProjectUtilities.isDynamicWebComponent(this); - - try { - if (project == null || !project.isAccessible() || !project.hasNature(JavaCore.NATURE_ID)) { - return new IVirtualReference[0]; - } - - final IJavaProject javaProject = JavaCore.create(project); - if (javaProject == null) { - return new IVirtualReference[0]; - } - - // retrieve all referenced classpath entries - final Map referencedEntries = ClasspathDependencyUtil.getComponentClasspathDependencies(javaProject, isWebApp); - - if (referencedEntries.isEmpty()) { - return new IVirtualReference[0]; - } - - if (hardReferences == null) { - // only compute this not set and if we have some cp dependencies - hardReferences = super.getReferences(); - } - final IPath[] hardRefPaths = new IPath[hardReferences.length]; - for (int j = 0; j < hardReferences.length; j++) { - final IVirtualComponent comp = hardReferences[j].getReferencedComponent(); - if (comp.isBinary()) { - final VirtualArchiveComponent archiveComp = (VirtualArchiveComponent) comp; - final File diskFile = archiveComp.getUnderlyingDiskFile(); - IPath diskPath = null; - if (diskFile.exists()) { - diskPath =new Path(diskFile.getAbsolutePath()); - } else { - final IFile iFile = archiveComp.getUnderlyingWorkbenchFile(); - diskPath = iFile.getFullPath(); - } - hardRefPaths[j] = diskPath; - } - } - - IContainer[] mappedClassFolders = null; - final Iterator i = referencedEntries.keySet().iterator(); - while (i.hasNext()) { - final IClasspathEntry entry = (IClasspathEntry) i.next(); - final IClasspathAttribute attrib = (IClasspathAttribute) referencedEntries.get(entry); - final boolean isClassFolder = ClasspathDependencyUtil.isClassFolderEntry(entry); - final IPath runtimePath = ClasspathDependencyUtil.getRuntimePath(attrib, isWebApp, isClassFolder); - boolean add = true; - final IPath entryLocation = ClasspathDependencyUtil.getEntryLocation(entry); - if (entryLocation == null) { - // unable to retrieve location for cp entry, do not contribute as a virtual ref - add = false; - } else if (!isClassFolder) { // check hard archive refs - for (int j = 0; j < hardRefPaths.length; j++) { - if (entryLocation.equals(hardRefPaths[j])) { - // entry resolves to same file as existing hard reference, can skip - add = false; - break; - } - } - } else { // check class folders mapped in component file as class folders associated with mapped src folders - if (mappedClassFolders == null) { - mappedClassFolders = J2EEProjectUtilities.getAllOutputContainers(getProject()); - } - for (int j = 0; j < mappedClassFolders.length; j++) { - if (entryLocation.equals(mappedClassFolders[j].getFullPath())) { - // entry resolves to same file as existing class folder mapping, skip - add = false; - break; - } - } - } - - if (add) { - String componentPath = null; - ClasspathDependencyVirtualComponent entryComponent = null; - /* - if (entry.getEntryKind() == IClasspathEntry.CPE_PROJECT) { - componentPath = VirtualArchiveComponent.CLASSPATHARCHIVETYPE; - final IProject cpEntryProject = ResourcesPlugin.getWorkspace().getRoot().getProject(entry.getPath().lastSegment()); - entryComponent = (VirtualArchiveComponent) ComponentCore.createArchiveComponent(cpEntryProject, componentPath); - } else { - */ - componentPath = VirtualArchiveComponent.CLASSPATHARCHIVETYPE + IPath.SEPARATOR + entryLocation.toPortableString(); - entryComponent = new ClasspathDependencyVirtualComponent(project, componentPath, isClassFolder); - //} - final IVirtualReference entryReference = ComponentCore.createReference(this, entryComponent, runtimePath); - entryReference.setArchiveName(ClasspathDependencyUtil.getArchiveName(entry)); - cpRefs.add(entryReference); - } - } - - } catch (CoreException jme) { - Logger.getLogger().logError(jme); - } - - return (IVirtualReference[]) cpRefs.toArray(new IVirtualReference[cpRefs.size()]); - } - - public static List getManifestReferences(IVirtualComponent moduleComponent, IVirtualReference[] hardReferences) { - return getManifestReferences(moduleComponent, hardReferences, false); - } - - public static List getManifestReferences(IVirtualComponent moduleComponent, IVirtualReference[] hardReferences, boolean findFuzzyEARRefs) { - List dynamicReferences = null; - String [] manifestClasspath = getManifestClasspath(moduleComponent); - - IVirtualReference foundRef = null; - String earArchiveURI = null; //The URI for this archive in the EAR - boolean simplePath = false; - - if (manifestClasspath != null && manifestClasspath.length > 0) { - boolean [] foundRefAlready = findFuzzyEARRefs ? new boolean[manifestClasspath.length]: null; - if(null != foundRefAlready){ - for(int i=0; i<foundRefAlready.length; i++){ - foundRefAlready[i] = false; - } - } - - IProject [] earProjects = EarUtilities.getReferencingEARProjects(moduleComponent.getProject()); - for (IProject earProject : earProjects) { - if(!JavaEEProjectUtilities.isEARProject(earProject)){ - continue; - } - IVirtualReference[] earRefs = null; - IVirtualComponent tempEARComponent = ComponentCore.createComponent(earProject); - IVirtualReference[] tempEarRefs = tempEARComponent.getReferences(); - for (int j = 0; j < tempEarRefs.length && earRefs == null; j++) { - if (tempEarRefs[j].getReferencedComponent().equals(moduleComponent)) { - earRefs = tempEarRefs; - foundRef = tempEarRefs[j]; - earArchiveURI = foundRef.getArchiveName(); - simplePath = earArchiveURI != null ? earArchiveURI.lastIndexOf("/") == -1 : true; //$NON-NLS-1$ - } - } - if (null != earRefs) { - for (int manifestIndex = 0; manifestIndex < manifestClasspath.length; manifestIndex++) { - boolean found = false; - if(foundRefAlready != null && foundRefAlready[manifestIndex]){ - continue; - } - for (int j = 0; j < earRefs.length && !found; j++) { - if(foundRef != earRefs[j]){ - String archiveName = earRefs[j].getArchiveName(); - if (null != archiveName){ - boolean shouldAdd = false; - String manifestEntryString = manifestClasspath[manifestIndex]; - if( manifestEntryString != null ){ - IPath manifestPath = new Path(manifestEntryString); - manifestEntryString = manifestPath.toPortableString(); - } - - if(simplePath && manifestEntryString.lastIndexOf("/") == -1){ //$NON-NLS-1$ - shouldAdd = archiveName.equals(manifestEntryString); - } else { - String earRelativeURI = ArchiveUtil.deriveEARRelativeURI(manifestEntryString, earArchiveURI); - if(null != earRelativeURI){ - shouldAdd = earRelativeURI.equals(archiveName); - } - } - - if(shouldAdd){ - if(findFuzzyEARRefs){ - foundRefAlready[manifestIndex] = true; - } - found = true; - boolean shouldInclude = true; - IVirtualComponent dynamicComponent = earRefs[j].getReferencedComponent(); - if(null != hardReferences){ - for (int k = 0; k < hardReferences.length && shouldInclude; k++) { - if (hardReferences[k].getReferencedComponent().equals(dynamicComponent)) { - shouldInclude = false; - } - } - } - if (shouldInclude) { - IVirtualReference dynamicReference = ComponentCore.createReference(moduleComponent, dynamicComponent); - if (null == dynamicReferences) { - dynamicReferences = new ArrayList(); - } - dynamicReferences.add(dynamicReference); - } - } - } - } - } - - } - if(!findFuzzyEARRefs){ - break; - } else { - boolean foundAll = true; - for(int i = 0; i < foundRefAlready.length && foundAll; i++){ - if(!foundRefAlready[i]){ - foundAll = false; - } - } - if(foundAll){ - break; - } - } - } - } - } - return dynamicReferences; - } - -} diff --git a/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/internal/componentcore/AppClientBinaryComponentHelper.java b/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/internal/componentcore/AppClientBinaryComponentHelper.java deleted file mode 100644 index 5831ab659..000000000 --- a/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/internal/componentcore/AppClientBinaryComponentHelper.java +++ /dev/null @@ -1,129 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2003, 2007 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.internal.componentcore; - -import java.io.File; -import java.io.IOException; - -import org.eclipse.emf.ecore.EObject; -import org.eclipse.jst.j2ee.commonarchivecore.internal.ApplicationClientFile; -import org.eclipse.jst.j2ee.commonarchivecore.internal.Archive; -import org.eclipse.jst.j2ee.commonarchivecore.internal.exception.OpenFailureException; -import org.eclipse.jst.j2ee.commonarchivecore.internal.exception.SaveFailureException; -import org.eclipse.jst.j2ee.commonarchivecore.internal.helpers.ArchiveTypeDiscriminator; -import org.eclipse.jst.j2ee.commonarchivecore.internal.impl.ApplicationClientFileImpl; -import org.eclipse.jst.j2ee.commonarchivecore.internal.strategy.AppClient12ImportStrategyImpl; -import org.eclipse.jst.j2ee.commonarchivecore.internal.strategy.LoadStrategy; -import org.eclipse.wst.common.componentcore.resources.IVirtualComponent; - -/** - * @deprecated see {@link JavaEEBinaryComponentHelper} - * @author jasholl - * - */ -public class AppClientBinaryComponentHelper extends EnterpriseBinaryComponentHelper { - - public static boolean handlesComponent(IVirtualComponent component) { - AppClientBinaryComponentHelper helper = null; - try { - helper = new AppClientBinaryComponentHelper(component); - return helper.isArchiveValid(); - } catch (Exception e) { - return false; - } finally { - helper.dispose(); - } - } - - protected static class Discriminator extends AppClient12ImportStrategyImpl.Discriminator { - - private static Discriminator instance; - - public static Discriminator getInstance() { - if (instance == null) { - instance = new Discriminator(); - } - return instance; - } - - public Archive createConvertedArchive() { - ReferenceCountedApplicationClientFileImpl archive = new ReferenceCountedApplicationClientFileImpl(); - return archive; - } - } - - protected static class ReferenceCountedApplicationClientFileImpl extends ApplicationClientFileImpl implements IReferenceCountedArchive { - - private int count = 0; - - public void access() { - synchronized (this) { - count++; - } - } - - public void close() { - helper.aboutToClose(); - synchronized (this) { - count--; - if (count > 0) { - return; - } - } - physicallyClose(this); - } - - public void forceClose(){ - count = 0; - helper.aboutToClose(); - super.close(); - } - - private EnterpriseBinaryComponentHelper helper = null; - - public EnterpriseBinaryComponentHelper getEnterpriseBinaryComponentHelper() { - return helper; - } - - public void setEnterpriseBinaryComponentHelper(EnterpriseBinaryComponentHelper helper) { - this.helper = helper; - } - - protected LoadStrategy createLoadStrategyForReopen(Archive parent) throws IOException { - try { - return createBinaryLoadStrategy(getEnterpriseBinaryComponentHelper()); - } catch (OpenFailureException e) { - throw new IOException(e.getMessage()); - } - } - - @Override - protected void cleanupAfterTempSave(String uri, File original, File destinationFile) throws SaveFailureException { - helper.preCleanupAfterTempSave(uri, original, destinationFile); - super.cleanupAfterTempSave(uri, original, destinationFile); - helper.postCleanupAfterTempSave(uri, original, destinationFile); - } - } - - protected ArchiveTypeDiscriminator getDiscriminator() { - return Discriminator.getInstance(); - } - - - public AppClientBinaryComponentHelper(IVirtualComponent component) { - super(component); - } - - public EObject getPrimaryRootObject() { - return ((ApplicationClientFile) getArchive()).getDeploymentDescriptor(); - } - -} diff --git a/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/internal/componentcore/ComponentArchiveOptions.java b/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/internal/componentcore/ComponentArchiveOptions.java deleted file mode 100644 index 5b0e06a36..000000000 --- a/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/internal/componentcore/ComponentArchiveOptions.java +++ /dev/null @@ -1,33 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2003, 2006 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.internal.componentcore; - -import org.eclipse.jst.j2ee.commonarchivecore.internal.helpers.ArchiveOptions; -import org.eclipse.wst.common.componentcore.resources.IVirtualComponent; - -/** - * @deprecated see {@link JavaEEBinaryComponentHelper} - * @author jasholl - * - */ -public class ComponentArchiveOptions extends ArchiveOptions { - - private IVirtualComponent component; - - public ComponentArchiveOptions(IVirtualComponent component){ - this.component = component; - } - - public IVirtualComponent getComponent() { - return component; - } - -} diff --git a/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/internal/componentcore/EJBBinaryComponentHelper.java b/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/internal/componentcore/EJBBinaryComponentHelper.java deleted file mode 100644 index 234ddbbc8..000000000 --- a/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/internal/componentcore/EJBBinaryComponentHelper.java +++ /dev/null @@ -1,128 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2003, 2007 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.internal.componentcore; - -import java.io.File; -import java.io.IOException; - -import org.eclipse.emf.ecore.EObject; -import org.eclipse.jst.j2ee.commonarchivecore.internal.Archive; -import org.eclipse.jst.j2ee.commonarchivecore.internal.EJBJarFile; -import org.eclipse.jst.j2ee.commonarchivecore.internal.exception.OpenFailureException; -import org.eclipse.jst.j2ee.commonarchivecore.internal.exception.SaveFailureException; -import org.eclipse.jst.j2ee.commonarchivecore.internal.helpers.ArchiveTypeDiscriminator; -import org.eclipse.jst.j2ee.commonarchivecore.internal.impl.EJBJarFileImpl; -import org.eclipse.jst.j2ee.commonarchivecore.internal.strategy.EjbJar11ImportStrategyImpl; -import org.eclipse.jst.j2ee.commonarchivecore.internal.strategy.LoadStrategy; -import org.eclipse.wst.common.componentcore.resources.IVirtualComponent; - -/** - * @deprecated see {@link JavaEEBinaryComponentHelper} - * @author jasholl - * - */ -public class EJBBinaryComponentHelper extends EnterpriseBinaryComponentHelper { - - public static boolean handlesComponent(IVirtualComponent component) { - EJBBinaryComponentHelper helper = null; - try { - helper = new EJBBinaryComponentHelper(component); - return helper.isArchiveValid(); - } catch (Exception e) { - return false; - } finally { - helper.dispose(); - } - } - - protected static class Discriminator extends EjbJar11ImportStrategyImpl.Discriminator { - - private static Discriminator instance; - - public static Discriminator getInstance() { - if (instance == null) { - instance = new Discriminator(); - } - return instance; - } - - public Archive createConvertedArchive() { - ReferenceCountedEJBJarFileImpl archive = new ReferenceCountedEJBJarFileImpl(); - return archive; - } - } - - protected static class ReferenceCountedEJBJarFileImpl extends EJBJarFileImpl implements IReferenceCountedArchive { - - private int count = 0; - - public void access() { - synchronized (this) { - count++; - } - } - - public void close() { - helper.aboutToClose(); - synchronized (this) { - count--; - if (count > 0) { - return; - } - } - physicallyClose(this); - } - - public void forceClose(){ - count = 0; - helper.aboutToClose(); - super.close(); - } - - private EnterpriseBinaryComponentHelper helper = null; - - public EnterpriseBinaryComponentHelper getEnterpriseBinaryComponentHelper() { - return helper; - } - - public void setEnterpriseBinaryComponentHelper(EnterpriseBinaryComponentHelper helper) { - this.helper = helper; - } - - protected LoadStrategy createLoadStrategyForReopen(Archive parent) throws IOException { - try { - return createBinaryLoadStrategy(getEnterpriseBinaryComponentHelper()); - } catch (OpenFailureException e) { - throw new IOException(e.getMessage()); - } - } - - @Override - protected void cleanupAfterTempSave(String uri, File original, File destinationFile) throws SaveFailureException { - helper.preCleanupAfterTempSave(uri, original, destinationFile); - super.cleanupAfterTempSave(uri, original, destinationFile); - helper.postCleanupAfterTempSave(uri, original, destinationFile); - } - } - - protected ArchiveTypeDiscriminator getDiscriminator() { - return Discriminator.getInstance(); - } - - public EJBBinaryComponentHelper(IVirtualComponent component) { - super(component); - } - - public EObject getPrimaryRootObject() { - return ((EJBJarFile) getArchive()).getDeploymentDescriptor(); - } - -} diff --git a/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/internal/componentcore/EnterpriseBinaryComponentHelper.java b/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/internal/componentcore/EnterpriseBinaryComponentHelper.java deleted file mode 100644 index 5da1af901..000000000 --- a/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/internal/componentcore/EnterpriseBinaryComponentHelper.java +++ /dev/null @@ -1,403 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2003, 2007 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.internal.componentcore; - -import java.io.File; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.io.InputStream; -import java.util.HashSet; -import java.util.Hashtable; -import java.util.Iterator; -import java.util.Map; -import java.util.Set; -import java.util.zip.ZipEntry; -import java.util.zip.ZipException; - -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IProject; -import org.eclipse.emf.common.util.URI; -import org.eclipse.emf.ecore.resource.Resource; -import org.eclipse.jem.util.emf.workbench.WorkbenchResourceHelperBase; -import org.eclipse.jem.util.logger.proxy.Logger; -import org.eclipse.jst.j2ee.commonarchivecore.internal.Archive; -import org.eclipse.jst.j2ee.commonarchivecore.internal.CommonArchiveResourceHandler; -import org.eclipse.jst.j2ee.commonarchivecore.internal.CommonarchiveFactory; -import org.eclipse.jst.j2ee.commonarchivecore.internal.exception.OpenFailureException; -import org.eclipse.jst.j2ee.commonarchivecore.internal.helpers.ArchiveOptions; -import org.eclipse.jst.j2ee.commonarchivecore.internal.helpers.ArchiveTypeDiscriminator; -import org.eclipse.jst.j2ee.commonarchivecore.internal.strategy.ZipFileLoadStrategyImpl; -import org.eclipse.jst.j2ee.internal.project.J2EEProjectUtilities; -import org.eclipse.jst.jee.archive.internal.ArchiveUtil; -import org.eclipse.wst.common.componentcore.internal.BinaryComponentHelper; -import org.eclipse.wst.common.componentcore.internal.resources.VirtualArchiveComponent; -import org.eclipse.wst.common.componentcore.resources.IVirtualComponent; -import org.eclipse.wst.common.componentcore.resources.IVirtualReference; - -/** - * @deprecated see {@link JavaEEBinaryComponentHelper} - * @author jasholl - * - */ -public abstract class EnterpriseBinaryComponentHelper extends BinaryComponentHelper { - - public static EnterpriseBinaryComponentHelper getHelper(IVirtualComponent aComponent){ - EnterpriseBinaryComponentHelper helper = null; - if (J2EEProjectUtilities.isEJBComponent(aComponent)) { - helper = new EJBBinaryComponentHelper(aComponent); - } else if (J2EEProjectUtilities.isApplicationClientComponent(aComponent)) { - helper = new AppClientBinaryComponentHelper(aComponent); - } else if (J2EEProjectUtilities.isJCAComponent(aComponent)) { - helper = new JCABinaryComponentHelper(aComponent); - } else if (J2EEProjectUtilities.isDynamicWebComponent(aComponent)) { - helper = new WebBinaryComponentHelper(aComponent); - } else { - helper = new UtilityBinaryComponentHelper(aComponent); - } - return helper; - } - - IReferenceCountedArchive archive = null; - - protected EnterpriseBinaryComponentHelper(IVirtualComponent component) { - super(component); - } - - protected ComponentArchiveOptions getArchiveOptions() { - ComponentArchiveOptions options = new ComponentArchiveOptions(getComponent()); - options.setIsReadOnly(true); - options.setRendererType(ArchiveOptions.SAX); - options.setUseJavaReflection(false); - return options; - } - - protected IReferenceCountedArchive getUniqueArchive() { - try { - return openArchive(); - } catch (OpenFailureException e) { - Logger.getLogger().logError(e); - } - return null; - } - - public Archive accessArchive() { - IReferenceCountedArchive archive = getArchive(); - archive.access(); - if(!isPhysicallyOpen(archive)){ - physicallyOpen(archive); - } - return archive; - } - - protected IReferenceCountedArchive getArchive() { - if (archive == null) { - archive = getUniqueArchive(); - } - return archive; - } - - protected boolean isArchiveValid() { - if (archive != null) { - return true; - } - Archive anArchive = null; - try { - anArchive = CommonarchiveFactory.eINSTANCE.primOpenArchive(getArchiveOptions(), getArchiveURI()); - ArchiveTypeDiscriminator disc = getDiscriminator(); - return null == disc || disc.canImport(anArchive); - } catch (Exception e) { - return false; - } finally { - if (anArchive != null) { - anArchive.close(); - } - } - } - - protected String getArchiveURI() { - String archiveURI = null; - VirtualArchiveComponent archiveComp = (VirtualArchiveComponent) getComponent(); - java.io.File diskFile = archiveComp.getUnderlyingDiskFile(); - if (diskFile.exists()) - archiveURI = diskFile.getAbsolutePath(); - else { - IFile iFile = archiveComp.getUnderlyingWorkbenchFile(); - archiveURI = iFile.getRawLocation().toOSString(); - } - return archiveURI; - } - - public void dispose() { - if (archive != null) { - archive.close(); - archive = null; - } - } - - protected abstract ArchiveTypeDiscriminator getDiscriminator(); - - protected IReferenceCountedArchive openArchive() throws OpenFailureException { - ArchiveCache cache = ArchiveCache.getInstance(); - IReferenceCountedArchive archive = cache.getArchive(getComponent()); - if (archive != null) { - archive.access(); - return archive; - } - return cache.openArchive(this); - } - - boolean gotResource = false; - - public Resource getResource(URI uri) { - Resource resource = null; - if(!isPhysicallyOpen(getArchive())){ - resource = getArchive().getResourceSet().getResource(uri, false); - if(resource == null){ - physicallyOpen(getArchive()); - } - } - if(resource == null){ - resource = getArchive().getResourceSet().getResource(uri, true); - } - - return resource; - } - - public void releaseAccess() { - dispose(); - } - - private static void unloadArchive(IReferenceCountedArchive archive) { - WorkbenchResourceHelperBase.removeAndUnloadAll(archive.getResourceSet().getResources(), archive.getResourceSet()); - archive.getLoadStrategy().setResourceSet(null); - archive.setLoadStrategy(null); - } - - private static boolean isPhysicallyOpen(IReferenceCountedArchive archive) { - return ((BinaryZipFileLoadStrategy)archive.getLoadStrategy()).isPhysicallyOpen(); - } - - private static void physicallyOpen(IReferenceCountedArchive archive) { - try { - ((BinaryZipFileLoadStrategy)archive.getLoadStrategy()).physicallyOpen(); - } catch (ZipException e) { - Logger.getLogger().logError(e); - } catch (IOException e) { - Logger.getLogger().logError(e); - } - } - - protected static void physicallyClose(IReferenceCountedArchive archive) { - ((BinaryZipFileLoadStrategy)archive.getLoadStrategy()).physicallyClose(); - } - - protected void aboutToClose() { - //default is to do nothing - } - - protected void preCleanupAfterTempSave(String uri, File original, File destinationFile) { - //default is to do nothing - } - protected void postCleanupAfterTempSave(String uri, File original, File destinationFile) { - //default is to do nothing - } - - private static class BinaryZipFileLoadStrategy extends ZipFileLoadStrategyImpl { - - private boolean physicallyOpen = true; - - public BinaryZipFileLoadStrategy() { - super(); - } - - public BinaryZipFileLoadStrategy(java.io.File file) throws IOException { - super(file); - } - - public void close() { - physicallyOpen = false; - super.close(); - } - - public boolean isPhysicallyOpen(){ - return physicallyOpen; - } - - public void physicallyOpen() throws ZipException, IOException{ - if(!isPhysicallyOpen()){ - physicallyOpen = true; - setZipFile(ArchiveUtil.newZipFile(file)); - } - } - - public void physicallyClose(){ - if(isPhysicallyOpen()){ - physicallyOpen = false; - try{ - zipFile.close(); - } - catch (Throwable t) { - //Ignore - } - } - } - - public InputStream getInputStream(String uri) throws IOException, FileNotFoundException { - final boolean isPhysciallyOpen = isPhysicallyOpen(); - Exception caughtException = null; - try { - if (!isPhysciallyOpen) { - physicallyOpen(); - } - ZipEntry entry = getZipFile().getEntry(uri); - if (entry == null) - throw new FileNotFoundException(uri); - - return new java.io.BufferedInputStream(getZipFile().getInputStream(entry)) { - public void close() throws IOException { - super.close(); - if (!isPhysciallyOpen ) { - physicallyClose(); - } - } - }; - } catch (FileNotFoundException e) { - caughtException = e; - throw e; - } catch (IllegalStateException zipClosed) { - caughtException = zipClosed; - throw new IOException(zipClosed.toString()); - } catch (Exception e) { - caughtException = e; - throw new IOException(e.toString()); - } finally { - if (caughtException != null) { - if (!isPhysciallyOpen) { - physicallyClose(); - } - } - } - } - }; - - public static class ArchiveCache { - - private static ArchiveCache instance = null; - - public static ArchiveCache getInstance() { - if (instance == null) { - instance = new ArchiveCache(); - } - return instance; - } - - protected Map componentsToArchives = new Hashtable(); - - public synchronized IReferenceCountedArchive getArchive(IVirtualComponent component) { - IReferenceCountedArchive archive = (IReferenceCountedArchive) componentsToArchives.get(component); - return archive; - } - - public synchronized void clearDisconnectedArchivesInEAR(IVirtualComponent earComponent) { - if (componentsToArchives.isEmpty()) { - return; - } - Set liveBinaryComponnts = new HashSet(); - IVirtualReference[] refs = earComponent.getReferences(); - IVirtualComponent component = null; - for (int i = 0; i < refs.length; i++) { - component = refs[i].getReferencedComponent(); - if (component.isBinary()) { - liveBinaryComponnts.add(component); - } - } - clearArchivesInProject(earComponent.getProject(), liveBinaryComponnts); - } - - public synchronized void clearAllArchivesInProject(IProject earProject) { - if (componentsToArchives.isEmpty()) { - return; - } - clearArchivesInProject(earProject, null); - } - - private void clearArchivesInProject(IProject earProject, Set excludeSet) { - Iterator iterator = componentsToArchives.entrySet().iterator(); - IVirtualComponent component = null; - IReferenceCountedArchive archive = null; - while (iterator.hasNext()) { - Map.Entry entry = (Map.Entry)iterator.next(); - component = (IVirtualComponent) entry.getKey(); - if (component.getProject().equals(earProject) && (excludeSet == null || !excludeSet.contains(component))) { - archive = (IReferenceCountedArchive) entry.getValue(); - archive.forceClose(); - unloadArchive(archive); - iterator.remove(); - } - } - } - - public synchronized IReferenceCountedArchive openArchive(EnterpriseBinaryComponentHelper helper) throws OpenFailureException { - ArchiveOptions options = helper.getArchiveOptions(); - String archiveURI = helper.getArchiveURI(); - - options.setLoadStrategy(createBinaryLoadStrategy(helper)); - - Archive anArchive = CommonarchiveFactory.eINSTANCE.primOpenArchive(options, archiveURI); - - ArchiveTypeDiscriminator discriminator = helper.getDiscriminator(); - - if (!discriminator.canImport(anArchive)) { - anArchive.close(); - throw new OpenFailureException(discriminator.getUnableToOpenMessage()); - } - IReferenceCountedArchive specificArchive = (IReferenceCountedArchive) discriminator.openArchive(anArchive); - specificArchive.setEnterpriseBinaryComponentHelper(helper); - specificArchive.initializeAfterOpen(); - specificArchive.access(); - componentsToArchives.put(helper.getComponent(), specificArchive); - return specificArchive; - } - } - - protected static BinaryZipFileLoadStrategy createBinaryLoadStrategy(EnterpriseBinaryComponentHelper helper) throws OpenFailureException { - String archiveURI = helper.getArchiveURI(); - String filename = archiveURI.replace('/', java.io.File.separatorChar); - java.io.File file = new java.io.File(filename); - if (!file.exists()) { - throw new OpenFailureException(CommonArchiveResourceHandler.getString(CommonArchiveResourceHandler.file_not_found_EXC_, (new Object[] { archiveURI, file.getAbsolutePath() }))); - } - try { - BinaryZipFileLoadStrategy strategy = new BinaryZipFileLoadStrategy(file); - return strategy; - } catch (IOException ex) { - throw new OpenFailureException(CommonArchiveResourceHandler.getString(CommonArchiveResourceHandler.could_not_open_EXC_, (new Object[] { archiveURI })), ex); - } - } - - protected interface IReferenceCountedArchive extends Archive { - - /** - * Increases the reference count by one. A call to close will decriment - * the count by one. If after decrimenting the count the count is 0 - * - */ - public void access(); - - public void forceClose(); - - public void setEnterpriseBinaryComponentHelper(EnterpriseBinaryComponentHelper helper); - - public EnterpriseBinaryComponentHelper getEnterpriseBinaryComponentHelper(); - - } - -} diff --git a/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/internal/componentcore/JCABinaryComponentHelper.java b/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/internal/componentcore/JCABinaryComponentHelper.java deleted file mode 100644 index a7f5110e8..000000000 --- a/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/internal/componentcore/JCABinaryComponentHelper.java +++ /dev/null @@ -1,128 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2003, 2007 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.internal.componentcore; - -import java.io.File; -import java.io.IOException; - -import org.eclipse.emf.ecore.EObject; -import org.eclipse.jst.j2ee.commonarchivecore.internal.Archive; -import org.eclipse.jst.j2ee.commonarchivecore.internal.RARFile; -import org.eclipse.jst.j2ee.commonarchivecore.internal.exception.OpenFailureException; -import org.eclipse.jst.j2ee.commonarchivecore.internal.exception.SaveFailureException; -import org.eclipse.jst.j2ee.commonarchivecore.internal.helpers.ArchiveTypeDiscriminator; -import org.eclipse.jst.j2ee.commonarchivecore.internal.impl.RARFileImpl; -import org.eclipse.jst.j2ee.commonarchivecore.internal.strategy.LoadStrategy; -import org.eclipse.jst.j2ee.commonarchivecore.internal.strategy.RarImportStrategyImpl; -import org.eclipse.wst.common.componentcore.resources.IVirtualComponent; - -/** - * @deprecated see {@link JavaEEBinaryComponentHelper} - * @author jasholl - * - */ -public class JCABinaryComponentHelper extends EnterpriseBinaryComponentHelper { - - public static boolean handlesComponent(IVirtualComponent component) { - JCABinaryComponentHelper helper = null; - try { - helper = new JCABinaryComponentHelper(component); - return helper.isArchiveValid(); - } catch (Exception e) { - return false; - } finally { - helper.dispose(); - } - } - - protected static class Discriminator extends RarImportStrategyImpl.Discriminator { - - private static Discriminator instance; - - public static Discriminator getInstance() { - if (instance == null) { - instance = new Discriminator(); - } - return instance; - } - - public Archive createConvertedArchive() { - ReferenceCountedRARFileImpl archive = new ReferenceCountedRARFileImpl(); - return archive; - } - } - - protected static class ReferenceCountedRARFileImpl extends RARFileImpl implements IReferenceCountedArchive { - - private int count = 0; - - public void access() { - synchronized (this) { - count++; - } - } - - public void close() { - helper.aboutToClose(); - synchronized (this) { - count--; - if (count > 0) { - return; - } - } - physicallyClose(this); - } - - public void forceClose(){ - count = 0; - helper.aboutToClose(); - super.close(); - } - - private EnterpriseBinaryComponentHelper helper = null; - - public EnterpriseBinaryComponentHelper getEnterpriseBinaryComponentHelper() { - return helper; - } - - public void setEnterpriseBinaryComponentHelper(EnterpriseBinaryComponentHelper helper) { - this.helper = helper; - } - - protected LoadStrategy createLoadStrategyForReopen(Archive parent) throws IOException { - try { - return createBinaryLoadStrategy(getEnterpriseBinaryComponentHelper()); - } catch (OpenFailureException e) { - throw new IOException(e.getMessage()); - } - } - - @Override - protected void cleanupAfterTempSave(String uri, File original, File destinationFile) throws SaveFailureException { - helper.preCleanupAfterTempSave(uri, original, destinationFile); - super.cleanupAfterTempSave(uri, original, destinationFile); - helper.postCleanupAfterTempSave(uri, original, destinationFile); - } - } - - protected ArchiveTypeDiscriminator getDiscriminator() { - return Discriminator.getInstance(); - } - - public JCABinaryComponentHelper(IVirtualComponent component) { - super(component); - } - - public EObject getPrimaryRootObject() { - return ((RARFile) getArchive()).getDeploymentDescriptor(); - } - -} diff --git a/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/internal/componentcore/JavaEEBinaryComponentHelper.java b/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/internal/componentcore/JavaEEBinaryComponentHelper.java deleted file mode 100644 index 729954264..000000000 --- a/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/internal/componentcore/JavaEEBinaryComponentHelper.java +++ /dev/null @@ -1,478 +0,0 @@ -package org.eclipse.jst.j2ee.internal.componentcore; - -import java.io.File; -import java.io.IOException; -import java.util.HashSet; -import java.util.Hashtable; -import java.util.Iterator; -import java.util.Map; -import java.util.Set; -import java.util.zip.ZipException; - -import org.eclipse.core.resources.IProject; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.Path; -import org.eclipse.emf.common.util.URI; -import org.eclipse.emf.ecore.EObject; -import org.eclipse.emf.ecore.resource.Resource; -import org.eclipse.jst.j2ee.commonarchivecore.internal.Archive; -import org.eclipse.jst.j2ee.internal.J2EEConstants; -import org.eclipse.jst.j2ee.internal.archive.JavaEEArchiveUtilities; -import org.eclipse.jst.j2ee.internal.componentcore.EnterpriseBinaryComponentHelper.IReferenceCountedArchive; -import org.eclipse.jst.j2ee.internal.plugin.J2EEPlugin; -import org.eclipse.jst.javaee.applicationclient.ApplicationClient; -import org.eclipse.jst.javaee.applicationclient.ApplicationclientFactory; -import org.eclipse.jst.javaee.core.DisplayName; -import org.eclipse.jst.javaee.core.JavaeeFactory; -import org.eclipse.jst.javaee.ejb.EJBJar; -import org.eclipse.jst.javaee.ejb.EjbFactory; -import org.eclipse.jst.javaee.web.WebApp; -import org.eclipse.jst.javaee.web.WebFactory; -import org.eclipse.jst.jee.archive.ArchiveModelLoadException; -import org.eclipse.jst.jee.archive.ArchiveOpenFailureException; -import org.eclipse.jst.jee.archive.ArchiveOptions; -import org.eclipse.jst.jee.archive.IArchive; -import org.eclipse.jst.jee.archive.IArchiveFactory; -import org.eclipse.jst.jee.archive.IArchiveLoadAdapter; -import org.eclipse.jst.jee.util.internal.JavaEEQuickPeek; -import org.eclipse.wst.common.componentcore.ComponentCore; -import org.eclipse.wst.common.componentcore.internal.BinaryComponentHelper; -import org.eclipse.wst.common.componentcore.resources.IVirtualComponent; -import org.eclipse.wst.common.componentcore.resources.IVirtualReference; - -public class JavaEEBinaryComponentHelper extends BinaryComponentHelper { - - private IArchive archive; - private EnterpriseBinaryComponentHelper legacyBinaryHelper; - - private int localArchiveAccessCount = 0; - - public static JavaEEQuickPeek getJavaEEQuickPeek(IVirtualComponent aBinaryComponent) { - JavaEEBinaryComponentHelper helper = null; - try { - helper = new JavaEEBinaryComponentHelper(aBinaryComponent); - IArchive archive = helper.getArchive(); - if (archive == null) { - return new JavaEEQuickPeek(null); - } - JavaEEQuickPeek qp = JavaEEArchiveUtilities.INSTANCE.getJavaEEQuickPeek(archive); - return qp; - } finally { - if (helper != null) { - helper.dispose(); - } - } - } - - public JavaEEBinaryComponentHelper(IVirtualComponent aBinaryComponent) { - super(aBinaryComponent); - } - - public IPath getAbsolutePath() { - IArchiveLoadAdapter loadAdapter = null; - if(getArchive().getArchiveOptions().hasOption(JavaEEArchiveUtilities.WRAPPED_LOAD_ADAPTER)){ - loadAdapter = (IArchiveLoadAdapter)getArchive().getArchiveOptions().getOption(JavaEEArchiveUtilities.WRAPPED_LOAD_ADAPTER); - } else { - loadAdapter = (IArchiveLoadAdapter)getArchive().getArchiveOptions().getOption(ArchiveOptions.LOAD_ADAPTER); - } - return ((JavaEEBinaryComponentLoadAdapter) loadAdapter).getArchivePath(); - } - - @Override - public EObject getPrimaryRootObject() { - JavaEEQuickPeek qp = JavaEEArchiveUtilities.INSTANCE.getJavaEEQuickPeek(getArchive()); - IPath ddPath = null; - switch (qp.getType()) { - case JavaEEQuickPeek.APPLICATION_CLIENT_TYPE: - ddPath = new Path(J2EEConstants.APP_CLIENT_DD_URI); - break; - case JavaEEQuickPeek.EJB_TYPE: - ddPath = new Path(J2EEConstants.EJBJAR_DD_URI); - break; - case JavaEEQuickPeek.WEB_TYPE: - ddPath = new Path(J2EEConstants.WEBAPP_DD_URI); - break; - case JavaEEQuickPeek.CONNECTOR_TYPE: - ddPath = new Path(J2EEConstants.RAR_DD_URI); - break; - } - if (ddPath != null) { - if (getArchive().containsArchiveResource(ddPath)) { - try { - return (EObject) getArchive().getModelObject(ddPath); - } catch (ArchiveModelLoadException e) { - J2EEPlugin.logError(e); - } - } else { - String displayName = getComponent().getName(); - //because this component is binary, its project must be the EAR. - IVirtualComponent earComponent = ComponentCore.createComponent(getComponent().getProject()); - IVirtualReference [] refs = earComponent.getReferences(); - for(IVirtualReference ref:refs){ - if(ref.getReferencedComponent().equals(getComponent())){ - displayName = ref.getArchiveName(); - break; - } - } - DisplayName dn = JavaeeFactory.eINSTANCE.createDisplayName(); - dn.setValue(displayName); - EObject root = null; - switch (qp.getType()) { - case JavaEEQuickPeek.APPLICATION_CLIENT_TYPE: - ApplicationClient applicationClient = ApplicationclientFactory.eINSTANCE.createApplicationClient(); - applicationClient.getDisplayNames().add(dn); - root = (EObject) applicationClient; - break; - case JavaEEQuickPeek.EJB_TYPE: - EJBJar ejbJar = EjbFactory.eINSTANCE.createEJBJar(); - ejbJar.getDisplayNames().add(dn); - root = (EObject) ejbJar; - break; - case JavaEEQuickPeek.WEB_TYPE: - WebApp webApp = WebFactory.eINSTANCE.createWebApp(); - webApp.getDisplayNames().add(dn); - root = (EObject) webApp; - break; - } - return root; - } - } - return null; - } - - @Override - public Resource getResource(URI uri) { - IPath path = new Path(uri.toString()); - try { - IArchiveLoadAdapter loadAdapter = null; - if(getArchive().getArchiveOptions().hasOption(JavaEEArchiveUtilities.WRAPPED_LOAD_ADAPTER)){ - loadAdapter = (IArchiveLoadAdapter)getArchive().getArchiveOptions().getOption(JavaEEArchiveUtilities.WRAPPED_LOAD_ADAPTER); - } else { - loadAdapter = (IArchiveLoadAdapter)getArchive().getArchiveOptions().getOption(ArchiveOptions.LOAD_ADAPTER); - } - EObject modelRoot = (EObject)((JavaEEBinaryComponentLoadAdapter) loadAdapter).getModelObject(path); - return modelRoot.eResource(); - } catch (ArchiveModelLoadException e) { - J2EEPlugin.logError(e); - } - return null; - } - - public IArchive accessArchive() { - IArchive archive = getArchive(); - if (null != archive) { - ArchiveCache cache = ArchiveCache.getInstance(); - cache.accessArchive(archive); - synchronized (this) { - localArchiveAccessCount++; - } - } - return archive; - } - - protected void safeReleaseArchive(IArchive archive){ - int count = 0; - synchronized(this){ - count = localArchiveAccessCount; - } - if(count > 0){ - releaseArchive(archive); - } - } - - public void releaseArchive(IArchive archive) { - if (archive != this.archive) { - throw new RuntimeException("The IArchive parameter must be the same IArchive retrieved from accessArchive"); - } - if (null != archive) { - ArchiveCache cache = ArchiveCache.getInstance(); - cache.releaseArchive(archive); - synchronized (this) { - localArchiveAccessCount--; - } - } - } - - private int preSwapAccessCount = 0; - protected void preFileSwap(){ - int count = 0; - synchronized (this) { - preSwapAccessCount = localArchiveAccessCount; - count = preSwapAccessCount; - } - while (count > 0){ - count --; - releaseArchive(archive); - } - } - - protected void postFileSwap() { - int count = 0; - synchronized (this) { - count = preSwapAccessCount; - preSwapAccessCount = 0; - } - while(count > 0){ - count --; - accessArchive(); - } - } - - public Archive accessLegacyArchive() { - if(legacyBinaryHelper == null){ - JavaEEQuickPeek qp = getJavaEEQuickPeek(getComponent()); - IPath ddPath = null; - switch (qp.getType()) { - case JavaEEQuickPeek.APPLICATION_CLIENT_TYPE: - legacyBinaryHelper = new AppClientBinaryComponentHelper(getComponent()){ - protected void aboutToClose() { - safeReleaseArchive(JavaEEBinaryComponentHelper.this.archive); - } - protected void preCleanupAfterTempSave(String uri, File original, File destinationFile) { - preFileSwap(); - } - protected void postCleanupAfterTempSave(String uri, File original, File destinationFile) { - postFileSwap(); - } - }; - break; - case JavaEEQuickPeek.EJB_TYPE: - legacyBinaryHelper = new EJBBinaryComponentHelper(getComponent()){ - protected void aboutToClose() { - safeReleaseArchive(JavaEEBinaryComponentHelper.this.archive); - } - protected void preCleanupAfterTempSave(String uri, File original, File destinationFile) { - preFileSwap(); - } - protected void postCleanupAfterTempSave(String uri, File original, File destinationFile) { - postFileSwap(); - } - }; - break; - case JavaEEQuickPeek.WEB_TYPE: - legacyBinaryHelper = new WebBinaryComponentHelper(getComponent()){ - protected void aboutToClose() { - safeReleaseArchive(JavaEEBinaryComponentHelper.this.archive); - } - protected void preCleanupAfterTempSave(String uri, File original, File destinationFile) { - preFileSwap(); - } - protected void postCleanupAfterTempSave(String uri, File original, File destinationFile) { - postFileSwap(); - } - }; - break; - case JavaEEQuickPeek.CONNECTOR_TYPE: - legacyBinaryHelper = new JCABinaryComponentHelper(getComponent()){ - protected void aboutToClose() { - safeReleaseArchive(JavaEEBinaryComponentHelper.this.archive); - } - protected void preCleanupAfterTempSave(String uri, File original, File destinationFile) { - preFileSwap(); - } - protected void postCleanupAfterTempSave(String uri, File original, File destinationFile) { - postFileSwap(); - } - }; - break; - default: //utility jar - legacyBinaryHelper = new UtilityBinaryComponentHelper(getComponent()){ - protected void aboutToClose() { - safeReleaseArchive(JavaEEBinaryComponentHelper.this.archive); - } - protected void preCleanupAfterTempSave(String uri, File original, File destinationFile) { - preFileSwap(); - } - protected void postCleanupAfterTempSave(String uri, File original, File destinationFile) { - postFileSwap(); - } - }; - break; - } - } - accessArchive(); - Archive legacyArchive = legacyBinaryHelper.accessArchive(); - return legacyArchive; - } - - @Override - public void dispose() { - super.dispose(); - int count = 0; - int legacyCount = 0; - synchronized (this) { - count = localArchiveAccessCount; - } - if (count > 0 && archive != null) { - ArchiveCache cache = ArchiveCache.getInstance(); - for (int i = 0; i < count; i++) { - cache.releaseArchive(archive); - synchronized (this) { - localArchiveAccessCount--; - } - } - } - if(legacyBinaryHelper != null){ - IReferenceCountedArchive legacyArchive = legacyBinaryHelper.archive; - if(legacyArchive != null){ - legacyArchive.forceClose(); - } - } - } - - protected IArchive getArchive() { - if (archive == null) { - archive = getUniqueArchive(); - } - return archive; - } - - protected IArchive getUniqueArchive() { - try { - return openArchive(); - } catch (ArchiveOpenFailureException e) { - J2EEPlugin.logError(e); - } - return null; - } - - protected IArchive openArchive() throws ArchiveOpenFailureException { - ArchiveCache cache = ArchiveCache.getInstance(); - IArchive archive = cache.getArchive(getComponent()); - if (archive == null) { - archive = cache.openArchive(this); - } - if (archive != null) { - cache.accessArchive(archive); - synchronized (this) { - localArchiveAccessCount++; - } - } - return archive; - } - - public static void clearDisconnectedArchivesInEAR(IVirtualComponent earComponent) { - ArchiveCache.getInstance().clearDisconnectedArchivesInEAR(earComponent); - } - - public static void clearAllArchivesInProject(IProject earProject) { - ArchiveCache.getInstance().clearAllArchivesInProject(earProject); - } - - /** - * This cache manages IArchives across all - * {@link JavaEEBinaryComponentHelper} instances. If multiple - * {@link JavaEEBinaryComponentHelper} instances exist for the same - * underlying archive file (e.g. a jar file on disk) all will use the exact - * same IArchive instance. Care needs to be taken in managing the opening - * and closing of this IArchive which should only be done through internal - * methods within {@link JavaEEBinaryComponentHelper} - */ - private static class ArchiveCache { - - private static ArchiveCache instance = null; - - public static ArchiveCache getInstance() { - if (instance == null) { - instance = new ArchiveCache(); - } - return instance; - } - - protected Map<IVirtualComponent, IArchive> componentsToArchives = new Hashtable<IVirtualComponent, IArchive>(); - - protected Map<IArchive, Integer> archiveAccessCount = new Hashtable<IArchive, Integer>(); - - public synchronized void accessArchive(IArchive archive) { - Integer count = archiveAccessCount.get(archive); - Integer newCount = new Integer(count.intValue() + 1); - archiveAccessCount.put(archive, newCount); - if (newCount.intValue() == 1) { - JavaEEBinaryComponentLoadAdapter binaryAdapter = null; - if (archive.getArchiveOptions().hasOption(JavaEEArchiveUtilities.WRAPPED_LOAD_ADAPTER)) { - binaryAdapter = (JavaEEBinaryComponentLoadAdapter) archive.getArchiveOptions().getOption(JavaEEArchiveUtilities.WRAPPED_LOAD_ADAPTER); - } else { - binaryAdapter = (JavaEEBinaryComponentLoadAdapter) archive.getArchiveOptions().getOption(ArchiveOptions.LOAD_ADAPTER); - } - if (!binaryAdapter.isPhysicallyOpen()) { - try { - binaryAdapter.physicallyOpen(); - } catch (ZipException e) { - org.eclipse.jst.j2ee.internal.plugin.J2EEPlugin.logError(e); - } catch (IOException e) { - org.eclipse.jst.j2ee.internal.plugin.J2EEPlugin.logError(e); - } - } - } - } - - public synchronized void releaseArchive(IArchive archive) { - Integer count = archiveAccessCount.get(archive); - Integer newCount = new Integer(count.intValue() - 1); - archiveAccessCount.put(archive, newCount); - if (newCount.intValue() == 0) { - JavaEEBinaryComponentLoadAdapter binaryAdapter = null; - if (archive.getArchiveOptions().hasOption(JavaEEArchiveUtilities.WRAPPED_LOAD_ADAPTER)) { - binaryAdapter = (JavaEEBinaryComponentLoadAdapter) archive.getArchiveOptions().getOption(JavaEEArchiveUtilities.WRAPPED_LOAD_ADAPTER); - } else { - binaryAdapter = (JavaEEBinaryComponentLoadAdapter) archive.getArchiveOptions().getOption(ArchiveOptions.LOAD_ADAPTER); - } - if (binaryAdapter.isPhysicallyOpen()) { - binaryAdapter.physicallyClose(); - } - } - } - - public synchronized IArchive getArchive(IVirtualComponent component) { - IArchive archive = componentsToArchives.get(component); - return archive; - } - - public synchronized void clearDisconnectedArchivesInEAR(IVirtualComponent earComponent) { - if (componentsToArchives.isEmpty()) { - return; - } - Set<IVirtualComponent> liveBinaryComponnts = new HashSet<IVirtualComponent>(); - IVirtualReference[] refs = earComponent.getReferences(); - IVirtualComponent component = null; - for (int i = 0; i < refs.length; i++) { - component = refs[i].getReferencedComponent(); - if (component.isBinary()) { - liveBinaryComponnts.add(component); - } - } - clearArchivesInProject(earComponent.getProject(), liveBinaryComponnts); - } - - public synchronized void clearAllArchivesInProject(IProject earProject) { - if (componentsToArchives.isEmpty()) { - return; - } - clearArchivesInProject(earProject, null); - } - - private void clearArchivesInProject(IProject earProject, Set excludeSet) { - Iterator iterator = componentsToArchives.entrySet().iterator(); - IVirtualComponent component = null; - IArchive archive = null; - while (iterator.hasNext()) { - Map.Entry entry = (Map.Entry) iterator.next(); - component = (IVirtualComponent) entry.getKey(); - if (component.getProject().equals(earProject) && (excludeSet == null || !excludeSet.contains(component))) { - archive = (IArchive) entry.getValue(); - IArchiveFactory.INSTANCE.closeArchive(archive); - iterator.remove(); - archiveAccessCount.remove(archive); - } - } - } - - public synchronized IArchive openArchive(JavaEEBinaryComponentHelper helper) throws ArchiveOpenFailureException { - IArchive archive = JavaEEArchiveUtilities.INSTANCE.openArchive(helper.getComponent()); - componentsToArchives.put(helper.getComponent(), archive); - archiveAccessCount.put(archive, new Integer(0)); - return archive; - } - } - -} diff --git a/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/internal/componentcore/JavaEEBinaryComponentLoadAdapter.java b/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/internal/componentcore/JavaEEBinaryComponentLoadAdapter.java deleted file mode 100644 index f73d804a8..000000000 --- a/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/internal/componentcore/JavaEEBinaryComponentLoadAdapter.java +++ /dev/null @@ -1,227 +0,0 @@ -package org.eclipse.jst.j2ee.internal.componentcore; - -import java.io.File; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.util.Collections; -import java.util.List; -import java.util.zip.ZipEntry; -import java.util.zip.ZipException; -import java.util.zip.ZipFile; - -import org.eclipse.core.resources.IFile; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.Path; -import org.eclipse.jst.j2ee.internal.archive.JavaEEEMFZipFileLoadAdapterImpl; -import org.eclipse.jst.j2ee.internal.plugin.J2EEPlugin; -import org.eclipse.jst.jee.archive.ArchiveOpenFailureException; -import org.eclipse.jst.jee.archive.IArchiveResource; -import org.eclipse.jst.jee.archive.internal.ArchiveUtil; -import org.eclipse.wst.common.componentcore.internal.resources.VirtualArchiveComponent; - -/** - * @author jsholl - * - */ -public class JavaEEBinaryComponentLoadAdapter extends JavaEEEMFZipFileLoadAdapterImpl { - - private java.io.File file = null; - private IPath archivePath; - private boolean physicallyOpen = true; - - private VirtualArchiveComponent archiveComponent; - - public JavaEEBinaryComponentLoadAdapter(VirtualArchiveComponent archiveComponent) throws ArchiveOpenFailureException { - super(); - this.archiveComponent = archiveComponent; - IPath archivePath = recomputeArchivePath(); - try{ - resetZipFile(archivePath); - } catch (ZipException e) { - ArchiveOpenFailureException openFailureException = new ArchiveOpenFailureException(file.getAbsolutePath(), e); - throw openFailureException; - } catch (IOException e) { - ArchiveOpenFailureException openFailureException = new ArchiveOpenFailureException(file.getAbsolutePath(), e); - throw openFailureException; - } - } - - private void resetZipFile(IPath archivePath) throws ZipException, IOException { - file = new java.io.File(archivePath.toOSString()); - ZipFile zipFile = ArchiveUtil.newZipFile(file); - setZipFile(zipFile); - setArchivePath(archivePath); - } - - private IPath recomputeArchivePath() { - java.io.File diskFile = archiveComponent.getUnderlyingDiskFile(); - if (!diskFile.exists()) { - IFile wbFile = archiveComponent.getUnderlyingWorkbenchFile(); - diskFile = new File(wbFile.getLocation().toOSString()); - } - IPath archivePath = new Path(diskFile.getAbsolutePath()); - return archivePath; - } - - private void setArchivePath(IPath archivePath) { - this.archivePath = archivePath; - } - - public IPath getArchivePath() { - return archivePath; - } - - public boolean isPhysicallyOpen(){ - return physicallyOpen; - } - - public void physicallyOpen() throws ZipException, IOException{ - if(!isPhysicallyOpen()){ - if(file.exists()){ - setZipFile(ArchiveUtil.newZipFile(file)); - } else { - //check if the file has moved -- this can happen when - //checking into ClearCase. - IPath newPath = recomputeArchivePath(); - if(newPath.equals(archivePath)){ - throw new FileNotFoundException(archivePath.toOSString()); - } else { - resetZipFile(newPath); - } - } - physicallyOpen = true; - } - } - - public void physicallyClose(){ - if(isPhysicallyOpen()){ - physicallyOpen = false; - try{ - zipFile.close(); - } - catch (Throwable t) { - //Ignore - } - } - } - - public boolean containsArchiveResource(IPath resourcePath) { - final boolean isPhysciallyOpen = isPhysicallyOpen(); - Exception caughtException = null; - try { - if (!isPhysciallyOpen) { - physicallyOpen(); - } - try{ - return super.containsArchiveResource(resourcePath); - } catch(Exception e){ - J2EEPlugin.logError(caughtException); - } - } catch (Exception e) { - caughtException = e; - J2EEPlugin.logError(caughtException); - } finally { - if (caughtException != null) { - if (!isPhysciallyOpen) { - physicallyClose(); - } - } - } - return false; - } - - public IArchiveResource getArchiveResource(IPath filePath) { - final boolean isPhysciallyOpen = isPhysicallyOpen(); - Exception caughtException = null; - try { - if (!isPhysciallyOpen) { - physicallyOpen(); - } - try { - return super.getArchiveResource(filePath); - } catch(Exception e){ - J2EEPlugin.logError(caughtException); - } - } catch (Exception e) { - caughtException = e; - J2EEPlugin.logError(caughtException); - } finally { - if (caughtException != null) { - if (!isPhysciallyOpen) { - physicallyClose(); - } - } - } - return null; - } - - @Override - public List getArchiveResources() { - final boolean isPhysciallyOpen = isPhysicallyOpen(); - Exception caughtException = null; - try { - if (!isPhysciallyOpen) { - physicallyOpen(); - } - try { - return super.getArchiveResources(); - } catch(Exception e){ - J2EEPlugin.logError(caughtException); - } - } catch (Exception e) { - caughtException = e; - J2EEPlugin.logError(caughtException); - } finally { - if (caughtException != null) { - if (!isPhysciallyOpen) { - physicallyClose(); - } - } - } - return Collections.EMPTY_LIST; - } - - - public java.io.InputStream getInputStream(IArchiveResource aFile) throws IOException, FileNotFoundException { - final boolean isPhysciallyOpen = isPhysicallyOpen(); - Exception caughtException = null; - try { - if (!isPhysciallyOpen) { - physicallyOpen(); - } - IPath path = aFile.getPath(); - String uri = path.toString(); - ZipEntry entry = getZipFile().getEntry(uri); - if (entry == null) - throw new FileNotFoundException(uri); - - return new java.io.BufferedInputStream(getZipFile().getInputStream(entry)) { - public void close() throws IOException { - super.close(); - if (!isPhysciallyOpen ) { - physicallyClose(); - } - } - }; - } catch (FileNotFoundException e) { - caughtException = e; - throw e; - } catch (IllegalStateException zipClosed) { - caughtException = zipClosed; - throw new IOException(zipClosed.toString()); - } catch (Exception e) { - caughtException = e; - throw new IOException(e.toString()); - } finally { - if (caughtException != null) { - if (!isPhysciallyOpen) { - physicallyClose(); - } - } - } - } - - public VirtualArchiveComponent getArchiveComponent() { - return archiveComponent; - } -}
\ No newline at end of file diff --git a/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/internal/componentcore/UtilityBinaryComponentHelper.java b/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/internal/componentcore/UtilityBinaryComponentHelper.java deleted file mode 100644 index d4001358c..000000000 --- a/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/internal/componentcore/UtilityBinaryComponentHelper.java +++ /dev/null @@ -1,136 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2007 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.internal.componentcore; - -import java.io.File; -import java.io.IOException; - -import org.eclipse.emf.ecore.EObject; -import org.eclipse.jst.j2ee.commonarchivecore.internal.Archive; -import org.eclipse.jst.j2ee.commonarchivecore.internal.exception.OpenFailureException; -import org.eclipse.jst.j2ee.commonarchivecore.internal.exception.SaveFailureException; -import org.eclipse.jst.j2ee.commonarchivecore.internal.helpers.ArchiveTypeDiscriminator; -import org.eclipse.jst.j2ee.commonarchivecore.internal.helpers.ArchiveTypeDiscriminatorImpl; -import org.eclipse.jst.j2ee.commonarchivecore.internal.impl.ArchiveImpl; -import org.eclipse.jst.j2ee.commonarchivecore.internal.strategy.ImportStrategy; -import org.eclipse.jst.j2ee.commonarchivecore.internal.strategy.LoadStrategy; -import org.eclipse.wst.common.componentcore.resources.IVirtualComponent; - -/** - * @deprecated see {@link JavaEEBinaryComponentHelper} - * @author jasholl - * - */ -public class UtilityBinaryComponentHelper extends EnterpriseBinaryComponentHelper { - - public UtilityBinaryComponentHelper(IVirtualComponent component) { - super(component); - } - - protected static class Discriminator extends ArchiveTypeDiscriminatorImpl { - - private static Discriminator instance; - - public static Discriminator getInstance() { - if (instance == null) { - instance = new Discriminator(); - } - return instance; - } - - public Archive createConvertedArchive() { - ReferenceCountedArchiveImpl archive = new ReferenceCountedArchiveImpl(); - return archive; - } - - public boolean canImport(Archive anArchive) { - return true; - } - - public ImportStrategy createImportStrategy(Archive old, Archive newArchive) { - return null; - } - - public String getUnableToOpenMessage() { - return "";//$NON-NLS-1$ - } - } - - protected static class ReferenceCountedArchiveImpl extends ArchiveImpl implements IReferenceCountedArchive { - - private int count = 0; - - public void access() { - synchronized (this) { - count++; - } - } - - public void close() { - helper.aboutToClose(); - synchronized (this) { - count--; - if (count > 0) { - return; - } - } - physicallyClose(this); - } - - public void forceClose(){ - count = 0; - helper.aboutToClose(); - super.close(); - } - - private EnterpriseBinaryComponentHelper helper = null; - - public EnterpriseBinaryComponentHelper getEnterpriseBinaryComponentHelper() { - return helper; - } - - public void setEnterpriseBinaryComponentHelper(EnterpriseBinaryComponentHelper helper) { - this.helper = helper; - } - - protected LoadStrategy createLoadStrategyForReopen(Archive parent) throws IOException { - try { - return createBinaryLoadStrategy(getEnterpriseBinaryComponentHelper()); - } catch (OpenFailureException e) { - throw new IOException(e.getMessage()); - } - } - - @Override - protected void cleanupAfterTempSave(String uri, File original, File destinationFile) throws SaveFailureException { - helper.preCleanupAfterTempSave(uri, original, destinationFile); - super.cleanupAfterTempSave(uri, original, destinationFile); - helper.postCleanupAfterTempSave(uri, original, destinationFile); - } - } - - protected ArchiveTypeDiscriminator getDiscriminator() { - return Discriminator.getInstance(); - } - - protected IReferenceCountedArchive getUniqueArchive() { - try { - return openArchive(); - } catch (OpenFailureException e) { - } - return null; - } - - public EObject getPrimaryRootObject() { - return null; - } - -}
\ No newline at end of file diff --git a/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/internal/componentcore/WebBinaryComponentHelper.java b/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/internal/componentcore/WebBinaryComponentHelper.java deleted file mode 100644 index 9b7591ea7..000000000 --- a/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/internal/componentcore/WebBinaryComponentHelper.java +++ /dev/null @@ -1,128 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2003, 2007 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.internal.componentcore; - -import java.io.File; -import java.io.IOException; - -import org.eclipse.emf.ecore.EObject; -import org.eclipse.jst.j2ee.commonarchivecore.internal.Archive; -import org.eclipse.jst.j2ee.commonarchivecore.internal.WARFile; -import org.eclipse.jst.j2ee.commonarchivecore.internal.exception.OpenFailureException; -import org.eclipse.jst.j2ee.commonarchivecore.internal.exception.SaveFailureException; -import org.eclipse.jst.j2ee.commonarchivecore.internal.helpers.ArchiveTypeDiscriminator; -import org.eclipse.jst.j2ee.commonarchivecore.internal.impl.WARFileImpl; -import org.eclipse.jst.j2ee.commonarchivecore.internal.strategy.LoadStrategy; -import org.eclipse.jst.j2ee.commonarchivecore.internal.strategy.War22ImportStrategyImpl; -import org.eclipse.wst.common.componentcore.resources.IVirtualComponent; - -/** - * @deprecated see {@link JavaEEBinaryComponentHelper} - * @author jasholl - * - */ -public class WebBinaryComponentHelper extends EnterpriseBinaryComponentHelper { - - public static boolean handlesComponent(IVirtualComponent component) { - WebBinaryComponentHelper helper = null; - try { - helper = new WebBinaryComponentHelper(component); - return helper.isArchiveValid(); - } catch (Exception e) { - return false; - } finally { - helper.dispose(); - } - } - - protected static class Discriminator extends War22ImportStrategyImpl.Discriminator { - - private static Discriminator instance; - - public static Discriminator getInstance() { - if (instance == null) { - instance = new Discriminator(); - } - return instance; - } - - public Archive createConvertedArchive() { - ReferenceCountedWARFileImpl archive = new ReferenceCountedWARFileImpl(); - return archive; - } - } - - protected static class ReferenceCountedWARFileImpl extends WARFileImpl implements IReferenceCountedArchive { - - private int count = 0; - - public void access() { - synchronized (this) { - count++; - } - } - - public void close() { - helper.aboutToClose(); - synchronized (this) { - count--; - if (count > 0) { - return; - } - } - physicallyClose(this); - } - - public void forceClose(){ - count = 0; - helper.aboutToClose(); - super.close(); - } - - private EnterpriseBinaryComponentHelper helper = null; - - public EnterpriseBinaryComponentHelper getEnterpriseBinaryComponentHelper() { - return helper; - } - - public void setEnterpriseBinaryComponentHelper(EnterpriseBinaryComponentHelper helper) { - this.helper = helper; - } - - protected LoadStrategy createLoadStrategyForReopen(Archive parent) throws IOException { - try { - return createBinaryLoadStrategy(getEnterpriseBinaryComponentHelper()); - } catch (OpenFailureException e) { - throw new IOException(e.getMessage()); - } - } - - @Override - protected void cleanupAfterTempSave(String uri, File original, File destinationFile) throws SaveFailureException { - helper.preCleanupAfterTempSave(uri, original, destinationFile); - super.cleanupAfterTempSave(uri, original, destinationFile); - helper.postCleanupAfterTempSave(uri, original, destinationFile); - } - } - - protected ArchiveTypeDiscriminator getDiscriminator() { - return Discriminator.getInstance(); - } - - public WebBinaryComponentHelper(IVirtualComponent component) { - super(component); - } - - public EObject getPrimaryRootObject() { - return ((WARFile) getArchive()).getDeploymentDescriptor(); - } - -} diff --git a/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/internal/delete/ClasspathDeleteInfo.java b/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/internal/delete/ClasspathDeleteInfo.java deleted file mode 100644 index fbb8341f7..000000000 --- a/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/internal/delete/ClasspathDeleteInfo.java +++ /dev/null @@ -1,76 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2003, 2004 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.internal.delete; - - -import java.util.ArrayList; -import java.util.List; - -import org.eclipse.core.resources.IProject; - -/** - * A simple structure that remembers for a given project, the manifest entries to be deleted and the - * build path entries to be deleted - */ -public class ClasspathDeleteInfo { - /** - * The project from which the dependencies will be removed - */ - protected IProject targetProject; - /** - * The literal manifest entries to be removed; String - */ - protected List manifestEntries; - /** - * The project references to be removed from the build path; IProject - */ - protected List referencedProjects; - - public ClasspathDeleteInfo(IProject project) { - super(); - targetProject = project; - } - - /** - * Gets the manifestEntries. - * - * @return Returns a List - */ - public List getManifestEntries() { - if (manifestEntries == null) - manifestEntries = new ArrayList(); - return manifestEntries; - } - - - /** - * Gets the referencedProjects. - * - * @return Returns a List - */ - public List getReferencedProjects() { - if (referencedProjects == null) - referencedProjects = new ArrayList(); - return referencedProjects; - } - - - /** - * Gets the targetProject. - * - * @return Returns a IProject - */ - public IProject getTargetProject() { - return targetProject; - } - - -}
\ No newline at end of file diff --git a/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/internal/delete/DeleteModuleOperation.java b/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/internal/delete/DeleteModuleOperation.java deleted file mode 100644 index a09dd6281..000000000 --- a/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/internal/delete/DeleteModuleOperation.java +++ /dev/null @@ -1,258 +0,0 @@ -/******************************************************************************* - * 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.internal.delete; - - -import java.lang.reflect.InvocationTargetException; - -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IProgressMonitor; - -/** - * Do not use this. It will be deleted in 3.0 - * - * @deprecated - * - */ -public class DeleteModuleOperation { //extends WTPOperation { - - protected void execute(IProgressMonitor monitor) throws CoreException, InvocationTargetException, InterruptedException { - // TODO Auto-generated method stub - - } - -// protected DeleteOptions options; -// /* -// * key is an EAREditModel and the value is a list of delete commands. We cache the commands and -// * execute later because the modules still need to exist when we go to remove module dependency -// * references. -// */ -// protected Map deferredCommands; -// protected IProgressMonitor monitor; -// protected DeleteModuleDependencyOperation deleteModuleDependencyOperation; -// protected LooseComposedEditModel deleteEditModel; -// protected List dirtyEarModels; -// -// protected static String EDIT_MODEL_KEY = "DELETE_MODULES"; //$NON-NLS-1$ -// -// public DeleteModuleOperation(DeleteOptions options) { -// this.options = options; -// } -// -// /** -// * @see HeadlessJ2EEOperation#execute(IProgressMonitor) -// */ -// protected void execute(IProgressMonitor aMonitor) throws CoreException, InvocationTargetException, InterruptedException { -// this.monitor = aMonitor; -// try { -// buildDeleteCommandsIfNecessary(); -// if (options.shouldDeleteModuleDependencies()) { -// deleteModuleDependencies(); -// } -// checkIfEarsAreDirty(); -// executeDeferredCommands(); -// saveModelsIfNecessary(); -// } finally { -// releaseModels(); -// } -// -// } -// -// protected void checkIfEarsAreDirty() { -// dirtyEarModels = new ArrayList(); -// if (deferredCommands == null) -// return; -// Iterator models = deferredCommands.keySet().iterator(); -// while (models.hasNext()) { -// EAREditModel model = (EAREditModel) models.next(); -// if (model.isDirty() && !dirtyEarModels.contains(model)) { -// dirtyEarModels.add(model); -// } -// } -// } -// -// protected void buildDeleteCommandsIfNecessary() { -// if (deferredCommands != null && !deferredCommands.isEmpty()) -// return; -// deferredCommands = new HashMap(); -// List earProjects = EARNatureRuntime.getAllEARProjectsInWorkbench(); -// for (int i = 0; i < earProjects.size(); i++) { -// IProject p = (IProject) earProjects.get(i); -// if (options.getSelectedProjects().contains(p)) -// return; -// EARNatureRuntime runtime = EARNatureRuntime.getRuntime(p); -// if (runtime != null) -// buildDeleteCommands(runtime); -// } -// } -// -// protected void buildDeleteCommands(EARNatureRuntime runtime) { -// List commands = new ArrayList(); -// EAREditModel model = runtime.getEarEditModelForWrite(this); -// List projects = options.getModuleAndUtilityProjects(); -// try { -// if (options.shouldDeleteModules()) { -// for (int i = 0; i < projects.size(); i++) { -// IProject project = (IProject) projects.get(i); -// Module m = runtime.getModule(project); -// if (m != null) -// commands.add(new RemoveModuleFromEARProjectCommand(m, runtime.getProject())); -// else { -// String uri = runtime.getJARUri(project); -// if (uri != null) -// commands.add(new RemoveUtilityJARMapCommand(runtime.getProject(), uri, project)); -// } -// } -// } -// if (!commands.isEmpty()) -// deferredCommands.put(model, commands); -// else -// model.releaseAccess(this); -// } catch (RuntimeException e) { -// model.releaseAccess(this); -// throw e; -// } catch (Error err) { -// model.releaseAccess(this); -// throw err; -// } -// } -// -// /** -// * Do this for unhandled exceptions -// */ -// protected void releaseModels() { -// if (deleteEditModel != null) { -// //TODO - RLS, 2/19/2004 we need to revisit the whole notion of the loose composed edit -// //model beccause this does not release the nested models as expected, also it looks -// // like -// // the delete edit model is never created which means validate edit is not happening -// //TODO - JAS when you look at this class to clean up the above, also look at -// // RenameModuleOperation -// //because it has the same kind of mess -// deleteEditModel.releaseAccess(this); -// deleteEditModel = null; -// } -// if (deferredCommands != null) { -// Iterator iter = deferredCommands.keySet().iterator(); -// while (iter.hasNext()) { -// EditModel editModel = (EditModel) iter.next(); -// editModel.releaseAccess(this); -// iter.remove(); -// } -// } -// } -// -// public void release() { -// releaseModels(); -// } -// -// /** -// * After a normal execution flow, save the models if necessary -// */ -// protected void saveModelsIfNecessary() { -// if (deferredCommands == null) -// return; -// Iterator models = deferredCommands.keySet().iterator(); -// while (models.hasNext()) { -// EAREditModel model = (EAREditModel) models.next(); -// if (model.isDirty()) { -// if (dirtyEarModels.contains(model)) { -// model.saveIfNecessary(this); -// } else { -// model.save(this); -// } -// } -// } -// } -// -// protected void deleteModuleDependencies() throws InvocationTargetException, InterruptedException { -// getDeleteModuleDependencyOperation().run(monitor); -// } -// -// protected DeleteModuleDependencyOperation getDeleteModuleDependencyOperation() { -// if (deleteModuleDependencyOperation == null) { -// List earEditModels = new ArrayList(); -// Iterator iter = deferredCommands.keySet().iterator(); -// while (iter.hasNext()) -// earEditModels.add(((EAREditModel) iter.next()).getEARNature()); -// deleteModuleDependencyOperation = new DeleteModuleDependencyOperation(earEditModels, new HashSet(options.getModuleAndUtilityProjects())); -// } -// return deleteModuleDependencyOperation; -// } -// -// protected void executeDeferredCommands() { -// Iterator it = deferredCommands.entrySet().iterator(); -// while (it.hasNext()) { -// Map.Entry entry = (Map.Entry) it.next(); -// List commands = (List) entry.getValue(); -// executeCommands(commands); -// -// } -// } -// -// protected void executeCommands(List commands) { -// for (int i = 0; i < commands.size(); i++) { -// Command cmd = (Command) commands.get(i); -// cmd.execute(); -// } -// } -// -// /** -// * Return a list of all the non-resource files that will get modified as a result of running -// * this operation; used for validate edit. -// */ -// protected List getAffectedNonResourceFiles() { -// if (options.shouldDeleteModuleDependencies()) -// return getDeleteModuleDependencyOperation().getAffectedFiles(); -// return Collections.EMPTY_LIST; -// } -// -// /** -// * Use this only for validate edits -// */ -// public ComposedEditModel getDeleteEditModel() { -// if (deleteEditModel == null) -// initializeDeleteEditModel(); -// return deleteEditModel; -// } -// -// protected void initializeDeleteEditModel() { -// if (options.getAllProjectsToDelete().size() == 0) { -// throw new RuntimeException(J2EECreationResourceHandler.getString("DeleteModuleOperation_UI_0")); //$NON-NLS-1$ -// } -// -// buildDeleteCommandsIfNecessary(); -// IProject project = null; -// project = (IProject) options.getAllProjectsToDelete().get(0); -// -// deleteEditModel = new LooseComposedEditModel(EDIT_MODEL_KEY, (EMFWorkbenchContext) WorkbenchResourceHelper.getEMFContext(project)) { -// -// /** -// * @see org.eclipse.jst.j2ee.internal.internal.workbench.EditModel#getNonResourceFiles() -// */ -// public List getNonResourceFiles() { -// List result = super.getNonResourceFiles(); -// result.addAll(getAffectedNonResourceFiles()); -// return result; -// } -// }; -// -// Iterator it = deferredCommands.keySet().iterator(); -// while (it.hasNext()) { -// deleteEditModel.addChild((J2EEEditModel) it.next()); -// } -// } -// -// public IStatus getStatus() { -// return deleteModuleDependencyOperation.getStatus(); -// } - -} diff --git a/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/internal/delete/DeleteOptions.java b/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/internal/delete/DeleteOptions.java deleted file mode 100644 index a921577e5..000000000 --- a/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/internal/delete/DeleteOptions.java +++ /dev/null @@ -1,126 +0,0 @@ -/*************************************************************************************************** - * Copyright (c) 2003, 2004 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.internal.delete; - - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -public class DeleteOptions { - - protected boolean isEARDelete; - protected boolean deleteProjects; - protected boolean deleteModules; - protected boolean deleteModuleDependencies; - protected List selectedProjects; - /** Applicable for EAR delete */ - protected List selectedReferencedProjects; - - /** - * Constructor for DeleteOptions. - */ - public DeleteOptions() { - super(); - } - - - public boolean shouldDeleteModules() { - return deleteModules; - } - - - public void setDeleteModules(boolean deleteModulesFromAllEARs) { - this.deleteModules = deleteModulesFromAllEARs; - } - - - public boolean shouldDeleteProjects() { - return deleteProjects; - } - - - public void setDeleteProjects(boolean deleteProjects) { - this.deleteProjects = deleteProjects; - } - - - public boolean shouldDeleteModuleDependencies() { - return deleteModuleDependencies; - } - - - public void setDeleteModuleDependencies(boolean deleteReferencesFromModuleDependencies) { - this.deleteModuleDependencies = deleteReferencesFromModuleDependencies; - } - - public List getModuleAndUtilityProjects() { - if (isEARDelete) - return getSelectedReferencedProjects(); - return getSelectedProjects(); - } - - public List getAllProjectsToDelete() { - List result = new ArrayList(); - result.addAll(getSelectedProjects()); - result.addAll(getSelectedReferencedProjects()); - return result; - } - - /** - * Gets the selectedProjects. - * - * @return Returns a List - */ - public List getSelectedProjects() { - if (selectedProjects == null) - return Collections.EMPTY_LIST; - return selectedProjects; - } - - /** - * Sets the selectedProjects. - * - * @param selectedProjects - * The selectedProjects to set - */ - public void setSelectedProjects(List selectedProjects) { - this.selectedProjects = selectedProjects; - } - - /** - * Gets the selectedReferencedProjects. - * - * @return Returns a List - */ - public List getSelectedReferencedProjects() { - if (selectedReferencedProjects == null) - return Collections.EMPTY_LIST; - return selectedReferencedProjects; - } - - /** - * Sets the selectedReferencedProjects. - * - * @param selectedReferencedProjects - * The selectedReferencedProjects to set - */ - public void setSelectedReferencedProjects(List selectedReferencedProjects) { - this.selectedReferencedProjects = selectedReferencedProjects; - } - - public boolean isEARDelete() { - return isEARDelete; - } - - public void setIsEARDelete(boolean isEARDelete) { - this.isEARDelete = isEARDelete; - } - -}
\ No newline at end of file diff --git a/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/internal/project/Assert.java b/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/internal/project/Assert.java deleted file mode 100644 index 126f9e882..000000000 --- a/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/internal/project/Assert.java +++ /dev/null @@ -1,110 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 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.internal.project; - -/** - * <code>Assert</code> is useful for for embedding runtime sanity checks - * in code. - * The predicate methods all test a condition and throw some - * type of unchecked exception if the condition does not hold. - * <p> - * Assertion failure exceptions, like most runtime exceptions, are - * thrown when something is misbehaving. Assertion failures are invariably - * unspecified behavior; consequently, clients should never rely on - * these being thrown (and certainly should not being catching them - * specifically). - * </p> - */ -public final class Assert { - /* This class is not intended to be instantiated. */ - private Assert() { - // not allowed - } - - /** Asserts that an argument is legal. If the given boolean is - * not <code>true</code>, an <code>IllegalArgumentException</code> - * is thrown. - * - * @param expression the outcode of the check - * @return <code>true</code> if the check passes (does not return - * if the check fails) - * @exception IllegalArgumentException if the legality test failed - */ - public static boolean isLegal(boolean expression) { - return isLegal(expression, ""); //$NON-NLS-1$ - } - - /** Asserts that an argument is legal. If the given boolean is - * not <code>true</code>, an <code>IllegalArgumentException</code> - * is thrown. - * The given message is included in that exception, to aid debugging. - * - * @param expression the outcode of the check - * @param message the message to include in the exception - * @return <code>true</code> if the check passes (does not return - * if the check fails) - * @exception IllegalArgumentException if the legality test failed - */ - public static boolean isLegal(boolean expression, String message) { - if (!expression) - throw new IllegalArgumentException(message); - return expression; - } - - /** Asserts that the given object is not <code>null</code>. If this - * is not the case, some kind of unchecked exception is thrown. - * - * @param object the value to test - * @exception IllegalArgumentException if the object is <code>null</code> - */ - public static void isNotNull(Object object) { - isNotNull(object, ""); //$NON-NLS-1$ - } - - /** Asserts that the given object is not <code>null</code>. If this - * is not the case, some kind of unchecked exception is thrown. - * The given message is included in that exception, to aid debugging. - * - * @param object the value to test - * @param message the message to include in the exception - * @exception IllegalArgumentException if the object is <code>null</code> - */ - public static void isNotNull(Object object, String message) { - if (object == null) - throw new AssertionFailedException("null argument:" + message); //$NON-NLS-1$ - } - - /** Asserts that the given boolean is <code>true</code>. If this - * is not the case, some kind of unchecked exception is thrown. - * - * @param expression the outcode of the check - * @return <code>true</code> if the check passes (does not return - * if the check fails) - */ - public static boolean isTrue(boolean expression) { - return isTrue(expression, ""); //$NON-NLS-1$ - } - - /** Asserts that the given boolean is <code>true</code>. If this - * is not the case, some kind of unchecked exception is thrown. - * The given message is included in that exception, to aid debugging. - * - * @param expression the outcode of the check - * @param message the message to include in the exception - * @return <code>true</code> if the check passes (does not return - * if the check fails) - */ - public static boolean isTrue(boolean expression, String message) { - if (!expression) - throw new AssertionFailedException("assertion failed: " + message); //$NON-NLS-1$ - return expression; - } -} diff --git a/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/internal/project/AssertionFailedException.java b/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/internal/project/AssertionFailedException.java deleted file mode 100644 index 4b73c2bf3..000000000 --- a/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/internal/project/AssertionFailedException.java +++ /dev/null @@ -1,34 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 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.internal.project; - -/** - * <code>AssertionFailedException</code> is a runtime exception thrown - * by some of the methods in <code>Assert</code>. - * <p> - * This class is not declared public to prevent some misuses; programs that catch - * or otherwise depend on assertion failures are susceptible to unexpected - * breakage when assertions in the code are added or removed. - * </p> - */ -/* package */ -class AssertionFailedException extends RuntimeException { - /** - * All serializable objects should have a stable serialVersionUID - */ - private static final long serialVersionUID = 1L; - - /** Constructs a new exception with the given message. - */ - public AssertionFailedException(String detail) { - super(detail); - } -} diff --git a/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/internal/project/IJ2EEProjectTypes.java b/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/internal/project/IJ2EEProjectTypes.java deleted file mode 100644 index 684f12120..000000000 --- a/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/internal/project/IJ2EEProjectTypes.java +++ /dev/null @@ -1,23 +0,0 @@ -/*************************************************************************************************** - * Copyright (c) 2003, 2004 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.internal.project; - - -public interface IJ2EEProjectTypes { - int SOURCE = 1; - int BINARY = 2; - int DEFAULT = 3; - int UTIL = 4; - int EJB_CLIENT = 5; - int MODULE = 6; - int EJB_MODULE = 7; - int WEB_MODULE = 8; - int JCA_MODULE = 9; - int APPCLIENT_MODULE = 10; -}
\ No newline at end of file diff --git a/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/internal/project/J2EECreationResourceHandler.java b/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/internal/project/J2EECreationResourceHandler.java deleted file mode 100644 index dcb326b28..000000000 --- a/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/internal/project/J2EECreationResourceHandler.java +++ /dev/null @@ -1,162 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2003, 2006 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.internal.project; - - -import org.eclipse.osgi.util.NLS; - -public class J2EECreationResourceHandler extends NLS { - private static final String BUNDLE_NAME = "j2eecreation";//$NON-NLS-1$ - - private J2EECreationResourceHandler() { - // Do not instantiate - } - - public static String EJBReferenceDataModel_UI_12; - public static String MIGRATE_J2EE_SPEC_UI_; - public static String EJBReferenceDataModel_UI_11; - public static String EJBReferenceDataModel_UI_10; - public static String REQUIRED_CLIENT_VIEW_TITLE; - public static String MIGRATION_COMPLETE; - public static String NOT_NEEDED_DEPLOYMENT_DESC_MIG; - public static String MIGRATION_WARNINGS_REPORT_UI_; - public static String BACKEND_MIGRATION_FAILED; - public static String REUSE_DELETED_CLIENT_VIEW_NAME_UI_; - public static String EJB_PROJECTS_UI_; - public static String NOT_NEEDED_BACKEND_MIG; - public static String MIGRATION_NOT_POSSIBLE_REPORT; - public static String PROJECT_MUST_BE_SELECTED_UI_; - public static String JAR_11_IMPORT_20_UI_; - public static String WEBCONTENT_FOLDER_RENAME_SKIPPED; - public static String CONFIRM_MIGRATE_PROJECT_STRUCTURE; - public static String WEBPROJECT_VERSION_MIGRATE_FAILED; - public static String JdkJarFileDoesNotExist_UI; - public static String Local_cannot_be_empty_UI_; - public static String LOCAL_CLIENT_NOT_NEEDED; - public static String REMOTE_CLIENT_VIEWS_NOT_EXIST_UI_; - public static String MIGRATING_PROJECT_STRUCTURES_UI_; - public static String ResourceEnvironmentReferenceDataModel_2; - public static String J2EE_1_2_ONLY_HAVE_REMOTE; - public static String OPEN_EDITORS_TITLE; - public static String EJB_MUST_BE_SELECTED_UI_; - public static String FAILED_MIGRATING_IMPORTED_CLASSES; - public static String OPEN_J2EE_MIGRATION_WIZARD_UI_; - public static String LOCAL_CLIENT_VIEWS_EXIST_UI_; - public static String DELETING_REMOTE_CLIENT_VIEWS_UI_; - public static String EJB_UI_; - public static String CONFIRM_CLIENT_VIEW_REQUIRED; - public static String MIGRATION_NOT_NEEDED; - public static String ADDING_LOCAL_CLIENT_VIEWS_UI_; - public static String WEB_UI_; - public static String DeleteModuleOperation_UI_0; - public static String Home_cannot_be_empty_UI_; - public static String WEBCONTENT_LIBPATH_UPDATE_FAILED; - public static String REMOTE_CLIENT_DELETE_SUCCESS_UI_; - public static String ServerTargetDataModel_UI_9; - public static String LOCAL_CLIENT_ADD_FAILED_UI_; - public static String ServerTargetDataModel_UI_8; - public static String OLD_PROJECT_STRUCTURE_UI_; - public static String ServerTargetDataModel_UI_7; - public static String INFORM_PROPER_SELECTION; - public static String MIGRATE_MODULE_PROJECTS_UI_; - public static String COMPLETED_LOCAL_CLIENT_CREATE; - public static String IMPORTED_CLASSES_FILE_DELETED; - public static String ADD_LOCAL_CLIENT_VIEWS_BAN_UI_; - public static String USE_REMOTE_FOR_DIFFERENT_EAR; - public static String APP_PROJECT_ERROR_EXC_; - public static String InvalidCharsError; - public static String ENTERPRISE_APPLICATIONS_UI_; - public static String ResourceReferenceDataModel_UI_1; - public static String ResourceReferenceDataModel_UI_0; - public static String DELETE_REM_CLIENT_VIEWS_UI_; - public static String Errors_occurred_renaming_module_dependencies_UI_; - public static String MIGRATION_ERRORS_REPORT_UI_; - public static String J2EE_VERSION_FAILED_UI_; - public static String COMPLETED_DEPLOY_DELETE; - public static String PROJECT_REFERENCES_UPDATED; - public static String TARGET_ALSO_EXIST_IN_SAME_EAR; - public static String WEBCONTENT_FOLDER_RENAME_FAILED; - public static String MIGRATE_UI_; - public static String Creating__UI_; - public static String Error_creating_an_EAR_proj_UI_; - public static String ReferenceDataModel_UI_6; - public static String ReferenceDataModel_UI_5; - public static String ReferenceDataModel_UI_3; - public static String ENTERPRISE_BEANS_BAN_UI_; - public static String ADD_LOCAL_CLIENT_VIEWS_CHECK_UI_; - public static String Can_not_rename_module_dependency_from_project_UI_; - public static String PROJECT_STRUCTURE_SUCCESS_UI_; - public static String SOURCE_FOLDER_RENAME_SKIPPED; - public static String UNKNOWN_UI_; - public static String WIZ_BAN_DESC_UI_; - public static String COMPLETED_CMP20_CODEGEN; - public static String PROJECT_NOT_NEED_MIGRATION_UI_; - public static String SELECT_EJB_CLIENT_VIEWS_UI_; - public static String Creating_Java_Project_UI_; - public static String REMOTE_CLIENT_DELETE_FAILED_UI_; - public static String FILES_OUT_OF_SYNC; - public static String MIGRATE_CMP_BEANS_UI_; - public static String Remote_cannot_be_empty_UI_; - public static String Errors_occurred_deleting_module_dependencies_UI_; - public static String Can_not_remove_module_dependency_from_project_UI_; - public static String INVALID_SELECTION_TITLE; - public static String ABS_PATHS_APP_EXT_REMOVED; - public static String Local_home_cannot_be_empty_UI_; - public static String USE_LOCAL_FOR_DIFFERENT_EAR; - public static String ENTERPRISE_APP_PROJECTS_UI_; - public static String MIGRATE_J2EE_PROJECTS_UI_; - public static String MIGRATION_SUCCESS_REPORT_UI_; - public static String FAILED_DEPLOY_DELETE; - public static String J2EE_VERSION_NOT_NEED_MIGRATION_UI_; - public static String MIGRATING_J2EE_VERSION_UI_; - public static String APPLICATION_CLIENTS_UI_; - public static String ServiceReferenceDataModel_ERROR_8; - public static String PROJECT_STRUCTURE_FAILED_UI_; - public static String LOCAL_CLIENT_ADD_SUCCESS_UI_; - public static String COMPONENT_ALREADYINEAR; - public static String COMPLETED_BACKEND_MIG; - public static String MIGRATE_EJB_SPEC_UI_; - public static String RenameModuleOperation_UI_0; - public static String CMP_11_IMPORT_20_UI_; - public static String J2EE_PROJECT_MIGRATION_TITLE_UI_; - public static String APP_CLIENT_ONLY_HAVE_REMOTE; - public static String MIGRATION_NOT_NEEDED_REPORT; - public static String LOCAL_CLIENT_VIEW_SCHEME_UI_; - public static String BINARY_MIGRATION_FAILED; - public static String ENTERPRISE_APPLICATION_UI_; - public static String INFORM_OPEN_EDITORS; - public static String EXTRACTED_IMPORTED_CLASSES; - public static String J2EE_VERSION_SUCCESS_UI_; - public static String SUFFIX_EXAMPLE_UI_; - public static String CONFIRMATION_TITLE; - public static String MIGRATION_ERRORS; - public static String APPLICATION_CLIENT_UI_; - public static String SPECIFY_SUFFIX_UI_; - public static String CONFIRM_MIGRATE_J2EE_13; - public static String PortComponentReferenceDataModel_ERROR_4; - public static String FAILED_LOCAL_CLIENT_CREATE; - public static String MessageDestReferenceDataModel_9; - public static String APPLICATION_CLIENT_PROJECTS_UI_; - public static String MessageDestReferenceDataModel_8; - public static String SOURCE_FOLDER_RENAME_FAILED; - public static String MessageDestReferenceDataModel_7; - public static String ENTERPRISE_BEANS_LIST_UI_; - public static String PROJECT_CLASSPATH_UPDATED; - public static String VERSION_NOT_SUPPORTED; - - static { - NLS.initializeMessages(BUNDLE_NAME, J2EECreationResourceHandler.class); - } - - public static String getString(String key, Object[] args) { - return NLS.bind(key, args); - } -} diff --git a/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/internal/project/J2EEJavaProjectInfo.java b/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/internal/project/J2EEJavaProjectInfo.java deleted file mode 100644 index bdbacddfe..000000000 --- a/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/internal/project/J2EEJavaProjectInfo.java +++ /dev/null @@ -1,481 +0,0 @@ -/******************************************************************************* - * 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.internal.project; - - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IWorkspace; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.Path; -import org.eclipse.jdt.core.IClasspathEntry; -import org.eclipse.jdt.core.IJavaProject; -import org.eclipse.jdt.core.JavaCore; -import org.eclipse.jdt.core.JavaModelException; -import org.eclipse.jem.internal.plugin.JavaProjectInfo; -import org.eclipse.wst.server.core.IRuntime; - -/** - * This class stores the info required for creating a new J2EE project; not all info will apply to - * all kinds of projects - */ -public class J2EEJavaProjectInfo extends JavaProjectInfo { - protected static final String SRCROOT_VAR = "JRE_SRCROOT"; //$NON-NLS-1$ - protected IProject project; - protected String jdkRTJarPath; - protected String projectName; - protected IPath projectLocation; - protected String javaOutputPath; - protected IClasspathEntry[] classpathEntries; - protected boolean shouldInitializeDefaultClasspath = true; - protected String natureId; - protected IRuntime serverTarget; - protected int moduleVersion; - - /** - * EJBProjectInfo constructor comment. - */ - public J2EEJavaProjectInfo() { - super(); - } - - /** - * EJBProjectInfo constructor comment. - */ - public J2EEJavaProjectInfo(IProject project) { - super(); - setProject(project); - } - - public IClasspathEntry[] calculateServerClasspathEntries() throws JavaModelException { - IJavaProject javaProject = getJavaProject(); - if (javaProject == null) - return null; - if (getProject().exists()) { - //We don't need to remove a server target anyomre as it need to be there - //ServerTargetManager.removeServerTarget(getProject(),null); - IClasspathEntry[] ces = javaProject.getRawClasspath(); - if (ces.length > 0) - addToClasspathEntries(ces); - } - addServerJdkRuntimeToClasspathEntries(); - addServerJarsToClasspathEntries(); - return classpathEntries; - } - - /** - * Sets up the default classpath for this project - */ - protected void addDefaultToClasspathEntries() { - addToClasspathEntries(computeDefaultJavaClasspath()); - } - - /** - * Set the corresponding jsp and servlet levels. Creation date: (11/09/00 10:05:24 AM) - */ - public void setJ2EEVersion(int newVersion) { - } - - - /** - * add the source folder to classpath dir (IClasspathEntry.CPE_SOURCE) - */ - public void addJavaSourceToClasspathEntries() { - IPath sourceClassPath = new Path(getFullSourcePath()); - addToClasspathEntries(new IClasspathEntry[]{JavaCore.newSourceEntry(sourceClassPath)}); - } - - public boolean addJdkJarToClasspathEntries(String jdkJarFullPathName) { - - IJavaProject javaProject = getJavaProject(); - if (javaProject == null) - return false; - - IClasspathEntry[] entry = new IClasspathEntry[1]; - Path path = new Path(jdkJarFullPathName); - if (!path.toFile().exists()) { - org.eclipse.jem.util.logger.proxy.Logger.getLogger().logError(J2EECreationResourceHandler.getString(J2EECreationResourceHandler.JdkJarFileDoesNotExist_UI, new Object[]{jdkJarFullPathName})); - return false; - } - - entry[0] = JavaCore.newLibraryEntry(path, null, null); - addToClasspathEntries(entry); - - return true; - } - - /** - * add rt.jar form the server.jdk plugin - */ - public void addServerJdkRuntimeToClasspathEntries() { - addToClasspathEntries(getServerJDKClasspathEntries()); - } - - public IClasspathEntry[] getServerJDKClasspathEntries() { - List list = new ArrayList(4); - //TODO This class should be deleted. - // if (isJ2EE13() - // || !org.eclipse.jst.j2ee.internal.internal.plugin.J2EEPlugin.hasDevelopmentRole()) { - // list.add(JavaCore.newVariableEntry(new - // Path(IEJBNatureConstants.SERVERJDK_50_PLUGINDIR_VARIABLE + "/jre/lib/rt.jar"), - // //$NON-NLS-1$ - // new Path(IEJBNatureConstants.SERVERJDK_50_PLUGINDIR_VARIABLE + "/src.jar"), //$NON-NLS-1$ - // new Path(IEJBNatureConstants.SERVERJDK_SRCROOT_VARIABLE))); //$NON-NLS-1$ - // } else { - // list.add(JavaCore.newVariableEntry(new - // Path(IEJBNatureConstants.SERVERJDK_PLUGINDIR_VARIABLE + "/jre/lib/rt.jar"), //$NON-NLS-1$ - // new Path(IEJBNatureConstants.SERVERJDK_PLUGINDIR_VARIABLE + "/src.jar"), //$NON-NLS-1$ - // new Path(IEJBNatureConstants.SERVERJDK_SRCROOT_VARIABLE))); //$NON-NLS-1$ - // } - return (IClasspathEntry[]) list.toArray(new IClasspathEntry[list.size()]); - } - - /** - * Adds entries to the class path for this project - */ - public void addToClasspathEntries(IClasspathEntry[] entries) { - - java.util.List list = new ArrayList(10); - // add the existing ones if any - if (classpathEntries != null) - list.addAll(Arrays.asList(classpathEntries)); - - // add the new ones - list.addAll(Arrays.asList(entries)); - - // convert - classpathEntries = new IClasspathEntry[list.size()]; - classpathEntries = (IClasspathEntry[]) list.toArray(classpathEntries); - - } - - public boolean addVariableJarToClasspathEntries(String fullPath) { - - IJavaProject javaProject = getJavaProject(); - if (javaProject == null) - return false; - - IClasspathEntry[] entry = new IClasspathEntry[1]; - entry[0] = JavaCore.newVariableEntry(new Path(fullPath), null, null); - addToClasspathEntries(entry); - return true; - } - - public boolean addVariableJarToClasspathEntriesWithAttachments(String fullPath, String srcPath, String srcRoot) { - - IJavaProject javaProject = getJavaProject(); - if (javaProject == null) - return false; - - IClasspathEntry[] entry = new IClasspathEntry[1]; - entry[0] = JavaCore.newVariableEntry(new Path(fullPath), new Path(srcPath), new Path(srcRoot)); - addToClasspathEntries(entry); - return true; - } - - /** - * Return the default classpath for projects of this kind; subclasses should override for - * setting up new projects - */ - protected IClasspathEntry[] computeDefaultJavaClasspath() { - IJavaProject javaProject = getJavaProject(); - if (javaProject == null) - return null; - addJavaSourceToClasspathEntries(); - if (serverTarget == null) { - addServerJdkRuntimeToClasspathEntries(); - addServerJarsToClasspathEntries(); - } - return classpathEntries; - } - - /** - * Sublcasses have to overide this method to set the server jars - */ - public void addServerJarsToClasspathEntries() { - - } - - /** - * Creates a project handle with a specified path. The project resource should <b>not </b> be - * created concretely here; - */ - public IProject createProjectHandle(IPath projectPath) { - return getWorkspace().getRoot().getProject(projectPath.segment(0)); - } - - public IClasspathEntry[] getClasspathEntries() { - if (classpathEntries == null) - initializeClasspathEntries(); - return classpathEntries; - } - - /** - * Insert the method's description here. Creation date: (11/09/00 10:05:24 AM) - * - * @return java.lang.String - */ - public java.lang.String getDefaultContextRoot() { - return null; - } - - /** - * Subclasses should override as necessary - */ - protected String getDefaultJavaOutputPath() { - return DEFAULT_JAVA_OUTPUT_PATH; - } - - /** - * Insert the method's description here. Creation date: (11/09/00 10:05:24 AM) - * - * @return java.lang.String - */ - public java.lang.String getDefaultUri() { - return projectName.replace(' ', '_') + ".jar"; //$NON-NLS-1$ - } - - /** - * Get the java output folder for the receiver, in the form of /project/ <output folder> - * - * @return java.lang.String - */ - public String getFullJavaOutputPath() { - return Path.ROOT.append(getProjectPath()).append(getJavaOutputPath()).toString(); - } - - /** - * Get the module path folder for the receiver in the form of /project/modulepath - * - * @return java.lang.String - */ - protected String getFullSourcePath() { - return Path.ROOT.append(getProjectPath()).append(getSourcePath()).toString(); - } - - /** - * Returns the project relative path of the java build destination - */ - public java.lang.String getJavaOutputPath() { - if (javaOutputPath == null) - javaOutputPath = getDefaultJavaOutputPath(); - return javaOutputPath; - } - - /** - * @param i - */ - public void setModuleVersion(int version) { - moduleVersion = version; - } - - public IJavaProject getJavaProject() { - // needed to get an IJavaProject to create classpaths from. - IProject aProject = getProject(); - if (aProject == null) - aProject = getWorkspace().getRoot().getProject(getProjectName()); - - return JavaCore.create(aProject); - } - - /** - * Return the absolute path of the default jdk rt.jar to use for this project - */ - public java.lang.String getJdkRTJarPath() { - return jdkRTJarPath; - } - - /** - * Return the project being created; checks the workspace for an existing project - */ - public IProject getProject() { - if (project == null) { - IProject aProject = getWorkspace().getRoot().getProject(getProjectName()); - if (aProject.exists()) - project = aProject; - } - return project; - } - - /** - * Return the location of the project in the file system. - * - * @return org.eclipse.core.runtime.IPath - */ - public IPath getProjectLocation() { - return projectLocation; - } - - /** - * Insert the method's description here. Creation date: (11/09/00 10:05:24 AM) - * - * @return java.lang.String - */ - public java.lang.String getProjectName() { - if (projectName == null && project != null) - projectName = project.getName(); - return projectName; - } - - public IPath getProjectPath() { - return new Path(getProjectName()); - } - - public IWorkspace getWorkspace() { - return org.eclipse.jst.j2ee.internal.plugin.J2EEPlugin.getWorkspace(); - } - - /** - * Lazy initialization - useGetClasspathEntries - */ - protected void initializeClasspathEntries() { - if (shouldInitializeDefaultClasspath()) - computeDefaultJavaClasspath(); - else - classpathEntries = new IClasspathEntry[0]; - } - - /** - * Answer false by default - * - * @deprecated - Use getModuleVersion() with J2EEVersionConstants - */ - protected boolean isJ2EE13() { - return false; - } - - public IProject primGetProject() { - return project; - } - - public void removeClasspathEntry(IClasspathEntry entry) { - if (entry == null) - return; - - List list = new ArrayList(Arrays.asList(getClasspathEntries())); - list.remove(entry); - classpathEntries = (IClasspathEntry[]) list.toArray(new IClasspathEntry[list.size()]); - } - - /** - * Insert the method's description here. Creation date: (11/10/00 10:09:58 AM) - * - * @param newClassPathEntries - * org.eclipse.jdt.core.api.IClasspathEntry - */ - public void setClasspathEntries(IClasspathEntry[] newClasspathEntries) { - classpathEntries = newClasspathEntries; - } - - public void setJavaOutputPath(String path) { - javaOutputPath = path; - } - - public void setJdkRTJarPath(String path) { - jdkRTJarPath = path; - } - - public void setProject(IProject aProject) { - project = aProject; - } - - /** - * Set the location in the file system that the project is to be created. - * - * @param newProjectLocation - * IPath - */ - public void setProjectLocation(IPath newProjectLocation) { - projectLocation = newProjectLocation; - } - - /** - * Insert the method's description here. Creation date: (11/09/00 10:05:24 AM) - * - * @param newProjectName - * java.lang.String - */ - public void setProjectName(java.lang.String newProjectName) { - if (projectName != newProjectName) - setClasspathEntries(null); - projectName = newProjectName; - } - - public void setShouldInitializeDefaultClasspath(boolean value) { - shouldInitializeDefaultClasspath = value; - } - - public boolean shouldInitializeDefaultClasspath() { - return shouldInitializeDefaultClasspath; - } - - /** - * Gets the natureId. - * - * @return Returns a String - */ - public String getNatureId() { - if (natureId == null) - return getDefaultNatureId(); - return natureId; - } - - /** - * returns the correct nature id string based on the J2EE spec level being used - */ - public String getDefaultNatureId() { - return null; - } - - /** - * Sets the natureId. - * - * @param natureId - * The natureId to set - */ - public void setNatureId(String natureId) { - this.natureId = natureId; - } - - /** - * Get the correct WAS classpath variable based on the J2EE version. - */ - protected String getWASPluginVariable() { - //TODO This class needs to be deleted. - // if (isJ2EE13() - // || !org.eclipse.jst.j2ee.internal.internal.plugin.J2EEPlugin.hasDevelopmentRole()) - // return IEJBNatureConstants.WAS_50_PLUGINDIR_VARIABLE; - // else - // return IEJBNatureConstants.WAS_PLUGINDIR_VARIABLE; - return ""; //$NON-NLS-1$ - } - - public int getModuleVersion() { - return moduleVersion; - } - - /** - * @return - */ - public IRuntime getServerTarget() { - return serverTarget; - } - - /** - * @param target - */ - public void setServerTarget(IRuntime target) { - serverTarget = target; - } -} diff --git a/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/internal/project/J2EEProjectUtilities.java b/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/internal/project/J2EEProjectUtilities.java deleted file mode 100644 index eee910fb8..000000000 --- a/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/internal/project/J2EEProjectUtilities.java +++ /dev/null @@ -1,1179 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2003, 2007 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.internal.project; - -import java.io.FileNotFoundException; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.eclipse.core.resources.ICommand; -import org.eclipse.core.resources.IContainer; -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IFolder; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IProjectDescription; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.NullProgressMonitor; -import org.eclipse.core.runtime.Path; -import org.eclipse.core.runtime.Platform; -import org.eclipse.emf.common.util.URI; -import org.eclipse.jdt.core.IClasspathEntry; -import org.eclipse.jdt.core.ICompilationUnit; -import org.eclipse.jdt.core.IJavaProject; -import org.eclipse.jdt.core.IPackageFragmentRoot; -import org.eclipse.jdt.core.JavaCore; -import org.eclipse.jdt.core.JavaModelException; -import org.eclipse.jem.java.JavaClass; -import org.eclipse.jem.java.JavaRefFactory; -import org.eclipse.jem.util.emf.workbench.ProjectUtilities; -import org.eclipse.jem.util.emf.workbench.WorkbenchByteArrayOutputStream; -import org.eclipse.jem.util.logger.proxy.Logger; -import org.eclipse.jem.util.plugin.JEMUtilPlugin; -import org.eclipse.jem.workbench.utility.JemProjectUtilities; -import org.eclipse.jst.j2ee.commonarchivecore.internal.Archive; -import org.eclipse.jst.j2ee.commonarchivecore.internal.EARFile; -import org.eclipse.jst.j2ee.commonarchivecore.internal.EJBJarFile; -import org.eclipse.jst.j2ee.commonarchivecore.internal.File; -import org.eclipse.jst.j2ee.commonarchivecore.internal.exception.DeploymentDescriptorLoadException; -import org.eclipse.jst.j2ee.commonarchivecore.internal.exception.OpenFailureException; -import org.eclipse.jst.j2ee.commonarchivecore.internal.helpers.ArchiveManifest; -import org.eclipse.jst.j2ee.commonarchivecore.internal.helpers.ArchiveManifestImpl; -import org.eclipse.jst.j2ee.commonarchivecore.internal.impl.CommonarchiveFactoryImpl; -import org.eclipse.jst.j2ee.commonarchivecore.internal.util.ArchiveUtil; -import org.eclipse.jst.j2ee.ejb.EJBJar; -import org.eclipse.jst.j2ee.ejb.EnterpriseBean; -import org.eclipse.jst.j2ee.internal.J2EEConstants; -import org.eclipse.jst.j2ee.internal.J2EEVersionConstants; -import org.eclipse.jst.j2ee.internal.archive.operations.JavaComponentLoadStrategyImpl; -import org.eclipse.jst.j2ee.internal.common.J2EEVersionUtil; -import org.eclipse.jst.j2ee.internal.common.classpath.J2EEComponentClasspathUpdater; -import org.eclipse.jst.j2ee.internal.componentcore.JavaEEBinaryComponentHelper; -import org.eclipse.jst.j2ee.internal.moduleextension.EarModuleManager; -import org.eclipse.jst.j2ee.internal.plugin.J2EEPlugin; -import org.eclipse.jst.j2ee.project.EarUtilities; -import org.eclipse.jst.j2ee.project.JavaEEProjectUtilities; -import org.eclipse.jst.j2ee.project.facet.IJ2EEFacetConstants; -import org.eclipse.jst.j2ee.project.facet.IJavaProjectMigrationDataModelProperties; -import org.eclipse.jst.j2ee.project.facet.JavaProjectMigrationDataModelProvider; -import org.eclipse.jst.j2ee.project.facet.JavaProjectMigrationOperation; -import org.eclipse.jst.jee.archive.IArchive; -import org.eclipse.jst.jee.archive.IArchiveResource; -import org.eclipse.jst.server.core.FacetUtil; -import org.eclipse.wst.common.componentcore.ComponentCore; -import org.eclipse.wst.common.componentcore.internal.impl.ModuleURIUtil; -import org.eclipse.wst.common.componentcore.internal.util.ComponentUtilities; -import org.eclipse.wst.common.componentcore.internal.util.IModuleConstants; -import org.eclipse.wst.common.componentcore.resources.IVirtualComponent; -import org.eclipse.wst.common.componentcore.resources.IVirtualFile; -import org.eclipse.wst.common.componentcore.resources.IVirtualFolder; -import org.eclipse.wst.common.componentcore.resources.IVirtualReference; -import org.eclipse.wst.common.componentcore.resources.IVirtualResource; -import org.eclipse.wst.common.frameworks.datamodel.DataModelFactory; -import org.eclipse.wst.common.frameworks.datamodel.IDataModel; -import org.eclipse.wst.common.frameworks.internal.SimpleValidateEdit; -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; -import org.eclipse.wst.server.core.IRuntime; - -public class J2EEProjectUtilities extends ProjectUtilities implements IJ2EEFacetConstants { - - /** - * Return the absolute path of a loose archive in a J2EE application or WAR file - */ - public static IPath getRuntimeLocation(IProject aProject) { - if (JemProjectUtilities.isBinaryProject(aProject)) - return getBinaryProjectJARLocation(aProject); - return JemProjectUtilities.getJavaProjectOutputAbsoluteLocation(aProject); - } - - public static IPath getBinaryProjectJARLocation(IProject aProject) { - List sources = JemProjectUtilities.getLocalJARPathsFromClasspath(aProject); - if (!sources.isEmpty()) { - IPath path = (IPath) sources.get(0); - return aProject.getFile(path).getLocation(); - } - return null; - } - - public static Archive getClientJAR(EJBJarFile file, EARFile earFile) { - EJBJar jar = null; - try { - jar = file.getDeploymentDescriptor(); - } catch (DeploymentDescriptorLoadException exc) { - return null; - } - if (jar == null) - return null; - String clientJAR = jar.getEjbClientJar(); - if (clientJAR == null || clientJAR.length() == 0) - return null; - String normalized = ArchiveUtil.deriveEARRelativeURI(clientJAR, file.getURI()); - if (normalized != null) { - try { - File aFile = earFile.getFile(normalized); - if (aFile.isArchive() && !aFile.isModuleFile()) - return (Archive) aFile; - } catch (FileNotFoundException nothingThere) { - } - } - return null; - // TODO - release the DD here to free up space - } - - /** - * Append one IClasspathEntry to the build path of the passed project. If a classpath entry - * having the same path as the parameter already exists, then does nothing. - */ - public static void appendJavaClassPath(IProject p, IClasspathEntry newEntry) throws JavaModelException { - IJavaProject javaProject = JemProjectUtilities.getJavaProject(p); - if (javaProject == null) - return; - IClasspathEntry[] classpath = javaProject.getRawClasspath(); - List newPathList = new ArrayList(classpath.length); - for (int i = 0; i < classpath.length; i++) { - IClasspathEntry entry = classpath[i]; - // fix dup class path entry for .JETEmitter project - // Skip the entry to be added if it already exists - if (Platform.getOS().equals(Platform.OS_WIN32)) { - if (!entry.getPath().toString().equalsIgnoreCase(newEntry.getPath().toString())) - newPathList.add(entry); - else - return; - } else { - if (!entry.getPath().equals(newEntry.getPath())) - newPathList.add(entry); - else - return; - } - } - newPathList.add(newEntry); - IClasspathEntry[] newClasspath = (IClasspathEntry[]) newPathList.toArray(new IClasspathEntry[newPathList.size()]); - javaProject.setRawClasspath(newClasspath, new NullProgressMonitor()); - } - - public static Archive asArchiveFromBinary(String jarUri, IProject aProject) throws OpenFailureException { - IPath path = getBinaryProjectJARLocation(aProject); - if (path != null) { - String location = path.toOSString(); - Archive anArchive = CommonarchiveFactoryImpl.getActiveFactory().primOpenArchive(location); - anArchive.setURI(jarUri); - return anArchive; - } - return null; - } - - public static ArchiveManifest readManifest(IFile aFile) { - InputStream in = null; - try { - if (aFile == null || !aFile.exists()) - return null; - in = aFile.getContents(); - return new ArchiveManifestImpl(in); - } catch (Exception ex) { - org.eclipse.jem.util.logger.proxy.Logger.getLogger().logError(ex); - return null; - } finally { - if (in != null) { - try { - in.close(); - } catch (IOException weTried) { - } - } - } - } - - public static ArchiveManifest readManifest(IProject p) { - InputStream in = null; - try { - IFile aFile = getManifestFile(p); - if (aFile == null || !aFile.exists()) - return null; - in = aFile.getContents(); - return new ArchiveManifestImpl(in); - } catch (Exception ex) { - org.eclipse.jem.util.logger.proxy.Logger.getLogger().logError(ex); - return null; - } finally { - if (in != null) { - try { - in.close(); - } catch (IOException weTried) { - } - } - } - } - - /** - * Equavalent to calling getManifestFile(project, true) - * - * @param p - * @return - */ - public static IFile getManifestFile(IProject project) { - return getManifestFile(project, true); - } - - /** - * Returns the IFile handle to the J2EE manifest file for the specified - * project. If createIfNecessary is true, the MANIFEST.MF file will be - * created if it does not already exist. - * - * @param p - * @param createIfNecessary - * @return - */ - public static IFile getManifestFile(IProject p, boolean createIfNecessary) { - IVirtualComponent component = ComponentCore.createComponent(p); - try { - IFile file = ComponentUtilities.findFile(component, new Path(J2EEConstants.MANIFEST_URI)); - if (createIfNecessary && file == null) { - IVirtualFolder virtualFolder = component.getRootFolder(); - file = virtualFolder.getUnderlyingFolder().getFile(new Path(J2EEConstants.MANIFEST_URI)); - - try { - ManifestFileCreationAction.createManifestFile(file, p); - } catch (CoreException e) { - Logger.getLogger().log(e); - } catch (IOException e) { - Logger.getLogger().log(e); - } - } - return file; - } catch (CoreException ce) { - Logger.getLogger().log(ce); - } - return null; - } - - public static void writeManifest(IProject aProject, ArchiveManifest manifest) throws java.io.IOException { - writeManifest(aProject, getManifestFile(aProject), manifest); - } - - public static void writeManifest(IFile aFile, ArchiveManifest manifest) throws java.io.IOException { - writeManifest(aFile.getProject(), aFile, manifest); - } - - private static void writeManifest(IProject aProject, IFile aFile, ArchiveManifest manifest) throws java.io.IOException { - if (aFile != null) { - if(SimpleValidateEdit.validateEdit(new IFile[] { aFile })){ - OutputStream out = new WorkbenchByteArrayOutputStream(aFile); - manifest.writeSplittingClasspath(out); - out.close(); - J2EEComponentClasspathUpdater.getInstance().queueUpdateModule(aProject); - } - } - } - - public static ArchiveManifest readManifest(IVirtualComponent component) { - if (!component.isBinary()) { - IVirtualFile vManifest = component.getRootFolder().getFile(J2EEConstants.MANIFEST_URI); - if (vManifest.exists()) { - IFile manifestFile = vManifest.getUnderlyingFile(); - InputStream in = null; - try { - in = manifestFile.getContents(); - return new ArchiveManifestImpl(in); - } catch (IOException e) { - J2EEPlugin.logError(e); - } catch (CoreException e) { - J2EEPlugin.logError(e); - } finally { - if (in != null) { - try { - in.close(); - in = null; - } catch (IOException e) { - J2EEPlugin.logError(e); - } - } - } - } - } else { - JavaEEBinaryComponentHelper helper = null; - try{ - helper = new JavaEEBinaryComponentHelper(component); - if(helper != null){ - IArchive archive = null; - InputStream in = null; - try{ - archive = helper.accessArchive(); - if(null != archive){ - IPath manifestPath = new Path(J2EEConstants.MANIFEST_URI); - if(archive.containsArchiveResource(manifestPath)){ - IArchiveResource manifestResource = archive.getArchiveResource(manifestPath); - if(manifestResource != null){ - in = manifestResource.getInputStream(); - ArchiveManifest manifest = new ArchiveManifestImpl(in); - return manifest; - } - } - } - } catch (FileNotFoundException e) { - J2EEPlugin.logError(e); - } catch (IOException e) { - J2EEPlugin.logError(e); - } finally{ - if (in != null) { - try { - in.close(); - in = null; - } catch (IOException e) { - J2EEPlugin.logError(e); - } - } - if(archive != null){ - helper.releaseArchive(archive); - } - } - } - } finally{ - if(helper != null){ - helper.dispose(); - } - } - } - return null; - } - /** - * Keys are the EJB JAR files and the values are the respective client JARs; includes only key - * value pairs for which EJB Client JARs are defined and exist. - * - * @author schacher - */ - public static Map collectEJBClientJARs(EARFile earFile) { - if (earFile == null) - return Collections.EMPTY_MAP; - Map ejbClientJARs = null; - List ejbJARFiles = earFile.getEJBJarFiles(); - Archive clientJAR = null; - for (int i = 0; i < ejbJARFiles.size(); i++) { - EJBJarFile ejbJarFile = (EJBJarFile) ejbJARFiles.get(i); - clientJAR = getClientJAR(ejbJarFile, earFile); - if (clientJAR != null) { - if (ejbClientJARs == null) - ejbClientJARs = new HashMap(); - ejbClientJARs.put(ejbJarFile, clientJAR); - } - } - return ejbClientJARs == null ? Collections.EMPTY_MAP : ejbClientJARs; - } - - public static String computeRelativeText(String referencingURI, String referencedURI, EnterpriseBean bean) { - if (bean == null) - return null; - - String beanName = bean.getName(); - if (beanName == null) - return null; - - String relativeUri = computeRelativeText(referencingURI, referencedURI); - if (relativeUri == null) - return beanName; - return relativeUri + "#" + beanName; //$NON-NLS-1$ - } - - public static String computeRelativeText(String referencingURI, String referencedURI) { - if (referencingURI == null || referencedURI == null) - return null; - IPath pPre = new Path(referencingURI); - IPath pDep = new Path(referencedURI); - if (pPre.getDevice() != null || pDep.getDevice() != null) - return null; - pPre = pPre.makeRelative(); - pDep = pDep.makeRelative(); // referenced Archive path URI - - while (pPre.segmentCount() > 1 && pDep.segmentCount() > 1 && pPre.segment(0).equals(pDep.segment(0))) { - pPre = pPre.removeFirstSegments(1); - pDep = pDep.removeFirstSegments(1); - } - - IPath result = null; - StringBuffer buf = new StringBuffer(); - String segment = null; - do { - segment = pDep.lastSegment(); - pPre = pPre.removeLastSegments(1); - pDep = pDep.removeLastSegments(1); - if (segment != null) { - if (result == null) - result = new Path(segment); - else - result = new Path(segment).append(result); - } - if (!pPre.equals(pDep) && !pPre.isEmpty()) - buf.append("../"); //$NON-NLS-1$ - } while (!pPre.equals(pDep)); - - if (result != null) - buf.append(result.makeRelative().toString()); - - return buf.toString(); - } - - public static IProject getEJBProjectFromEJBClientProject(IProject ejbClientProject) { - try { - if (null != ejbClientProject && ejbClientProject.hasNature(JavaCore.NATURE_ID)) { - IProject[] allProjects = getAllProjects(); - for (int i = 0; i < allProjects.length; i++) { - if (null != EarModuleManager.getEJBModuleExtension().getEJBJar(allProjects[i])) { - if (ejbClientProject == EarModuleManager.getEJBModuleExtension().getDefinedEJBClientJARProject(allProjects[i])) { - return allProjects[i]; - } - } - } - } - } catch (CoreException e) { - } - return null; - } - - public static EnterpriseBean getEnterpriseBean(ICompilationUnit cu) { - IProject proj = cu.getJavaProject().getProject(); - EJBJar jar = EarModuleManager.getEJBModuleExtension().getEJBJar(proj); - if (null == jar) { - jar = EarModuleManager.getEJBModuleExtension().getEJBJar(getEJBProjectFromEJBClientProject(proj)); - } - if (jar != null) { - int index = cu.getElementName().indexOf('.'); - String className = cu.getElementName(); - if (index > 0) - className = className.substring(0, index); - JavaClass javaClass = (JavaClass) JavaRefFactory.eINSTANCE.reflectType(cu.getParent().getElementName(), className, jar.eResource().getResourceSet()); - return jar.getEnterpriseBeanWithReference(javaClass); - } - return null; - } - - public static IContainer getSourceFolderOrFirst(IProject p, String defaultSourceName) { - try { - IPath sourcePath = getSourcePathOrFirst(p, defaultSourceName); - if (sourcePath == null) - return null; - else if (sourcePath.isEmpty()) - return p; - else - return p.getFolder(sourcePath); - } catch (IllegalArgumentException ex) { - return null; - } - } - - public static void removeBuilders(IProject project, List builderids) throws CoreException { - IProjectDescription desc = project.getDescription(); - ICommand[] oldSpec = desc.getBuildSpec(); - int oldLength = oldSpec.length; - if (oldLength == 0) - return; - int remaining = 0; - // null out all commands that match the builder to remove - for (int i = 0; i < oldSpec.length; i++) { - if (builderids.contains(oldSpec[i].getBuilderName())) - oldSpec[i] = null; - else - remaining++; - } - // check if any were actually removed - if (remaining == oldSpec.length) - return; - ICommand[] newSpec = new ICommand[remaining]; - for (int i = 0, newIndex = 0; i < oldLength; i++) { - if (oldSpec[i] != null) - newSpec[newIndex++] = oldSpec[i]; - } - desc.setBuildSpec(newSpec); - project.setDescription(desc, IResource.NONE, null); - } - - public static IPath getSourcePathOrFirst(IProject p, String defaultSourceName) { - IJavaProject javaProj = JemProjectUtilities.getJavaProject(p); - if (javaProj == null) - return null; - IClasspathEntry[] cp = null; - try { - cp = javaProj.getRawClasspath(); - } catch (JavaModelException ex) { - JEMUtilPlugin.getLogger().logError(ex); - return null; - } - IClasspathEntry firstSource = null; - IPath defaultSourcePath = null; - if (defaultSourceName != null) - defaultSourcePath = createPath(p, defaultSourceName); - boolean found = false; - for (int i = 0; i < cp.length; i++) { - if (cp[i].getEntryKind() == IClasspathEntry.CPE_SOURCE) { - // check if it contains /META-INF/MANIFEST.MF - IPath sourceFolderPath = cp[i].getPath().removeFirstSegments(1); - IFolder sourceFolder = p.getFolder(sourceFolderPath); - if (isSourceFolderAnInputContainer(sourceFolder)) { - found = true; - if (firstSource == null) { - firstSource = cp[i]; - if (defaultSourcePath == null) - break; - } - if (cp[i].getPath().equals(defaultSourcePath)) - return defaultSourcePath.removeFirstSegments(1); - } - } - } - if (!found) { - for (int i = 0; i < cp.length; i++) { - if (cp[i].getEntryKind() == IClasspathEntry.CPE_SOURCE) { - if (firstSource == null) { - firstSource = cp[i]; - if (defaultSourcePath == null) - break; - } - if (cp[i].getPath().equals(defaultSourcePath)) - return defaultSourcePath.removeFirstSegments(1); - } - } - } - if (firstSource == null) - return null; - if (firstSource.getPath().segment(0).equals(p.getName())) - return firstSource.getPath().removeFirstSegments(1); - return null; - } - - public static boolean isSourceFolderAnInputContainer(IFolder sourceFolder) { - IContainer parent = sourceFolder; - while (true) { - parent = parent.getParent(); - if (parent == null) - return false; - if (parent instanceof IProject) - break; - } - IProject project = (IProject) parent; - try { - if (!project.isAccessible()) - return false; - if (isEJBProject(project)) { - return sourceFolder.findMember(J2EEConstants.EJBJAR_DD_URI) != null; - } else if (isApplicationClientProject(project)) { - return sourceFolder.findMember(J2EEConstants.APP_CLIENT_DD_URI) != null; - } else if (isDynamicWebProject(project)) { - return sourceFolder.findMember(J2EEConstants.WEBAPP_DD_URI) != null; - } else if (isJCAProject(project)) { - return sourceFolder.findMember(J2EEConstants.RAR_DD_URI) != null; - } - } catch (Exception e) { - e.printStackTrace(); - } - return false; - } - - public static Archive asArchive(String jarUri, IProject project, boolean exportSource) throws OpenFailureException { - return asArchive(jarUri, project, exportSource, true); - } - - public static Archive asArchive(String jarUri, IProject project, boolean exportSource, boolean includeClasspathComponents) throws OpenFailureException { - JavaComponentLoadStrategyImpl strat = new JavaComponentLoadStrategyImpl(ComponentCore.createComponent(project), includeClasspathComponents); - strat.setExportSource(exportSource); - return CommonarchiveFactoryImpl.getActiveFactory().primOpenArchive(strat, jarUri); - } - - /** - * @deprecated - see {@link JavaEEProjectUtilities.isProjectOfType(IProject project, String typeID)} - */ - public static boolean isProjectOfType(IProject project, String typeID) { - return JavaEEProjectUtilities.isProjectOfType(project,typeID); - } - - private static boolean isProjectOfType(IFacetedProject facetedProject, String typeID) { - - if (facetedProject != null && ProjectFacetsManager.isProjectFacetDefined(typeID)) { - IProjectFacet projectFacet = ProjectFacetsManager.getProjectFacet(typeID); - return projectFacet != null && facetedProject.hasProjectFacet(projectFacet); - } - return false; - } - - private static boolean isEARProject(IFacetedProject project) { - return isProjectOfType(project, ENTERPRISE_APPLICATION); - } - - private static boolean isDynamicWebProject(IFacetedProject project) { - return isProjectOfType(project, DYNAMIC_WEB); - } - - private static boolean isEJBProject(IFacetedProject project) { - return isProjectOfType(project, EJB); - } - - private static boolean isJCAProject(IFacetedProject project) { - return isProjectOfType(project, JCA); - } - - private static boolean isApplicationClientProject(IFacetedProject project) { - return isProjectOfType(project, APPLICATION_CLIENT); - } - - private static boolean isUtilityProject(IFacetedProject project) { - return isProjectOfType(project, UTILITY); - } - - /** - * @deprecated - see {@link JavaEEProjectUtilities.isEARProject(IProject project)} - */ - public static boolean isEARProject(IProject project) { - return JavaEEProjectUtilities.isEARProject(project); - } - - /** - * @deprecated - see {@link JavaEEProjectUtilities.isDynamicWebComponent(IVirtualComponent component)} - */ - public static boolean isDynamicWebComponent(IVirtualComponent component) { - return JavaEEProjectUtilities.isDynamicWebComponent(component); - } - - /** - * @deprecated - see {@link JavaEEProjectUtilities.isDynamicWebProject(IProject project)} - */ - public static boolean isDynamicWebProject(IProject project) { - return JavaEEProjectUtilities.isDynamicWebProject(project); - } - - /** - * @deprecated - see {@link JavaEEProjectUtilities.isStaticWebProject(IProject project)} - */ - public static boolean isStaticWebProject(IProject project) { - return JavaEEProjectUtilities.isStaticWebProject(project); - } - - /** - * @deprecated - see {@link JavaEEProjectUtilities.isEJBComponent(IVirtualComponent component)} - */ - public static boolean isEJBComponent(IVirtualComponent component) { - return JavaEEProjectUtilities.isEJBComponent(component); - } - - /** - * @deprecated - see {@link JavaEEProjectUtilities.isEJBProject(IProject project)} - */ - public static boolean isEJBProject(IProject project) { - return JavaEEProjectUtilities.isEJBProject(project); - } - - /** - * @deprecated - see {@link JavaEEProjectUtilities.isJCAComponent(IVirtualComponent component)} - */ - public static boolean isJCAComponent(IVirtualComponent component) { - return JavaEEProjectUtilities.isJCAComponent(component); - } - - /** - * @deprecated - see {@link JavaEEProjectUtilities.isJCAProject(IProject project)} - */ - public static boolean isJCAProject(IProject project) { - return JavaEEProjectUtilities.isJCAProject(project); - } - - /** - * @deprecated - see {@link JavaEEProjectUtilities.isApplicationClientComponent(IVirtualComponent component)} - */ - public static boolean isApplicationClientComponent(IVirtualComponent component) { - return JavaEEProjectUtilities.isApplicationClientComponent(component); - } - - /** - * @deprecated - see {@link JavaEEProjectUtilities.isApplicationClientProject(IProject project)} - */ - public static boolean isApplicationClientProject(IProject project) { - return JavaEEProjectUtilities.isApplicationClientProject(project); - } - - /** - * @deprecated - see {@link JavaEEProjectUtilities.isUtilityProject(IProject project)} - */ - public static boolean isUtilityProject(IProject project) { - return JavaEEProjectUtilities.isUtilityProject(project); - } - - /** - * @deprecated - see {@link EarUtilities.isStandaloneProject(IProject project)} - */ - public static boolean isStandaloneProject(IProject project) { - return EarUtilities.isStandaloneProject(project); - } - - /** - * Returns all referencing EAR projects. - * @param project Project to check. If null or an EAR, returns a zero length array. - * @return Array of referencing EAR projects. - */ - public static IProject[] getReferencingEARProjects(final IProject project) { - if(project != null && isEARProject(project)){ - return new IProject[] {project}; - } - - List result = new ArrayList(); - IVirtualComponent component = ComponentCore.createComponent(project); - if (component != null) { - IVirtualComponent[] refComponents = component.getReferencingComponents(); - for (int i = 0; i < refComponents.length; i++) { - if (isEARProject(refComponents[i].getProject())) - result.add(refComponents[i].getProject()); - } - } - return (IProject[]) result.toArray(new IProject[result.size()]); - } - - /** - * Returns all referencing dynamic web projects. - * @param project Project to check. If null or a dynamic web project, returns a zero length array. - * @return Array of referencing dynamic web projects. - */ - public static IProject[] getReferencingWebProjects(final IProject project) { - if(project != null && isDynamicWebProject(project)){ - return new IProject[] {project}; - } - - List result = new ArrayList(); - IVirtualComponent component = ComponentCore.createComponent(project); - if (component != null) { - IVirtualComponent[] refComponents = component.getReferencingComponents(); - for (int i = 0; i < refComponents.length; i++) { - if (isDynamicWebProject(refComponents[i].getProject())) - result.add(refComponents[i].getProject()); - } - } - return (IProject[]) result.toArray(new IProject[result.size()]); - } - - /** - * Return all projects in workspace of the specified type - * - * @param type - - * use one of the static strings on this class as a type - * @return IProject[] - * @deprecated - see {@link JavaEEProjectUtilities.getAllProjectsInWorkspaceOfType(String type)} - */ - public static IProject[] getAllProjectsInWorkspaceOfType(String type) { - return JavaEEProjectUtilities.getAllProjectsInWorkspaceOfType(type); - } - - /** - * @deprecated - see {@link JavaEEProjectUtilities.getJ2EEComponentType(IVirtualComponent component)} - */ - public static String getJ2EEComponentType(IVirtualComponent component) { - return JavaEEProjectUtilities.getJ2EEComponentType(component); - } - - /** - * @deprecated - see {@link JavaEEProjectUtilities.getJ2EEProjectType(IProject project)} - */ - public static String getJ2EEProjectType(IProject project) { - return JavaEEProjectUtilities.getJ2EEProjectType(project); - } - /** - * Returns the J2EE Module version based on the DD XML file - * @param project - * @return version String - * @deprecated - see {@link JavaEEProjectUtilities.getJ2EEDDProjectVersion(IProject project)} - */ - public static String getJ2EEDDProjectVersion(IProject project) { - return JavaEEProjectUtilities.getJ2EEDDProjectVersion(project); - } - - public static IRuntime getServerRuntime(IProject project) throws CoreException { - if (project == null) - return null; - IFacetedProject facetedProject = ProjectFacetsManager.create(project); - if (facetedProject == null) - return null; - org.eclipse.wst.common.project.facet.core.runtime.IRuntime runtime = facetedProject.getRuntime(); - if (runtime == null) - return null; - return FacetUtil.getRuntime(runtime); - } - - /** - * Returns the J2EE Module version based on the project Facet installed - * @param project - * @return version String - */ - public static String getJ2EEProjectVersion(IProject project) { - String type = getJ2EEProjectType(project); - IFacetedProject facetedProject = null; - IProjectFacet facet = null; - try { - facetedProject = ProjectFacetsManager.create(project); - facet = ProjectFacetsManager.getProjectFacet(type); - } catch (Exception e) { - // Not Faceted project or not J2EE Project - } - if (facet != null && facetedProject.hasProjectFacet(facet)) - return facetedProject.getInstalledVersion(facet).getVersionString(); - return null; - } - - public static JavaProjectMigrationOperation createFlexJavaProjectForProjectOperation(IProject project) { - IDataModel model = DataModelFactory.createDataModel(new JavaProjectMigrationDataModelProvider()); - model.setProperty(IJavaProjectMigrationDataModelProperties.PROJECT_NAME, project.getName()); - return new JavaProjectMigrationOperation(model); - } - - public static JavaProjectMigrationOperation createFlexJavaProjectForProjectOperation(IProject project, boolean addToEAR) { - IDataModel model = DataModelFactory.createDataModel(new JavaProjectMigrationDataModelProvider()); - model.setProperty(IJavaProjectMigrationDataModelProperties.PROJECT_NAME, project.getName()); - model.setBooleanProperty(IJavaProjectMigrationDataModelProperties.ADD_TO_EAR, addToEAR); - return new JavaProjectMigrationOperation(model); - } - - /** - * Retrieve all the source containers for a given virtual workbench component - * - * @param vc - * @return the array of IPackageFragmentRoots - */ - public static IPackageFragmentRoot[] getSourceContainers(IProject project) { - IJavaProject jProject = JemProjectUtilities.getJavaProject(project); - if (jProject == null) - return new IPackageFragmentRoot[0]; - List list = new ArrayList(); - IVirtualComponent vc = ComponentCore.createComponent(project); - IPackageFragmentRoot[] roots; - try { - roots = jProject.getPackageFragmentRoots(); - for (int i = 0; i < roots.length; i++) { - if (roots[i].getKind() != IPackageFragmentRoot.K_SOURCE) - continue; - IResource resource = roots[i].getResource(); - if (null != resource) { - IVirtualResource[] vResources = ComponentCore.createResources(resource); - boolean found = false; - for (int j = 0; !found && j < vResources.length; j++) { - if (vResources[j].getComponent().equals(vc)) { - if (!list.contains(roots[i])) - list.add(roots[i]); - found = true; - } - } - } - } - } catch (JavaModelException e) { - Logger.getLogger().logError(e); - } - return (IPackageFragmentRoot[]) list.toArray(new IPackageFragmentRoot[list.size()]); - } - - /** - * Retrieves the IContainers for all Java output folders that correspond to src folders that are mapped to the - * virtual component tree via the component file. - * - * @param vc - * @return array of IContainers for the output folders - */ - public static IContainer[] getOutputContainers(IProject project) { - List result = new ArrayList(); - try { - if (!project.hasNature(JavaCore.NATURE_ID)) - return new IContainer[] {}; - } catch (Exception e) { - } - IPackageFragmentRoot[] sourceContainers = getSourceContainers(project); - for (int i = 0; i < sourceContainers.length; i++) { - IContainer outputFolder = getOutputContainer(project, sourceContainers[i]); - if (outputFolder != null && !result.contains(outputFolder)) - result.add(outputFolder); - } - return (IContainer[]) result.toArray(new IContainer[result.size()]); - } - - public static IContainer getOutputContainer(IProject project, IPackageFragmentRoot sourceContainer) { - try { - IJavaProject jProject = JavaCore.create(project); - IPath outputPath = sourceContainer.getRawClasspathEntry().getOutputLocation(); - if (outputPath == null) { - if (jProject.getOutputLocation().segmentCount() == 1) - return project; - return project.getFolder(jProject.getOutputLocation().removeFirstSegments(1)); - } - return project.getFolder(outputPath.removeFirstSegments(1)); - } catch (Exception e) { - } - return null; - } - - /** - * Retrieve all Java output containers mapped into the virtual resource tree via the component file. Includes both directly - * mapped class folders and the class folders associated with mapped source folders. - * - * @param vc - * @return the array of IPackageFragmentRoots - */ - public static IContainer[] getAllOutputContainers(IProject project) { - IJavaProject jProject = JemProjectUtilities.getJavaProject(project); - if (jProject == null) - return new IContainer[0]; - List list = new ArrayList(); - IContainer[] srcOutputContainers = getOutputContainers(project); - for (int i = 0; i < srcOutputContainers.length; i++) { - list.add(srcOutputContainers[i]); - } - IVirtualComponent vc = ComponentCore.createComponent(project); - IPackageFragmentRoot[] roots; - try { - roots = jProject.getPackageFragmentRoots(); - for (int i = 0; i < roots.length; i++) { - if (roots[i].getKind() != IPackageFragmentRoot.K_BINARY) - continue; - IResource resource = roots[i].getResource(); - if (null != resource) { - IVirtualResource[] vResources = ComponentCore.createResources(resource); - boolean found = false; - for (int j = 0; !found && j < vResources.length; j++) { - if (vResources[j].getComponent().equals(vc)) { - if (resource instanceof IContainer) { - IContainer outputContainer = (IContainer) resource; - if (!list.contains(outputContainer)) { - list.add(outputContainer); - found = true; - } - } - } - } - } - } - } catch (JavaModelException e) { - Logger.getLogger().logError(e); - } - return (IContainer[]) list.toArray(new IContainer[list.size()]); - } - - - /** - * - * @param name - * @return - * @description the passed name should have either lib or var as its first segment e.g. - * lib/D:/foo/foo.jar or var/<CLASSPATHVAR>/foo.jar - */ - public static IPath getResolvedPathForArchiveComponent(String name) { - - URI uri = URI.createURI(name); - - String resourceType = uri.segment(0); - URI contenturi = ModuleURIUtil.trimToRelativePath(uri, 1); - String contentName = contenturi.toString(); - - if (resourceType.equals("lib")) { //$NON-NLS-1$ - // module:/classpath/lib/D:/foo/foo.jar - return Path.fromOSString(contentName); - - } else if (resourceType.equals("var")) { //$NON-NLS-1$ - - // module:/classpath/var/<CLASSPATHVAR>/foo.jar - String classpathVar = contenturi.segment(0); - URI remainingPathuri = ModuleURIUtil.trimToRelativePath(contenturi, 1); - String remainingPath = remainingPathuri.toString(); - - String[] classpathvars = JavaCore.getClasspathVariableNames(); - boolean found = false; - for (int i = 0; i < classpathvars.length; i++) { - if (classpathVar.equals(classpathvars[i])) { - found = true; - break; - } - } - if (found) { - IPath path = JavaCore.getClasspathVariable(classpathVar); - if (path != null ){ - URI finaluri = URI.createURI(path.toOSString() + IPath.SEPARATOR + remainingPath); - return Path.fromOSString(finaluri.toString()); - } - } - } - return null; - } - - public static List getAllJavaNonFlexProjects() throws CoreException { - List nonFlexJavaProjects = new ArrayList(); - IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects(); - for (int i = 0; i < projects.length; i++) { - if (projects[i].isAccessible() && projects[i].hasNature(JavaCore.NATURE_ID) && !projects[i].hasNature(IModuleConstants.MODULE_NATURE_ID)) { - nonFlexJavaProjects.add(projects[i]); - } - } - return nonFlexJavaProjects; - } - - /** - * This method will retrieve the context root for the associated workbench module which is used - * by the server at runtime. This method is not yet completed as the context root has to be - * abstracted and added to the workbenchModule model. This API will not change though. Returns - * null for now. - * - * @return String value of the context root for runtime of the associated module - */ - public static String getServerContextRoot(IProject project) { - return ComponentUtilities.getServerContextRoot(project); - } - - /** - * This method will set the context root on the associated workbench module with the given - * string value passed in. This context root is used by the server at runtime. This method is - * not yet completed as the context root still needs to be abstracted and added to the workbench - * module model. This API will not change though. Does nothing as of now. - * - * @param contextRoot - * string - */ - public static void setServerContextRoot(IProject project, String contextRoot) { - ComponentUtilities.setServerContextRoot(project, contextRoot); - } - - /** - * @param project - * @return true, if jee version 5.0 (or their respective ejb, web, app versions) - * , it must be noted that this method only looks at the facet & their versions to determine - * the jee level. It does not read deployment descriptors for performance reasons. - */ - public static boolean isJEEProject(IProject project){ - boolean ret = false; - - IFacetedProject facetedProject; - try { - facetedProject = ProjectFacetsManager.create(project); - if (facetedProject == null) - return false; - if(isEARProject(facetedProject)){ - IProjectFacet earFacet = ProjectFacetsManager.getProjectFacet(IModuleConstants.JST_EAR_MODULE); - ret = facetedProject.hasProjectFacet(earFacet.getVersion(J2EEVersionUtil.convertVersionIntToString(J2EEVersionConstants.JEE_5_0_ID))); - } else if(isDynamicWebProject(facetedProject)){ - IProjectFacet webFacet = ProjectFacetsManager.getProjectFacet(IModuleConstants.JST_WEB_MODULE); - ret = facetedProject.hasProjectFacet(webFacet.getVersion(J2EEVersionUtil.convertVersionIntToString(J2EEVersionUtil.convertJ2EEVersionIDToWebVersionID(J2EEVersionConstants.JEE_5_0_ID)))); - } else if(isEJBProject(facetedProject)){ - IProjectFacet ejbFacet = ProjectFacetsManager.getProjectFacet(IModuleConstants.JST_EJB_MODULE); - ret = facetedProject.hasProjectFacet(ejbFacet.getVersion(J2EEVersionUtil.convertVersionIntToString(J2EEVersionUtil.convertJ2EEVersionIDToEJBVersionID(J2EEVersionConstants.JEE_5_0_ID)))); - } else if(isApplicationClientProject(facetedProject)){ - IProjectFacet appFacet = ProjectFacetsManager.getProjectFacet(IModuleConstants.JST_APPCLIENT_MODULE); - ret = facetedProject.hasProjectFacet(appFacet.getVersion(J2EEVersionUtil.convertVersionIntToString(J2EEVersionConstants.JEE_5_0_ID))); - } - } catch (CoreException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - return ret; - } - - /** - * @param project - * @return true, if j2ee version 1.2, 1.3, 1.4 (or their respective ejb, web, app versions) - * , it must be noted that this method only looks at the facet & their versions to determine - * the j2ee level. It does not read deployment descriptors for performance reasons. - */ - public static boolean isLegacyJ2EEProject(IProject project){ - boolean ret = false; - - IFacetedProject facetedProject; - try { - facetedProject = ProjectFacetsManager.create(project); - if (facetedProject == null) - return false; - - if(isEARProject(facetedProject)){ - IProjectFacet earFacet = ProjectFacetsManager.getProjectFacet(IModuleConstants.JST_EAR_MODULE); - ret = (facetedProject.hasProjectFacet(earFacet.getVersion(J2EEVersionUtil.convertVersionIntToString(J2EEVersionConstants.J2EE_1_4_ID))) - || facetedProject.hasProjectFacet(earFacet.getVersion(J2EEVersionUtil.convertVersionIntToString(J2EEVersionConstants.J2EE_1_3_ID))) - || facetedProject.hasProjectFacet(earFacet.getVersion(J2EEVersionUtil.convertVersionIntToString(J2EEVersionConstants.J2EE_1_2_ID))) - ); - } else if(isDynamicWebProject(facetedProject)){ - IProjectFacet webFacet = ProjectFacetsManager.getProjectFacet(IModuleConstants.JST_WEB_MODULE); - ret = (facetedProject.hasProjectFacet(webFacet.getVersion(J2EEVersionUtil.convertVersionIntToString(J2EEVersionUtil.convertJ2EEVersionIDToWebVersionID(J2EEVersionConstants.J2EE_1_4_ID)))) - || facetedProject.hasProjectFacet(webFacet.getVersion(J2EEVersionUtil.convertVersionIntToString(J2EEVersionUtil.convertJ2EEVersionIDToWebVersionID(J2EEVersionConstants.J2EE_1_3_ID)))) - || facetedProject.hasProjectFacet(webFacet.getVersion(J2EEVersionUtil.convertVersionIntToString(J2EEVersionUtil.convertJ2EEVersionIDToWebVersionID(J2EEVersionConstants.J2EE_1_2_ID)))) - ); - } else if(isEJBProject(facetedProject)){ - IProjectFacet ejbFacet = ProjectFacetsManager.getProjectFacet(IModuleConstants.JST_EJB_MODULE); - ret = (facetedProject.hasProjectFacet(ejbFacet.getVersion(J2EEVersionUtil.convertVersionIntToString(J2EEVersionUtil.convertJ2EEVersionIDToEJBVersionID(J2EEVersionConstants.J2EE_1_4_ID)))) - || facetedProject.hasProjectFacet(ejbFacet.getVersion(J2EEVersionUtil.convertVersionIntToString(J2EEVersionUtil.convertJ2EEVersionIDToEJBVersionID(J2EEVersionConstants.J2EE_1_3_ID)))) - || facetedProject.hasProjectFacet(ejbFacet.getVersion(J2EEVersionUtil.convertVersionIntToString(J2EEVersionUtil.convertJ2EEVersionIDToEJBVersionID(J2EEVersionConstants.J2EE_1_2_ID)))) - ); - } else if(isApplicationClientProject(facetedProject)){ - IProjectFacet appFacet = ProjectFacetsManager.getProjectFacet(IModuleConstants.JST_APPCLIENT_MODULE); - ret = (facetedProject.hasProjectFacet(appFacet.getVersion(J2EEVersionUtil.convertVersionIntToString(J2EEVersionConstants.J2EE_1_4_ID))) - || facetedProject.hasProjectFacet(appFacet.getVersion(J2EEVersionUtil.convertVersionIntToString(J2EEVersionConstants.J2EE_1_3_ID))) - || facetedProject.hasProjectFacet(appFacet.getVersion(J2EEVersionUtil.convertVersionIntToString(J2EEVersionConstants.J2EE_1_2_ID))) - ); - } else if(isJCAProject(facetedProject)){ - IProjectFacet jcaFacet = ProjectFacetsManager.getProjectFacet(IModuleConstants.JST_CONNECTOR_MODULE); - ret = (facetedProject.hasProjectFacet(jcaFacet.getVersion(J2EEVersionUtil.convertVersionIntToString(J2EEVersionUtil.convertJ2EEVersionIDToConnectorVersionID(J2EEVersionConstants.J2EE_1_4_ID)))) - || facetedProject.hasProjectFacet(jcaFacet.getVersion(J2EEVersionUtil.convertVersionIntToString(J2EEVersionUtil.convertJ2EEVersionIDToConnectorVersionID(J2EEVersionConstants.J2EE_1_3_ID)))) - ); - } else if(isUtilityProject(facetedProject)){ - // not sure if there is a better way - ret = true; - } - } catch (CoreException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - return ret; - } - - /** - * This method will return the an IVirtualComponent for the given module name. The method take - * either moduleName or moduleName + ".module_extension" (module_extension = ".jar" || ".war" || - * ".rar") which allows users to get a IVirtualComponent for a given entry in an application.xml - * - * @return - a IVirtualComponent for module name - * @deprecated - see {@link EarUtilities.getModule(IVirtualComponent earComponent, String moduleName)} - */ - public static IVirtualComponent getModule(IVirtualComponent earComponent, String moduleName) { - return EarUtilities.getModule(earComponent, moduleName); - } - - /** - * This method will return the list of IVirtualReferences for the J2EE module components - * contained in this EAR application. - * - * @return - an array of IVirtualReferences for J2EE modules in the EAR - * @deprecated - see {@link EarUtilities.getJ2EEModuleReferences(IVirtualComponent earComponent)} - */ - public static IVirtualReference[] getJ2EEModuleReferences(IVirtualComponent earComponent) { - return EarUtilities.getJ2EEModuleReferences(earComponent); - } - - /** - * This method will return the list of IVirtualReferences for all of the components contained in - * an EAR application. - * - * @return - an array of IVirtualReferences for components in the EAR - * @deprecated - see {@link EarUtilities.getComponentReferences(IVirtualComponent earComponent)} - */ - public static IVirtualReference[] getComponentReferences(IVirtualComponent earComponent) { - return EarUtilities.getComponentReferences(earComponent); - } - - /** - * This method will return the IVirtualReference to the component of the given name - * - * @return - IVirtualReference or null if not found - * @deprecated - see {@link EarUtilities.getComponentReference(IVirtualComponent earComponent, String componentName)} - */ - public static IVirtualReference getComponentReference(IVirtualComponent earComponent, String componentName) { - return EarUtilities.getComponentReference(earComponent, componentName); - } -} diff --git a/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/internal/project/ManifestFileCreationAction.java b/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/internal/project/ManifestFileCreationAction.java deleted file mode 100644 index 78e2cddfa..000000000 --- a/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/internal/project/ManifestFileCreationAction.java +++ /dev/null @@ -1,41 +0,0 @@ -/******************************************************************************* - * 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.internal.project; - -import java.io.IOException; - -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.jem.util.emf.workbench.WorkbenchByteArrayOutputStream; - -public class ManifestFileCreationAction { - - public static final String MANIFEST_HEADER = "Manifest-Version: 1.0\r\nClass-Path: \r\n\r\n"; //$NON-NLS-1$ - - /** - * Constructor for ManifestFileCreationAction. - */ - public ManifestFileCreationAction() { - super(); - } - - public static void createManifestFile(IFile file, IProject aJ2EEProject) throws CoreException, IOException { - try { - WorkbenchByteArrayOutputStream out = new WorkbenchByteArrayOutputStream(file); - out.write(MANIFEST_HEADER.getBytes()); - out.close(); - - } catch (IOException ioe) { - throw ioe; - } - } -} diff --git a/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/internal/project/ProjectSupportResourceHandler.java b/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/internal/project/ProjectSupportResourceHandler.java deleted file mode 100644 index 9da142847..000000000 --- a/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/internal/project/ProjectSupportResourceHandler.java +++ /dev/null @@ -1,68 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2003, 2006 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.internal.project; - -import org.eclipse.osgi.util.NLS; - -public class ProjectSupportResourceHandler extends NLS { - private static final String BUNDLE_NAME = "projectsupport";//$NON-NLS-1$ - - private ProjectSupportResourceHandler() { - // Do not instantiate - } - - public static String Folder_name_cannot_be_the_same_as_Java_source_folder_5; - public static String Target_Update_Op; - public static String Operation_failed_due_to_SA_ERROR_; - public static String Creating_Web_Project____UI_; - public static String Could_not_rename_____2; - public static String A_web_project_must_be_open_and_must_exist_for_properties_to_be_edited_30; - public static String Operation_failed_due_to_IO_ERROR_; - public static String Cannot_clone_TaglibInfo_1_EXC_; - public static String Syntax_Error_in_the_links_UI_; - public static String Sync_WLP_Op; - public static String Generated_by_Web_Tooling_23; - public static String _1concat_EXC_; - public static String File_Serving_Enabler_7; - public static String Auto_Generated___File_Enabler_9; - public static String Not_a_web_project_29; - public static String Names_cannot_begin_or_end_with_whitespace_5; - public static String The_character_is_invalid_in_a_context_root; - public static String Folder_name_cannot_be_the_same_as_Java_class_folder_6; - public static String The_path_for_the_links_sta_EXC_; - public static String Operation_failed_due_to_Ja_ERROR_; - public static String Folder_name_cannot_be_empty_2; - public static String Error_importing_Module_Fil_EXC_; - public static String Operation_failed_due_to_Co_ERROR_; - public static String Folder_names_cannot_be_equal_4; - public static String Could_not_read_TLD_15; - public static String Folder_name_is_not_valid; - public static String Invalid_Servlet_Level_set_on_WebNature_3_EXC_; - public static String Context_Root_cannot_be_empty_2; - public static String Error_while_saving_links_s_EXC_; - public static String Sychronize_Class_Path_UI_; - public static String UNABLE_TO_LOAD_MODULE_ERROR_; - public static String Catalog_Lib_Directory__UI_; - public static String Update_ClassPath__UI_; - public static String Set_ClassPath__UI_; - public static String Names_cannot_contain_whitespace_; - public static String Importing_archive; - public static String Exporting_archive; - - - static { - NLS.initializeMessages(BUNDLE_NAME, ProjectSupportResourceHandler.class); - } - - public static String getString(String key, Object[] args) { - return NLS.bind(key, args); - } -} diff --git a/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/internal/project/WTPJETEmitter.java b/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/internal/project/WTPJETEmitter.java deleted file mode 100644 index 6036f12fa..000000000 --- a/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/internal/project/WTPJETEmitter.java +++ /dev/null @@ -1,638 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2003, 2006 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 - *******************************************************************************/ -/* - * Created on Mar 17, 2004 - * - * To change the template for this generated file go to - * Window>Preferences>Java>Code Generation>Code and Comments - */ -package org.eclipse.jst.j2ee.internal.project; - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.lang.reflect.Method; -import java.net.MalformedURLException; -import java.net.URL; -import java.net.URLClassLoader; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.StringTokenizer; - -import org.eclipse.core.resources.IContainer; -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IFolder; -import org.eclipse.core.resources.IMarker; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IProjectDescription; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.resources.IWorkspace; -import org.eclipse.core.resources.IncrementalProjectBuilder; -import org.eclipse.core.resources.ProjectScope; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.FileLocator; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.NullProgressMonitor; -import org.eclipse.core.runtime.Path; -import org.eclipse.core.runtime.Platform; -import org.eclipse.core.runtime.SubProgressMonitor; -import org.eclipse.core.runtime.preferences.IEclipsePreferences; -import org.eclipse.core.runtime.preferences.IScopeContext; -import org.eclipse.emf.codegen.CodeGenPlugin; -import org.eclipse.emf.codegen.jet.JETCompiler; -import org.eclipse.emf.codegen.jet.JETEmitter; -import org.eclipse.emf.codegen.jet.JETException; -import org.eclipse.jdt.core.IClasspathAttribute; -import org.eclipse.jdt.core.IClasspathEntry; -import org.eclipse.jdt.core.IJavaModel; -import org.eclipse.jdt.core.IJavaProject; -import org.eclipse.jdt.core.IPackageFragmentRoot; -import org.eclipse.jdt.core.JavaCore; -import org.eclipse.jdt.core.JavaModelException; -import org.eclipse.jdt.launching.JavaRuntime; -import org.eclipse.jem.util.logger.proxy.Logger; -import org.eclipse.jst.j2ee.internal.plugin.J2EEPlugin; -import org.eclipse.jst.j2ee.internal.plugin.J2EEPluginResourceHandler; -import org.eclipse.osgi.util.ManifestElement; -import org.osgi.framework.Bundle; -import org.osgi.framework.Constants; -import org.osgi.service.prefs.BackingStoreException; - -/** - * @author schacher, mdelder - * - * To change the template for this generated type comment go to - * Window>Preferences>Java>Code Generation>Code and Comments - */ -public class WTPJETEmitter extends JETEmitter { - - public static final String PROJECT_NAME = ".JETEmitters"; //$NON-NLS-1$ - private Map variables; - - private boolean intelligentLinkingEnabled = false; - - private JETCompiler jetCompiler; - - /** - * @param templateURI - */ - public WTPJETEmitter(String templateURI) { - super(templateURI); - } - - /** - * @param templateURIPath - * @param relativeTemplateURI - */ - public WTPJETEmitter(String[] templateURIPath, String relativeTemplateURI) { - super(templateURIPath, relativeTemplateURI); - } - - /** - * @param templateURI - * @param classLoader - */ - public WTPJETEmitter(String templateURI, ClassLoader classLoader) { - super(templateURI, classLoader); - try { - initialize(new NullProgressMonitor()); - } catch (JETException e) { - e.printStackTrace(); - } - } - - /** - * @param templateURIPath - * @param relativeTemplateURI - * @param classLoader - */ - public WTPJETEmitter(String[] templateURIPath, String relativeTemplateURI, ClassLoader classLoader) { - super(templateURIPath, relativeTemplateURI, classLoader); - } - - /** - * @param templateURIPath - * @param relativeTemplateURI - * @param classLoader - * @param encoding - */ - public WTPJETEmitter(String[] templateURIPath, String relativeTemplateURI, ClassLoader classLoader, String encoding) { - super(templateURIPath, relativeTemplateURI, classLoader, encoding); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.emf.codegen.jet.JETEmitter#initialize(org.eclipse.core.runtime.IProgressMonitor) - */ - public void initialize(IProgressMonitor progressMonitor) throws JETException { - - progressMonitor.beginTask("", 10); //$NON-NLS-1$ - progressMonitor.subTask(CodeGenPlugin.getPlugin().getString("_UI_GeneratingJETEmitterFor_message", new Object[]{templateURI})); //$NON-NLS-1$ - - try { - // This ensures that the JRE variables are initialized. - try { - JavaRuntime.getDefaultVMInstall(); - } catch (Throwable throwable) { - // This is kind of nasty to come here. - URL jreURL = Platform.find(Platform.getBundle("org.eclipse.emf.codegen"),new Path("plugin.xml")); //$NON-NLS-1$ //$NON-NLS-2$ - IPath jrePath = new Path(Platform.asLocalURL(jreURL).getFile()); - jrePath = jrePath.removeLastSegments(1).append(new Path("../../jre/lib/rt.jar")); //$NON-NLS-1$ - if (!jrePath.equals(JavaCore.getClasspathVariable(JavaRuntime.JRELIB_VARIABLE))) { - JavaCore.setClasspathVariable(JavaRuntime.JRELIB_VARIABLE, jrePath, null); - } - } - - /* - * final JETCompiler jetCompiler = templateURIPath == null ? new - * MyJETCompiler(templateURI, encoding) : - */ - - getJetCompiler(); - - progressMonitor.subTask(CodeGenPlugin.getPlugin().getString("_UI_JETParsing_message", new Object[]{jetCompiler.getResolvedTemplateURI()})); //$NON-NLS-1$ - jetCompiler.parse(); - progressMonitor.worked(1); - - ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); - jetCompiler.generate(outputStream); - final InputStream contents = new ByteArrayInputStream(outputStream.toByteArray()); - - final IWorkspace workspace = ResourcesPlugin.getWorkspace(); - IJavaModel javaModel = JavaCore.create(ResourcesPlugin.getWorkspace().getRoot()); - if (!javaModel.isOpen()) { - javaModel.open(new SubProgressMonitor(progressMonitor, 1)); - } else { - progressMonitor.worked(1); - } - - final IProject project = workspace.getRoot().getProject(getProjectName()); - progressMonitor.subTask(CodeGenPlugin.getPlugin().getString("_UI_JETPreparingProject_message", new Object[]{project.getName()})); //$NON-NLS-1$ - - IJavaProject javaProject; - if (!project.exists()) { - javaProject = createJavaProject(progressMonitor, workspace, project); - - initializeJavaProject(progressMonitor, project, javaProject); - - javaProject.close(); - } else { - project.open(new SubProgressMonitor(progressMonitor, 5)); - javaProject = JavaCore.create(project); - List rawClassPath = Arrays.asList(javaProject.getRawClasspath()); - for (int i=0; i<rawClassPath.size(); i++) { - IClasspathEntry entry = (IClasspathEntry) rawClassPath.get(i); - if (entry.getEntryKind()==IClasspathEntry.CPE_LIBRARY) - classpathEntries.add(entry); - } - } - - IPackageFragmentRoot sourcePackageFragmentRoot = openJavaProjectIfNecessary(progressMonitor, project, javaProject); - - String packageName = jetCompiler.getSkeleton().getPackageName(); - StringTokenizer stringTokenizer = new StringTokenizer(packageName, "."); //$NON-NLS-1$ - IProgressMonitor subProgressMonitor = new SubProgressMonitor(progressMonitor, 1); - subProgressMonitor.beginTask("", stringTokenizer.countTokens() + 4); //$NON-NLS-1$ - subProgressMonitor.subTask(CodeGenPlugin.getPlugin().getString("_UI_CreateTargetFile_message")); //$NON-NLS-1$ - IContainer sourceContainer = (IContainer) sourcePackageFragmentRoot.getCorrespondingResource(); - while (stringTokenizer.hasMoreElements()) { - String folderName = stringTokenizer.nextToken(); - sourceContainer = sourceContainer.getFolder(new Path(folderName)); - if (!sourceContainer.exists()) { - ((IFolder) sourceContainer).create(false, true, new SubProgressMonitor(subProgressMonitor, 1)); - } - } - IFile targetFile = sourceContainer.getFile(new Path(jetCompiler.getSkeleton().getClassName() + ".java")); //$NON-NLS-1$ - if (!targetFile.exists()) { - subProgressMonitor.subTask(CodeGenPlugin.getPlugin().getString("_UI_JETCreating_message", new Object[]{targetFile.getFullPath()})); //$NON-NLS-1$ - targetFile.create(contents, true, new SubProgressMonitor(subProgressMonitor, 1)); - } else { - subProgressMonitor.subTask(CodeGenPlugin.getPlugin().getString("_UI_JETUpdating_message", new Object[]{targetFile.getFullPath()})); //$NON-NLS-1$ - targetFile.setContents(contents, true, true, new SubProgressMonitor(subProgressMonitor, 1)); - } - - boolean errors = performBuild(project, subProgressMonitor, targetFile); - - if (!errors) { - loadClass(workspace, project, javaProject, packageName, subProgressMonitor); - } - - subProgressMonitor.done(); - } catch (CoreException exception) { - throw new JETException(exception); - } catch (Exception exception) { - throw new JETException(exception); - } finally { - progressMonitor.done(); - } - - } - - /** - * @param progressMonitor - * @param project - * @param javaProject - * @return - * @throws JavaModelException - */ - protected IPackageFragmentRoot openJavaProjectIfNecessary(IProgressMonitor progressMonitor, final IProject project, IJavaProject javaProject) throws JavaModelException { - progressMonitor.subTask(CodeGenPlugin.getPlugin().getString("_UI_JETOpeningJavaProject_message", new Object[]{project.getName()})); //$NON-NLS-1$ - javaProject.open(new SubProgressMonitor(progressMonitor, 1)); - - IPackageFragmentRoot[] packageFragmentRoots = javaProject.getPackageFragmentRoots(); - IPackageFragmentRoot sourcePackageFragmentRoot = null; - for (int j = 0; j < packageFragmentRoots.length; ++j) { - IPackageFragmentRoot packageFragmentRoot = packageFragmentRoots[j]; - if (packageFragmentRoot.getKind() == IPackageFragmentRoot.K_SOURCE) { - sourcePackageFragmentRoot = packageFragmentRoot; - break; - } - } - return sourcePackageFragmentRoot; - } - - /** - * @param progressMonitor - * @param project - * @param javaProject - * @throws CoreException - * @throws JavaModelException - * @throws BackingStoreException - */ - protected void initializeJavaProject(IProgressMonitor progressMonitor, final IProject project, IJavaProject javaProject) throws CoreException, JavaModelException, BackingStoreException { - progressMonitor.subTask(CodeGenPlugin.getPlugin().getString("_UI_JETInitializingProject_message", new Object[]{project.getName()})); //$NON-NLS-1$ - IClasspathEntry classpathEntry = JavaCore.newSourceEntry(new Path("/" + project.getName() + "/src")); //$NON-NLS-1$ //$NON-NLS-2$ - - //IClasspathEntry jreClasspathEntry = JavaCore.newVariableEntry(new Path(JavaRuntime.JRELIB_VARIABLE), new Path(JavaRuntime.JRESRC_VARIABLE), new Path(JavaRuntime.JRESRCROOT_VARIABLE)); - IClasspathEntry jreClasspathEntry = JavaRuntime.getDefaultJREContainerEntry(); - - List classpath = new ArrayList(); - classpath.add(classpathEntry); - classpath.add(jreClasspathEntry); - classpath.addAll(classpathEntries); - - IFolder sourceFolder = project.getFolder(new Path("src")); //$NON-NLS-1$ - if (!sourceFolder.exists()) { - sourceFolder.create(false, true, new SubProgressMonitor(progressMonitor, 1)); - } - IFolder runtimeFolder = project.getFolder(new Path("runtime")); //$NON-NLS-1$ - if (!runtimeFolder.exists()) { - runtimeFolder.create(false, true, new SubProgressMonitor(progressMonitor, 1)); - } - - IClasspathEntry[] classpathEntryArray = (IClasspathEntry[]) classpath.toArray(new IClasspathEntry[classpath.size()]); - - javaProject.setRawClasspath(classpathEntryArray, new SubProgressMonitor(progressMonitor, 1)); - - javaProject.setOutputLocation(new Path("/" + project.getName() + "/runtime"), new SubProgressMonitor(progressMonitor, 1)); //$NON-NLS-1$ //$NON-NLS-2$ - - // appended from previous implementation - createClasspathEntries(project); - - IScopeContext context = new ProjectScope( project ); - IEclipsePreferences prefs = context.getNode( JavaCore.PLUGIN_ID ); - prefs.put( JavaCore.COMPILER_PB_RAW_TYPE_REFERENCE, JavaCore.IGNORE ); - prefs.put( JavaCore.COMPILER_PB_UNCHECKED_TYPE_OPERATION, JavaCore.IGNORE ); - - // set Java compiler compliance level to 1.5 - prefs.put( JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_5 ); - prefs.put( JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_5 ); - prefs.put( JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_5 ); - prefs.put( JavaCore.COMPILER_PB_ASSERT_IDENTIFIER, JavaCore.ERROR ); - prefs.put( JavaCore.COMPILER_PB_ENUM_IDENTIFIER, JavaCore.ERROR ); - - // set Javadoc validation to the default ignore level - prefs.put( JavaCore.COMPILER_PB_INVALID_JAVADOC, JavaCore.IGNORE ); - prefs.put( JavaCore.COMPILER_PB_INVALID_JAVADOC_TAGS, JavaCore.DISABLED ); - prefs.put( JavaCore.COMPILER_PB_INVALID_JAVADOC_TAGS__DEPRECATED_REF, JavaCore.DISABLED ); - prefs.put( JavaCore.COMPILER_PB_INVALID_JAVADOC_TAGS__NOT_VISIBLE_REF, JavaCore.DISABLED ); - prefs.put( JavaCore.COMPILER_PB_INVALID_JAVADOC_TAGS_VISIBILITY, JavaCore.PUBLIC ); - prefs.put( JavaCore.COMPILER_PB_MISSING_JAVADOC_TAG_DESCRIPTION, JavaCore.COMPILER_PB_MISSING_JAVADOC_TAG_DESCRIPTION_RETURN_TAG ); - prefs.put( JavaCore.COMPILER_PB_MISSING_JAVADOC_TAGS, JavaCore.IGNORE ); - prefs.put( JavaCore.COMPILER_PB_MISSING_JAVADOC_TAGS_VISIBILITY, JavaCore.PUBLIC ); - prefs.put( JavaCore.COMPILER_PB_MISSING_JAVADOC_TAGS_OVERRIDING, JavaCore.DISABLED ); - prefs.put( JavaCore.COMPILER_PB_MISSING_JAVADOC_COMMENTS, JavaCore.IGNORE ); - prefs.put( JavaCore.COMPILER_PB_MISSING_JAVADOC_COMMENTS_VISIBILITY, JavaCore.PUBLIC ); - prefs.put( JavaCore.COMPILER_PB_MISSING_JAVADOC_COMMENTS_OVERRIDING, JavaCore.DISABLED ); - - // store changed properties permanently - prefs.flush(); - } - - /** - * @param progressMonitor - * @param workspace - * @param project - * @return - * @throws CoreException - */ - private IJavaProject createJavaProject(IProgressMonitor progressMonitor, final IWorkspace workspace, final IProject project) throws CoreException { - IJavaProject javaProject; - progressMonitor.subTask("JET creating project " + project.getName()); //$NON-NLS-1$ - project.create(new SubProgressMonitor(progressMonitor, 1)); - progressMonitor.subTask(CodeGenPlugin.getPlugin().getString("_UI_JETCreatingProject_message", new Object[]{project.getName()})); //$NON-NLS-1$ - IProjectDescription description = workspace.newProjectDescription(project.getName()); - description.setNatureIds(new String[]{JavaCore.NATURE_ID}); - description.setLocation(null); - project.open(new SubProgressMonitor(progressMonitor, 1)); - project.setDescription(description, new SubProgressMonitor(progressMonitor, 1)); - - javaProject = JavaCore.create(project); - return javaProject; - } - - /** - * @param workspace - * @param project - * @param javaProject - * @param packageName - * @param subProgressMonitor - * @throws JavaModelException - * @throws MalformedURLException - * @throws ClassNotFoundException - * @throws SecurityException - */ - protected void loadClass(final IWorkspace workspace, final IProject project, IJavaProject javaProject, String packageName, IProgressMonitor subProgressMonitor) throws JavaModelException, MalformedURLException, ClassNotFoundException, SecurityException { - //IContainer targetContainer = - // workspace.getRoot().getFolder(javaProject.getOutputLocation()); - - subProgressMonitor.subTask(CodeGenPlugin.getPlugin().getString("_UI_JETLoadingClass_message", new Object[]{jetCompiler.getSkeleton().getClassName() + ".class"})); //$NON-NLS-1$ //$NON-NLS-2$ - - // Construct a proper URL for relative lookup. - // - URL url = new File(project.getLocation() + "/" + javaProject.getOutputLocation().removeFirstSegments(1) + "/").toURL(); //$NON-NLS-1$ //$NON-NLS-2$ - URLClassLoader theClassLoader = new URLClassLoader(new URL[]{url}, classLoader); - Class theClass = theClassLoader.loadClass((packageName.length() == 0 ? "" : packageName + ".") + jetCompiler.getSkeleton().getClassName()); //$NON-NLS-1$ //$NON-NLS-2$ - String methodName = jetCompiler.getSkeleton().getMethodName(); - Method[] methods = theClass.getDeclaredMethods(); - for (int i = 0; i < methods.length; ++i) { - if (methods[i].getName().equals(methodName)) { - setMethod(methods[i]); - break; - } - } - } - - /** - * @param project - * @param subProgressMonitor - * @param targetFile - * @return - * @throws CoreException - */ - protected boolean performBuild(final IProject project, IProgressMonitor subProgressMonitor, IFile targetFile) throws CoreException { - subProgressMonitor.subTask(CodeGenPlugin.getPlugin().getString("_UI_JETBuilding_message", new Object[]{project.getName()})); //$NON-NLS-1$ - project.build(IncrementalProjectBuilder.INCREMENTAL_BUILD, new SubProgressMonitor(subProgressMonitor, 1)); - - IMarker[] markers = targetFile.findMarkers(IMarker.PROBLEM, true, IResource.DEPTH_INFINITE); - boolean errors = false; - for (int i = 0; i < markers.length; ++i) { - IMarker marker = markers[i]; - if (marker.getAttribute(IMarker.SEVERITY, IMarker.SEVERITY_INFO) == IMarker.SEVERITY_ERROR) { - errors = true; - subProgressMonitor.subTask(marker.getAttribute(IMarker.MESSAGE) + " : " + (CodeGenPlugin.getPlugin().getString("jet.mark.file.line", new Object[]{targetFile.getLocation(), marker.getAttribute(IMarker.LINE_NUMBER)}))); //$NON-NLS-1$ //$NON-NLS-2$ - } - } - return errors; - } - - /** - * Create the correct classpath entries for the given project - * - * @param project - */ - protected void createClasspathEntries(IProject project) { - Assert.isNotNull(project, "A valid project is required in order to append to a classpath"); //$NON-NLS-1$ - String variableName = null; - String pluginId = null; - for (Iterator variablesKeyIterator = getVariables().keySet().iterator(); variablesKeyIterator.hasNext();) { - variableName = (String) variablesKeyIterator.next(); - pluginId = (String) getVariables().get(variableName); - if (hasOutputDirectory(pluginId)) - addLinkedFolderAsLibrary(project, variableName, pluginId); - else - addRuntimeJarsAsLibrary(project, pluginId); - } - } - - /** - * @param pluginId - * @return - */ - protected boolean hasOutputDirectory(String pluginId) { - Bundle bundle = Platform.getBundle(pluginId); - URL outputDirectory = Platform.find(bundle,new Path("bin")); //$NON-NLS-1$ - if (outputDirectory == null) - return false; - URL installLocation = null; - try { - installLocation = Platform.asLocalURL(outputDirectory); - } catch (IOException e) { - Logger.getLogger().logWarning(J2EEPluginResourceHandler.getString("Install_Location_Error_", new Object[]{installLocation}) + e); //$NON-NLS-1$ - } - File outputDirectoryFile = new File(installLocation.getPath());// new File(location); - return outputDirectoryFile.canRead() && outputDirectoryFile.isDirectory() && outputDirectoryFile.listFiles().length > 0; - } - - /** - * @param project - * @param variableName - * @param pluginId - */ - protected void addRuntimeJarsAsLibrary(IProject project, String pluginId) { - ManifestElement[] elements = null; - Bundle bundle = Platform.getBundle(pluginId); - try { - String requires = (String) bundle.getHeaders().get(Constants.BUNDLE_CLASSPATH); - elements = ManifestElement.parseHeader(Constants.BUNDLE_CLASSPATH, requires); - } catch (Exception e) { - Logger.getLogger().logError(e); - elements = new ManifestElement[0]; - } - IPath runtimeLibFullPath = null; - URL fullurl = null; - if (elements == null) { - if (bundle.getLocation().endsWith(".jar")) - try { - runtimeLibFullPath = getJarredPluginPath(bundle); - } catch (IOException e) { - J2EEPlugin.logError(e); - } - appendToClassPath(runtimeLibFullPath,project); - return; - } - for (int i = 0; i < elements.length; i++) { - String value = elements[i].getValue(); - if (".".equals(value)) //$NON-NLS-1$ - value = "/"; //$NON-NLS-1$ - fullurl = Platform.getBundle(pluginId).getEntry(value); - // fix the problem with leading slash that caused dup classpath entries - if (fullurl==null) continue; - try { - runtimeLibFullPath = new Path(Platform.asLocalURL(fullurl).getPath()); - } catch (Exception e) { - Logger.getLogger().logError(e); - } - //TODO handle jar'ed plugins, this is a hack for now, need to find proper bundle API - if (bundle.getLocation().endsWith(".jar")) - try { - runtimeLibFullPath = getJarredPluginPath(bundle); - } catch (IOException e) { - J2EEPlugin.logError(e); - } - if (!"jar".equals(runtimeLibFullPath.getFileExtension()) && !"zip".equals(runtimeLibFullPath.getFileExtension())) //$NON-NLS-1$ //$NON-NLS-2$ - continue; - appendToClassPath(runtimeLibFullPath,project); - } - } - - private void appendToClassPath(IPath runtimeLibFullPath, IProject project) { - IClasspathEntry entry = null; - entry = JavaCore.newLibraryEntry(runtimeLibFullPath, null,null,null,new IClasspathAttribute[]{},false); - try { - if (!classpathEntries.contains(entry)) - classpathEntries.add(entry); - //J2EEProjectUtilities.appendJavaClassPath(project, entry); - } catch (Exception e) { - Logger.getLogger().logError("Problem appending \"" + entry.getPath() + "\" to classpath of Project \"" + project.getName() + "\"."); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - Logger.getLogger().logError(e); - } - } - - private IPath getJarredPluginPath(Bundle bundle) throws IOException { - Path runtimeLibFullPath = null; - String jarPluginLocation = FileLocator.getBundleFile(bundle).getPath(); - Path jarPluginPath = new Path(jarPluginLocation); - // handle case where jars are installed outside of eclipse installation - if (jarPluginPath.isAbsolute()) - runtimeLibFullPath = jarPluginPath; - // handle normal case where all plugins under eclipse install - else { - String installPath = Platform.getInstallLocation().getURL().getPath(); - runtimeLibFullPath = new Path(installPath+"/"+jarPluginLocation); //$NON-NLS-1$ - } - return runtimeLibFullPath; - } - - /** - * @param progressMonitor - */ - protected void updateProgress(IProgressMonitor progressMonitor, String key) { - progressMonitor.subTask(getMessage(key)); - } - - /** - * @param progressMonitor - */ - protected void updateProgress(IProgressMonitor progressMonitor, String key, Object[] args) { - progressMonitor.subTask(getMessage(key, args)); - } - - protected String getMessage(String key) { - return CodeGenPlugin.getPlugin().getString(key); - } - - protected String getMessage(String key, Object[] args) { - return CodeGenPlugin.getPlugin().getString(key, args); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.emf.codegen.jet.JETEmitter#addVariable(java.lang.String, java.lang.String) - */ - public void addVariable(String variableName, String pluginID) throws JETException { - if (!isIntelligentLinkingEnabled()) - super.addVariable(variableName, pluginID); - else { - getVariables().put(variableName, pluginID); - IWorkspace workspace = ResourcesPlugin.getWorkspace(); - IProject project = workspace.getRoot().getProject(getProjectName()); - if (project != null && project.exists()) - createClasspathEntries(project); - } - - } - - /** - * @return - */ - private boolean isIntelligentLinkingEnabled() { - return intelligentLinkingEnabled; - } - - /** - * @return - */ - private Map getVariables() { - if (variables == null) - variables = new HashMap(); - return variables; - } - - protected void addLinkedFolderAsLibrary(IProject project, String variableName, String pluginID) { - try { - URL outputDirectory = Platform.find(Platform.getBundle(pluginID),new Path("bin")); //$NON-NLS-1$ -// IPluginDescriptor pluginDescriptor = Platform.getPlugin(pluginID).getDescriptor(); -// URL outputDirectory = pluginDescriptor.find(new Path("bin")); //$NON-NLS-1$ - String pathString = Platform.asLocalURL(outputDirectory).getPath(); - if (pathString.endsWith("/")) //$NON-NLS-1$ - pathString = pathString.substring(0, pathString.length() - 1); - if (pathString.startsWith("/")) //$NON-NLS-1$ - pathString = pathString.substring(1, pathString.length()); - IPath path = new Path(pathString).makeAbsolute(); - - String binDirectoryVariable = variableName + "_BIN"; //$NON-NLS-1$ - IFolder linkedDirectory = project.getFolder(binDirectoryVariable); - if (!linkedDirectory.exists()) { - linkedDirectory.createLink(path, IResource.ALLOW_MISSING_LOCAL, null); - linkedDirectory.setDerived(true); - project.refreshLocal(IResource.DEPTH_INFINITE, null); - } - IClasspathEntry entry = JavaCore.newLibraryEntry(linkedDirectory.getFullPath(), null,null,null,new IClasspathAttribute[]{},false); - - if (!classpathEntries.contains(entry)) - classpathEntries.add(entry); - //J2EEProjectUtilities.appendJavaClassPath(project, entry); - - } catch (Exception e) { - Logger.getLogger().logError(e); - } - } - - /** - * @param intelligentLinkingEnabled - * The intelligentLinkingEnabled to set. - */ - public void setIntelligentLinkingEnabled(boolean intelligentLinkingEnabled) { - this.intelligentLinkingEnabled = intelligentLinkingEnabled; - } - - protected JETCompiler getJetCompiler() { - try { - if (jetCompiler == null) { - jetCompiler = templateURIPath == null ? new MyJETCompiler(templateURI, encoding) : new MyJETCompiler(templateURIPath, templateURI, encoding); - } - } catch (JETException e) { - Logger.getLogger().logError(e); - } - return jetCompiler; - } -} diff --git a/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/internal/project/test.jpage b/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/internal/project/test.jpage deleted file mode 100644 index e69de29bb..000000000 --- a/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/internal/project/test.jpage +++ /dev/null diff --git a/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/internal/rename/ClasspathRenameInfo.java b/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/internal/rename/ClasspathRenameInfo.java deleted file mode 100644 index ba2780c43..000000000 --- a/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/internal/rename/ClasspathRenameInfo.java +++ /dev/null @@ -1,76 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2003, 2004 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.internal.rename; - - -import java.util.ArrayList; -import java.util.List; - -import org.eclipse.core.resources.IProject; - -/** - * A simple structure that remembers for a given project, the manifest entries to be deleted and the - * build path entries to be deleted - */ -public class ClasspathRenameInfo { - /** - * The project from which the dependencies will be removed - */ - protected IProject targetProject; - /** - * The literal manifest entries to be removed; String - */ - protected List manifestEntries; - /** - * The project references to be removed from the build path; IProject - */ - protected List referencedProjects; - - public ClasspathRenameInfo(IProject project) { - super(); - targetProject = project; - } - - /** - * Gets the manifestEntries. - * - * @return Returns a List - */ - public List getManifestEntries() { - if (manifestEntries == null) - manifestEntries = new ArrayList(); - return manifestEntries; - } - - - /** - * Gets the referencedProjects. - * - * @return Returns a List - */ - public List getReferencedProjects() { - if (referencedProjects == null) - referencedProjects = new ArrayList(); - return referencedProjects; - } - - - /** - * Gets the targetProject. - * - * @return Returns a IProject - */ - public IProject getTargetProject() { - return targetProject; - } - - -}
\ No newline at end of file diff --git a/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/internal/rename/RenameOptions.java b/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/internal/rename/RenameOptions.java deleted file mode 100644 index 3041a2415..000000000 --- a/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/internal/rename/RenameOptions.java +++ /dev/null @@ -1,165 +0,0 @@ -/*************************************************************************************************** - * Copyright (c) 2003, 2004 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.internal.rename; - - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -public class RenameOptions { - protected boolean isEARRename; - protected boolean renameProjects; - protected boolean renameModules; - protected boolean renameModuleDependencies; - protected List selectedProjects; - /** Applicable for EAR rename */ - protected List selectedReferencedProjects; - protected String newName = null; - protected String newContextRoot = null; - protected boolean bogus; - - /** - * Constructor for RenameOptions. - */ - public RenameOptions() { - super(); - } - - - public boolean shouldRenameModules() { - return renameModules; - } - - - public void setRenameModules(boolean renameModulesFromAllEARs) { - this.renameModules = renameModulesFromAllEARs; - } - - - public boolean shouldRenameProjects() { - return renameProjects; - } - - - public void setRenameProjects(boolean renameProjects) { - this.renameProjects = renameProjects; - } - - - public boolean shouldRenameModuleDependencies() { - return renameModuleDependencies; - } - - - public void setRenameModuleDependencies(boolean renameReferencesFromModuleDependencies) { - this.renameModuleDependencies = renameReferencesFromModuleDependencies; - } - - public List getModuleAndUtilityProjects() { - if (isEARRename) - return getSelectedReferencedProjects(); - return getSelectedProjects(); - } - - public List getAllProjectsToRename() { - List result = new ArrayList(); - result.addAll(getSelectedProjects()); - result.addAll(getSelectedReferencedProjects()); - return result; - } - - /** - * Gets the selectedProjects. - * - * @return Returns a List - */ - public List getSelectedProjects() { - if (selectedProjects == null) - return Collections.EMPTY_LIST; - return selectedProjects; - } - - /** - * Sets the selectedProjects. - * - * @param selectedProjects - * The selectedProjects to set - */ - public void setSelectedProjects(List selectedProjects) { - this.selectedProjects = selectedProjects; - } - - /** - * Gets the selectedReferencedProjects. - * - * @return Returns a List - */ - public List getSelectedReferencedProjects() { - if (selectedReferencedProjects == null) - return Collections.EMPTY_LIST; - return selectedReferencedProjects; - } - - /** - * Sets the selectedReferencedProjects. - * - * @param selectedReferencedProjects - * The selectedReferencedProjects to set - */ - public void setSelectedReferencedProjects(List selectedReferencedProjects) { - this.selectedReferencedProjects = selectedReferencedProjects; - } - - public boolean isEARRename() { - return isEARRename; - } - - public void setIsEARRename(boolean isEARRename) { - this.isEARRename = isEARRename; - } - - /** - * Gets the newName. - * - * @return Returns a String - */ - public String getNewName() { - return newName; - } - - /** - * Sets the newName. - * - * @param newName - * The newName to set - */ - public void setNewName(String newName) { - this.newName = newName; - } - - /** - * Gets the newContextRoot. - * - * @return Returns a String - */ - public String getNewContextRoot() { - return newContextRoot; - } - - /** - * Sets the newContextRoot. - * - * @param newContextRoot - * The newContextRoot to set - */ - public void setNewContextRoot(String newContextRoot) { - this.newContextRoot = newContextRoot; - } -}
\ No newline at end of file diff --git a/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/internal/servertarget/IServerTargetConstants.java b/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/internal/servertarget/IServerTargetConstants.java deleted file mode 100644 index d54ae2061..000000000 --- a/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/internal/servertarget/IServerTargetConstants.java +++ /dev/null @@ -1,41 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2003, 2004 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 - *******************************************************************************/ -/* - * Created on Aug 6, 2003 - * - * To change the template for this generated file go to - * Window>Preferences>Java>Code Generation>Code and Comments - */ -package org.eclipse.jst.j2ee.internal.servertarget; - - -/** - * @author vijayb - * - * To change the template for this generated type comment go to Window>Preferences>Java>Code - * Generation>Code and Comments - */ -public interface IServerTargetConstants { - String EAR_TYPE = "j2ee.ear"; //$NON-NLS-1$ - String WEB_TYPE = "j2ee.web"; //$NON-NLS-1$ - String WEB_PORTAL_TYPE = "j2ee.web.portal"; //$NON-NLS-1$ - String EJB_TYPE = "j2ee.ejb"; //$NON-NLS-1$ - String APP_CLIENT_TYPE = "j2ee.appclient"; //$NON-NLS-1$ - String CONNECTOR_TYPE = "j2ee.connector"; //$NON-NLS-1$ - String J2EE_12 = "1.2"; //$NON-NLS-1$ - String J2EE_13 = "1.3"; //$NON-NLS-1$ - String J2EE_14 = "1.4"; //$NON-NLS-1$ - String SERVER_FILE_NAME = ".server"; //$NON-NLS-1$ - String aesV4ServerTargetId = "com.ibm.etools.websphere.aes.v4";//$NON-NLS-1$ - String v5ServerTargetId = "com.ibm.etools.websphere.serverTarget.base.v5";//$NON-NLS-1$ - String v51ServerTargetId = "com.ibm.etools.websphere.serverTarget.base.v51";//$NON-NLS-1$ - -}
\ No newline at end of file diff --git a/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/internal/servertarget/ITargetRuntimeExtensionHandler.java b/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/internal/servertarget/ITargetRuntimeExtensionHandler.java deleted file mode 100644 index 5b7882d8c..000000000 --- a/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/internal/servertarget/ITargetRuntimeExtensionHandler.java +++ /dev/null @@ -1,29 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2003, 2004 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 - *******************************************************************************/ -/* - * Created on Feb 5, 2004 - * - * To change the template for this generated file go to - * Window - Preferences - Java - Code Generation - Code and Comments - */ -package org.eclipse.jst.j2ee.internal.servertarget; - -import org.eclipse.core.resources.IProject; - -/** - * @author vijayb - * - * To change the template for this generated type comment go to Window - Preferences - Java - Code - * Generation - Code and Comments - */ -public interface ITargetRuntimeExtensionHandler { - public boolean removeTargetRuntimeClasspath(IProject project); -}
\ No newline at end of file diff --git a/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/internal/servertarget/J2EEProjectServerTargetDataModelProvider.java b/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/internal/servertarget/J2EEProjectServerTargetDataModelProvider.java deleted file mode 100644 index 1a5802930..000000000 --- a/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/internal/servertarget/J2EEProjectServerTargetDataModelProvider.java +++ /dev/null @@ -1,299 +0,0 @@ -/******************************************************************************* - * Copyright (c) 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.internal.servertarget; - -import java.util.Arrays; -import java.util.Collections; -import java.util.List; -import java.util.Set; - -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.jst.j2ee.internal.J2EEVersionConstants; -import org.eclipse.jst.j2ee.internal.common.XMLResource; -import org.eclipse.jst.j2ee.internal.plugin.J2EEPlugin; -import org.eclipse.jst.j2ee.internal.project.J2EECreationResourceHandler; -import org.eclipse.jst.j2ee.project.datamodel.properties.IJ2EEProjectServerTargetDataModelProperties; -import org.eclipse.wst.common.frameworks.datamodel.AbstractDataModelProvider; -import org.eclipse.wst.common.frameworks.datamodel.DataModelPropertyDescriptor; -import org.eclipse.wst.common.frameworks.datamodel.IDataModel; -import org.eclipse.wst.common.frameworks.datamodel.IDataModelOperation; -import org.eclipse.wst.server.core.IRuntime; -import org.eclipse.wst.server.core.ServerUtil; -import org.eclipse.wst.server.core.internal.ResourceManager; - -public class J2EEProjectServerTargetDataModelProvider extends AbstractDataModelProvider implements IJ2EEProjectServerTargetDataModelProperties { - - private static final String DEFAULT_TARGET_ID = "org.eclipse.jst.server.core.runtimeType"; //$NON-NLS-1$ - - public void init() { - model.setProperty(RUNTIME_TARGET_ID, getDefaultServerTargetID()); - super.init(); - } - - public IDataModelOperation getDefaultOperation() { - return new J2EEProjectServerTargetOp(model); - } - - public Set getPropertyNames() { - Set propertyNames = super.getPropertyNames(); - propertyNames.add(PROJECT_NAME); - propertyNames.add(RUNTIME_TARGET_ID); - propertyNames.add(J2EE_VERSION_ID); - propertyNames.add(DEPLOYMENT_TYPE_ID); - propertyNames.add(UPDATE_MODULES); - return propertyNames; - } - - public IProject getProject() { - String name = (String) getProperty(PROJECT_NAME); - if (name != null && name.length() > 0) - return ResourcesPlugin.getWorkspace().getRoot().getProject(name); - return null; - } - - public IRuntime getRuntimeTarget() { - String serverTargetId = (String) getProperty(RUNTIME_TARGET_ID); - return ResourceManager.getInstance().getRuntime(serverTargetId); - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.wst.common.frameworks.internal.operation.WTPOperationDataModel#getDefaultProperty(java.lang.String) - */ - public Object getDefaultProperty(String propertyName) { - if (propertyName.equals(RUNTIME_TARGET_ID)) - return getDefaultServerTargetID(); - else if (propertyName.equals(J2EE_VERSION_ID)) - return getDefaultVersionID(); - else if (propertyName.equals(UPDATE_MODULES)) { - return Boolean.TRUE; - } - return super.getDefaultProperty(propertyName); - } - - private Integer getDefaultVersionID() { - return new Integer(J2EEVersionConstants.J2EE_1_4_ID); - } - - /** - * @return - */ - private Object getDefaultServerTargetID() { - List targets = getValidServerTargets(); - if (!targets.isEmpty()) { - IRuntime target = null; - for (int i = targets.size() - 1; i < targets.size() && i >= 0; i--) { - target = (IRuntime) targets.get(i); - if (DEFAULT_TARGET_ID.equals(target.getId())) - return target.getId(); - } - if (target != null) - return target.getId(); - } - return null; - } - - /** - * This should only be used by clients that need to interact with the Server tooling directly. - * The return value corresponds to the type id associated with a runtime target. - * - * @return - */ - public String computeTypeId() { - int type = -1; - if (getDataModel().isPropertySet(DEPLOYMENT_TYPE_ID)) - type = getIntProperty(DEPLOYMENT_TYPE_ID); - // else { - // J2EENature nature = J2EENature.getRegisteredRuntime(getProject()); - // if (nature != null) - // type = nature.getDeploymentDescriptorType(); - // else - // type = getIntProperty(DEPLOYMENT_TYPE_ID); - // } - return computeTypeId(type); - } - - /** - * @param deploymentDescriptorType2 - * @return - */ - private String computeTypeId(int deploymentDescriptorType) { - switch (deploymentDescriptorType) { - case XMLResource.APPLICATION_TYPE : - return IServerTargetConstants.EAR_TYPE; - case XMLResource.APP_CLIENT_TYPE : - return IServerTargetConstants.APP_CLIENT_TYPE; - case XMLResource.EJB_TYPE : - return IServerTargetConstants.EJB_TYPE; - case XMLResource.WEB_APP_TYPE : - return IServerTargetConstants.WEB_TYPE; - case XMLResource.RAR_TYPE : - return IServerTargetConstants.CONNECTOR_TYPE; - } - return null; - } - - /** - * This is only to be used by clients that need to interact with the Server tooling directly. - * The return value corresponds to the version id associated with a runtime target. - */ - public String computeVersionId() { - int version = -1; - if (getDataModel().isPropertySet(J2EE_VERSION_ID)) - version = getIntProperty(J2EE_VERSION_ID); - // else { - // J2EENature nature = J2EENature.getRegisteredRuntime(getProject()); - // if (nature != null) - // version = nature.getJ2EEVersion(); - // else - // version = getIntProperty(J2EE_VERSION_ID); - // } - return computeVersionId(version); - } - - /** - * @param version - * @return - */ - private String computeVersionId(int version) { - switch (version) { - case J2EEVersionConstants.J2EE_1_2_ID : - return IServerTargetConstants.J2EE_12; - case J2EEVersionConstants.J2EE_1_3_ID : - return IServerTargetConstants.J2EE_13; - case J2EEVersionConstants.J2EE_1_4_ID : - return IServerTargetConstants.J2EE_14; - } - return null; - } - - /* - * (non-Javadoc) - * - * @see org.eclipse.wst.common.frameworks.internal.operation.WTPOperationDataModel#doGetValidPropertyValues(java.lang.String) - */ - public DataModelPropertyDescriptor[] getValidPropertyDescriptors(String propertyName) { - if (propertyName.equals(RUNTIME_TARGET_ID)) - return getValidServerTargetDescriptors(); - return super.getValidPropertyDescriptors(propertyName); - } - - private DataModelPropertyDescriptor[] getValidServerTargetDescriptors() { - List targets = getValidServerTargets(); - DataModelPropertyDescriptor[] descriptors = null; - if (!targets.isEmpty()) { - int serverTargetListSize = targets.size(); - descriptors = new DataModelPropertyDescriptor[serverTargetListSize]; - for (int i = 0; i < targets.size(); i++) { - IRuntime runtime = (IRuntime) targets.get(i); - descriptors[i] = new DataModelPropertyDescriptor(runtime.getId(), runtime.getName()); - } - } else { - descriptors = new DataModelPropertyDescriptor[0]; - } - return descriptors; - } - - public boolean propertySet(String propertyName, Object propertyValue) { - if (propertyName.equals(J2EE_VERSION_ID)) { - IRuntime target = getServerTargetByID(getStringProperty(RUNTIME_TARGET_ID)); - if (target == null) - setProperty(RUNTIME_TARGET_ID, null); - model.notifyPropertyChange(RUNTIME_TARGET_ID, IDataModel.VALID_VALUES_CHG); - } else if (RUNTIME_TARGET_ID.equals(propertyName)) { - setProperty(RUNTIME_TARGET_ID, propertyValue); - } - return true; - } - - - private IRuntime getServerTargetByID(String id) { - List targets = getValidServerTargets(); - IRuntime target; - for (int i = 0; i < targets.size(); i++) { - target = (IRuntime) targets.get(i); - if (id.equals(target.getId())) - return target; - } - return null; - } - - /** - * @return - */ - private List getValidServerTargets() { - List validServerTargets = null; - // TODO: api is needed from the server target helper to get all server targets - // validServerTargets = ServerTargetHelper.getServerTargets(IServerTargetConstants.EAR_TYPE, - // IServerTargetConstants.J2EE_14); - validServerTargets = getServerTargets("", ""); //$NON-NLS-1$ //$NON-NLS-2$ - if (validServerTargets != null && validServerTargets.isEmpty()) - validServerTargets = null; - if (validServerTargets == null) - return Collections.EMPTY_LIST; - return validServerTargets; - } - - public static List getServerTargets(String type, String version) { - List targets = Arrays.asList(ServerUtil.getRuntimes(type, version)); - return targets; - } - - /** - * @return - */ - // private List getValidServerTargets() { - // List validServerTargets = null; - // String type = computeTypeId(); - // if (type != null) { - // String version = computeVersionId(); - // if (version != null) { - // validServerTargets = ServerTargetHelper.getServerTargets(type, version); - // if (validServerTargets != null && validServerTargets.isEmpty()) - // validServerTargets = null; - // } - // } - // if (validServerTargets == null) - // return Collections.EMPTY_LIST; - // return validServerTargets; - // } - /* - * (non-Javadoc) - * - * @see org.eclipse.wst.common.frameworks.internal.operation.WTPOperationDataModel#doValidateProperty(java.lang.String) - */ - public IStatus validate(String propertyName) { - if (propertyName.equals(RUNTIME_TARGET_ID)) - return validateServerTarget(); - return super.validate(propertyName); - } - - /** - * @return - */ - private IStatus validateServerTarget() { - List targets = getValidServerTargets(); - if (targets.isEmpty()) { - return J2EEPlugin.newErrorStatus(J2EECreationResourceHandler.ServerTargetDataModel_UI_7, null); - } - IRuntime target = getRuntimeTarget(); - if (target == null) { - return J2EEPlugin.newErrorStatus(J2EECreationResourceHandler.ServerTargetDataModel_UI_8, null); - } else if (!targets.contains(target)) { - return J2EEPlugin.newErrorStatus(J2EECreationResourceHandler.ServerTargetDataModel_UI_9, null); - } - return OK_STATUS; - } - -} diff --git a/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/internal/servertarget/J2EEProjectServerTargetOp.java b/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/internal/servertarget/J2EEProjectServerTargetOp.java deleted file mode 100644 index 215063985..000000000 --- a/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/internal/servertarget/J2EEProjectServerTargetOp.java +++ /dev/null @@ -1,70 +0,0 @@ -/******************************************************************************* - * Copyright (c) 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.internal.servertarget; - -import org.eclipse.core.commands.ExecutionException; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IAdaptable; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.jst.j2ee.project.datamodel.properties.IJ2EEProjectServerTargetDataModelProperties; -import org.eclipse.wst.common.componentcore.internal.util.IModuleConstants; -import org.eclipse.wst.common.frameworks.datamodel.AbstractDataModelOperation; -import org.eclipse.wst.common.frameworks.datamodel.IDataModel; -import org.eclipse.wst.server.core.IRuntime; -import org.eclipse.wst.server.core.internal.ResourceManager; - -public class J2EEProjectServerTargetOp extends AbstractDataModelOperation { - - /** - * @param operationDataModel - */ - public J2EEProjectServerTargetOp(IDataModel model) { - super(model); - // TODO Auto-generated constructor stub - } - - public IStatus execute(IProgressMonitor monitor, IAdaptable info) throws ExecutionException { - String serverTargetId = model.getStringProperty(IJ2EEProjectServerTargetDataModelProperties.RUNTIME_TARGET_ID); - IRuntime runtime = ResourceManager.getInstance().getRuntime(serverTargetId); - IProject project = null; - String name = model.getStringProperty(IJ2EEProjectServerTargetDataModelProperties.PROJECT_NAME); - if (name != null && name.length() > 0) - project = ResourcesPlugin.getWorkspace().getRoot().getProject(name); - if (runtime != null && project != null) { - try { - //ServerCore.getProjectProperties(project).setRuntimeTarget(runtime, monitor); - if (model.getBooleanProperty(IJ2EEProjectServerTargetDataModelProperties.UPDATE_MODULES) - && project.hasNature(IModuleConstants.MODULE_NATURE_ID)) { - //ServerTargetHelper.setNewServerTargetForEARModules(runtime, project); - //ServerTargetHelper.setNewServerTargetForEARUtilityJars(runtime, project); - } - } catch (CoreException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - return OK_STATUS; - } - - public IStatus redo(IProgressMonitor monitor, IAdaptable info) throws ExecutionException { - // TODO Auto-generated method stub - return null; - } - - public IStatus undo(IProgressMonitor monitor, IAdaptable info) throws ExecutionException { - // TODO Auto-generated method stub - return null; - } - -} diff --git a/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/internal/servertarget/ServerTargetHelper.java b/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/internal/servertarget/ServerTargetHelper.java deleted file mode 100644 index 879a73588..000000000 --- a/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/internal/servertarget/ServerTargetHelper.java +++ /dev/null @@ -1,476 +0,0 @@ -/******************************************************************************* - * 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 - *******************************************************************************/ -/* - * Created on Aug 15, 2003 - * - * To change the template for this generated file go to Window>Preferences>Java>Code - * Generation>Code and Comments - */ -package org.eclipse.jst.j2ee.internal.servertarget; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -import org.eclipse.core.resources.IProject; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.jdt.core.IClasspathEntry; -import org.eclipse.jdt.core.IJavaProject; -import org.eclipse.jdt.core.JavaCore; -import org.eclipse.jdt.core.JavaModelException; -import org.eclipse.jem.util.logger.proxy.Logger; -import org.eclipse.jem.workbench.utility.JemProjectUtilities; -import org.eclipse.wst.server.core.IRuntime; -import org.eclipse.wst.server.core.ServerCore; -import org.eclipse.wst.server.core.ServerUtil; - -//import com.ibm.etools.j2ee.internal.project.EAREditModel; -//import com.ibm.etools.j2ee.internal.project.EARNatureRuntime; - -/** - * @author vijayb - * @deprecated - Use server core api to set Runtime Targets. Use artifact edit api to - * get to any j2ee related methods in the class. - * To change the template for this generated type comment go to Window>Preferences>Java>Code - * Generation>Code and Comments - */ -public class ServerTargetHelper { - public static final String JAVA_NATURE_ID = "org.eclipse.jdt.core.javanature"; //$NON-NLS-1$ - - public static final String SERVER_CONTAINER = "org.eclipse.jst.server.core.container"; //$NON-NLS-1$ - - /** - * - */ - public ServerTargetHelper() { - super(); - // TODO Auto-generated constructor stub - } - - public static void cleanUpNonServerTargetClasspath(IProject project) { - List existingClasspathEntries = ServerTargetHelper.getExistingNonServerTargetClasspath(project); - if (!existingClasspathEntries.isEmpty()) - ServerTargetHelper.removeNonSeverTargetClasspathEntries(project, existingClasspathEntries); - } - - /** - * @param existingClasspathEntries - */ - public static void removeNonSeverTargetClasspathEntries(IProject project, List existingClasspathEntries) { - try { - JemProjectUtilities.removeFromJavaClassPath(project, existingClasspathEntries); - } catch (JavaModelException jme) { - Logger.getLogger().logError(jme); - } - } - - /** - * @param project - */ - // public static void syncNoServerTargetForEARModules(IProject project) { - // removeServerTargetForEARModuleProjects(project); - // removeServerTargetForEARUtilsProject(project); - // } - /** - * @param project - */ - // public static void removeServerTargetForEAR(IProject project, boolean - // updateModules) { - // //We don't need to remove a server target anyomre as it need to be - // // there - // //ServerTargetManager.removeServerTarget(project, null); - // if (updateModules) { - // removeServerTargetForEARModuleProjects(project); - // removeServerTargetForEARUtilsProject(project); - // } - // } - /** - * @param project - */ - // private static void removeServerTargetForEARModuleProjects(IProject - // project) { - // List moduleProjects = - // ServerTargetHelper.getAllEarModuleProjects(project); - // if (!moduleProjects.isEmpty()) { - // for (int i = 0; i < moduleProjects.size(); i++) { - // IProject moduleProject = (IProject) moduleProjects.get(i); - // ServerTargetType tt = - // ServerTargetManager.getServerTargetType(moduleProject); - // if (tt != null) { - // J2EEJavaProjectInfo info = getNewJ2EEProjectInfo(moduleProject); - // if (info != null) { - // info.setProject(moduleProject); - // try { - // info.calculateServerClasspathEntries(); - // info.getJavaProject().setRawClasspath(info.getClasspathEntries(), null); - // } catch (JavaModelException jme) { - // Logger.getLogger().logTrace(jme); - // } - // } - // } - // } - // } - // } - /** - * @param project - */ - // private static void removeServerTargetForEARUtilsProject(IProject - // project) { - // EARNatureRuntime nature = EARNatureRuntime.getRuntime(project); - // EAREditModel editModel = null; - // Object key = new ServerTargetHelper(); - // try { - // editModel = nature.getEarEditModelForRead(key); - // List utilProjects = - // ServerTargetHelper.getAllEarUtilityProjects(editModel, project); - // if (!utilProjects.isEmpty()) { - // for (int i = 0; i < utilProjects.size(); i++) { - // IProject moduleProject = (IProject) utilProjects.get(i); - // //We don't need to remove a server target anyomre as it need to be there - // //ServerTargetType existingTargetType = - // // ServerTargetManager.getServerTargetType(moduleProject); - // //if (existingTargetType != null) { - // //if (!editModel.isEjbClientJarProject(moduleProject)) - // //We don't need to remove a server target anyomre as it - // // need to be there - // //ServerTargetManager.removeServerTarget(moduleProject,null); - // //else - // // removeServerTargetForEJBClientJar(moduleProject); - // } - // } - // } finally { - // editModel.releaseAccess(key); - // } - // } - /** - * @param moduleProject - */ - // public static void removeServerTargetForEJBClientJar(IProject - // ejbClientJarProject) { - // EjbModuleExtension ejbExt = EarModuleManager.getEJBModuleExtension(); - // J2EEJavaProjectInfo info = ejbExt.createProjectInfo(); - // if (info != null) { - // info.setProject(ejbClientJarProject); - // try { - // info.calculateServerClasspathEntries(); - // info.getJavaProject().setRawClasspath(info.getClasspathEntries(), null); - // } catch (JavaModelException jme) { - // Logger.getLogger().logTrace(jme); - // } - // } - // } - // public static void removeServerTargetOnProject(IProject project, String - // projectType) { - // setServerClassPathForJ2EEProject(project, projectType); - // } - /** - * @param project - */ - // public static void setServerClassPathForJ2EEProject(IProject project, - // String projectType) { - // try { - // J2EEJavaProjectInfo info = getNewJ2EEProjectInfo(project, projectType); - // if (info != null) { - // info.setProject(project); - // info.calculateServerClasspathEntries(); - // info.getJavaProject().setRawClasspath(info.getClasspathEntries(), null); - // } - // } catch (JavaModelException jme) { - // Logger.getLogger().logError(jme); - // } - // } - // public static J2EEJavaProjectInfo getNewJ2EEProjectInfo(IProject project, - // String projectType) - // { - // if (projectType.equals(IServerTargetConstants.APP_CLIENT_TYPE)) - // return new ApplicationClientProjectInfo(); - // else if (projectType.equals(IServerTargetConstants.WEB_TYPE)) { - // WebModuleExtension webExt = EarModuleManager.getWebModuleExtension(); - // J2EEJavaProjectInfo info = webExt.createProjectInfo(); - // String webNature = J2EENature.getRegisteredRuntimeID(project); - // info.setJ2EEVersion(webNature.equals(J2EEVersionConstants.VERSION_1_3_TEXT) - // ? - // J2EEVersionConstants.J2EE_1_3_ID : J2EEVersionConstants.J2EE_1_2_ID); - // return info; - // } else if (projectType.equals(IServerTargetConstants.EJB_TYPE)) { - // EjbModuleExtension ejbExt = EarModuleManager.getEJBModuleExtension(); - // return ejbExt.createProjectInfo(); - // } else if (projectType.equals(IServerTargetConstants.CONNECTOR_TYPE)) { - // JcaModuleExtension jcaExt = EarModuleManager.getJCAModuleExtension(); - // return jcaExt.createProjectInfo(); - // } - // return null; - // } - // public static J2EEJavaProjectInfo getNewJ2EEProjectInfo(IProject project) - // { - // if (J2EENature.hasRuntime(project, IEJBNatureConstants.EJB_NATURE_IDS)) { - // EjbModuleExtension ejbExt = EarModuleManager.getEJBModuleExtension(); - // return ejbExt.createProjectInfo(); - // } else if (J2EENature.hasRuntime(project, - // IWebNatureConstants.J2EE_NATURE_ID)) { - // WebModuleExtension webExt = EarModuleManager.getWebModuleExtension(); - // return webExt.createProjectInfo(); - // } else if (ApplicationClientNatureRuntime.hasRuntime(project)) - // return new ApplicationClientProjectInfo(); - // else if (J2EENature.hasRuntime(project, - // IConnectorNatureConstants.CONNECTOR_NATURE_ID)) { - // JcaModuleExtension jcaExt = EarModuleManager.getJCAModuleExtension(); - // return jcaExt.createProjectInfo(); - // } - // return null; - // } -// public static void setNewServerTargetForEARModules(IRuntime newServerTarget, IProject project) { -// List moduleProjects = ServerTargetHelper.getAllEarModuleProjects(project); -// if (!moduleProjects.isEmpty()) { -// for (int i = 0; i < moduleProjects.size(); i++) { -// IProject moduleProject = (IProject) moduleProjects.get(i); -// String[] projectAttr = ServerTargetHelper.getProjectTypeAndJ2EELevel(moduleProject); -// if (projectAttr[0] != null && projectAttr[1] != null) { -// IRuntime existingTargetType = ServerCore.getProjectProperties(moduleProject).getRuntimeTarget(); -// if (existingTargetType != null) { -// if (!existingTargetType.getId().equals(newServerTarget.getId())) -// setServerTargetForModuleProject(newServerTarget, moduleProject, projectAttr); -// // TODO Move the WLP sync to this method -// } else -// setServerTargetForModuleProject(newServerTarget, moduleProject, projectAttr); -// } -// } -// } -// } - -// public static void setServerTargetForModuleProject(IRuntime newServerTarget, IProject moduleProject, String[] projectAttr) { -// ServerTargetHelper.cleanUpNonServerTargetClasspath(moduleProject); -// setServerTarget(moduleProject, newServerTarget, null); -// } - -// public static List getWebProjectsInEAR(IProject earProject) { -// List moduleProjects = ServerTargetHelper.getAllEarModuleProjects(earProject); -// if (!moduleProjects.isEmpty()) { -// List webProjects = new ArrayList(); -// for (int i = 0; i < moduleProjects.size(); i++) { -// IProject project = (IProject) moduleProjects.get(i); -// WebModuleExtension webExt = EarModuleManager.getWebModuleExtension(); -// if (webExt.hasRuntime(project)) -// webProjects.add(project); -// } -// return webProjects; -// } -// return Collections.EMPTY_LIST; -// } - - /** - * @param newServerTarget - * @param tt - * @param project - */ -// public static void setNewServerTargetForEARUtilityJars(IRuntime newServerTarget, IProject project) { -// EARNatureRuntime nature = EARNatureRuntime.getRuntime(project); -// EAREditModel editModel = null; -// Object key = new ServerTargetHelper(); -// try { -// editModel = nature.getEarEditModelForRead(key); -// List utilProjects = ServerTargetHelper.getAllEarUtilityProjects(editModel, project); -// if (!utilProjects.isEmpty()) { -// for (int i = 0; i < utilProjects.size(); i++) { -// IProject moduleProject = (IProject) utilProjects.get(i); -// IRuntime existingTargetType = ServerCore.getProjectProperties(moduleProject).getRuntimeTarget(); -// if (existingTargetType != null) { -// if (!existingTargetType.getId().equals(newServerTarget.getId())) { -// setServerTargetForUtilProject(newServerTarget, moduleProject); -// } -// } else { -// setServerTargetForUtilProject(newServerTarget, moduleProject); -// } -// } -// } -// } finally { -// editModel.releaseAccess(key); -// } -// } - -// public static void setServerTargetForUtilProject(IRuntime newServerTarget, IProject moduleProject) { -// ServerTargetHelper.cleanUpNonServerTargetClasspath(moduleProject); -// setServerTarget(moduleProject, newServerTarget, null); -// } - -// public static void setServerTarget(IProject project, IRuntime runtime, IProgressMonitor monitor) { -// try { -// ServerCore.getProjectProperties(project).setRuntimeTarget(runtime, monitor); -// } catch (CoreException ce) { -// Logger.getLogger().logError(ce); -// } -// } - - /** - * @param earProject - */ -// public static List getAllEarModuleProjects(IProject earProject) { -// EARNatureRuntime nature = EARNatureRuntime.getRuntime(earProject); -// EAREditModel editModel = null; -// List moduleProjects = new ArrayList(); -// Object key = new ServerTargetHelper(); -// try { -// editModel = nature.getEarEditModelForRead(key); -// Set allModuleProjects = editModel.getModuleMappedModuleProjects(); -// if (!allModuleProjects.isEmpty()) -// moduleProjects.addAll(allModuleProjects); -// return moduleProjects; -// } finally { -// if (editModel != null) -// editModel.releaseAccess(key); -// } -// } -// - public static String[] getProjectTypeAndJ2EELevel(IProject project) { - String[] projectAttr = new String[2]; -// boolean isJ2EE13 = true; -// if (EARNatureRuntime.hasRuntime(project)) { -// projectAttr[0] = IServerTargetConstants.EAR_TYPE; -// isJ2EE13 = EARNatureRuntime.getRuntime(project).isJ2EE1_3(); -// } else if (J2EENature.hasRuntime(project, IEJBNatureConstants.EJB_NATURE_IDS)) { -// projectAttr[0] = IServerTargetConstants.EJB_TYPE; -// isJ2EE13 = J2EENature.getRuntime(project, IEJBNatureConstants.EJB_NATURE_IDS).isJ2EE1_3(); -// } else if (J2EENature.hasRuntime(project, IWebNatureConstants.J2EE_NATURE_ID)) { -// projectAttr[0] = IServerTargetConstants.WEB_TYPE; -// isJ2EE13 = J2EENature.getRuntime(project, IWebNatureConstants.J2EE_NATURE_ID).isJ2EE1_3(); -// } else if (J2EENature.hasRuntime(project,IApplicationClientNatureConstants.NATURE_ID)) { -// projectAttr[0] = IServerTargetConstants.APP_CLIENT_TYPE; -// isJ2EE13 = J2EENature.getRuntime(project,IApplicationClientNatureConstants.NATURE_ID).isJ2EE1_3(); -// } else if (J2EENature.hasRuntime(project, IConnectorNatureConstants.NATURE_ID)) { -// projectAttr[0] = IServerTargetConstants.CONNECTOR_TYPE; -// isJ2EE13 = J2EENature.getRuntime(project, IConnectorNatureConstants.NATURE_ID).isJ2EE1_3(); -// } else if (hasJavaNature(project)) -// projectAttr[0] = null; -// if (projectAttr[0] != null && projectAttr[0].length() > 0) { -// if (isJ2EE13) -// projectAttr[1] = IServerTargetConstants.J2EE_13; -// else -// projectAttr[1] = IServerTargetConstants.J2EE_12; -// } - return projectAttr; - } - - /** - * @param project - * @return - */ - public static boolean hasJavaNature(IProject project) { - try { - return project.hasNature(JAVA_NATURE_ID); - } catch (CoreException ce) { - Logger.getLogger().logTrace(ce); - } - return false; - } - - /** - * @param earProject - */ -// public static List getAllEarUtilityProjects(EAREditModel earEditModel, IProject earProject) { -// List utilityProjects = new ArrayList(); -// Set utilProjects = earEditModel.getModuleMappedUtilityJarProjects(); -// if (!utilProjects.isEmpty()) -// utilityProjects.addAll(utilProjects); -// return utilityProjects; -// } - - public static int getExistingServerTargetIndex(List validServerTargets, IProject project) { - if (validServerTargets != null) { - IRuntime st = ServerCore.getProjectProperties(project).getRuntimeTarget(); - if (st != null) { - for (int i = 0; i < validServerTargets.size(); i++) { - if (((IRuntime) validServerTargets.get(i)).getId() == st.getId()) - return i; - } - } - } - return -1; - } - - public static List getExistingNonServerTargetClasspath(IProject project) { - IJavaProject javaProject = null; - List list = new ArrayList(); - try { - javaProject = (IJavaProject) project.getNature(JavaCore.NATURE_ID); - } catch (Exception e) { - } - if (javaProject != null) { - try { - IClasspathEntry[] cp = javaProject.getRawClasspath(); - int size = cp.length; - for (int i = 0; i < size; i++) { - int entryKind = cp[i].getEntryKind(); - if (entryKind != IClasspathEntry.CPE_SOURCE && entryKind != IClasspathEntry.CPE_LIBRARY && entryKind != IClasspathEntry.CPE_PROJECT && (entryKind == IClasspathEntry.CPE_VARIABLE && isWASVariable(cp[i])) && (entryKind != IClasspathEntry.CPE_CONTAINER || !cp[i].getPath().segment(0).equals(SERVER_CONTAINER))) { - list.add(cp[i]); - } - } - } catch (Exception e) { - } - return list; - } - return list; - } - - /** - * @param entry - * @return - */ - private static boolean isWASVariable(IClasspathEntry entry) { - // TODO This is no longer valid in the base. - // IPath path = entry.getPath(); - // if (path != null && path.segmentCount() != 0) { - // String classpathVariable = path.segment(0); - // return - // classpathVariable.equals(IEJBNatureConstants.WAS_PLUGINDIR_VARIABLE) - // || - // classpathVariable.equals(IEJBNatureConstants.WAS_50_PLUGINDIR_VARIABLE) - // || - // classpathVariable.equals(IEJBNatureConstants.SERVERJDK_50_PLUGINDIR_VARIABLE) - // || - // classpathVariable.equals(IEJBNatureConstants.SERVERJDK_PLUGINDIR_VARIABLE) - // || classpathVariable.equals(J2EEPlugin.SOAP_PLUGINDIR_VARIABLE) - // || classpathVariable.equals(J2EEPlugin.SOAPSEC_PLUGINDIR_VARIABLE); - // //|| classpathVariable.equals(J2EEPlugin.XERCES_IMPL_VARIABLE) - // //|| classpathVariable.equals(J2EEPlugin.XERCES_PLUGINDIR_VARIABLE) - // //|| classpathVariable.equals(J2EEPlugin.WORF_PLUGINDIR_VARIABLE) - // //|| classpathVariable.equals(J2EEPlugin.MAIL_CLASSPATH_VARIABLE) - // //|| - // classpathVariable.equals(J2EEPlugin.ACTIVATION_CLASSPATH_VARIABLE); - // } - return false; - } - - /** - * @param earProject - * @param st - * @return - */ -// public static boolean serverTargetValidForEAR(IProject earProject, IRuntime st) { -// return !(J2EENature.hasRuntime(earProject, IEARNatureConstants.NATURE_ID) && st.getId().equals(IServerTargetConstants.aesV4ServerTargetId)); -// } - - public static List getServerTargets(String type, String version) { - List targets = Arrays.asList(ServerUtil.getRuntimes(type, version)); - return targets; - } - /* - * public static ITargetType getV50TargetType(IProject project, IServerTarget v50ServerTarget) { - * if (J2EENature.hasRuntime(project, IEARNatureConstants.NATURE_ID)) return - * ServerTargetManager.getTargetType(v50ServerTarget, IServerTargetConstants.EAR_TYPE); if - * (J2EENature.hasRuntime(project, IApplicationClientNatureConstants.NATURE_ID)) return - * ServerTargetManager.getTargetType(v50ServerTarget, IServerTargetConstants.EAR_TYPE); else if - * (J2EENature.hasRuntime(project, IEJBNatureConstants.NATURE_ID)) return - * ServerTargetManager.getTargetType(v50ServerTarget, IServerTargetConstants.EJB_TYPE); else if - * (J2EENature.hasRuntime(project, IWebNatureConstants.J2EE_NATURE_ID)) return - * ServerTargetManager.getTargetType(v50ServerTarget, IServerTargetConstants.WEB_TYPE); return - * null; } - */ -} diff --git a/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/internal/servertarget/TargetRuntimeExtension.java b/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/internal/servertarget/TargetRuntimeExtension.java deleted file mode 100644 index 26334b1d3..000000000 --- a/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/internal/servertarget/TargetRuntimeExtension.java +++ /dev/null @@ -1,62 +0,0 @@ -/******************************************************************************* - * 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 - *******************************************************************************/ -/* - * Created on Feb 5, 2004 - * - * To change the template for this generated file go to - * Window - Preferences - Java - Code Generation - Code and Comments - */ -package org.eclipse.jst.j2ee.internal.servertarget; - -import org.eclipse.core.runtime.IConfigurationElement; -import org.eclipse.core.runtime.Plugin; - -/** - * @author vijayb - * @deprecated - * To change the template for this generated type comment go to Window - Preferences - Java - Code - * Generation - Code and Comments - */ -public class TargetRuntimeExtension { - String groupID; - String className; - IConfigurationElement configElement; - Plugin plugin; - - /** - * - */ - public TargetRuntimeExtension() { - super(); - } - - public TargetRuntimeExtension(Plugin aPlugin, IConfigurationElement element, String groupId, String handlerClass) { - super(); - plugin = aPlugin; - configElement = element; - groupID = groupId; - className = handlerClass; - } - - /** - * @return - */ - public String getGroupId() { - return groupID; - } - - /** - * @param string - */ - public void setGroupId(String string) { - groupID = string; - } -} diff --git a/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/project/EJBUtilities.java b/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/project/EJBUtilities.java deleted file mode 100644 index c740c9f57..000000000 --- a/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/project/EJBUtilities.java +++ /dev/null @@ -1,145 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 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.project; - -import java.util.Properties; - -import org.eclipse.core.resources.IProject; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.Path; -import org.eclipse.jst.j2ee.internal.common.CreationConstants; -import org.eclipse.jst.j2ee.internal.componentcore.JavaEEBinaryComponentHelper; -import org.eclipse.jst.j2ee.model.ModelProviderManager; -import org.eclipse.jst.jee.archive.ArchiveModelLoadException; -import org.eclipse.jst.jee.archive.IArchive; -import org.eclipse.wst.common.componentcore.ComponentCore; -import org.eclipse.wst.common.componentcore.resources.IVirtualComponent; -import org.eclipse.wst.common.componentcore.resources.IVirtualReference; - -public class EJBUtilities extends JavaEEProjectUtilities { - - public EJBUtilities() { - // TODO Auto-generated constructor stub - } - - public static IVirtualComponent getEJBClientJar(IVirtualComponent ejbComponent){ - if(!ejbComponent.isBinary()){ - return getEJBClientJar(ejbComponent.getProject()); - } else { - if(ejbComponent.isBinary()){ - JavaEEBinaryComponentHelper helper = null; - try{ - helper = new JavaEEBinaryComponentHelper(ejbComponent); - IArchive archive = null; - try { - archive = helper.accessArchive(); - IPath ddPath = new Path("META-INF/ejb-jar.xml"); - if(archive.containsArchiveResource(ddPath)){ - Object jar = archive.getModelObject(ddPath); - String clientJAR = null; - if (jar != null) - { - if (jar instanceof org.eclipse.jst.j2ee.ejb.EJBJar) - { - clientJAR = ((org.eclipse.jst.j2ee.ejb.EJBJar)jar).getEjbClientJar(); - } - else if (jar instanceof org.eclipse.jst.javaee.ejb.EJBJar) - { - clientJAR = ((org.eclipse.jst.javaee.ejb.EJBJar)jar).getEjbClientJar(); - } - } - if (clientJAR != null) { - IVirtualComponent earComponent = ComponentCore.createComponent(ejbComponent.getProject()); - IVirtualReference[] refs = earComponent.getReferences(); - for (int i = 0; i < refs.length; i++) { - if (refs[i].getArchiveName().equals(clientJAR)) { - return refs[i].getReferencedComponent(); - } - } - } - } - } catch (ArchiveModelLoadException e) { - org.eclipse.jst.j2ee.internal.plugin.J2EEPlugin.logError(e); - } finally { - if(archive != null){ - helper.releaseArchive(archive); - } - } - } finally { - if(helper != null){ - helper.dispose(); - } - } - } - } - return null; - } - - - /** - * This method will return the IVirtualComponent of the EJBClientJar for a given EJB project - * @param project - * @return IVirtualComponent - */ - public static IVirtualComponent getEJBClientJar(IProject ejbProject) { - Object jar = ModelProviderManager.getModelProvider(ejbProject).getModelObject(); - IVirtualComponent ejbComponent, ejbClientComponent = null; - ejbComponent = ComponentCore.createComponent(ejbProject); - if (ejbComponent == null) - return null; - Properties props = ejbComponent.getMetaProperties(); - String clientCompName = props.getProperty(CreationConstants.EJB_CLIENT_NAME); - if (clientCompName != null && !clientCompName.equals("")) { //$NON-NLS-1$ - IVirtualReference vRef = ejbComponent.getReference(clientCompName); - if (vRef != null) - ejbClientComponent = vRef.getReferencedComponent(); - } else { - String clientJAR = null; - if (jar != null) - { - if (jar instanceof org.eclipse.jst.j2ee.ejb.EJBJar) - { - clientJAR = ((org.eclipse.jst.j2ee.ejb.EJBJar)jar).getEjbClientJar(); - } - else if (jar instanceof org.eclipse.jst.javaee.ejb.EJBJar) - { - clientJAR = ((org.eclipse.jst.javaee.ejb.EJBJar)jar).getEjbClientJar(); - } - } - if (clientJAR != null) { - clientJAR = clientJAR.substring(0, clientJAR.length() - 4); - ejbComponent = ComponentCore.createComponent(ejbProject); - if (ejbComponent == null) - return null; - IVirtualReference ref = ejbComponent.getReference(clientJAR); - if (ref != null) - ejbClientComponent = ref.getReferencedComponent(); - } - } - return ejbClientComponent; - } - - /** - * <p> - * Checks is a EJB Client Jar exists for the ejb module project - * </p> - * - * @return boolean - * - */ - - public static boolean hasEJBClientJARProject(IProject ejbProject) { - - if (getEJBClientJar(ejbProject) != null) - return true; - return false; - } -} diff --git a/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/project/EarUtilities.java b/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/project/EarUtilities.java deleted file mode 100644 index 67a6cb809..000000000 --- a/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/project/EarUtilities.java +++ /dev/null @@ -1,339 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 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.project; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.Iterator; -import java.util.List; - -import org.eclipse.core.resources.IProject; -import org.eclipse.jst.j2ee.application.Module; -import org.eclipse.jst.j2ee.internal.J2EEVersionConstants; -import org.eclipse.jst.j2ee.internal.common.J2EEVersionUtil; -import org.eclipse.jst.j2ee.internal.plugin.IJ2EEModuleConstants; -import org.eclipse.jst.j2ee.model.IEARModelProvider; -import org.eclipse.jst.j2ee.model.ModelProviderManager; -import org.eclipse.jst.j2ee.project.facet.IJ2EEFacetConstants; -import org.eclipse.jst.jee.application.ICommonApplication; -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.util.IModuleConstants; -import org.eclipse.wst.common.componentcore.resources.IVirtualComponent; -import org.eclipse.wst.common.componentcore.resources.IVirtualReference; -import org.eclipse.wst.common.project.facet.core.IProjectFacet; -import org.eclipse.wst.common.project.facet.core.IProjectFacetVersion; - -public class EarUtilities extends JavaEEProjectUtilities { - - public EarUtilities() { - // TODO Auto-generated constructor stub - } - - /** - * This method will return the an IVirtualComponent for the given module name. The method take - * either moduleName or moduleName + ".module_extension" (module_extension = ".jar" || ".war" || - * ".rar") which allows users to get a IVirtualComponent for a given entry in an application.xml - * - * @return - a IVirtualComponent for module name - */ - public static IVirtualComponent getModule(IVirtualComponent earComponent, String moduleName) { - if (moduleName == null) - return null; - if (moduleName.endsWith(IJ2EEModuleConstants.JAR_EXT) || moduleName.endsWith(IJ2EEModuleConstants.WAR_EXT) || moduleName.endsWith(IJ2EEModuleConstants.RAR_EXT)) - moduleName = moduleName.substring(0, (moduleName.length() - IJ2EEModuleConstants.JAR_EXT.length())); - IVirtualReference[] references = getComponentReferences(earComponent); - for (int i = 0; i < references.length; i++) { - IVirtualComponent component = references[i].getReferencedComponent(); - if (component.getName().equals(moduleName)) { - return component; - } - } - return null; - } - - /** - * This method will return the list of IVirtualReferences for the J2EE module components - * contained in this EAR application. - * - * @return - an array of IVirtualReferences for J2EE modules in the EAR - */ - public static IVirtualReference[] getJ2EEModuleReferences(IVirtualComponent earComponent) { - List j2eeTypes = new ArrayList(); - j2eeTypes.add(IJ2EEFacetConstants.APPLICATION_CLIENT); - j2eeTypes.add(IJ2EEFacetConstants.JCA); - j2eeTypes.add(IJ2EEFacetConstants.EJB); - j2eeTypes.add(IJ2EEFacetConstants.DYNAMIC_WEB); - return getComponentReferences(earComponent, j2eeTypes); - } - - /** - * This method will return the list of IVirtualReferences for all of the components contained in - * an EAR application. - * - * @return - an array of IVirtualReferences for components in the EAR - */ - public static IVirtualReference[] getComponentReferences(IVirtualComponent earComponent) { - return getComponentReferences(earComponent, Collections.EMPTY_LIST); - } - - /** - * This method will return the IVirtualReference to the component of the given name - * - * @return - IVirtualReference or null if not found - */ - public static IVirtualReference getComponentReference(IVirtualComponent earComponent, String componentName) { - IVirtualReference[] refs = getComponentReferences(earComponent, Collections.EMPTY_LIST); - for (int i = 0; i < refs.length; i++) { - IVirtualReference reference = refs[i]; - if (reference.getReferencedComponent().getName().equals(componentName)) - return reference; - - } - return null; - } - - private static IVirtualReference[] getComponentReferences(IVirtualComponent earComponent, List componentTypes) { - List components = getComponentReferencesAsList(earComponent, componentTypes); - if(components.size() > 0) - return (IVirtualReference[]) components.toArray(new IVirtualReference[components.size()]); - return NO_REFERENCES; - } - - /** - * - * @param componentTypes - * @return A List of {@link IVirtualReference}s. - * - * This method is copied from EARArtifactEdit. Any bug fixes should occur in both locations. - */ - private static List getComponentReferencesAsList(IVirtualComponent earComponent, List componentTypes) { - List components = new ArrayList(); - if (earComponent != null && isEARProject(earComponent.getProject())) { - IVirtualReference[] refComponents = earComponent.getReferences(); - for (int i = 0; i < refComponents.length; i++) { - IVirtualComponent module = refComponents[i].getReferencedComponent(); - if (module == null) - continue; - // if component types passed in is null then return all components - if (componentTypes == null || componentTypes.size() == 0) - components.add(refComponents[i]); - else { - if (componentTypes.contains(getJ2EEComponentType(module))) { - components.add(refComponents[i]); - } - } - } - } - return components; - } - - /** - * Checks if the uri mapping already exists. - * - * @param String - * currentURI - The current uri of the module. - * @return boolean - */ - public static boolean uriExists(String currentURI, IProject earProject) { - StructureEdit edit = null; - try { - edit = StructureEdit.getStructureEditForRead(earProject); - if (edit!=null && edit.getComponent()!=null) { - List referencedComps = edit.getComponent().getReferencedComponents(); - for (int i=0; i<referencedComps.size(); i++) { - ReferencedComponent ref = (ReferencedComponent) referencedComps.get(i); - Object module = ref.getDependentObject(); - if (module!=null && module instanceof Module) { - String existingURI = ((Module)module).getUri(); - if (existingURI!=null && existingURI.equals(currentURI)) - return true; - } - } - } - } finally { - if (edit != null) - edit.dispose(); - } - return false; - } - - /** - * Returns all referencing EAR projects. - * @param project Project to check. If null or an EAR, returns a zero length array. - * @return Array of referencing EAR projects. - */ - public static IProject[] getReferencingEARProjects(final IProject project) { - // TODO - should this go here, or in JavaEEProjectUtilities? - if(project != null && isEARProject(project)){ - return new IProject[] {project}; - } - - List result = new ArrayList(); - IVirtualComponent component = ComponentCore.createComponent(project); - if (component != null) { - IVirtualComponent[] refComponents = component.getReferencingComponents(); - for (int i = 0; i < refComponents.length; i++) { - if (isEARProject(refComponents[i].getProject())) - result.add(refComponents[i].getProject()); - } - } - return (IProject[]) result.toArray(new IProject[result.size()]); - } - - public static boolean isStandaloneProject(IProject project) { - return getReferencingEARProjects(project).length == 0; - } - - /** - * This method will return the list of IVirtualReferences for all of the utility modules - * contained in the EAR application - * - * @return - an array of IVirtualReferences for utility modules in the EAR - */ - public static IVirtualReference[] getUtilityModuleReferences(IVirtualComponent earComponent) { - if (earComponent != null && isEARProject(earComponent.getProject())) { - List explicitUtilityReferences = - getComponentReferencesAsList(earComponent, Collections.singletonList(IJ2EEFacetConstants.UTILITY)); - - // fetch other Utility Jars attached to the EAR project - List implicitUtilityReferenceTypes = - Arrays.asList(new String[] { IModuleConstants.JST_APPCLIENT_MODULE, - IModuleConstants.JST_WEB_MODULE, - IModuleConstants.JST_EJB_MODULE }); - - List implicitUtilityReferences = - getComponentReferencesAsList(earComponent, implicitUtilityReferenceTypes); - - IEARModelProvider earModel = (IEARModelProvider)ModelProviderManager.getModelProvider(earComponent.getProject()); - ICommonApplication application = (ICommonApplication)earModel.getModelObject(); - Object module = null; - IVirtualReference reference = null; - for (Iterator referenceItr = implicitUtilityReferences.iterator(); referenceItr.hasNext(); ) { - module = null; - reference = (IVirtualReference) referenceItr.next(); - if (application instanceof org.eclipse.jst.javaee.application.internal.impl.ApplicationImpl) - { - module = ((org.eclipse.jst.javaee.application.internal.impl.ApplicationImpl)application).getFirstModule(reference.getArchiveName()); - } - else if (application instanceof org.eclipse.jst.j2ee.application.internal.impl.ApplicationImpl) - { - module = ((org.eclipse.jst.j2ee.application.internal.impl.ApplicationImpl)application).getFirstModule(reference.getArchiveName()); - } - if(module != null) - referenceItr.remove(); - } - - List allUtilityModuleReferences = new ArrayList(); - allUtilityModuleReferences.addAll(explicitUtilityReferences); - allUtilityModuleReferences.addAll(implicitUtilityReferences); - - if(allUtilityModuleReferences.size() > 0) - return (IVirtualReference[]) allUtilityModuleReferences.toArray(new IVirtualReference[allUtilityModuleReferences.size()]); - } - return NO_REFERENCES; - - } - - /** - * Returns a List of ProjectFacetVersions for a given module type that are supported by a given ear version - * @param earProjectFacetVersion - the ProjectFacetVersion for the ENTERPRISE_APPLICATION that the module will be added to - * @param moduleProjectFacet - the module type whose appropriate ProjectFacetVersions are desired - * @return List of compatible ProjectFacetVersions of the moduleProjectFacet type - */ - public static List<IProjectFacetVersion> getSupportedFacets(IProjectFacetVersion earProjectFacetVersion, IProjectFacet moduleProjectFacet) - { - List<IProjectFacetVersion> retVal = new ArrayList<IProjectFacetVersion>(); - - if (earProjectFacetVersion != null && ENTERPRISE_APPLICATION.equals(earProjectFacetVersion.getProjectFacet().getId())) - { - String moduleProjectFacetId = moduleProjectFacet.getId(); - int earVersion = J2EEVersionUtil.convertVersionStringToInt(earProjectFacetVersion.getVersionString()); - - if (DYNAMIC_WEB.equals(moduleProjectFacetId)) - { - switch (earVersion) - { - case J2EEVersionConstants.VERSION_5_0: - retVal.add(DYNAMIC_WEB_25); - case J2EEVersionConstants.VERSION_1_4: - retVal.add(DYNAMIC_WEB_24); - case J2EEVersionConstants.VERSION_1_3: - retVal.add(DYNAMIC_WEB_23); - case J2EEVersionConstants.VERSION_1_2: - retVal.add(DYNAMIC_WEB_22); - } - } - else if (EJB.equals(moduleProjectFacetId)) - { - switch (earVersion) - { - case J2EEVersionConstants.VERSION_5_0: - retVal.add(EJB_30); - case J2EEVersionConstants.VERSION_1_4: - retVal.add(EJB_21); - case J2EEVersionConstants.VERSION_1_3: - retVal.add(EJB_20); - case J2EEVersionConstants.VERSION_1_2: - retVal.add(EJB_11); - } - } - else if (JCA.equals(moduleProjectFacetId)) - { - switch (earVersion) - { - case J2EEVersionConstants.VERSION_5_0: - case J2EEVersionConstants.VERSION_1_4: - retVal.add(JCA_15); - case J2EEVersionConstants.VERSION_1_3: - retVal.add(JCA_10); - case J2EEVersionConstants.VERSION_1_2: - // there is no JCA in EAR 1.2 - } - } - else if (APPLICATION_CLIENT.equals(moduleProjectFacetId)) - { - switch (earVersion) - { - case J2EEVersionConstants.VERSION_5_0: - retVal.add(APPLICATION_CLIENT_50); - case J2EEVersionConstants.VERSION_1_4: - retVal.add(APPLICATION_CLIENT_14); - case J2EEVersionConstants.VERSION_1_3: - retVal.add(APPLICATION_CLIENT_13); - case J2EEVersionConstants.VERSION_1_2: - retVal.add(APPLICATION_CLIENT_12); - } - } - else if (UTILITY.equals(moduleProjectFacetId)) - { - retVal.add(UTILITY_FACET_10); - } - else - { - // invalid module type - throw new IllegalArgumentException("The moduleProjectFacet parameter must be a valid Java EE module type."); - } - } - else - { - // invalid EAR facet - if (earProjectFacetVersion == null) - throw new IllegalArgumentException("The earProjectFacetVersion parameter cannot be null"); - else - throw new IllegalArgumentException("The earProjectFacetVersion parameter must be an ENTERPRISE_APPLICATION facet."); - } - - return retVal; - } -} diff --git a/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/project/JavaEEProjectUtilities.java b/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/project/JavaEEProjectUtilities.java deleted file mode 100644 index c3b2a82da..000000000 --- a/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/project/JavaEEProjectUtilities.java +++ /dev/null @@ -1,386 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 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.project; - -import java.io.IOException; -import java.io.InputStream; -import java.util.ArrayList; -import java.util.List; - -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.Path; -import org.eclipse.jem.util.emf.workbench.ProjectUtilities; -import org.eclipse.jem.util.logger.proxy.Logger; -import org.eclipse.jst.j2ee.internal.J2EEConstants; -import org.eclipse.jst.j2ee.internal.J2EEVersionConstants; -import org.eclipse.jst.j2ee.internal.common.J2EEVersionUtil; -import org.eclipse.jst.j2ee.internal.componentcore.JavaEEBinaryComponentHelper; -import org.eclipse.jst.j2ee.project.facet.IJ2EEFacetConstants; -import org.eclipse.jst.jee.util.internal.JavaEEQuickPeek; -import org.eclipse.wst.common.componentcore.ComponentCore; -import org.eclipse.wst.common.componentcore.resources.IVirtualComponent; -import org.eclipse.wst.common.componentcore.resources.IVirtualFile; -import org.eclipse.wst.common.componentcore.resources.IVirtualReference; -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.IProjectFacetVersion; -import org.eclipse.wst.common.project.facet.core.ProjectFacetsManager; - -public class JavaEEProjectUtilities extends ProjectUtilities implements IJ2EEFacetConstants { - protected static final IVirtualReference[] NO_REFERENCES = new IVirtualReference[0]; - - public JavaEEProjectUtilities() { - // TODO Auto-generated constructor stub - } - - public static boolean isProjectOfType(IProject project, String typeID) { - return getProjectFacetVersion(project, typeID) != null; - } - - public static IProjectFacetVersion getProjectFacetVersion(IProject project, String typeID){ - IFacetedProject facetedProject = null; - try { - facetedProject = ProjectFacetsManager.create(project); - } catch (CoreException e) { - return null; - } - - if (facetedProject != null && ProjectFacetsManager.isProjectFacetDefined(typeID)) { - IProjectFacet projectFacet = ProjectFacetsManager.getProjectFacet(typeID); - if(projectFacet == null){ - return null; - } - return facetedProject.getProjectFacetVersion(projectFacet); - } - return null; - } - - private static boolean isProjectOfType(IFacetedProject facetedProject, String typeID) { - - if (facetedProject != null && ProjectFacetsManager.isProjectFacetDefined(typeID)) { - IProjectFacet projectFacet = ProjectFacetsManager.getProjectFacet(typeID); - return projectFacet != null && facetedProject.hasProjectFacet(projectFacet); - } - return false; - } - - private static boolean isEARProject(IFacetedProject project) { - return isProjectOfType(project, ENTERPRISE_APPLICATION); - } - - private static boolean isDynamicWebProject(IFacetedProject project) { - return isProjectOfType(project, DYNAMIC_WEB); - } - - private static boolean isStaticWebProject(IFacetedProject project) { - return isProjectOfType(project, STATIC_WEB); - } - - private static boolean isEJBProject(IFacetedProject project) { - return isProjectOfType(project, EJB); - } - - private static boolean isJCAProject(IFacetedProject project) { - return isProjectOfType(project, JCA); - } - - private static boolean isApplicationClientProject(IFacetedProject project) { - return isProjectOfType(project, APPLICATION_CLIENT); - } - - private static boolean isUtilityProject(IFacetedProject project) { - return isProjectOfType(project, UTILITY); - } - - public static boolean isEARProject(IProject project) { - return isProjectOfType(project, ENTERPRISE_APPLICATION); - } - - public static boolean isDynamicWebComponent(IVirtualComponent component) { - if (component.isBinary()) { - return isBinaryType(component, JavaEEQuickPeek.WEB_TYPE); - } - return isProjectOfType(component.getProject(), DYNAMIC_WEB); - } - - public static boolean isDynamicWebProject(IProject project) { - return isProjectOfType(project, DYNAMIC_WEB); - } - - public static boolean isStaticWebProject(IProject project) { - return isProjectOfType(project, STATIC_WEB); - } - - public static boolean isEJBComponent(IVirtualComponent component) { - if (component.isBinary()) { - return isBinaryType(component, JavaEEQuickPeek.EJB_TYPE); - } - return isProjectOfType(component.getProject(), EJB); - } - - public static boolean isEJBProject(IProject project) { - return isProjectOfType(project, EJB); - } - - public static boolean isJCAComponent(IVirtualComponent component) { - if (component.isBinary()) { - return isBinaryType(component, JavaEEQuickPeek.CONNECTOR_TYPE); - } - return isProjectOfType(component.getProject(), JCA); - } - - public static boolean isJCAProject(IProject project) { - return isProjectOfType(project, JCA); - } - - public static boolean isApplicationClientComponent(IVirtualComponent component) { - if (component.isBinary()) { - return isBinaryType(component, JavaEEQuickPeek.APPLICATION_CLIENT_TYPE); - } - return isProjectOfType(component.getProject(), APPLICATION_CLIENT); - } - - public static boolean isApplicationClientProject(IProject project) { - return isProjectOfType(project, APPLICATION_CLIENT); - } - - public static boolean isUtilityProject(IProject project) { - return isProjectOfType(project, UTILITY); - } - - /** - * Return all projects in workspace of the specified type - * - * @param type - - * use one of the static strings on this class as a type - * @return IProject[] - */ - public static IProject[] getAllProjectsInWorkspaceOfType(String type) { - IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects(); - List result = new ArrayList(); - for (int i = 0; i < projects.length; i++) { - if (isProjectOfType(projects[i], type)) - result.add(projects[i]); - } - return (IProject[]) result.toArray(new IProject[result.size()]); - } - - private static boolean isBinaryType(IVirtualComponent aBinaryComponent, int quickPeekType){ - JavaEEQuickPeek qp = JavaEEBinaryComponentHelper.getJavaEEQuickPeek(aBinaryComponent); - int type = qp.getType(); - return quickPeekType == type; - } - - public static String getJ2EEComponentType(IVirtualComponent component) { - if (null != component) { - if (component.isBinary()) { - JavaEEQuickPeek qp = JavaEEBinaryComponentHelper.getJavaEEQuickPeek(component); - switch(qp.getType()){ - case JavaEEQuickPeek.APPLICATION_CLIENT_TYPE: - return APPLICATION_CLIENT; - case JavaEEQuickPeek.WEB_TYPE: - return DYNAMIC_WEB; - case JavaEEQuickPeek.EJB_TYPE: - return EJB; - case JavaEEQuickPeek.CONNECTOR_TYPE: - return JCA; - case JavaEEQuickPeek.APPLICATION_TYPE: - return ENTERPRISE_APPLICATION; - default: - return UTILITY; - } - } - return getJ2EEProjectType(component.getProject()); - } - return ""; //$NON-NLS-1$ - } - - public static String getJ2EEProjectType(IProject project) { - if (null != project && project.isAccessible()) { - IFacetedProject facetedProject = null; - try { - facetedProject = ProjectFacetsManager.create(project); - } catch (CoreException e) { - return ""; //$NON-NLS-1$ - } - if (isApplicationClientProject(facetedProject)) - return APPLICATION_CLIENT; - else if (isDynamicWebProject(facetedProject)) - return DYNAMIC_WEB; - else if (isEJBProject(facetedProject)) - return EJB; - else if (isEARProject(facetedProject)) - return ENTERPRISE_APPLICATION; - else if (isJCAProject(facetedProject)) - return JCA; - else if (isStaticWebProject(facetedProject)) - return STATIC_WEB; - else if (isUtilityProject(facetedProject)) - return UTILITY; - } - return ""; //$NON-NLS-1$ - } - /** - * Returns the J2EE Module version based on the DD XML file - * @param project - * @return version String - */ - public static String getJ2EEDDProjectVersion(IProject project) { - int type = J2EEVersionConstants.UNKNOWN; - String ddURI = null; - if (isEARProject(project)) { - type = J2EEVersionConstants.APPLICATION_TYPE; - ddURI = J2EEConstants.APPLICATION_DD_URI; - } else if (isEJBProject(project)) { - type = J2EEVersionConstants.EJB_TYPE; - ddURI = J2EEConstants.EJBJAR_DD_URI; - } else if (isApplicationClientProject(project)) { - type = J2EEVersionConstants.APPLICATION_CLIENT_TYPE; - ddURI = J2EEConstants.APP_CLIENT_DD_URI; - } else if (isJCAProject(project)) { - type = J2EEVersionConstants.CONNECTOR_TYPE; - ddURI = J2EEConstants.RAR_DD_URI; - } else if (isDynamicWebProject(project)) { - type = J2EEVersionConstants.WEB_TYPE; - ddURI = J2EEConstants.WEBAPP_DD_URI; - } - - if(type != J2EEVersionConstants.UNKNOWN){ - IVirtualComponent comp = ComponentCore.createComponent(project); - if (comp != null) { - IVirtualFile vFile = comp.getRootFolder().getFile(new Path(ddURI)); - if(vFile.exists()){ - InputStream in= null; - try{ - in = vFile.getUnderlyingFile().getContents(); - JavaEEQuickPeek quickPeek = new JavaEEQuickPeek(in); - int vers = (quickPeek.getVersion() == J2EEVersionConstants.UNKNOWN) ? getJEEVersion(project) : quickPeek.getVersion(); - return J2EEVersionUtil.convertVersionIntToString(vers); - } catch (CoreException e) { - Logger.getLogger().logError(e); - } finally { - if(in != null){ - try { - in.close(); - } catch (IOException e) { - Logger.getLogger().logError(e); - } - } - } - - } - else - return J2EEVersionUtil.convertVersionIntToString(getJEEVersion(project)); - } - } - - return null; - } - - - private static int getJEEVersion(IProject project) { - if (isEARProject(project) || isApplicationClientProject(project)) - return J2EEVersionConstants.VERSION_5_0; - if (isEJBProject(project)) - return J2EEVersionConstants.VERSION_3_0; - if (isDynamicWebProject(project)) - return J2EEVersionConstants.VERSION_2_5; - return J2EEVersionConstants.UNKNOWN; - - } - - public static int getJ2EEVersion(IProject javaEEProject) - { - int retVal = 0; - return retVal; - } - - /** - * Given a component returns whether the component has - * Java EE version greater than or equal to 5 - * - * @param component - * @return true if the component is Java EE version 5 or greater, false otherwise - */ - public static boolean isJEEComponent(IVirtualComponent component){ - if(component.isBinary()){ - JavaEEQuickPeek qp = JavaEEBinaryComponentHelper.getJavaEEQuickPeek(component); - int javaEEVersion = qp.getJavaEEVersion(); - return javaEEVersion >= J2EEConstants.JEE_5_0_ID; - } else { - IProject project = component.getProject(); - - IProjectFacetVersion facetVersion = getProjectFacetVersion(project, ENTERPRISE_APPLICATION); - if(facetVersion != null){ - if(facetVersion == IJ2EEFacetConstants.ENTERPRISE_APPLICATION_12 || - facetVersion == IJ2EEFacetConstants.ENTERPRISE_APPLICATION_13 || - facetVersion == IJ2EEFacetConstants.ENTERPRISE_APPLICATION_14){ - return false; - } - return true; - } - - facetVersion = getProjectFacetVersion(project, APPLICATION_CLIENT); - if(facetVersion != null){ - if(facetVersion == IJ2EEFacetConstants.APPLICATION_CLIENT_12 || - facetVersion == IJ2EEFacetConstants.APPLICATION_CLIENT_13 || - facetVersion == IJ2EEFacetConstants.APPLICATION_CLIENT_14){ - return false; - } - return true; - } - - facetVersion = getProjectFacetVersion(project, EJB); - if(facetVersion != null){ - if(facetVersion == IJ2EEFacetConstants.EJB_11 || - facetVersion == IJ2EEFacetConstants.EJB_20 || - facetVersion == IJ2EEFacetConstants.EJB_21){ - return false; - } - return true; - } - - facetVersion = getProjectFacetVersion(project, DYNAMIC_WEB); - if(facetVersion != null){ - if(facetVersion == IJ2EEFacetConstants.DYNAMIC_WEB_22 || - facetVersion == IJ2EEFacetConstants.DYNAMIC_WEB_23 || - facetVersion == IJ2EEFacetConstants.DYNAMIC_WEB_24){ - return false; - } - return true; - } - - facetVersion = getProjectFacetVersion(project, JCA); - if(facetVersion != null){ - if(facetVersion == IJ2EEFacetConstants.JCA_10 || - facetVersion == IJ2EEFacetConstants.JCA_15 ){ - return false; - } - return true; - } - - return false; - } - } - - /** - * Given a component returns whether the component has Java EE version less than 5 - * - * @param component - * @return true if the component is less then Java EE version 5, false otherwise - */ - public static boolean isLegacyJ2EEComponent(IVirtualComponent component){ - return !isJEEComponent(component); - } - -} diff --git a/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/project/WebUtilities.java b/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/project/WebUtilities.java deleted file mode 100644 index b3b6e25fd..000000000 --- a/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/project/WebUtilities.java +++ /dev/null @@ -1,113 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 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.project; - -import java.util.ArrayList; -import java.util.List; - -import org.eclipse.core.resources.IProject; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.Path; -import org.eclipse.jst.j2ee.componentcore.J2EEModuleVirtualComponent; -import org.eclipse.jst.j2ee.internal.J2EEVersionConstants; -import org.eclipse.jst.j2ee.internal.common.XMLResource; -import org.eclipse.jst.j2ee.model.ModelProviderManager; -import org.eclipse.jst.javaee.web.WebApp; -import org.eclipse.jst.javaee.web.WebAppVersionType; -import org.eclipse.wst.common.componentcore.ComponentCore; -import org.eclipse.wst.common.componentcore.resources.IVirtualComponent; -import org.eclipse.wst.common.componentcore.resources.IVirtualReference; - -public class WebUtilities extends JavaEEProjectUtilities { - public static IPath WEBLIB = new Path("/WEB-INF/lib"); //$NON-NLS-1$ - - public WebUtilities() { - // TODO Auto-generated constructor stub - } - - /** - * <p> - * Retrieves Servlet version information derived from the {@see WebAppResource}. - * </p> - * - * @return an integer representation of a module version - * - */ - public static int getServletVersion(IProject webProject) { - int retVal = 0; - Object webAppResource = ModelProviderManager.getModelProvider(webProject).getModelObject(); - if (webAppResource instanceof XMLResource) - { - retVal = ((XMLResource)webAppResource).getModuleVersionID(); - } - else if (webAppResource instanceof WebApp) - { - switch (((WebApp)webAppResource).getVersion().getValue()) { - case WebAppVersionType._25: - retVal = J2EEVersionConstants.WEB_2_5_ID; - break; - } - } - - return retVal; - } - - /** - * This method returns the integer representation for the JSP specification level associated - * with the J2EE version for this workbench module. This method will not return null and returns - * 20 as default. - * - * @return an integer representation of the JSP level - */ - public static int getJSPVersion(IProject webProject) { - int servletVersion = getServletVersion(webProject); - if (servletVersion == J2EEVersionConstants.WEB_2_2_ID) - return J2EEVersionConstants.JSP_1_1_ID; - else if (servletVersion == J2EEVersionConstants.WEB_2_3_ID) - return J2EEVersionConstants.JSP_1_2_ID; - else - return J2EEVersionConstants.JSP_2_0_ID; - } - - /** - * This method will return the list of dependent modules which are utility jars in the web lib - * folder of the deployed path of the module. It will not return null. - * - * @return array of the web library dependent modules - */ - public static IVirtualReference[] getLibModules(IVirtualComponent webComponent){ - List result = new ArrayList(); - IVirtualReference[] refComponents = null; - if (!webComponent.isBinary()) - refComponents = ((J2EEModuleVirtualComponent)webComponent).getNonManifestReferences(); - else - refComponents = webComponent.getReferences(); - // Check the deployed path to make sure it has a lib parent folder and matchs the web.xml - // base path - for (int i = 0; i < refComponents.length; i++) { - if (refComponents[i].getRuntimePath().equals(WEBLIB)) - result.add(refComponents[i]); - } - - return (IVirtualReference[]) result.toArray(new IVirtualReference[result.size()]); - } - - /** - * This method will return the list of dependent modules which are utility jars in the web lib - * folder of the deployed path of the module. It will not return null. - * - * @return array of the web library dependent modules - */ - public static IVirtualReference[] getLibModules(IProject webProject) { - IVirtualComponent webComponent = ComponentCore.createComponent(webProject); - return getLibModules(webComponent); - } -} diff --git a/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/project/datamodel/properties/IJ2EEProjectServerTargetDataModelProperties.java b/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/project/datamodel/properties/IJ2EEProjectServerTargetDataModelProperties.java deleted file mode 100644 index 735a26fa9..000000000 --- a/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/project/datamodel/properties/IJ2EEProjectServerTargetDataModelProperties.java +++ /dev/null @@ -1,50 +0,0 @@ -/******************************************************************************* - * Copyright (c) 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.project.datamodel.properties; - -import org.eclipse.wst.common.frameworks.datamodel.IDataModelProperties; - -public interface IJ2EEProjectServerTargetDataModelProperties extends IDataModelProperties{ - - /** - * required, type String - */ - public static final String PROJECT_NAME = "IJ2EEProjectServerTargetDataModelProperties.PROJECT_NAME"; //$NON-NLS-1$ - /** - * required, not defaulted. If null, will not run. - */ - public static final String RUNTIME_TARGET_ID = "IJ2EEProjectServerTargetDataModelProperties.RUNTIME_TARGET_ID"; //$NON-NLS-1$ - /** - * Optional - This needs to be set if the PROJECT_NAME does not exist. - * - * @link J2EEVersionConstants - */ - public static final String J2EE_VERSION_ID = "IJ2EEProjectServerTargetDataModelProperties.J2EE_VERSION_ID"; //$NON-NLS-1$ - - /** - * optional, default true, type Boolean. Set this to true if the operation is supposed to update - * all dependent modules and projects in an ear if the passed project name is an ear project - */ - public static final String UPDATE_MODULES = "IJ2EEProjectServerTargetDataModelProperties.UPDATE_MODULES"; //$NON-NLS-1$ - - /** - * Optional - This needs to be set if the PROJECT_NAME does not exist. - * - * @link XMLResource#APP_CLIENT_TYPE - * @link XMLResource#APPLICATION_TYPE - * @link XMLResource#EJB_TYPE - * @link XMLResource#RAR_TYPE - * @link XMLResource#WEB_APP_TYPE - */ - public static final String DEPLOYMENT_TYPE_ID = "IJ2EEProjectServerTargetDataModelProperties.DD_TYPE_ID"; //$NON-NLS-1$ - - -} diff --git a/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/project/facet/IJ2EEFacetConstants.java b/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/project/facet/IJ2EEFacetConstants.java deleted file mode 100644 index 2e0e949b6..000000000 --- a/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/project/facet/IJ2EEFacetConstants.java +++ /dev/null @@ -1,63 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 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.project.facet; - -import org.eclipse.wst.common.componentcore.internal.util.IModuleConstants; -import org.eclipse.wst.common.project.facet.core.IProjectFacet; -import org.eclipse.wst.common.project.facet.core.IProjectFacetVersion; -import org.eclipse.wst.common.project.facet.core.ProjectFacetsManager; - -public interface IJ2EEFacetConstants { - - //moduleTypes - public static final String ENTERPRISE_APPLICATION = IModuleConstants.JST_EAR_MODULE; - public static final IProjectFacet ENTERPRISE_APPLICATION_FACET = ProjectFacetsManager.getProjectFacet(ENTERPRISE_APPLICATION); - public static final IProjectFacetVersion ENTERPRISE_APPLICATION_12 = ENTERPRISE_APPLICATION_FACET.getVersion("1.2"); //$NON-NLS-1$ - public static final IProjectFacetVersion ENTERPRISE_APPLICATION_13 = ENTERPRISE_APPLICATION_FACET.getVersion("1.3"); //$NON-NLS-1$ - public static final IProjectFacetVersion ENTERPRISE_APPLICATION_14 = ENTERPRISE_APPLICATION_FACET.getVersion("1.4"); //$NON-NLS-1$ - public static final IProjectFacetVersion ENTERPRISE_APPLICATION_50 = ENTERPRISE_APPLICATION_FACET.getVersion("5.0"); //$NON-NLS-1$ - - public static final String APPLICATION_CLIENT = IModuleConstants.JST_APPCLIENT_MODULE; - public static final IProjectFacet APPLICATION_CLIENT_FACET = ProjectFacetsManager.getProjectFacet(APPLICATION_CLIENT); - public static final IProjectFacetVersion APPLICATION_CLIENT_12 = APPLICATION_CLIENT_FACET.getVersion("1.2"); //$NON-NLS-1$ - public static final IProjectFacetVersion APPLICATION_CLIENT_13 = APPLICATION_CLIENT_FACET.getVersion("1.3"); //$NON-NLS-1$ - public static final IProjectFacetVersion APPLICATION_CLIENT_14 = APPLICATION_CLIENT_FACET.getVersion("1.4"); //$NON-NLS-1$ - public static final IProjectFacetVersion APPLICATION_CLIENT_50 = APPLICATION_CLIENT_FACET.getVersion("5.0"); //$NON-NLS-1$ - - public static final String EJB = IModuleConstants.JST_EJB_MODULE; - public static final IProjectFacet EJB_FACET = ProjectFacetsManager.getProjectFacet(EJB); - public static final IProjectFacetVersion EJB_11 = EJB_FACET.getVersion("1.1"); //$NON-NLS-1$ - public static final IProjectFacetVersion EJB_20 = EJB_FACET.getVersion("2.0"); //$NON-NLS-1$ - public static final IProjectFacetVersion EJB_21 = EJB_FACET.getVersion("2.1"); //$NON-NLS-1$ - public static final IProjectFacetVersion EJB_30 = EJB_FACET.getVersion("3.0"); //$NON-NLS-1$ - - public static final String DYNAMIC_WEB = IModuleConstants.JST_WEB_MODULE; - public static final IProjectFacet DYNAMIC_WEB_FACET = ProjectFacetsManager.getProjectFacet(DYNAMIC_WEB); - public static final IProjectFacetVersion DYNAMIC_WEB_22 = DYNAMIC_WEB_FACET.getVersion("2.2"); //$NON-NLS-1$ - public static final IProjectFacetVersion DYNAMIC_WEB_23 = DYNAMIC_WEB_FACET.getVersion("2.3"); //$NON-NLS-1$ - public static final IProjectFacetVersion DYNAMIC_WEB_24 = DYNAMIC_WEB_FACET.getVersion("2.4"); //$NON-NLS-1$ - public static final IProjectFacetVersion DYNAMIC_WEB_25 = DYNAMIC_WEB_FACET.getVersion("2.5"); //$NON-NLS-1$ - - public static final String DYNAMIC_WEB_XDOCLET = "jst.web.xdoclet"; //$NON-NLS-1$ - - public static final String UTILITY = IModuleConstants.JST_UTILITY_MODULE; - public static final IProjectFacet UTILITY_FACET = ProjectFacetsManager.getProjectFacet(UTILITY); - public static final IProjectFacetVersion UTILITY_FACET_10 = UTILITY_FACET.getVersion("1.0"); //$NON-NLS-1$ - - public static final String JCA = IModuleConstants.JST_CONNECTOR_MODULE; - public static final IProjectFacet JCA_FACET = ProjectFacetsManager.getProjectFacet(JCA); - public static final IProjectFacetVersion JCA_10 = JCA_FACET.getVersion("1.0"); //$NON-NLS-1$ - public static final IProjectFacetVersion JCA_15 = JCA_FACET.getVersion("1.5"); //$NON-NLS-1$ - - public static final String STATIC_WEB = IModuleConstants.WST_WEB_MODULE; - - public static final String JAVA = IModuleConstants.JST_JAVA; -} diff --git a/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/project/facet/IJ2EEFacetInstallDataModelProperties.java b/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/project/facet/IJ2EEFacetInstallDataModelProperties.java deleted file mode 100644 index d4db236c2..000000000 --- a/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/project/facet/IJ2EEFacetInstallDataModelProperties.java +++ /dev/null @@ -1,29 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2003, 2007 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.project.facet; - -import org.eclipse.wst.common.componentcore.datamodel.properties.IFacetInstallDataModelProperties; -import org.eclipse.wst.common.componentcore.datamodel.properties.IFacetProjectCreationDataModelProperties; - -public interface IJ2EEFacetInstallDataModelProperties extends IFacetInstallDataModelProperties, IJ2EEFacetConstants { - - //TODO this property should probably be deleted - public static final String RUNTIME_TARGET_ID = "IJ2EEFacetInstallDataModelProperties.RUNTIME_TARGET_ID"; //$NON-NLS-1$ - - public static final String FACET_RUNTIME = IFacetProjectCreationDataModelProperties.FACET_RUNTIME; - - /** - * boolean property for Java EE 5 projects, to create/not create a deployment descriptor, - * The default value is false - */ - public static final String GENERATE_DD = "IJ2EEFacetInstallDataModelProperties.GENERATE_DD"; //$NON-NLS-1$ - -} diff --git a/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/project/facet/IJ2EEFacetProjectCreationDataModelProperties.java b/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/project/facet/IJ2EEFacetProjectCreationDataModelProperties.java deleted file mode 100644 index 9ab7ec1d0..000000000 --- a/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/project/facet/IJ2EEFacetProjectCreationDataModelProperties.java +++ /dev/null @@ -1,23 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2006 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.project.facet; - - -import org.eclipse.wst.common.componentcore.datamodel.properties.IFacetProjectCreationDataModelProperties; - -public interface IJ2EEFacetProjectCreationDataModelProperties - extends IFacetProjectCreationDataModelProperties{ - - public static final String ADD_TO_EAR = "IJ2EEFacetProjectCreationDataModelProperties.ADD_TO_EAR"; //$NON-NLS-1$ - public static final String EAR_PROJECT_NAME = "IJ2EEFacetProjectCreationDataModelProperties.EAR_PROJECT_NAME"; //$NON-NLS-1$ - public static final String MODULE_URI = "IJ2EEFacetProjectCreationDataModelProperties.MODULE_URI"; //$NON-NLS-1$ - -} diff --git a/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/project/facet/IJ2EEModuleFacetInstallDataModelProperties.java b/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/project/facet/IJ2EEModuleFacetInstallDataModelProperties.java deleted file mode 100644 index 97adec782..000000000 --- a/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/project/facet/IJ2EEModuleFacetInstallDataModelProperties.java +++ /dev/null @@ -1,20 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2006 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.project.facet; - -public interface IJ2EEModuleFacetInstallDataModelProperties extends IJ2EEFacetInstallDataModelProperties{ - - public static final String ADD_TO_EAR = "IJ2EEFacetInstallDataModelProperties.ADD_TO_EAR"; //$NON-NLS-1$ - public static final String EAR_PROJECT_NAME = "IJ2EEFacetInstallDataModelProperties.EAR_PROJECT_NAME"; //$NON-NLS-1$ - public static final String CONFIG_FOLDER = "IJ2EEFacetInstallDataModelProperties.CONFIG_FOLDER"; //$NON-NLS-1$ - public static final String LAST_EAR_NAME = "IJ2EEModuleFacetInstallDataModelProperties.LAST_EAR_NAME"; //$NON-NLS-1$ - public static final String MODULE_URI = "IJ2EEModuleFacetInstallDataModelProperties.MODULE_URI"; //$NON-NLS-1$ -} diff --git a/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/project/facet/J2EEFacetInstallDataModelProvider.java b/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/project/facet/J2EEFacetInstallDataModelProvider.java deleted file mode 100644 index ddda96da1..000000000 --- a/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/project/facet/J2EEFacetInstallDataModelProvider.java +++ /dev/null @@ -1,59 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2003, 2007 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.project.facet; - -import java.util.Set; - -import org.eclipse.core.resources.IResource; -import org.eclipse.core.resources.IWorkspace; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Path; -import org.eclipse.wst.common.componentcore.datamodel.FacetInstallDataModelProvider; -import org.eclipse.wst.common.project.facet.core.IProjectFacetVersion; - -public abstract class J2EEFacetInstallDataModelProvider extends FacetInstallDataModelProvider implements IJ2EEFacetInstallDataModelProperties{ - - public Set getPropertyNames() { - Set names = super.getPropertyNames(); - names.add(RUNTIME_TARGET_ID); - names.add(FACET_RUNTIME); - // added for jee projects that make deployment descriptors optional - names.add(GENERATE_DD); - return names; - } - - protected final int getJ2EEVersion() { - return convertFacetVersionToJ2EEVersion((IProjectFacetVersion) getProperty(FACET_VERSION)); - } - - protected abstract int convertFacetVersionToJ2EEVersion(IProjectFacetVersion version); - - protected IStatus validateFolderName(String folderName) { - // the directory is not required, but if the name is entered ensure that it - // contains only valid characters. - if (folderName == null || folderName.length() == 0) { - return OK_STATUS; - } - IWorkspace workspace = ResourcesPlugin.getWorkspace(); - IPath path = new Path(folderName); - for (int i = 0, max = path.segmentCount(); i < max; i++) { - IStatus status = workspace.validateName(path.segment(i), IResource.FOLDER); - if (! status.isOK()) - return status; - } - - // all of the potential segments of the folder have been verified - return OK_STATUS; - } - -} diff --git a/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/project/facet/J2EEFacetInstallDelegate.java b/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/project/facet/J2EEFacetInstallDelegate.java deleted file mode 100644 index 61e0cc335..000000000 --- a/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/project/facet/J2EEFacetInstallDelegate.java +++ /dev/null @@ -1,215 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2003, 2007 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.project.facet; - -import java.io.IOException; -import java.lang.reflect.InvocationTargetException; -import java.util.Collections; -import java.util.List; -import java.util.Map; - -import org.eclipse.core.commands.ExecutionException; -import org.eclipse.core.resources.IContainer; -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.Path; -import org.eclipse.jdt.core.IClasspathEntry; -import org.eclipse.jdt.core.IJavaProject; -import org.eclipse.jem.util.UIContextDetermination; -import org.eclipse.jem.util.emf.workbench.ProjectUtilities; -import org.eclipse.jem.util.logger.proxy.Logger; -import org.eclipse.jst.common.frameworks.CommonFrameworksPlugin; -import org.eclipse.jst.j2ee.application.internal.operations.AddComponentToEnterpriseApplicationDataModelProvider; -import org.eclipse.jst.j2ee.application.internal.operations.IAddComponentToEnterpriseApplicationDataModelProperties; -import org.eclipse.jst.j2ee.internal.J2EEConstants; -import org.eclipse.jst.j2ee.internal.project.ManifestFileCreationAction; -import org.eclipse.wst.common.componentcore.ComponentCore; -import org.eclipse.wst.common.componentcore.datamodel.properties.ICreateReferenceComponentsDataModelProperties; -import org.eclipse.wst.common.componentcore.resources.IVirtualComponent; -import org.eclipse.wst.common.frameworks.datamodel.DataModelFactory; -import org.eclipse.wst.common.frameworks.datamodel.IDataModel; -import org.eclipse.wst.common.internal.emf.resource.RendererFactory; -import org.eclipse.wst.common.project.facet.core.FacetedProjectFramework; -import org.eclipse.wst.common.project.facet.core.IFacetedProjectWorkingCopy; -import org.eclipse.wst.common.project.facet.core.IProjectFacetVersion; -import org.eclipse.wst.common.project.facet.core.runtime.IRuntime; -import org.eclipse.wst.common.project.facet.core.runtime.IRuntimeComponent; -import org.eclipse.wst.project.facet.ProductManager; -import org.eclipse.wst.web.internal.facet.RuntimePresetMappingRegistry; - -public abstract class J2EEFacetInstallDelegate { - - protected static void addToClasspath(final IJavaProject jproj, final IClasspathEntry entry) throws CoreException { - final IClasspathEntry[] current = jproj.getRawClasspath(); - final IClasspathEntry[] updated = new IClasspathEntry[current.length + 1]; - System.arraycopy(current, 0, updated, 0, current.length); - updated[current.length] = entry; - jproj.setRawClasspath(updated, null); - } - - protected void installEARFacet( final String j2eeVersionText, - final String earProjectName, - final IRuntime runtime, - final IProgressMonitor monitor ) - { - IProject project = ProjectUtilities.getProject(earProjectName); - if( project.exists()) - return; - - final IFacetedProjectWorkingCopy fpjwc = FacetedProjectFramework.createNewProject(); - - fpjwc.setProjectName( earProjectName ); - - if( runtime != null ) - { - fpjwc.setTargetedRuntimes( Collections.singleton( runtime ) ); - } - - fpjwc.setFixedProjectFacets( Collections.singleton( EARFacetUtils.EAR_FACET ) ); - fpjwc.setSelectedPreset( FacetedProjectFramework.DEFAULT_CONFIGURATION_PRESET_ID ); - - if( j2eeVersionText != null ) - { - final IProjectFacetVersion defaultEarFacetVersion - = fpjwc.getProjectFacetVersion( EARFacetUtils.EAR_FACET ); - - if( ! defaultEarFacetVersion.getVersionString().equals( j2eeVersionText ) ) - { - String presetId = null; - - if( runtime != null ) - { - for( IRuntimeComponent rc : runtime.getRuntimeComponents() ) - { - presetId = RuntimePresetMappingRegistry.INSTANCE.getPresetID - ( - rc.getRuntimeComponentType().getId(), - rc.getRuntimeComponentVersion().getVersionString(), - EARFacetUtils.EAR_FACET.getId(), - j2eeVersionText - ); - - if( presetId != null ) - { - break; - } - } - } - - final IProjectFacetVersion earFacetVersion - = EARFacetUtils.EAR_FACET.getVersion( j2eeVersionText ); - - // Note that the next call is necessary even if a preset is going to be selected - // later since it allows the dynamic preset to adjust for the ear facet version. - - fpjwc.setProjectFacets( Collections.singleton( earFacetVersion ) ); - - if( presetId != null ) - { - fpjwc.setSelectedPreset( presetId ); - } - } - } - - try - { - fpjwc.commitChanges( null ); - } - catch( CoreException e ) - { - Logger.getLogger().logError( e ); - } - } - - protected void createManifest(IProject project, IContainer aFolder, IProgressMonitor monitor) throws CoreException, InvocationTargetException, InterruptedException { - - IFile file = aFolder.getFile(new Path(J2EEConstants.MANIFEST_URI)); - if (file.exists()) return; - try { - ManifestFileCreationAction.createManifestFile(file, project); - } catch (CoreException e) { - Logger.getLogger().log(e); - } catch (IOException e) { - Logger.getLogger().log(e); - } - } - - protected void addToEar(IVirtualComponent earComp, IVirtualComponent j2eeComp, String moduleURI ){ - final IDataModel dataModel = DataModelFactory.createDataModel(new AddComponentToEnterpriseApplicationDataModelProvider()); - Map map = (Map)dataModel.getProperty(IAddComponentToEnterpriseApplicationDataModelProperties.TARGET_COMPONENTS_TO_URI_MAP); - map.put(j2eeComp, moduleURI); - - dataModel.setProperty(ICreateReferenceComponentsDataModelProperties.SOURCE_COMPONENT, earComp); - - List modList = (List) dataModel.getProperty(ICreateReferenceComponentsDataModelProperties.TARGET_COMPONENT_LIST); - modList.add(j2eeComp); - dataModel.setProperty(ICreateReferenceComponentsDataModelProperties.TARGET_COMPONENT_LIST, modList); - try { - dataModel.getDefaultOperation().execute(null, null); - } catch (ExecutionException e) { - Logger.getLogger().logError(e); - } - } - - protected void installAndAddModuletoEAR( String j2eeVersionText, - String earProjectName, - IRuntime runtime, - IProject moduleProject, - String moduleURI, - IProgressMonitor monitor ){ - - installEARFacet(j2eeVersionText, - earProjectName, - runtime, - monitor); - - final IVirtualComponent c = ComponentCore.createComponent( moduleProject ); - final IProject earProject = ProjectUtilities.getProject( earProjectName ); - final IVirtualComponent earComp = ComponentCore.createComponent( earProject ); - - if( UIContextDetermination.getCurrentContext() == UIContextDetermination.HEADLESS_CONTEXT ){ - boolean isValidating = RendererFactory.getDefaultRendererFactory().isValidating(); - try{ - if( isValidating ){ - RendererFactory.getDefaultRendererFactory().setValidating(false); - } - addToEar( earComp, c, moduleURI ); - }finally{ - RendererFactory.getDefaultRendererFactory().setValidating(isValidating); - } - } - else - addToEar( earComp, c, moduleURI ); - } - - /** - * This method will set the output property on the model element for the given component. - * If the single root structure is set for optimized use, the output folder will be the - * content root. Otherwise the default will be used. This may be overrided by specific - * J2EE modules to do more appropriate behaviour. - * - * @param model - * @param component - */ - protected void setOutputFolder(IDataModel model, IVirtualComponent component) { - String outputFolder = null; - // If using single root structure, set output folder to be the content folder - if (ProductManager.shouldUseSingleRootStructure()) - outputFolder = model.getStringProperty(IJ2EEModuleFacetInstallDataModelProperties.CONFIG_FOLDER); - // Otherwise just use the product default for java output path - else - outputFolder = CommonFrameworksPlugin.getDefault().getPluginPreferences().getString(CommonFrameworksPlugin.OUTPUT_FOLDER); - component.setMetaProperty("java-output-path", outputFolder ); //$NON-NLS-1$ - } - -} diff --git a/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/project/facet/J2EEFacetProjectCreationDataModelProvider.java b/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/project/facet/J2EEFacetProjectCreationDataModelProvider.java deleted file mode 100644 index 071e0607e..000000000 --- a/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/project/facet/J2EEFacetProjectCreationDataModelProvider.java +++ /dev/null @@ -1,209 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2007 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.project.facet; - -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.jem.util.emf.workbench.ProjectUtilities; -import org.eclipse.wst.common.componentcore.datamodel.FacetProjectCreationDataModelProvider; -import org.eclipse.wst.common.componentcore.datamodel.properties.IFacetProjectCreationDataModelProperties; -import org.eclipse.wst.common.frameworks.datamodel.DataModelPropertyDescriptor; -import org.eclipse.wst.common.frameworks.datamodel.IDataModel; -import org.eclipse.wst.common.frameworks.internal.operations.ProjectCreationDataModelProviderNew; -import org.eclipse.wst.common.frameworks.internal.plugin.WTPCommonMessages; -import org.eclipse.wst.common.frameworks.internal.plugin.WTPCommonPlugin; -import org.eclipse.wst.common.project.facet.core.IFacetedProject; -import org.eclipse.wst.common.project.facet.core.IFacetedProjectWorkingCopy; -import org.eclipse.wst.common.project.facet.core.IProjectFacet; -import org.eclipse.wst.common.project.facet.core.IProjectFacetVersion; -import org.eclipse.wst.common.project.facet.core.ProjectFacetsManager; -import org.eclipse.wst.common.project.facet.core.runtime.IRuntime; - -public class J2EEFacetProjectCreationDataModelProvider extends FacetProjectCreationDataModelProvider implements IJ2EEFacetProjectCreationDataModelProperties { - - private static Set<IProjectFacet> MODULE_FACETS = new HashSet<IProjectFacet>(); - - static - { - for( IProjectFacetVersion fv : ProjectFacetsManager.getGroup( "modules" ).getMembers() ) - { - MODULE_FACETS.add( fv.getProjectFacet() ); - } - } - - public J2EEFacetProjectCreationDataModelProvider() { - super(); - } - - public void init() { - super.init(); - } - - public Object getDefaultProperty(String propertyName) { - if (EAR_PROJECT_NAME.equals(propertyName)) { - IDataModel nestedJ2EEFacetDataModel = getJ2EEFacetModel(); - if (nestedJ2EEFacetDataModel!=null) - return nestedJ2EEFacetDataModel.getProperty(IJ2EEModuleFacetInstallDataModelProperties.EAR_PROJECT_NAME); - } - return super.getDefaultProperty(propertyName); - } - - public Set getPropertyNames() { - Set names = super.getPropertyNames(); - names.add(EAR_PROJECT_NAME); - names.add(ADD_TO_EAR); - names.add(MODULE_URI); - return names; - } - - public DataModelPropertyDescriptor[] getValidPropertyDescriptors(String propertyName) { - if (FACET_RUNTIME.equals(propertyName) && getBooleanProperty(ADD_TO_EAR)) { - DataModelPropertyDescriptor[] descriptors = super.getValidPropertyDescriptors(propertyName); - List list = new ArrayList(); - for (int i = 0; i < descriptors.length; i++) { - IRuntime rt = (IRuntime) descriptors[i].getPropertyValue(); - if (rt == null || rt.supports(EARFacetUtils.EAR_FACET)) { - list.add(descriptors[i]); - } - } - descriptors = new DataModelPropertyDescriptor[list.size()]; - for (int i = 0; i < descriptors.length; i++) { - descriptors[i] = (DataModelPropertyDescriptor) list.get(i); - } - return descriptors; - } - return super.getValidPropertyDescriptors(propertyName); - } - - public boolean propertySet(String propertyName, Object propertyValue) { - if (EAR_PROJECT_NAME.equals(propertyName) || ADD_TO_EAR.equals(propertyName)) { - IDataModel nestedJ2EEFacetDataModel = getJ2EEFacetModel(); - if(null != nestedJ2EEFacetDataModel){ - if(EAR_PROJECT_NAME.equals(propertyName)){ - nestedJ2EEFacetDataModel.setProperty(IJ2EEModuleFacetInstallDataModelProperties.EAR_PROJECT_NAME, propertyValue); - } else { - nestedJ2EEFacetDataModel.setProperty(IJ2EEModuleFacetInstallDataModelProperties.ADD_TO_EAR, propertyValue); - } - - } - if (getBooleanProperty(ADD_TO_EAR)) { - IStatus status = validateEAR(model.getStringProperty(EAR_PROJECT_NAME)); - if (status.isOK()) { - IProject earProject = ProjectUtilities.getProject(getStringProperty(EAR_PROJECT_NAME)); - if (earProject != null) { - IFacetedProject facetdEarProject; - try { - facetdEarProject = ProjectFacetsManager.create(earProject); - if (facetdEarProject != null) { - setProperty(FACET_RUNTIME, facetdEarProject.getRuntime()); - } - } catch (CoreException e) { - e.printStackTrace(); - } - } - } - } - if (ADD_TO_EAR.equals(propertyName)) { - model.notifyPropertyChange(FACET_RUNTIME, IDataModel.VALID_VALUES_CHG); - } - model.notifyPropertyChange(FACET_RUNTIME, IDataModel.ENABLE_CHG); - } - return super.propertySet(propertyName, propertyValue); - } - - protected IDataModel getJ2EEFacetModel() - { - final IFacetedProjectWorkingCopy fpjwc - = (IFacetedProjectWorkingCopy) this.model.getProperty( FACETED_PROJECT_WORKING_COPY ); - - for( IProjectFacet moduleFacet : MODULE_FACETS ) - { - if( fpjwc.hasProjectFacet( moduleFacet ) ) - { - final IFacetedProject.Action action = fpjwc.getProjectFacetAction( moduleFacet ); - return (IDataModel) action.getConfig(); - } - } - - return null; - } - - public boolean isPropertyEnabled(String propertyName) { - if (FACET_RUNTIME.equals(propertyName)) { - if (getBooleanProperty(ADD_TO_EAR)) { - IStatus status = validateEAR(model.getStringProperty(EAR_PROJECT_NAME)); - if (status.isOK()) { - IProject earProject = ProjectUtilities.getProject(getStringProperty(EAR_PROJECT_NAME)); - if (earProject != null) { - IFacetedProject facetdEarProject; - try { - facetdEarProject = ProjectFacetsManager.create(earProject); - if (facetdEarProject != null) { - return false; - } - } catch (CoreException e) { - e.printStackTrace(); - } - } - } - } - return true; - } - return super.isPropertyEnabled(propertyName); - } - - public IStatus validate(String propertyName) { - if (ADD_TO_EAR.equals(propertyName) || EAR_PROJECT_NAME.equals(propertyName) || FACET_PROJECT_NAME.equals(propertyName)) { - if (model.getBooleanProperty(ADD_TO_EAR)) { - IStatus status = validateEAR(model.getStringProperty(EAR_PROJECT_NAME)); - if (!status.isOK()) - return status; - if (getStringProperty(IFacetProjectCreationDataModelProperties.FACET_PROJECT_NAME).equals(getStringProperty(EAR_PROJECT_NAME))) { - String errorMessage = WTPCommonPlugin.getResourceString(WTPCommonMessages.SAME_MODULE_AND_EAR_NAME, new Object[]{getStringProperty(EAR_PROJECT_NAME)}); - return WTPCommonPlugin.createErrorStatus(errorMessage); - } - } - } - return super.validate(propertyName); - } - - protected IStatus validateEAR(String earName) { - if (earName.indexOf("#") != -1 || earName.indexOf("/") != -1) { //$NON-NLS-1$ //$NON-NLS-2$ - String errorMessage = WTPCommonPlugin.getResourceString(WTPCommonMessages.ERR_INVALID_CHARS); - return WTPCommonPlugin.createErrorStatus(errorMessage); - } else if (earName == null || earName.equals("")) { //$NON-NLS-1$ - String errorMessage = WTPCommonPlugin.getResourceString(WTPCommonMessages.ERR_EMPTY_MODULE_NAME); - return WTPCommonPlugin.createErrorStatus(errorMessage); - } - - IStatus status = ProjectCreationDataModelProviderNew.validateProjectName(earName); - //check for the deleted case, the project is deleted from the workspace but still exists in the - //file system. - if( status.isOK()){ - IProject earProject = ProjectUtilities.getProject(getStringProperty(EAR_PROJECT_NAME)); - if( !earProject.exists() ){ - IPath path = ResourcesPlugin.getWorkspace().getRoot().getLocation(); - path = path.append(earName); - status = ProjectCreationDataModelProviderNew.validateExisting(earName, path.toOSString()); - } - } - return status; - } - -} diff --git a/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/project/facet/J2EEFacetRuntimeChangedDelegate.java b/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/project/facet/J2EEFacetRuntimeChangedDelegate.java deleted file mode 100644 index a58fbe941..000000000 --- a/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/project/facet/J2EEFacetRuntimeChangedDelegate.java +++ /dev/null @@ -1,67 +0,0 @@ -/****************************************************************************** - * Copyright (c) 2005 BEA Systems, Inc. - * 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: - * Konstantin Komissarchik - initial API and implementation - ******************************************************************************/ - -package org.eclipse.jst.j2ee.project.facet; - -import org.eclipse.core.resources.IProject; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.jst.common.project.facet.core.ClasspathHelper; -import org.eclipse.wst.common.project.facet.core.IDelegate; -import org.eclipse.wst.common.project.facet.core.IProjectFacetVersion; - -/** - * @author <a href="mailto:kosta@bea.com">Konstantin Komissarchik</a> - */ - -public final class J2EEFacetRuntimeChangedDelegate - - implements IDelegate - -{ - public void execute( final IProject project, - final IProjectFacetVersion fv, - final Object cfg, - final IProgressMonitor monitor ) - - throws CoreException - - { - if( monitor != null ) - { - monitor.beginTask( "", 1 ); - } - - try - { - ClasspathHelper.removeClasspathEntries( project, fv ); - - if( ! ClasspathHelper.addClasspathEntries( project, fv ) ) - { - // TODO: Support the no runtime case. - // ClasspathHelper.addClasspathEntries( project, fv, <something> ); - } - - if( monitor != null ) - { - monitor.worked( 1 ); - } - } - finally - { - if( monitor != null ) - { - monitor.done(); - } - } - } - -} diff --git a/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/project/facet/J2EEModuleFacetInstallDataModelProvider.java b/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/project/facet/J2EEModuleFacetInstallDataModelProvider.java deleted file mode 100644 index 24c4a43f4..000000000 --- a/plugins/org.eclipse.jst.j2ee/j2eecreation/org/eclipse/jst/j2ee/project/facet/J2EEModuleFacetInstallDataModelProvider.java +++ /dev/null @@ -1,259 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2003, 2007 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.project.facet; - -import java.util.ArrayList; -import java.util.Set; - -import org.eclipse.core.internal.resources.ResourceStatus; -import org.eclipse.core.internal.utils.Messages; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IResourceStatus; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.NullProgressMonitor; -import org.eclipse.jem.util.emf.workbench.ProjectUtilities; -import org.eclipse.jem.util.logger.proxy.Logger; -import org.eclipse.jst.common.project.facet.IJavaFacetInstallDataModelProperties; -import org.eclipse.jst.j2ee.internal.common.J2EEVersionUtil; -import org.eclipse.jst.j2ee.internal.plugin.J2EEPlugin; -import org.eclipse.jst.j2ee.internal.plugin.J2EEPreferences; -import org.eclipse.jst.j2ee.internal.project.J2EEProjectUtilities; -import org.eclipse.osgi.util.NLS; -import org.eclipse.wst.common.componentcore.ComponentCore; -import org.eclipse.wst.common.componentcore.ModuleCoreNature; -import org.eclipse.wst.common.componentcore.datamodel.properties.IFacetProjectCreationDataModelProperties; -import org.eclipse.wst.common.componentcore.datamodel.properties.IFacetProjectCreationDataModelProperties.FacetDataModelMap; -import org.eclipse.wst.common.componentcore.internal.StructureEdit; -import org.eclipse.wst.common.componentcore.resources.IVirtualComponent; -import org.eclipse.wst.common.frameworks.datamodel.DataModelPropertyDescriptor; -import org.eclipse.wst.common.frameworks.datamodel.IDataModel; -import org.eclipse.wst.common.frameworks.internal.operations.ProjectCreationDataModelProviderNew; -import org.eclipse.wst.common.frameworks.internal.plugin.WTPCommonMessages; -import org.eclipse.wst.common.frameworks.internal.plugin.WTPCommonPlugin; -import org.eclipse.wst.common.project.facet.core.IFacetedProject; -import org.eclipse.wst.common.project.facet.core.IFacetedProjectWorkingCopy; -import org.eclipse.wst.common.project.facet.core.ProjectFacetsManager; -import org.eclipse.wst.common.project.facet.core.runtime.IRuntime; -import org.eclipse.wst.project.facet.ProductManager; - -public abstract class J2EEModuleFacetInstallDataModelProvider extends J2EEFacetInstallDataModelProvider implements IJ2EEModuleFacetInstallDataModelProperties { - - /** - * An internal Boolean property used to prohibit adding this module to an EAR. This is set on - * the nested models when used during EAR creation since EAR creation handles adding to the EAR - */ - public static final String PROHIBIT_ADD_TO_EAR = "J2EEModuleFacetInstallDataModelProvider.PROHIBIT_ADD_TO_EAR"; //$NON-NLS-1$ - - public Set getPropertyNames() { - Set names = super.getPropertyNames(); - names.add(ADD_TO_EAR); - names.add(PROHIBIT_ADD_TO_EAR); - names.add(CONFIG_FOLDER); - names.add(EAR_PROJECT_NAME); - names.add(LAST_EAR_NAME); - names.add(MODULE_URI); - // added for jee modules that make deployment descriptors optional - names.add(IJ2EEFacetInstallDataModelProperties.GENERATE_DD); - return names; - } - - public Object getDefaultProperty(String propertyName) { - if (propertyName.equals(PROHIBIT_ADD_TO_EAR)) { - return Boolean.FALSE; - } else if (propertyName.equals(ADD_TO_EAR)) { - return new Boolean( J2EEPlugin.getDefault().getJ2EEPreferences().getBoolean(J2EEPreferences.Keys.ADD_TO_EAR_BY_DEFAULT) && isEARSupportedByRuntime()); - } else if (propertyName.equals(EAR_PROJECT_NAME)) { - if (model.isPropertySet(LAST_EAR_NAME)) { - IProject project = ProjectUtilities.getProject(getStringProperty(LAST_EAR_NAME)); - if (project.exists() && project.isAccessible()) - return project.getName(); - } - DataModelPropertyDescriptor[] descs = getValidPropertyDescriptors(EAR_PROJECT_NAME); - if (descs.length > 0) { - DataModelPropertyDescriptor desc = descs[0]; - String eARName = desc.getPropertyDescription(); - if (eARName != null && !eARName.equals("")) { //$NON-NLS-1$ - return eARName; - } else { - return getDataModel().getStringProperty(FACET_PROJECT_NAME) + "EAR"; //$NON-NLS-1$ - } - } else { - return getDataModel().getStringProperty(FACET_PROJECT_NAME) + "EAR"; //$NON-NLS-1$ - } - } - return super.getDefaultProperty(propertyName); - } - - public boolean propertySet(String propertyName, Object propertyValue) { - if (propertyName.equals(PROHIBIT_ADD_TO_EAR)) { - setBooleanProperty(ADD_TO_EAR, false); - } - if (FACET_PROJECT_NAME.equals(propertyName)) { - if (getBooleanProperty(ADD_TO_EAR)) { - if (!model.isPropertySet(EAR_PROJECT_NAME)) { - model.notifyPropertyChange(EAR_PROJECT_NAME, IDataModel.DEFAULT_CHG); - } - } - } else if (FACET_VERSION.equals(propertyName)) { - model.notifyPropertyChange(EAR_PROJECT_NAME, IDataModel.VALID_VALUES_CHG); - } else if (propertyName.equals(CONFIG_FOLDER)) { - IDataModel masterModel = (IDataModel) model.getProperty(MASTER_PROJECT_DM); - if (masterModel != null) { - FacetDataModelMap map = (FacetDataModelMap) masterModel.getProperty(IFacetProjectCreationDataModelProperties.FACET_DM_MAP); - IDataModel javaModel = map.getFacetDataModel(JAVA); - if (javaModel != null) { - javaModel.setProperty(IJavaFacetInstallDataModelProperties.SOURCE_FOLDER_NAME, propertyValue); - // If applicable, react to the change in content folder to update the output folder for single root structures - if (ProductManager.shouldUseSingleRootStructure()) - javaModel.setProperty(IJavaFacetInstallDataModelProperties.DEFAULT_OUTPUT_FOLDER_NAME,propertyValue); - } - } - } else if ((EAR_PROJECT_NAME.equals(propertyName) || ADD_TO_EAR.equals(propertyName) || LAST_EAR_NAME.equals(propertyName)) && getBooleanProperty(ADD_TO_EAR)) { - IStatus status = validateEAR(model.getStringProperty(EAR_PROJECT_NAME)); - if (status.isOK()) { - IProject project = ProjectUtilities.getProject(getStringProperty(EAR_PROJECT_NAME)); - if (project.exists() && project.isAccessible() && J2EEProjectUtilities.isEARProject(project)) { - try { - IFacetedProject facetProj = ProjectFacetsManager.create(project, false, new NullProgressMonitor()); - setProperty(FACET_RUNTIME, facetProj.getRuntime()); - } catch (CoreException e) { - Logger.getLogger().logError(e); - } - } - } - model.notifyPropertyChange(FACET_RUNTIME, IDataModel.ENABLE_CHG); - } else if (propertyName.equals(IFacetProjectCreationDataModelProperties.FACET_RUNTIME)) { - model.notifyPropertyChange(ADD_TO_EAR, IDataModel.VALID_VALUES_CHG); - model.notifyPropertyChange(EAR_PROJECT_NAME, IDataModel.VALID_VALUES_CHG); - } - - if (ADD_TO_EAR.equals(propertyName)) { - IStatus stat = model.validateProperty(propertyName); - if (stat != OK_STATUS) { - return true; - } - model.notifyPropertyChange(EAR_PROJECT_NAME, IDataModel.VALID_VALUES_CHG); - } - - return super.propertySet(propertyName, propertyValue); - } - - public boolean isPropertyEnabled(String propertyName) { - if (ADD_TO_EAR.equals(propertyName)) { - return !getBooleanProperty(PROHIBIT_ADD_TO_EAR) && isEARSupportedByRuntime(); - } - if (EAR_PROJECT_NAME.equals(propertyName)) { - return !getBooleanProperty(PROHIBIT_ADD_TO_EAR) && isEARSupportedByRuntime() && getBooleanProperty(ADD_TO_EAR); - } - return super.isPropertyEnabled(propertyName); - } - - public DataModelPropertyDescriptor[] getValidPropertyDescriptors(String propertyName) { - if (EAR_PROJECT_NAME.equals(propertyName)) { - int j2eeVersion = getJ2EEVersion(); - return getEARPropertyDescriptors(j2eeVersion); - } - return super.getValidPropertyDescriptors(propertyName); - } - - protected DataModelPropertyDescriptor[] getEARPropertyDescriptors(int j2eeVersion) { - StructureEdit mc = null; - ArrayList earDescriptorList = new ArrayList(); - - IProject[] projs = ProjectUtilities.getAllProjects(); - - for (int index = 0; index < projs.length; index++) { - IProject flexProject = projs[index]; - try { - if (flexProject != null) { - if (ModuleCoreNature.isFlexibleProject(flexProject)) { - IVirtualComponent comp = ComponentCore.createComponent(flexProject); - if (J2EEProjectUtilities.isEARProject(comp.getProject())) { - String sVer = J2EEProjectUtilities.getJ2EEProjectVersion(comp.getProject()); - int ver = J2EEVersionUtil.convertVersionStringToInt(sVer); - if (j2eeVersion <= ver) { - DataModelPropertyDescriptor desc = new DataModelPropertyDescriptor(comp.getProject().getName()); - earDescriptorList.add(desc); - } - } - } - } - } finally { - if (mc != null) - mc.dispose(); - } - } - DataModelPropertyDescriptor[] descriptors = new DataModelPropertyDescriptor[earDescriptorList.size()]; - for (int i = 0; i < descriptors.length; i++) { - DataModelPropertyDescriptor desc = (DataModelPropertyDescriptor) earDescriptorList.get(i); - descriptors[i] = new DataModelPropertyDescriptor(desc.getPropertyDescription(), desc.getPropertyDescription()); - } - return descriptors; - } - - public IStatus validate(String name) { - if (name.equals(EAR_PROJECT_NAME) && getBooleanProperty(ADD_TO_EAR)) { - IStatus status = validateEAR(getStringProperty(EAR_PROJECT_NAME)); - if (!status.isOK()) - return status; - final IFacetedProjectWorkingCopy fpjwc = (IFacetedProjectWorkingCopy) getProperty(FACETED_PROJECT_WORKING_COPY); - String fpjwcName = fpjwc.getProjectName(); - if(fpjwcName != null && fpjwcName.equals(getStringProperty(EAR_PROJECT_NAME))){ - String errorMessage = WTPCommonPlugin.getResourceString(WTPCommonMessages.SAME_MODULE_AND_EAR_NAME, new Object [] {getStringProperty(EAR_PROJECT_NAME) }); - return WTPCommonPlugin.createErrorStatus(errorMessage); - } - } else if (name.equals(CONFIG_FOLDER)) { - String folderName = model.getStringProperty(CONFIG_FOLDER); - if (folderName == null || folderName.length() == 0 || folderName.equals("/") || folderName.equals("\\")) { - // all folders which meet the criteria of "CONFIG_FOLDER" are required - String errorMessage = WTPCommonPlugin.getResourceString(WTPCommonMessages.SOURCEFOLDER_EMPTY); - return WTPCommonPlugin.createErrorStatus(errorMessage); - } else { - IStatus status = validateFolderName(folderName); - if (status.isOK()) - { - /* bug 223072 test invalid character - URI.FRAGMENT_SEPARATOR */ - if (folderName.indexOf('#') != -1) { //$NON-NLS-1$ - String message = NLS.bind(Messages.resources_invalidCharInName, "#", folderName); //$NON-NLS-1$ - status = new ResourceStatus(IResourceStatus.INVALID_VALUE, null, message); - } - } - return status; - } - } else if (name.equals(ADD_TO_EAR)) { - if (!isEARSupportedByRuntime()) { - String errorMessage = WTPCommonPlugin.getResourceString(WTPCommonMessages.MODULE_NOT_SUPPORTED); - return WTPCommonPlugin.createErrorStatus(errorMessage); - } - } - return super.validate(name); - } - - protected IStatus validateEAR(String earName) { - if (earName == null || earName.equals("")) { //$NON-NLS-1$ - String errorMessage = WTPCommonPlugin.getResourceString(WTPCommonMessages.ERR_EMPTY_MODULE_NAME); - return WTPCommonPlugin.createErrorStatus(errorMessage); - } else if (earName.indexOf("#") != -1 || earName.indexOf("/") != -1) { //$NON-NLS-1$ //$NON-NLS-2$ - String errorMessage = WTPCommonPlugin.getResourceString(WTPCommonMessages.ERR_INVALID_CHARS); - return WTPCommonPlugin.createErrorStatus(errorMessage); - } - return (ProjectCreationDataModelProviderNew.validateProjectName(earName)); - } - - private boolean isEARSupportedByRuntime() { - boolean ret = true; - IRuntime rt = (IRuntime) model.getProperty(IFacetProjectCreationDataModelProperties.FACET_RUNTIME); - if (rt != null) - ret = rt.supports(EARFacetUtils.EAR_FACET); - return ret; - } -} |