|
From: <caw...@us...> - 2007-01-24 22:06:16
|
Revision: 1876
http://svn.sourceforge.net/rubyeclipse/?rev=1876&view=rev
Author: cawilliams
Date: 2007-01-24 13:50:11 -0800 (Wed, 24 Jan 2007)
Log Message:
-----------
fix a broken test
Modified Paths:
--------------
trunk/org.rubypeople.rdt.core.tests/src/org/rubypeople/rdt/core/tests/AbstractRubyModelTest.java
trunk/org.rubypeople.rdt.core.tests/src/org/rubypeople/rdt/core/tests/ModifyingResourceTest.java
trunk/org.rubypeople.rdt.core.tests/src/org/rubypeople/rdt/core/tests/util/Util.java
trunk/org.rubypeople.rdt.launching/src/org/rubypeople/rdt/internal/launching/VMDefinitionsContainer.java
trunk/org.rubypeople.rdt.launching/src/org/rubypeople/rdt/launching/RubyRuntime.java
trunk/org.rubypeople.rdt.launching.tests/src/org/rubypeople/rdt/internal/launching/TC_RubyRuntime.java
Modified: trunk/org.rubypeople.rdt.core.tests/src/org/rubypeople/rdt/core/tests/AbstractRubyModelTest.java
===================================================================
--- trunk/org.rubypeople.rdt.core.tests/src/org/rubypeople/rdt/core/tests/AbstractRubyModelTest.java 2007-01-24 15:54:40 UTC (rev 1875)
+++ trunk/org.rubypeople.rdt.core.tests/src/org/rubypeople/rdt/core/tests/AbstractRubyModelTest.java 2007-01-24 21:50:11 UTC (rev 1876)
@@ -267,7 +267,7 @@
protected IRubyProject createRubyProject(String projectName) throws CoreException {
- return this.createRubyProject(projectName, new String[] {""}, new String[] {"JCL_LIB"});
+ return this.createRubyProject(projectName, new String[] {""}, new String[] {"RUBY_LIB"});
}
/*
@@ -675,4 +675,20 @@
// TODO Find some way to wait until the indexes are ready from SymbolIndex/build process
}
+
+ public void deleteFile(File file) {
+ int retryCount = 0;
+ while (++retryCount <= 60) { // wait 1 minute at most
+ if (org.rubypeople.rdt.core.tests.util.Util.delete(file)) {
+ break;
+ }
+ }
+ }
+ protected void deleteFolder(IPath folderPath) throws CoreException {
+ deleteResource(getFolder(folderPath));
+ }
+
+ protected IFolder getFolder(IPath path) {
+ return getWorkspaceRoot().getFolder(path);
+ }
}
Modified: trunk/org.rubypeople.rdt.core.tests/src/org/rubypeople/rdt/core/tests/ModifyingResourceTest.java
===================================================================
--- trunk/org.rubypeople.rdt.core.tests/src/org/rubypeople/rdt/core/tests/ModifyingResourceTest.java 2007-01-24 15:54:40 UTC (rev 1875)
+++ trunk/org.rubypeople.rdt.core.tests/src/org/rubypeople/rdt/core/tests/ModifyingResourceTest.java 2007-01-24 21:50:11 UTC (rev 1876)
@@ -45,4 +45,11 @@
}
return file;
}
+
+ protected void deleteFile(String filePath) throws CoreException {
+ deleteResource(this.getFile(filePath));
+ }
+ protected void deleteFolder(String folderPath) throws CoreException {
+ deleteFolder(new Path(folderPath));
+ }
}
Modified: trunk/org.rubypeople.rdt.core.tests/src/org/rubypeople/rdt/core/tests/util/Util.java
===================================================================
--- trunk/org.rubypeople.rdt.core.tests/src/org/rubypeople/rdt/core/tests/util/Util.java 2007-01-24 15:54:40 UTC (rev 1875)
+++ trunk/org.rubypeople.rdt.core.tests/src/org/rubypeople/rdt/core/tests/util/Util.java 2007-01-24 21:50:11 UTC (rev 1876)
@@ -429,4 +429,109 @@
buffer.append("\"");
return buffer.toString();
}
+
+ /**
+ * Delete a file or directory and insure that the file is no longer present
+ * on file system. In case of directory, delete all the hierarchy underneath.
+ *
+ * @param file The file or directory to delete
+ * @return true iff the file was really delete, false otherwise
+ */
+ public static boolean delete(File file) {
+ // flush all directory content
+ if (file.isDirectory()) {
+ flushDirectoryContent(file);
+ }
+ // remove file
+ file.delete();
+ if (isFileDeleted(file)) {
+ return true;
+ }
+ return waitUntilFileDeleted(file);
+ }
+
+ /**
+ * Flush content of a given directory (leaving it empty),
+ * no-op if not a directory.
+ */
+ public static void flushDirectoryContent(File dir) {
+ File[] files = dir.listFiles();
+ if (files == null) return;
+ for (int i = 0, max = files.length; i < max; i++) {
+ delete(files[i]);
+ }
+ }
+
+ /**
+ * Wait until the file is _really_ deleted on file system.
+ *
+ * @param file Deleted file
+ * @return true if the file was finally deleted, false otherwise
+ */
+ private static boolean waitUntilFileDeleted(File file) {
+ if (DELETE_DEBUG) {
+ System.out.println();
+ System.out.println("WARNING in test: "+getTestName());
+ System.out.println(" - problems occured while deleting "+file);
+ printRdtCoreStackTrace(null, 1);
+ printFileInfo(file.getParentFile(), 1, -1); // display parent with its children
+ System.out.print(" - wait for ("+DELETE_MAX_WAIT+"ms max): ");
+ }
+ int count = 0;
+ int delay = 10; // ms
+ int maxRetry = DELETE_MAX_WAIT / delay;
+ int time = 0;
+ while (count < maxRetry) {
+ try {
+ count++;
+ Thread.sleep(delay);
+ time += delay;
+ if (time > DELETE_MAX_TIME) DELETE_MAX_TIME = time;
+ if (DELETE_DEBUG) System.out.print('.');
+ if (file.exists()) {
+ if (file.delete()) {
+ // SUCCESS
+ if (DELETE_DEBUG) {
+ System.out.println();
+ System.out.println(" => file really removed after "+time+"ms (max="+DELETE_MAX_TIME+"ms)");
+ System.out.println();
+ }
+ return true;
+ }
+ }
+ if (isFileDeleted(file)) {
+ // SUCCESS
+ if (DELETE_DEBUG) {
+ System.out.println();
+ System.out.println(" => file disappeared after "+time+"ms (max="+DELETE_MAX_TIME+"ms)");
+ System.out.println();
+ }
+ return true;
+ }
+ // Increment waiting delay exponentially
+ if (count >= 10 && delay <= 100) {
+ count = 1;
+ delay *= 10;
+ maxRetry = DELETE_MAX_WAIT / delay;
+ if ((DELETE_MAX_WAIT%delay) != 0) {
+ maxRetry++;
+ }
+ }
+ }
+ catch (InterruptedException ie) {
+ break; // end loop
+ }
+ }
+ if (!DELETE_DEBUG) {
+ System.out.println();
+ System.out.println("WARNING in test: "+getTestName());
+ System.out.println(" - problems occured while deleting "+file);
+ printRdtCoreStackTrace(null, 1);
+ printFileInfo(file.getParentFile(), 1, -1); // display parent with its children
+ }
+ System.out.println();
+ System.out.println(" !!! ERROR: "+file+" was never deleted even after having waited "+DELETE_MAX_TIME+"ms!!!");
+ System.out.println();
+ return false;
+ }
}
Modified: trunk/org.rubypeople.rdt.launching/src/org/rubypeople/rdt/internal/launching/VMDefinitionsContainer.java
===================================================================
--- trunk/org.rubypeople.rdt.launching/src/org/rubypeople/rdt/internal/launching/VMDefinitionsContainer.java 2007-01-24 15:54:40 UTC (rev 1875)
+++ trunk/org.rubypeople.rdt.launching/src/org/rubypeople/rdt/internal/launching/VMDefinitionsContainer.java 2007-01-24 21:50:11 UTC (rev 1876)
@@ -83,11 +83,6 @@
private String fDefaultVMInstallCompositeID;
/**
- * The identifier of the connector to use for the default VM.
- */
- private String fDefaultVMInstallConnectorTypeID;
-
- /**
* Constructs an empty VM container
*/
public VMDefinitionsContainer() {
@@ -202,24 +197,6 @@
}
/**
- * Return the default VM's connector type ID.
- *
- * @return String the current value of the default VM's connector type ID
- */
- public String getDefaultVMInstallConnectorTypeID() {
- return fDefaultVMInstallConnectorTypeID;
- }
-
- /**
- * Set the default VM's connector type ID.
- *
- * @param id the new value of the default VM's connector type ID
- */
- public void setDefaultVMInstallConnectorTypeID(String id){
- fDefaultVMInstallConnectorTypeID = id;
- }
-
- /**
* Return the VM definitions contained in this object as a String of XML. The String
* is suitable for storing in the workbench preferences.
* <p>
@@ -243,12 +220,7 @@
if (getDefaultVMInstallCompositeID() != null) {
config.setAttribute("defaultVM", getDefaultVMInstallCompositeID()); //$NON-NLS-1$
}
-
- // Set the defaultVMConnector attribute on the top-level node
- if (getDefaultVMInstallConnectorTypeID() != null) {
- config.setAttribute("defaultVMConnector", getDefaultVMInstallConnectorTypeID()); //$NON-NLS-1$
- }
-
+
// Create a node for each install type represented in this container
Set vmInstallTypeSet = getVMTypeToVMMap().keySet();
Iterator keyIterator = vmInstallTypeSet.iterator();
@@ -398,7 +370,6 @@
// Populate the default VM-related fields
container.setDefaultVMInstallCompositeID(config.getAttribute("defaultVM")); //$NON-NLS-1$
- container.setDefaultVMInstallConnectorTypeID(config.getAttribute("defaultVMConnector")); //$NON-NLS-1$
// Traverse the parsed structure and populate the VMType to VM Map
NodeList list = config.getChildNodes();
Modified: trunk/org.rubypeople.rdt.launching/src/org/rubypeople/rdt/launching/RubyRuntime.java
===================================================================
--- trunk/org.rubypeople.rdt.launching/src/org/rubypeople/rdt/launching/RubyRuntime.java 2007-01-24 15:54:40 UTC (rev 1875)
+++ trunk/org.rubypeople.rdt.launching/src/org/rubypeople/rdt/launching/RubyRuntime.java 2007-01-24 21:50:11 UTC (rev 1876)
@@ -123,7 +123,6 @@
private static boolean fgInitializingVMs;
private static String fgDefaultVMId;
private static ListenerList fgVMListeners = new ListenerList(5);
- private static String fgDefaultVMConnectorId;
/**
* Cache of already resolved projects in container entries. Used to avoid
@@ -250,8 +249,7 @@
private static String getVMsAsXML() throws IOException, ParserConfigurationException, TransformerException {
VMDefinitionsContainer container = new VMDefinitionsContainer();
- container.setDefaultVMInstallCompositeID(getDefaultVMId());
- container.setDefaultVMInstallConnectorTypeID(getDefaultVMConnectorId());
+ container.setDefaultVMInstallCompositeID(getDefaultVMId());
IVMInstallType[] vmTypes= getVMInstallTypes();
for (int i = 0; i < vmTypes.length; ++i) {
IVMInstall[] vms = vmTypes[i].getVMInstalls();
@@ -263,11 +261,6 @@
return container.getAsXML();
}
- private static String getDefaultVMConnectorId() {
- initializeVMs();
- return fgDefaultVMConnectorId;
- }
-
/**
* Saves the preferences for the launching plug-in.
*
@@ -362,7 +355,6 @@
}
}
fgDefaultVMId = vmDefs.getDefaultVMInstallCompositeID();
- fgDefaultVMConnectorId = vmDefs.getDefaultVMInstallConnectorTypeID();
// Create the underlying VMs for each valid VM
List vmList = vmDefs.getValidVMList();
Modified: trunk/org.rubypeople.rdt.launching.tests/src/org/rubypeople/rdt/internal/launching/TC_RubyRuntime.java
===================================================================
--- trunk/org.rubypeople.rdt.launching.tests/src/org/rubypeople/rdt/internal/launching/TC_RubyRuntime.java 2007-01-24 15:54:40 UTC (rev 1875)
+++ trunk/org.rubypeople.rdt.launching.tests/src/org/rubypeople/rdt/internal/launching/TC_RubyRuntime.java 2007-01-24 21:50:11 UTC (rev 1876)
@@ -2,20 +2,22 @@
import java.io.File;
-import junit.framework.TestCase;
-
+import org.eclipse.core.resources.IFolder;
import org.eclipse.core.runtime.CoreException;
+import org.rubypeople.rdt.core.tests.ModifyingResourceTest;
import org.rubypeople.rdt.launching.IVMInstall;
import org.rubypeople.rdt.launching.IVMInstallType;
import org.rubypeople.rdt.launching.RubyRuntime;
import org.rubypeople.rdt.launching.VMStandin;
-public class TC_RubyRuntime extends TestCase {
+public class TC_RubyRuntime extends ModifyingResourceTest {
private static final String VM_TYPE_ID = "org.rubypeople.rdt.launching.StandardVMType";
private IVMInstallType vmType;
-
+ private IFolder folderOne;
+ private IFolder folderTwo;
+
public TC_RubyRuntime(String name) {
super(name);
}
@@ -24,13 +26,26 @@
protected void setUp() throws Exception {
super.setUp();
vmType = RubyRuntime.getVMInstallType(VM_TYPE_ID);
+ RubyRuntime.setDefaultVMInstall(null, null, true);
+ LaunchingPlugin.getDefault().setIgnoreVMDefPropertyChangeEvents(true);
+ createProject("/rubyRuntime");
+ folderOne = createFolder("/rubyRuntime/interpreterOne");
+ createFolder("/rubyRuntime/interpreterOne/lib");
+ createFolder("/rubyRuntime/interpreterOne/bin");
+ createFile("/rubyRuntime/interpreterOne/bin/ruby", "");
+ folderTwo = createFolder("/rubyRuntime/interpreterTwo");
+ createFolder("/rubyRuntime/interpreterTwo/lib");
+ createFolder("/rubyRuntime/interpreterTwo/bin");
+ createFile("/rubyRuntime/interpreterTwo/bin/ruby", "");
}
@Override
protected void tearDown() throws Exception {
super.tearDown();
-// RubyRuntime.setDefaultVMInstall(null, true);
+ vmType = null;
+ RubyRuntime.setDefaultVMInstall(null, null, true);
RubyRuntime.getPreferences().setValue(RubyRuntime.PREF_VM_XML, "");
+ deleteProject("/rubyRuntime");
}
public void testGetInstalledInterpreters() {
@@ -59,29 +74,29 @@
public void testSetInstalledInterpreters() throws CoreException {
try {
VMStandin standin = new VMStandin(vmType, "InterpreterOne");
- standin.setInstallLocation(new File("C:\\RubyInstallRootOne"));
+ standin.setInstallLocation(folderOne.getLocation().toFile());
standin.setName("InterpreterOne");
- standin.convertToRealVM();
- RubyRuntime.saveVMConfiguration();
+ IVMInstall one = standin.convertToRealVM();
+ RubyRuntime.setDefaultVMInstall(one, null,true);
assertEquals(
"XML should indicate only one interpreter with it being the selected.",
- "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n<vmSettings defaultVM=\"\" defaultVMConnector=\"\">\r\n<vmType id=\"org.rubypeople.rdt.launching.StandardVMType\">\r\n<vm id=\"InterpreterOne\" name=\"InterpreterOne\" path=\"C:\\RubyInstallRootOne\"/>\r\n</vmType>\r\n</vmSettings>\r\n",
+ "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n<vmSettings defaultVM=\"43,org.rubypeople.rdt.launching.StandardVMType14,InterpreterOne\">\r\n<vmType id=\"org.rubypeople.rdt.launching.StandardVMType\">\r\n<vm id=\"InterpreterOne\" name=\"InterpreterOne\" path=\"" + folderOne.getLocation().toOSString() + "\"/>\r\n</vmType>\r\n</vmSettings>\r\n",
getVMsXML());
VMStandin standin2 = new VMStandin(vmType, "InterpreterTwo");
- standin2.setInstallLocation(new File("C:\\RubyInstallRootTwo"));
+ standin2.setInstallLocation(folderTwo.getLocation().toFile());
standin2.setName("InterpreterTwo");
- standin2.convertToRealVM();
+ IVMInstall two = standin2.convertToRealVM();
RubyRuntime.saveVMConfiguration();
assertEquals(
"XML should indicate both interpreters with the first one being selected.",
- "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n<vmSettings defaultVM=\"\" defaultVMConnector=\"\">\r\n<vmType id=\"org.rubypeople.rdt.launching.StandardVMType\">\r\n<vm id=\"InterpreterOne\" name=\"InterpreterOne\" path=\"C:\\RubyInstallRootOne\"/>\r\n<vm id=\"InterpreterTwo\" name=\"InterpreterTwo\" path=\"C:\\RubyInstallRootTwo\"/>\r\n</vmType>\r\n</vmSettings>\r\n",
+ "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n<vmSettings defaultVM=\"43,org.rubypeople.rdt.launching.StandardVMType14,InterpreterOne\">\r\n<vmType id=\"org.rubypeople.rdt.launching.StandardVMType\">\r\n<vm id=\"InterpreterOne\" name=\"InterpreterOne\" path=\"" + folderOne.getLocation().toOSString() + "\"/>\r\n<vm id=\"InterpreterTwo\" name=\"InterpreterTwo\" path=\"" + folderTwo.getLocation().toOSString() + "\"/>\r\n</vmType>\r\n</vmSettings>\r\n",
getVMsXML());
- RubyRuntime.setDefaultVMInstall(standin2, null,true);
+ RubyRuntime.setDefaultVMInstall(two, null,true);
assertEquals(
"XML should indicate both interpreters with the first one being selected.",
- "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n<vmSettings defaultVM=\"" + RubyRuntime.getCompositeIdFromVM(standin2) + "\" defaultVMConnector=\"\">\r\n<vmType id=\"org.rubypeople.rdt.launching.StandardVMType\">\r\n<vm id=\"InterpreterOne\" name=\"InterpreterOne\" path=\"C:\\RubyInstallRootOne\"/>\r\n<vm id=\"InterpreterTwo\" name=\"InterpreterTwo\" path=\"C:\\RubyInstallRootTwo\"/>\r\n</vmType>\r\n</vmSettings>\r\n",
+ "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n<vmSettings defaultVM=\"" + RubyRuntime.getCompositeIdFromVM(standin2) + "\">\r\n<vmType id=\"org.rubypeople.rdt.launching.StandardVMType\">\r\n<vm id=\"InterpreterOne\" name=\"InterpreterOne\" path=\"" + folderOne.getLocation().toOSString() + "\"/>\r\n<vm id=\"InterpreterTwo\" name=\"InterpreterTwo\" path=\"" + folderTwo.getLocation().toOSString() + "\"/>\r\n</vmType>\r\n</vmSettings>\r\n",
getVMsXML());
} finally {
vmType.disposeVMInstall("InterpreterOne");
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|