[jbosstools-dev] Fwd: [jbosstools-commits] JBoss Tools SVN: r6173 - in trunk/hibernatetools/plugins/org.hibernate.eclipse.console: src/org/hibernate/eclipse/launch and 2 other directories.

Max Rydahl Andersen max.andersen at redhat.com
Thu Feb 7 14:53:06 EST 2008


hi Dmitry,

Looking at the rename configuration patch you did.

Two questions:

1) Where are the unittests for this ?

2) Why is it relevant to compute the runtimeclasspath for deciding it the configuration is changed ?

/max


+	static boolean isConfigurationChanged(ILaunchConfiguration config, IPath oldPath) throws CoreException{
+		String attrib = null;
+		for (int i = 0; i < stringAttribs.length; i++) {
+			attrib = config.getAttribute(stringAttribs[i], (String)null);
+			if (isAttributeChanged(attrib, oldPath))
+				return true;			
+		}
+		
+		for (int i = 0; i < strListAttribs.length; i++) {
+			List list = config.getAttribute(strListAttribs[i], Collections.EMPTY_LIST);
+			List newMappings = new ArrayList();
+			Iterator iter = list.iterator();
+			while ( iter.hasNext() ) {
+				attrib = (String) iter.next();
+				if (isAttributeChanged(attrib, oldPath)){
+					return true;
+				}
+				newMappings.add(attrib);
+			}
+		}
+		
+		//classpath
+		IRuntimeClasspathEntry[] entries;
+		try {
+			entries = JavaRuntime.computeUnresolvedRuntimeClasspath(config);
+			for (int i = 0; i < entries.length; i++) {
+				IRuntimeClasspathEntry entry = entries[i];
+				if(entry.getClasspathProperty()==IRuntimeClasspathEntry.USER_CLASSES) {
+					attrib = entry.getPath() == null ? null
+							: entry.getPath().toString();
+					if(isAttributeChanged(attrib, oldPath)){
+						return true;
+					}
+				}
+			}
+		}
+		catch (CoreException e) {
+			HibernateConsolePlugin.getDefault().log( e );
+		}
+		
+		return false;
+	}
+	
+	public static boolean isAttributeChanged(String attrib, IPath path){
+		if (attrib == null || path == null) return false;
+		return path.isPrefixOf(new Path(attrib));
+	}
+	
+	public static ILaunchConfiguration updateLaunchConfig(ILaunchConfiguration config, IPath oldPath, IPath newPath) throws CoreException{
+		final ILaunchConfigurationWorkingCopy wc = config.getWorkingCopy();
+		
+		String attrib = null;
+		for (int i = 0; i < stringAttribs.length; i++) {
+			attrib = wc.getAttribute(stringAttribs[i], (String)null);
+			if (isAttributeChanged(attrib, oldPath)){
+				attrib = getUpdatedPath(attrib, oldPath, newPath);
+				wc.setAttribute(stringAttribs[i], attrib);				
+			}
+		}
+		
+		boolean isChanged = false;
+		for (int i = 0; i < strListAttribs.length; i++) {
+			List list = wc.getAttribute(strListAttribs[i], Collections.EMPTY_LIST);
+			isChanged = false;
+			List newMappings = new ArrayList();
+			Iterator iter = list.iterator();
+			while ( iter.hasNext() ) {
+				attrib = (String) iter.next();
+				if (isAttributeChanged(attrib, oldPath)){
+					attrib = getUpdatedPath(attrib, oldPath, newPath);
+					isChanged = true;
+				}
+				newMappings.add(attrib);
+			}
+			if (isChanged) wc.setAttribute(strListAttribs[i], newMappings);
+		}
+		
+		//classpath
+		isChanged = false;
+		IRuntimeClasspathEntry[] entries;		
+		try {
+			entries = JavaRuntime.computeUnresolvedRuntimeClasspath(config);
+			List mementos = new ArrayList(entries.length);
+			for (int i = 0; i < entries.length; i++) {
+				IRuntimeClasspathEntry entry = entries[i];
+				if(entry.getClasspathProperty()==IRuntimeClasspathEntry.USER_CLASSES) {
+					attrib = entry.getPath() == null ? null
+							: entry.getPath().toString();
+					if(isAttributeChanged(attrib, oldPath)){
+						attrib = getUpdatedPath(attrib, oldPath, newPath);
+						IPath p = new Path(attrib).makeAbsolute();
+						
+						switch (entry.getClasspathEntry().getEntryKind()) {
+						case IClasspathEntry.CPE_PROJECT:
+							entry = new RuntimeClasspathEntry( JavaCore.newProjectEntry(p));
+							break;
+						default:
+							entry = JavaRuntime.newArchiveRuntimeClasspathEntry(p);
+							break;
+						} 		
+						
+						entries[i] = entry;
+						isChanged = true;
+					}
+				}
+				mementos.add(entries[i].getMemento());
+			}
+			if (isChanged) wc.setAttribute(IJavaLaunchConfigurationConstants.ATTR_CLASSPATH, mementos);
+		}
+		catch (CoreException e) {
+			HibernateConsolePlugin.getDefault().log( e );
+		}
+		
+		//JavaMigrationDelegate.updateResourceMapping(wc);
+		
+		if (wc.isDirty()) {
+			return wc.doSave();
+		} else {
+			return config;
+		}
+	}
+	
+	private static String getUpdatedPath(String attrib, IPath oldPath, IPath newPath){
+		IPath attribPath = new Path(attrib);
+		IPath newAttribPath = Path.EMPTY;
+		for (int j = 0; j < attribPath.segmentCount(); j++){
+			if (!oldPath.isPrefixOf(attribPath.removeFirstSegments(j))){
+				//add prefix
+				newAttribPath = newAttribPath.append(attribPath.segment(j));
+			} else {
+				newAttribPath = newAttribPath.append(newPath);	//add new path instead of old path
+				// add suffix
+				newAttribPath = newAttribPath.append(attribPath.removeFirstSegments(j + oldPath.segmentCount()));
+				break;
+			}
+		}
+		return newAttribPath.toString();
+	}
+	
+	public static ILaunchConfiguration[] getChangedLaunchConfigurations(IPath path){
+		ILaunchConfiguration[] configs = null;
+		try {
+			configs = DebugPlugin.getDefault().getLaunchManager().getLaunchConfigurations();
+			ArrayList list = new ArrayList();
+			for(int i = 0; i < configs.length; i++) {
+				//ILaunchConfigurationWorkingCopy wc = configs[i].getWorkingCopy();
+				if (HibernateRefactoringUtil.isConfigurationChanged(configs[i], path)) list.add(configs[i]);
+			}
+			configs = (ILaunchConfiguration[])list.toArray(new ILaunchConfiguration[list.size()]);
+		}
+		catch(CoreException e) {
+			configs = new ILaunchConfiguration[0];
+			HibernateConsolePlugin.getDefault().logErrorMessage( ERROR_MESS, e );
+		}
+		
+		return configs;
+	}
+	
+	/**
+	 * @param changes - List of Change objects
+	 * @return
+	 */
+	public static Change createChangesFromList(List changes, String name) {
+		if (changes.size() == 0) {
+			return null;
+		} else if (changes.size() == 1) {
+			return (Change) changes.get(0);
+		} else {
+			return new CompositeChange(name, (Change[])changes.toArray(new Change[changes.size()]));
+		}
+	}
+}


