[jboss-svn-commits] JBL Code SVN: r20950 - in labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools: META-INF and 8 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Mon Jul 7 18:12:43 EDT 2008


Author: john.graham at jboss.org
Date: 2008-07-07 18:12:42 -0400 (Mon, 07 Jul 2008)
New Revision: 20950

Added:
   labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/icons/guvnor_controlled_dirty.gif
Modified:
   labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/META-INF/MANIFEST.MF
   labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/plugin.properties
   labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/plugin.xml
   labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/src/org/guvnor/tools/Activator.java
   labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/src/org/guvnor/tools/GuvnorDecorator.java
   labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/src/org/guvnor/tools/actions/CommitAction.java
   labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/src/org/guvnor/tools/actions/UpdateAction.java
   labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/src/org/guvnor/tools/utils/GuvnorMetadataUtils.java
   labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/src/org/guvnor/tools/utils/webdav/IWebDavClient.java
   labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/src/org/guvnor/tools/utils/webdav/WebDavClient.java
   labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/src/org/guvnor/tools/views/RepositoryView.java
   labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/src/org/guvnor/tools/views/model/TreeParent.java
   labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/src/org/guvnor/tools/wizards/CheckoutWizard.java
Log:
Import wizard, first version of commit action

Modified: labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/META-INF/MANIFEST.MF
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/META-INF/MANIFEST.MF	2008-07-07 21:27:46 UTC (rev 20949)
+++ labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/META-INF/MANIFEST.MF	2008-07-07 22:12:42 UTC (rev 20950)
@@ -2,7 +2,7 @@
 Bundle-ManifestVersion: 2
 Bundle-Name: %plugin.name
 Bundle-SymbolicName: org.guvnor.tools;singleton:=true
-Bundle-Version: 0.5.0.200807031810
+Bundle-Version: 0.6.0.200807071811
 Bundle-Activator: org.guvnor.tools.Activator
 Bundle-Vendor: %plugin.provider
 Bundle-Localization: plugin

Added: labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/icons/guvnor_controlled_dirty.gif
===================================================================
(Binary files differ)


Property changes on: labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/icons/guvnor_controlled_dirty.gif
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Modified: labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/plugin.properties
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/plugin.properties	2008-07-07 21:27:46 UTC (rev 20949)
+++ labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/plugin.properties	2008-07-07 22:12:42 UTC (rev 20950)
@@ -22,7 +22,7 @@
 action.properties.tooltip = Show properties for the selected element
 
 action.popup.update = Update
-action.popup.add = Add
+action.popup.add = Add...
 action.popup.commit = Commit
 action.popup.showhistory = Show History
 action.popup.compareversion = Compare with Version...

Modified: labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/plugin.xml
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/plugin.xml	2008-07-07 21:27:46 UTC (rev 20949)
+++ labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/plugin.xml	2008-07-07 22:12:42 UTC (rev 20950)
@@ -27,7 +27,6 @@
   
   <extension point = "org.eclipse.ui.newWizards">
 		<category id = "org.guvnor.tools.wizcat" name="%category.name"/>
-<!--
 	 	<wizard id = "org.guvnor.tools.wizards.checkoutwizard"
 	      	    name = "%wiz.copy.resources"
 		        class="org.guvnor.tools.wizards.CheckoutWizard"
@@ -36,7 +35,6 @@
 		        icon="icons/guvnor_rep.gif">
 	    	   <description>%wiz.copy.resources.desc</description>
 		</wizard>
--->
 		<wizard name = "%wiz.new.repository.location"
 		        id = "org.guvnor.tools.wizards.newreplocationwizard"
 		        class="org.guvnor.tools.wizards.NewRepLocationWizard"
@@ -45,7 +43,6 @@
 	    	   <description>%wiz.new.repository.location.desc</description>
 		</wizard>
 	</extension>
