Return-Path: Delivered-To: apmail-sling-commits-archive@www.apache.org Received: (qmail 22225 invoked from network); 18 Jan 2011 08:03:35 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 18 Jan 2011 08:03:35 -0000 Received: (qmail 86137 invoked by uid 500); 18 Jan 2011 08:03:34 -0000 Delivered-To: apmail-sling-commits-archive@sling.apache.org Received: (qmail 86074 invoked by uid 500); 18 Jan 2011 08:03:33 -0000 Mailing-List: contact commits-help@sling.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@sling.apache.org Delivered-To: mailing list commits@sling.apache.org Received: (qmail 86067 invoked by uid 99); 18 Jan 2011 08:03:33 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 18 Jan 2011 08:03:33 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.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; Tue, 18 Jan 2011 08:03:28 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 02A8423889EA; Tue, 18 Jan 2011 08:03:01 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1060231 - in /sling/trunk/installer/factories: ./ deploymentpck/ deploymentpck/src/ deploymentpck/src/main/ deploymentpck/src/main/java/ deploymentpck/src/main/java/org/ deploymentpck/src/main/java/org/apache/ deploymentpck/src/main/java/o... Date: Tue, 18 Jan 2011 08:03:00 -0000 To: commits@sling.apache.org From: cziegeler@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20110118080301.02A8423889EA@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: cziegeler Date: Tue Jan 18 08:03:00 2011 New Revision: 1060231 URL: http://svn.apache.org/viewvc?rev=1060231&view=rev Log: First version of deployment package support for the installer. Added: sling/trunk/installer/factories/ sling/trunk/installer/factories/deploymentpck/ sling/trunk/installer/factories/deploymentpck/pom.xml (with props) sling/trunk/installer/factories/deploymentpck/src/ sling/trunk/installer/factories/deploymentpck/src/main/ sling/trunk/installer/factories/deploymentpck/src/main/java/ sling/trunk/installer/factories/deploymentpck/src/main/java/org/ sling/trunk/installer/factories/deploymentpck/src/main/java/org/apache/ sling/trunk/installer/factories/deploymentpck/src/main/java/org/apache/sling/ sling/trunk/installer/factories/deploymentpck/src/main/java/org/apache/sling/installer/ sling/trunk/installer/factories/deploymentpck/src/main/java/org/apache/sling/installer/factories/ sling/trunk/installer/factories/deploymentpck/src/main/java/org/apache/sling/installer/factories/deploypck/ sling/trunk/installer/factories/deploymentpck/src/main/java/org/apache/sling/installer/factories/deploypck/impl/ sling/trunk/installer/factories/deploymentpck/src/main/java/org/apache/sling/installer/factories/deploypck/impl/Activator.java (with props) sling/trunk/installer/factories/deploymentpck/src/main/java/org/apache/sling/installer/factories/deploypck/impl/DeployPckTask.java (with props) sling/trunk/installer/factories/deploymentpck/src/main/java/org/apache/sling/installer/factories/deploypck/impl/DeploymentPackageInstaller.java (with props) Added: sling/trunk/installer/factories/deploymentpck/pom.xml URL: http://svn.apache.org/viewvc/sling/trunk/installer/factories/deploymentpck/pom.xml?rev=1060231&view=auto ============================================================================== --- sling/trunk/installer/factories/deploymentpck/pom.xml (added) +++ sling/trunk/installer/factories/deploymentpck/pom.xml Tue Jan 18 08:03:00 2011 @@ -0,0 +1,83 @@ + + + 4.0.0 + + org.apache.sling + sling + 10 + ../../../parent/pom.xml + + + org.apache.sling.installer.factory.deploymentpackage + 0.0.1-SNAPSHOT + bundle + + Apache Sling Deployment Package Installer + + Provides support for deployment packages to the Apache Sling OSGi installer + + + + scm:svn:http://svn.apache.org/repos/asf/sling/trunk/installer/factories/deploymentpck + scm:svn:https://svn.apache.org/repos/asf/sling/trunk/installer/factories/deploymentpck + http://svn.apache.org/viewvc/sling/trunk/installer/factories/deploymentpck/ + + + + + + org.apache.felix + maven-bundle-plugin + true + + + + org.apache.sling.installer.factories.deploypck.impl.Activator + + + org.apache.sling.installer.factories.deploypck..impl.* + + + + + + + + + + org.slf4j + slf4j-api + + + org.osgi + org.osgi.core + + + org.osgi + org.osgi.compendium + + + org.apache.sling + org.apache.sling.installer.core + 3.0.1-SNAPSHOT + provided + + + Propchange: sling/trunk/installer/factories/deploymentpck/pom.xml ------------------------------------------------------------------------------ svn:eol-style = native Propchange: sling/trunk/installer/factories/deploymentpck/pom.xml ------------------------------------------------------------------------------ svn:keywords = Id Propchange: sling/trunk/installer/factories/deploymentpck/pom.xml ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: sling/trunk/installer/factories/deploymentpck/src/main/java/org/apache/sling/installer/factories/deploypck/impl/Activator.java URL: http://svn.apache.org/viewvc/sling/trunk/installer/factories/deploymentpck/src/main/java/org/apache/sling/installer/factories/deploypck/impl/Activator.java?rev=1060231&view=auto ============================================================================== --- sling/trunk/installer/factories/deploymentpck/src/main/java/org/apache/sling/installer/factories/deploypck/impl/Activator.java (added) +++ sling/trunk/installer/factories/deploymentpck/src/main/java/org/apache/sling/installer/factories/deploypck/impl/Activator.java Tue Jan 18 08:03:00 2011 @@ -0,0 +1,101 @@ +/* + * 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.sling.installer.factories.deploypck.impl; + +import java.util.Dictionary; +import java.util.Hashtable; + +import org.apache.sling.installer.api.tasks.InstallTaskFactory; +import org.apache.sling.installer.api.tasks.ResourceTransformer; +import org.osgi.framework.BundleActivator; +import org.osgi.framework.BundleContext; +import org.osgi.framework.Constants; +import org.osgi.framework.ServiceEvent; +import org.osgi.framework.ServiceListener; +import org.osgi.framework.ServiceReference; +import org.osgi.framework.ServiceRegistration; +import org.osgi.service.deploymentadmin.DeploymentAdmin; + +public class Activator implements ServiceListener, BundleActivator { + + private static final String DEPLOYMENT_ADMIN = "org.osgi.service.deploymentadmin.DeploymentAdmin"; + + /** The bundle context. */ + private BundleContext bundleContext; + + /** The service reference to the deployment admin. */ + private ServiceReference deploymentAdminReference; + + /** The service registration for the install service. */ + private ServiceRegistration serviceReg; + + /** + * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext) + */ + public void start(final BundleContext context) throws Exception { + this.bundleContext = context; + this.bundleContext.addServiceListener(this, "(" + Constants.OBJECTCLASS + + "=" + DEPLOYMENT_ADMIN + ")"); + + } + /** + * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext) + */ + public void stop(final BundleContext context) throws Exception { + this.bundleContext.removeServiceListener(this); + this.unregister(); + this.bundleContext = null; + } + + /** + * Wait for the deployment admin service. + * @see org.osgi.framework.ServiceListener#serviceChanged(org.osgi.framework.ServiceEvent) + */ + public synchronized void serviceChanged(ServiceEvent event) { + if ( event.getType() == ServiceEvent.REGISTERED && this.deploymentAdminReference == null ) { + this.deploymentAdminReference = this.bundleContext.getServiceReference(DEPLOYMENT_ADMIN); + if ( this.deploymentAdminReference != null ) { + final DeploymentAdmin deploymentAdmin = (DeploymentAdmin) this.bundleContext.getService(this.deploymentAdminReference); + if ( deploymentAdmin == null ) { + this.deploymentAdminReference = null; + } else { + final Dictionary props = new Hashtable(); + props.put(Constants.SERVICE_DESCRIPTION, "Apache Sling Installer Support for Deployment Packages"); + props.put(Constants.SERVICE_VENDOR, "The Apache Software Foundation"); + this.serviceReg = this.bundleContext.registerService(new String[] {ResourceTransformer.class.getName(), + InstallTaskFactory.class.getName()}, + new DeploymentPackageInstaller(deploymentAdmin), props); + } + } + } else if ( event.getType() == ServiceEvent.UNREGISTERING && this.deploymentAdminReference != null ) { + this.unregister(); + } + } + + private void unregister() { + if ( this.deploymentAdminReference != null ) { + this.bundleContext.ungetService(this.deploymentAdminReference); + this.deploymentAdminReference = null; + } + if ( serviceReg != null ) { + serviceReg.unregister(); + serviceReg = null; + } + } +} Propchange: sling/trunk/installer/factories/deploymentpck/src/main/java/org/apache/sling/installer/factories/deploypck/impl/Activator.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: sling/trunk/installer/factories/deploymentpck/src/main/java/org/apache/sling/installer/factories/deploypck/impl/Activator.java ------------------------------------------------------------------------------ svn:keywords = author date id revision rev url Propchange: sling/trunk/installer/factories/deploymentpck/src/main/java/org/apache/sling/installer/factories/deploypck/impl/Activator.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: sling/trunk/installer/factories/deploymentpck/src/main/java/org/apache/sling/installer/factories/deploypck/impl/DeployPckTask.java URL: http://svn.apache.org/viewvc/sling/trunk/installer/factories/deploymentpck/src/main/java/org/apache/sling/installer/factories/deploypck/impl/DeployPckTask.java?rev=1060231&view=auto ============================================================================== --- sling/trunk/installer/factories/deploymentpck/src/main/java/org/apache/sling/installer/factories/deploypck/impl/DeployPckTask.java (added) +++ sling/trunk/installer/factories/deploymentpck/src/main/java/org/apache/sling/installer/factories/deploypck/impl/DeployPckTask.java Tue Jan 18 08:03:00 2011 @@ -0,0 +1,128 @@ +/* + * 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.sling.installer.factories.deploypck.impl; + +import java.io.IOException; +import java.io.InputStream; + +import org.apache.sling.installer.api.tasks.InstallTask; +import org.apache.sling.installer.api.tasks.InstallationContext; +import org.apache.sling.installer.api.tasks.ResourceState; +import org.apache.sling.installer.api.tasks.TaskResource; +import org.apache.sling.installer.api.tasks.TaskResourceGroup; +import org.osgi.framework.Version; +import org.osgi.service.deploymentadmin.DeploymentAdmin; +import org.osgi.service.deploymentadmin.DeploymentException; +import org.osgi.service.deploymentadmin.DeploymentPackage; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class DeployPckTask extends InstallTask { + + private static final String INSTALL_ORDER = "55-"; + + private final DeploymentAdmin deploymentAdmin; + + private final Logger logger = LoggerFactory.getLogger(this.getClass()); + + public DeployPckTask(final TaskResourceGroup grp, final DeploymentAdmin dp) { + super(grp); + this.deploymentAdmin = dp; + } + + @Override + public void execute(final InstallationContext ctx) { + final TaskResource tr = this.getResource(); + + // get and check symbolic name + final String symbolicName = (String)tr.getAttribute(DeploymentPackageInstaller.DEPLOYMENTPACKAGE_SYMBOLICMAME); + if ( symbolicName == null ) { + logger.error("Resource {} has no symbolic name - ignoring.", tr); + this.getResourceGroup().setFinishState(ResourceState.IGNORED); + return; + } + + // get package if available + final DeploymentPackage dp = this.deploymentAdmin.getDeploymentPackage(symbolicName); + + if ( tr.getState() == ResourceState.INSTALL) { + InputStream is = null; + try { + is = tr.getInputStream(); + if ( is == null ) { + // something went wrong + logger.error("Resource {} does not provide an input stream!", tr); + this.getResourceGroup().setFinishState(ResourceState.IGNORED); + } else { + final Version newVersion = new Version((String)tr.getAttribute(DeploymentPackageInstaller.DEPLOYMENTPACKAGE_VERSION)); + // check version + if ( dp != null ) { + final int compare = dp.getVersion().compareTo(newVersion); + if (compare < 0) { + // installed version is lower -> update + this.deploymentAdmin.installDeploymentPackage(is); + ctx.log("Installed deployment package {} : {}", symbolicName, newVersion); + this.getResourceGroup().setFinishState(ResourceState.INSTALLED); + } else if (compare >= 0) { + logger.debug("Deployment package " + symbolicName + " " + newVersion + + " is not installed, package with higher or same version is already installed."); + } + } else { + this.deploymentAdmin.installDeploymentPackage(is); + ctx.log("Installed deployment package {} : {}", symbolicName, newVersion); + this.getResourceGroup().setFinishState(ResourceState.INSTALLED); + } + } + } catch (final DeploymentException e) { + logger.error("Unable to install deployment package {} from resource {}", + symbolicName, + tr); + this.getResourceGroup().setFinishState(ResourceState.IGNORED); + } catch (final IOException ioe) { + logger.error("Unable to install deployment package {} from resource {}", + symbolicName, + tr); + this.getResourceGroup().setFinishState(ResourceState.IGNORED); + } finally { + if ( is != null ) { + try { + is.close(); + } catch (IOException ignore) {} + } + } + } else { // uninstall + if ( dp != null ) { + try { + dp.uninstall(); + } catch (final DeploymentException e) { + logger.error("Unable to uninstall deployment package {} from resource {}", symbolicName, tr); + } + } else { + logger.info("Unable to find deployment package with symbolic name {} for uninstalling.", + symbolicName); + } + this.getResourceGroup().setFinishState(ResourceState.UNINSTALLED); + } + } + + @Override + public String getSortKey() { + return INSTALL_ORDER + getResource().getURL(); + } +} Propchange: sling/trunk/installer/factories/deploymentpck/src/main/java/org/apache/sling/installer/factories/deploypck/impl/DeployPckTask.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: sling/trunk/installer/factories/deploymentpck/src/main/java/org/apache/sling/installer/factories/deploypck/impl/DeployPckTask.java ------------------------------------------------------------------------------ svn:keywords = author date id revision rev url Propchange: sling/trunk/installer/factories/deploymentpck/src/main/java/org/apache/sling/installer/factories/deploypck/impl/DeployPckTask.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: sling/trunk/installer/factories/deploymentpck/src/main/java/org/apache/sling/installer/factories/deploypck/impl/DeploymentPackageInstaller.java URL: http://svn.apache.org/viewvc/sling/trunk/installer/factories/deploymentpck/src/main/java/org/apache/sling/installer/factories/deploypck/impl/DeploymentPackageInstaller.java?rev=1060231&view=auto ============================================================================== --- sling/trunk/installer/factories/deploymentpck/src/main/java/org/apache/sling/installer/factories/deploypck/impl/DeploymentPackageInstaller.java (added) +++ sling/trunk/installer/factories/deploymentpck/src/main/java/org/apache/sling/installer/factories/deploypck/impl/DeploymentPackageInstaller.java Tue Jan 18 08:03:00 2011 @@ -0,0 +1,129 @@ +/* + * 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.sling.installer.factories.deploypck.impl; + +import java.io.IOException; +import java.io.InputStream; +import java.util.HashMap; +import java.util.Map; +import java.util.jar.JarInputStream; +import java.util.jar.Manifest; + +import org.apache.sling.installer.api.InstallableResource; +import org.apache.sling.installer.api.tasks.InstallTask; +import org.apache.sling.installer.api.tasks.InstallTaskFactory; +import org.apache.sling.installer.api.tasks.RegisteredResource; +import org.apache.sling.installer.api.tasks.ResourceTransformer; +import org.apache.sling.installer.api.tasks.TaskResourceGroup; +import org.apache.sling.installer.api.tasks.TransformationResult; +import org.osgi.service.deploymentadmin.DeploymentAdmin; + +/** + * This is an extension for the OSGi installer + * It listens for files ending with ".dp" and installs them through + * the deployment package admin. + */ +public class DeploymentPackageInstaller + implements ResourceTransformer, InstallTaskFactory { + + public static final String DEPLOYMENTPACKAGE_SYMBOLICMAME = "DeploymentPackage-SymbolicName"; + public static final String DEPLOYMENTPACKAGE_VERSION = "DeploymentPackage-Version"; + + private static final String TYPE_DP = "dp"; + + private final DeploymentAdmin deploymentAdmin; + + public DeploymentPackageInstaller(final DeploymentAdmin dpA) { + this.deploymentAdmin = dpA; + } + + /** + * @see org.apache.sling.installer.api.tasks.ResourceTransformer#transform(org.apache.sling.installer.api.tasks.RegisteredResource) + */ + public TransformationResult[] transform(final RegisteredResource resource) { + if ( resource.getType().equals(InstallableResource.TYPE_FILE) ) { + try { + final Manifest m = getManifest(resource.getInputStream()); + if (m != null) { + final String sn = m.getMainAttributes().getValue(DEPLOYMENTPACKAGE_SYMBOLICMAME); + if (sn != null) { + final String v = m.getMainAttributes().getValue(DEPLOYMENTPACKAGE_VERSION); + if (v != null) { + final Map attr = new HashMap(); + attr.put(DEPLOYMENTPACKAGE_SYMBOLICMAME, sn); + attr.put(DEPLOYMENTPACKAGE_VERSION, v.toString()); + + final TransformationResult tr = new TransformationResult(); + tr.setId(sn); + tr.setResourceType(TYPE_DP); + tr.setAttributes(attr); + + return new TransformationResult[] {tr}; + } + } + } + } catch (final IOException ignore) { + // ignore + } + } + return null; + } + + /** + * Read the manifest from supplied input stream, which is closed before return. + */ + private Manifest getManifest(final InputStream ins) throws IOException { + Manifest result = null; + + JarInputStream jis = null; + try { + jis = new JarInputStream(ins); + result= jis.getManifest(); + + } finally { + + // close the jar stream or the inputstream, if the jar + // stream is set, we don't need to close the input stream + // since closing the jar stream closes the input stream + if (jis != null) { + try { + jis.close(); + } catch (IOException ignore) { + } + } else { + try { + ins.close(); + } catch (IOException ignore) { + } + } + } + + return result; + } + + /** + * @see org.apache.sling.installer.api.tasks.InstallTaskFactory#createTask(org.apache.sling.installer.api.tasks.TaskResourceGroup) + */ + public InstallTask createTask(final TaskResourceGroup toActivate) { + if ( toActivate.getActiveResource().getType().equals(TYPE_DP) ) { + return new DeployPckTask(toActivate, this.deploymentAdmin); + } + return null; + } +} Propchange: sling/trunk/installer/factories/deploymentpck/src/main/java/org/apache/sling/installer/factories/deploypck/impl/DeploymentPackageInstaller.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: sling/trunk/installer/factories/deploymentpck/src/main/java/org/apache/sling/installer/factories/deploypck/impl/DeploymentPackageInstaller.java ------------------------------------------------------------------------------ svn:keywords = author date id revision rev url Propchange: sling/trunk/installer/factories/deploymentpck/src/main/java/org/apache/sling/installer/factories/deploypck/impl/DeploymentPackageInstaller.java ------------------------------------------------------------------------------ svn:mime-type = text/plain