geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ammul...@apache.org
Subject svn commit: r427650 - in /geronimo/branches/1.1: applications/console-standard/src/java/org/apache/geronimo/console/car/ modules/common/src/java/org/apache/geronimo/common/ modules/deploy-jsr88/src/java/org/apache/geronimo/deployment/plugin/ modules/sy...
Date Tue, 01 Aug 2006 17:13:55 GMT
Author: ammulder
Date: Tue Aug  1 10:13:55 2006
New Revision: 427650

URL: http://svn.apache.org/viewvc?rev=427650&view=rev
Log:
Fix copying plugins from server to server (GERONIMO-2228)
Fix the fix to the plugin install progress display (GERONIMO-1869)
1.1 branch fix for repository that won't unpack a module that
  doesn't have a type of CAR (GERONIMO-2258)

Added:
    geronimo/branches/1.1/modules/common/src/java/org/apache/geronimo/common/FileUtils.java
  (with props)
Modified:
    geronimo/branches/1.1/applications/console-standard/src/java/org/apache/geronimo/console/car/GeronimoAsMavenServlet.java
    geronimo/branches/1.1/modules/deploy-jsr88/src/java/org/apache/geronimo/deployment/plugin/ConfigIDExtractor.java
    geronimo/branches/1.1/modules/system/src/java/org/apache/geronimo/system/repository/AbstractRepository.java

Modified: geronimo/branches/1.1/applications/console-standard/src/java/org/apache/geronimo/console/car/GeronimoAsMavenServlet.java
URL: http://svn.apache.org/viewvc/geronimo/branches/1.1/applications/console-standard/src/java/org/apache/geronimo/console/car/GeronimoAsMavenServlet.java?rev=427650&r1=427649&r2=427650&view=diff
==============================================================================
--- geronimo/branches/1.1/applications/console-standard/src/java/org/apache/geronimo/console/car/GeronimoAsMavenServlet.java
(original)
+++ geronimo/branches/1.1/applications/console-standard/src/java/org/apache/geronimo/console/car/GeronimoAsMavenServlet.java
Tue Aug  1 10:13:55 2006
@@ -51,6 +51,7 @@
 import org.apache.geronimo.kernel.config.ConfigurationStore;
 import org.apache.geronimo.kernel.config.ConfigurationUtil;
 import org.apache.geronimo.kernel.config.NoSuchStoreException;
+import org.apache.geronimo.kernel.config.NoSuchConfigException;
 import org.apache.geronimo.kernel.repository.Artifact;
 import org.apache.geronimo.kernel.repository.Repository;
 import org.apache.geronimo.kernel.repository.Version;
@@ -116,54 +117,54 @@
             if(path.startsWith("/")) {
                 path = path.substring(1);
             }
-            String[] parts = path.split("/");
-            if(parts.length != 3) {
-                response.sendError(404, "Unrecognized path form "+path);
+            String configId = parsePath(path, response);
+            if(configId == null) { // we already sent the 404
                 return;
             }
-            String groupId = parts[0];
-            String type = parts[1].substring(0, parts[1].length()-1);
-            if(!parts[2].endsWith("."+type)) {
-                response.sendError(404, "Unrecognized path structure "+path);
-            }
-            parts[2] = parts[2].substring(0, parts[2].length()-(type.length()+1));
-            int pos = parts[2].lastIndexOf("-");
-            String version = parts[2].substring(pos+1);
-            if(version.equalsIgnoreCase("SNAPSHOT")) {
-                pos = parts[2].lastIndexOf("-", pos-1);
-                version = parts[2].substring(pos+1);
-            }
-            String artifactId = parts[2].substring(0, pos);
-            String configId = groupId+"/"+artifactId+"/"+version+"/"+type;
             if(!produceDownloadFile(kernel, Artifact.create(configId), response, reply))
{
                 response.sendError(404, "Cannot locate download file "+path);
             }
         }
     }
 