-<!--
 	<extension point = "org.eclipse.ui.importWizards">
 	    <category id = "org.guvnor.tools.importwizcat" name="%category.name"/>
 	 	<wizard id = "org.guvnor.tools.checkoutwizard"
@@ -56,7 +53,6 @@
 	    	   <description>%wiz.import.resources.desc</description>
 		</wizard>
 	</extension>
--->
 	<extension point="org.eclipse.ui.perspectiveExtensions">
     	<perspectiveExtension targetID="org.eclipse.ui.resourcePerspective">
            <view id="org.guvnor.tools.views.RepositoriesView"

Modified: labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/src/org/guvnor/tools/Activator.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/src/org/guvnor/tools/Activator.java	2008-07-07 21:27:46 UTC (rev 20949)
+++ labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/src/org/guvnor/tools/Activator.java	2008-07-07 22:12:42 UTC (rev 20950)
@@ -43,8 +43,7 @@
 	public void start(BundleContext context) throws Exception {
 		super.start(context);
 		plugin = this;
-		IWorkspace workspace = ResourcesPlugin.getWorkspace();
-		workspace.addResourceChangeListener(new ResourceChangeListener());
+		getWorkspace().addResourceChangeListener(new ResourceChangeListener());
 	}
 
 	/*
@@ -65,6 +64,10 @@
 		return plugin;
 	}
 	
+	public IWorkspace getWorkspace() {
+		return ResourcesPlugin.getWorkspace();
+	}
+	
 	public void writeLog(int severity, String msg, Throwable t) {
 		IStatus status = new Status(severity, PLUGIN_ID, msg, t);
 		super.getLog().log(status);
@@ -124,7 +127,7 @@
 	private static ImageDescriptor GUVLOCADD_IMG;
 	private static ImageDescriptor GUVREPWIZBAN_IMG;
 	
-	public static final String IMG_GUVCONTROLLED = "guvnor_controlled.gif";
-	public static final String IMG_GUVLOCADD = "guvnor_rep_add.gif";
-	public static final String IMG_GUVREPWIZBAN = "guvnor_rep_wizban.gif";
+	public static final String IMG_GUVCONTROLLED 		= "guvnor_controlled.gif";
+	public static final String IMG_GUVLOCADD 			= "guvnor_rep_add.gif";
+	public static final String IMG_GUVREPWIZBAN 		= "guvnor_rep_wizban.gif";
 }

Modified: labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/src/org/guvnor/tools/GuvnorDecorator.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/src/org/guvnor/tools/GuvnorDecorator.java	2008-07-07 21:27:46 UTC (rev 20949)
+++ labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/src/org/guvnor/tools/GuvnorDecorator.java	2008-07-07 22:12:42 UTC (rev 20950)
@@ -24,13 +24,10 @@
 	private void decorateResource(IResource resource, IDecoration decoration) {
 		try {	
 			if (resource instanceof IFile) {
-				if (GuvnorMetadataUtils.isGuvnorResourceCurrent(resource)) {
-					decoration.addOverlay(
-							Activator.getImageDescriptor(Activator.IMG_GUVCONTROLLED), 
-							IDecoration.TOP_RIGHT);
-				} else {
-					//TODO: Would like a different overlay icon, instead of this, but for the time being...
-					decoration.addPrefix("{g} ");
+				decoration.addOverlay(Activator.getImageDescriptor(Activator.IMG_GUVCONTROLLED), 
+						             IDecoration.TOP_RIGHT);
+				if (!GuvnorMetadataUtils.isGuvnorResourceCurrent(resource)) {
+					decoration.addSuffix(" >");
 				}
 				GuvnorMetadataProps props = GuvnorMetadataUtils.getGuvnorMetadata(resource);
 				if (props.getVersion() != null) {

Modified: labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/src/org/guvnor/tools/actions/CommitAction.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/src/org/guvnor/tools/actions/CommitAction.java	2008-07-07 21:27:46 UTC (rev 20949)
+++ labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/src/org/guvnor/tools/actions/CommitAction.java	2008-07-07 22:12:42 UTC (rev 20950)
@@ -1,17 +1,25 @@
 package org.guvnor.tools.actions;
 
+import java.net.URL;
+
 import org.eclipse.core.resources.IFile;
 import org.eclipse.core.runtime.IStatus;
 import org.eclipse.jface.action.IAction;
-import org.eclipse.jface.dialogs.MessageDialog;
 import org.eclipse.jface.viewers.ISelection;
 import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.IActionDelegate;
 import org.eclipse.ui.IObjectActionDelegate;
 import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.webdav.IResponse;
 import org.guvnor.tools.Activator;
 import org.guvnor.tools.utils.GuvnorMetadataProps;
 import org.guvnor.tools.utils.GuvnorMetadataUtils;
+import org.guvnor.tools.utils.PlatformUtils;
+import org.guvnor.tools.utils.webdav.IWebDavClient;
+import org.guvnor.tools.utils.webdav.ResourceProperties;
+import org.guvnor.tools.utils.webdav.WebDavClientFactory;
+import org.guvnor.tools.utils.webdav.WebDavException;
+import org.guvnor.tools.utils.webdav.WebDavServerCache;
 
 public class CommitAction implements IObjectActionDelegate {
 	
@@ -35,11 +43,41 @@
 	 * @see IActionDelegate#run(IAction)
 	 */
 	public void run(IAction action) {
-		Shell shell = new Shell();
-		MessageDialog.openInformation(
-			shell,
-			"JBoss Guvnor Tools Plug-in",
-			"Commit Verson was executed.");
+		if (selectedFile == null
+		   || props == null) {
+			return;
+		}
+		try {
+			IWebDavClient client = WebDavServerCache.getWebDavClient(props.getRepository());
+			if (client == null) {
+				client = WebDavClientFactory.createClient(new URL(props.getRepository()));
+				WebDavServerCache.cacheWebDavClient(props.getRepository(), client);
+			}
+			try {
+				client.putResource(props.getFullpath(), selectedFile.getContents());
+				client.closeResponse();
+			} catch (WebDavException wde) {
+				if (wde.getErrorCode() != IResponse.SC_UNAUTHORIZED) {
+					// If not an authentication failure, we don't know what to do with it
+					throw wde;
+				}
+				boolean retry = PlatformUtils.getInstance().
+									authenticateForServer(props.getRepository(), client); 
+				if (retry) {
+					client.putResource(props.getFullpath(), selectedFile.getContents());
+					client.closeResponse();
+				}
+			}
+			GuvnorMetadataUtils.markCurrentGuvnorResource(selectedFile);
+			ResourceProperties resProps = client.queryProperties(props.getFullpath());
+			client.closeResponse();
+			GuvnorMetadataProps mdProps = GuvnorMetadataUtils.getGuvnorMetadata(selectedFile);
+			mdProps.setVersion(resProps.getLastModifiedDate());
+			GuvnorMetadataUtils.setGuvnorMetadataProps(selectedFile.getFullPath(), mdProps);
+			PlatformUtils.updateDecoration();
+		} catch (Exception e) {
+			Activator.getDefault().writeLog(IStatus.ERROR, e.getMessage(), e);
+		}
 	}
 
 	/**
@@ -55,9 +93,11 @@
 			if (selection instanceof IStructuredSelection) {
 				IStructuredSelection sel = (IStructuredSelection)selection;
 				if (sel.getFirstElement() instanceof IFile) {
-					props = GuvnorMetadataUtils.getGuvnorMetadata((IFile)sel.getFirstElement());
-					if (props != null) {
-						selectedFile = (IFile)sel.getFirstElement();
+					IFile theFile = (IFile)sel.getFirstElement();
+					props = GuvnorMetadataUtils.getGuvnorMetadata(theFile);
+					if (props != null
+					   && !GuvnorMetadataUtils.isGuvnorResourceCurrent(theFile)) {
+						selectedFile = theFile;
 						action.setEnabled(true);
 					}
 				}

Modified: labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/src/org/guvnor/tools/actions/UpdateAction.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/src/org/guvnor/tools/actions/UpdateAction.java	2008-07-07 21:27:46 UTC (rev 20949)
+++ labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/src/org/guvnor/tools/actions/UpdateAction.java	2008-07-07 22:12:42 UTC (rev 20950)
@@ -17,6 +17,7 @@
 import org.guvnor.tools.utils.GuvnorMetadataUtils;
 import org.guvnor.tools.utils.PlatformUtils;
 import org.guvnor.tools.utils.webdav.IWebDavClient;
+import org.guvnor.tools.utils.webdav.ResourceProperties;
 import org.guvnor.tools.utils.webdav.WebDavClientFactory;
 import org.guvnor.tools.utils.webdav.WebDavException;
 import org.guvnor.tools.utils.webdav.WebDavServerCache;
@@ -70,7 +71,13 @@
 			}
 			if (ins != null) {
 				selectedFile.setContents(ins, true, true, null);
+				client.closeResponse();
 				GuvnorMetadataUtils.markCurrentGuvnorResource(selectedFile);
+				ResourceProperties resProps = client.queryProperties(props.getFullpath());
+				client.closeResponse();
+				GuvnorMetadataProps mdProps = GuvnorMetadataUtils.getGuvnorMetadata(selectedFile);
+				mdProps.setVersion(resProps.getLastModifiedDate());
+				GuvnorMetadataUtils.setGuvnorMetadataProps(selectedFile.getFullPath(), mdProps);
 				PlatformUtils.updateDecoration();
 			}
 		} catch (Exception e) {

Modified: labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/src/org/guvnor/tools/utils/GuvnorMetadataUtils.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/src/org/guvnor/tools/utils/GuvnorMetadataUtils.java	2008-07-07 21:27:46 UTC (rev 20949)
+++ labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/src/org/guvnor/tools/utils/GuvnorMetadataUtils.java	2008-07-07 22:12:42 UTC (rev 20950)
@@ -1,16 +1,20 @@
 package org.guvnor.tools.utils;
 
+import java.io.ByteArrayInputStream;
 import java.io.File;
 import java.io.FileOutputStream;
+import java.io.OutputStream;
 import java.util.Properties;
 
 import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IFolder;
 import org.eclipse.core.resources.IResource;
-import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.resources.IWorkspaceRoot;
 import org.eclipse.core.runtime.CoreException;
 import org.eclipse.core.runtime.IPath;
 import org.eclipse.core.runtime.Path;
 import org.eclipse.core.runtime.QualifiedName;
+import org.guvnor.tools.Activator;
 
 /**
  * A set of utilities for dealing with (local) Guvnor metadata.
@@ -52,7 +56,7 @@
 				                       props.getProperty("lastmodified"));
 	}
 	
-	public static void setGuvnorMetadataProps(File mdFile, 
+	public static void writeGuvnorMetadataProps(File mdFile, 
 			                                 GuvnorMetadataProps mdProps) throws Exception {
 		FileOutputStream fos = new FileOutputStream(mdFile);
 		Properties props = new Properties();
@@ -65,6 +69,42 @@
 		fos.close();	
 	}
 	
+	public static void setGuvnorMetadataProps(IPath controlledFile,
+			                                 GuvnorMetadataProps mdProps) throws Exception {
+		IWorkspaceRoot root = Activator.getDefault().getWorkspace().getRoot();
+		IFolder mdFolder = root.getFolder(
+							controlledFile.removeLastSegments(1).append(".guvnorinfo"));
+		if (!mdFolder.exists()) {
+			mdFolder.create(true, true, null);
+		}
+		IFile mdFile = root.getFile(
+						mdFolder.getFullPath().append("." + controlledFile.lastSegment()));
+		Properties props = new Properties();
+		if (!mdFile.exists()) {
+			mdFile.create(new ByteArrayInputStream(new byte[] {}), true, null);
+		} else {
+			props.load(mdFile.getContents());
+		}
+		if (mdProps.getRepository() != null) {
+			props.put("repository", mdProps.getRepository());
+		}
+		if (mdProps.getFullpath() != null) {
+			props.put("fullpath", mdProps.getFullpath());
+		}
+		if (mdProps.getFilename() != null) {
+			props.put("filename", mdProps.getFilename());
+		}
+		if (mdProps.getVersion() != null) {
+			props.put("lastmodified", mdProps.getVersion());
+		}
+		OutputStream os = new FileOutputStream(
+							new File(mdFile.getLocation().toOSString()));
+		props.store(os, null);
+		os.flush();
+		os.close();
+		mdFolder.refreshLocal(IResource.DEPTH_INFINITE, null);
+	}
+	
 	public static IPath createGuvnorMetadataLocation(String rootPath) throws Exception {
 		IPath path = new Path(rootPath + File.separator + ".guvnorinfo");
 		if (!path.toFile().exists()) {
@@ -80,15 +120,17 @@
 	}
 	
 	public static IFile getGuvnorControlledResource(IResource resource) throws Exception {
+		IFile res = null;
 		if (resource instanceof IFile) {
 			Properties props = new Properties();
 			props.load(((IFile)resource).getContents());
-			return (IFile)ResourcesPlugin.getWorkspace().
+			if (props.getProperty("filename") != null) {
+				res = (IFile)Activator.getDefault().getWorkspace().
 								getRoot().findMember(resource.getFullPath().
 										removeLastSegments(2).append(props.getProperty("filename")));
-		} else {
-			return null;
+			}
 		}
+		return res;
 	}
 	
 	public static boolean isGuvnorMetadata(IResource resource) {

Modified: labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/src/org/guvnor/tools/utils/webdav/IWebDavClient.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/src/org/guvnor/tools/utils/webdav/IWebDavClient.java	2008-07-07 21:27:46 UTC (rev 20949)
+++ labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/src/org/guvnor/tools/utils/webdav/IWebDavClient.java	2008-07-07 22:12:42 UTC (rev 20950)
@@ -76,5 +76,17 @@
 	 */
 	public InputStream getInputStream(String resource) throws Exception;
 	