Property changes on: trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/core/refactoring/HibernateRefactoringUtil.java
___________________________________________________________________
Name: svn:mime-type
  + text/plain
Name: svn:keywords
  + Author Id Revision Date
Name: svn:eol-style
  + native

Added: trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/core/refactoring/LaunchConfigurationResourceNameChange.java
===================================================================
--- trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/core/refactoring/LaunchConfigurationResourceNameChange.java	                        (rev 0)
+++ trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/core/refactoring/LaunchConfigurationResourceNameChange.java	2008-02-07 16:19:37 UTC (rev 6173)
@@ -0,0 +1,77 @@
+/*******************************************************************************
+  * Copyright (c) 2007-2008 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
+  *
+  * Contributor:
+  *     Red Hat, Inc. - initial API and implementation
+  ******************************************************************************/
+package org.hibernate.eclipse.launch.core.refactoring;
+
+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.debug.core.ILaunchConfiguration;
+import org.eclipse.ltk.core.refactoring.Change;
+import org.eclipse.ltk.core.refactoring.RefactoringStatus;
+
+/**
+ * @author Dmitry Geraskov
+ *
+ */
+public class LaunchConfigurationResourceNameChange extends Change {
+	
+	private ILaunchConfiguration fLaunchConfiguration;
+	private IPath fOldPath;
+	private IPath fNewPath;
+	
+	/**
+	 * LaunchConfigurationResourceMoveChange constructor.
+	 * @param launchConfiguration the launch configuration to modify
+	 * @param oldPath the old Path of the resource.
+	 * @param newPath the new Path of the resource.
+	 */
+	LaunchConfigurationResourceNameChange(ILaunchConfiguration launchConfiguration, IPath oldPath, IPath newPath){
+		fLaunchConfiguration = launchConfiguration;
+		fOldPath = oldPath;
+		fNewPath = newPath;
+	}
+
+	/* (non-Javadoc)
+	 * @see org.eclipse.ltk.core.refactoring.Change#getModifiedElement()
+	 */
+	public Object getModifiedElement() {
+		return fLaunchConfiguration;
+	}
+
+	/* (non-Javadoc)
+	 * @see org.eclipse.ltk.core.refactoring.Change#getName()
+	 */
+	public String getName() {
+		return "Update resource path in launch configuration " + fLaunchConfiguration.getName();
+	}
+
+	/* (non-Javadoc)
+	 * @see org.eclipse.ltk.core.refactoring.Change#initializeValidationData(org.eclipse.core.runtime.IProgressMonitor)
+	 */
+	public void initializeValidationData(IProgressMonitor pm) {	}
+
+	/* (non-Javadoc)
+	 * @see org.eclipse.ltk.core.refactoring.Change#isValid(org.eclipse.core.runtime.IProgressMonitor)
+	 */
+	public RefactoringStatus isValid(IProgressMonitor pm) throws CoreException,
+			OperationCanceledException {
+		return new RefactoringStatus();
+	}
+
+	/* (non-Javadoc)
+	 * @see org.eclipse.ltk.core.refactoring.Change#perform(org.eclipse.core.runtime.IProgressMonitor)
+	 */
+	public Change perform(IProgressMonitor pm) throws CoreException {
+		fLaunchConfiguration = HibernateRefactoringUtil.updateLaunchConfig(fLaunchConfiguration, fOldPath, fNewPath);			
+		return new LaunchConfigurationResourceNameChange(fLaunchConfiguration, fNewPath, fOldPath);
+	}
+}