+    private static String parsePath(String path, HttpServletResponse response) throws IOException
{
+        String[] parts = path.split("/");
+        String groupId, artifactId, version, type;
+        if(parts.length < 4) {
+            response.sendError(404, "Unrecognized path form "+path);
+            return null;
+        } else {  // e.g.   console/MyDatabase/1.0-SNAPSHOT/MyDatabase-1.0-SNAPSHOT.rar
+            groupId = parts[0];
+            for(int i=4; i<parts.length; i++) {
+                groupId = groupId+"."+parts[i-3];
+            }
+            artifactId = parts[parts.length-3];
+            version = parts[parts.length-2];
+            if(!parts[parts.length-1].startsWith(artifactId+"-"+version)) {
+                response.sendError(404, "Unrecognized path structure "+path);
+                return null;
+            }
+            type = parts[parts.length-1].substring(artifactId.length()+version.length()+2);
+        }
+        return groupId+"/"+artifactId+"/"+version+"/"+type;
+    }
+
     private boolean produceDownloadFile(Kernel kernel, Artifact configId, HttpServletResponse
response, boolean reply) throws IOException {
         //todo: replace kernel mumbo jumbo with JSR-77 navigation
         // Step 1: check if it's in a configuration store
         ConfigurationManager mgr = ConfigurationUtil.getConfigurationManager(kernel);
-        List stores = mgr.listStores();
-        for (int i = 0; i < stores.size(); i++) {
-            AbstractName name = (AbstractName) stores.get(i);
-            //todo: this is bad!!!
-            if(name.getName().get(NameFactory.J2EE_NAME).equals("Local")) {
-                ConfigurationStore store = (ConfigurationStore) kernel.getProxyManager().createProxy(name,
ConfigurationStore.class);
-                if(store.containsConfiguration(configId)) {
-                    response.setContentType("application/zip");
-                    if(!reply) {
-                        return true;
-                    }
-                    try {
-                        kernel.invoke(name, "exportConfiguration", new Object[]{configId.toString(),
response.getOutputStream()}, new String[]{String.class.getName(), OutputStream.class.getName()});
-                        return true;
-                    } catch (Exception e) {
-                        log.error("Unable to export configuration ZIP", e);
-                        throw new IOException("Unable to write ZIP file: "+e.getMessage());
-                    }
-                }
+        if(mgr.isConfiguration(configId)) {
+            ConfigurationStore store = mgr.getStoreForConfiguration(configId);
+            response.setContentType("application/zip");
+            if(!reply) {
+                return true;
+            }
+            try {
+                store.exportConfiguration(configId, response.getOutputStream());
+                return true;
+            } catch (NoSuchConfigException e) {
+                log.error("Inconsistent ConfigurationStore data; ConfigManager claims it
has configuration "+configId+" but store claims it doesn't",e);
+                throw new IOException("Unable to write ZIP file; see server log for details");
             }
         }
         // Step 2: check if it's in a repository
@@ -173,7 +174,7 @@
             Repository repo = (Repository) kernel.getProxyManager().createProxy(name, Repository.class);
             if(repo.contains(configId)) {
                 File path = repo.getLocation(configId);
-                if(!path.exists()) throw new IllegalStateException("Can't find file '"+path.getAbsolutePath()+"'");
+                if(!path.exists()) throw new IllegalStateException("Can't find file '"+path.getAbsolutePath()+"'
though repository said there's an artifact there!");
                 response.setContentType("application/zip");
                 if(!reply) {
                     return true;
@@ -202,6 +203,7 @@
         DocumentBuilder builder = factory.newDocumentBuilder();
         Document doc = builder.newDocument();
         Element root = doc.createElementNS("http://geronimo.apache.org/xml/ns/plugins-1.1",
"geronimo-plugin-list");
+        root.setAttribute("xmlns", "http://geronimo.apache.org/xml/ns/plugins-1.1");
         doc.appendChild(root);
         List stores = mgr.listStores();
         for (int i = 0; i < stores.size(); i++) {
@@ -255,7 +257,7 @@
                 // Skip repositories since we want the download to come from here
             }
         }
-        String repo = request.getProtocol()+"://"+request.getServerName()+":"+request.getServerPort()+request.getContextPath()+request.getServletPath();
+        String repo = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+request.getContextPath()+request.getServletPath();
         if(!repo.endsWith("/")) repo += "/";
         createText(doc, root, "default-repository", repo);
         TransformerFactory xfactory = TransformerFactory.newInstance();

Added: geronimo/branches/1.1/modules/common/src/java/org/apache/geronimo/common/FileUtils.java
URL: http://svn.apache.org/viewvc/geronimo/branches/1.1/modules/common/src/java/org/apache/geronimo/common/FileUtils.java?rev=427650&view=auto
==============================================================================
--- geronimo/branches/1.1/modules/common/src/java/org/apache/geronimo/common/FileUtils.java
(added)
+++ geronimo/branches/1.1/modules/common/src/java/org/apache/geronimo/common/FileUtils.java
Tue Aug  1 10:13:55 2006
@@ -0,0 +1,64 @@
+/**
+ *
+ * Copyright 2005 The Apache Software Foundation
+ *
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.geronimo.common;
+
+import java.io.File;
+import java.io.DataInputStream;
+import java.io.BufferedInputStream;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.util.zip.ZipFile;
+
+/**
+ * Utility functions related to Files.
+ *
+ * @version $Rev: 368994 $ $Date: 2006-01-14 02:07:18 -0500 (Sat, 14 Jan 2006) $
+ */
+public class FileUtils {
+    /**
+     * Determine whether a file is a JAR File.
+     */
+    public static boolean isJarFile(File file) throws IOException {
+        if(!isZipFile(file)) {
+            return false;
+        }
+        ZipFile zip = new ZipFile(file);
+        boolean manifest = zip.getEntry("META-INF/MANIFEST.MF") != null;
+        zip.close();
+        return manifest;
+    }
+
+    /**
+     * Determine whether a file is a ZIP File.
+     */
+    public static boolean isZipFile(File file) throws IOException {
+        if(file.isDirectory()) {
+            return false;
+        }
+        if(!file.canRead()) {
+            throw new IOException("Cannot read file "+file.getAbsolutePath());
+        }
+        if(file.length() < 4) {
+            return false;
+        }
+        DataInputStream in = new DataInputStream(new BufferedInputStream(new FileInputStream(file)));
+        int test = in.readInt();
+        in.close();
+        return test == 0x504b0304;
+    }
+
+}

Propchange: geronimo/branches/1.1/modules/common/src/java/org/apache/geronimo/common/FileUtils.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: geronimo/branches/1.1/modules/deploy-jsr88/src/java/org/apache/geronimo/deployment/plugin/ConfigIDExtractor.java
URL: http://svn.apache.org/viewvc/geronimo/branches/1.1/modules/deploy-jsr88/src/java/org/apache/geronimo/deployment/plugin/ConfigIDExtractor.java?rev=427650&r1=427649&r2=427650&view=diff
==============================================================================
--- geronimo/branches/1.1/modules/deploy-jsr88/src/java/org/apache/geronimo/deployment/plugin/ConfigIDExtractor.java
(original)
+++ geronimo/branches/1.1/modules/deploy-jsr88/src/java/org/apache/geronimo/deployment/plugin/ConfigIDExtractor.java
Tue Aug  1 10:13:55 2006
@@ -36,6 +36,7 @@
 import javax.xml.parsers.ParserConfigurationException;
 import javax.enterprise.deploy.spi.TargetModuleID;
 import org.apache.geronimo.common.DeploymentException;
+import org.apache.geronimo.common.FileUtils;
 import org.apache.geronimo.kernel.repository.Artifact;
 import org.apache.geronimo.kernel.repository.Version;
 import org.xml.sax.InputSource;
@@ -231,24 +232,14 @@
 
     /**
      * Try to determine whether a file is a JAR File (or, at least, a ZIP file).
+     *
+     * @deprecated See org.apache.geronimo.common.FileUtils.isJarFile
      */
     public static boolean isJarFile(File file) throws DeploymentException {
-        if(file.isDirectory()) {
-            return false;
-        }
-        if(!file.canRead()) {
-            throw new DeploymentException("Cannot read file "+file.getAbsolutePath());
-        }
-        if(file.length() < 4) {
-            return false;
-        }
         try {
-            DataInputStream in = new DataInputStream(new BufferedInputStream(new FileInputStream(file)));
-            int test = in.readInt();
-            in.close();
-            return test == 0x504b0304;
-        } catch(IOException e) {
-            throw new DeploymentException("Cannot read from file "+file.getAbsolutePath(),
e);
+            return FileUtils.isZipFile(file);
+        } catch (IOException e) {
+            throw new DeploymentException("Unable to read file "+file.getAbsolutePath());
         }
     }
 

Modified: geronimo/branches/1.1/modules/system/src/java/org/apache/geronimo/system/repository/AbstractRepository.java
URL: http://svn.apache.org/viewvc/geronimo/branches/1.1/modules/system/src/java/org/apache/geronimo/system/repository/AbstractRepository.java?rev=427650&r1=427649&r2=427650&view=diff
==============================================================================
--- geronimo/branches/1.1/modules/system/src/java/org/apache/geronimo/system/repository/AbstractRepository.java
(original)
+++ geronimo/branches/1.1/modules/system/src/java/org/apache/geronimo/system/repository/AbstractRepository.java
Tue Aug  1 10:13:55 2006
@@ -42,6 +42,7 @@
 import org.apache.geronimo.kernel.repository.FileWriteMonitor;
 import org.apache.geronimo.kernel.repository.WriteableRepository;
 import org.apache.geronimo.system.serverinfo.ServerInfo;
+import org.apache.geronimo.common.FileUtils;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 import org.w3c.dom.Node;
@@ -190,18 +191,21 @@
             throw new IllegalArgumentException("Cannot read source file at " + source.getAbsolutePath());
         }
         int size = 0;
-        try {
+        boolean forceConfiguration = false;
+        if(FileUtils.isZipFile(source)) {
             ZipFile zip = new ZipFile(source);
             for (Enumeration entries=zip.entries(); entries.hasMoreElements();) {
             	ZipEntry entry = (ZipEntry)entries.nextElement();
-            	size += entry.getSize();
+                if(entry.getName().equals("META-INF/config.ser")) {
+                    forceConfiguration = true;
+                }
+                size += entry.getSize();
             }
-        } catch (ZipException ze) {
-        	size = (int)source.length();
+            zip.close();
         }
         FileInputStream is = new FileInputStream(source);
         try {
-            copyToRepository(is, size, destination, monitor);
+            copyToRepository(is, size, destination, monitor, forceConfiguration);
         } finally {
             try {
                 is.close();
@@ -212,6 +216,10 @@
     }
 
     public void copyToRepository(InputStream source, int size, Artifact destination, FileWriteMonitor
monitor) throws IOException {
+        copyToRepository(source, size, destination, monitor, false);
+    }
+
+    private void copyToRepository(InputStream source, int size, Artifact destination, FileWriteMonitor
monitor, boolean isConfiguration) throws IOException {
         if(!destination.isResolved()) {
             throw new IllegalArgumentException("Artifact "+destination+" is not fully resolved");
         }
@@ -228,11 +236,16 @@
             throw new IllegalArgumentException("Destination " + location.getAbsolutePath()
+ " already exists!");
         }
 
-        ArtifactTypeHandler typeHandler = (ArtifactTypeHandler) typeHandlers.get(destination.getType());
+        ArtifactTypeHandler typeHandler;
+        if(isConfiguration) {
+            typeHandler = (ArtifactTypeHandler) typeHandlers.get("car");
+        } else {
+            typeHandler = (ArtifactTypeHandler) typeHandlers.get(destination.getType());
+        }
         if (typeHandler == null) typeHandler = DEFAULT_TYPE_HANDLER;
         typeHandler.install(source, size, destination, monitor, location);
 
-        if (destination.getType().equalsIgnoreCase("car")) {
+        if (isConfiguration || destination.getType().equalsIgnoreCase("car")) {
             System.out.println("############################################################");
             System.out.println("# Installed configuration");
             System.out.println("#   id = " + destination);



Mime
View raw message