-	public void putResource(String location, String name, InputStream is) throws Exception;
+	/**
+	 * Write a file to the WebDav repository
+	 * @param resource The path and name of the resource
+	 * @param is A stream to the file contents
+	 * @throws Exception Various WebDav errors can occur (See IResponse for details)
+	 */
+	public void putResource(String resource, InputStream is) throws Exception;
+	
+	/**
+	 * <b>Must</b> be called after server operation methods to ensure
+	 * resource clean up.
+	 */
+	public void closeResponse() throws Exception;
 }

Modified: labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/src/org/guvnor/tools/utils/webdav/WebDavClient.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/src/org/guvnor/tools/utils/webdav/WebDavClient.java	2008-07-07 21:27:46 UTC (rev 20949)
+++ labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/src/org/guvnor/tools/utils/webdav/WebDavClient.java	2008-07-07 22:12:42 UTC (rev 20950)
@@ -25,6 +25,8 @@
 	private HttpClient hClient;
 	private boolean usingSessionAuthen;
 	
+	private IResponse response;
+	
 	/**
 	 * Ctor for this wrapper WebDav client.
 	 * @param serverUrl The WebDav repository location (server)
@@ -99,9 +101,8 @@
 			IContext context = createContext();
 			context.put("Depth", "1");
 			ILocator locator = WebDAVFactory.locatorFactory.newLocator(path);
-			IResponse response = client.propfind(locator, context, null);
-			if (response.getStatusCode() != IResponse.SC_MULTI_STATUS 
-			   && response.getStatusCode() != IResponse.SC_MULTI_STATUS) {
+			response = client.propfind(locator, context, null);
+			if (response.getStatusCode() != IResponse.SC_MULTI_STATUS) {
 				throw new WebDavException("WebDav error: " + response.getStatusCode(), 
 									     response.getStatusCode());
 			}
@@ -129,9 +130,8 @@
 			IContext context = createContext();
 			context.put("Depth", "1");
 			ILocator locator = WebDAVFactory.locatorFactory.newLocator(resource);
-			IResponse response = client.propfind(locator, context, null);
-			if (response.getStatusCode() != IResponse.SC_MULTI_STATUS 
-			   && response.getStatusCode() != IResponse.SC_MULTI_STATUS) {
+			response = client.propfind(locator, context, null);
+			if (response.getStatusCode() != IResponse.SC_MULTI_STATUS) {
 				throw new WebDavException("WebDav error: " + response.getStatusCode(), 
 									     response.getStatusCode());
 			}
@@ -179,14 +179,33 @@
 	
 	/*
 	 * (non-Javadoc)
-	 * @see org.guvnor.tools.utils.webdav.IWebDavClient#putResource(java.lang.String, java.lang.String, java.io.InputStream)
+	 * @see org.guvnor.tools.utils.webdav.IWebDavClient#putResource(java.lang.String, java.io.InputStream)
 	 */