Property changes on: trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/core/refactoring/LaunchConfigurationResourceNameChange.java
___________________________________________________________________
Name: svn:mime-type
  + text/plain
Name: svn:keywords
  + Author Id Revision Date
Name: svn:eol-style
  + native

Added: trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/core/refactoring/MoveResourceParticipant.java
===================================================================
--- trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/core/refactoring/MoveResourceParticipant.java	                        (rev 0)
+++ trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/core/refactoring/MoveResourceParticipant.java	2008-02-07 16:19:37 UTC (rev 6173)
@@ -0,0 +1,48 @@
+package org.hibernate.eclipse.launch.core.refactoring;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.OperationCanceledException;
+import org.eclipse.debug.core.ILaunchConfiguration;
+import org.eclipse.ltk.core.refactoring.Change;
+import org.eclipse.ltk.core.refactoring.RefactoringStatus;
+import org.eclipse.ltk.core.refactoring.participants.CheckConditionsContext;
+import org.eclipse.ltk.core.refactoring.participants.MoveParticipant;
+
+public class MoveResourceParticipant extends MoveParticipant {
+	
+	private IResource fResource;
+
+	public RefactoringStatus checkConditions(IProgressMonitor pm,
+			CheckConditionsContext context) throws OperationCanceledException {
+		return new RefactoringStatus();
+	}
+
+	public Change createChange(IProgressMonitor pm) throws CoreException,
+			OperationCanceledException {
+		ILaunchConfiguration[] configs = HibernateRefactoringUtil.getChangedLaunchConfigurations(fResource.getFullPath());
+		
+		List changes = new ArrayList();		
+		LaunchConfigurationResourceNameChange change = null;
+		for (int i= 0; i < configs.length; i++) {
+			change = new LaunchConfigurationResourceNameChange(configs[i], fResource.getFullPath(), ((IResource)getArguments().getDestination()).getFullPath().append(fResource.getName()));
+			changes.add(change);
+		}
+
+		return HibernateRefactoringUtil.createChangesFromList(changes, getName());
+	}
+
+	public String getName() {
+		return "Launch Configurations updates";
+	}
+
+	protected boolean initialize(Object element) {		
+		fResource = (IResource) element;
+		return true;
+	}
+
+}


