Return-Path: X-Original-To: apmail-felix-commits-archive@www.apache.org Delivered-To: apmail-felix-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id D7493964A for ; Wed, 30 May 2012 16:27:01 +0000 (UTC) Received: (qmail 89884 invoked by uid 500); 30 May 2012 16:27:01 -0000 Delivered-To: apmail-felix-commits-archive@felix.apache.org Received: (qmail 89822 invoked by uid 500); 30 May 2012 16:27:01 -0000 Mailing-List: contact commits-help@felix.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@felix.apache.org Delivered-To: mailing list commits@felix.apache.org Received: (qmail 89815 invoked by uid 99); 30 May 2012 16:27:01 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 30 May 2012 16:27:01 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 30 May 2012 16:26:57 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id BA29F23889BF for ; Wed, 30 May 2012 16:26:34 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1344338 - in /felix/trunk/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin: ExplodingOutputtingInputStream.java FileDeploymentPackage.java Utils.java spi/DropBundleCommand.java spi/UpdateCommand.java Date: Wed, 30 May 2012 16:26:34 -0000 To: commits@felix.apache.org From: marrs@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20120530162634.BA29F23889BF@eris.apache.org> Author: marrs Date: Wed May 30 16:26:34 2012 New Revision: 1344338 URL: http://svn.apache.org/viewvc?rev=1344338&view=rev Log: FELIX-3526 Applied the patch, merged two very similar static methods into one. Added: felix/trunk/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/Utils.java Modified: felix/trunk/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/ExplodingOutputtingInputStream.java felix/trunk/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/FileDeploymentPackage.java felix/trunk/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/DropBundleCommand.java felix/trunk/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/UpdateCommand.java Modified: felix/trunk/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/ExplodingOutputtingInputStream.java URL: http://svn.apache.org/viewvc/felix/trunk/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/ExplodingOutputtingInputStream.java?rev=1344338&r1=1344337&r2=1344338&view=diff ============================================================================== --- felix/trunk/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/ExplodingOutputtingInputStream.java (original) +++ felix/trunk/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/ExplodingOutputtingInputStream.java Wed May 30 16:26:34 2012 @@ -136,7 +136,7 @@ class ExplodingOutputtingInputStream ext writer.close(); } } - + try { byte[] buffer = new byte[1024]; int c = m_input.read(buffer); @@ -158,7 +158,7 @@ class ExplodingOutputtingInputStream ext } } } - + private void pushException(Exception e) { Exception e2 = new Exception(e.getMessage()); e2.setStackTrace(e.getStackTrace()); @@ -171,7 +171,7 @@ class ExplodingOutputtingInputStream ext public static boolean replace(File target, File source) { return delete(target, true) && rename(source, target); } - + public static boolean copy(File from, File to) { boolean result = true; if (from.isDirectory()) { @@ -223,7 +223,7 @@ class ExplodingOutputtingInputStream ext } return result; } - + public static boolean rename(File from, File to) { if (!from.renameTo(to)) { if (copy(from, to)) { @@ -265,7 +265,7 @@ class ExplodingOutputtingInputStream ext List result = new ArrayList(targetFiles); File manifestFile = new File(source, (String) sourceFiles.remove(0)); - Manifest resultManifest = new Manifest(new GZIPInputStream(new FileInputStream(manifestFile))); + Manifest resultManifest = Utils.readManifest(manifestFile); resultManifest.getMainAttributes().remove(new Name(Constants.DEPLOYMENTPACKAGE_FIXPACK)); Modified: felix/trunk/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/FileDeploymentPackage.java URL: http://svn.apache.org/viewvc/felix/trunk/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/FileDeploymentPackage.java?rev=1344338&r1=1344337&r2=1344338&view=diff ============================================================================== --- felix/trunk/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/FileDeploymentPackage.java (original) +++ felix/trunk/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/FileDeploymentPackage.java Wed May 30 16:26:34 2012 @@ -53,27 +53,11 @@ public class FileDeploymentPackage exten } private FileDeploymentPackage(List index, File packageDir, BundleContext bundleContext, DeploymentAdminImpl deploymentAdmin) throws DeploymentException, IOException { - super(readManifest(index, packageDir), bundleContext, deploymentAdmin); + super(Utils.readManifest(new File(packageDir, (String) index.remove(0))), bundleContext, deploymentAdmin); m_index = index; m_contentsDir = packageDir; } - private static Manifest readManifest(List index, File packageDir) throws FileNotFoundException, IOException { - final File manifestFile = new File(packageDir, (String) index.remove(0)); - InputStream is = null; - Manifest mf = null; - try { - is = new GZIPInputStream(new FileInputStream(manifestFile)); - mf = new Manifest(is); - } - finally { - if (is != null) { - is.close(); - } - } - return mf; - } - public BundleInfoImpl[] getOrderedBundleInfos() { List result = new ArrayList(); for(Iterator i = m_index.iterator(); i.hasNext();) { Added: felix/trunk/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/Utils.java URL: http://svn.apache.org/viewvc/felix/trunk/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/Utils.java?rev=1344338&view=auto ============================================================================== --- felix/trunk/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/Utils.java (added) +++ felix/trunk/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/Utils.java Wed May 30 16:26:34 2012 @@ -0,0 +1,43 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.felix.deploymentadmin; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.jar.Manifest; +import java.util.zip.GZIPInputStream; + +public class Utils { + public static Manifest readManifest(File manifestFile) throws IOException { + InputStream is = null; + Manifest mf = null; + try { + is = new GZIPInputStream(new FileInputStream(manifestFile)); + mf = new Manifest(is); + } + finally { + if (is != null) { + is.close(); + } + } + return mf; + } +} Modified: felix/trunk/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/DropBundleCommand.java URL: http://svn.apache.org/viewvc/felix/trunk/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/DropBundleCommand.java?rev=1344338&r1=1344337&r2=1344338&view=diff ============================================================================== --- felix/trunk/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/DropBundleCommand.java (original) +++ felix/trunk/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/DropBundleCommand.java Wed May 30 16:26:34 2012 @@ -47,37 +47,47 @@ public class DropBundleCommand extends C try { Bundle bundle = target.getBundle(symbolicName); bundle.uninstall(); - addRollback(new InstallBundleRunnable(bundle, target.getBundleStream(symbolicName), log)); + addRollback(new InstallBundleRunnable(bundle, target, log)); } catch (BundleException be) { log.log(LogService.LOG_WARNING, "Bundle '" + symbolicName + "' could not be uninstalled", be); } - catch (IOException e) { - log.log(LogService.LOG_WARNING, "Could not get bundle data stream for bundle '" + symbolicName + "'", e); - throw new DeploymentException(DeploymentException.CODE_OTHER_ERROR, "Could not prepare rollback for uninstalling bundle '" + symbolicName + "'"); - } } } } private static class InstallBundleRunnable implements Runnable { - private final InputStream m_bundleStream; + private final AbstractDeploymentPackage m_target; private final Bundle m_bundle; private final LogService m_log; - public InstallBundleRunnable(Bundle bundle, InputStream bundleStream, LogService log) { + public InstallBundleRunnable(Bundle bundle, AbstractDeploymentPackage target, LogService log) { m_bundle = bundle; - m_bundleStream = bundleStream; + m_target = target; m_log = log; } public void run() { + InputStream is = null; try { - m_bundle.update(m_bundleStream); + is = m_target.getBundleStream(m_bundle.getSymbolicName()); + if (is != null) { + m_bundle.update(is); + } + throw new Exception("Unable to get Inputstream for bundle " + m_bundle.getSymbolicName()); } - catch (BundleException e) { - m_log.log(LogService.LOG_WARNING, "Could not rollback uninstallation of bundle '" + m_bundle.getSymbolicName() + "'", e); + catch (Exception e) { + m_log.log(LogService.LOG_WARNING, + "Could not rollback uninstallation of bundle '" + m_bundle.getSymbolicName() + "'", e); + } + finally { + if (is != null) { + try { + is.close(); + } + catch (IOException e) {} + } } } } Modified: felix/trunk/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/UpdateCommand.java URL: http://svn.apache.org/viewvc/felix/trunk/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/UpdateCommand.java?rev=1344338&r1=1344337&r2=1344338&view=diff ============================================================================== --- felix/trunk/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/UpdateCommand.java (original) +++ felix/trunk/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/UpdateCommand.java Wed May 30 16:26:34 2012 @@ -32,6 +32,7 @@ import org.osgi.framework.BundleContext; import org.osgi.framework.BundleException; import org.osgi.framework.Version; import org.osgi.service.deploymentadmin.DeploymentException; +import org.osgi.service.log.LogService; /** * Command that installs all bundles described in the source deployment package of a deployment @@ -44,6 +45,7 @@ public class UpdateCommand extends Comma AbstractDeploymentPackage source = session.getSourceAbstractDeploymentPackage(); AbstractDeploymentPackage targetPackage = session.getTargetAbstractDeploymentPackage(); BundleContext context = session.getBundleContext(); + LogService log = session.getLog(); Map expectedBundles = new HashMap(); AbstractInfo[] bundleInfos = (AbstractInfo[]) source.getBundleInfos(); @@ -72,14 +74,14 @@ public class UpdateCommand extends Comma if (bundle == null) { // new bundle, install it bundle = context.installBundle(Constants.BUNDLE_LOCATION_PREFIX + bundleInfo.getSymbolicName(), new BundleInputStream(source.getCurrentEntryStream())); - addRollback(new UninstallBundleRunnable(bundle)); + addRollback(new UninstallBundleRunnable(bundle, log)); } else { // existing bundle, update it Version sourceVersion = bundleInfo.getVersion(); Version targetVersion = Version.parseVersion((String) bundle.getHeaders().get(org.osgi.framework.Constants.BUNDLE_VERSION)); if (!sourceVersion.equals(targetVersion)) { bundle.update(new BundleInputStream(source.getCurrentEntryStream())); - addRollback(new UpdateBundleRunnable(bundle, targetPackage, bundleInfo.getSymbolicName())); + addRollback(new UpdateBundleRunnable(bundle, targetPackage, log)); } } } @@ -102,9 +104,11 @@ public class UpdateCommand extends Comma private static class UninstallBundleRunnable implements Runnable { private final Bundle m_bundle; + private final LogService m_log; - public UninstallBundleRunnable(Bundle bundle) { + public UninstallBundleRunnable(Bundle bundle, LogService log) { m_bundle = bundle; + m_log = log; } public void run() { @@ -112,31 +116,43 @@ public class UpdateCommand extends Comma m_bundle.uninstall(); } catch (BundleException e) { - // TODO: log this - e.printStackTrace(); + m_log.log(LogService.LOG_WARNING, "Could not rollback update of bundle '" + m_bundle.getSymbolicName() + "'", e); } } } private static class UpdateBundleRunnable implements Runnable { - private final Bundle m_bundle; private final AbstractDeploymentPackage m_targetPackage; - private final String m_symbolicName; + private final Bundle m_bundle; + private final LogService m_log; - public UpdateBundleRunnable(Bundle bundle, AbstractDeploymentPackage targetPackage, String symbolicName) { + public UpdateBundleRunnable(Bundle bundle, AbstractDeploymentPackage targetPackage, LogService log) { m_bundle = bundle; m_targetPackage = targetPackage; - m_symbolicName = symbolicName; + m_log = log; } public void run() { + InputStream is = null; try { - m_bundle.update(m_targetPackage.getBundleStream(m_symbolicName)); + is = m_targetPackage.getBundleStream(m_bundle.getSymbolicName()); + if(is != null){ + m_bundle.update(is); + } + throw new Exception("Unable to get Inputstream for bundle " + m_bundle.getSymbolicName()); } catch (Exception e) { - // TODO: log this - e.printStackTrace(); + m_log.log(LogService.LOG_WARNING, "Could not rollback update of bundle '" + m_bundle.getSymbolicName() + "'", e); + } finally { + if(is != null){ + try { + is.close(); + } + catch (IOException e) { + e.printStackTrace(); + } + } } } }