-	public void putResource(String location, String name, InputStream is) throws Exception {
-		ILocator locator = WebDAVFactory.locatorFactory.newLocator(location + "/" + name);
-		IResponse response = client.post(locator, createContext(), is);
-		if (response.getStatusCode() != IResponse.SC_OK) {
+	public void putResource(String resource, InputStream is) throws Exception {
+		if (isUsingSessionAuthenication()) {
+			if (sessionAuthen != null) {
+				hClient.setAuthenticator(sessionAuthen);
+			} else {
+				setSessionAuthentication(false);
+			}
+		}
+		ILocator locator = WebDAVFactory.locatorFactory.newLocator(resource);
+		IResponse response = client.put(locator, createContext(), is);
+		if (response.getStatusCode() != IResponse.SC_OK
+		   && response.getStatusCode() != IResponse.SC_NO_CONTENT) {
 			throw new WebDavException("WebDav error: " + response.getStatusCode(), 
 									 response.getStatusCode());
 		}
 	}
+	
+	/*
+	 * (non-Javadoc)
+	 * @see org.guvnor.tools.utils.webdav.IWebDavClient#closeResponse()
+	 */
+	public void closeResponse() throws Exception {
+		if (response != null) {
+			response.close();
+			response = null;
+		}
+	}
 }
\ No newline at end of file

Modified: labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/src/org/guvnor/tools/views/RepositoryView.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/src/org/guvnor/tools/views/RepositoryView.java	2008-07-07 21:27:46 UTC (rev 20949)
+++ labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/src/org/guvnor/tools/views/RepositoryView.java	2008-07-07 22:12:42 UTC (rev 20950)
@@ -169,7 +169,7 @@
 					               node.getGuvnorRepository().getLocation(),
 				                   node.getFullPath(), 
 				                   node.getResourceProps().getLastModifiedDate());
