Author: dgeraskov
Date: 2009-12-21 02:59:50 -0500 (Mon, 21 Dec 2009)
New Revision: 19490
Added:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/core/refactoring/CodeGenerationReseourceNameChange.java
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/HibernateConsoleMessages.properties
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/utils/LaunchHelper.java
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/ICodeGenerationLaunchConstants.java
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/core/refactoring/ConnectionProfileRenameChange.java
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/core/refactoring/HibernateRefactoringUtil.java
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/MoveResourceParticipant.java
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/core/refactoring/RenameResourceParticipant.java
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/console/test/RefactoringTest.java
Log:
https://jira.jboss.org/jira/browse/JBIDE-5499
Refactoring for hibernate code generation configuration.
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/HibernateConsoleMessages.properties
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/HibernateConsoleMessages.properties 2009-12-21
07:21:33 UTC (rev 19489)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/HibernateConsoleMessages.properties 2009-12-21
07:59:50 UTC (rev 19490)
@@ -481,7 +481,7 @@
HibernateRefactoringUtil_error_during_refactoring=Error during refactoring
HibernateRefactoringUtil_error_occured_while_updating_classpath=Error occured while
updating classpath.
-LaunchConfigurationResourceNameChange_update_resource_path_in_launch_cfg=Update resource
path in launch configuration
+LaunchConfigurationResourceNameChange_update_resource_path_in_launch_cfg=Update resource
path in launch configuration ''{0}''
MoveResourceParticipant_launch_configurations_updates=Launch Configurations updates
RenameResourceParticipant_launch_configurations_updates=Launch Configurations updates
DeleteResourceParticipant_hibernate_configurations_updates=Hibernate Configurations
updates
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/utils/LaunchHelper.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/utils/LaunchHelper.java 2009-12-21
07:21:33 UTC (rev 19489)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/utils/LaunchHelper.java 2009-12-21
07:59:50 UTC (rev 19490)
@@ -157,4 +157,26 @@
}
return false;
}
+
+ //***************************** Hibernate Code Generation Launch Configurations
************
+
+ public static ILaunchConfiguration[] findFilteredCodeGenerationConfigs() throws
CoreException{
+ ILaunchConfiguration[] allHibernateLaunchConfigurations = findCodeGenerationConfigs();
+ List<ILaunchConfiguration> launchConfigurations = new
ArrayList<ILaunchConfiguration>();
+ for (ILaunchConfiguration config : allHibernateLaunchConfigurations) {
+ if (DebugUIPlugin.doLaunchConfigurationFiltering(config))
launchConfigurations.add(config);
+ }
+ return launchConfigurations.toArray(new
ILaunchConfiguration[launchConfigurations.size()]);
+ }
+
+ public static ILaunchConfiguration[] findCodeGenerationConfigs() throws CoreException {
+ ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager();
+ return launchManager.getLaunchConfigurations(getCodeGenerationType());
+ }
+
+ public static ILaunchConfigurationType getCodeGenerationType(){
+ ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager();
+ return launchManager.getLaunchConfigurationType(
+ ICodeGenerationLaunchConstants.CODE_GENERATION_LAUNCH_TYPE_ID);
+ }
}
\ No newline at end of file
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/ICodeGenerationLaunchConstants.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/ICodeGenerationLaunchConstants.java 2009-12-21
07:21:33 UTC (rev 19489)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/ICodeGenerationLaunchConstants.java 2009-12-21
07:59:50 UTC (rev 19490)
@@ -3,6 +3,7 @@
public interface ICodeGenerationLaunchConstants {
static final String CONSOLE_CONFIGURATION_LAUNCH_TYPE_ID =
"org.hibernate.eclipse.launch.ConsoleConfigurationLaunchConfigurationType";
//$NON-NLS-1$
+ static final String CODE_GENERATION_LAUNCH_TYPE_ID =
"org.hibernate.eclipse.launch.CodeGenerationLaunchConfigurationType";//$NON-NLS-1$
static final int ERR_UNSPECIFIED_CONSOLE_CONFIGURATION = 1000;
static final int ERR_CONSOLE_CONFIGURATION_NOTFOUND = 1001;
static final int ERR_OUTPUT_PATH_NOTFOUND = 1002;
Added:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/core/refactoring/CodeGenerationReseourceNameChange.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/core/refactoring/CodeGenerationReseourceNameChange.java
(rev 0)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/core/refactoring/CodeGenerationReseourceNameChange.java 2009-12-21
07:59:50 UTC (rev 19490)
@@ -0,0 +1,65 @@
+/*******************************************************************************
+ * Copyright (c) 2009 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;
+import org.eclipse.osgi.util.NLS;
+import org.hibernate.eclipse.console.HibernateConsoleMessages;
+
+/**
+ * @author Dmitry Geraskov
+ *
+ */
+public class CodeGenerationReseourceNameChange extends Change {
+
+ private ILaunchConfiguration fLaunchConfiguration;
+ private IPath fOldPath;
+ private IPath fNewPath;
+
+ CodeGenerationReseourceNameChange(ILaunchConfiguration launchConfiguration, IPath
oldPath, IPath newPath){
+ fLaunchConfiguration = launchConfiguration;
+ fOldPath = oldPath;
+ fNewPath = newPath;
+ }
+
+ @Override
+ public Object getModifiedElement() {
+ return fLaunchConfiguration;
+ }
+
+ @Override
+ public String getName() {
+ return
NLS.bind(HibernateConsoleMessages.LaunchConfigurationResourceNameChange_update_resource_path_in_launch_cfg,
fLaunchConfiguration.getName());
+ }
+
+ @Override
+ public void initializeValidationData(IProgressMonitor pm) { }
+
+ @Override
+ public RefactoringStatus isValid(IProgressMonitor pm) throws CoreException,
+ OperationCanceledException {
+ return new RefactoringStatus();
+ }
+
+ @Override
+ public Change perform(IProgressMonitor pm) throws CoreException {
+ fLaunchConfiguration =
HibernateRefactoringUtil.updateCodeGenerationConfig(fLaunchConfiguration, fOldPath,
fNewPath);
+ return new CodeGenerationReseourceNameChange(fLaunchConfiguration, fNewPath,
fOldPath);
+ }
+
+}
Property changes on:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/core/refactoring/CodeGenerationReseourceNameChange.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Author Id Revision Date
Name: svn:eol-style
+ native
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/core/refactoring/ConnectionProfileRenameChange.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/core/refactoring/ConnectionProfileRenameChange.java 2009-12-21
07:21:33 UTC (rev 19489)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/core/refactoring/ConnectionProfileRenameChange.java 2009-12-21
07:59:50 UTC (rev 19490)
@@ -73,9 +73,7 @@
return new RefactoringStatus();
}
- /* (non-Javadoc)
- * @see
org.eclipse.ltk.core.refactoring.Change#perform(org.eclipse.core.runtime.IProgressMonitor)
- */
+ @SuppressWarnings("deprecation")
@Override
public Change perform(IProgressMonitor pm) throws CoreException {
if (fLaunchConfiguration.exists()){
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/core/refactoring/HibernateRefactoringUtil.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/core/refactoring/HibernateRefactoringUtil.java 2009-12-21
07:21:33 UTC (rev 19489)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/core/refactoring/HibernateRefactoringUtil.java 2009-12-21
07:59:50 UTC (rev 19490)
@@ -15,8 +15,10 @@
import java.io.StringWriter;
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 javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
@@ -67,37 +69,51 @@
private static final String ERROR_MESS =
HibernateConsoleMessages.HibernateRefactoringUtil_error_during_refactoring;
- private static String[] pathKeys = new String[]{
+ private static String[] ccKeys = new String[]{
IConsoleConfigurationLaunchConstants.CFG_XML_FILE,
IConsoleConfigurationLaunchConstants.PROPERTY_FILE,
HibernateLaunchConstants.ATTR_TEMPLATE_DIR,
HibernateLaunchConstants.ATTR_OUTPUT_DIR,
HibernateLaunchConstants.ATTR_REVERSE_ENGINEER_SETTINGS,
};
+
+ private static String[] cgKeys = new String[]{
+ HibernateLaunchConstants.ATTR_TEMPLATE_DIR,
+ HibernateLaunchConstants.ATTR_OUTPUT_DIR,
+ HibernateLaunchConstants.ATTR_REVERSE_ENGINEER_SETTINGS,
+ };
- private static String[] pathListKeys = new String[]{
+ private static String[] ccListKeys = new String[]{
IConsoleConfigurationLaunchConstants.FILE_MAPPINGS,
};
- public static boolean isConfigurationAffected(ILaunchConfiguration config, IPath
oldPath) throws CoreException{
- return isAttributesAffected(config, oldPath) || isClassPathAffected(config, oldPath);
+ public static boolean isConsoleConfigAffected(ILaunchConfiguration config, IPath
oldPath) throws CoreException{
+ return isAttributesAffected(config, oldPath, ccKeys) ||
isListAttributesAffected(config, oldPath, ccListKeys)
+ || isClassPathAffected(config, oldPath);
}
+
+ public static boolean isCodeGenerationConfigAffected(ILaunchConfiguration config, IPath
oldPath) throws CoreException{
+ return isAttributesAffected(config, oldPath, cgKeys) || isExportersAffected(config,
oldPath);
+ }
- @SuppressWarnings("unchecked")
- private static boolean isAttributesAffected(ILaunchConfiguration config, IPath oldPath)
throws CoreException{
+ private static boolean isAttributesAffected(ILaunchConfiguration config, IPath oldPath,
String[] paths) throws CoreException{
String attrib = null;
- for (int i = 0; i < pathKeys.length; i++) {
- attrib = config.getAttribute(pathKeys[i], (String)null);
+ for (int i = 0; i < paths.length; i++) {
+ attrib = config.getAttribute(paths[i], (String)null);
if (isAttributeChanged(attrib, oldPath))
return true;
}
-
- for (int i = 0; i < pathListKeys.length; i++) {
- List<String> list = config.getAttribute(pathListKeys[i],
Collections.EMPTY_LIST);
+ return false;
+ }
+
+ @SuppressWarnings("unchecked")
+ private static boolean isListAttributesAffected(ILaunchConfiguration config, IPath
oldPath, String[] listPaths) throws CoreException{
+ for (int i = 0; i < listPaths.length; i++) {
+ List<String> list = config.getAttribute(listPaths[i], Collections.EMPTY_LIST);
List<String> newMappings = new ArrayList<String>();
Iterator<String> iter = list.iterator();
while ( iter.hasNext() ) {
- attrib = iter.next();
+ String attrib = iter.next();
if (isAttributeChanged(attrib, oldPath)){
return true;
}
@@ -106,7 +122,24 @@
}
return false;
}
+
+ @SuppressWarnings("unchecked")
+ private static boolean isExportersAffected(ILaunchConfiguration config,
+ IPath oldPath) throws CoreException {
+ String[] k = new String[]{"outputdir"}; //$NON-NLS-1$
+ List<String> exporterNames =
config.getAttribute(HibernateLaunchConstants.ATTR_EXPORTERS, Collections.EMPTY_LIST);
+ for (String exporterName : exporterNames) {
+ Map<String, String> props =
config.getAttribute(HibernateLaunchConstants.ATTR_EXPORTERS + '.' +
+ exporterName + ".properties", new HashMap<String, String>() );
//$NON-NLS-1$
+ for (String attribute : k) {
+ if (isAttributeChanged(props.get(attribute), oldPath))
+ return true; ;
+ }
+ }
+ return false;
+ }
+
private static boolean isClassPathAffected(ILaunchConfiguration config, IPath oldPath)
throws CoreException{
boolean useDefault =
config.getAttribute(IJavaLaunchConfigurationConstants.ATTR_DEFAULT_CLASSPATH, true);
if (useDefault){
@@ -152,9 +185,10 @@
}
@SuppressWarnings("unchecked")
- public static ILaunchConfiguration updateLaunchConfig(ILaunchConfiguration config, IPath
oldPath, IPath newPath) throws CoreException{
+ public static ILaunchConfiguration updateConsoleConfig(ILaunchConfiguration config,
IPath oldPath, IPath newPath) throws CoreException{
final ILaunchConfigurationWorkingCopy wc = config.getWorkingCopy();
- updateAttributes(oldPath, newPath, wc);
+ updateAttributes(oldPath, newPath, wc, ccKeys);
+ updateListAttributes(oldPath, newPath, wc, ccListKeys);
//classpath
try {
@@ -168,14 +202,53 @@
HibernateConsolePlugin.getDefault().log( e );
}
- //JavaMigrationDelegate.updateResourceMapping(wc);
if (wc.isDirty()) {
return wc.doSave();
} else {
return config;
}
}
+
+ public static ILaunchConfiguration updateCodeGenerationConfig(ILaunchConfiguration
config, IPath oldPath, IPath newPath) throws CoreException{
+ final ILaunchConfigurationWorkingCopy wc = config.getWorkingCopy();
+ updateAttributes(oldPath, newPath, wc, cgKeys);
+ updateExporters(oldPath, newPath, wc);
+ if (wc.isDirty()) {
+ return wc.doSave();
+ } else {
+ return config;
+ }
+ }
+ /**
+ * @param oldPath
+ * @param newPath
+ * @param wc
+ * @throws CoreException
+ */
+ @SuppressWarnings("unchecked")
+ private static void updateExporters(IPath oldPath, IPath newPath,
+ ILaunchConfigurationWorkingCopy wc) throws CoreException {
+ String[] keys = new String[]{"outputdir"}; //$NON-NLS-1$
+ List<String> exporterNames =
wc.getAttribute(HibernateLaunchConstants.ATTR_EXPORTERS, Collections.EMPTY_LIST);
+ for (String exporterName : exporterNames) {
+ String exporterProp = HibernateLaunchConstants.ATTR_EXPORTERS + '.' +
+ exporterName + ".properties";//$NON-NLS-1$
+ Map<String, String> props = wc.getAttribute(exporterProp,
+ new HashMap<String, String>() );
+ boolean isChanged = false;
+ for (String key : keys) {
+ String attrib = props.get(key);
+ if (isAttributeChanged(attrib, oldPath)){
+ attrib = getUpdatedPath(attrib, oldPath, newPath);
+ props.put(key, attrib);
+ isChanged = true;
+ }
+ }
+ if (isChanged) wc.setAttribute(exporterProp, props);
+ }
+ }
+
/*
* Use IRuntimeClasspathEntry[] and oldMementos instead of entries[i].getMemento(),
because
* when resource renamed instead of internalArchive you can have externalArchive.
@@ -287,9 +360,8 @@
}
}
- @SuppressWarnings("unchecked")
private static void updateAttributes(IPath oldPath, IPath newPath,
- final ILaunchConfigurationWorkingCopy wc) throws CoreException {
+ final ILaunchConfigurationWorkingCopy wc, String[] pathKeys) throws CoreException {
String attrib = null;
for (int i = 0; i < pathKeys.length; i++) {
attrib = wc.getAttribute(pathKeys[i], (String)null);
@@ -298,7 +370,12 @@
wc.setAttribute(pathKeys[i], attrib);
}
}
-
+ }
+
+ @SuppressWarnings("unchecked")
+ private static void updateListAttributes(IPath oldPath, IPath newPath,
+ final ILaunchConfigurationWorkingCopy wc, String[] pathListKeys) throws CoreException
{
+ String attrib = null;
boolean isChanged = false;
for (int i = 0; i < pathListKeys.length; i++) {
List<String> list = wc.getAttribute(pathListKeys[i], Collections.EMPTY_LIST);
@@ -334,13 +411,13 @@
return newAttribPath.toOSString();
}
- public static ILaunchConfiguration[] getAffectedLaunchConfigurations(IPath path){
+ public static ILaunchConfiguration[] getAffectedConsoleConfigs(IPath path){
ILaunchConfiguration[] configs = null;
try {
configs = LaunchHelper.findHibernateLaunchConfigs();
List<ILaunchConfiguration> list = new ArrayList<ILaunchConfiguration>();
for(int i = 0; i < configs.length && configs[i].exists(); i++) {//refactor
only hibernate launch configurations
- if (HibernateRefactoringUtil.isConfigurationAffected(configs[i], path))
list.add(configs[i]);
+ if (HibernateRefactoringUtil.isConsoleConfigAffected(configs[i], path))
list.add(configs[i]);
}
configs = list.toArray(new ILaunchConfiguration[list.size()]);
}
@@ -352,6 +429,24 @@
return configs;
}
+ public static ILaunchConfiguration[] getAffectedCodeGenerationConfigs(IPath path){
+ ILaunchConfiguration[] configs = null;
+ try {
+ configs = LaunchHelper.findCodeGenerationConfigs();
+ List<ILaunchConfiguration> list = new ArrayList<ILaunchConfiguration>();
+ for(int i = 0; i < configs.length && configs[i].exists(); i++) {
+ if (HibernateRefactoringUtil.isCodeGenerationConfigAffected(configs[i], path))
list.add(configs[i]);
+ }
+ configs = list.toArray(new ILaunchConfiguration[list.size()]);
+ }
+ catch(CoreException e) {
+ configs = new ILaunchConfiguration[0];
+ HibernateConsolePlugin.getDefault().logErrorMessage( ERROR_MESS, e );
+ }
+
+ return configs;
+ }
+
public static ILaunchConfiguration[] getAffectedLaunchConfigurations(IProject project){
ILaunchConfiguration[] configs = null;
try {
Modified:
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 2009-12-21
07:21:33 UTC (rev 19489)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/core/refactoring/LaunchConfigurationResourceNameChange.java 2009-12-21
07:59:50 UTC (rev 19490)
@@ -22,6 +22,7 @@
import org.eclipse.debug.core.ILaunchConfiguration;
import org.eclipse.ltk.core.refactoring.Change;
import org.eclipse.ltk.core.refactoring.RefactoringStatus;
+import org.eclipse.osgi.util.NLS;
import org.hibernate.eclipse.console.HibernateConsoleMessages;
/**
@@ -35,7 +36,7 @@
private IPath fNewPath;
/**
- * LaunchConfigurationResourceMoveChange constructor.
+ * LaunchConfigurationResourceNameChange constructor.
* @param launchConfiguration the launch configuration to modify
* @param oldPath the old Path of the resource.
* @param newPath the new Path of the resource.
@@ -57,7 +58,7 @@
* @see org.eclipse.ltk.core.refactoring.Change#getName()
*/
public String getName() {
- return
HibernateConsoleMessages.LaunchConfigurationResourceNameChange_update_resource_path_in_launch_cfg
+ fLaunchConfiguration.getName();
+ return
NLS.bind(HibernateConsoleMessages.LaunchConfigurationResourceNameChange_update_resource_path_in_launch_cfg,
fLaunchConfiguration.getName());
}
/* (non-Javadoc)
@@ -73,9 +74,7 @@
return new RefactoringStatus();
}
- /* (non-Javadoc)
- * @see
org.eclipse.ltk.core.refactoring.Change#perform(org.eclipse.core.runtime.IProgressMonitor)
- */
+ @SuppressWarnings("deprecation")
public Change perform(IProgressMonitor pm) throws CoreException {
if (!fLaunchConfiguration.exists()){
IWorkspace workspace = ResourcesPlugin.getWorkspace();
@@ -100,7 +99,7 @@
}
}
}
- fLaunchConfiguration =
HibernateRefactoringUtil.updateLaunchConfig(fLaunchConfiguration, fOldPath, fNewPath);
+ fLaunchConfiguration =
HibernateRefactoringUtil.updateConsoleConfig(fLaunchConfiguration, fOldPath, fNewPath);
return new LaunchConfigurationResourceNameChange(fLaunchConfiguration, fNewPath,
fOldPath);
}
}
Modified:
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 2009-12-21
07:21:33 UTC (rev 19489)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/core/refactoring/MoveResourceParticipant.java 2009-12-21
07:59:50 UTC (rev 19490)
@@ -25,14 +25,20 @@
public Change createChange(IProgressMonitor pm) throws CoreException,
OperationCanceledException {
- ILaunchConfiguration[] configs =
HibernateRefactoringUtil.getAffectedLaunchConfigurations(fResource.getFullPath());
+ ILaunchConfiguration[] configs =
HibernateRefactoringUtil.getAffectedConsoleConfigs(fResource.getFullPath());
List<Change> changes = new ArrayList<Change>();
- LaunchConfigurationResourceNameChange change = null;
+ Change 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);
}
+
+ configs =
HibernateRefactoringUtil.getAffectedCodeGenerationConfigs(fResource.getFullPath());
+ for (int i= 0; i < configs.length; i++) {
+ change = new CodeGenerationReseourceNameChange(configs[i], fResource.getFullPath(),
((IResource)getArguments().getDestination()).getFullPath().append(fResource.getName()));
+ changes.add(change);
+ }
return HibernateRefactoringUtil.createChangesFromList(changes, getName());
}
Modified:
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 2009-12-21
07:21:33 UTC (rev 19489)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/launch/core/refactoring/RenameResourceParticipant.java 2009-12-21
07:59:50 UTC (rev 19490)
@@ -45,15 +45,22 @@
*/
public Change createChange(IProgressMonitor pm) throws CoreException,
OperationCanceledException {
- ILaunchConfiguration[] configs =
HibernateRefactoringUtil.getAffectedLaunchConfigurations(fResource.getFullPath());
+ ILaunchConfiguration[] configs =
HibernateRefactoringUtil.getAffectedConsoleConfigs(fResource.getFullPath());
List<Change> changes = new ArrayList<Change>();
- LaunchConfigurationResourceNameChange change = null;
+ Change 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);
}
+
+ configs =
HibernateRefactoringUtil.getAffectedCodeGenerationConfigs(fResource.getFullPath());
+ for (int i= 0; i < configs.length; i++) {
+ change = new CodeGenerationReseourceNameChange(configs[i], fResource.getFullPath(),
+ fResource.getParent().getFullPath().append(getArguments().getNewName()));
+ changes.add(change);
+ }
return HibernateRefactoringUtil.createChangesFromList(changes, getName());
}
Modified:
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/console/test/RefactoringTest.java
===================================================================
---
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/console/test/RefactoringTest.java 2009-12-21
07:21:33 UTC (rev 19489)
+++
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/console/test/RefactoringTest.java 2009-12-21
07:59:50 UTC (rev 19490)
@@ -12,6 +12,7 @@
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -37,6 +38,7 @@
import org.eclipse.jdt.internal.launching.RuntimeClasspathEntry;
import org.eclipse.jdt.launching.IRuntimeClasspathEntry;
import org.hibernate.eclipse.console.test.project.SimpleTestProject;
+import org.hibernate.eclipse.launch.HibernateLaunchConstants;
import org.hibernate.eclipse.launch.IConsoleConfigurationLaunchConstants;
import org.hibernate.eclipse.launch.core.refactoring.HibernateRefactoringUtil;
@@ -47,6 +49,8 @@
@SuppressWarnings("restriction")
public class RefactoringTest extends TestCase {
+ private static final String HBMTEMPLATE0 = "hbmtemplate0";
+ private static final String HBMTEMPLATE0_PROPERTIES =
HibernateLaunchConstants.ATTR_EXPORTERS + '.' + HBMTEMPLATE0 +
".properties";
private final String[] oldPathElements = new
String[]{"oldPrj","oldSrc", "oldPack",
"oldHibernate.cfg.xml"}; //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
//$NON-NLS-4$
private final String[] newPathElements = new
String[]{"newPrj","newSrc", "newPack",
"newHibernate.cfg.xml"}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
//$NON-NLS-4$
@@ -55,6 +59,8 @@
private TestLaunchConfig testStrConfig = null;
private TestLaunchConfig testStrListConfig = null;
private TestLaunchConfig testNotChangedConfig = null;
+ private TestLaunchConfig testCodeGenerationConfig = null;
+ private TestLaunchConfig testNotChangedCodeGenerationConfig = null;
private IRuntimeClasspathEntry[] runtimeClasspathEntries = null;
@@ -73,6 +79,8 @@
Map<String, Object> testStrAttr = new HashMap<String, Object>();
Map<String, Object> testStrListAttr = new HashMap<String, Object>();
Map<String, Object> testNotChangedAttr = new HashMap<String, Object>();
+ Map<String, Object> testCodeGenerationAttr = new HashMap<String,
Object>();
+ Map<String, Object> testNotChangedCodeGenerationAttr = new HashMap<String,
Object>();
testStrAttr.put(IConsoleConfigurationLaunchConstants.CFG_XML_FILE, oldPathStr);
@@ -81,9 +89,29 @@
testNotChangedAttr.put(IConsoleConfigurationLaunchConstants.CFG_XML_FILE,
notChangedPathStr);
testNotChangedAttr.put(IConsoleConfigurationLaunchConstants.FILE_MAPPINGS,
Arrays.asList(new String[]{notChangedPathStr}));
+ testCodeGenerationAttr.put(HibernateLaunchConstants.ATTR_TEMPLATE_DIR,
generateOldPathForSegment(2).toString());
+ testCodeGenerationAttr.put(HibernateLaunchConstants.ATTR_OUTPUT_DIR,
generateOldPathForSegment(2).toString());
+ testCodeGenerationAttr.put(HibernateLaunchConstants.ATTR_REVERSE_ENGINEER_SETTINGS,
oldPathStr.toString());
+ testCodeGenerationAttr.put(HibernateLaunchConstants.ATTR_EXPORTERS,
Collections.singletonList(HBMTEMPLATE0));
+ Map<String, String> expProps = new HashMap<String, String>();
+ expProps.put("outputdir", generateOldPathForSegment(2).toString());
+ testCodeGenerationAttr.put(HBMTEMPLATE0_PROPERTIES, expProps);
+
+ testNotChangedCodeGenerationAttr.put(HibernateLaunchConstants.ATTR_TEMPLATE_DIR,
notChangedPathStr.toString());
+ testNotChangedCodeGenerationAttr.put(HibernateLaunchConstants.ATTR_OUTPUT_DIR,
notChangedPathStr.toString());
+ testNotChangedCodeGenerationAttr.put(HibernateLaunchConstants.ATTR_REVERSE_ENGINEER_SETTINGS,
notChangedPathStr.toString());
+ testCodeGenerationAttr.put(HibernateLaunchConstants.ATTR_EXPORTERS,
Collections.singletonList(HBMTEMPLATE0));
+ Map<String, String> expProps2 = new HashMap<String, String>();
+ expProps2.put("outputdir", generateOldPathForSegment(2).toString());
+ testNotChangedCodeGenerationAttr.put(HBMTEMPLATE0_PROPERTIES, expProps2);
+
+
testStrConfig = new TestLaunchConfig(testStrAttr);
testStrListConfig = new TestLaunchConfig(testStrListAttr);
testNotChangedConfig = new TestLaunchConfig(testNotChangedAttr);
+ testCodeGenerationConfig = new TestLaunchConfig(testCodeGenerationAttr);
+ testNotChangedCodeGenerationConfig = new
TestLaunchConfig(testNotChangedCodeGenerationAttr);
+
project = new SimpleTestProject(oldPathElements[0]);
IJavaProject proj = project.getIJavaProject();
@@ -108,9 +136,11 @@
for (int i = 0; i < oldPathElements.length - 1; i++) {
IPath oldPathPart = generateOldPathForSegment(i);
try {
- assertTrue(HibernateRefactoringUtil.isConfigurationAffected(testStrConfig,
oldPathPart));
- assertTrue(HibernateRefactoringUtil.isConfigurationAffected(testStrListConfig,
oldPathPart));
- assertFalse(HibernateRefactoringUtil.isConfigurationAffected(testNotChangedConfig,
oldPathPart));
+ assertTrue(HibernateRefactoringUtil.isConsoleConfigAffected(testStrConfig,
oldPathPart));
+ assertTrue(HibernateRefactoringUtil.isConsoleConfigAffected(testStrListConfig,
oldPathPart));
+ assertFalse(HibernateRefactoringUtil.isConsoleConfigAffected(testNotChangedConfig,
oldPathPart));
+ assertTrue(HibernateRefactoringUtil.isCodeGenerationConfigAffected(testCodeGenerationConfig,
oldPathPart));
+ assertFalse(HibernateRefactoringUtil.isConsoleConfigAffected(testNotChangedCodeGenerationConfig,
oldPathPart));
} catch (CoreException e) {
fail(ConsoleTestMessages.RefactoringTest_exception_while_findchange_launch_config_processing
+ e.getMessage());
}
@@ -147,7 +177,9 @@
int segmentNum = 0;
try {
updatePaths(generateOldPathForSegment(segmentNum),
generateNewPathForSegment(segmentNum));
- checkPaths(generateTruePathForSegment(segmentNum));
+ Path truePath = generateTruePathForSegment(segmentNum);
+ checkPaths(truePath);
+ checkAdditional(truePath);
} catch (CoreException e) {
fail(ConsoleTestMessages.RefactoringTest_exception_while_projnamechange_refactor);
}
@@ -157,7 +189,9 @@
int segmentNum = 1;
try {
updatePaths(generateOldPathForSegment(segmentNum),
generateNewPathForSegment(segmentNum));
- checkPaths(generateTruePathForSegment(segmentNum));
+ Path truePath = generateTruePathForSegment(segmentNum);
+ checkPaths(truePath);
+ checkAdditional(truePath);
} catch (CoreException e) {
fail(ConsoleTestMessages.RefactoringTest_exception_while_srcnamechange_refactor);
}
@@ -167,7 +201,9 @@
int segmentNum = 2;
try {
updatePaths(generateOldPathForSegment(segmentNum),
generateNewPathForSegment(segmentNum));
- checkPaths(generateTruePathForSegment(segmentNum));
+ Path truePath = generateTruePathForSegment(segmentNum);
+ checkPaths(truePath);
+ checkAdditional(truePath);
} catch (CoreException e) {
fail(ConsoleTestMessages.RefactoringTest_exception_while_packnamechange_refactor);
}
@@ -199,8 +235,9 @@
}
private void updatePaths(Path oldPath, Path newPath) throws CoreException{
- HibernateRefactoringUtil.updateLaunchConfig(testStrConfig, oldPath, newPath);
- HibernateRefactoringUtil.updateLaunchConfig(testStrListConfig, oldPath, newPath);
+ HibernateRefactoringUtil.updateConsoleConfig(testStrConfig, oldPath, newPath);
+ HibernateRefactoringUtil.updateConsoleConfig(testStrListConfig, oldPath, newPath);
+ HibernateRefactoringUtil.updateCodeGenerationConfig(testCodeGenerationConfig, oldPath,
newPath);
}
private void checkMementoChanged(String oldMemento, String newMemento, IPath
oldPathPart, IPath newPath){
@@ -244,7 +281,21 @@
assertEquals(truePath.makeAbsolute(), new Path(newPath).makeAbsolute());
newPath = ((List<String>)
testStrListConfig.getNewAttribute(IConsoleConfigurationLaunchConstants.FILE_MAPPINGS)).get(0);
assertEquals(truePath.makeAbsolute(), new Path(newPath).makeAbsolute());
+
+ newPath = (String)
testCodeGenerationConfig.getNewAttribute(HibernateLaunchConstants.ATTR_REVERSE_ENGINEER_SETTINGS);
+ assertEquals(truePath.makeAbsolute(), new Path(newPath).makeAbsolute());
}
+
+ @SuppressWarnings("unchecked")
+ private void checkAdditional(Path truePath) throws CoreException {
+ String newPath = (String)
testCodeGenerationConfig.getNewAttribute(HibernateLaunchConstants.ATTR_TEMPLATE_DIR);
+ assertEquals(truePath.removeLastSegments(1).makeAbsolute(), new
Path(newPath).makeAbsolute());
+ newPath = (String)
testCodeGenerationConfig.getNewAttribute(HibernateLaunchConstants.ATTR_OUTPUT_DIR);
+ assertEquals(truePath.removeLastSegments(1).makeAbsolute(), new
Path(newPath).makeAbsolute());
+ Map<String, String> props =
testCodeGenerationConfig.getAttribute(HBMTEMPLATE0_PROPERTIES,
+ new HashMap<String, String>());
+ assertEquals(truePath.removeLastSegments(1).makeAbsolute(), new
Path(props.get("outputdir")).makeAbsolute());
+ }
private Path generateNewPathForSegment(int segmentNum){
assertTrue(ConsoleTestMessages.RefactoringTest_segmentnum_too_match, segmentNum <
oldPathElements.length);
@@ -333,7 +384,9 @@
attributes.put(attributeName, value);
}
- public void setAttribute(String attributeName, Map value)
{fail(ConsoleTestMessages.RefactoringTest_method_not_tested);}
+ public void setAttribute(String attributeName, Map value) {
+ attributes.put(attributeName, value);
+ }
public void setAttribute(String attributeName, boolean value)
{fail(ConsoleTestMessages.RefactoringTest_method_not_tested);}
@@ -387,8 +440,7 @@
public Map getAttribute(String attributeName, Map defaultValue)
throws CoreException {
- fail(ConsoleTestMessages.RefactoringTest_method_not_tested);
- return null;
+ return parent.getAttribute(attributeName, defaultValue);
}
public String getAttribute(String attributeName, String defaultValue)
@@ -559,7 +611,11 @@
public Map getAttribute(String attributeName, Map defaultValue)
throws CoreException {
- return null;
+ if (attributes.containsKey(attributeName)){
+ return (Map) attributes.get(attributeName);
+ } else {
+ return defaultValue;
+ }
}
public String getAttribute(String attributeName, String defaultValue)