Property changes on: trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/core/refactoring/MoveResourceParticipant.java
___________________________________________________________________
Name: svn:mime-type
  + text/plain
Name: svn:keywords
  + Author Id Revision Date
Name: svn:eol-style
  + native

Added: trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/core/refactoring/RenameResourceParticipant.java
===================================================================
--- trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/core/refactoring/RenameResourceParticipant.java	                        (rev 0)
+++ trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/core/refactoring/RenameResourceParticipant.java	2008-02-07 16:19:37 UTC (rev 6173)
@@ -0,0 +1,77 @@
+/*******************************************************************************
+  * Copyright (c) 2007-2008 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
+  *
+  * Contributor:
+  *     Red Hat, Inc. - initial API and implementation
+  ******************************************************************************/
+package org.hibernate.eclipse.launch.core.refactoring;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.OperationCanceledException;
+import org.eclipse.debug.core.ILaunchConfiguration;
+import org.eclipse.ltk.core.refactoring.Change;
+import org.eclipse.ltk.core.refactoring.RefactoringStatus;
+import org.eclipse.ltk.core.refactoring.participants.CheckConditionsContext;
+import org.eclipse.ltk.core.refactoring.participants.RenameParticipant;
+
+/**
+ * @author Dmitry Geraskov
+ *
+ */
+public class RenameResourceParticipant extends RenameParticipant {
+	
+	private IResource fResource;
+
+	/* (non-Javadoc)
+	 * @see org.eclipse.ltk.core.refactoring.participants.RefactoringParticipant#checkConditions(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.ltk.core.refactoring.participants.CheckConditionsContext)
+	 */
+	public RefactoringStatus checkConditions(IProgressMonitor pm,
+			CheckConditionsContext context) throws OperationCanceledException {
+		return new RefactoringStatus();
+	}
+
+	/* (non-Javadoc)
+	 * @see org.eclipse.ltk.core.refactoring.participants.RefactoringParticipant#createChange(org.eclipse.core.runtime.IProgressMonitor)
+	 */
+	public Change createChange(IProgressMonitor pm) throws CoreException,
+			OperationCanceledException {
+		ILaunchConfiguration[] configs = HibernateRefactoringUtil.getChangedLaunchConfigurations(fResource.getFullPath());
+		
+		List changes = new ArrayList();		
+		LaunchConfigurationResourceNameChange change = null;
+		for (int i= 0; i < configs.length; i++) {
+			change = new LaunchConfigurationResourceNameChange(configs[i], fResource.getFullPath(),
+					fResource.getParent().getFullPath().append(getArguments().getNewName()));
+			changes.add(change);
+		}
+
+		return HibernateRefactoringUtil.createChangesFromList(changes, getName());
+	}
+	
+	
+	
+	/* (non-Javadoc)
+	 * @see org.eclipse.ltk.core.refactoring.participants.RefactoringParticipant#getName()
+	 */
+	public String getName() {
+		return "Launch Configurations updates";
+	}
+
+	/* (non-Javadoc)
+	 * @see org.eclipse.ltk.core.refactoring.participants.RefactoringParticipant#initialize(java.lang.Object)
+	 */
+	protected boolean initialize(Object element) {		
+		fResource = (IResource) element;
+		return true;
+	}
+
+}


Property changes on: trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/core/refactoring/RenameResourceParticipant.java
___________________________________________________________________
Name: svn:mime-type
  + text/plain
Name: svn:keywords
  + Author Id Revision Date
Name: svn:eol-style
  + native

_______________________________________________
jbosstools-commits mailing list
jbosstools-commits at lists.jboss.org
https://lists.jboss.org/mailman/listinfo/jbosstools-commits



-- 
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/




More information about the jbosstools-dev mailing list