-		GuvnorMetadataUtils.setGuvnorMetadataProps(metaFile, mdProps);
+		GuvnorMetadataUtils.writeGuvnorMetadataProps(metaFile, mdProps);
 		res.add(metaFile.getAbsolutePath());
 		
 		return res;
@@ -302,7 +302,9 @@
 			webdav = WebDavClientFactory.createClient(new URL(rep.getLocation()));
 			WebDavServerCache.cacheWebDavClient(rep.getLocation(), webdav);
 		}
-		return webdav.getResourceContents(node.getFullPath());	
+		String res = webdav.getResourceContents(node.getFullPath());
+		webdav.closeResponse();
+		return res;
 	}
 	
 //	private void putResource(TreeParent node, String name, InputStream is) throws Exception {

Modified: labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/src/org/guvnor/tools/views/model/TreeParent.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/src/org/guvnor/tools/views/model/TreeParent.java	2008-07-07 21:27:46 UTC (rev 20949)
+++ labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/src/org/guvnor/tools/views/model/TreeParent.java	2008-07-07 22:12:42 UTC (rev 20950)
@@ -97,6 +97,7 @@
 				Map<String, ResourceProperties> listing = null;
 				try {
 					listing = webdav.listDirectory(node.getFullPath());
+					webdav.closeResponse();
 				} catch (WebDavException wde) {
 					if (wde.getErrorCode() != IResponse.SC_UNAUTHORIZED) {
 						// If not an authentication failure, we don't know what to do with it
@@ -106,6 +107,7 @@
 												node.getGuvnorRepository().getLocation(), webdav); 
 					if (retry) {
 						listing = webdav.listDirectory(node.getFullPath());
+						webdav.closeResponse();
 					}
 				}
 				if (listing != null) {

Modified: labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/src/org/guvnor/tools/wizards/CheckoutWizard.java
===================================================================
--- labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/src/org/guvnor/tools/wizards/CheckoutWizard.java	2008-07-07 21:27:46 UTC (rev 20949)
+++ labs/jbossrules/trunk/drools-eclipse/org.guvnor.tools/src/org/guvnor/tools/wizards/CheckoutWizard.java	2008-07-07 22:12:42 UTC (rev 20950)
@@ -1,17 +1,17 @@
 package org.guvnor.tools.wizards;
 
-import java.util.Properties;
+import java.io.ByteArrayInputStream;
 
 import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IWorkspaceRoot;
-import org.eclipse.core.resources.ResourcesPlugin;
 import org.eclipse.core.runtime.IPath;
 import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Path;
 import org.eclipse.jface.viewers.IStructuredSelection;
 import org.eclipse.jface.wizard.Wizard;
 import org.eclipse.ui.INewWizard;
 import org.eclipse.ui.IWorkbench;
 import org.guvnor.tools.Activator;
+import org.guvnor.tools.utils.GuvnorMetadataProps;
 import org.guvnor.tools.utils.GuvnorMetadataUtils;
 import org.guvnor.tools.utils.webdav.IWebDavClient;
 import org.guvnor.tools.utils.webdav.ResourceProperties;
@@ -77,14 +77,33 @@
 			// to choose resources. Therefore, we should have a cached repository connection
 			// that is authenticated already. If not, something is really strange.
 			assert(webdav != null);
-			IPath metaPath = GuvnorMetadataUtils.createGuvnorMetadataLocation(model.getTargetLocation());
-			IWorkspaceRoot wsRoot = ResourcesPlugin.getWorkspace().getRoot();
 			for (String oneResource:model.getResources()) {
 				// Get the metadata properties
 				ResourceProperties resprops = webdav.queryProperties(oneResource);
 				if (resprops == null) {
 					throw new Exception("Null resource properties for " + oneResource);
 				}
+				webdav.closeResponse();
+				String contents = webdav.getResourceContents(oneResource);
+				webdav.closeResponse();
+				IPath targetLocation = new Path(model.getTargetLocation());
+				IFile targetFile = Activator.getDefault().getWorkspace().
+									getRoot().getFile(targetLocation.append(
+											oneResource.substring(oneResource.lastIndexOf('/'))));
+				ByteArrayInputStream bis = 
+							new ByteArrayInputStream(contents.getBytes(targetFile.getCharset()));
+				if (targetFile.exists()) {
+					//TODO: Prompt for overwrite
+					targetFile.setContents(bis, true, true, null);
+				} else {
+					targetFile.create(bis, true, null);
+				}
+				GuvnorMetadataProps mdProps = new GuvnorMetadataProps(targetFile.getName(), 
+						                                             model.getRepLocation(), 
+						                                             oneResource, 
+						                                             resprops.getLastModifiedDate());
+				GuvnorMetadataUtils.setGuvnorMetadataProps(targetFile.getFullPath(), mdProps);
+				GuvnorMetadataUtils.markCurrentGuvnorResource(targetFile);
 			}
 		} catch (Exception e) {
 			Activator.getDefault().writeLog(IStatus.ERROR, e.getMessage(), e);




More information about the jboss-svn-commits mailing list