geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ga...@apache.org
Subject svn commit: r1363220 - in /geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core: DeploymentUtils.java GeronimoServerBehaviourDelegate.java
Date Thu, 19 Jul 2012 05:34:56 GMT
Author: gawor
Date: Thu Jul 19 05:34:56 2012
New Revision: 1363220

URL: http://svn.apache.org/viewvc?rev=1363220&view=rev
Log:
improve handling and error tracking when publishing file modifications directly to a directory

Modified:
    geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/DeploymentUtils.java
    geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/GeronimoServerBehaviourDelegate.java

Modified: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/DeploymentUtils.java
URL: http://svn.apache.org/viewvc/geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/DeploymentUtils.java?rev=1363220&r1=1363219&r2=1363220&view=diff
==============================================================================
--- geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/DeploymentUtils.java
(original)
+++ geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/DeploymentUtils.java
Thu Jul 19 05:34:56 2012
@@ -17,7 +17,10 @@
 package org.apache.geronimo.st.v30.core;
 
 import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
 import java.io.IOException;
+import java.io.InputStream;
 import java.util.ArrayList;
 import java.util.List;
 
@@ -33,6 +36,7 @@ import org.apache.geronimo.st.v30.core.i
 import org.apache.geronimo.st.v30.core.osgi.AriesHelper;
 import org.apache.geronimo.st.v30.core.osgi.OsgiConstants;
 import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.resources.IFile;
 import org.eclipse.core.runtime.CoreException;
 import org.eclipse.core.runtime.IPath;
 import org.eclipse.core.runtime.IStatus;
@@ -330,17 +334,15 @@ public class DeploymentUtils {
         return null;
     }
     
