[jbosstools-commits] JBoss Tools SVN: r7096 - in trunk/seam: plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/refactoring and 1 other directories.
jbosstools-commits at lists.jboss.org
jbosstools-commits at lists.jboss.org
Mon Mar 24 14:36:14 EDT 2008
Author: akazakov
Date: 2008-03-24 14:36:14 -0400 (Mon, 24 Mar 2008)
New Revision: 7096
Added:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/refactoring/SeamFolderRenameChange.java
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/refactoring/SeamFolderRenameParticipant.java
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/refactoring/SeamJavaPackageRenameChange.java
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/refactoring/SeamJavaPackageRenameParticipant.java
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/refactoring/SeamProjectRenameChange.java
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/refactoring/SeamProjectRenameParticipant.java
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/refactoring/SeamRenameParticipant.java
Removed:
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/refactoring/SeamRenameFolderChange.java
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/refactoring/SeamRenameFolderParticipant.java
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/refactoring/SeamRenameProjectChange.java
trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/refactoring/SeamRenameProjectParticipant.java
Modified:
trunk/seam/plugins/org.jboss.tools.seam.core/plugin.xml
trunk/seam/tests/org.jboss.tools.seam.core.test/src/org/jboss/tools/seam/core/test/refactoring/SeamPropertyRefactoringTest.java
Log:
http://jira.jboss.com/jira/browse/JBIDE-1919 Added package name refactoring.
Modified: trunk/seam/plugins/org.jboss.tools.seam.core/plugin.xml
===================================================================
--- trunk/seam/plugins/org.jboss.tools.seam.core/plugin.xml 2008-03-24 18:00:37 UTC (rev 7095)
+++ trunk/seam/plugins/org.jboss.tools.seam.core/plugin.xml 2008-03-24 18:36:14 UTC (rev 7096)
@@ -293,8 +293,8 @@
point="org.eclipse.ltk.core.refactoring.renameParticipants">
<renameParticipant
- class="org.jboss.tools.seam.internal.core.refactoring.SeamRenameProjectParticipant"
- id="org.jboss.tools.seam.internal.core.refactoring.SeamRenameProjectParticipant"
+ class="org.jboss.tools.seam.internal.core.refactoring.SeamProjectRenameParticipant"
+ id="org.jboss.tools.seam.internal.core.refactoring.SeamProjectRenameParticipant"
name="seam-RenameProjectParticipant">
<enablement>
<with variable="element">
@@ -305,8 +305,8 @@
</enablement>
</renameParticipant>
<renameParticipant
- class="org.jboss.tools.seam.internal.core.refactoring.SeamRenameFolderParticipant"
- id="org.jboss.tools.seam.internal.core.refactoring.SeamRenameFolderParticipant"
+ class="org.jboss.tools.seam.internal.core.refactoring.SeamFolderRenameParticipant"
+ id="org.jboss.tools.seam.internal.core.refactoring.SeamFolderRenameParticipant"
name="seam-RenameFolderParticipant">
<enablement>
<with variable="element">
@@ -316,6 +316,18 @@
</with>
</enablement>
</renameParticipant>
+ <renameParticipant
+ class="org.jboss.tools.seam.internal.core.refactoring.SeamJavaPackageRenameParticipant"
+ id="org.jboss.tools.seam.internal.core.refactoring.SeamJavaPackageRenameParticipant"
+ name="seam-JavaPackageRenameParticipant">
+ <enablement>
+ <with variable="element">
+ <or>
+ <instanceof value="org.eclipse.jdt.core.IPackageFragment"/>
+ </or>
+ </with>
+ </enablement>
+ </renameParticipant>
</extension>
Copied: trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/refactoring/SeamFolderRenameChange.java (from rev 7049, trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/refactoring/SeamRenameFolderChange.java)
===================================================================
--- trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/refactoring/SeamFolderRenameChange.java (rev 0)
+++ trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/refactoring/SeamFolderRenameChange.java 2008-03-24 18:36:14 UTC (rev 7096)
@@ -0,0 +1,96 @@
+ /*******************************************************************************
+ * Copyright (c) 2007 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is 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:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.seam.internal.core.refactoring;
+
+import java.util.ArrayList;
+import java.util.List;
+
+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.core.runtime.preferences.IEclipsePreferences;
+import org.eclipse.ltk.core.refactoring.Change;
+import org.jboss.tools.seam.core.SeamCorePlugin;
+import org.osgi.service.prefs.BackingStoreException;
+
+/**
+ * @author Alexey Kazakov
+ */
+public class SeamFolderRenameChange extends SeamProjectChange {
+
+ private IPath oldPath;
+ private IPath newPath;
+
+ private List<String> relevantProperties = new ArrayList<String>();
+
+ public SeamFolderRenameChange(IProject project, String newName, IPath oldPath) {
+ super(project);
+ this.oldPath = oldPath;
+ this.newPath = oldPath.removeLastSegments(1).append(newName);
+
+ IEclipsePreferences ps = getSeamPreferences();
+ for (int i = 0; i < FOLDER_PROPERTIES.length; i++) {
+ String propertyValue = ps.get(FOLDER_PROPERTIES[i], null);
+ if(propertyValue==null) {
+ continue;
+ }
+ String oldPathString = oldPath.toString();
+ if(propertyValue.equals(oldPathString) ||
+ propertyValue.startsWith(oldPathString + "/")) {
+ relevantProperties.add(FOLDER_PROPERTIES[i]);
+ }
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.jboss.tools.seam.internal.core.refactoring.SeamProjectChange#isRelevant()
+ */
+ @Override
+ public boolean isRelevant() {
+ return relevantProperties.size()>0;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ltk.core.refactoring.Change#perform(org.eclipse.core.runtime.IProgressMonitor)
+ */
+ @Override
+ public Change perform(IProgressMonitor pm) throws CoreException {
+ if(!isRelevant()) {
+ return null;
+ }
+ try {
+ pm.beginTask(getName(), 1);
+
+ IEclipsePreferences ps = getSeamPreferences();
+ for (String propertyName: relevantProperties) {
+ String propertyValue = ps.get(propertyName, "");
+ String oldPathString = oldPath.toString();
+ if(propertyValue.equals(oldPathString)) {
+ ps.put(propertyName, newPath.toString());
+ } else if(propertyValue.startsWith(oldPathString + "/")) {
+ String newPathString = newPath.toString() + propertyValue.substring(oldPathString.length());
+ ps.put(propertyName, newPathString);
+ }
+ }
+
+ try {
+ ps.flush();
+ } catch (BackingStoreException e) {
+ SeamCorePlugin.getPluginLog().logError(e);
+ }
+ return new SeamFolderRenameChange(project, oldPath.lastSegment(), newPath);
+ } finally {
+ pm.done();
+ }
+ }
+}
\ No newline at end of file
Copied: trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/refactoring/SeamFolderRenameParticipant.java (from rev 7050, trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/refactoring/SeamRenameFolderParticipant.java)
===================================================================
--- trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/refactoring/SeamFolderRenameParticipant.java (rev 0)
+++ trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/refactoring/SeamFolderRenameParticipant.java 2008-03-24 18:36:14 UTC (rev 7096)
@@ -0,0 +1,58 @@
+ /*******************************************************************************
+ * Copyright (c) 2007 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is 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:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.seam.internal.core.refactoring;
+
+import org.eclipse.core.resources.IFolder;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.IPath;
+
+/**
+ * Updates seam settings of seam projects if somebody renames source folder.
+ * @author Alexey Kazakov
+ */
+public class SeamFolderRenameParticipant extends SeamRenameParticipant {
+
+ public static final String PARTICIPANT_NAME="seam-FolderRenameParticipant";
+
+ private IPath oldPath;
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.ltk.core.refactoring.participants.RefactoringParticipant#getName()
+ */
+ @Override
+ public String getName() {
+ return PARTICIPANT_NAME;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.ltk.core.refactoring.participants.RefactoringParticipant#initialize(java.lang.Object)
+ */
+ @Override
+ protected boolean initialize(Object element) {
+ if(!(element instanceof IFolder)) {
+ return false;
+ }
+ oldPath = ((IResource)element).getFullPath();
+
+ return true;
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.tools.seam.internal.core.refactoring.SeamRenameParticipant#createChange(org.eclipse.core.resources.IProject, java.lang.String)
+ */
+ @Override
+ protected SeamProjectChange createChange(IProject project, String newName) {
+ return new SeamFolderRenameChange(project, newName, oldPath);
+ }
+}
\ No newline at end of file
Added: trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/refactoring/SeamJavaPackageRenameChange.java
===================================================================
--- trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/refactoring/SeamJavaPackageRenameChange.java (rev 0)
+++ trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/refactoring/SeamJavaPackageRenameChange.java 2008-03-24 18:36:14 UTC (rev 7096)
@@ -0,0 +1,111 @@
+ /*******************************************************************************
+ * Copyright (c) 2007 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is 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:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.seam.internal.core.refactoring;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.preferences.IEclipsePreferences;
+import org.eclipse.jdt.core.IPackageFragmentRoot;
+import org.eclipse.ltk.core.refactoring.Change;
+import org.jboss.tools.seam.core.SeamCorePlugin;
+import org.jboss.tools.seam.internal.core.project.facet.ISeamFacetDataModelProperties;
+import org.osgi.service.prefs.BackingStoreException;
+
+/**
+ * @author Alexey Kazakov
+ */
+public class SeamJavaPackageRenameChange extends SeamProjectChange {
+
+ protected static String[] PACKAGE_NAME_PROPERTIES = {
+ ISeamFacetDataModelProperties.ENTITY_BEAN_PACKAGE_NAME,
+ ISeamFacetDataModelProperties.SESSION_BEAN_PACKAGE_NAME,
+ ISeamFacetDataModelProperties.TEST_CASES_PACKAGE_NAME
+ };
+ protected static String[] SOURCE_NAME_PROPERTIES = {
+ ISeamFacetDataModelProperties.ENTITY_BEAN_SOURCE_FOLDER,
+ ISeamFacetDataModelProperties.SESSION_BEAN_SOURCE_FOLDER,
+ ISeamFacetDataModelProperties.TEST_SOURCE_FOLDER
+ };
+
+ private IPackageFragmentRoot source;
+ private String newName;
+ private String oldName;
+ private List<Integer> relevantPropertyIndexes = new ArrayList<Integer>();
+
+ /**
+ * @param project
+ */
+ public SeamJavaPackageRenameChange(IProject project, IPackageFragmentRoot source, String newName, String oldName) {
+ super(project);
+ this.source = source;
+ this.newName = newName;
+ this.oldName = oldName;
+ IEclipsePreferences ps = getSeamPreferences();
+ for (int i = 0; i < PACKAGE_NAME_PROPERTIES.length; i++) {
+ String name = ps.get(PACKAGE_NAME_PROPERTIES[i], null);
+ if(name!=null && (oldName.equals(name) || name.startsWith(oldName + "."))) {
+ relevantPropertyIndexes.add(new Integer(i));
+ }
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.tools.seam.internal.core.refactoring.SeamProjectChange#isRelevant()
+ */
+ @Override
+ public boolean isRelevant() {
+ return relevantPropertyIndexes.size()>0;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ltk.core.refactoring.Change#perform(org.eclipse.core.runtime.IProgressMonitor)
+ */
+ @Override
+ public Change perform(IProgressMonitor pm) throws CoreException {
+ if(!isRelevant()) {
+ return null;
+ }
+ try {
+ pm.beginTask(getName(), 1);
+
+ IEclipsePreferences ps = getSeamPreferences();
+ for (Integer index: relevantPropertyIndexes) {
+ String sourceFolderProperty = ps.get(SOURCE_NAME_PROPERTIES[index], null);
+ if(!source.getResource().getFullPath().toString().equals(sourceFolderProperty)) {
+ continue;
+ }
+ String packageProperty = PACKAGE_NAME_PROPERTIES[index];
+ String name = ps.get(packageProperty, null);
+ if(name==null) {
+ continue;
+ }
+ if(oldName.equals(name)) {
+ ps.put(packageProperty, newName);
+ } else if(name.startsWith(oldName + ".")) {
+ ps.put(packageProperty, newName + name.substring(oldName.length()));
+ }
+ }
+
+ try {
+ ps.flush();
+ } catch (BackingStoreException e) {
+ SeamCorePlugin.getPluginLog().logError(e);
+ }
+ return new SeamJavaPackageRenameChange(project, source, oldName, newName);
+ } finally {
+ pm.done();
+ }
+ }
+}
\ No newline at end of file
Added: trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/refactoring/SeamJavaPackageRenameParticipant.java
===================================================================
--- trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/refactoring/SeamJavaPackageRenameParticipant.java (rev 0)
+++ trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/refactoring/SeamJavaPackageRenameParticipant.java 2008-03-24 18:36:14 UTC (rev 7096)
@@ -0,0 +1,59 @@
+ /*******************************************************************************
+ * Copyright (c) 2007 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is 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:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.seam.internal.core.refactoring;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.jdt.core.IJavaElement;
+import org.eclipse.jdt.core.IPackageFragment;
+import org.eclipse.jdt.core.IPackageFragmentRoot;
+
+/**
+ * @author Alexey Kazakov
+ */
+public class SeamJavaPackageRenameParticipant extends SeamRenameParticipant {
+
+ public static final String PARTICIPANT_NAME="seam-JavaPackageRenameParticipant";
+
+ private String oldName;
+ private IPackageFragmentRoot source;
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ltk.core.refactoring.Change#getName()
+ */
+ @Override
+ public String getName() {
+ return PARTICIPANT_NAME;
+ }
+
+ @Override
+ protected boolean initialize(Object element) {
+ if(!(element instanceof IPackageFragment)) {
+ return false;
+ }
+ IPackageFragment packageFragment = (IPackageFragment)element;
+ oldName = packageFragment.getElementName();
+ IJavaElement parent = packageFragment.getParent();
+ if(parent instanceof IPackageFragmentRoot) {
+ source = (IPackageFragmentRoot)parent;
+ return true;
+ }
+
+ return false;
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.tools.seam.internal.core.refactoring.SeamRenameParticipant#createChange(org.eclipse.core.resources.IProject, java.lang.String)
+ */
+ @Override
+ protected SeamProjectChange createChange(IProject project, String newName) {
+ return new SeamJavaPackageRenameChange(project, source, newName, oldName);
+ }
+}
\ No newline at end of file
Copied: trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/refactoring/SeamProjectRenameChange.java (from rev 7049, trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/refactoring/SeamRenameProjectChange.java)
===================================================================
--- trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/refactoring/SeamProjectRenameChange.java (rev 0)
+++ trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/refactoring/SeamProjectRenameChange.java 2008-03-24 18:36:14 UTC (rev 7096)
@@ -0,0 +1,110 @@
+/*******************************************************************************
+ * Copyright (c) 2007 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is 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:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.seam.internal.core.refactoring;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.preferences.IEclipsePreferences;
+import org.eclipse.ltk.core.refactoring.Change;
+import org.jboss.tools.seam.core.SeamCorePlugin;
+import org.osgi.service.prefs.BackingStoreException;
+
+/**
+ * @author Viacheslav Kabanovich
+ */
+public class SeamProjectRenameChange extends SeamProjectChange {
+
+ protected String newName;
+ protected String oldName;
+
+ private List<String> relevantProjectNameProperties = new ArrayList<String>();
+ private List<String> relevantSourceFolderProperties = new ArrayList<String>();
+
+ /**
+ * @param project
+ * @param newName
+ * @param oldName
+ */
+ public SeamProjectRenameChange(IProject project, String newName, String oldName) {
+ super(project);
+ this.newName = newName;
+ this.oldName = oldName;
+ IEclipsePreferences ps = getSeamPreferences();
+ for (int i = 0; i < PROJECT_NAME_PROPERTIES.length; i++) {
+ if(oldName.equals(ps.get(PROJECT_NAME_PROPERTIES[i], null))) {
+ relevantProjectNameProperties.add(PROJECT_NAME_PROPERTIES[i]);
+ }
+ }
+ for (int i = 0; i < FOLDER_PROPERTIES.length; i++) {
+ if(ps.get(FOLDER_PROPERTIES[i], "").startsWith("/" + oldName + "/")) {
+ relevantSourceFolderProperties.add(FOLDER_PROPERTIES[i]);
+ }
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.jboss.tools.seam.internal.core.refactoring.SeamProjectChange#isRelevant()
+ */
+ @Override
+ public boolean isRelevant() {
+ return relevantProjectNameProperties.size() > 0 || relevantSourceFolderProperties.size() > 0;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.ltk.core.refactoring.Change#perform(org.eclipse.core.runtime.IProgressMonitor)
+ */
+ @Override
+ public Change perform(IProgressMonitor pm) throws CoreException {
+ if(!isRelevant()) {
+ return null;
+ }
+ try {
+ pm.beginTask(getName(), 1);
+
+ if(project.getName().equals(oldName)) {
+ IResource newProject = ResourcesPlugin.getWorkspace().getRoot().findMember(newName);
+ if(!project.exists() && (newProject instanceof IProject) && newProject.exists()) {
+ project = (IProject)newProject;
+ }
+ }
+ IEclipsePreferences ps = getSeamPreferences();
+ for (String property: relevantProjectNameProperties) {
+ if(oldName.equals(ps.get(property, null))) {
+ ps.put(property, newName);
+ }
+ }
+ String oldPrefix = "/" + oldName + "/";
+ for (String property: relevantSourceFolderProperties) {
+ String oldProperty = ps.get(property, "");
+ if(oldProperty.startsWith(oldPrefix) && oldProperty.length()>oldPrefix.length()) {
+ ps.put(property, "/" + newName + "/" + oldProperty.substring(oldPrefix.length()));
+ }
+ }
+
+ try {
+ ps.flush();
+ } catch (BackingStoreException e) {
+ SeamCorePlugin.getPluginLog().logError(e);
+ }
+ return new SeamProjectRenameChange(project, oldName, newName);
+ } finally {
+ pm.done();
+ }
+ }
+}
\ No newline at end of file
Copied: trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/refactoring/SeamProjectRenameParticipant.java (from rev 7049, trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/refactoring/SeamRenameProjectParticipant.java)
===================================================================
--- trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/refactoring/SeamProjectRenameParticipant.java (rev 0)
+++ trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/refactoring/SeamProjectRenameParticipant.java 2008-03-24 18:36:14 UTC (rev 7096)
@@ -0,0 +1,48 @@
+/*******************************************************************************
+ * Copyright (c) 2007 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is 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:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.seam.internal.core.refactoring;
+
+import org.eclipse.core.resources.IProject;
+
+/**
+ * @author Viacheslav Kabanovich
+ */
+public class SeamProjectRenameParticipant extends SeamRenameParticipant {
+
+ public static final String PARTICIPANT_NAME="seam-ProjectRenameParticipant";
+
+ private String oldName;
+
+ /* (non-Javadoc)
+ * @see org.eclipse.ltk.core.refactoring.Change#getName()
+ */
+ @Override
+ public String getName() {
+ return PARTICIPANT_NAME;
+ }
+
+ @Override
+ protected boolean initialize(Object element) {
+ if(!(element instanceof IProject)) {
+ return false;
+ }
+ oldName = ((IProject)element).getName();
+ return true;
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.tools.seam.internal.core.refactoring.SeamRenameParticipant#createChange(org.eclipse.core.resources.IProject, java.lang.String)
+ */
+ @Override
+ protected SeamProjectChange createChange(IProject project, String newName) {
+ return new SeamProjectRenameChange(project, newName, oldName);
+ }
+}
\ No newline at end of file
Deleted: trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/refactoring/SeamRenameFolderChange.java
===================================================================
--- trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/refactoring/SeamRenameFolderChange.java 2008-03-24 18:00:37 UTC (rev 7095)
+++ trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/refactoring/SeamRenameFolderChange.java 2008-03-24 18:36:14 UTC (rev 7096)
@@ -1,96 +0,0 @@
- /*******************************************************************************
- * Copyright (c) 2007 Red Hat, Inc.
- * Distributed under license by Red Hat, Inc. All rights reserved.
- * This program is 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:
- * Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
-package org.jboss.tools.seam.internal.core.refactoring;
-
-import java.util.ArrayList;
-import java.util.List;
-
-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.core.runtime.preferences.IEclipsePreferences;
-import org.eclipse.ltk.core.refactoring.Change;
-import org.jboss.tools.seam.core.SeamCorePlugin;
-import org.osgi.service.prefs.BackingStoreException;
-
-/**
- * @author Alexey Kazakov
- */
-public class SeamRenameFolderChange extends SeamProjectChange {
-
- private IPath oldPath;
- private IPath newPath;
-
- private List<String> relevantProperties = new ArrayList<String>();
-
- public SeamRenameFolderChange(IProject project, String newName, IPath oldPath) {
- super(project);
- this.oldPath = oldPath;
- this.newPath = oldPath.removeLastSegments(1).append(newName);
-
- IEclipsePreferences ps = getSeamPreferences();
- for (int i = 0; i < FOLDER_PROPERTIES.length; i++) {
- String propertyValue = ps.get(FOLDER_PROPERTIES[i], null);
- if(propertyValue==null) {
- continue;
- }
- String oldPathString = oldPath.toString();
- if(propertyValue.equals(oldPathString) ||
- propertyValue.startsWith(oldPathString + "/")) {
- relevantProperties.add(FOLDER_PROPERTIES[i]);
- }
- }
- }
-
- /*
- * (non-Javadoc)
- * @see org.jboss.tools.seam.internal.core.refactoring.SeamProjectChange#isRelevant()
- */
- @Override
- public boolean isRelevant() {
- return relevantProperties.size()>0;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.ltk.core.refactoring.Change#perform(org.eclipse.core.runtime.IProgressMonitor)
- */
- @Override
- public Change perform(IProgressMonitor pm) throws CoreException {
- if(!isRelevant()) {
- return null;
- }
- try {
- pm.beginTask(getName(), 1);
-
- IEclipsePreferences ps = getSeamPreferences();
- for (String propertyName: relevantProperties) {
- String propertyValue = ps.get(propertyName, "");
- String oldPathString = oldPath.toString();
- if(propertyValue.equals(oldPathString)) {
- ps.put(propertyName, newPath.toString());
- } else if(propertyValue.startsWith(oldPathString + "/")) {
- String newPathString = newPath.toString() + propertyValue.substring(oldPathString.length());
- ps.put(propertyName, newPathString);
- }
- }
-
- try {
- ps.flush();
- } catch (BackingStoreException e) {
- SeamCorePlugin.getPluginLog().logError(e);
- }
- return new SeamRenameFolderChange(project, oldPath.lastSegment(), newPath);
- } finally {
- pm.done();
- }
- }
-}
\ No newline at end of file
Deleted: trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/refactoring/SeamRenameFolderParticipant.java
===================================================================
--- trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/refactoring/SeamRenameFolderParticipant.java 2008-03-24 18:00:37 UTC (rev 7095)
+++ trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/refactoring/SeamRenameFolderParticipant.java 2008-03-24 18:36:14 UTC (rev 7096)
@@ -1,78 +0,0 @@
- /*******************************************************************************
- * Copyright (c) 2007 Red Hat, Inc.
- * Distributed under license by Red Hat, Inc. All rights reserved.
- * This program is 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:
- * Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
-package org.jboss.tools.seam.internal.core.refactoring;
-
-import org.eclipse.core.resources.IFolder;
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.IResource;
-import org.eclipse.core.resources.ResourcesPlugin;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.OperationCanceledException;
-import org.eclipse.ltk.core.refactoring.Change;
-import org.eclipse.ltk.core.refactoring.CompositeChange;
-import org.eclipse.ltk.core.refactoring.RefactoringStatus;
-import org.eclipse.ltk.core.refactoring.participants.CheckConditionsContext;
-import org.eclipse.ltk.core.refactoring.participants.RenameParticipant;
-
-/**
- * Updates seam settings of seam projects if somebody renames source folder.
- * @author Alexey Kazakov
- */
-public class SeamRenameFolderParticipant extends RenameParticipant {
- public static final String PARTICIPANT_NAME="seam-RenameFolderParticipant";
-
- private IPath oldPath;
-
- public SeamRenameFolderParticipant() {
- }
-
- @Override
- public RefactoringStatus checkConditions(IProgressMonitor pm, CheckConditionsContext context) throws OperationCanceledException {
- return null;
- }
-
- @Override
- public Change createChange(IProgressMonitor pm) throws CoreException, OperationCanceledException {
- if (!pm.isCanceled()) {
- String newName = getArguments().getNewName();
- if(newName == null || newName.trim().length() == 0) {
- return null;
- }
- CompositeChange change = new CompositeChange("Update Seam Projects");
- IProject[] ps = ResourcesPlugin.getWorkspace().getRoot().getProjects();
- for (int i = 0; i < ps.length; i++) {
- SeamRenameFolderChange c = new SeamRenameFolderChange(ps[i], newName, oldPath);
- if(c.isRelevant()) change.add(c);
- }
- if(change.getChildren().length > 0) {
- return change;
- }
- }
- return null;
- }
-
- @Override
- public String getName() {
- return PARTICIPANT_NAME;
- }
-
- @Override
- protected boolean initialize(Object element) {
- if(!(element instanceof IFolder)) {
- return false;
- }
- oldPath = ((IResource)element).getFullPath();
-
- return true;
- }
-}
\ No newline at end of file
Added: trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/refactoring/SeamRenameParticipant.java
===================================================================
--- trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/refactoring/SeamRenameParticipant.java (rev 0)
+++ trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/refactoring/SeamRenameParticipant.java 2008-03-24 18:36:14 UTC (rev 7096)
@@ -0,0 +1,63 @@
+ /*******************************************************************************
+ * Copyright (c) 2007 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is 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:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.jboss.tools.seam.internal.core.refactoring;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.OperationCanceledException;
+import org.eclipse.ltk.core.refactoring.Change;
+import org.eclipse.ltk.core.refactoring.CompositeChange;
+import org.eclipse.ltk.core.refactoring.RefactoringStatus;
+import org.eclipse.ltk.core.refactoring.participants.CheckConditionsContext;
+import org.eclipse.ltk.core.refactoring.participants.RenameParticipant;
+
+/**
+ * @author Alexey Kazakov
+ */
+abstract public class SeamRenameParticipant extends RenameParticipant {
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.ltk.core.refactoring.participants.RefactoringParticipant#checkConditions(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.ltk.core.refactoring.participants.CheckConditionsContext)
+ */
+ @Override
+ public RefactoringStatus checkConditions(IProgressMonitor pm, CheckConditionsContext context) throws OperationCanceledException {
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.ltk.core.refactoring.participants.RefactoringParticipant#createChange(org.eclipse.core.runtime.IProgressMonitor)
+ */
+ @Override
+ public Change createChange(IProgressMonitor pm) throws CoreException, OperationCanceledException {
+ if (!pm.isCanceled()) {
+ String newName = getArguments().getNewName();
+ if(newName == null || newName.trim().length() == 0) {
+ return null;
+ }
+ CompositeChange change = new CompositeChange("Update Seam Projects");
+ IProject[] ps = ResourcesPlugin.getWorkspace().getRoot().getProjects();
+ for (int i = 0; i < ps.length; i++) {
+ SeamProjectChange c = createChange(ps[i], newName);
+ if(c.isRelevant()) change.add(c);
+ }
+ if(change.getChildren().length > 0) {
+ return change;
+ }
+ }
+ return null;
+ }
+
+ abstract protected SeamProjectChange createChange(IProject project, String newName);
+}
\ No newline at end of file
Deleted: trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/refactoring/SeamRenameProjectChange.java
===================================================================
--- trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/refactoring/SeamRenameProjectChange.java 2008-03-24 18:00:37 UTC (rev 7095)
+++ trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/refactoring/SeamRenameProjectChange.java 2008-03-24 18:36:14 UTC (rev 7096)
@@ -1,108 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007 Red Hat, Inc.
- * Distributed under license by Red Hat, Inc. All rights reserved.
- * This program is 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:
- * Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
-package org.jboss.tools.seam.internal.core.refactoring;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.IResource;
-import org.eclipse.core.resources.ResourcesPlugin;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.preferences.IEclipsePreferences;
-import org.eclipse.ltk.core.refactoring.Change;
-import org.jboss.tools.seam.core.SeamCorePlugin;
-import org.osgi.service.prefs.BackingStoreException;
-
-/**
- * @author Viacheslav Kabanovich
- */
-public class SeamRenameProjectChange extends SeamProjectChange {
-
- protected String newName;
- protected String oldName;
-
- private List<String> relevantProjectNameProperties = new ArrayList<String>();
- private List<String> relevantSourceFolderProperties = new ArrayList<String>();
-
- /**
- * @param project
- * @param newName
- * @param oldName
- */
- public SeamRenameProjectChange(IProject project, String newName, String oldName) {
- super(project);
- this.newName = newName;
- this.oldName = oldName;
- IEclipsePreferences ps = getSeamPreferences();
- for (int i = 0; i < PROJECT_NAME_PROPERTIES.length; i++) {
- if(oldName.equals(ps.get(PROJECT_NAME_PROPERTIES[i], null))) {
- relevantProjectNameProperties.add(PROJECT_NAME_PROPERTIES[i]);
- }
- }
- for (int i = 0; i < FOLDER_PROPERTIES.length; i++) {
- if(ps.get(FOLDER_PROPERTIES[i], "").startsWith("/" + oldName + "/")) {
- relevantSourceFolderProperties.add(FOLDER_PROPERTIES[i]);
- }
- }
- }
-
- /*
- * (non-Javadoc)
- * @see org.jboss.tools.seam.internal.core.refactoring.SeamProjectChange#isRelevant()
- */
- @Override
- public boolean isRelevant() {
- return relevantProjectNameProperties.size() > 0 || relevantSourceFolderProperties.size() > 0;
- }
-
- /*
- * (non-Javadoc)
- * @see org.eclipse.ltk.core.refactoring.Change#perform(org.eclipse.core.runtime.IProgressMonitor)
- */
- @Override
- public Change perform(IProgressMonitor pm) throws CoreException {
- if(!isRelevant()) return null;
- try {
- pm.beginTask(getName(), 1);
-
- if(project.getName().equals(oldName)) {
- IResource newProject = ResourcesPlugin.getWorkspace().getRoot().findMember(newName);
- if(!project.exists() && (newProject instanceof IProject) && newProject.exists()) {
- project = (IProject)newProject;
- }
- }
- IEclipsePreferences ps = getSeamPreferences();
- for (String property: relevantProjectNameProperties) {
- if(oldName.equals(ps.get(property, null))) {
- ps.put(property, newName);
- }
- }
- String oldPrefix = "/" + oldName + "/";
- for (String property: relevantSourceFolderProperties) {
- String oldProperty = ps.get(property, "");
- if(oldProperty.startsWith(oldPrefix) && oldProperty.length()>oldPrefix.length()) {
- ps.put(property, "/" + newName + "/" + oldProperty.substring(oldPrefix.length()));
- }
- }
-
- try {
- ps.flush();
- } catch (BackingStoreException e) {
- SeamCorePlugin.getPluginLog().logError(e);
- }
- return new SeamRenameProjectChange(project, oldName, newName);
- } finally {
- pm.done();
- }
- }
-}
\ No newline at end of file
Deleted: trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/refactoring/SeamRenameProjectParticipant.java
===================================================================
--- trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/refactoring/SeamRenameProjectParticipant.java 2008-03-24 18:00:37 UTC (rev 7095)
+++ trunk/seam/plugins/org.jboss.tools.seam.core/src/org/jboss/tools/seam/internal/core/refactoring/SeamRenameProjectParticipant.java 2008-03-24 18:36:14 UTC (rev 7096)
@@ -1,73 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007 Red Hat, Inc.
- * Distributed under license by Red Hat, Inc. All rights reserved.
- * This program is 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:
- * Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
-package org.jboss.tools.seam.internal.core.refactoring;
-
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.ResourcesPlugin;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.OperationCanceledException;
-import org.eclipse.ltk.core.refactoring.Change;
-import org.eclipse.ltk.core.refactoring.CompositeChange;
-import org.eclipse.ltk.core.refactoring.RefactoringStatus;
-import org.eclipse.ltk.core.refactoring.participants.CheckConditionsContext;
-import org.eclipse.ltk.core.refactoring.participants.RenameParticipant;
-
-/**
- * @author Viacheslav Kabanovich
- */
-public class SeamRenameProjectParticipant extends RenameParticipant {
- public static final String PARTICIPANT_NAME="seam-RenameProjectParticipant";
-
- IProject project;
- String oldName;
-
- public SeamRenameProjectParticipant() {}
-
- @Override
- public RefactoringStatus checkConditions(IProgressMonitor pm, CheckConditionsContext context) throws OperationCanceledException {
- return null;
- }
-
- @Override
- public Change createChange(IProgressMonitor pm) throws CoreException, OperationCanceledException {
- if (!pm.isCanceled()) {
- String newName = getArguments().getNewName();
- if(newName == null || newName.trim().length() == 0) return null;
- CompositeChange change = new CompositeChange("Update Seam Projects");
- IProject[] ps = ResourcesPlugin.getWorkspace().getRoot().getProjects();
- for (int i = 0; i < ps.length; i++) {
- SeamRenameProjectChange c = new SeamRenameProjectChange(ps[i], newName, oldName);
- if(c.isRelevant()) change.add(c);
- }
- if(change.getChildren().length > 0) return change;
- }
- return null;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.ltk.core.refactoring.Change#getName()
- */
- @Override
- public String getName() {
- return PARTICIPANT_NAME;
- }
-
- @Override
- protected boolean initialize(Object element) {
- if(!(element instanceof IProject)) {
- return false;
- }
- project = (IProject)element;
- oldName = project.getName();
- return true;
- }
-}
\ No newline at end of file
Modified: trunk/seam/tests/org.jboss.tools.seam.core.test/src/org/jboss/tools/seam/core/test/refactoring/SeamPropertyRefactoringTest.java
===================================================================
--- trunk/seam/tests/org.jboss.tools.seam.core.test/src/org/jboss/tools/seam/core/test/refactoring/SeamPropertyRefactoringTest.java 2008-03-24 18:00:37 UTC (rev 7095)
+++ trunk/seam/tests/org.jboss.tools.seam.core.test/src/org/jboss/tools/seam/core/test/refactoring/SeamPropertyRefactoringTest.java 2008-03-24 18:36:14 UTC (rev 7096)
@@ -23,7 +23,9 @@
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
+import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.IPackageFragment;
import org.eclipse.jdt.core.IPackageFragmentRoot;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.core.JavaModelException;
@@ -62,6 +64,9 @@
static String testSourceFolderPath = "/" + testProjectName + "/" + testSourceFolderName;
static String viewFolderName = "WebContent";
static String viewFolderPath = "/" + warProjectName + "/" + viewFolderName;
+ static String actionPackageName = "ejbdemo";
+ static String modelPackageName = "wardemo";
+ static String testPackageName = "testdemo";
static IProject warProject;
static IProject ejbProject;
static IProject testProject;
@@ -115,18 +120,7 @@
updateFields();
warProject = renameProject(warProject, warProjectName);
seamWarProject = SeamCorePlugin.getSeamProject(warProject, true);
-
- String newParentName = seamEjbProject.getParentProjectName();
- assertEquals("WAR project was renamed but parent seam project property for EJB project was not.", warProjectName, newParentName);
- newParentName = seamTestProject.getParentProjectName();
- assertEquals("WAR project was renamed but parent seam project property for test project was not.", warProjectName, newParentName);
-
- IEclipsePreferences pref = SeamCorePlugin.getSeamPreferences(warProject);
- String modelSources = pref.get(ISeamFacetDataModelProperties.ENTITY_BEAN_SOURCE_FOLDER, "");
- assertEquals("WAR project was renamed but model source folder property was not.", modelSourceFolderPath, modelSources);
-
- String viewFolder = pref.get(ISeamFacetDataModelProperties.WEB_CONTENTS_FOLDER, "");
- assertEquals("WAR project was renamed but view folder property was not.", viewFolderPath, viewFolder);
+ assertCorrectProperties();
}
public void testEjbProjectRename() throws CoreException {
@@ -134,13 +128,7 @@
updateFields();
ejbProject = renameProject(ejbProject, ejbProjectName);
seamEjbProject = SeamCorePlugin.getSeamProject(ejbProject, true);
-
- IEclipsePreferences pref = SeamCorePlugin.getSeamPreferences(warProject);
- String newEjbName = pref.get(ISeamFacetDataModelProperties.SEAM_EJB_PROJECT, "");
- assertEquals("EJB project was renamed but property was not.", ejbProjectName, newEjbName);
-
- String actionSources = pref.get(ISeamFacetDataModelProperties.SESSION_BEAN_SOURCE_FOLDER, "");
- assertEquals("EJB project was renamed but action source folder property was not.", actionSourceFolderPath, actionSources);
+ assertCorrectProperties();
}
public void testTestProjectRename() throws CoreException {
@@ -148,53 +136,91 @@
updateFields();
testProject = renameProject(testProject, testProjectName);
seamTestProject = SeamCorePlugin.getSeamProject(testProject, true);
-
- String newTestName = SeamCorePlugin.getSeamPreferences(warProject).get(ISeamFacetDataModelProperties.SEAM_TEST_PROJECT, "");
- assertEquals("Test project was renamed but property was not.", testProjectName, newTestName);
-
- IEclipsePreferences pref = SeamCorePlugin.getSeamPreferences(warProject);
- String testSources = pref.get(ISeamFacetDataModelProperties.TEST_SOURCE_FOLDER, "");
- assertEquals("Test project was renamed but test source folder property was not.", testSourceFolderPath, testSources);
+ assertCorrectProperties();
}
public void testActionSourceFolderRename() throws CoreException {
actionSourceFolderName = "newActionSrc";
renameSourceFolder(actionSourceFolderPath, actionSourceFolderName);
- updateFields();
-
- IEclipsePreferences pref = SeamCorePlugin.getSeamPreferences(warProject);
- String actionSources = pref.get(ISeamFacetDataModelProperties.SESSION_BEAN_SOURCE_FOLDER, "");
- assertEquals("Action source folder was renamed but property was not.", actionSourceFolderPath, actionSources);
+ assertCorrectProperties();
}
public void testModelSourceFolderRename() throws CoreException {
modelSourceFolderName = "newModelSrc";
renameSourceFolder(modelSourceFolderPath, modelSourceFolderName);
- updateFields();
-
- IEclipsePreferences pref = SeamCorePlugin.getSeamPreferences(warProject);
- String modelSources = pref.get(ISeamFacetDataModelProperties.ENTITY_BEAN_SOURCE_FOLDER, "");
- assertEquals("Model source folder was renamed but property was not.", modelSourceFolderPath, modelSources);
+ assertCorrectProperties();
}
public void testTestSourceFolderRename() throws CoreException {
testSourceFolderName = "newTestSrc";
renameSourceFolder(testSourceFolderPath, testSourceFolderName);
- updateFields();
-
- IEclipsePreferences pref = SeamCorePlugin.getSeamPreferences(warProject);
- String testSources = pref.get(ISeamFacetDataModelProperties.TEST_SOURCE_FOLDER, "");
- assertEquals("Test source folder was renamed but property was not.", testSourceFolderPath, testSources);
+ assertCorrectProperties();
}
public void testViewFolderRename() throws CoreException {
viewFolderName = "newViewFolder";
renameFolder(viewFolderPath, viewFolderName);
+ assertCorrectProperties();
+ }
+
+ public void testActionPackageRename() throws CoreException {
+ String oldName = actionPackageName;
+ actionPackageName = "newejbdemo";
+ renamePackage(actionSourceFolderPath, oldName, actionPackageName);
+ assertCorrectProperties();
+ }
+
+ public void testModelPackageRename() throws CoreException {
+ String oldName = modelPackageName;
+ modelPackageName = "newwardemo";
+ renamePackage(modelSourceFolderPath, oldName, modelPackageName);
+ assertCorrectProperties();
+ }
+
+ public void testTestPackageRename() throws CoreException {
+ String oldName = testPackageName;
+ testPackageName = "newtestdemo";
+ renamePackage(testSourceFolderPath, oldName, testPackageName);
+ assertCorrectProperties();
+ }
+
+ private void assertCorrectProperties() {
updateFields();
IEclipsePreferences pref = SeamCorePlugin.getSeamPreferences(warProject);
+
+ String parentName = seamEjbProject.getParentProjectName();
+ assertEquals("Parent seam project property for EJB project was not updated.", warProjectName, parentName);
+
+ parentName = seamTestProject.getParentProjectName();
+ assertEquals("Parent seam project property for Test project was not updated.", warProjectName, parentName);
+
+ String ejbName = pref.get(ISeamFacetDataModelProperties.SEAM_EJB_PROJECT, "");
+ assertEquals("EJB project name property was not updated.", ejbProjectName, ejbName);
+
+ String testName = pref.get(ISeamFacetDataModelProperties.SEAM_TEST_PROJECT, "");
+ assertEquals("Test project name property was not updated.", testProjectName, testName);
+
+ String actionSources = pref.get(ISeamFacetDataModelProperties.SESSION_BEAN_SOURCE_FOLDER, "");
+ assertEquals("Action source folder property was not updated.", actionSourceFolderPath, actionSources);
+
+ String modelSources = pref.get(ISeamFacetDataModelProperties.ENTITY_BEAN_SOURCE_FOLDER, "");
+ assertEquals("Model source folder property was not.", modelSourceFolderPath, modelSources);
+
+ String testSources = pref.get(ISeamFacetDataModelProperties.TEST_SOURCE_FOLDER, "");
+ assertEquals("Test source folder property was not updated.", testSourceFolderPath, testSources);
+
String viewFolder = pref.get(ISeamFacetDataModelProperties.WEB_CONTENTS_FOLDER, "");
- assertEquals("View folder was renamed but property was not.", viewFolderPath, viewFolder);
+ assertEquals("View folder property was not updated.", viewFolderPath, viewFolder);
+
+ String actionPackage = pref.get(ISeamFacetDataModelProperties.SESSION_BEAN_PACKAGE_NAME, "");
+ assertEquals("Action package name property was not updated.", actionPackageName, actionPackage);
+
+ String modelPackage = pref.get(ISeamFacetDataModelProperties.ENTITY_BEAN_PACKAGE_NAME, "");
+ assertEquals("Model package name property was not updated.", modelPackageName, modelPackage);
+
+ String testPackage = pref.get(ISeamFacetDataModelProperties.TEST_CASES_PACKAGE_NAME, "");
+ assertEquals("Test package name property was not updated.", testPackageName, testPackage);
}
private void updateFields() {
@@ -278,6 +304,52 @@
return (IFolder)resource;
}
+ private IPackageFragment renamePackage(String sourceFolderPath, String oldPackageName, String newPackageName) throws CoreException {
+ IResource resource = ResourcesPlugin.getWorkspace().getRoot().findMember(sourceFolderPath);
+ assertNotNull("Can't find source folder: " + sourceFolderPath, resource);
+ IProject project = resource.getProject();
+ IJavaProject javaProject = EclipseResourceUtil.getJavaProject(project);
+ assertNotNull("Can't find java project: " + project.getName(), javaProject);
+ IPackageFragmentRoot root = null;
+ try {
+ IPackageFragmentRoot[] roots = javaProject.getPackageFragmentRoots();
+ for (int i = 0; i < roots.length; i++) {
+ if (roots[i].getKind() == IPackageFragmentRoot.K_SOURCE && roots[i].getResource().getFullPath().toString().equals(sourceFolderPath)) {
+ root = roots[i];
+ break;
+ }
+ }
+ } catch (JavaModelException e) {
+ JUnitUtils.fail("Can't find source folder: " + sourceFolderPath, e);
+ }
+ assertNotNull("Can't find source folder: " + sourceFolderPath, root);
+
+ IPackageFragment oldPackage = findPackage(root, oldPackageName);
+ assertNotNull("Can't find package \"" + oldPackageName + "\". So it's impossible to rename it.", oldPackage);
+
+ IJavaElement[] packages = root.getChildren();
+ performRename(RenameSupport.create(oldPackage, newPackageName, RenameSupport.UPDATE_REFERENCES));
+
+ IPackageFragment newPackage = findPackage(root, newPackageName);
+ assertNotNull("Can't find renamed package \"" + newPackageName + "\". It seems this package was not renamed.", newPackage);
+ return null;
+ }
+
+ private IPackageFragment findPackage(IPackageFragmentRoot root, String packageName) {
+ IJavaElement[] packages = null;
+ try {
+ packages = root.getChildren();
+ } catch (JavaModelException e) {
+ JUnitUtils.fail("Can't find package: " + packageName, e);
+ }
+ for (IJavaElement javaElement : packages) {
+ if(javaElement instanceof IPackageFragment && javaElement.getElementName().equals(packageName)) {
+ return (IPackageFragment)javaElement;
+ }
+ }
+ return null;
+ }
+
private IProject renameProject(IProject project, String newProjectName) throws CoreException {
performRename(RenameSupport.create(JavaCore.create(project), newProjectName, RenameSupport.UPDATE_REFERENCES));
More information about the jbosstools-commits
mailing list