diff options
Diffstat (limited to 'plugins/org.eclipse.jst.j2ee/refactor/org')
30 files changed, 0 insertions, 2859 deletions
diff --git a/plugins/org.eclipse.jst.j2ee/refactor/org/eclipse/jst/j2ee/refactor/ProjectDependencyCache.java b/plugins/org.eclipse.jst.j2ee/refactor/org/eclipse/jst/j2ee/refactor/ProjectDependencyCache.java deleted file mode 100644 index 08abac355..000000000 --- a/plugins/org.eclipse.jst.j2ee/refactor/org/eclipse/jst/j2ee/refactor/ProjectDependencyCache.java +++ /dev/null @@ -1,150 +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: - * rfrost@bea.com - initial API and implementation - *******************************************************************************/ - -package org.eclipse.jst.j2ee.refactor; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; - -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.jst.j2ee.internal.plugin.J2EEPlugin; - -/** - * Maintains a cache of project dependencies as represented by references in the .project file. - * - * XXX DependencyManagerGraph is being used instead now that inter-project dependencies have - * dependent-module entries, however, this type of dependency representation might be useful if - * we want to capture dependencies on projects not represented in the .component file. - */ -public class ProjectDependencyCache { - - private static ProjectDependencyCache cache; - - public synchronized static ProjectDependencyCache getCache() { - if (cache == null) { - try { - cache = new ProjectDependencyCache(); - } catch (CoreException ce) { - J2EEPlugin.logError(ce); - } - } - return cache; - } - - /* - * Map from target IProject to List of dependent IProjects - */ - private final Map dependencyCache = new HashMap(); - - /* - * Map from dependent IProject to List of target IProject - */ - private final Map referenceCache = new HashMap(); - - /** - * Creates and initializes the cache. - */ - protected ProjectDependencyCache() throws CoreException { - final IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects(); - for (int i = 0; i < projects.length; i++) { - refreshDependencies(projects[i]); - } - } - - public synchronized IProject[] getDependentProjects(final IProject project) { - List dependencies = (List) dependencyCache.get(project); - if (dependencies == null) { - return new IProject[0]; - } - return (IProject[]) dependencies.toArray(new IProject[dependencies.size()]); - } - - public synchronized void refreshDependencies(final IProject project) throws CoreException { - List oldRefs = (List) referenceCache.get(project); - if (oldRefs == null) { - oldRefs = new ArrayList(); - } - final IProject[] refProjects = project.getDescription().getReferencedProjects(); - final List newRefs = new ArrayList(); - for (int j = 0; j < refProjects.length; j++) { - addDependency(refProjects[j], project); - newRefs.add(refProjects[j]); - oldRefs.remove(refProjects[j]); - } - referenceCache.put(project, newRefs); - - // need to cull the stale refs from the reverse map - Iterator i = oldRefs.iterator(); - while (i.hasNext()) { - removeDependency((IProject) i.next(), project); - } - } - - public synchronized void refreshDependenciesForTarget(final IProject target) throws CoreException { - final IProject[] dependents= getDependentProjects(target); - for (int i = 0; i < dependents.length; i++) { - refreshDependencies(dependents[i]); - } - } - - public synchronized void removeProject(final IProject project) throws CoreException { - // remove from the dependency cache - dependencyCache.remove(project); - // remove from the reference cache and clear the from the cache of all dependent projects - List dependencies = (List) referenceCache.remove(project); - if (dependencies != null) { - final Iterator i = dependencies.iterator(); - while (i.hasNext()) { - removeDependency((IProject) i.next(), project); - } - } - } - - public synchronized void replaceProject(final IProject originalProject, final IProject newProject) throws CoreException { - // rename dependencyCache entry - dependencyCache.put(newProject, dependencyCache.remove(originalProject)); - - // rename reference cache and clear the from the cache of all dependent projects - List dependencies = (List) referenceCache.remove(originalProject); - referenceCache.put(newProject, dependencies); - if (dependencies != null) { - final Iterator i = dependencies.iterator(); - while (i.hasNext()) { - final IProject ref = (IProject) i.next(); - removeDependency(ref, originalProject); - addDependency(ref, newProject); - } - } - } - - private void removeDependency(final IProject target, final IProject dependent) { - List dependentProjects = (List) dependencyCache.get(target); - if (dependentProjects != null) { - dependentProjects.remove(dependent); - } - } - - private void addDependency(final IProject target, final IProject dependent) { - List dependentProjects = (List) dependencyCache.get(target); - if (dependentProjects == null) { - dependentProjects = new ArrayList(); - dependencyCache.put(target, dependentProjects); - } - if (!dependentProjects.contains(dependent)) { - dependentProjects.add(dependent); - } - } -} diff --git a/plugins/org.eclipse.jst.j2ee/refactor/org/eclipse/jst/j2ee/refactor/RefactorResourceHandler.java b/plugins/org.eclipse.jst.j2ee/refactor/org/eclipse/jst/j2ee/refactor/RefactorResourceHandler.java deleted file mode 100644 index ba04f3ac1..000000000 --- a/plugins/org.eclipse.jst.j2ee/refactor/org/eclipse/jst/j2ee/refactor/RefactorResourceHandler.java +++ /dev/null @@ -1,67 +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.refactor; - -import java.text.MessageFormat; -import java.util.MissingResourceException; -import java.util.ResourceBundle; - -/** - * Supports access to resource strings. - */ -public class RefactorResourceHandler { - - private static ResourceBundle fgResourceBundle; - - /** - * Returns the resource bundle used by all classes in this Project - */ - public static ResourceBundle getResourceBundle() { - try { - return ResourceBundle.getBundle("refactor");//$NON-NLS-1$ - } catch (MissingResourceException e) { - // does nothing - this method will return null and - // getString(String, String) will return the key - // it was called with - } - return null; - } - - public static String getString(String key) { - if (fgResourceBundle == null) { - fgResourceBundle = getResourceBundle(); - } - - if (fgResourceBundle != null) { - try { - return fgResourceBundle.getString(key); - } catch (MissingResourceException e) { - return "!" + key + "!";//$NON-NLS-2$//$NON-NLS-1$ - } - } - return "!" + key + "!";//$NON-NLS-2$//$NON-NLS-1$ - } - - public static String getString(String key, Object[] args) { - - try { - return MessageFormat.format(getString(key), args); - } catch (IllegalArgumentException e) { - return getString(key); - } - - } - - public static void nlsConcatenationFinder() { - // used to tag methods which have concatenated strings - } - -} diff --git a/plugins/org.eclipse.jst.j2ee/refactor/org/eclipse/jst/j2ee/refactor/listeners/J2EEElementChangedListener.java b/plugins/org.eclipse.jst.j2ee/refactor/org/eclipse/jst/j2ee/refactor/listeners/J2EEElementChangedListener.java deleted file mode 100644 index 87d42449c..000000000 --- a/plugins/org.eclipse.jst.j2ee/refactor/org/eclipse/jst/j2ee/refactor/listeners/J2EEElementChangedListener.java +++ /dev/null @@ -1,338 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005, 2007 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: - * rfrost@bea.com - initial API and implementation - *******************************************************************************/ -package org.eclipse.jst.j2ee.refactor.listeners; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; - -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IResourceDelta; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.resources.WorkspaceJob; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Path; -import org.eclipse.core.runtime.Status; -import org.eclipse.jdt.core.ElementChangedEvent; -import org.eclipse.jdt.core.IElementChangedListener; -import org.eclipse.jdt.core.IJavaElement; -import org.eclipse.jdt.core.IJavaElementDelta; -import org.eclipse.jdt.core.IJavaModel; -import org.eclipse.jdt.core.IJavaProject; -import org.eclipse.jdt.core.IPackageFragmentRoot; -import org.eclipse.jdt.core.JavaModelException; -import org.eclipse.jst.j2ee.internal.J2EEConstants; -import org.eclipse.jst.j2ee.internal.plugin.J2EEPlugin; -import org.eclipse.jst.j2ee.internal.project.J2EEProjectUtilities; -import org.eclipse.wst.common.componentcore.ComponentCore; -import org.eclipse.wst.common.componentcore.ModuleCoreNature; -import org.eclipse.wst.common.componentcore.internal.ComponentResource; -import org.eclipse.wst.common.componentcore.internal.StructureEdit; -import org.eclipse.wst.common.componentcore.internal.WorkbenchComponent; -import org.eclipse.wst.common.componentcore.resources.IVirtualComponent; -import org.eclipse.wst.common.componentcore.resources.IVirtualFolder; - -/** - * Implementation of <code>IElementChangedListener that updates mappings for src folders - * in the .component file in response to changes in a project's Java classpath. - */ -public class J2EEElementChangedListener implements IElementChangedListener { - - /** - * Name of the Job family in which all component update jobs belong. - */ - public static final String PROJECT_COMPONENT_UPDATE_JOB_FAMILY = "org.eclipse.jst.j2ee.refactor.component"; //$NON-NLS-1$ - - - /* (non-Javadoc) - * @see org.eclipse.jdt.core.IElementChangedListener#elementChanged(org.eclipse.jdt.core.ElementChangedEvent) - */ - public void elementChanged(final ElementChangedEvent event) { - processJavaElementDelta(event.getDelta()); - } - - private void processJavaElementDelta(final IJavaElementDelta delta) { - final int kind = delta.getKind(); - if (kind == IJavaElementDelta.CHANGED) { - final int flags = delta.getFlags(); - final IJavaElement element = delta.getElement(); - if (element instanceof IJavaModel) { - if ((flags & IJavaElementDelta.F_CHILDREN) == IJavaElementDelta.F_CHILDREN) { - final IJavaElementDelta[] children = delta.getChangedChildren(); - for (int i = 0; i < children.length; i++) { - // handle all of the IJavaProject children - processJavaElementDelta(children[i]); - } - } else { - // not a Java project (i.e. could be an EAR project) - processResourceDeltas(flags, kind, delta); - } - } else if (element instanceof IJavaProject) { - processJavaProject((IJavaProject) element, flags, kind, delta); - } - } - } - - private void processJavaProject(final IJavaProject jproject, final int flags, final int kind, final IJavaElementDelta delta) { - - final IProject project = jproject.getProject(); - final List pathsToAdd = new ArrayList(); - final List pathsToRemove = new ArrayList(); - final List changedJavaPaths = new ArrayList(); - - // make certain this is a J2EE project - if (ModuleCoreNature.isFlexibleProject(project)) { - IVirtualComponent c = ComponentCore.createComponent(project); - if(c == null) - return; - try { - // Did the classpath change? - if ((flags & IJavaElementDelta.F_CHILDREN) == IJavaElementDelta.F_CHILDREN) { - final boolean cpChanged = (flags & IJavaElementDelta.F_CLASSPATH_CHANGED) != 0; - getJavaSrcMappings(c, delta.getAffectedChildren(), cpChanged, jproject, pathsToAdd, pathsToRemove, changedJavaPaths); - } - - // Did a non-Java folder change name? - final IResourceDelta[] deltas = delta.getResourceDeltas(); - if (deltas != null && deltas.length > 0) { - getNonJavaFolderMappings(deltas, c, pathsToAdd, pathsToRemove, changedJavaPaths); - } - - } catch (CoreException ce) { - J2EEPlugin.logError(ce); - return; - } - updateMappingsInJob(pathsToAdd, pathsToRemove); - } - } - - private void processResourceDeltas(final int flags, final int kind, final IJavaElementDelta delta) { - final List pathsToAdd = new ArrayList(); - final List pathsToRemove = new ArrayList(); - - final IResourceDelta[] deltas = delta.getResourceDeltas(); - if (deltas != null && deltas.length > 0) { - try { - getNonJavaFolderMappings(deltas, null, pathsToAdd, pathsToRemove, Collections.EMPTY_LIST); - } catch (CoreException ce) { - J2EEPlugin.logError(ce); - return; - } - } - - updateMappingsInJob(pathsToAdd, pathsToRemove); - } - - /* - * Adds and removes the specified component resource mappings in a WorkspaceJob - */ - private void updateMappingsInJob(final List pathsToAdd, final List pathsToRemove) { - // If there are corrections to the virtual path mappings, execute them in a Job - if (!pathsToAdd.isEmpty() || !pathsToRemove.isEmpty()) { - WorkspaceJob job = new WorkspaceJob(RefactorMessages.J2EEElementChangedListener_J2EE_Component_Mapping_Update_) { - @Override - public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException { - for(int i=0;i<pathsToAdd.size(); i++){ - Object[] toAdd = (Object[]) pathsToAdd.get(i); - final IVirtualFolder destFolder = (IVirtualFolder) toAdd[1]; - final IPath pathToAdd = (IPath) toAdd[0]; - destFolder.createLink(pathToAdd, 0, monitor); - } - for(int i=0;i<pathsToRemove.size(); i++){ - Object[] toRemove = (Object[]) pathsToRemove.get(i); - final IVirtualFolder destFolder = (IVirtualFolder) toRemove[1]; - final IPath pathToRemove = (IPath) toRemove[0]; - destFolder.removeLink(pathToRemove, 0, monitor); - } - return Status.OK_STATUS; - } - @Override - public boolean belongsTo(final Object family) { - return PROJECT_COMPONENT_UPDATE_JOB_FAMILY.equals(family); - } - }; - job.setRule(ResourcesPlugin.getWorkspace().getRoot()); - job.schedule(); - } - } - - /* - * Computes the virtual component path mapping changes the need to be made due to - * Java src path changes. - */ - private void getJavaSrcMappings(final IVirtualComponent virtualComp, final IJavaElementDelta[] children, final boolean cpChanged, final IJavaProject jproject, final List pathsToAdd, final List pathsToRemove, final List changedPaths) - throws CoreException { - - // get the default destination folder - final IVirtualFolder defaultDestFolder = getDestinationFolder(virtualComp); - - for (int i = 0; i < children.length; i++) { - final IJavaElementDelta delta = children[i]; - final IJavaElement element = delta.getElement(); - if(element.getElementType() == IJavaElement.PACKAGE_FRAGMENT_ROOT){ - final IPackageFragmentRoot root = (IPackageFragmentRoot) element; - int cpeKind = IPackageFragmentRoot.K_SOURCE; - boolean abortAdd = false; - try { - cpeKind = root.getKind(); - } catch (JavaModelException jme) { - // this is thrown if the folder corresponding to the CPE has been deleted - // since it could represent another error, we need to abort adding. - abortAdd = true; - } - // only update if we know it is a src folder - if (cpeKind == IPackageFragmentRoot.K_SOURCE) { - final int kind = delta.getKind(); - if (!cpChanged) { - // if the classpath is not changed, save modifications to the Java src path - if (kind == IJavaElementDelta.CHANGED || kind == IJavaElementDelta.REMOVED) { - changedPaths.add(root.getPath().removeFirstSegments(1)); - } - } else { - - // kind and flags for CP additions are somewhat sporadic; either: - // -kind is ADDED and flags are 0 - // or - // -kind is CHANGED and flags are F_ADDED_TO_CLASSPATH - final int flags = delta.getFlags(); - - if (kind == IJavaElementDelta.ADDED || - (flags & IJavaElementDelta.F_ADDED_TO_CLASSPATH) == IJavaElementDelta.F_ADDED_TO_CLASSPATH) { - if (!abortAdd) { - final IPath pathToAdd = root.getPath().removeFirstSegments(1); - pathsToAdd.add(new Object[]{pathToAdd, defaultDestFolder}); - // if the added src path was moved from another location, remove any mapping for that - // location - if ((flags & IJavaElementDelta.F_MOVED_FROM) == IJavaElementDelta.F_MOVED_FROM) { - final IJavaElement movedFromElement = delta.getMovedFromElement(); - final IPath pathToRemove = movedFromElement.getPath().removeFirstSegments(1); - pathsToRemove.add(new Object[]{pathToRemove, defaultDestFolder}); - } - } - // getting a kind = REMOVED and flags = 0 for removal of the folder (w/o removing the CPE), probably - // should not be generated - } else if ((flags & IJavaElementDelta.F_REMOVED_FROM_CLASSPATH) == IJavaElementDelta.F_REMOVED_FROM_CLASSPATH) { - IPath path = root.getPath().removeFirstSegments(1); - pathsToRemove.add(new Object[]{path, defaultDestFolder}); - } - } - } - } - } - } - - /* - * Computes the virtual component path mapping changes the need to be made due to changes to - * non-Java folders. - */ - private void getNonJavaFolderMappings(final IResourceDelta[] deltas, final IVirtualComponent virtualComp, final List pathsToAdd, final List pathsToRemove, final List changedJavaPaths) throws CoreException { - IVirtualFolder rootFolder = null; - if (virtualComp != null) { - rootFolder = virtualComp.getRootFolder(); - } - Map sourceToRuntime = null; - if (virtualComp != null) { - sourceToRuntime = getResourceMappings(virtualComp.getProject()); - } - for (int i = 0; i < deltas.length; i++) { - final IResourceDelta delta = deltas[i]; - processResourceDelta(delta, rootFolder, sourceToRuntime, pathsToAdd, pathsToRemove, changedJavaPaths); - } - } - - /* - * Processes a single IResourceDelta. - */ - private void processResourceDelta(final IResourceDelta delta, IVirtualFolder rootFolder, Map sourceToRuntime, final List pathsToAdd, final List pathsToRemove, final List changedJavaPaths) throws CoreException { - IVirtualFolder localRootFolder = rootFolder; - Map localSourceToRuntime = sourceToRuntime; - final int kind = delta.getKind(); - if (kind == IResourceDelta.CHANGED) { - IResourceDelta[] childDeltas = delta.getAffectedChildren(); - for (int i = 0; i < childDeltas.length; i++) { - processResourceDelta(childDeltas[i], localRootFolder, localSourceToRuntime, pathsToAdd, pathsToRemove, changedJavaPaths); - } - } else { - final int flags = delta.getFlags(); - if ((flags & IResourceDelta.MOVED_FROM) == IResourceDelta.MOVED_FROM) { - if (localRootFolder == null) { - final IProject project = delta.getResource().getProject(); - // make certain this is a J2EE project - if (ModuleCoreNature.getModuleCoreNature(project) != null) { - IVirtualComponent c = ComponentCore.createComponent(project); - localRootFolder = c.getRootFolder(); - localSourceToRuntime = getResourceMappings(project); - } else { - // not a J2EE project - return; - } - } - final IPath movedFrom = delta.getMovedFromPath().removeFirstSegments(1); - if (changedJavaPaths.contains(movedFrom)) { - // don't update renamed Java src paths - return; - } - final IPath movedTo = delta.getFullPath().removeFirstSegments(1); - final IPath runtimePath = (IPath) localSourceToRuntime.get(movedFrom); - // does the old path have a virtual component mapping? - if (runtimePath != null) { - final IVirtualFolder folder = localRootFolder.getFolder(runtimePath); - // only add if the project relative paths are not equal (these can be equal when the root folder is mapped and the project is renamed) - if (!movedFrom.equals(movedTo)) { - pathsToRemove.add(new Object[]{movedFrom, folder}); - pathsToAdd.add(new Object[]{movedTo, folder}); - } - } - } - } - } - - private Map getResourceMappings(final IProject project){ - final Map sourceToRuntime = new HashMap(); - StructureEdit core = null; - try { - core = StructureEdit.getStructureEditForRead(project); - final WorkbenchComponent component = core.getComponent(); - if (null != component) { - final List currentResources = component.getResources(); - for (Iterator iter = currentResources.iterator(); iter.hasNext();) { - final ComponentResource resource = (ComponentResource) iter.next(); - sourceToRuntime.put(resource.getSourcePath().makeRelative(), resource.getRuntimePath()); - } - } - return sourceToRuntime; - } finally { - if (core != null) - core.dispose(); - } - } - - /* - * Retrieves the IVirtualFolder to which Java src folders should be mapped - */ - private IVirtualFolder getDestinationFolder(final IVirtualComponent c) throws CoreException { - final IVirtualFolder root = c.getRootFolder(); - if (J2EEProjectUtilities.isDynamicWebProject(c.getProject())) { - // web projects map to WEB-INF/classes - return root.getFolder(new Path(J2EEConstants.WEB_INF_CLASSES)); - } - // all other J2EE project types (that are Java projects) map - // Java src folders to the project root - return root; - } - -} diff --git a/plugins/org.eclipse.jst.j2ee/refactor/org/eclipse/jst/j2ee/refactor/listeners/ProjectRefactoringListener.java b/plugins/org.eclipse.jst.j2ee/refactor/org/eclipse/jst/j2ee/refactor/listeners/ProjectRefactoringListener.java deleted file mode 100644 index db4ed8bef..000000000 --- a/plugins/org.eclipse.jst.j2ee/refactor/org/eclipse/jst/j2ee/refactor/listeners/ProjectRefactoringListener.java +++ /dev/null @@ -1,254 +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: - * rfrost@bea.com - initial API and implementation - *******************************************************************************/ - -package org.eclipse.jst.j2ee.refactor.listeners; - -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.resources.IResourceChangeEvent; -import org.eclipse.core.resources.IResourceChangeListener; -import org.eclipse.core.resources.IResourceDelta; -import org.eclipse.core.resources.IResourceDeltaVisitor; -import org.eclipse.core.resources.IWorkspaceRoot; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.resources.WorkspaceJob; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; -import org.eclipse.jst.j2ee.internal.plugin.J2EEPlugin; -import org.eclipse.jst.j2ee.refactor.RefactorResourceHandler; -import org.eclipse.jst.j2ee.refactor.operations.OptionalRefactorHandler; -import org.eclipse.jst.j2ee.refactor.operations.ProjectRefactorMetadata; -import org.eclipse.jst.j2ee.refactor.operations.ProjectRefactoringDataModelProvider; -import org.eclipse.jst.j2ee.refactor.operations.ProjectRenameDataModelProvider; -import org.eclipse.wst.common.componentcore.ModuleCoreNature; -import org.eclipse.wst.common.componentcore.internal.builder.DependencyGraphManager; -import org.eclipse.wst.common.frameworks.datamodel.DataModelFactory; -import org.eclipse.wst.common.frameworks.datamodel.IDataModel; -import org.eclipse.wst.common.project.facet.core.ProjectFacetsManager; -import org.eclipse.wst.server.core.IModule; -import org.eclipse.wst.server.core.IServer; -import org.eclipse.wst.server.core.IServerWorkingCopy; -import org.eclipse.wst.server.core.ServerUtil; -import org.eclipse.wst.server.core.internal.DeletedModule; - -/** - * Listens for project rename/delete events and, if the project had the - * ModuleCore nature, executes the appropriate logic to update - * project references. - */ -public final class ProjectRefactoringListener implements IResourceChangeListener, IResourceDeltaVisitor { - - /** - * Name of the Job family in which all project rename/delete refactoring jobs belong. - */ - public static final String PROJECT_REFACTORING_JOB_FAMILY = "org.eclipse.jst.j2ee.refactor.project"; //$NON-NLS-1$ - - /* - * Map from name of deleted project to ProjectRefactorMetadata instances. - */ - private final Map deletedProjectMetadata = new HashMap(); - - /** - * Maintains a cache of project depencencies; - */ - public ProjectRefactoringListener() { - } - - /* (non-Javadoc) - * @see org.eclipse.core.resources.IResourceChangeListener#resourceChanged(org.eclipse.core.resources.IResourceChangeEvent) - */ - public void resourceChanged(final IResourceChangeEvent event) { - // need to capture PRE_DELETE events so that metadata about the - // deleted project can be collected and cached - try { - if (event.getType() == IResourceChangeEvent.PRE_DELETE) { - // for now, only dependencies on ModuleCoreNature projects - final IProject project = (IProject) event.getResource(); - // ensure project is accessible and has both module core and faceted natures - if (ModuleCoreNature.getModuleCoreNature(project) != null - && ProjectFacetsManager.create(project) != null) { - cacheDeletedProjectMetadata(project); - } - } else { - event.getDelta().accept(this); - } - } catch (CoreException ce) { - J2EEPlugin.logError(ce); - } - } - - private synchronized void cacheDeletedProjectMetadata(final IProject project) { - final ProjectRefactorMetadata metadata = new ProjectRefactorMetadata(project, ProjectRefactorMetadata.REFERER_CACHING); - // precompute the metadata while the project still exists - metadata.computeMetadata(); - metadata.computeServers(); - metadata.computeDependentMetadata(ProjectRefactorMetadata.REF_CACHING, - DependencyGraphManager.getInstance().getDependencyGraph().getReferencingComponents(project)); - deletedProjectMetadata.put(project.getName(), metadata); - } - - /* (non-Javadoc) - * @see org.eclipse.core.resources.IResourceDeltaVisitor#visit(org.eclipse.core.resources.IResourceDelta) - */ - public boolean visit(final IResourceDelta delta) throws CoreException { - final IResource resource = delta.getResource(); - if (resource instanceof IWorkspaceRoot) { - // delta is at the workspace root so keep going - return true; - } else if (resource instanceof IProject) { - processProjectDelta((IProject) resource, delta); - } - return false; - } - - /* - * Process the project delta in a sync block. - */ - private synchronized void processProjectDelta(final IProject project, final IResourceDelta delta) throws CoreException { - final int kind = delta.getKind(); - final int flags = delta.getFlags(); - - if (kind == IResourceDelta.REMOVED) { - if (hasDeletedRemovedFlags(flags)) { - // if the kind is REMOVED and there are no special flags, the project was deleted - ProjectRefactorMetadata metadata = (ProjectRefactorMetadata) deletedProjectMetadata.remove(project.getName()); - // note: only projects with ModuleCoreNature will have cached metadata - if (metadata != null && OptionalRefactorHandler.getInstance().shouldRefactorDeletedProject(metadata)) { - //Delete refactoring is now being done by the LTK refactoring framework - //for all java ee modules. Please refer to JavaEERefactoringParticipant - //we are only cleaning up the server references here - updateServerRefs(metadata); - - } - } - } else if (kind == IResourceDelta.ADDED && hasRenamedAddedFlags(flags)) { // was renamed - // get the original name - final String originalName = delta.getMovedFromPath().lastSegment(); - //Logger.getLogger().logInfo("Added event for " + originalName + " with flags " + flags); - // we get PRE_DELETE events on rename so retrieve this - ProjectRefactorMetadata originalMetadata = (ProjectRefactorMetadata) deletedProjectMetadata.remove(originalName); - // get the metadata for the new project - final ProjectRefactorMetadata newMetadata = new ProjectRefactorMetadata(project); - // note: only projects with ModuleCoreNature will have cached metadata - if (originalMetadata != null && OptionalRefactorHandler.getInstance().shouldRefactorRenamedProject(originalMetadata)) { - newMetadata.computeMetadata(originalMetadata.getProject()); - processRename(originalMetadata, newMetadata, delta); - } - } - } - - /* - * Determines if the added project was renamed based on the IResourceDelta flags - */ - private boolean hasRenamedAddedFlags(final int flags) { - if ((flags & IResourceDelta.DESCRIPTION) > 0 - && (flags & IResourceDelta.MOVED_FROM) > 0) { - return true; - } - return false; - } - - /* - * Determines if the removed project was deleted based on the IResourceDelta flags - */ - private boolean hasDeletedRemovedFlags(final int flags) { - if ((flags & IResourceDelta.MOVED_TO) == 0 - && (flags & IResourceDelta.REPLACED) == 0) { - return true; - } - return false; - } - - /* - * Processes the renaming of a project. - */ - private void processRename(final ProjectRefactorMetadata originalMetadata, final ProjectRefactorMetadata newMetadata, final IResourceDelta delta) { - WorkspaceJob job = new WorkspaceJob(RefactorMessages.ProjectRefactoringListener_J2EE_Project_Rename_) { - @Override - public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException { - final IDataModel dataModel = DataModelFactory.createDataModel(new ProjectRenameDataModelProvider()); - dataModel.setProperty(ProjectRefactoringDataModelProvider.PROJECT_METADATA, newMetadata); - dataModel.setProperty(ProjectRenameDataModelProvider.ORIGINAL_PROJECT_METADATA, originalMetadata); - dataModel.setProperty(ProjectRenameDataModelProvider.RESOURCE_DELTA, delta); - try { - dataModel.getDefaultOperation().execute(monitor, null); - } catch (Exception e) { - final String msg = RefactorResourceHandler.getString("error_updating_project_on_rename", new Object[]{originalMetadata.getProjectName()}); //$NON-NLS-1$ - J2EEPlugin.logError(msg); - J2EEPlugin.logError(e); - return new Status(Status.ERROR, J2EEPlugin.PLUGIN_ID, 0, msg, e); - } - return Status.OK_STATUS; - } - - @Override - public boolean belongsTo(final Object family) { - return PROJECT_REFACTORING_JOB_FAMILY.equals(family); - } - }; - // XXX note: might want to consider switching to a MultiRule for optimization - job.setRule(ResourcesPlugin.getWorkspace().getRoot()); - job.schedule(); - } - - private void updateServerRefs(final ProjectRefactorMetadata refactorMetadata) { - WorkspaceJob job = new WorkspaceJob("ServerRefreshJob") { //$NON-NLS-1$ - @Override - public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException { - final IModule moduleToRemove = refactorMetadata.getModule(); - if (moduleToRemove == null) { - return Status.OK_STATUS; - } - // Need to replace the original module with a DeletedModule - final IModule[] toUpdate = new IModule[1]; - toUpdate[0] = new DeletedModule(moduleToRemove.getId(), moduleToRemove - .getName(), moduleToRemove.getModuleType()); - IServer[] affectedServers = refactorMetadata.getServers(); - IServerWorkingCopy wc = null; - for (int i = 0; i < affectedServers.length; i++) { - try { - wc = affectedServers[i].createWorkingCopy(); - List list = Arrays.asList(affectedServers[i].getModules()); - if (list.contains(moduleToRemove)) { - ServerUtil.modifyModules(wc, null, toUpdate, null); - } - } catch (CoreException ce) { - J2EEPlugin.logError(ce); - } finally { - try { - if (wc != null) { - wc.saveAll(true, null); - } - } catch (CoreException ce) { - J2EEPlugin.logError(ce); - } - } - } - return Status.OK_STATUS; - } - - @Override - public boolean belongsTo(final Object family) { - return ProjectRefactoringListener.PROJECT_REFACTORING_JOB_FAMILY.equals(family); - } - }; - job.setRule(ResourcesPlugin.getWorkspace().getRoot()); - job.schedule(); - } - -}
\ No newline at end of file diff --git a/plugins/org.eclipse.jst.j2ee/refactor/org/eclipse/jst/j2ee/refactor/listeners/RefactorMessages.java b/plugins/org.eclipse.jst.j2ee/refactor/org/eclipse/jst/j2ee/refactor/listeners/RefactorMessages.java deleted file mode 100644 index 79c337640..000000000 --- a/plugins/org.eclipse.jst.j2ee/refactor/org/eclipse/jst/j2ee/refactor/listeners/RefactorMessages.java +++ /dev/null @@ -1,15 +0,0 @@ -package org.eclipse.jst.j2ee.refactor.listeners; - -import org.eclipse.osgi.util.NLS; - -public class RefactorMessages extends NLS { - - public static final String BUNDLE_NAME = "org.eclipse.jst.j2ee.refactor.listeners.messages"; //$NON-NLS-1$ - public static String J2EEElementChangedListener_J2EE_Component_Mapping_Update_; - public static String ProjectRefactoringListener_J2EE_Project_Rename_; - - static { - NLS.initializeMessages(BUNDLE_NAME, RefactorMessages.class); - } - -} diff --git a/plugins/org.eclipse.jst.j2ee/refactor/org/eclipse/jst/j2ee/refactor/listeners/messages.properties b/plugins/org.eclipse.jst.j2ee/refactor/org/eclipse/jst/j2ee/refactor/listeners/messages.properties deleted file mode 100644 index d562d6bf4..000000000 --- a/plugins/org.eclipse.jst.j2ee/refactor/org/eclipse/jst/j2ee/refactor/listeners/messages.properties +++ /dev/null @@ -1,2 +0,0 @@ -J2EEElementChangedListener_J2EE_Component_Mapping_Update_=J2EE Component Mapping Update -ProjectRefactoringListener_J2EE_Project_Rename_=J2EE Project Rename diff --git a/plugins/org.eclipse.jst.j2ee/refactor/org/eclipse/jst/j2ee/refactor/operations/AbstractOptionalRefactorHandler.java b/plugins/org.eclipse.jst.j2ee/refactor/org/eclipse/jst/j2ee/refactor/operations/AbstractOptionalRefactorHandler.java deleted file mode 100644 index 167d10e46..000000000 --- a/plugins/org.eclipse.jst.j2ee/refactor/org/eclipse/jst/j2ee/refactor/operations/AbstractOptionalRefactorHandler.java +++ /dev/null @@ -1,49 +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.refactor.operations; - -/** - * Abstract implementation of IOptionalRefactorHandler. - */ -public abstract class AbstractOptionalRefactorHandler implements IOptionalRefactorHandler{ - - public AbstractOptionalRefactorHandler(){ - - } - - /* (non-Javadoc) - * @see org.eclipse.jst.j2ee.refactor.operations.IOptionalRefactorHandler#shouldRefactorDeletedProject(org.eclipse.jst.j2ee.refactor.operations.ProjectRefactorMetadata) - */ - public boolean shouldRefactorDeletedProject(final ProjectRefactorMetadata metadata) { - return true; - } - - /* (non-Javadoc) - * @see org.eclipse.jst.j2ee.refactor.operations.IOptionalRefactorHandler#shouldRefactorRenamedProject(org.eclipse.jst.j2ee.refactor.operations.ProjectRefactorMetadata) - */ - public boolean shouldRefactorRenamedProject(final ProjectRefactorMetadata metadata) { - return true; - } - - /* (non-Javadoc) - * @see org.eclipse.jst.j2ee.refactor.operations.IOptionalRefactorHandler#shouldRefactorDependentProjectOnDelete(org.eclipse.jst.j2ee.refactor.operations.ProjectRefactorMetadata, org.eclipse.jst.j2ee.refactor.operations.ProjectRefactorMetadata) - */ - public boolean shouldRefactorDependentProjectOnDelete(final ProjectRefactorMetadata deletedMetadata, ProjectRefactorMetadata dependentMetadata) { - return true; - } - - /* (non-Javadoc) - * @see org.eclipse.jst.j2ee.refactor.operations.IOptionalRefactorHandler#shouldRefactorDependentProjectOnRename(org.eclipse.jst.j2ee.refactor.operations.ProjectRefactorMetadata, org.eclipse.jst.j2ee.refactor.operations.ProjectRefactorMetadata) - */ - public boolean shouldRefactorDependentProjectOnRename(final ProjectRefactorMetadata renamedMetadata, ProjectRefactorMetadata dependentMetadata) { - return true; - } -} diff --git a/plugins/org.eclipse.jst.j2ee/refactor/org/eclipse/jst/j2ee/refactor/operations/CreateOptionalReferenceOp.java b/plugins/org.eclipse.jst.j2ee/refactor/org/eclipse/jst/j2ee/refactor/operations/CreateOptionalReferenceOp.java deleted file mode 100644 index 152fdcd93..000000000 --- a/plugins/org.eclipse.jst.j2ee/refactor/org/eclipse/jst/j2ee/refactor/operations/CreateOptionalReferenceOp.java +++ /dev/null @@ -1,45 +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: - * rfrost@bea.com - initial API and implementation - *******************************************************************************/ - -package org.eclipse.jst.j2ee.refactor.operations; - -import org.eclipse.core.commands.ExecutionException; -import org.eclipse.core.runtime.IAdaptable; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; -import org.eclipse.wst.common.componentcore.internal.operation.CreateReferenceComponentsOp; -import org.eclipse.wst.common.frameworks.datamodel.IDataModel; - -/** - * Extension of <code>CreateReferenceComponentsOp</code> that supports the optional creation of - * the component and project references. - */ -public class CreateOptionalReferenceOp extends CreateReferenceComponentsOp { - - public CreateOptionalReferenceOp(final IDataModel model) { - super(model); - } - - @Override - public IStatus execute(IProgressMonitor monitor, IAdaptable info) throws ExecutionException { - if (!validateEdit().isOK()) - return Status.CANCEL_STATUS; - if (model.getBooleanProperty(CreateOptionalReferenceOpDataModelProvider.CREATE_COMPONENT_REF)) { - addReferencedComponents(monitor); - } - if (model.getBooleanProperty(CreateOptionalReferenceOpDataModelProvider.CREATE_PROJECT_REF)) { - addProjectReferences(); - } - return OK_STATUS; - } - -} diff --git a/plugins/org.eclipse.jst.j2ee/refactor/org/eclipse/jst/j2ee/refactor/operations/CreateOptionalReferenceOpDataModelProvider.java b/plugins/org.eclipse.jst.j2ee/refactor/org/eclipse/jst/j2ee/refactor/operations/CreateOptionalReferenceOpDataModelProvider.java deleted file mode 100644 index 2092dede3..000000000 --- a/plugins/org.eclipse.jst.j2ee/refactor/org/eclipse/jst/j2ee/refactor/operations/CreateOptionalReferenceOpDataModelProvider.java +++ /dev/null @@ -1,57 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2006 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: - * rfrost@bea.com - initial API and implementation - *******************************************************************************/ - -package org.eclipse.jst.j2ee.refactor.operations; - -import java.util.Set; - -import org.eclipse.wst.common.componentcore.internal.operation.CreateReferenceComponentsDataModelProvider; -import org.eclipse.wst.common.frameworks.datamodel.IDataModelOperation; - -public class CreateOptionalReferenceOpDataModelProvider extends CreateReferenceComponentsDataModelProvider { - - /** - * Property that holds a Boolen which controls whether the component reference is - * added/removed. - */ - public static final String CREATE_COMPONENT_REF = "IOptionalReferenceProperties.CREATE_COMPONENT_REF"; //$NON-NLS-1$ - /** - * Property that holds a Boolen which controls whether the .project reference is - * added/removed. - */ - public static final String CREATE_PROJECT_REF = "IOptionalReferenceProperties.CREATE_PROJECT_REF"; //$NON-NLS-1$ - - - /* (non-Javadoc) - * @see org.eclipse.wst.common.frameworks.datamodel.IDataModelProvider#getDefaultOperation() - */ - @Override - public IDataModelOperation getDefaultOperation() { - return new CreateOptionalReferenceOp(model); - } - - @Override - public Set getPropertyNames() { - Set propertyNames = super.getPropertyNames(); - propertyNames.add(CREATE_COMPONENT_REF); - propertyNames.add(CREATE_PROJECT_REF); - return propertyNames; - } - - @Override - public Object getDefaultProperty(String propertyName) { - if (CREATE_COMPONENT_REF.equals(propertyName) - ||CREATE_PROJECT_REF.equals(propertyName)) { - return Boolean.TRUE; - } - return super.getDefaultProperty(propertyName); - } -} diff --git a/plugins/org.eclipse.jst.j2ee/refactor/org/eclipse/jst/j2ee/refactor/operations/IOptionalRefactorHandler.java b/plugins/org.eclipse.jst.j2ee/refactor/org/eclipse/jst/j2ee/refactor/operations/IOptionalRefactorHandler.java deleted file mode 100644 index 35f5f8dc2..000000000 --- a/plugins/org.eclipse.jst.j2ee/refactor/org/eclipse/jst/j2ee/refactor/operations/IOptionalRefactorHandler.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.refactor.operations; - -/** - * Interface for classes that compute whether the automatically executed J2EE - * refactoring logic should be executed when a project is deleted or renamed. - */ -public interface IOptionalRefactorHandler { - - /** - * Called to determine if automatic refactoring logic should be executed - * for a given deleted project. The project will already have been deleted. - * this method is called. - * - * @param metadata Metadata for the deleted project. - * - * @return True to refactor, false to skip refactoring for all dependent projects. - */ - public boolean shouldRefactorDeletedProject(ProjectRefactorMetadata metadata); - - /** - * Called to determine if automatic refactoring logic should be executed - * for a given renamed project. The project will already have been be renamed when - * this method is called. - * - * @param metadata Metadata for the renamed project (pre-rename). - * - * @return True to refactor, false to skip refactoring for all dependent projects. - */ - public boolean shouldRefactorRenamedProject(ProjectRefactorMetadata metadata); - - /** - * Called to determine if automatic refactoring logic should be executed - * on the specified dependent project when a referenced project has been deleted. - * The referenced project will already have been deleted when this method is called. - * - * @param deletedMetadata Metadata for the deleted project. - * @param dependentMetadata Metadata for the dependent project. - * - * @return True to refactor the dependent project. - */ - public boolean shouldRefactorDependentProjectOnDelete(ProjectRefactorMetadata deletedMetadata, ProjectRefactorMetadata dependentMetadata); - - /** - * Called to determine if automatic refactoring logic should be executed - * on the specified dependent project when a referenced project has been renamed. - * The referenced project will already have been renamed when this method is called. - * - * @param renamedMetadata Metadata for the renamed project. - * @param dependentMetadata Metadata for the dependent project. - * - * @return True to refactor the dependent project. - */ - public boolean shouldRefactorDependentProjectOnRename(ProjectRefactorMetadata renamedMetadata, ProjectRefactorMetadata dependentMetadata); -} diff --git a/plugins/org.eclipse.jst.j2ee/refactor/org/eclipse/jst/j2ee/refactor/operations/OptionalRefactorHandler.java b/plugins/org.eclipse.jst.j2ee/refactor/org/eclipse/jst/j2ee/refactor/operations/OptionalRefactorHandler.java deleted file mode 100644 index 53a8e0807..000000000 --- a/plugins/org.eclipse.jst.j2ee/refactor/org/eclipse/jst/j2ee/refactor/operations/OptionalRefactorHandler.java +++ /dev/null @@ -1,149 +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.refactor.operations; - -import java.util.ArrayList; -import java.util.List; - -import org.eclipse.core.runtime.IConfigurationElement; -import org.eclipse.core.runtime.ISafeRunnable; -import org.eclipse.core.runtime.SafeRunner; -import org.eclipse.jem.util.RegistryReader; -import org.eclipse.jst.j2ee.internal.plugin.J2EEPlugin; - -public class OptionalRefactorHandler implements IOptionalRefactorHandler{ - - private static final String EXTENSION_POINT = "optionalRefactorHandler"; //$NON-NLS-1$ - private static final String TAG_OPTIONAL_REFACTOR = "optionalRefactorHandler"; //$NON-NLS-1$ - private static final String ATT_CLASS = "class"; //$NON-NLS-1$ - - private static OptionalRefactorHandler instance = new OptionalRefactorHandler(); - private IOptionalRefactorHandler [] handlers = null; - - private OptionalRefactorHandler () { - SafeRunner.run(new ISafeRunnable() { - - public void handleException(Throwable exception) { - J2EEPlugin.logError(0, exception.getMessage(), exception); - } - - public void run() throws Exception { - OptionalRefactorHandlerRegistryReader reader = new OptionalRefactorHandlerRegistryReader(); - reader.readRegistry(); - handlers = reader.getHandlers(); - } - - }); - } - - public static OptionalRefactorHandler getInstance() { - return instance; - } - - /* (non-Javadoc) - * @see org.eclipse.jst.j2ee.refactor.operations.IOptionalRefactorHandler#shouldRefactorDeletedProject(org.eclipse.jst.j2ee.refactor.operations.ProjectRefactorMetadata) - */ - public boolean shouldRefactorDeletedProject(final ProjectRefactorMetadata metadata) { - for(int i=0;i<handlers.length; i++){ - if(!handlers[i].shouldRefactorDeletedProject(metadata)){ - return false; - } - } - return true; - } - - /* (non-Javadoc) - * @see org.eclipse.jst.j2ee.refactor.operations.IOptionalRefactorHandler#shouldRefactorRenamedProject(org.eclipse.jst.j2ee.refactor.operations.ProjectRefactorMetadata) - */ - public boolean shouldRefactorRenamedProject(final ProjectRefactorMetadata metadata) { - for(int i=0;i<handlers.length; i++){ - if(!handlers[i].shouldRefactorRenamedProject(metadata)){ - return false; - } - } - return true; - } - - /* (non-Javadoc) - * @see org.eclipse.jst.j2ee.refactor.operations.IOptionalRefactorHandler#shouldRefactorDependentProjectOnDelete(org.eclipse.jst.j2ee.refactor.operations.ProjectRefactorMetadata, org.eclipse.jst.j2ee.refactor.operations.ProjectRefactorMetadata) - */ - public boolean shouldRefactorDependentProjectOnDelete(final ProjectRefactorMetadata deletedMetadata, ProjectRefactorMetadata dependentMetadata) { - for(int i=0;i<handlers.length; i++){ - if(!handlers[i].shouldRefactorDependentProjectOnDelete(deletedMetadata, dependentMetadata)){ - return false; - } - } - return true; - } - - /* (non-Javadoc) - * @see org.eclipse.jst.j2ee.refactor.operations.IOptionalRefactorHandler#shouldRefactorDependentProjectOnRename(org.eclipse.jst.j2ee.refactor.operations.ProjectRefactorMetadata, org.eclipse.jst.j2ee.refactor.operations.ProjectRefactorMetadata) - */ - public boolean shouldRefactorDependentProjectOnRename(final ProjectRefactorMetadata renamedMetadata, ProjectRefactorMetadata dependentMetadata) { - for(int i=0;i<handlers.length; i++){ - if(!handlers[i].shouldRefactorDependentProjectOnRename(renamedMetadata, dependentMetadata)){ - return false; - } - } - return true; - } - - - private class OptionalRefactorHandlerRegistryReader extends RegistryReader { - - private List innerHandlers = new ArrayList(); - - public OptionalRefactorHandlerRegistryReader() { - super(J2EEPlugin.PLUGIN_ID, EXTENSION_POINT); - } - - /** - * @see org.eclipse.wst.common.frameworks.internal.RegistryReader#readElement(org.eclipse.core.runtime.IConfigurationElement) - */ - @Override - public boolean readElement(final IConfigurationElement element) { - if (TAG_OPTIONAL_REFACTOR.equals(element.getName())) { - - /* - * Because the only instance of this type is created from a static singleton field, and - * the registry is initialized in the constructor of this type, other threads cannot - * compete with readElement() for access to <i>descriptors</i> - */ - final IOptionalRefactorHandler[] handlerArray = new IOptionalRefactorHandler[1]; - - SafeRunner.run(new ISafeRunnable() { - - public void handleException(Throwable exception) { - J2EEPlugin.logError(0, exception.getMessage(), exception); - } - - public void run() throws Exception { - handlerArray[0] = (IOptionalRefactorHandler) element.createExecutableExtension(ATT_CLASS); - } - - }); - - innerHandlers.add(handlerArray[0]); - return true; - } - return false; - } - - public IOptionalRefactorHandler [] getHandlers() { - IOptionalRefactorHandler [] handlersArray = new IOptionalRefactorHandler[innerHandlers.size()]; - for(int i=0;i<handlersArray.length;i++){ - handlersArray[i] = (IOptionalRefactorHandler)innerHandlers.get(i); - } - return handlersArray; - } - } - -} diff --git a/plugins/org.eclipse.jst.j2ee/refactor/org/eclipse/jst/j2ee/refactor/operations/ProjectRefactorMetadata.java b/plugins/org.eclipse.jst.j2ee/refactor/org/eclipse/jst/j2ee/refactor/operations/ProjectRefactorMetadata.java deleted file mode 100644 index 2bdbb753b..000000000 --- a/plugins/org.eclipse.jst.j2ee/refactor/org/eclipse/jst/j2ee/refactor/operations/ProjectRefactorMetadata.java +++ /dev/null @@ -1,370 +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: - * rfrost@bea.com - initial API and implementation - *******************************************************************************/ - -package org.eclipse.jst.j2ee.refactor.operations; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Properties; -import java.util.Set; - -import org.eclipse.core.resources.IProject; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.jst.j2ee.internal.plugin.J2EEPlugin; -import org.eclipse.jst.j2ee.model.IEARModelProvider; -import org.eclipse.jst.j2ee.model.ModelProviderManager; -import org.eclipse.wst.common.componentcore.ComponentCore; -import org.eclipse.wst.common.componentcore.ModuleCoreNature; -import org.eclipse.wst.common.componentcore.internal.resources.VirtualComponent; -import org.eclipse.wst.common.componentcore.internal.util.IModuleConstants; -import org.eclipse.wst.common.componentcore.resources.IVirtualComponent; -import org.eclipse.wst.common.componentcore.resources.IVirtualFolder; -import org.eclipse.wst.common.componentcore.resources.IVirtualReference; -import org.eclipse.wst.common.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; -import org.eclipse.wst.server.core.IModule; -import org.eclipse.wst.server.core.IServer; -import org.eclipse.wst.server.core.ServerUtil; - -/** - * IDataModel object property stored under the property name - * {@link ProjectRefactoringDataModelProvider#PROJECT_METADATA}. - * - * Note: this class is not multi-thread safe. - */ -public class ProjectRefactorMetadata { - - public static int NON_CACHING = 0; - public static int REF_CACHING = 1; - public static int REFERER_CACHING = 2; - - private int _virtualCompCaching = NON_CACHING; - private final IProject _project; - private IServer[] servers; - private IVirtualComponent virtualComp = null; - private final List dependentMetadata = new ArrayList(); - private boolean javaNature; - private boolean moduleCoreNature; - private IModule module; - private Set facets = new HashSet(); - private final Map earToModuleURI = new HashMap(); - - public ProjectRefactorMetadata(final IProject project) { - _project = project; - } - - public ProjectRefactorMetadata(final IProject project, final int virtualCompCaching) { - this(project); - _virtualCompCaching = virtualCompCaching; - } - - public void computeMetadata() { - computeMetadata(_project); - } - public void computeMetadata(final IProject oldProject) { - try { - javaNature = _project.hasNature("org.eclipse.jdt.core.javanature"); //$NON-NLS-1$ - moduleCoreNature = ModuleCoreNature.getModuleCoreNature(_project) != null; - if (moduleCoreNature) { - if (_virtualCompCaching == REF_CACHING) { - virtualComp = new RefCachingVirtualComponent(ComponentCore.createComponent(_project)); - } else if (_virtualCompCaching == REFERER_CACHING) { - virtualComp = new RefererCachingVirtualComponent(ComponentCore.createComponent(_project)); - } else { - virtualComp = ComponentCore.createComponent(_project); - } - final IFacetedProject facetedProject = ProjectFacetsManager.create(_project); - module = ServerUtil.getModule(_project); - // XXX Due to resource change listener order uncertainty, the project associated with the - // module may be either the new (correct) project or the old project so need to try both - if (module == null && !_project.equals(oldProject)) { - module = ServerUtil.getModule(oldProject); - } - if (facetedProject != null) { - facets = facetedProject.getProjectFacets(); - } - } - } catch (CoreException ce) { - J2EEPlugin.logError(ce); - } - } - - public void computeServers() { - servers = ServerUtil.getServersByModule(module, null); - } - - public IServer[] getServers() { - return servers; - } - - public void computeDependentMetadata(final int virtualComponentCaching, final IProject[] dependentProjects) { - // get all referencing projects and execute the appropriate update operation for each one - ProjectRefactorMetadata metadata; - for (int i = 0; i < dependentProjects.length; i++) { - final IProject dependentProject = dependentProjects[i]; - if (dependentProject.exists() && dependentProject.isOpen()) { - metadata = new ProjectRefactorMetadata(dependentProjects[i], virtualComponentCaching); - metadata.computeMetadata(); - dependentMetadata.add(metadata); - if (metadata.isEAR()) { - final String uri = getModuleURI(dependentProject, virtualComp); - if (uri != null) { - earToModuleURI.put(dependentProject.getName(), uri); - } - } - } - } - } - - /** - * If this project is associated with the specified EAR project, retrieves the module URI for the dependency or null if - * it could not be retrieved. - * @param earName Name of the EAR project. - * @return Module URI for the project in the context of that EAR. - */ - public String getModuleURI(final String earName) { - return (String) earToModuleURI.get(earName); - } - - private String getModuleURI(final IProject earProject, final IVirtualComponent comp) { - IEARModelProvider earModelProvider = null; - earModelProvider = (IEARModelProvider) ModelProviderManager.getModelProvider(earProject); - if (earModelProvider != null) { - return earModelProvider.getModuleURI(comp); - } - return null; - } - - /** - * Retrieves the IProject that represents the referenced project. - */ - public IProject getProject() { - return _project; - } - - /** - * Retrieves the IModule for the project, or null if no IModule representation - * exists. - */ - public IModule getModule() { - return module; - } - - /** - * Retrieves the project name. - */ - public String getProjectName() { - return _project.getName(); - } - - /** - * Retrieves all ProjectRefactorMetadata for dependent projects. - * Will be empty if not computed. - */ - public ProjectRefactorMetadata[] getDependentMetadata() { - return (ProjectRefactorMetadata[]) dependentMetadata.toArray(new ProjectRefactorMetadata[dependentMetadata.size()]); - } - - /** - * Returns the IVirtualComponent for the project. - */ - public IVirtualComponent getVirtualComponent() { - return virtualComp; - } - - public boolean hasJavaNature() { - return javaNature; - } - - public boolean hasModuleCoreNature() { - return moduleCoreNature; - } - - public Set getProjectFacets() { - return facets; - } - - public boolean hasFacet(final IProjectFacet facet) { - for(Iterator itr = facets.iterator(); itr.hasNext();) { - final IProjectFacetVersion fv = (IProjectFacetVersion) itr.next(); - - if(fv.getProjectFacet() == facet) { - return true; - } - } - - return false; - } - - public boolean isEAR() { - return hasFacet(ProjectFacetsManager.getProjectFacet(IModuleConstants.JST_EAR_MODULE)); - } - - public boolean isEJB() { - return hasFacet(ProjectFacetsManager.getProjectFacet(IModuleConstants.JST_EJB_MODULE)); - } - - public boolean isWeb() { - return hasFacet(ProjectFacetsManager.getProjectFacet(IModuleConstants.JST_WEB_MODULE)); - } - - public boolean isAppClient() { - return hasFacet(ProjectFacetsManager.getProjectFacet(IModuleConstants.JST_APPCLIENT_MODULE)); - } - - public boolean isConnector() { - return hasFacet(ProjectFacetsManager.getProjectFacet(IModuleConstants.JST_CONNECTOR_MODULE)); - } - - public boolean isUtility() { - return hasFacet(ProjectFacetsManager.getProjectFacet(IModuleConstants.JST_UTILITY_MODULE)); - } - - public class CachingVirtualComponent implements IVirtualComponent { - protected final IVirtualComponent _comp; - protected boolean _caching = true; - public CachingVirtualComponent(final IVirtualComponent comp) { - _comp = comp; - } - public void addReferences(IVirtualReference[] references) { - _comp.addReferences(references); - } - public void create(int updateFlags, IProgressMonitor aMonitor) throws CoreException { - _comp.create(updateFlags, aMonitor); - } - public boolean exists() { - return _comp.exists(); - } - public IVirtualComponent getComponent() { - return _comp.getComponent(); - } - public Properties getMetaProperties() { - return _comp.getMetaProperties(); - } - public IPath[] getMetaResources() { - return _comp.getMetaResources(); - } - public String getName() { - return _comp.getName(); - } - public String getDeployedName() { - return _comp.getDeployedName(); - } - public IProject getProject() { - return _comp.getProject(); - } - public IVirtualReference getReference(String aComponentName) { - return _comp.getReference(aComponentName); - } - public IVirtualReference[] getReferences() { - return _comp.getReferences(); - } - public void setCaching(boolean caching) { - _caching = caching; - } - public IVirtualComponent[] getReferencingComponents() { - return _comp.getReferencingComponents(); - } - public IVirtualFolder getRootFolder() { - return _comp.getRootFolder(); - } - public boolean isBinary() { - return _comp.isBinary(); - } - public void setMetaProperties(Properties properties) { - _comp.setMetaProperties(properties); - } - public void setMetaProperty(String name, String value) { - _comp.setMetaProperty(name, value); - } - public void setMetaResources(IPath[] theMetaResourcePaths) { - _comp.setMetaResources(theMetaResourcePaths); - } - public void setReferences(IVirtualReference[] theReferences) { - _comp.setReferences(theReferences); - } - public Object getAdapter(Class adapter) { - return _comp.getAdapter(adapter); - } - - @Override - public boolean equals(Object o) { - return _comp.equals(o); - } - - @Override - public int hashCode() { - return _comp.hashCode(); - } - - @Override - public String toString() { - return _comp.toString(); - } - - public void removeReference(IVirtualReference aReference) { - ((VirtualComponent)_comp).removeReference(aReference); - } - } - - public class RefCachingVirtualComponent extends CachingVirtualComponent { - private IVirtualReference[] cachedRefs; - public RefCachingVirtualComponent(final IVirtualComponent comp) { - super(comp); - cachedRefs = ((VirtualComponent)comp).getAllReferences(); - } - - @Override - public IVirtualReference getReference(String aComponentName) { - IVirtualReference[] refs = getReferences(); - for (int i = 0; i < refs.length; i++) { - IVirtualReference reference = refs[i]; - if (reference == null || reference.getReferencedComponent() == null) { - return null; - } - if (reference.getReferencedComponent().getName().equals(aComponentName)) - return reference; - } - return null; - } - @Override - public IVirtualReference[] getReferences() { - if (_caching) { - return cachedRefs; - } - return super.getReferences(); - } - } - - public class RefererCachingVirtualComponent extends CachingVirtualComponent { - private IVirtualComponent[] cachedReferers; - public RefererCachingVirtualComponent(final IVirtualComponent comp) { - super(comp); - cachedReferers = comp.getReferencingComponents(); - } - - @Override - public IVirtualComponent[] getReferencingComponents() { - if (_caching) { - return cachedReferers; - } - return _comp.getReferencingComponents(); - } - } -} diff --git a/plugins/org.eclipse.jst.j2ee/refactor/org/eclipse/jst/j2ee/refactor/operations/ProjectRefactorOperation.java b/plugins/org.eclipse.jst.j2ee/refactor/org/eclipse/jst/j2ee/refactor/operations/ProjectRefactorOperation.java deleted file mode 100644 index 123e2ffa4..000000000 --- a/plugins/org.eclipse.jst.j2ee/refactor/org/eclipse/jst/j2ee/refactor/operations/ProjectRefactorOperation.java +++ /dev/null @@ -1,203 +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: - * rfrost@bea.com - initial API and implementation - *******************************************************************************/ - -package org.eclipse.jst.j2ee.refactor.operations; - -import java.util.Arrays; -import java.util.List; - -import org.eclipse.core.commands.ExecutionException; -import org.eclipse.core.resources.IProject; -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.core.runtime.Status; -import org.eclipse.jst.j2ee.refactor.RefactorResourceHandler; -import org.eclipse.wst.common.frameworks.datamodel.AbstractDataModelOperation; -import org.eclipse.wst.common.frameworks.datamodel.IDataModel; -import org.eclipse.wst.server.core.IModule; -import org.eclipse.wst.server.core.IModuleType; -import org.eclipse.wst.server.core.IServer; -import org.eclipse.wst.server.core.IServerWorkingCopy; -import org.eclipse.wst.server.core.ServerUtil; -import org.eclipse.wst.server.core.internal.DeletedModule; -import org.eclipse.wst.server.core.internal.Module; - -/** - * Abstract base class for project refactoring operations. - */ -public abstract class ProjectRefactorOperation extends AbstractDataModelOperation - implements ProjectRefactoringProperties { - - /** - * Creates a new refactoring operation for the specified data model. - * @param model The data model. - */ - public ProjectRefactorOperation(final IDataModel model) { - super(model); - } - - /* (non-Javadoc) - * @see org.eclipse.core.commands.operations.IUndoableOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable) - */ - @Override - public IStatus execute(IProgressMonitor monitor, IAdaptable info) throws ExecutionException { - try { - final ProjectRefactorMetadata refactoredMetadata = getProjectMetadata(); - - // Update this project's metadata - if (refactoredMetadata.hasModuleCoreNature()) { - updateProject(refactoredMetadata); - } - - updateDependentProjects(refactoredMetadata, monitor); - } finally { - if (monitor != null) { - monitor.done(); - } - } - - return Status.OK_STATUS; - } - - /** - * Updates the project's own metadata. - */ - protected abstract void updateProject(final ProjectRefactorMetadata refactoredMetadata) - throws ExecutionException; - - /** - * Updates the metadata for dependent projects - * @throws ExecutionException - */ - protected void updateDependentProjects(final ProjectRefactorMetadata refactoredMetadata, - final IProgressMonitor monitor) throws ExecutionException { - // get the metadata for all dependent projects - final ProjectRefactorMetadata[] dependentMetadata = refactoredMetadata.getDependentMetadata(); - if (monitor != null) { - monitor.beginTask(RefactorResourceHandler.getString("task_name"), dependentMetadata.length); //$NON-NLS-1$ - } - ProjectRefactorMetadata metadata; - for (int i = 0; i < dependentMetadata.length; i++) { - metadata = dependentMetadata[i]; - // if the project is an EAR, execute the update operation created by the - // DependentEARUpdateProvider; if the project is a non-EAR project with the - // module core nature, execute the appropriate update - if (metadata.isEAR()) { - updateDependentEARProject(metadata, refactoredMetadata); - } else if (metadata.hasModuleCoreNature()) { - updateDependentModuleProject(metadata, refactoredMetadata); - } - if (monitor != null) { - monitor.worked(1); - } - } - } - - /** - * Updates any server references. - */ - protected void updateServerRefs(final ProjectRefactorMetadata originalMetadata, - final ProjectRefactorMetadata newMetadata) - throws ExecutionException { - final IModule originalModule = originalMetadata.getModule(); - if (originalModule == null) { - // no module for the original project, so return - return; - } - // Need to replace the original module with a DeletedModule - final IModule[] toRemove = new IModule[1]; - toRemove[0] = new DeletedModule(originalModule.getId(), originalModule.getName(), - originalModule.getModuleType()); - - IModule newModule = null; - IModule[] toAdd = new IModule[0]; - if (newMetadata != null) { - newModule = newMetadata.getModule(); - if (newModule == null) { - // no module for the new project, so return - return; - } - // XXX Due to https://bugs.eclipse.org/bugs/show_bug.cgi?id=124292, - // need to ensure that the IModule for the renamed project has the - // id and name for the renamed IProject and not the old name - final IProject newProject = newMetadata.getProject(); - final IModuleType moduleType = newModule.getModuleType(); - ((Module) newModule).getModuleFactory().getModules(); - newModule = new Module(((Module) newModule).getModuleFactory(), newProject.getName(), newProject.getName(), moduleType.getId(), - moduleType.getVersion(), newProject); - toAdd = new IModule[]{newModule}; - } - - final IServer[] server = originalMetadata.getServers(); - IServerWorkingCopy wc = null; - for (int i = 0; i < server.length; i++) { - try { - wc = server[i].createWorkingCopy(); - List list = Arrays.asList(server[i].getModules()); - if (list.contains(originalModule)) { - // remove the original and potentially add a new - ServerUtil.modifyModules(wc, toAdd, toRemove, null); - } - } catch (CoreException ce) { - throw new ExecutionException(RefactorResourceHandler.getString("error_updating_server", //$NON-NLS-1$ - new Object[]{server[i].getId(), originalMetadata.getProjectName()}), ce); - } finally { - try { - if(wc != null) - wc.saveAll(true, null); - } catch (CoreException ce) { - throw new ExecutionException(RefactorResourceHandler.getString("error_updating_server", //$NON-NLS-1$ - new Object[]{server[i].getId(), originalMetadata.getProjectName()}), ce); - } - } - } - } - - /** - * Updates the dependent EAR project to account for the refactoring of the referenced project. - */ - protected abstract void updateDependentEARProject(final ProjectRefactorMetadata dependentMetadata, - final ProjectRefactorMetadata refactoredMetadata) throws ExecutionException; - - /** - * Updates the dependent module project to account for the refactoring of the referenced project. - */ - protected abstract void updateDependentModuleProject(final ProjectRefactorMetadata dependentMetadata, - final ProjectRefactorMetadata refactoredMetadata) throws ExecutionException; - - /** - * Retrieves the ProjectRefactorMetadata property. - */ - protected ProjectRefactorMetadata getProjectMetadata() { - return (ProjectRefactorMetadata) model.getProperty(PROJECT_METADATA); - } - - /** - * Override to disable redo support - * @see org.eclipse.core.commands.operations.IUndoableOperation#canRedo() - */ - @Override - public boolean canRedo() { - return false; - } - - /** - * Override to disable undo support. - * @see org.eclipse.core.commands.operations.IUndoableOperation#canUndo() - */ - @Override - public boolean canUndo() { - return false; - } - -} diff --git a/plugins/org.eclipse.jst.j2ee/refactor/org/eclipse/jst/j2ee/refactor/operations/ProjectRefactoringDataModelProvider.java b/plugins/org.eclipse.jst.j2ee/refactor/org/eclipse/jst/j2ee/refactor/operations/ProjectRefactoringDataModelProvider.java deleted file mode 100644 index 47f859d1f..000000000 --- a/plugins/org.eclipse.jst.j2ee/refactor/org/eclipse/jst/j2ee/refactor/operations/ProjectRefactoringDataModelProvider.java +++ /dev/null @@ -1,56 +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: - * rfrost@bea.com - initial API and implementation - *******************************************************************************/ - -package org.eclipse.jst.j2ee.refactor.operations; - -import java.util.Iterator; -import java.util.Set; - -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; -import org.eclipse.jst.j2ee.internal.plugin.J2EEPlugin; -import org.eclipse.jst.j2ee.refactor.RefactorResourceHandler; -import org.eclipse.wst.common.frameworks.datamodel.AbstractDataModelProvider; - -public abstract class ProjectRefactoringDataModelProvider extends - AbstractDataModelProvider implements ProjectRefactoringProperties { - - /* (non-Javadoc) - * @see org.eclipse.wst.common.frameworks.datamodel.IDataModelProvider#getPropertyNames() - */ - @Override - public Set getPropertyNames() { - Set propertyNames = super.getPropertyNames(); - propertyNames.add(PROJECT_METADATA); - return propertyNames; - } - - /* (non-Javadoc) - * @see org.eclipse.wst.common.frameworks.datamodel.IDataModelProvider#validate(java.lang.String) - */ - @Override - public IStatus validate(String propertyName) { - Iterator i = getPropertyNames().iterator(); - boolean valid = false; - while (i.hasNext()) { - if (i.next().equals(propertyName)) { - valid = true; - break; - } - } - if (!valid) { - return new Status(IStatus.ERROR, J2EEPlugin.PLUGIN_ID, IStatus.OK, - RefactorResourceHandler.getString("invalid_property_name", new Object[]{propertyName}), null); //$NON-NLS-1$ - } - return OK_STATUS; - } - -} diff --git a/plugins/org.eclipse.jst.j2ee/refactor/org/eclipse/jst/j2ee/refactor/operations/ProjectRefactoringProperties.java b/plugins/org.eclipse.jst.j2ee/refactor/org/eclipse/jst/j2ee/refactor/operations/ProjectRefactoringProperties.java deleted file mode 100644 index 53bf78dba..000000000 --- a/plugins/org.eclipse.jst.j2ee/refactor/org/eclipse/jst/j2ee/refactor/operations/ProjectRefactoringProperties.java +++ /dev/null @@ -1,40 +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: - * rfrost@bea.com - initial API and implementation - *******************************************************************************/ - -package org.eclipse.jst.j2ee.refactor.operations; - -public interface ProjectRefactoringProperties { - - /** - * Name of the property that holds an instance of ProjectRefactorMetadata for the - * refactored project. - */ - public static final String PROJECT_METADATA = "ProjectRefactoringProperties.PROJECT_METADATA"; //$NON-NLS-1$ - - /** - * Name of the property that holds an instance of ProjectRefactorMetadata for the original version of - * the refactored project. - */ - public static final String ORIGINAL_PROJECT_METADATA = "ProjectRefactoringProperties.ORIGINAL_PROJECT_METADATA"; //$NON-NLS-1$ - - /** - * Name of the property that holds an instance of ProjectRefactorMetadata for the - * dependent project. - */ - public static final String DEPENDENT_PROJECT_METADATA = "ProjectRefactoringProperties.DEPENDENT_PROJECT_METADATA"; //$NON-NLS-1$ - - /** - * Name of the property that holds an instance of the IResourceDelta - */ - public static final String RESOURCE_DELTA= "ProjectRefactoringProperties.RESOURCE_DELTA"; //$NON-NLS-1$ - - -} diff --git a/plugins/org.eclipse.jst.j2ee/refactor/org/eclipse/jst/j2ee/refactor/operations/ProjectRenameDataModelProvider.java b/plugins/org.eclipse.jst.j2ee/refactor/org/eclipse/jst/j2ee/refactor/operations/ProjectRenameDataModelProvider.java deleted file mode 100644 index 4361bb679..000000000 --- a/plugins/org.eclipse.jst.j2ee/refactor/org/eclipse/jst/j2ee/refactor/operations/ProjectRenameDataModelProvider.java +++ /dev/null @@ -1,38 +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: - * rfrost@bea.com - initial API and implementation - *******************************************************************************/ - -package org.eclipse.jst.j2ee.refactor.operations; - -import java.util.Set; - -import org.eclipse.wst.common.frameworks.datamodel.IDataModelOperation; - -public class ProjectRenameDataModelProvider extends ProjectRefactoringDataModelProvider{ - - /* (non-Javadoc) - * @see org.eclipse.wst.common.frameworks.datamodel.IDataModelProvider#getPropertyNames() - */ - @Override - public Set getPropertyNames() { - Set propertyNames = super.getPropertyNames(); - propertyNames.add(ORIGINAL_PROJECT_METADATA); - propertyNames.add(RESOURCE_DELTA); - return propertyNames; - } - - /* (non-Javadoc) - * @see org.eclipse.wst.common.frameworks.datamodel.IDataModelProvider#getDefaultOperation() - */ - @Override - public IDataModelOperation getDefaultOperation() { - return new ProjectRenameOperation(model); - } -} diff --git a/plugins/org.eclipse.jst.j2ee/refactor/org/eclipse/jst/j2ee/refactor/operations/ProjectRenameOperation.java b/plugins/org.eclipse.jst.j2ee/refactor/org/eclipse/jst/j2ee/refactor/operations/ProjectRenameOperation.java deleted file mode 100644 index 69f83ba0f..000000000 --- a/plugins/org.eclipse.jst.j2ee/refactor/org/eclipse/jst/j2ee/refactor/operations/ProjectRenameOperation.java +++ /dev/null @@ -1,184 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2005-2007 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: - * rfrost@bea.com - initial API and implementation - *******************************************************************************/ - -package org.eclipse.jst.j2ee.refactor.operations; - -import java.util.List; - -import org.eclipse.core.commands.ExecutionException; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IResourceDelta; -import org.eclipse.core.resources.ResourcesPlugin; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.jst.j2ee.common.CompatibilityDescriptionGroup; -import org.eclipse.jst.j2ee.internal.project.J2EEProjectUtilities; -import org.eclipse.jst.j2ee.model.IModelProvider; -import org.eclipse.jst.j2ee.model.ModelProviderManager; -import org.eclipse.jst.javaee.application.Application; -import org.eclipse.jst.javaee.applicationclient.ApplicationClient; -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.web.WebApp; -import org.eclipse.wst.common.componentcore.internal.StructureEdit; -import org.eclipse.wst.common.componentcore.internal.WorkbenchComponent; -import org.eclipse.wst.common.componentcore.internal.util.ComponentUtilities; -import org.eclipse.wst.common.frameworks.datamodel.AbstractDataModelProvider; -import org.eclipse.wst.common.frameworks.datamodel.DataModelFactory; -import org.eclipse.wst.common.frameworks.datamodel.IDataModel; -import org.eclipse.wst.server.core.util.ProjectModuleFactoryDelegate; - -public class ProjectRenameOperation extends ProjectRefactorOperation { - - public ProjectRenameOperation(final IDataModel model) { - super(model); - } - - /** - * Override to return the pre-rename metadata. - */ - @Override - protected ProjectRefactorMetadata getProjectMetadata() { - return (ProjectRefactorMetadata) model.getProperty(ProjectRenameDataModelProvider.ORIGINAL_PROJECT_METADATA); - } - - /** - * Updates the project's own metadata. - */ - @Override - protected void updateProject(final ProjectRefactorMetadata originalMetadata) - throws ExecutionException { - - // Update the project's .component file - final ProjectRefactorMetadata refactoredMetadata = super.getProjectMetadata(); - final String oldProjectName = originalMetadata.getProjectName(); - final String newProjectName = refactoredMetadata.getProjectName(); - IProject newProject = ResourcesPlugin.getWorkspace(). getRoot().getProject(newProjectName); - String originalContextRoot = ComponentUtilities.getServerContextRoot(newProject); - if (oldProjectName.equals(originalContextRoot)) { - // if old context root = project name, lets update it - ComponentUtilities.setServerContextRoot(newProject, newProjectName); - } - StructureEdit core = null; - WorkbenchComponent component = null; - try{ - core = StructureEdit.getStructureEditForWrite(refactoredMetadata.getProject()); - if(core != null){ - component = core.getComponent(); - } - - // if the deploy-name equals the old project name, update it in the module-specific deployment descriptor - if (component != null && component.getName().equals(originalMetadata.getProjectName())) { - component.setName(refactoredMetadata.getProjectName()); - } - }finally { - if(core != null) { - core.saveIfNecessary(null); - core.dispose(); - } - } - final IProject refactoredProject = refactoredMetadata.getProject(); - if (J2EEProjectUtilities.isUtilityProject(refactoredProject)) { - // skip if a utility project (will not have a ModelProvider and checking logs an error - return; - } - final IModelProvider model = ModelProviderManager.getModelProvider(refactoredProject); - if (model != null) { - model.modify(new Runnable() { - public void run() { - final Object modelObject = model.getModelObject(); - if (modelObject instanceof CompatibilityDescriptionGroup) { - CompatibilityDescriptionGroup cdg = (CompatibilityDescriptionGroup) modelObject; - if (cdg.getDisplayName().equals(oldProjectName)) { - cdg.setDisplayName(newProjectName); - } - } else { - DisplayName dn = JavaeeFactory.eINSTANCE.createDisplayName(); - dn.setValue(newProjectName); - List displayNames = null; - if (modelObject instanceof Application) { - displayNames = ((Application) modelObject).getDisplayNames(); - } else if (modelObject instanceof WebApp) { - displayNames = ((WebApp)modelObject).getDisplayNames(); - } else if (modelObject instanceof ApplicationClient) { - displayNames = ((ApplicationClient)modelObject).getDisplayNames(); - } else if (modelObject instanceof EJBJar) { - displayNames = ((EJBJar)modelObject).getDisplayNames(); - } - if (displayNames != null && !displayNames.isEmpty()) { - DisplayName oldDN = (DisplayName) displayNames.get(0); - if (oldDN.getValue().equals(oldProjectName)) { - displayNames.set(0, dn); - } - } - } - } - }, null); - } - } - - /** - * Updates the metadata for dependent projects - * @throws ExecutionException - */ - @Override - protected void updateDependentProjects(final ProjectRefactorMetadata originalMetadata, - final IProgressMonitor monitor) throws ExecutionException { - // If this is not an EAR, update metadata for dependent projects - // (not performing any refactoring for projects that depend on EAR's right now) - if (!originalMetadata.isEAR()) { - super.updateDependentProjects(originalMetadata, monitor); - } - // update any server instance refs to the refactored project - final ProjectRefactorMetadata refactoredMetadata = super.getProjectMetadata(); - ProjectModuleFactoryDelegate.handleGlobalProjectChange(refactoredMetadata.getProject(), - (IResourceDelta) model.getProperty(ProjectRenameDataModelProvider.RESOURCE_DELTA)); - super.updateServerRefs(originalMetadata, refactoredMetadata); - } - - /** - * Updates the dependent EAR project to account for the renaming of the referenced project. - */ - @Override - protected void updateDependentEARProject(final ProjectRefactorMetadata dependentMetadata, - final ProjectRefactorMetadata originalMetadata) throws ExecutionException { - if (OptionalRefactorHandler.getInstance().shouldRefactorDependentProjectOnRename(originalMetadata, dependentMetadata)) { - final IDataModel dataModel = createDataModel(dependentMetadata, originalMetadata, - new UpdateDependentEARonRenameProvider()); - dataModel.getDefaultOperation().execute(null, null); - } - } - - /** - * Updates the dependent module project to account for the renaming of the referenced project. - */ - @Override - protected void updateDependentModuleProject(final ProjectRefactorMetadata dependentMetadata, - final ProjectRefactorMetadata originalMetadata) throws ExecutionException { - if (OptionalRefactorHandler.getInstance().shouldRefactorDependentProjectOnRename(originalMetadata, dependentMetadata)) { - final IDataModel dataModel = createDataModel(dependentMetadata, originalMetadata, - new UpdateDependentModuleonRenameProvider()); - dataModel.getDefaultOperation().execute(null, null); - } - } - - private IDataModel createDataModel(final ProjectRefactorMetadata dependentMetadata, - final ProjectRefactorMetadata originalMetadata, - final AbstractDataModelProvider provider) { - final ProjectRefactorMetadata refactoredMetadata = super.getProjectMetadata(); - final IDataModel dataModel = DataModelFactory.createDataModel(provider); - dataModel.setProperty(PROJECT_METADATA, refactoredMetadata); - dataModel.setProperty(DEPENDENT_PROJECT_METADATA, dependentMetadata); - dataModel.setProperty(ORIGINAL_PROJECT_METADATA, originalMetadata); - return dataModel; - } - -} diff --git a/plugins/org.eclipse.jst.j2ee/refactor/org/eclipse/jst/j2ee/refactor/operations/RemoveDeletedComponentFromEARDataModelProvider.java b/plugins/org.eclipse.jst.j2ee/refactor/org/eclipse/jst/j2ee/refactor/operations/RemoveDeletedComponentFromEARDataModelProvider.java deleted file mode 100644 index 1f5e1b112..000000000 --- a/plugins/org.eclipse.jst.j2ee/refactor/org/eclipse/jst/j2ee/refactor/operations/RemoveDeletedComponentFromEARDataModelProvider.java +++ /dev/null @@ -1,59 +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.refactor.operations; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.eclipse.jst.j2ee.application.internal.operations.RemoveComponentFromEnterpriseApplicationDataModelProvider; -import org.eclipse.jst.j2ee.internal.plugin.IJ2EEModuleConstants; -import org.eclipse.wst.common.componentcore.resources.IVirtualComponent; -import org.eclipse.wst.common.frameworks.datamodel.IDataModelOperation; - -public class RemoveDeletedComponentFromEARDataModelProvider extends RemoveComponentFromEnterpriseApplicationDataModelProvider { - - private final ProjectRefactorMetadata _metadata; - public RemoveDeletedComponentFromEARDataModelProvider(final ProjectRefactorMetadata metadata) { - super(); - _metadata = metadata; - } - - @Override - public Object getDefaultProperty(String propertyName) { - if (TARGET_COMPONENTS_TO_URI_MAP.equals(propertyName)) { - Map map = new HashMap(); - List components = (List) getProperty(TARGET_COMPONENT_LIST); - for (int i = 0; i < components.size(); i++) { - IVirtualComponent component = (IVirtualComponent) components.get(i); -// IProject project = component.getProject(); - String name = component.getName(); - if (_metadata.isWeb()) { - name += IJ2EEModuleConstants.WAR_EXT; - } else if (_metadata.isEJB()) { - name += IJ2EEModuleConstants.JAR_EXT; - } else if (_metadata.isAppClient()) { - name += IJ2EEModuleConstants.JAR_EXT; - } else if (_metadata.isConnector()) { - name += IJ2EEModuleConstants.RAR_EXT; - } - map.put(component, name); - } - return map; - } - return super.getDefaultProperty(propertyName); - } - - @Override - public IDataModelOperation getDefaultOperation() { - return new RemoveDeletedComponentFromEAROperation(model); - } -} diff --git a/plugins/org.eclipse.jst.j2ee/refactor/org/eclipse/jst/j2ee/refactor/operations/RemoveDeletedComponentFromEAROperation.java b/plugins/org.eclipse.jst.j2ee/refactor/org/eclipse/jst/j2ee/refactor/operations/RemoveDeletedComponentFromEAROperation.java deleted file mode 100644 index 31531d5a9..000000000 --- a/plugins/org.eclipse.jst.j2ee/refactor/org/eclipse/jst/j2ee/refactor/operations/RemoveDeletedComponentFromEAROperation.java +++ /dev/null @@ -1,35 +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.refactor.operations; - -import java.util.Map; - -import org.eclipse.jst.j2ee.application.internal.operations.RemoveComponentFromEnterpriseApplicationOperation; -import org.eclipse.jst.j2ee.model.IEARModelProvider; -import org.eclipse.wst.common.componentcore.resources.IVirtualComponent; -import org.eclipse.wst.common.frameworks.datamodel.IDataModel; - -public class RemoveDeletedComponentFromEAROperation extends RemoveComponentFromEnterpriseApplicationOperation { - - public RemoveDeletedComponentFromEAROperation(IDataModel model) { - super(model); - } - - @Override - protected String getModuleURI(final IEARModelProvider earModel, final IVirtualComponent targetComponent) { - String uri = earModel.getModuleURI(targetComponent); - if (uri == null) { - Map compToURI = (Map) model.getProperty(RemoveDeletedComponentFromEARDataModelProvider.TARGET_COMPONENTS_TO_URI_MAP); - uri = (String) compToURI.get(targetComponent); - } - return uri; - } -} diff --git a/plugins/org.eclipse.jst.j2ee/refactor/org/eclipse/jst/j2ee/refactor/operations/UpdateDependentEARonDeleteOp.java b/plugins/org.eclipse.jst.j2ee/refactor/org/eclipse/jst/j2ee/refactor/operations/UpdateDependentEARonDeleteOp.java deleted file mode 100644 index 366e44ca2..000000000 --- a/plugins/org.eclipse.jst.j2ee/refactor/org/eclipse/jst/j2ee/refactor/operations/UpdateDependentEARonDeleteOp.java +++ /dev/null @@ -1,80 +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: - * rfrost@bea.com - initial API and implementation - *******************************************************************************/ - -package org.eclipse.jst.j2ee.refactor.operations; - -import java.util.List; -import java.util.Map; - -import org.eclipse.core.commands.ExecutionException; -import org.eclipse.core.runtime.IAdaptable; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.NullProgressMonitor; -import org.eclipse.core.runtime.Status; -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; - -/** - * Subclass of <code>UpdateDependentProjectOp</code> that updates a dependent - * EAR project when one of the referenced projects has been deleted. - */ -public class UpdateDependentEARonDeleteOp extends UpdateDependentProjectOp { - - /** - * Creates a new refactoring operation for the specified data model. - * @param model The data model. - */ - public UpdateDependentEARonDeleteOp(final IDataModel model) { - super(model); - } - - /* (non-Javadoc) - * @see org.eclipse.core.commands.operations.IUndoableOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable) - */ - @Override - public IStatus execute(IProgressMonitor monitor, IAdaptable info) throws ExecutionException { - final ProjectRefactorMetadata dependentMetadata = (ProjectRefactorMetadata) model.getProperty(DEPENDENT_PROJECT_METADATA); - final ProjectRefactorMetadata refactoredMetadata = (ProjectRefactorMetadata) model.getProperty(PROJECT_METADATA); - removeEARDependency(dependentMetadata, refactoredMetadata); - return Status.OK_STATUS; - } - - /** - * Updates the dependent EAR project to account for the deletion of the referenced project. - */ - protected static void removeEARDependency(final ProjectRefactorMetadata dependentMetadata, - final ProjectRefactorMetadata refactoredMetadata) throws ExecutionException { - - // create IVirtualComponents for the EAR and the refactored project - final IVirtualComponent earComp = dependentMetadata.getVirtualComponent(); - final IVirtualComponent refactoredComp = refactoredMetadata.getVirtualComponent(); - final IProgressMonitor monitor = new NullProgressMonitor(); - - // remove the dependency on the deleted project - if (refactoredComp != null) { - final IDataModel model = DataModelFactory.createDataModel(new RemoveDeletedComponentFromEARDataModelProvider(refactoredMetadata)); - model.setProperty(ICreateReferenceComponentsDataModelProperties.SOURCE_COMPONENT, earComp); - final List modHandlesList = (List) model.getProperty(ICreateReferenceComponentsDataModelProperties.TARGET_COMPONENT_LIST); - modHandlesList.add(refactoredComp); - model.setProperty(ICreateReferenceComponentsDataModelProperties.TARGET_COMPONENT_LIST, modHandlesList); - final String moduleURI = refactoredMetadata.getModuleURI(dependentMetadata.getProjectName()); - if (moduleURI != null) { - final Map compToURI = (Map) model.getProperty(RemoveDeletedComponentFromEARDataModelProvider.TARGET_COMPONENTS_TO_URI_MAP); - compToURI.put(refactoredComp, moduleURI); - model.setProperty(RemoveDeletedComponentFromEARDataModelProvider.TARGET_COMPONENTS_TO_URI_MAP, compToURI); - } - model.getDefaultOperation().execute(monitor, null); - } - } -} diff --git a/plugins/org.eclipse.jst.j2ee/refactor/org/eclipse/jst/j2ee/refactor/operations/UpdateDependentEARonDeleteProvider.java b/plugins/org.eclipse.jst.j2ee/refactor/org/eclipse/jst/j2ee/refactor/operations/UpdateDependentEARonDeleteProvider.java deleted file mode 100644 index 57b2b7a71..000000000 --- a/plugins/org.eclipse.jst.j2ee/refactor/org/eclipse/jst/j2ee/refactor/operations/UpdateDependentEARonDeleteProvider.java +++ /dev/null @@ -1,22 +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: - * rfrost@bea.com - initial API and implementation - *******************************************************************************/ - -package org.eclipse.jst.j2ee.refactor.operations; - -import org.eclipse.wst.common.frameworks.datamodel.IDataModelOperation; -public class UpdateDependentEARonDeleteProvider extends UpdateDependentProjectDataModelProvider { - - @Override - public IDataModelOperation getDefaultOperation() { - return new UpdateDependentEARonDeleteOp(model); - } - -} diff --git a/plugins/org.eclipse.jst.j2ee/refactor/org/eclipse/jst/j2ee/refactor/operations/UpdateDependentEARonRenameOp.java b/plugins/org.eclipse.jst.j2ee/refactor/org/eclipse/jst/j2ee/refactor/operations/UpdateDependentEARonRenameOp.java deleted file mode 100644 index 089069139..000000000 --- a/plugins/org.eclipse.jst.j2ee/refactor/org/eclipse/jst/j2ee/refactor/operations/UpdateDependentEARonRenameOp.java +++ /dev/null @@ -1,99 +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: - * rfrost@bea.com - initial API and implementation - *******************************************************************************/ - -package org.eclipse.jst.j2ee.refactor.operations; - -import java.util.ArrayList; -import java.util.List; - -import org.eclipse.core.commands.ExecutionException; -import org.eclipse.core.runtime.IAdaptable; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.NullProgressMonitor; -import org.eclipse.core.runtime.Status; -import org.eclipse.jst.j2ee.application.internal.operations.AddComponentToEnterpriseApplicationDataModelProvider; -import org.eclipse.jst.j2ee.project.facet.IJavaProjectMigrationDataModelProperties; -import org.eclipse.jst.j2ee.project.facet.JavaProjectMigrationDataModelProvider; -import org.eclipse.jst.j2ee.refactor.RefactorResourceHandler; -import org.eclipse.jst.j2ee.refactor.operations.ProjectRefactorMetadata.RefCachingVirtualComponent; -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; - -/** - * Subclass of <code>UpdateDependentProjectOp</code> that updates a dependent - * EAR project when a referenced project has been renamed. - */ -public class UpdateDependentEARonRenameOp extends UpdateDependentProjectOp { - - public UpdateDependentEARonRenameOp(final IDataModel model) { - super(model); - } - - /* (non-Javadoc) - * @see org.eclipse.core.commands.operations.IUndoableOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable) - */ - @Override - public IStatus execute(IProgressMonitor monitor, IAdaptable info) throws ExecutionException { - - final ProjectRefactorMetadata dependentMetadata = (ProjectRefactorMetadata) model.getProperty(DEPENDENT_PROJECT_METADATA); - final ProjectRefactorMetadata originalMetadata = (ProjectRefactorMetadata) model.getProperty(ORIGINAL_PROJECT_METADATA); - final ProjectRefactorMetadata refactoredMetadata = (ProjectRefactorMetadata) model.getProperty(PROJECT_METADATA); - - // create IVirtualComponents for the EAR and the refactored project - final RefCachingVirtualComponent earComp = (RefCachingVirtualComponent) dependentMetadata.getVirtualComponent(); - final IVirtualComponent refactoredComp = refactoredMetadata.getVirtualComponent(); - - if (refactoredComp == null) { - return Status.OK_STATUS; - } - - boolean hadModuleReference = hadReference(dependentMetadata, originalMetadata) != null; - boolean hadProjectReference = hadProjectReference(dependentMetadata, originalMetadata); - - // first, remove the dependency on the old project name via the - // ProjectDeleteOperation - UpdateDependentEARonDeleteOp.removeEARDependency(dependentMetadata, originalMetadata); - - // change to use not use caching - earComp.setCaching(false); - - // add back a dependency on the renamed project - if (refactoredMetadata.hasModuleCoreNature()) { - // the refactored project was a module project - final IDataModel dm = DataModelFactory.createDataModel(new AddComponentToEnterpriseApplicationDataModelProvider()); - dm.setProperty(ICreateReferenceComponentsDataModelProperties.SOURCE_COMPONENT, earComp); - final List depList = new ArrayList(); - depList.add(refactoredComp); - dm.setProperty(ICreateReferenceComponentsDataModelProperties.TARGET_COMPONENT_LIST, depList); - dm.getDefaultOperation().execute(monitor, null); - } else if (refactoredMetadata.hasJavaNature()) { - // the refactored project was a plain java project - final IDataModel migrationdm = DataModelFactory.createDataModel(new JavaProjectMigrationDataModelProvider()); - migrationdm.setProperty(IJavaProjectMigrationDataModelProperties.PROJECT_NAME, refactoredMetadata.getProjectName()); - migrationdm.getDefaultOperation().execute(new NullProgressMonitor(), null); - final IDataModel refdm = DataModelFactory.createDataModel(new CreateOptionalReferenceOpDataModelProvider()); - final List targetCompList = (List) refdm.getProperty(ICreateReferenceComponentsDataModelProperties.TARGET_COMPONENT_LIST); - targetCompList.add(refactoredComp); - refdm.setProperty(ICreateReferenceComponentsDataModelProperties.SOURCE_COMPONENT, earComp); - refdm.setProperty(ICreateReferenceComponentsDataModelProperties.TARGET_COMPONENT_LIST, targetCompList); - refdm.setBooleanProperty(CreateOptionalReferenceOpDataModelProvider.CREATE_COMPONENT_REF,hadModuleReference); - refdm.setBooleanProperty(CreateOptionalReferenceOpDataModelProvider.CREATE_PROJECT_REF,hadProjectReference); - refdm.getDefaultOperation().execute(monitor, null); - } else { - throw new ExecutionException(RefactorResourceHandler.getString("missing_natures"), null); //$NON-NLS-1$ - } - return Status.OK_STATUS; - } - -} diff --git a/plugins/org.eclipse.jst.j2ee/refactor/org/eclipse/jst/j2ee/refactor/operations/UpdateDependentEARonRenameProvider.java b/plugins/org.eclipse.jst.j2ee/refactor/org/eclipse/jst/j2ee/refactor/operations/UpdateDependentEARonRenameProvider.java deleted file mode 100644 index a3339b9ce..000000000 --- a/plugins/org.eclipse.jst.j2ee/refactor/org/eclipse/jst/j2ee/refactor/operations/UpdateDependentEARonRenameProvider.java +++ /dev/null @@ -1,23 +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: - * rfrost@bea.com - initial API and implementation - *******************************************************************************/ - -package org.eclipse.jst.j2ee.refactor.operations; - -import org.eclipse.wst.common.frameworks.datamodel.IDataModelOperation; - -public class UpdateDependentEARonRenameProvider extends UpdateDependentProjectRenameDataModelProvider{ - - @Override - public IDataModelOperation getDefaultOperation() { - return new UpdateDependentEARonRenameOp(model); - } - -} diff --git a/plugins/org.eclipse.jst.j2ee/refactor/org/eclipse/jst/j2ee/refactor/operations/UpdateDependentModuleonDeleteOp.java b/plugins/org.eclipse.jst.j2ee/refactor/org/eclipse/jst/j2ee/refactor/operations/UpdateDependentModuleonDeleteOp.java deleted file mode 100644 index f102b49e8..000000000 --- a/plugins/org.eclipse.jst.j2ee/refactor/org/eclipse/jst/j2ee/refactor/operations/UpdateDependentModuleonDeleteOp.java +++ /dev/null @@ -1,162 +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: - * rfrost@bea.com - initial API and implementation - * IBM - bug 281382 clean up - *******************************************************************************/ - -package org.eclipse.jst.j2ee.refactor.operations; - -import java.io.IOException; -import java.io.InputStream; -import java.util.ArrayList; -import java.util.List; -import java.util.jar.Manifest; - -import org.eclipse.core.commands.ExecutionException; -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IProject; -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.core.runtime.NullProgressMonitor; -import org.eclipse.core.runtime.Path; -import org.eclipse.core.runtime.Status; -import org.eclipse.jst.j2ee.application.internal.operations.UpdateManifestDataModelProperties; -import org.eclipse.jst.j2ee.application.internal.operations.UpdateManifestDataModelProvider; -import org.eclipse.jst.j2ee.commonarchivecore.internal.helpers.ArchiveManifest; -import org.eclipse.jst.j2ee.commonarchivecore.internal.helpers.ArchiveManifestImpl; -import org.eclipse.jst.j2ee.internal.J2EEConstants; -import org.eclipse.jst.j2ee.internal.plugin.IJ2EEModuleConstants; -import org.eclipse.jst.j2ee.refactor.RefactorResourceHandler; -import org.eclipse.wst.common.componentcore.datamodel.properties.ICreateReferenceComponentsDataModelProperties; -import org.eclipse.wst.common.componentcore.internal.operation.RemoveReferenceComponentsDataModelProvider; -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.frameworks.datamodel.DataModelFactory; -import org.eclipse.wst.common.frameworks.datamodel.IDataModel; - -/** - * Subclass of <code>UpdateDependentProjectOp</code> that updates a dependent - * module project when one of the referenced projects has been deleted. - */ -public class UpdateDependentModuleonDeleteOp extends UpdateDependentProjectOp { - - /** - * Creates a new refactoring operation for the specified data model. - * @param model The data model. - */ - public UpdateDependentModuleonDeleteOp(final IDataModel model) { - super(model); - } - - /* (non-Javadoc) - * @see org.eclipse.core.commands.operations.IUndoableOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable) - */ - @Override - public IStatus execute(IProgressMonitor monitor, IAdaptable info) throws ExecutionException { - final ProjectRefactorMetadata dependentMetadata = (ProjectRefactorMetadata) model.getProperty(DEPENDENT_PROJECT_METADATA); - final ProjectRefactorMetadata refactoredMetadata = (ProjectRefactorMetadata) model.getProperty(PROJECT_METADATA); - removeModuleDependency(dependentMetadata, refactoredMetadata); - return Status.OK_STATUS; - } - - /** - * Updates the dependent module project to account for the deletion of the referenced project. - */ - protected static void removeModuleDependency(final ProjectRefactorMetadata dependentMetadata, - final ProjectRefactorMetadata refactoredMetadata) throws ExecutionException { - - // create IVirtualComponents for the dependent and the refactored project - final IVirtualComponent dependentComp = dependentMetadata.getVirtualComponent(); - final IVirtualComponent refactoredComp = refactoredMetadata.getVirtualComponent(); - final IProgressMonitor monitor = new NullProgressMonitor(); - - // Does the dependent project have a .component reference on the refactored project? - final IVirtualReference ref = hadReference(dependentMetadata, refactoredMetadata); - final boolean webLibDep = hasWebLibDependency(ref); - - // remove the component reference on the deleted project - if (refactoredComp != null) { - final IDataModel model = DataModelFactory.createDataModel(new RemoveReferenceComponentsDataModelProvider()); - model.setProperty(ICreateReferenceComponentsDataModelProperties.SOURCE_COMPONENT, dependentComp); - final List modHandlesList = (List) model.getProperty(ICreateReferenceComponentsDataModelProperties.TARGET_COMPONENT_LIST); - modHandlesList.add(refactoredComp); - model.setProperty(ICreateReferenceComponentsDataModelProperties.TARGET_COMPONENT_LIST, modHandlesList); - if (webLibDep) { - model.setProperty(ICreateReferenceComponentsDataModelProperties.TARGET_COMPONENTS_DEPLOY_PATH,"/WEB-INF/lib"); //$NON-NLS-1$ - } - model.getDefaultOperation().execute(monitor, null); - } - - // update the manifest - if (!webLibDep) { - updateManifestDependency(refactoredMetadata, dependentMetadata, true); - } - } - - protected static void updateManifestDependency(final ProjectRefactorMetadata refactoredMetadata, - final ProjectRefactorMetadata dependentMetadata, final boolean remove) throws ExecutionException { - final IVirtualComponent dependentComp = dependentMetadata.getVirtualComponent(); - IProject project= dependentComp.getProject(); - if(project.isAccessible()){ - final String dependentProjName = dependentMetadata.getProjectName(); - final String refactoredProjName = refactoredMetadata.getProjectName(); - final IVirtualFile vf = dependentComp.getRootFolder().getFile(new Path(J2EEConstants.MANIFEST_URI) ); - final IFile manifestmf = vf.getUnderlyingFile(); - // adding this check for https://bugs.eclipse.org/bugs/show_bug.cgi?id=170074 - // (some adopters have non-jst.ear module projects that are missing manifests) - if (!manifestmf.exists()) { - return; - } - final IProgressMonitor monitor = new NullProgressMonitor(); - final IDataModel updateManifestDataModel = DataModelFactory.createDataModel(new UpdateManifestDataModelProvider()); - updateManifestDataModel.setProperty(UpdateManifestDataModelProperties.PROJECT_NAME, dependentProjName); - updateManifestDataModel.setBooleanProperty(UpdateManifestDataModelProperties.MERGE, false); - updateManifestDataModel.setProperty(UpdateManifestDataModelProperties.MANIFEST_FILE, manifestmf); - final ArchiveManifest manifest = getArchiveManifest(manifestmf); - String[] cp = manifest.getClassPathTokenized(); - List cpList = new ArrayList(); - String newCp = refactoredProjName + IJ2EEModuleConstants.JAR_EXT; - for (int i = 0; i < cp.length; i++) { - if (!cp[i].equals(newCp)) { - cpList.add(cp[i]); - } - } - if (!remove) { - cpList.add(newCp); - } - updateManifestDataModel.setProperty(UpdateManifestDataModelProperties.JAR_LIST, cpList); - updateManifestDataModel.getDefaultOperation().execute(monitor, null ); - } - } - - private static ArchiveManifest getArchiveManifest(final IFile manifestFile) throws ExecutionException { - InputStream in = null; - try { - in = manifestFile.getContents(); - ArchiveManifest mf = new ArchiveManifestImpl(new Manifest(in)); - return mf; - } catch (CoreException ce) { - throw new ExecutionException(RefactorResourceHandler.getString("error_reading_manifest"), ce); //$NON-NLS-1$ - } catch (IOException io) { - throw new ExecutionException(RefactorResourceHandler.getString("error_reading_manifest"), io); //$NON-NLS-1$ - } finally { - if (in != null) { - try { - in.close(); - } catch (IOException weTried) { - //Ignore - } - } - } - } - -} diff --git a/plugins/org.eclipse.jst.j2ee/refactor/org/eclipse/jst/j2ee/refactor/operations/UpdateDependentModuleonDeleteProvider.java b/plugins/org.eclipse.jst.j2ee/refactor/org/eclipse/jst/j2ee/refactor/operations/UpdateDependentModuleonDeleteProvider.java deleted file mode 100644 index 5425512c4..000000000 --- a/plugins/org.eclipse.jst.j2ee/refactor/org/eclipse/jst/j2ee/refactor/operations/UpdateDependentModuleonDeleteProvider.java +++ /dev/null @@ -1,22 +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: - * rfrost@bea.com - initial API and implementation - *******************************************************************************/ - -package org.eclipse.jst.j2ee.refactor.operations; - -import org.eclipse.wst.common.frameworks.datamodel.IDataModelOperation; -public class UpdateDependentModuleonDeleteProvider extends UpdateDependentProjectDataModelProvider{ - - @Override - public IDataModelOperation getDefaultOperation() { - return new UpdateDependentModuleonDeleteOp(model); - } - -} diff --git a/plugins/org.eclipse.jst.j2ee/refactor/org/eclipse/jst/j2ee/refactor/operations/UpdateDependentModuleonRenameOp.java b/plugins/org.eclipse.jst.j2ee/refactor/org/eclipse/jst/j2ee/refactor/operations/UpdateDependentModuleonRenameOp.java deleted file mode 100644 index 7939c2917..000000000 --- a/plugins/org.eclipse.jst.j2ee/refactor/org/eclipse/jst/j2ee/refactor/operations/UpdateDependentModuleonRenameOp.java +++ /dev/null @@ -1,88 +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: - * rfrost@bea.com - initial API and implementation - *******************************************************************************/ - -package org.eclipse.jst.j2ee.refactor.operations; - -import java.util.List; - -import org.eclipse.core.commands.ExecutionException; -import org.eclipse.core.runtime.IAdaptable; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; -import org.eclipse.jst.j2ee.refactor.operations.ProjectRefactorMetadata.RefCachingVirtualComponent; -import org.eclipse.wst.common.componentcore.datamodel.properties.ICreateReferenceComponentsDataModelProperties; -import org.eclipse.wst.common.componentcore.resources.IVirtualComponent; -import org.eclipse.wst.common.componentcore.resources.IVirtualReference; -import org.eclipse.wst.common.frameworks.datamodel.DataModelFactory; -import org.eclipse.wst.common.frameworks.datamodel.IDataModel; - -/** - * Subclass of <code>UpdateDependentProjectOp</code> that updates a dependent - * module project when a referenced project has been renamed. - */ -public class UpdateDependentModuleonRenameOp extends UpdateDependentProjectOp { - - public UpdateDependentModuleonRenameOp(final IDataModel model) { - super(model); - } - - /* (non-Javadoc) - * @see org.eclipse.core.commands.operations.IUndoableOperation#execute(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.core.runtime.IAdaptable) - */ - @Override - public IStatus execute(IProgressMonitor monitor, IAdaptable info) throws ExecutionException { - - final ProjectRefactorMetadata dependentMetadata = (ProjectRefactorMetadata) model.getProperty(DEPENDENT_PROJECT_METADATA); - final ProjectRefactorMetadata originalMetadata = (ProjectRefactorMetadata) model.getProperty(ORIGINAL_PROJECT_METADATA); - final ProjectRefactorMetadata refactoredMetadata = (ProjectRefactorMetadata) model.getProperty(PROJECT_METADATA); - - // create IVirtualComponents for the dependent project and the refactored project - final RefCachingVirtualComponent dependentComp = (RefCachingVirtualComponent) dependentMetadata.getVirtualComponent(); - final IVirtualComponent refactoredComp = refactoredMetadata.getVirtualComponent(); - - // Does the dependent project have a component and/or project references on the refactored project? - final IVirtualReference ref = hadReference(dependentMetadata, originalMetadata); - boolean hadModuleRef = ref != null; - boolean hadProjectRef = hadProjectReference(dependentMetadata, originalMetadata); - final boolean webLibDep = hasWebLibDependency(ref); - - // first, remove the dependency on the old project name via the - // ProjectDeleteOperation - UpdateDependentModuleonDeleteOp.removeModuleDependency(dependentMetadata, originalMetadata); - - // change to use not use caching - dependentComp.setCaching(false); - - // add a reference to the renamed project (need to be adding either a component or project ref) - if (refactoredComp != null && (hadModuleRef || hadProjectRef)) { - final IDataModel refdm = DataModelFactory.createDataModel(new CreateOptionalReferenceOpDataModelProvider()); - final List targetCompList = (List) refdm.getProperty(ICreateReferenceComponentsDataModelProperties.TARGET_COMPONENT_LIST); - targetCompList.add(refactoredComp); - refdm.setProperty(ICreateReferenceComponentsDataModelProperties.SOURCE_COMPONENT, dependentComp); - refdm.setProperty(ICreateReferenceComponentsDataModelProperties.TARGET_COMPONENT_LIST, targetCompList); - if (webLibDep) { - refdm.setProperty(ICreateReferenceComponentsDataModelProperties.TARGET_COMPONENTS_DEPLOY_PATH,"/WEB-INF/lib"); //$NON-NLS-1$ - } - refdm.setBooleanProperty(CreateOptionalReferenceOpDataModelProvider.CREATE_COMPONENT_REF,hadModuleRef); - refdm.setBooleanProperty(CreateOptionalReferenceOpDataModelProvider.CREATE_PROJECT_REF,hadProjectRef); - refdm.getDefaultOperation().execute(monitor, null); - } - - // update the manifest, unless this was a web library dependency - if (!webLibDep) { - UpdateDependentModuleonDeleteOp.updateManifestDependency(refactoredMetadata, dependentMetadata, false); - } - - return Status.OK_STATUS; - } - -} diff --git a/plugins/org.eclipse.jst.j2ee/refactor/org/eclipse/jst/j2ee/refactor/operations/UpdateDependentModuleonRenameProvider.java b/plugins/org.eclipse.jst.j2ee/refactor/org/eclipse/jst/j2ee/refactor/operations/UpdateDependentModuleonRenameProvider.java deleted file mode 100644 index 98a56f62b..000000000 --- a/plugins/org.eclipse.jst.j2ee/refactor/org/eclipse/jst/j2ee/refactor/operations/UpdateDependentModuleonRenameProvider.java +++ /dev/null @@ -1,23 +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: - * rfrost@bea.com - initial API and implementation - *******************************************************************************/ - -package org.eclipse.jst.j2ee.refactor.operations; - -import org.eclipse.wst.common.frameworks.datamodel.IDataModelOperation; - -public class UpdateDependentModuleonRenameProvider extends UpdateDependentProjectRenameDataModelProvider { - - @Override - public IDataModelOperation getDefaultOperation() { - return new UpdateDependentModuleonRenameOp(model); - } - -} diff --git a/plugins/org.eclipse.jst.j2ee/refactor/org/eclipse/jst/j2ee/refactor/operations/UpdateDependentProjectDataModelProvider.java b/plugins/org.eclipse.jst.j2ee/refactor/org/eclipse/jst/j2ee/refactor/operations/UpdateDependentProjectDataModelProvider.java deleted file mode 100644 index ded155f0a..000000000 --- a/plugins/org.eclipse.jst.j2ee/refactor/org/eclipse/jst/j2ee/refactor/operations/UpdateDependentProjectDataModelProvider.java +++ /dev/null @@ -1,27 +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: - * rfrost@bea.com - initial API and implementation - *******************************************************************************/ - -package org.eclipse.jst.j2ee.refactor.operations; - -import java.util.Set; - -public abstract class UpdateDependentProjectDataModelProvider extends ProjectRefactoringDataModelProvider { - - /* (non-Javadoc) - * @see org.eclipse.wst.common.frameworks.datamodel.IDataModelProvider#getPropertyNames() - */ - @Override - public Set getPropertyNames() { - Set propertyNames = super.getPropertyNames(); - propertyNames.add(DEPENDENT_PROJECT_METADATA); - return propertyNames; - } -} diff --git a/plugins/org.eclipse.jst.j2ee/refactor/org/eclipse/jst/j2ee/refactor/operations/UpdateDependentProjectOp.java b/plugins/org.eclipse.jst.j2ee/refactor/org/eclipse/jst/j2ee/refactor/operations/UpdateDependentProjectOp.java deleted file mode 100644 index b735168b4..000000000 --- a/plugins/org.eclipse.jst.j2ee/refactor/org/eclipse/jst/j2ee/refactor/operations/UpdateDependentProjectOp.java +++ /dev/null @@ -1,110 +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: - * rfrost@bea.com - initial API and implementation - *******************************************************************************/ - -package org.eclipse.jst.j2ee.refactor.operations; - -import org.eclipse.core.resources.IProject; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.Path; -import org.eclipse.jst.j2ee.internal.plugin.J2EEPlugin; -import org.eclipse.wst.common.componentcore.resources.IVirtualComponent; -import org.eclipse.wst.common.componentcore.resources.IVirtualReference; -import org.eclipse.wst.common.frameworks.datamodel.AbstractDataModelOperation; -import org.eclipse.wst.common.frameworks.datamodel.IDataModel; - -/** - * Abstract base class for operations that update dependent projects when a - * referenced project is refactored. - */ -public abstract class UpdateDependentProjectOp extends AbstractDataModelOperation - implements ProjectRefactoringProperties { - - /** - * Creates a new refactoring operation for the specified data model. - * @param model The data model. - */ - public UpdateDependentProjectOp(final IDataModel model) { - super(model); - } - - /** - * Does the dependent project have a .component reference on the refactored project? - * @return IVirtualReference or null if one didn't exist. - */ - protected static IVirtualReference hadReference(final ProjectRefactorMetadata dependentMetadata, - final ProjectRefactorMetadata refactoredMetadata) { - final IVirtualComponent refactoredComp = refactoredMetadata.getVirtualComponent(); - if (refactoredComp == null) { - return null; - } - final IVirtualReference[] refs = dependentMetadata.getVirtualComponent().getReferences(); - IVirtualReference ref = null; - for (int i = 0; i < refs.length; i++) { - if (refs[i].getReferencedComponent().equals(refactoredComp)) { - ref = refs[i]; - break; - } - } - return ref; - } - - /** - * Does the dependent project have a .project reference on the refactored project? - * (dynamic project refs don't count) - * @return True if a project reference exists. - */ - protected static boolean hadProjectReference(final ProjectRefactorMetadata dependentMetadata, - final ProjectRefactorMetadata refactoredMetadata) { - try { - final IProject[] refs = dependentMetadata.getProject().getDescription().getReferencedProjects(); - final IProject refactoredProject= refactoredMetadata.getProject(); - for (int i = 0; i < refs.length; i++) { - if (refs[i].equals(refactoredProject)) { - return true; - } - } - } catch (CoreException ce) { - J2EEPlugin.logError(ce); - } - return false; - } - - /** - * Returns true if the dependency was a web library dependency. - * @param ref - * @return - */ - protected static boolean hasWebLibDependency(final IVirtualReference ref) { - if (ref == null) { - return false; - } - return ref.getRuntimePath().equals(new Path("/WEB-INF/lib")); //$NON-NLS-1$ - } - - /** - * Override to disable redo support - * @see org.eclipse.core.commands.operations.IUndoableOperation#canRedo() - */ - @Override - public boolean canRedo() { - return false; - } - - /** - * Override to disable undo support. - * @see org.eclipse.core.commands.operations.IUndoableOperation#canUndo() - */ - @Override - public boolean canUndo() { - return false; - } - -} diff --git a/plugins/org.eclipse.jst.j2ee/refactor/org/eclipse/jst/j2ee/refactor/operations/UpdateDependentProjectRenameDataModelProvider.java b/plugins/org.eclipse.jst.j2ee/refactor/org/eclipse/jst/j2ee/refactor/operations/UpdateDependentProjectRenameDataModelProvider.java deleted file mode 100644 index ef8891ba6..000000000 --- a/plugins/org.eclipse.jst.j2ee/refactor/org/eclipse/jst/j2ee/refactor/operations/UpdateDependentProjectRenameDataModelProvider.java +++ /dev/null @@ -1,28 +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: - * rfrost@bea.com - initial API and implementation - *******************************************************************************/ - -package org.eclipse.jst.j2ee.refactor.operations; - -import java.util.Set; - -public abstract class UpdateDependentProjectRenameDataModelProvider extends ProjectRenameDataModelProvider{ - - /* (non-Javadoc) - * @see org.eclipse.wst.common.frameworks.datamodel.IDataModelProvider#getPropertyNames() - */ - @Override - public Set getPropertyNames() { - Set propertyNames = super.getPropertyNames(); - propertyNames.add(DEPENDENT_PROJECT_METADATA); - return propertyNames; - } - -} |