-    public static List<IModuleResourceDelta> getAffectedFiles(IModuleResourceDelta
delta, List<String> includes, List<String> excludes) {
-        Trace.tracePoint("Entry", Activator.traceCore, "DeploymentUtils.getAffectedFiles",
delta, includes, excludes);
-
+    public static boolean isMatchingDelta(IModuleResourceDelta delta, List<String>
includes, List<String> excludes) {
+        Trace.tracePoint("Entry", Activator.traceCore, "DeploymentUtils.isMatchingDelta",
delta, includes, excludes);
+        
         if (delta == null) {
-            Trace.tracePoint("Exit ", Activator.traceCore, "DeploymentUtils.getAffectedFiles",
(Object) null);
-            return null;
-        }
-
+            Trace.tracePoint("Exit ", Activator.traceCore, "DeploymentUtils.isMatchingDelta",
delta, false);
+            return false;
+        } 
+        
         IModuleResource resource = delta.getModuleResource();
-        List<IModuleResourceDelta> fileList = new ArrayList<IModuleResourceDelta>();
-
         if (resource instanceof IModuleFile) {
             IModuleFile moduleFile = (IModuleFile) resource;
             String name = moduleFile.getName();
@@ -349,30 +351,29 @@ public class DeploymentUtils {
                 name = relativePath.toOSString() + File.separator + moduleFile.getName();
             }
             if (hasMatch(name, excludes)) {
-                Trace.tracePoint("Exit ", Activator.traceCore, "DeploymentUtils.getAffectedFiles",
"Excluded", name);
-                return null;
+                Trace.tracePoint("Exit ", Activator.traceCore, "DeploymentUtils.isMatchingDelta",
"Excluded", name);
+                return false;
             }
             if (hasMatch(name, includes)) {
-                fileList.add(delta);
+                // we have a match - keep checking
             } else {
-                Trace.tracePoint("Exit ", Activator.traceCore, "DeploymentUtils.getAffectedFiles",
"Not included", name);
-                return null;
+                Trace.tracePoint("Exit ", Activator.traceCore, "DeploymentUtils.isMatchingDelta",
"Not included", name);
+                return false;
             }
         } else if (resource instanceof IModuleFolder) {
             IModuleResourceDelta[] deltaArray = delta.getAffectedChildren();
             for (IModuleResourceDelta childDelta : deltaArray) {
-                List<IModuleResourceDelta> deltaChildren = getAffectedFiles(childDelta,
includes, excludes);
-                if (deltaChildren != null) {
-                    fileList.addAll(deltaChildren);
+                if (isMatchingDelta(childDelta, includes, excludes)) {
+                    // we have a match - keep checking
                 } else {
-                    Trace.tracePoint("Exit ", Activator.traceCore, "DeploymentUtils.getAffectedFiles",
(Object) null);
-                    return null;
+                    Trace.tracePoint("Exit ", Activator.traceCore, "DeploymentUtils.isMatchingDelta",
delta, false);
+                    return false;
                 }
             }
         }
 
-        Trace.tracePoint("Exit ", Activator.traceCore, "DeploymentUtils.getAffectedFiles",
fileList);
-        return fileList;
+        Trace.tracePoint("Exit ", Activator.traceCore, "DeploymentUtils.isMatchingDelta",
delta, true);
+        return true;
     }
     
     private static boolean hasMatch(String name, List<String> patterns) {
@@ -384,6 +385,93 @@ public class DeploymentUtils {
         return false;
     }     
     
+    public static void publishDelta(IModuleResourceDelta delta, IPath publishPath, List<IStatus>
statusList) {
+        IModuleResource resource = delta.getModuleResource();
+        int kind = delta.getKind();
+
+        if (resource instanceof IModuleFile) {
+            // it's a file        
+            IPath filePath = publishPath.append(resource.getModuleRelativePath()).append(resource.getName());
+            File file = filePath.toFile();
+            if (kind == IModuleResourceDelta.REMOVED) {
+                if (file.exists() && !file.delete()) {
+                    statusList.add(new Status(IStatus.ERROR, Activator.PLUGIN_ID, 0, "Unable
to delete file: " + file.getAbsolutePath(), null));
+                }
+            } else {
+                File parentFile = file.getParentFile();
+                if (parentFile != null && !parentFile.exists()) {
+                    if (!parentFile.mkdirs()) {
+                        statusList.add(new Status(IStatus.ERROR, Activator.PLUGIN_ID, 0,
"Unable to create parent directory: " + parentFile.getAbsolutePath(), null));
+                        return;
+                    }
+                }
+                
+                IModuleFile moduleFile = (IModuleFile) resource;
+                try {
+                    copyFile(moduleFile, file);
+                } catch (CoreException e) {
+                    statusList.add(e.getStatus());
+                } catch (IOException e) {
+                    statusList.add(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Error
copying file " + file.getAbsolutePath(), e));
+                }
+            }
+        } else if (resource instanceof IModuleFolder) {
+            // it's directory
+            if (kind == IModuleResourceDelta.ADDED) {
+                IPath filePath = publishPath.append(resource.getModuleRelativePath()).append(resource.getName());
+                File file = filePath.toFile();
+                if (!file.exists() && !file.mkdirs()) {
+                    statusList.add(new Status(IStatus.ERROR, Activator.PLUGIN_ID, 0, "Unable
to create directory: " + file.getAbsolutePath(), null));
+                    return;
+                }
+            }
+
+            IModuleResourceDelta[] childDeltas = delta.getAffectedChildren();
+            if (childDeltas != null) {
+                for (IModuleResourceDelta childDelta : childDeltas) {
+                    publishDelta(childDelta, publishPath, statusList);
+                }
+            }
+
+            if (kind == IModuleResourceDelta.REMOVED) {
+                IPath filePath = publishPath.append(resource.getModuleRelativePath()).append(resource.getName());
+                File file = filePath.toFile();
+                if (file.exists() && !file.delete()) {
+                    statusList.add(new Status(IStatus.ERROR, Activator.PLUGIN_ID, 0, "Unable
to delete directory: " + file.getAbsolutePath(), null));
+                }
+            }
+        }
+    }
+    
+    private static void copyFile(IModuleFile moduleFile, File target) throws CoreException,
IOException {
+        byte[] buffer = new byte[10 * 1024];
+        int bytesRead;    
+        InputStream in = null;
+        FileOutputStream out = null;
+        try {
+            IFile srcIFile = (IFile) moduleFile.getAdapter(IFile.class);
+            if (srcIFile != null) {
+                in = srcIFile.getContents();
+            } else {
+                File srcFile = (File) moduleFile.getAdapter(File.class);
+                in = new FileInputStream(srcFile);
+            }
+        
+            out = new FileOutputStream(target);
+            
+            while ((bytesRead = in.read(buffer)) > 0) {
+                out.write(buffer, 0, bytesRead);
+            }
+        } finally {
+            if (in != null) {
+                try { in.close(); } catch (IOException ignore) {}
+            }
+            if (out != null) {
+                try { out.close(); } catch (IOException ignore) {}
+            }
+        }
+    }
+    
     public static boolean isInstalledModule(IServer server, String configId) {
         Trace.tracePoint("Entry", Activator.traceCore, "DeploymentUtils.isInstalledModule",
server, configId);
         boolean isInstalled = false;

Modified: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/GeronimoServerBehaviourDelegate.java
URL: http://svn.apache.org/viewvc/geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/GeronimoServerBehaviourDelegate.java?rev=1363220&r1=1363219&r2=1363220&view=diff
==============================================================================
--- geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/GeronimoServerBehaviourDelegate.java
(original)
+++ geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.v30.core/src/main/java/org/apache/geronimo/st/v30/core/GeronimoServerBehaviourDelegate.java
Thu Jul 19 05:34:56 2012
@@ -17,11 +17,6 @@
 package org.apache.geronimo.st.v30.core;
 
 import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
 import java.net.URL;
 import java.util.ArrayList;
 import java.util.Arrays;
@@ -69,7 +64,6 @@ import org.apache.geronimo.st.v30.core.o
 import org.apache.geronimo.st.v30.core.osgi.OSGiModuleHandler;
 import org.apache.geronimo.system.jmx.KernelDelegate;
 import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.core.resources.IFile;
 import org.eclipse.core.resources.IProject;
 import org.eclipse.core.runtime.CoreException;
 import org.eclipse.core.runtime.IPath;
@@ -112,7 +106,6 @@ import org.eclipse.wst.server.core.model
 import org.eclipse.wst.server.core.model.IModuleResource;
 import org.eclipse.wst.server.core.model.IModuleResourceDelta;
 import org.eclipse.wst.server.core.model.ServerBehaviourDelegate;
-import org.eclipse.wst.server.core.util.PublishHelper;
 import org.eclipse.wst.server.core.util.SocketUtil;
 
 /**
@@ -1094,120 +1087,41 @@ public class GeronimoServerBehaviourDele
             return null;
         }
 
-        List<IModuleResourceDelta> modifiedFiles = findModifiedFiles(module);
-        if (modifiedFiles == null) {
+        IModuleResourceDelta[] deltas = getPublishedResourceDelta(module);
+        if (!canPublishDelta(deltas)) {
             Trace.tracePoint("Exit", Activator.traceCore, "GeronimoServerBehaviourDelegate.tryFileReplace",
"Some modified files cannot be replaced");
             return null;
         }
-        Trace.trace(Trace.INFO, "Modified files: " + modifiedFiles, Activator.logCore);
 
-        IStatus status = findAndReplaceFiles(module[module.length - 1], modifiedFiles, publishLocation);
+        Path publishPath = new Path(publishLocation);
+        List<IStatus> statusList = new ArrayList<IStatus>();
+        for (IModuleResourceDelta delta : deltas) {
+            DeploymentUtils.publishDelta(delta, publishPath, statusList);
+        }
+        
+        IStatus status = Status.OK_STATUS;
+        if (!statusList.isEmpty()) {
+            IStatus[] statusArray = new IStatus[statusList.size()];
+            statusList.toArray(statusArray);
+            status = new MultiStatus(Activator.PLUGIN_ID, 0, statusArray, "", null);
+        }
+
         Trace.tracePoint("Exit", Activator.traceCore, "GeronimoServerBehaviourDelegate.tryFileReplace",
status);
         return status;
     }
         
-    private List<IModuleResourceDelta> findModifiedFiles(IModule[] module) {
-        IModuleResourceDelta[] deltaArray = getPublishedResourceDelta(module);
-
+    private boolean canPublishDelta(IModuleResourceDelta[] deltaArray) {
         GeronimoServerDelegate delegate = getServerDelegate();
         List<String> includes = delegate.getNoRedeployFilePatternsAsList(true);
         List<String> excludes = delegate.getNoRedeployFilePatternsAsList(false);
-        
-        List<IModuleResourceDelta> modifiedFiles = new ArrayList<IModuleResourceDelta>();
         for (IModuleResourceDelta delta : deltaArray) {
-            List<IModuleResourceDelta> files = DeploymentUtils.getAffectedFiles(delta,
includes, excludes);
-            // if null then some other files were changed that we cannot just copy/replace.
-            if (files == null) {
-                return null;
+            if (DeploymentUtils.isMatchingDelta(delta, includes, excludes)) {
+                // delta only contains files that can be copied / replaced - keep checking
             } else {
-                modifiedFiles.addAll(files);
-            }
-        }
-        return modifiedFiles;
-    }
-    
-    /*
-     * This method is used to replace updated files without redeploying the entire module.

-     */
-    private IStatus findAndReplaceFiles(IModule module, List<IModuleResourceDelta>
modifiedFiles, String documentBase) {
-        Trace.trace(Trace.INFO, "Replacing updated files for " + module.getName() + " module.",
Activator.logCore);
-        
-        String ch = File.separator;
-        byte[] buffer = new byte[10 * 1024];
-        int bytesRead;
-        
-        for (IModuleResourceDelta deltaModule : modifiedFiles) {
-            IModuleFile moduleFile = (IModuleFile) deltaModule.getModuleResource();
-
-            StringBuilder target = new StringBuilder(documentBase);
-            target.append(ch);
-            String relativePath = moduleFile.getModuleRelativePath().toOSString();
-            if (relativePath != null && relativePath.length() != 0) {
-                target.append(relativePath);
-                target.append(ch);
-            } 
-            target.append(moduleFile.getName());
-            
-            File file = new File(target.toString());
-            if (!file.isAbsolute()) {
-                return new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Unexpected publish
location", null);
+                return false;
             }
-            
-            switch (deltaModule.getKind()) {
-            case IModuleResourceDelta.REMOVED:
-                if (file.exists()) {
-                    file.delete();
-                }
-                break;
-            case IModuleResourceDelta.ADDED:
-            case IModuleResourceDelta.CHANGED:
-                File parentFile = file.getParentFile();
-                if (parentFile != null && !parentFile.exists()) {
-                    if (!parentFile.mkdirs()) {
-                        Trace.trace(Trace.ERROR, "Cannot create target directory: " + parentFile,
Activator.logCore);
-                        return new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Cannot create
target directory", null);
-                    }
-                }
-                
-                String sourceFile = relativePath;
-                InputStream in = null;
-                FileOutputStream out = null;
-                try {
-                    IFile srcIFile = (IFile) moduleFile.getAdapter(IFile.class);
-                    if (srcIFile != null) {
-                        in = srcIFile.getContents();
-                    } else {
-                        File srcFile = (File) moduleFile.getAdapter(File.class);
-                        in = new FileInputStream(srcFile);
-                    }
-                
-                    out = new FileOutputStream(file);
-                    
-                    while ((bytesRead = in.read(buffer)) > 0) {
-                        out.write(buffer, 0, bytesRead);
-                    }
-                } catch (FileNotFoundException e) {
-                    Trace.trace(Trace.ERROR, "Cannot find file to copy: " + sourceFile, e,
Activator.logCore);
-                    return new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Cannot find file
" + sourceFile, e);
-                } catch (IOException e) {
-                    Trace.trace(Trace.ERROR, "Cannot copy file: " + sourceFile, e, Activator.logCore);
-                    return new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Cannot copy file
" + sourceFile, e);
-                } catch (CoreException e) {
-                    Trace.trace(Trace.ERROR, "Cannot copy file: " + sourceFile, e, Activator.logCore);
-                    return e.getStatus();
-                } finally {
-                    if (in != null) {
-                        try { in.close(); } catch (IOException ignore) {}
-                    }
-                    if (out != null) {
-                        try { out.close(); } catch (IOException ignore) {}
-                    }
-                }
-                break;
-            }                    
         }
-
-        return Status.OK_STATUS;
+        return true;
     }
 
     public Map getServerInstanceProperties() {



Mime
View raw message