geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jdil...@apache.org
Subject svn commit: r427996 - in /geronimo/sandbox/svkmerge/trunk: ./ applications/console/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/deployme...
Date Wed, 02 Aug 2006 14:14:46 GMT
Author: jdillon
Date: Wed Aug  2 07:14:45 2006
New Revision: 427996

URL: http://svn.apache.org/viewvc?rev=427996&view=rev
Log:
 r612@dyn456093 (orig r427669):  ammulder | 2006-08-01 11:16:31 -0700
 Merge fix for GERONIMO-2228 (and plumbing for GERONIMO-1869) to trunk.
 

Added:
    geronimo/sandbox/svkmerge/trunk/modules/common/src/java/org/apache/geronimo/common/FileUtils.java
  (with props)
Modified:
    geronimo/sandbox/svkmerge/trunk/   (props changed)
    geronimo/sandbox/svkmerge/trunk/applications/console/console-standard/src/java/org/apache/geronimo/console/car/GeronimoAsMavenServlet.java
    geronimo/sandbox/svkmerge/trunk/modules/deploy-jsr88/src/java/org/apache/geronimo/deployment/plugin/ConfigIDExtractor.java

Propchange: geronimo/sandbox/svkmerge/trunk/
------------------------------------------------------------------------------
--- svk:merge (original)
+++ svk:merge Wed Aug  2 07:14:45 2006
@@ -1,2 +1,2 @@
 13f79535-47bb-0310-9956-ffa450edef68:/geronimo/sandbox/svkmerge/m2migration:419395
-13f79535-47bb-0310-9956-ffa450edef68:/geronimo/trunk:427563
+13f79535-47bb-0310-9956-ffa450edef68:/geronimo/trunk:427669

Modified: geronimo/sandbox/svkmerge/trunk/applications/console/console-standard/src/java/org/apache/geronimo/console/car/GeronimoAsMavenServlet.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/svkmerge/trunk/applications/console/console-standard/src/java/org/apache/geronimo/console/car/GeronimoAsMavenServlet.java?rev=427996&r1=427995&r2=427996&view=diff
==============================================================================
--- geronimo/sandbox/svkmerge/trunk/applications/console/console-standard/src/java/org/apache/geronimo/console/car/GeronimoAsMavenServlet.java
(original)
+++ geronimo/sandbox/svkmerge/trunk/applications/console/console-standard/src/java/org/apache/geronimo/console/car/GeronimoAsMavenServlet.java
Wed Aug  2 07:14:45 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/sandbox/svkmerge/trunk/modules/common/src/java/org/apache/geronimo/common/FileUtils.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/svkmerge/trunk/modules/common/src/java/org/apache/geronimo/common/FileUtils.java?rev=427996&view=auto
==============================================================================
--- geronimo/sandbox/svkmerge/trunk/modules/common/src/java/org/apache/geronimo/common/FileUtils.java
(added)
+++ geronimo/sandbox/svkmerge/trunk/modules/common/src/java/org/apache/geronimo/common/FileUtils.java
Wed Aug  2 07:14:45 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/sandbox/svkmerge/trunk/modules/common/src/java/org/apache/geronimo/common/FileUtils.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: geronimo/sandbox/svkmerge/trunk/modules/deploy-jsr88/src/java/org/apache/geronimo/deployment/plugin/ConfigIDExtractor.java
URL: http://svn.apache.org/viewvc/geronimo/sandbox/svkmerge/trunk/modules/deploy-jsr88/src/java/org/apache/geronimo/deployment/plugin/ConfigIDExtractor.java?rev=427996&r1=427995&r2=427996&view=diff
==============================================================================
--- geronimo/sandbox/svkmerge/trunk/modules/deploy-jsr88/src/java/org/apache/geronimo/deployment/plugin/ConfigIDExtractor.java
(original)
+++ geronimo/sandbox/svkmerge/trunk/modules/deploy-jsr88/src/java/org/apache/geronimo/deployment/plugin/ConfigIDExtractor.java
Wed Aug  2 07:14:45 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());
         }
     }
 



Mime
View raw message