You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by cz...@apache.org on 2023/08/22 15:44:53 UTC
[felix-dev] branch master updated: Unmaintained code removal - deploymentadmin
This is an automated email from the ASF dual-hosted git repository.
cziegeler pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/felix-dev.git
The following commit(s) were added to refs/heads/master by this push:
new e7100bc8fa Unmaintained code removal - deploymentadmin
e7100bc8fa is described below
commit e7100bc8fa5b6cd75ade26e3935939b156fd666c
Author: Carsten Ziegeler <cz...@apache.org>
AuthorDate: Tue Aug 22 17:44:45 2023 +0200
Unmaintained code removal - deploymentadmin
---
deploymentadmin/autoconf/DEPENDENCIES | 29 -
deploymentadmin/autoconf/LICENSE | 202 ------
deploymentadmin/autoconf/LICENSE.kxml2 | 19 -
deploymentadmin/autoconf/NOTICE | 15 -
deploymentadmin/autoconf/changelog.txt | 26 -
deploymentadmin/autoconf/pom.xml | 113 ---
.../felix/deployment/rp/autoconf/Activator.java | 58 --
.../rp/autoconf/AttributeDefinitionImpl.java | 68 --
.../deployment/rp/autoconf/AutoConfResource.java | 163 -----
.../rp/autoconf/AutoConfResourceProcessor.java | 782 ---------------------
.../felix/deployment/rp/autoconf/MetaTypeUtil.java | 233 ------
.../rp/autoconf/ObjectClassDefinitionImpl.java | 81 ---
.../deployment/rp/autoconf/PersistencyManager.java | 183 -----
.../rp/autoconf/AutoConfResourceProcessorTest.java | 627 -----------------
.../deployment/rp/autoconf/DefaultNullObject.java | 80 ---
.../rp/autoconf/PersistencyManagerTest.java | 99 ---
.../apache/felix/deployment/rp/autoconf/Utils.java | 148 ----
deploymentadmin/deploymentadmin/DEPENDENCIES | 24 -
deploymentadmin/deploymentadmin/LICENSE | 202 ------
deploymentadmin/deploymentadmin/NOTICE | 11 -
deploymentadmin/deploymentadmin/changelog.txt | 39 -
deploymentadmin/deploymentadmin/pom.xml | 96 ---
.../deploymentadmin/AbstractDeploymentPackage.java | 516 --------------
.../apache/felix/deploymentadmin/AbstractInfo.java | 139 ----
.../apache/felix/deploymentadmin/Activator.java | 54 --
.../felix/deploymentadmin/BundleInfoImpl.java | 112 ---
.../apache/felix/deploymentadmin/Constants.java | 75 --
.../ContentCopyingJarInputStream.java | 151 ----
.../deploymentadmin/DeploymentAdminConfig.java | 92 ---
.../felix/deploymentadmin/DeploymentAdminImpl.java | 617 ----------------
.../deploymentadmin/DeploymentPackageManifest.java | 167 -----
.../deploymentadmin/FileDeploymentPackage.java | 96 ---
.../felix/deploymentadmin/NonCloseableStream.java | 95 ---
.../felix/deploymentadmin/ResourceInfoImpl.java | 66 --
.../apache/felix/deploymentadmin/Semaphore.java | 121 ----
.../deploymentadmin/StreamDeploymentPackage.java | 117 ---
.../org/apache/felix/deploymentadmin/Utils.java | 241 -------
.../apache/felix/deploymentadmin/VersionRange.java | 156 ----
.../felix/deploymentadmin/spi/AbstractAction.java | 44 --
.../apache/felix/deploymentadmin/spi/Command.java | 186 -----
.../deploymentadmin/spi/CommitResourceCommand.java | 105 ---
.../deploymentadmin/spi/DeploymentSessionImpl.java | 214 ------
.../deploymentadmin/spi/DropAllBundlesCommand.java | 86 ---
.../spi/DropAllResourcesCommand.java | 115 ---
.../deploymentadmin/spi/DropBundleCommand.java | 88 ---
.../deploymentadmin/spi/DropResourceCommand.java | 97 ---
.../deploymentadmin/spi/GetStorageAreaCommand.java | 70 --
.../spi/ProcessResourceCommand.java | 151 ----
.../felix/deploymentadmin/spi/SnapshotCommand.java | 226 ------
.../deploymentadmin/spi/StartBundleCommand.java | 131 ----
.../spi/StartCustomizerCommand.java | 97 ---
.../deploymentadmin/spi/StopBundleCommand.java | 124 ----
.../felix/deploymentadmin/spi/UpdateCommand.java | 203 ------
.../ContentCopyingJarInputStreamTest.java | 257 -------
.../deploymentadmin/DeploymentAdminConfigTest.java | 139 ----
.../deploymentadmin/spi/SnapshotCommandTest.java | 229 ------
deploymentadmin/itest/pom.xml | 214 ------
.../deploymentadmin/itest/BaseIntegrationTest.java | 317 ---------
.../deploymentadmin/itest/CustomizerTest.java | 254 -------
.../felix/deploymentadmin/itest/DPSignerTest.java | 84 ---
.../itest/DeploymentAdminEventTest.java | 303 --------
.../deploymentadmin/itest/DeploymentAdminTest.java | 158 -----
.../itest/DeploymentPackageBuilderTest.java | 301 --------
.../itest/InstallDeploymentPackageTest.java | 609 ----------------
.../itest/InstallFixPackageTest.java | 603 ----------------
.../deploymentadmin/itest/ResourceSharingTest.java | 132 ----
.../itest/UninstallDeploymentPackageTest.java | 311 --------
.../deploymentadmin/itest/util/ArtifactData.java | 120 ----
.../itest/util/ArtifactDataBuilder.java | 86 ---
.../itest/util/BundleDataBuilder.java | 120 ----
.../itest/util/CertificateUtil.java | 123 ----
.../felix/deploymentadmin/itest/util/DPSigner.java | 273 -------
.../itest/util/DeploymentPackageBuilder.java | 437 ------------
.../util/LocalizationResourceDataBuilder.java | 43 --
.../itest/util/ResourceDataBuilder.java | 68 --
.../deploymentadmin/itest/util/ResourceFilter.java | 29 -
.../itest/util/ResourceProcessorDataBuilder.java | 66 --
deploymentadmin/itest/src/test/resources/LICENSE | 202 ------
.../itest/src/test/resources/dp.properties | 18 -
.../itest/src/test/resources/logback.xml | 30 -
deploymentadmin/itest/src/test/resources/logo.png | Bin 14927 -> 0 bytes
.../itest/src/test/resources/test-config1.xml | 30 -
deploymentadmin/pom.xml | 38 -
deploymentadmin/testbundles/bundle1/bnd.bnd | 21 -
deploymentadmin/testbundles/bundle1/pom.xml | 46 --
.../deploymentadmin/test/bundle1/TestService.java | 31 -
.../test/bundle1/impl/Activator.java | 34 -
.../test/bundle1/impl/TestServiceImpl.java | 31 -
deploymentadmin/testbundles/bundle2/bnd.bnd | 21 -
deploymentadmin/testbundles/bundle2/pom.xml | 55 --
.../test/bundle2/impl/Activator.java | 56 --
deploymentadmin/testbundles/bundle3/bnd.bnd | 20 -
deploymentadmin/testbundles/bundle3/pom.xml | 46 --
.../test/bundle3/impl/Activator.java | 48 --
deploymentadmin/testbundles/bundleapi1/bnd.bnd | 19 -
deploymentadmin/testbundles/bundleapi1/pom.xml | 46 --
.../deploymentadmin/test/bundleapi/MyService.java | 24 -
deploymentadmin/testbundles/bundleapi2/bnd.bnd | 19 -
deploymentadmin/testbundles/bundleapi2/pom.xml | 46 --
.../deploymentadmin/test/bundleapi/MyService.java | 24 -
deploymentadmin/testbundles/bundleimpl1/bnd.bnd | 20 -
deploymentadmin/testbundles/bundleimpl1/pom.xml | 51 --
.../test/bundleimpl/MyServiceImpl.java | 26 -
deploymentadmin/testbundles/bundleimpl2/bnd.bnd | 20 -
deploymentadmin/testbundles/bundleimpl2/pom.xml | 51 --
.../test/bundleimpl/MyServiceImpl.java | 26 -
deploymentadmin/testbundles/fragment1/bnd.bnd | 20 -
deploymentadmin/testbundles/fragment1/pom.xml | 46 --
.../deploymentadmin/test/fragment1/impl/Pojo.java | 27 -
deploymentadmin/testbundles/pom.xml | 54 --
deploymentadmin/testbundles/rp1/bnd.bnd | 22 -
deploymentadmin/testbundles/rp1/pom.xml | 50 --
.../deploymentadmin/test/rp1/impl/Activator.java | 97 ---
deploymentadmin/testbundles/rp2/bnd.bnd | 22 -
deploymentadmin/testbundles/rp2/pom.xml | 53 --
.../deploymentadmin/test/rp2/impl/Activator.java | 100 ---
116 files changed, 14916 deletions(-)
diff --git a/deploymentadmin/autoconf/DEPENDENCIES b/deploymentadmin/autoconf/DEPENDENCIES
deleted file mode 100644
index 00e508d843..0000000000
--- a/deploymentadmin/autoconf/DEPENDENCIES
+++ /dev/null
@@ -1,29 +0,0 @@
-Apache Felix AutoConf Resource Processor
-Copyright 2011-2016 The Apache Software Foundation
-
-This software was developed at the Apache Software Foundation
-(http://www.apache.org) and may have dependencies on other
-Apache software licensed under Apache License 2.0.
-
-I. Included Third-Party Software
-
-This product includes software developed at
-The OSGi Alliance (http://www.osgi.org/).
-Copyright (c) OSGi Alliance (2000, 2009).
-Licensed under the Apache License 2.0.
-
-This product includes software from http://kxml.sourceforge.net.
-Copyright (c) 2002,2003, Stefan Haustein, Oberhausen, Rhld., Germany.
-Licensed under BSD License.
-
-II. Used Third-Party Software
-
-This product uses software developed at
-The OSGi Alliance (http://www.osgi.org/).
-Copyright (c) OSGi Alliance (2000, 2009).
-Licensed under the Apache License 2.0.
-
-III. Overall License Summary
-
-- Apache License 2.0
-- BSD License
diff --git a/deploymentadmin/autoconf/LICENSE b/deploymentadmin/autoconf/LICENSE
deleted file mode 100644
index d645695673..0000000000
--- a/deploymentadmin/autoconf/LICENSE
+++ /dev/null
@@ -1,202 +0,0 @@
-
- Apache License
- Version 2.0, January 2004
- http://www.apache.org/licenses/
-
- TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
-
- 1. Definitions.
-
- "License" shall mean the terms and conditions for use, reproduction,
- and distribution as defined by Sections 1 through 9 of this document.
-
- "Licensor" shall mean the copyright owner or entity authorized by
- the copyright owner that is granting the License.
-
- "Legal Entity" shall mean the union of the acting entity and all
- other entities that control, are controlled by, or are under common
- control with that entity. For the purposes of this definition,
- "control" means (i) the power, direct or indirect, to cause the
- direction or management of such entity, whether by contract or
- otherwise, or (ii) ownership of fifty percent (50%) or more of the
- outstanding shares, or (iii) beneficial ownership of such entity.
-
- "You" (or "Your") shall mean an individual or Legal Entity
- exercising permissions granted by this License.
-
- "Source" form shall mean the preferred form for making modifications,
- including but not limited to software source code, documentation
- source, and configuration files.
-
- "Object" form shall mean any form resulting from mechanical
- transformation or translation of a Source form, including but
- not limited to compiled object code, generated documentation,
- and conversions to other media types.
-
- "Work" shall mean the work of authorship, whether in Source or
- Object form, made available under the License, as indicated by a
- copyright notice that is included in or attached to the work
- (an example is provided in the Appendix below).
-
- "Derivative Works" shall mean any work, whether in Source or Object
- form, that is based on (or derived from) the Work and for which the
- editorial revisions, annotations, elaborations, or other modifications
- represent, as a whole, an original work of authorship. For the purposes
- of this License, Derivative Works shall not include works that remain
- separable from, or merely link (or bind by name) to the interfaces of,
- the Work and Derivative Works thereof.
-
- "Contribution" shall mean any work of authorship, including
- the original version of the Work and any modifications or additions
- to that Work or Derivative Works thereof, that is intentionally
- submitted to Licensor for inclusion in the Work by the copyright owner
- or by an individual or Legal Entity authorized to submit on behalf of
- the copyright owner. For the purposes of this definition, "submitted"
- means any form of electronic, verbal, or written communication sent
- to the Licensor or its representatives, including but not limited to
- communication on electronic mailing lists, source code control systems,
- and issue tracking systems that are managed by, or on behalf of, the
- Licensor for the purpose of discussing and improving the Work, but
- excluding communication that is conspicuously marked or otherwise
- designated in writing by the copyright owner as "Not a Contribution."
-
- "Contributor" shall mean Licensor and any individual or Legal Entity
- on behalf of whom a Contribution has been received by Licensor and
- subsequently incorporated within the Work.
-
- 2. Grant of Copyright License. Subject to the terms and conditions of
- this License, each Contributor hereby grants to You a perpetual,
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
- copyright license to reproduce, prepare Derivative Works of,
- publicly display, publicly perform, sublicense, and distribute the
- Work and such Derivative Works in Source or Object form.
-
- 3. Grant of Patent License. Subject to the terms and conditions of
- this License, each Contributor hereby grants to You a perpetual,
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
- (except as stated in this section) patent license to make, have made,
- use, offer to sell, sell, import, and otherwise transfer the Work,
- where such license applies only to those patent claims licensable
- by such Contributor that are necessarily infringed by their
- Contribution(s) alone or by combination of their Contribution(s)
- with the Work to which such Contribution(s) was submitted. If You
- institute patent litigation against any entity (including a
- cross-claim or counterclaim in a lawsuit) alleging that the Work
- or a Contribution incorporated within the Work constitutes direct
- or contributory patent infringement, then any patent licenses
- granted to You under this License for that Work shall terminate
- as of the date such litigation is filed.
-
- 4. Redistribution. You may reproduce and distribute copies of the
- Work or Derivative Works thereof in any medium, with or without
- modifications, and in Source or Object form, provided that You
- meet the following conditions:
-
- (a) You must give any other recipients of the Work or
- Derivative Works a copy of this License; and
-
- (b) You must cause any modified files to carry prominent notices
- stating that You changed the files; and
-
- (c) You must retain, in the Source form of any Derivative Works
- that You distribute, all copyright, patent, trademark, and
- attribution notices from the Source form of the Work,
- excluding those notices that do not pertain to any part of
- the Derivative Works; and
-
- (d) If the Work includes a "NOTICE" text file as part of its
- distribution, then any Derivative Works that You distribute must
- include a readable copy of the attribution notices contained
- within such NOTICE file, excluding those notices that do not
- pertain to any part of the Derivative Works, in at least one
- of the following places: within a NOTICE text file distributed
- as part of the Derivative Works; within the Source form or
- documentation, if provided along with the Derivative Works; or,
- within a display generated by the Derivative Works, if and
- wherever such third-party notices normally appear. The contents
- of the NOTICE file are for informational purposes only and
- do not modify the License. You may add Your own attribution
- notices within Derivative Works that You distribute, alongside
- or as an addendum to the NOTICE text from the Work, provided
- that such additional attribution notices cannot be construed
- as modifying the License.
-
- You may add Your own copyright statement to Your modifications and
- may provide additional or different license terms and conditions
- for use, reproduction, or distribution of Your modifications, or
- for any such Derivative Works as a whole, provided Your use,
- reproduction, and distribution of the Work otherwise complies with
- the conditions stated in this License.
-
- 5. Submission of Contributions. Unless You explicitly state otherwise,
- any Contribution intentionally submitted for inclusion in the Work
- by You to the Licensor shall be under the terms and conditions of
- this License, without any additional terms or conditions.
- Notwithstanding the above, nothing herein shall supersede or modify
- the terms of any separate license agreement you may have executed
- with Licensor regarding such Contributions.
-
- 6. Trademarks. This License does not grant permission to use the trade
- names, trademarks, service marks, or product names of the Licensor,
- except as required for reasonable and customary use in describing the
- origin of the Work and reproducing the content of the NOTICE file.
-
- 7. Disclaimer of Warranty. Unless required by applicable law or
- agreed to in writing, Licensor provides the Work (and each
- Contributor provides its Contributions) on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
- implied, including, without limitation, any warranties or conditions
- of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
- PARTICULAR PURPOSE. You are solely responsible for determining the
- appropriateness of using or redistributing the Work and assume any
- risks associated with Your exercise of permissions under this License.
-
- 8. Limitation of Liability. In no event and under no legal theory,
- whether in tort (including negligence), contract, or otherwise,
- unless required by applicable law (such as deliberate and grossly
- negligent acts) or agreed to in writing, shall any Contributor be
- liable to You for damages, including any direct, indirect, special,
- incidental, or consequential damages of any character arising as a
- result of this License or out of the use or inability to use the
- Work (including but not limited to damages for loss of goodwill,
- work stoppage, computer failure or malfunction, or any and all
- other commercial damages or losses), even if such Contributor
- has been advised of the possibility of such damages.
-
- 9. Accepting Warranty or Additional Liability. While redistributing
- the Work or Derivative Works thereof, You may choose to offer,
- and charge a fee for, acceptance of support, warranty, indemnity,
- or other liability obligations and/or rights consistent with this
- License. However, in accepting such obligations, You may act only
- on Your own behalf and on Your sole responsibility, not on behalf
- of any other Contributor, and only if You agree to indemnify,
- defend, and hold each Contributor harmless for any liability
- incurred by, or claims asserted against, such Contributor by reason
- of your accepting any such warranty or additional liability.
-
- END OF TERMS AND CONDITIONS
-
- APPENDIX: How to apply the Apache License to your work.
-
- To apply the Apache License to your work, attach the following
- boilerplate notice, with the fields enclosed by brackets "[]"
- replaced with your own identifying information. (Don't include
- the brackets!) The text should be enclosed in the appropriate
- comment syntax for the file format. We also recommend that a
- file or class name and description of purpose be included on the
- same "printed page" as the copyright notice for easier
- identification within third-party archives.
-
- Copyright [yyyy] [name of copyright owner]
-
- 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.
diff --git a/deploymentadmin/autoconf/LICENSE.kxml2 b/deploymentadmin/autoconf/LICENSE.kxml2
deleted file mode 100644
index 1fe595b039..0000000000
--- a/deploymentadmin/autoconf/LICENSE.kxml2
+++ /dev/null
@@ -1,19 +0,0 @@
-Copyright (c) 2002,2003, Stefan Haustein, Oberhausen, Rhld., Germany
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or
-sell copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
-IN THE SOFTWARE.
diff --git a/deploymentadmin/autoconf/NOTICE b/deploymentadmin/autoconf/NOTICE
deleted file mode 100644
index 3b625ade24..0000000000
--- a/deploymentadmin/autoconf/NOTICE
+++ /dev/null
@@ -1,15 +0,0 @@
-Apache Felix AutoConf Resource Processor
-Copyright 2011-2016 The Apache Software Foundation
-
-This product includes software developed at
-The Apache Software Foundation (http://www.apache.org/).
-Licensed under the Apache License 2.0.
-
-This product includes software developed at
-The OSGi Alliance (http://www.osgi.org/).
-Copyright (c) OSGi Alliance (2000, 2009).
-Licensed under the Apache License 2.0.
-
-This product includes software from http://kxml.sourceforge.net.
-Copyright (c) 2002,2003, Stefan Haustein, Oberhausen, Rhld., Germany.
-Licensed under BSD License.
diff --git a/deploymentadmin/autoconf/changelog.txt b/deploymentadmin/autoconf/changelog.txt
deleted file mode 100644
index f10405c068..0000000000
--- a/deploymentadmin/autoconf/changelog.txt
+++ /dev/null
@@ -1,26 +0,0 @@
-Release 0.1.8
--------------
-
-FELIX-5169 AutoConf incorrectly references constants from DeploymentAdmin
-
-Release 0.1.6
--------------
-
-FELIX-4912 Upgrade autoconf to Dependency Manager 4
-
-Release 0.1.5
--------------
-
-FELIX-3355 Autoconf can't find Metatype service
-FELIX-4314 Split service registration to solve visibility issue in autoconf
-
-Release 0.1.4
--------------
-
-FELIX-3243 Autoconf does not recognize non-local non-factory OCDs
-FELIX-3245 Autoconf handles metatype 1.1 cardinalty wrong
-FELIX-3400 Nullpointer in autoconfprocessor for invalid metatype files
-
-
-Initial Release 0.1.0
----------------------
diff --git a/deploymentadmin/autoconf/pom.xml b/deploymentadmin/autoconf/pom.xml
deleted file mode 100644
index b822354b45..0000000000
--- a/deploymentadmin/autoconf/pom.xml
+++ /dev/null
@@ -1,113 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- 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.
--->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
- <modelVersion>4.0.0</modelVersion>
- <parent>
- <groupId>org.apache.felix</groupId>
- <artifactId>felix-parent</artifactId>
- <version>3</version>
- <relativePath>../../pom/pom.xml</relativePath>
- </parent>
- <properties>
- <osgi.version>4.2.0</osgi.version>
- </properties>
- <packaging>bundle</packaging>
- <name>Apache Felix AutoConf Resource Processor</name>
- <version>0.1.10-SNAPSHOT</version>
- <artifactId>org.apache.felix.deployment.rp.autoconf</artifactId>
- <dependencies>
- <dependency>
- <groupId>org.osgi</groupId>
- <artifactId>org.osgi.core</artifactId>
- <version>${osgi.version}</version>
- </dependency>
- <dependency>
- <groupId>org.osgi</groupId>
- <artifactId>org.osgi.compendium</artifactId>
- <version>${osgi.version}</version>
- </dependency>
- <dependency>
- <groupId>org.apache.felix</groupId>
- <artifactId>org.apache.felix.dependencymanager</artifactId>
- <version>4.1.1</version>
- </dependency>
- <dependency>
- <groupId>org.apache.felix</groupId>
- <artifactId>org.apache.felix.deploymentadmin</artifactId>
- <version>0.9.6</version>
- </dependency>
- <dependency>
- <groupId>org.apache.felix</groupId>
- <artifactId>org.apache.felix.metatype</artifactId>
- <version>1.1.2</version>
- </dependency>
- </dependencies>
- <build>
- <resources>
- <resource>
- <directory>.</directory>
- <targetPath>META-INF</targetPath>
- <includes>
- <include>LICENSE*</include>
- <include>NOTICE*</include>
- <include>DEPENDENCIES*</include>
- <include>*.txt</include>
- </includes>
- </resource>
- </resources>
- <plugins>
- <plugin>
- <groupId>org.apache.felix</groupId>
- <artifactId>maven-bundle-plugin</artifactId>
- <version>2.3.4</version>
- <extensions>true</extensions>
- <configuration>
- <instructions>
- <Bundle-SymbolicName>org.apache.felix.deployment.rp.autoconf</Bundle-SymbolicName>
- <Bundle-Activator>org.apache.felix.deployment.rp.autoconf.Activator</Bundle-Activator>
- <Bundle-Name>Apache Felix AutoConf Resource Processor</Bundle-Name>
- <Bundle-Description>A customizer bundle that publishes a Resource Processor service that processes configuration resources shipped in a Deployment Package.</Bundle-Description>
- <Bundle-Vendor>The Apache Software Foundation</Bundle-Vendor>
- <Private-Package>
- org.apache.felix.deployment.rp.autoconf,
- org.apache.felix.metatype,
- org.apache.felix.metatype.internal.l10n,
- org.apache.felix.metatype.internal,
- org.kxml2.io; -split-package:=merge-first,
- org.xmlpull.v1; -split-package:=merge-first,
- org.osgi.service.metatype; -split-package:=merge-first
- </Private-Package>
- <Export-Package>
- org.osgi.service.deploymentadmin.spi; -split-package:=merge-last;version="1.0",
- org.osgi.service.metatype; -split-package:=merge-last;version="1.2"
- </Export-Package>
- <DeploymentPackage-Customizer>true</DeploymentPackage-Customizer>
- <Deployment-ProvidesResourceProcessor>org.osgi.deployment.rp.autoconf</Deployment-ProvidesResourceProcessor>
- </instructions>
- </configuration>
- </plugin>
- </plugins>
- </build>
- <scm>
- <connection>scm:git:https://github.com/apache/felix-dev.git</connection>
- <developerConnection>scm:git:https://github.com/apache/felix-dev.git</developerConnection>
- <url>https://gitbox.apache.org/repos/asf?p=felix-dev.git</url>
- </scm>
-</project>
diff --git a/deploymentadmin/autoconf/src/main/java/org/apache/felix/deployment/rp/autoconf/Activator.java b/deploymentadmin/autoconf/src/main/java/org/apache/felix/deployment/rp/autoconf/Activator.java
deleted file mode 100644
index 0a31cfab07..0000000000
--- a/deploymentadmin/autoconf/src/main/java/org/apache/felix/deployment/rp/autoconf/Activator.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * 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.deployment.rp.autoconf;
-
-import java.util.Dictionary;
-import java.util.Properties;
-
-import org.apache.felix.dm.Component;
-import org.apache.felix.dm.DependencyActivatorBase;
-import org.apache.felix.dm.DependencyManager;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.Constants;
-import org.osgi.service.deploymentadmin.spi.ResourceProcessor;
-import org.osgi.service.log.LogService;
-import org.osgi.service.metatype.MetaTypeService;
-
-/**
- * Bundle activator for the AutoConf Resource Processor Customizer bundle
- */
-public class Activator extends DependencyActivatorBase {
-
- public void init(BundleContext context, DependencyManager manager) throws Exception {
- Dictionary properties = new Properties();
- properties.put(Constants.SERVICE_PID, "org.osgi.deployment.rp.autoconf");
-
- AutoConfResourceProcessor processor = new AutoConfResourceProcessor();
- manager.add(createComponent()
- .setInterface(ResourceProcessor.class.getName(), properties)
- .setAutoConfig(Component.class, false)
- .setImplementation(processor)
- .add(createServiceDependency()
- .setService(MetaTypeService.class)
- .setRequired(false))
- .add(createServiceDependency()
- .setService(LogService.class)
- .setRequired(false)));
- }
-
- public void destroy(BundleContext context, DependencyManager manager) throws Exception {
- // do nothing
- }
-}
\ No newline at end of file
diff --git a/deploymentadmin/autoconf/src/main/java/org/apache/felix/deployment/rp/autoconf/AttributeDefinitionImpl.java b/deploymentadmin/autoconf/src/main/java/org/apache/felix/deployment/rp/autoconf/AttributeDefinitionImpl.java
deleted file mode 100644
index 6cef598716..0000000000
--- a/deploymentadmin/autoconf/src/main/java/org/apache/felix/deployment/rp/autoconf/AttributeDefinitionImpl.java
+++ /dev/null
@@ -1,68 +0,0 @@
-/*
- * 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.deployment.rp.autoconf;
-
-import org.apache.felix.metatype.AD;
-import org.osgi.service.metatype.AttributeDefinition;
-
-public class AttributeDefinitionImpl implements AttributeDefinition {
-
- private final AD m_ad;
-
- public AttributeDefinitionImpl(AD ad) {
- m_ad = ad;
- }
-
- public int getCardinality() {
- return m_ad.getCardinality();
- }
-
- public String[] getDefaultValue() {
- return m_ad.getDefaultValue();
- }
-
- public String getDescription() {
- return m_ad.getDescription();
- }
-
- public String getID() {
- return m_ad.getID();
- }
-
- public String getName() {
- return m_ad.getName();
- }
-
- public String[] getOptionLabels() {
- return m_ad.getOptionLabels();
- }
-
- public String[] getOptionValues() {
- return m_ad.getOptionValues();
- }
-
- public int getType() {
- return m_ad.getType();
- }
-
- public String validate(String value) {
- return m_ad.validate(value);
- }
-
-}
diff --git a/deploymentadmin/autoconf/src/main/java/org/apache/felix/deployment/rp/autoconf/AutoConfResource.java b/deploymentadmin/autoconf/src/main/java/org/apache/felix/deployment/rp/autoconf/AutoConfResource.java
deleted file mode 100644
index ca7e936b56..0000000000
--- a/deploymentadmin/autoconf/src/main/java/org/apache/felix/deployment/rp/autoconf/AutoConfResource.java
+++ /dev/null
@@ -1,163 +0,0 @@
-/*
- * 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.deployment.rp.autoconf;
-
-import java.io.IOException;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-import java.io.Serializable;
-import java.util.Dictionary;
-
-import org.osgi.framework.Filter;
-import org.osgi.framework.FrameworkUtil;
-import org.osgi.framework.InvalidSyntaxException;
-
-public class AutoConfResource implements Serializable
-{
- private static final long serialVersionUID = 1L;
-
- private final String m_pid;
- private final String m_factoryPid;
- private final Dictionary m_properties;
- private final String m_bundleLoc;
- private final boolean m_merge;
- private final String m_name;
-
- private transient Filter m_filter;
- private String m_alias = null;
-
- public AutoConfResource(String name, String pid, String factoryPid, String bundleLocation, boolean merge, Dictionary properties, Filter filter)
- {
- m_name = name;
- m_pid = pid;
- m_filter = filter;
- m_factoryPid = (factoryPid == null) ? "" : factoryPid;
- m_bundleLoc = bundleLocation;
- m_merge = merge;
- m_properties = properties;
- }
-
- public String getName()
- {
- return m_name;
- }
-
- public String getPid()
- {
- return m_pid;
- }
-
- public Filter getFilter()
- {
- return m_filter;
- }
-
- /**
- * Returns empty string if this configuration is not a factory configuration, otherwise the factory
- * PID is returned.
- *
- * @return Empty string if this is not a factory configuration resource, else the factory PID is returned.
- */
- public String getFactoryPid()
- {
- return m_factoryPid;
- }
-
- public Dictionary getProperties()
- {
- return m_properties;
- }
-
- public String getBundleLocation()
- {
- return m_bundleLoc;
- }
-
- public boolean isMerge()
- {
- return m_merge;
- }
-
- public boolean isFactoryConfig()
- {
- return !(m_factoryPid == null || "".equals(m_factoryPid));
- }
-
- public void setGeneratedPid(String alias)
- {
- m_alias = alias;
- }
-
- public String getGeneratedPid()
- {
- if (m_alias == null)
- {
- throw new IllegalStateException("Must set an alias first.");
- }
- return m_alias;
- }
-
- /**
- * Determine if the specified <code>AutoConfResource</code> is meant to be used for the same <code>Configuration</code> as this object.
- *
- * @param resource The <code>AutoConfResource</code> to compare with.
- * @return Returns <code>true</code> if the two resources are meant to be used for the same <code>Configuration</code> object, false otherwise.
- */
- public boolean equalsTargetConfiguration(AutoConfResource resource)
- {
- if (isFactoryConfig())
- {
- return m_pid.equals(resource.getPid()) && m_factoryPid.equals(resource.getFactoryPid());
- }
- else
- {
- return m_pid.equals(resource.getPid());
- }
- }
-
- private void writeObject(ObjectOutputStream out) throws IOException
- {
- out.defaultWriteObject();
- if (m_filter != null)
- {
- out.writeUTF(m_filter.toString());
- }
- else
- {
- out.writeUTF("");
- }
- }
-
- private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException
- {
- in.defaultReadObject();
- String filter = in.readUTF();
- if (!"".equals(filter))
- {
- try
- {
- m_filter = FrameworkUtil.createFilter(filter);
- }
- catch (InvalidSyntaxException e)
- {
- throw new IOException("Unable to parse serialized filter: " + e.getMessage());
- }
- }
- }
-}
diff --git a/deploymentadmin/autoconf/src/main/java/org/apache/felix/deployment/rp/autoconf/AutoConfResourceProcessor.java b/deploymentadmin/autoconf/src/main/java/org/apache/felix/deployment/rp/autoconf/AutoConfResourceProcessor.java
deleted file mode 100644
index 415f4cc2fe..0000000000
--- a/deploymentadmin/autoconf/src/main/java/org/apache/felix/deployment/rp/autoconf/AutoConfResourceProcessor.java
+++ /dev/null
@@ -1,782 +0,0 @@
-/*
- * 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.deployment.rp.autoconf;
-
-import static org.osgi.service.deploymentadmin.spi.ResourceProcessorException.CODE_OTHER_ERROR;
-
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Dictionary;
-import java.util.Enumeration;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Properties;
-import java.util.concurrent.atomic.AtomicReference;
-
-import org.apache.felix.dm.Component;
-import org.apache.felix.dm.DependencyManager;
-import org.apache.felix.metatype.Designate;
-import org.apache.felix.metatype.DesignateObject;
-import org.apache.felix.metatype.MetaData;
-import org.apache.felix.metatype.MetaDataReader;
-import org.apache.felix.metatype.OCD;
-import org.osgi.framework.Bundle;
-import org.osgi.framework.Filter;
-import org.osgi.framework.FrameworkUtil;
-import org.osgi.framework.InvalidSyntaxException;
-import org.osgi.framework.ServiceReference;
-import org.osgi.service.cm.Configuration;
-import org.osgi.service.cm.ConfigurationAdmin;
-import org.osgi.service.deploymentadmin.spi.DeploymentSession;
-import org.osgi.service.deploymentadmin.spi.ResourceProcessor;
-import org.osgi.service.deploymentadmin.spi.ResourceProcessorException;
-import org.osgi.service.event.Event;
-import org.osgi.service.event.EventConstants;
-import org.osgi.service.event.EventHandler;
-import org.osgi.service.log.LogService;
-import org.osgi.service.metatype.MetaTypeInformation;
-import org.osgi.service.metatype.MetaTypeService;
-import org.osgi.service.metatype.ObjectClassDefinition;
-
-public class AutoConfResourceProcessor implements ResourceProcessor, EventHandler
-{
- public static final String CONFIGURATION_ADMIN_FILTER_ATTRIBUTE = "filter";
-
- private static final String LOCATION_PREFIX = "osgi-dp:";
- /** FELIX-5169 - do not reference this constant from the Constants class in DA! */
- private static final String EVENTTOPIC_COMPLETE = "org/osgi/service/deployment/COMPLETE";
-
- // dependencies injected by Dependency Manager
- private volatile LogService m_log;
- private volatile MetaTypeService m_metaService;
- private volatile DependencyManager m_dm;
- // Locally managed
- private Component m_component;
- private PersistencyManager m_persistencyManager;
-
- private final Object m_lock; // protects the members below
- private final Map<String, List<AutoConfResource>> m_toBeInstalled;
- private final Map<String, List<AutoConfResource>> m_toBeDeleted;
- private final AtomicReference<DeploymentSession> m_sessionRef;
- private final List<ConfigurationAdminTask> m_configurationAdminTasks;
- private final List<PostCommitTask> m_postCommitTasks;
-
- public AutoConfResourceProcessor()
- {
- m_lock = new Object();
- m_sessionRef = new AtomicReference<DeploymentSession>();
- m_toBeInstalled = new HashMap<String, List<AutoConfResource>>();
- m_toBeDeleted = new HashMap<String, List<AutoConfResource>>();
- m_configurationAdminTasks = new ArrayList<ConfigurationAdminTask>();
- m_postCommitTasks = new ArrayList<PostCommitTask>();
- }
-
- /**
- * Called by Felix DM for the component created in {@link #commit()}.
- */
- public void addConfigurationAdmin(ServiceReference ref, ConfigurationAdmin ca)
- {
- m_log.log(LogService.LOG_DEBUG, "found configuration admin " + ref);
-
- List<ConfigurationAdminTask> configAdminTasks;
- synchronized (m_lock)
- {
- configAdminTasks = new ArrayList<ConfigurationAdminTask>(m_configurationAdminTasks);
- }
-
- for (ConfigurationAdminTask task : configAdminTasks)
- {
- try
- {
- Filter filter = task.getFilter();
- if ((filter == null) || (filter != null && filter.match(ref)))
- {
- task.run(m_persistencyManager, ca);
- }
- }
- catch (Exception e)
- {
- m_log.log(LogService.LOG_ERROR, "Exception during configuration to " + ca + ". Trying to continue.", e);
- }
- }
-
- m_log.log(LogService.LOG_DEBUG, "found configuration admin " + ref + " done");
- }
-
- public void begin(DeploymentSession session)
- {
- m_log.log(LogService.LOG_DEBUG, "beginning session " + session);
-
- synchronized (m_lock)
- {
- DeploymentSession current = m_sessionRef.get();
- if (current != null)
- {
- throw new IllegalArgumentException("Trying to begin new deployment session while already in one.");
- }
- if (session == null)
- {
- throw new IllegalArgumentException("Trying to begin new deployment session with a null session.");
- }
- if (!m_toBeInstalled.isEmpty() || !m_toBeDeleted.isEmpty() || !m_configurationAdminTasks.isEmpty() || !m_postCommitTasks.isEmpty() || m_component != null)
- {
- throw new IllegalStateException("State not reset correctly at start of session.");
- }
- m_sessionRef.set(session);
- }
- }
-
- public void cancel()
- {
- m_log.log(LogService.LOG_DEBUG, "cancel");
- rollback();
- }
-
- public void commit()
- {
- m_log.log(LogService.LOG_DEBUG, "commit");
-
- Dictionary properties = new Properties();
- properties.put(EventConstants.EVENT_TOPIC, EVENTTOPIC_COMPLETE);
- m_component = m_dm.createComponent()
- .setInterface(EventHandler.class.getName(), properties)
- .setImplementation(this)
- .setCallbacks(null, null, null, null)
- .setAutoConfig(Component.class, false)
- .add(m_dm.createServiceDependency()
- .setService(ConfigurationAdmin.class)
- .setCallbacks("addConfigurationAdmin", null)
- .setRequired(false)
- );
- m_dm.add(m_component);
-
- m_log.log(LogService.LOG_DEBUG, "commit done");
- }
-
- public void dropAllResources() throws ResourceProcessorException
- {
- m_log.log(LogService.LOG_DEBUG, "drop all resources");
-
- assertInDeploymentSession("Can not drop all resources without a Deployment Session");
-
- for (String name : m_persistencyManager.getResourceNames())
- {
- dropped(name);
- }
-
- m_log.log(LogService.LOG_DEBUG, "drop all resources done");
- }
-
- public void dropped(String name) throws ResourceProcessorException
- {
- m_log.log(LogService.LOG_DEBUG, "dropped " + name);
-
- assertInDeploymentSession("Can not drop resource without a Deployment Session");
-
- Map<String, List<AutoConfResource>> toBeDeleted;
- synchronized (m_lock)
- {
- toBeDeleted = new HashMap<String, List<AutoConfResource>>(m_toBeDeleted);
- }
-
- try
- {
- List<AutoConfResource> resources = m_persistencyManager.load(name);
-
- if (!toBeDeleted.containsKey(name))
- {
- toBeDeleted.put(name, new ArrayList());
- }
- toBeDeleted.get(name).addAll(resources);
- }
- catch (IOException ioe)
- {
- throw new ResourceProcessorException(CODE_OTHER_ERROR, "Unable to drop resource: " + name, ioe);
- }
-
- synchronized (m_lock)
- {
- m_toBeDeleted.putAll(toBeDeleted);
- }
-
- m_log.log(LogService.LOG_DEBUG, "dropped " + name + " done");
- }
-
- public void handleEvent(Event event)
- {
- // regardless of the outcome, we simply invoke postcommit
- postcommit();
- }
-
- public void postcommit()
- {
- m_log.log(LogService.LOG_DEBUG, "post commit");
-
- List<PostCommitTask> postCommitTasks;
- synchronized (m_lock)
- {
- postCommitTasks = new ArrayList<PostCommitTask>(m_postCommitTasks);
- }
-
- for (PostCommitTask task : postCommitTasks)
- {
- try
- {
- task.run(m_persistencyManager);
- }
- catch (Exception e)
- {
- m_log.log(LogService.LOG_ERROR, "Exception during post commit wrap-up. Trying to continue.", e);
- }
- }
-
- endSession();
-
- m_log.log(LogService.LOG_DEBUG, "post commit done");
- }
-
- public void prepare() throws ResourceProcessorException
- {
- m_log.log(LogService.LOG_DEBUG, "prepare");
-
- assertInDeploymentSession("Can not prepare resource without a Deployment Session");
-
- Map<String, List<AutoConfResource>> toBeDeleted;
- Map<String, List<AutoConfResource>> toBeInstalled;
- synchronized (m_lock)
- {
- toBeDeleted = new HashMap<String, List<AutoConfResource>>(m_toBeDeleted);
- toBeInstalled = new HashMap<String, List<AutoConfResource>>(m_toBeInstalled);
- }
-
- List<ConfigurationAdminTask> configAdminTasks = new ArrayList<ConfigurationAdminTask>();
- List<PostCommitTask> postCommitTasks = new ArrayList<PostCommitTask>();
-
- m_log.log(LogService.LOG_DEBUG, "prepare delete");
- // delete dropped resources
- for (Map.Entry<String, List<AutoConfResource>> entry : toBeDeleted.entrySet())
- {
- String name = entry.getKey();
- for (AutoConfResource resource : entry.getValue())
- {
- configAdminTasks.add(new DropResourceTask(resource));
- }
- postCommitTasks.add(new DeleteResourceTask(name));
- }
-
- m_log.log(LogService.LOG_DEBUG, "prepare install/update");
- // install new/updated resources
- for (Map.Entry<String, List<AutoConfResource>> entry : toBeInstalled.entrySet())
- {
- String name = entry.getKey();
-
- List<AutoConfResource> existingResources = null;
- try
- {
- existingResources = m_persistencyManager.load(name);
- }
- catch (IOException ioe)
- {
- throw new ResourceProcessorException(ResourceProcessorException.CODE_PREPARE, "Unable to read existing resources for resource " + name, ioe);
- }
-
- List<AutoConfResource> resources = entry.getValue();
- for (AutoConfResource resource : resources)
- {
- // When updating existing configurations, make sure that we delete the ones that have become obsolete...
- if (existingResources != null)
- {
- Iterator<AutoConfResource> iter = existingResources.iterator();
- while (iter.hasNext())
- {
- AutoConfResource existing = iter.next();
- if (existing.equalsTargetConfiguration(resource))
- {
- iter.remove();
- }
- }
- }
-
- configAdminTasks.add(new InstallOrUpdateResourceTask(resource));
- }
- // remove existing configurations that were not in the new version of the resource
- for (AutoConfResource existingResource : existingResources)
- {
- configAdminTasks.add(new DropResourceTask(existingResource));
- }
-
- postCommitTasks.add(new StoreResourceTask(name, resources));
- }
-
- synchronized (m_lock)
- {
- m_configurationAdminTasks.addAll(configAdminTasks);
- m_postCommitTasks.addAll(postCommitTasks);
- }
-
- m_log.log(LogService.LOG_DEBUG, "prepare done");
- }
-
- public void process(String name, InputStream stream) throws ResourceProcessorException
- {
- m_log.log(LogService.LOG_DEBUG, "processing " + name);
-
- // initial validation
- assertInDeploymentSession("Can not process resource without a Deployment Session");
-
- Map<String, List<AutoConfResource>> toBeInstalled;
- synchronized (m_lock)
- {
- toBeInstalled = new HashMap<String, List<AutoConfResource>>(m_toBeInstalled);
- }
-
- MetaData data = parseAutoConfResource(stream);
- // process resources
- Filter filter = getFilter(data);
-
- // add to session data
- if (!toBeInstalled.containsKey(name))
- {
- toBeInstalled.put(name, new ArrayList<AutoConfResource>());
- }
-
- List<Designate> designates = data.getDesignates();
- if (designates == null || designates.isEmpty())
- {
- // if there are no designates, there's nothing to process
- m_log.log(LogService.LOG_INFO, "No designates found in the resource, so there's nothing to process.");
- return;
- }
-
- Map<String, OCD> localOcds = data.getObjectClassDefinitions();
- if (localOcds == null)
- {
- localOcds = Collections.emptyMap();
- }
-
- for (Designate designate : designates)
- {
- // check object
- DesignateObject objectDef = designate.getObject();
- if (objectDef == null)
- {
- throw new ResourceProcessorException(CODE_OTHER_ERROR, "Designate Object child missing or invalid");
- }
-
- // check attributes
- if (objectDef.getAttributes() == null || objectDef.getAttributes().isEmpty())
- {
- throw new ResourceProcessorException(CODE_OTHER_ERROR, "Object Attributes child missing or invalid");
- }
-
- // check ocdRef
- String ocdRef = objectDef.getOcdRef();
- if (ocdRef == null || "".equals(ocdRef))
- {
- throw new ResourceProcessorException(CODE_OTHER_ERROR, "Object ocdRef attribute missing or invalid");
- }
-
- // determine OCD
- ObjectClassDefinition ocd = null;
- OCD localOcd = localOcds.get(ocdRef);
- // ask meta type service for matching OCD if no local OCD has been defined
- ocd = (localOcd != null) ? new ObjectClassDefinitionImpl(localOcd) : getMetaTypeOCD(data, designate);
- if (ocd == null)
- {
- throw new ResourceProcessorException(CODE_OTHER_ERROR, "No Object Class Definition found with id=" + ocdRef);
- }
-
- // determine configuration data based on the values and their type definition
- Dictionary dict = MetaTypeUtil.getProperties(designate, ocd);
- if (dict == null)
- {
- // designate does not match it's definition, but was marked optional, ignore it
- continue;
- }
-
- AutoConfResource resource = new AutoConfResource(name, designate.getPid(), designate.getFactoryPid(), designate.getBundleLocation(), designate.isMerge(), dict, filter);
-
- toBeInstalled.get(name).add(resource);
- }
-
- synchronized (m_lock)
- {
- m_toBeInstalled.putAll(toBeInstalled);
- }
-
- m_log.log(LogService.LOG_DEBUG, "processing " + name + " done");
- }
-
- public void rollback()
- {
- m_log.log(LogService.LOG_DEBUG, "rollback");
-
- Map<String, List<AutoConfResource>> toBeInstalled;
- synchronized (m_lock)
- {
- toBeInstalled = new HashMap<String, List<AutoConfResource>>(m_toBeInstalled);
- }
-
- for (Map.Entry<String, List<AutoConfResource>> entry : toBeInstalled.entrySet())
- {
- for (AutoConfResource resource : entry.getValue())
- {
- String name = resource.getName();
- try
- {
- dropped(name);
- }
- catch (ResourceProcessorException e)
- {
- m_log.log(LogService.LOG_ERROR, "Unable to roll back resource '" + name + "', reason: " + e.getMessage() + ", caused by: " + e.getCause().getMessage());
- }
- break;
- }
- }
-
- endSession();
-
- m_log.log(LogService.LOG_DEBUG, "rollback done");
- }
-
- /**
- * Called by Felix DM when starting this component.
- */
- public void start() throws IOException
- {
- File root = m_dm.getBundleContext().getDataFile("");
- if (root == null)
- {
- throw new IOException("No file system support");
- }
- m_persistencyManager = new PersistencyManager(root);
- }
-
- private void assertInDeploymentSession(String msg) throws ResourceProcessorException
- {
- synchronized (m_lock)
- {
- DeploymentSession current = m_sessionRef.get();
- if (current == null)
- {
- throw new ResourceProcessorException(CODE_OTHER_ERROR, msg);
- }
- }
- }
-
- private void endSession()
- {
- if (m_component != null)
- {
- m_dm.remove(m_component);
- m_component = null;
- }
- synchronized (m_lock)
- {
- m_toBeInstalled.clear();
- m_toBeDeleted.clear();
- m_postCommitTasks.clear();
- m_configurationAdminTasks.clear();
- m_sessionRef.set(null);
- }
- }
-
- private Bundle getBundle(String bundleLocation, boolean isFactory) throws ResourceProcessorException
- {
- Bundle bundle = null;
- if (!isFactory)
- {
- // singleton configuration, no foreign bundles allowed, use source deployment package to find specified bundle
- if (bundleLocation.startsWith(LOCATION_PREFIX))
- {
- DeploymentSession session = m_sessionRef.get();
- bundle = session.getSourceDeploymentPackage().getBundle(bundleLocation.substring(LOCATION_PREFIX.length()));
- }
- }
- else
- {
- // factory configuration, foreign bundles allowed, use bundle context to find the specified bundle
- Bundle[] bundles = m_dm.getBundleContext().getBundles();
- for (int i = 0; i < bundles.length; i++)
- {
- String location = bundles[i].getLocation();
- if (bundleLocation.equals(location))
- {
- bundle = bundles[i];
- break;
- }
- }
- }
- return bundle;
- }
-
- private Filter getFilter(MetaData data) throws ResourceProcessorException
- {
- Map optionalAttributes = data.getOptionalAttributes();
- if (optionalAttributes != null)
- {
- try
- {
- return FrameworkUtil.createFilter((String) optionalAttributes.get(AutoConfResourceProcessor.CONFIGURATION_ADMIN_FILTER_ATTRIBUTE));
- }
- catch (InvalidSyntaxException e)
- {
- throw new ResourceProcessorException(CODE_OTHER_ERROR, "Unable to create filter!", e);
- }
- }
- return null;
- }
-
- /**
- * Determines the object class definition matching the specified designate.
- *
- * @param data The meta data containing 'local' object class definitions.
- * @param designate The designate whose object class definition should be determined.
- * @return
- * @throws ResourceProcessorException
- */
- private ObjectClassDefinition getMetaTypeOCD(MetaData data, Designate designate) throws ResourceProcessorException
- {
- boolean isFactoryConfig = isFactoryConfig(designate);
-
- Bundle bundle = getBundle(designate.getBundleLocation(), isFactoryConfig);
- if (bundle == null)
- {
- return null;
- }
-
- MetaTypeInformation mti = m_metaService.getMetaTypeInformation(bundle);
- if (mti == null)
- {
- return null;
- }
-
- String pid = isFactoryConfig ? pid = designate.getFactoryPid() : designate.getPid();
- try
- {
- ObjectClassDefinition tempOcd = mti.getObjectClassDefinition(pid, null);
- // tempOcd will always have a value, if pid was not known IAE will be thrown
- String ocdRef = designate.getObject().getOcdRef();
- if (ocdRef.equals(tempOcd.getID()))
- {
- return tempOcd;
- }
- }
- catch (IllegalArgumentException iae)
- {
- // let null be returned
- }
-
- return null;
- }
-
- private boolean isFactoryConfig(Designate designate)
- {
- String factoryPid = designate.getFactoryPid();
- return (factoryPid != null && !"".equals(factoryPid));
- }
-
- private MetaData parseAutoConfResource(InputStream stream) throws ResourceProcessorException
- {
- MetaDataReader reader = new MetaDataReader();
- MetaData data = null;
- try
- {
- data = reader.parse(stream);
- }
- catch (IOException e)
- {
- throw new ResourceProcessorException(CODE_OTHER_ERROR, "Unable to process resource.", e);
- }
- if (data == null)
- {
- throw new ResourceProcessorException(CODE_OTHER_ERROR, "Supplied configuration is not conform the metatype xml specification.");
- }
- return data;
- }
-}
-
-interface ConfigurationAdminTask
-{
- public Filter getFilter();
-
- public void run(PersistencyManager persistencyManager, ConfigurationAdmin configAdmin) throws Exception;
-}
-
-class DeleteResourceTask implements PostCommitTask
-{
- private final String m_name;
-
- public DeleteResourceTask(String name)
- {
- m_name = name;
- }
-
- public void run(PersistencyManager manager) throws Exception
- {
- manager.delete(m_name);
- }
-}
-
-class DropResourceTask implements ConfigurationAdminTask
-{
- private final AutoConfResource m_resource;
-
- public DropResourceTask(AutoConfResource resource)
- {
- m_resource = resource;
- }
-
- public Filter getFilter()
- {
- return m_resource.getFilter();
- }
-
- public void run(PersistencyManager persistencyManager, ConfigurationAdmin configAdmin) throws Exception
- {
- String pid;
- if (m_resource.isFactoryConfig())
- {
- pid = m_resource.getGeneratedPid();
- }
- else
- {
- pid = m_resource.getPid();
- }
- Configuration configuration = configAdmin.getConfiguration(pid, m_resource.getBundleLocation());
- configuration.delete();
- }
-}
-
-class InstallOrUpdateResourceTask implements ConfigurationAdminTask
-{
- private final AutoConfResource m_resource;
-
- public InstallOrUpdateResourceTask(AutoConfResource resource)
- {
- m_resource = resource;
- }
-
- public Filter getFilter()
- {
- return m_resource.getFilter();
- }
-
- public void run(PersistencyManager persistencyManager, ConfigurationAdmin configAdmin) throws Exception
- {
- String name = m_resource.getName();
- Dictionary properties = m_resource.getProperties();
- String bundleLocation = m_resource.getBundleLocation();
- Configuration configuration = null;
-
- List existingResources = null;
- try
- {
- existingResources = persistencyManager.load(name);
- }
- catch (IOException ioe)
- {
- throw new ResourceProcessorException(ResourceProcessorException.CODE_PREPARE, "Unable to read existing resources for resource " + name, ioe);
- }
-
- // update configuration
- if (m_resource.isFactoryConfig())
- {
- // check if this is an factory config instance update
- for (Iterator i = existingResources.iterator(); i.hasNext();)
- {
- AutoConfResource existingResource = (AutoConfResource) i.next();
- if (m_resource.equalsTargetConfiguration(existingResource))
- {
- // existing instance found
- configuration = configAdmin.getConfiguration(existingResource.getGeneratedPid(), bundleLocation);
- existingResources.remove(existingResource);
- break;
- }
- }
- if (configuration == null)
- {
- // no existing instance, create new
- configuration = configAdmin.createFactoryConfiguration(m_resource.getFactoryPid(), bundleLocation);
- }
- m_resource.setGeneratedPid(configuration.getPid());
- }
- else
- {
- for (Iterator i = existingResources.iterator(); i.hasNext();)
- {
- AutoConfResource existingResource = (AutoConfResource) i.next();
- if (m_resource.getPid().equals(existingResource.getPid()))
- {
- // existing resource found
- existingResources.remove(existingResource);
- break;
- }
- }
- configuration = configAdmin.getConfiguration(m_resource.getPid(), bundleLocation);
- if (!bundleLocation.equals(configuration.getBundleLocation()))
- {
- // an existing configuration exists that is bound to a different location, which is not allowed
- throw new ResourceProcessorException(ResourceProcessorException.CODE_PREPARE,
- "Existing configuration was bound to " + configuration.getBundleLocation() + " instead of " + bundleLocation);
- }
- }
- if (m_resource.isMerge())
- {
- Dictionary existingProperties = configuration.getProperties();
- if (existingProperties != null)
- {
- Enumeration keys = existingProperties.keys();
- while (keys.hasMoreElements())
- {
- Object key = keys.nextElement();
- properties.put(key, existingProperties.get(key));
- }
- }
- }
- configuration.update(properties);
- }
-}
-
-interface PostCommitTask
-{
- public void run(PersistencyManager manager) throws Exception;
-}
-
-class StoreResourceTask implements PostCommitTask
-{
- private final String m_name;
- private final List m_resources;
-
- public StoreResourceTask(String name, List resources)
- {
- m_name = name;
- m_resources = resources;
- }
-
- public void run(PersistencyManager manager) throws Exception
- {
- manager.store(m_name, m_resources);
- }
-}
\ No newline at end of file
diff --git a/deploymentadmin/autoconf/src/main/java/org/apache/felix/deployment/rp/autoconf/MetaTypeUtil.java b/deploymentadmin/autoconf/src/main/java/org/apache/felix/deployment/rp/autoconf/MetaTypeUtil.java
deleted file mode 100644
index 7abbb91e17..0000000000
--- a/deploymentadmin/autoconf/src/main/java/org/apache/felix/deployment/rp/autoconf/MetaTypeUtil.java
+++ /dev/null
@@ -1,233 +0,0 @@
-/*
- * 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.deployment.rp.autoconf;
-
-import static org.osgi.service.deploymentadmin.spi.ResourceProcessorException.CODE_OTHER_ERROR;
-
-import java.util.Arrays;
-import java.util.Dictionary;
-import java.util.Hashtable;
-import java.util.List;
-import java.util.Vector;
-
-import org.apache.felix.metatype.Attribute;
-import org.apache.felix.metatype.Designate;
-import org.osgi.service.deploymentadmin.spi.ResourceProcessorException;
-import org.osgi.service.metatype.AttributeDefinition;
-import org.osgi.service.metatype.ObjectClassDefinition;
-
-/**
- * Convenience methods to work with MetaType structures.
- */
-public class MetaTypeUtil
-{
- private MetaTypeUtil()
- {
- // Nop
- }
-
- /**
- * Determines the actual configuration data based on the specified designate and object class definition
- *
- * @param designate The designate object containing the values for the properties
- * @param ocd The object class definition
- * @return A dictionary containing data as described in the designate and ocd objects, or <code>null</code> if the designate does not match it's
- * definition and the designate was marked as optional.
- * @throws ResourceProcessorException If the designate does not match the ocd and the designate is not marked as optional.
- */
- public static Dictionary getProperties(Designate designate, ObjectClassDefinition ocd) throws ResourceProcessorException
- {
- Dictionary properties = new Hashtable();
- AttributeDefinition[] attributeDefs = ocd.getAttributeDefinitions(ObjectClassDefinition.ALL);
-
- List<Attribute> attributes = designate.getObject().getAttributes();
- for (Attribute attribute : attributes)
- {
- String adRef = attribute.getAdRef();
- boolean found = false;
- for (int j = 0; j < attributeDefs.length; j++)
- {
- AttributeDefinition ad = attributeDefs[j];
- if (adRef.equals(ad.getID()))
- {
- // found attribute definition
- Object value = getValue(attribute, ad);
- if (value == null)
- {
- if (designate.isOptional())
- {
- properties = null;
- break;
- }
- else
- {
- throw new ResourceProcessorException(CODE_OTHER_ERROR, "Could not match attribute to it's definition: adref=" + adRef);
- }
- }
- properties.put(adRef, value);
- found = true;
- break;
- }
- }
- if (!found)
- {
- if (designate.isOptional())
- {
- properties = null;
- break;
- }
- else
- {
- throw new ResourceProcessorException(CODE_OTHER_ERROR, "Could not find attribute definition: adref=" + adRef);
- }
- }
- }
-
- return properties;
- }
-
- /**
- * Determines the value of an attribute based on an attribute definition
- *
- * @param attribute The attribute containing value(s)
- * @param ad The attribute definition
- * @return An <code>Object</code> reflecting what was specified in the attribute and it's definition or <code>null</code> if the value did not match it's definition.
- * @throws ResourceProcessorException in case we're unable to parse the value of an attribute.
- */
- private static Object getValue(Attribute attribute, AttributeDefinition ad) throws ResourceProcessorException
- {
- if (attribute == null || ad == null || !attribute.getAdRef().equals(ad.getID()))
- {
- // wrong attribute or definition
- return null;
- }
- String[] content = attribute.getContent();
-
- // verify correct type of the value(s)
- int type = ad.getType();
- Object[] typedContent = null;
- try
- {
- for (int i = 0; i < content.length; i++)
- {
- String value = content[i];
- switch (type)
- {
- case AttributeDefinition.BOOLEAN:
- typedContent = (typedContent == null) ? new Boolean[content.length] : typedContent;
- typedContent[i] = Boolean.valueOf(value);
- break;
- case AttributeDefinition.BYTE:
- typedContent = (typedContent == null) ? new Byte[content.length] : typedContent;
- typedContent[i] = Byte.valueOf(value);
- break;
- case AttributeDefinition.CHARACTER:
- typedContent = (typedContent == null) ? new Character[content.length] : typedContent;
- char[] charArray = value.toCharArray();
- if (charArray.length == 1)
- {
- typedContent[i] = new Character(charArray[0]);
- }
- else
- {
- throw new ResourceProcessorException(CODE_OTHER_ERROR, "Unable to parse value for definition: adref=" + ad.getID());
- }
- break;
- case AttributeDefinition.DOUBLE:
- typedContent = (typedContent == null) ? new Double[content.length] : typedContent;
- typedContent[i] = Double.valueOf(value);
- break;
- case AttributeDefinition.FLOAT:
- typedContent = (typedContent == null) ? new Float[content.length] : typedContent;
- typedContent[i] = Float.valueOf(value);
- break;
- case AttributeDefinition.INTEGER:
- typedContent = (typedContent == null) ? new Integer[content.length] : typedContent;
- typedContent[i] = Integer.valueOf(value);
- break;
- case AttributeDefinition.LONG:
- typedContent = (typedContent == null) ? new Long[content.length] : typedContent;
- typedContent[i] = Long.valueOf(value);
- break;
- case AttributeDefinition.SHORT:
- typedContent = (typedContent == null) ? new Short[content.length] : typedContent;
- typedContent[i] = Short.valueOf(value);
- break;
- case AttributeDefinition.STRING:
- typedContent = (typedContent == null) ? new String[content.length] : typedContent;
- typedContent[i] = value;
- break;
- default:
- // unsupported type
- throw new ResourceProcessorException(CODE_OTHER_ERROR, "Unsupported value-type for definition: adref=" + ad.getID());
- }
- }
- }
- catch (NumberFormatException nfe)
- {
- throw new ResourceProcessorException(CODE_OTHER_ERROR, "Unable to parse value for definition: adref=" + ad.getID());
- }
-
- // verify cardinality of value(s)
- int cardinality = ad.getCardinality();
- Object result = null;
- if (cardinality == 0)
- {
- if (typedContent.length == 1)
- {
- result = typedContent[0];
- }
- else
- {
- result = null;
- }
- }
- else if (cardinality == Integer.MIN_VALUE)
- {
- result = new Vector(Arrays.asList(typedContent));
- }
- else if (cardinality == Integer.MAX_VALUE)
- {
- result = typedContent;
- }
- else if (cardinality < 0)
- {
- if (typedContent.length <= Math.abs(cardinality))
- {
- result = new Vector(Arrays.asList(typedContent));
- }
- else
- {
- result = null;
- }
- }
- else if (cardinality > 0)
- {
- if (typedContent.length <= cardinality)
- {
- result = typedContent;
- }
- else
- {
- result = null;
- }
- }
- return result;
- }
-}
diff --git a/deploymentadmin/autoconf/src/main/java/org/apache/felix/deployment/rp/autoconf/ObjectClassDefinitionImpl.java b/deploymentadmin/autoconf/src/main/java/org/apache/felix/deployment/rp/autoconf/ObjectClassDefinitionImpl.java
deleted file mode 100644
index 82634c3622..0000000000
--- a/deploymentadmin/autoconf/src/main/java/org/apache/felix/deployment/rp/autoconf/ObjectClassDefinitionImpl.java
+++ /dev/null
@@ -1,81 +0,0 @@
-/*
- * 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.deployment.rp.autoconf;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
-import org.apache.felix.metatype.AD;
-import org.apache.felix.metatype.OCD;
-import org.osgi.service.metatype.AttributeDefinition;
-import org.osgi.service.metatype.ObjectClassDefinition;
-
-public class ObjectClassDefinitionImpl implements ObjectClassDefinition {
-
- private final OCD m_ocd;
-
- public ObjectClassDefinitionImpl(OCD ocd) {
- m_ocd = ocd;
- }
-
- public AttributeDefinition[] getAttributeDefinitions(int filter) {
- if (m_ocd.getAttributeDefinitions() == null) {
- return null;
- }
- if (filter != ObjectClassDefinition.OPTIONAL && filter != ObjectClassDefinition.REQUIRED && filter != ObjectClassDefinition.ALL) {
- return null;
- }
-
- List result = new ArrayList();
- for (Iterator i = m_ocd.getAttributeDefinitions().values().iterator(); i.hasNext();) {
- AD ad = (AD) i.next();
- if (filter != ObjectClassDefinition.ALL) {
- if (ad.isRequired() && filter == ObjectClassDefinition.REQUIRED) {
- result.add(new AttributeDefinitionImpl(ad));
- }
- else if (!ad.isRequired() && filter == ObjectClassDefinition.OPTIONAL) {
- result.add(new AttributeDefinitionImpl(ad));
- }
- } else {
- result.add(new AttributeDefinitionImpl(ad));
- }
- }
-
- return (AttributeDefinition[]) result.toArray(new AttributeDefinition[result.size()]);
- }
-
- public InputStream getIcon(int size) throws IOException {
- return null;
- }
-
- public String getDescription() {
- return m_ocd.getDescription();
- }
-
- public String getID() {
- return m_ocd.getID();
- }
-
- public String getName() {
- return m_ocd.getName();
- }
-}
diff --git a/deploymentadmin/autoconf/src/main/java/org/apache/felix/deployment/rp/autoconf/PersistencyManager.java b/deploymentadmin/autoconf/src/main/java/org/apache/felix/deployment/rp/autoconf/PersistencyManager.java
deleted file mode 100644
index cd41d3089e..0000000000
--- a/deploymentadmin/autoconf/src/main/java/org/apache/felix/deployment/rp/autoconf/PersistencyManager.java
+++ /dev/null
@@ -1,183 +0,0 @@
-/*
- * 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.deployment.rp.autoconf;
-
-import java.io.File;
-import java.io.FileFilter;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-import java.util.ArrayList;
-import java.util.List;
-
-public class PersistencyManager
-{
- private static final FileFilter FILES_ONLY_FILTER = new FileFilter()
- {
- public boolean accept(File pathname)
- {
- return pathname.isFile();
- }
- };
-
- private final File m_root;
-
- public PersistencyManager(File root)
- {
- m_root = root;
- }
-
- /**
- * Deletes a resource.
- *
- * @param name Name of the resource.
- * @throws IOException If the resource could not be deleted.
- */
- public void delete(String name) throws IOException
- {
- name = name.replace('/', File.separatorChar);
- File target = new File(m_root, name);
- if (target.exists() && !target.delete())
- {
- throw new IOException("Unable to delete file: " + target.getAbsolutePath());
- }
- while (target.getParentFile().list().length == 0 && !target.getParentFile().getAbsolutePath().equals(m_root.getAbsolutePath()))
- {
- target = target.getParentFile();
- target.delete();
- }
- }
-
- /**
- * Returns the names of all persisted resources.
- * @return a list of resource names, never <code>null</code>.
- */
- public List<String> getResourceNames()
- {
- List<String> result = new ArrayList<String>();
-
- File[] list = m_root.listFiles(FILES_ONLY_FILTER);
- if (list != null && list.length > 0)
- {
- for (File resource : list)
- {
- result.add(resource.getName());
- }
- }
- return result;
- }
-
- /**
- * Loads a stored resource.
- *
- * @param name Name of the resource.
- * @return List of <code>AutoConfResource</code>s representing the specified resource, if the resource is unknown an empty list is returned.
- * @throws IOException If the resource could not be properly read.
- */
- public List<AutoConfResource> load(String name) throws IOException
- {
- List<AutoConfResource> resources = new ArrayList<AutoConfResource>();
- name = name.replace('/', File.separatorChar);
- File resourcesFile = new File(m_root, name);
- if (!resourcesFile.exists())
- {
- return resources;
- }
-
- ObjectInputStream in = null;
- try
- {
- in = new ObjectInputStream(new FileInputStream(resourcesFile));
- resources = (List<AutoConfResource>) in.readObject();
- }
- catch (FileNotFoundException e)
- {
- throw new IOException("Resource does not exist: " + name);
- }
- catch (ClassNotFoundException e)
- {
- throw new IOException("Unable to recreate persisted object from file: " + name);
- }
- finally
- {
- if (in != null)
- {
- try
- {
- in.close();
- }
- catch (Exception e)
- {
- // not much we can do
- }
- }
- }
- return resources;
- }
-
- /**
- * Stores a resource.
- *
- * @param name Name of the resource.
- * @param configs List of <code>AutoConfResource</code>s representing the specified resource.
- * @throws IOException If the resource could not be stored.
- */
- public void store(String name, List<AutoConfResource> configs) throws IOException
- {
- File targetDir = m_root;
- name = name.replace('/', File.separatorChar);
-
- if (name.startsWith(File.separator))
- {
- name = name.substring(1);
- }
- int lastSeparator = name.lastIndexOf(File.separator);
- File target = null;
- if (lastSeparator != -1)
- {
- targetDir = new File(targetDir, name.substring(0, lastSeparator));
- targetDir.mkdirs();
- }
- target = new File(targetDir, name.substring(lastSeparator + 1));
-
- ObjectOutputStream out = null;
- try
- {
- out = new ObjectOutputStream(new FileOutputStream(target));
- out.writeObject(configs);
- }
- finally
- {
- if (out != null)
- {
- try
- {
- out.close();
- }
- catch (Exception e)
- {
- // not much we can do
- }
- }
- }
- }
-}
diff --git a/deploymentadmin/autoconf/src/test/java/org/apache/felix/deployment/rp/autoconf/AutoConfResourceProcessorTest.java b/deploymentadmin/autoconf/src/test/java/org/apache/felix/deployment/rp/autoconf/AutoConfResourceProcessorTest.java
deleted file mode 100644
index 271520c89c..0000000000
--- a/deploymentadmin/autoconf/src/test/java/org/apache/felix/deployment/rp/autoconf/AutoConfResourceProcessorTest.java
+++ /dev/null
@@ -1,627 +0,0 @@
-/*
- * 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.deployment.rp.autoconf;
-
-import java.io.ByteArrayInputStream;
-import java.io.File;
-import java.io.IOException;
-import java.util.Collections;
-import java.util.Dictionary;
-import java.util.LinkedHashMap;
-import java.util.Map;
-import java.util.Properties;
-
-import junit.framework.TestCase;
-
-import org.apache.felix.dm.Component;
-import org.apache.felix.dm.DependencyManager;
-import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.Filter;
-import org.osgi.framework.InvalidSyntaxException;
-import org.osgi.framework.ServiceReference;
-import org.osgi.service.cm.Configuration;
-import org.osgi.service.cm.ConfigurationAdmin;
-import org.osgi.service.deploymentadmin.DeploymentPackage;
-import org.osgi.service.deploymentadmin.spi.DeploymentSession;
-import org.osgi.service.deploymentadmin.spi.ResourceProcessorException;
-import org.osgi.service.log.LogService;
-
-public class AutoConfResourceProcessorTest extends TestCase
-{
- private static class ConfigurationAdminImpl implements ConfigurationAdmin
- {
- private final String[] m_expectedPIDs;
- private final String[] m_expectedFactoryPIDs;
- private final Map<String, ConfigurationImpl> m_configs;
-
- public ConfigurationAdminImpl(String... expectedPIDs)
- {
- this(expectedPIDs, new String[0]);
- }
-
- public ConfigurationAdminImpl(String[] expectedPIDs, String[] expectedFactoryPIDs)
- {
- m_expectedPIDs = expectedPIDs;
- m_expectedFactoryPIDs = expectedFactoryPIDs;
-
- m_configs = new LinkedHashMap<String, ConfigurationImpl>();
- }
-
- public Configuration createFactoryConfiguration(String factoryPid) throws IOException
- {
- return createFactoryConfiguration(factoryPid, null);
- }
-
- public Configuration createFactoryConfiguration(String factoryPid, String location) throws IOException
- {
- if (!isExpected(m_expectedFactoryPIDs, factoryPid))
- {
- throw new IOException("Unexpected factory PID: " + factoryPid);
- }
- // This should be unique enough for our use cases...
- String pid = String.format("pid%d", m_configs.size());
-
- ConfigurationImpl config = m_configs.get(pid);
- if (config == null)
- {
- config = new ConfigurationImpl(factoryPid, pid, location);
- m_configs.put(pid, config);
- }
- config.setBundleLocation(location);
- return config;
- }
-
- public Configuration getConfiguration(String pid) throws IOException
- {
- return getConfiguration(pid, null);
- }
-
- public Configuration getConfiguration(String pid, String location) throws IOException
- {
- if (!isExpected(m_expectedPIDs, pid))
- {
- throw new IOException("Unexpected PID: " + pid);
- }
-
- ConfigurationImpl config = m_configs.get(pid);
- if (config == null)
- {
- config = new ConfigurationImpl(null, pid, location);
- m_configs.put(pid, config);
- }
- config.setBundleLocation(location);
- return config;
- }
-
- public Configuration[] listConfigurations(String filter) throws IOException, InvalidSyntaxException
- {
- return null;
- }
-
- private boolean isExpected(String[] expectedPIDs, String actualPID)
- {
- for (String expectedPID : expectedPIDs)
- {
- if (actualPID.equals(expectedPID))
- {
- return true;
- }
- }
- return false;
- }
- }
-
- private static class ConfigurationImpl implements Configuration
- {
- private final String m_factoryPID;
- private final String m_pid;
- private String m_bundleLocation;
- private Dictionary m_properties;
- private boolean m_deleted;
-
- public ConfigurationImpl(String factoryPid, String pid, String bundleLocation)
- {
- m_factoryPID = factoryPid;
- m_pid = pid;
- m_bundleLocation = bundleLocation;
- }
-
- public void delete() throws IOException
- {
- m_deleted = true;
- }
-
- public String getBundleLocation()
- {
- return m_bundleLocation;
- }
-
- public String getFactoryPid()
- {
- return m_factoryPID;
- }
-
- public String getPid()
- {
- return m_pid;
- }
-
- public Dictionary getProperties()
- {
- return m_properties;
- }
-
- public void setBundleLocation(String bundleLocation)
- {
- if (m_bundleLocation != null && !m_bundleLocation.equals(bundleLocation))
- {
- throw new RuntimeException("Configuration already bound to location: " + m_bundleLocation + " (trying to set to: " + bundleLocation + ")");
- }
- m_bundleLocation = bundleLocation;
- }
-
- public void update() throws IOException
- {
- }
-
- public void update(Dictionary properties) throws IOException
- {
- m_properties = properties;
- }
- }
-
- /** Dummy session. */
- private static class DeploymentSessionImpl implements DeploymentSession
- {
- public File getDataFile(Bundle bundle)
- {
- return null;
- }
-
- public DeploymentPackage getSourceDeploymentPackage()
- {
- return null;
- }
-
- public DeploymentPackage getTargetDeploymentPackage()
- {
- return null;
- }
-
- @Override
- public String toString()
- {
- return "Test DeploymentSession @ 0x" + System.identityHashCode(this);
- }
- }
-
- private static class LogServiceImpl implements LogService
- {
- private static final String[] LEVEL = { "", "[ERROR]", "[WARN ]", "[INFO ]", "[DEBUG]" };
- private Throwable m_exception;
-
- public void failOnException() throws Throwable
- {
- if (m_exception != null)
- {
- throw m_exception;
- }
- }
-
- public void log(int level, String message)
- {
- System.out.println(LEVEL[level] + " - " + message);
- }
-
- public void log(int level, String message, Throwable exception)
- {
- System.out.println(LEVEL[level] + " - " + message + " - " + exception.getMessage());
- m_exception = exception;
- }
-
- public void log(ServiceReference sr, int level, String message)
- {
- System.out.println(LEVEL[level] + " - " + message);
- }
-
- public void log(ServiceReference sr, int level, String message, Throwable exception)
- {
- System.out.println(LEVEL[level] + " - " + message + " - " + exception.getMessage());
- m_exception = exception;
- }
- }
-
- private static class ServiceReferenceImpl implements ServiceReference
- {
- private final Properties m_properties;
-
- public ServiceReferenceImpl()
- {
- this(new Properties());
- }
-
- public ServiceReferenceImpl(Properties properties)
- {
- m_properties = properties;
- }
-
- public int compareTo(Object reference)
- {
- return 0;
- }
-
- public Bundle getBundle()
- {
- return null;
- }
-
- public Object getProperty(String key)
- {
- return m_properties.get(key);
- }
-
- public String[] getPropertyKeys()
- {
- return Collections.list(m_properties.keys()).toArray(new String[0]);
- }
-
- public Bundle[] getUsingBundles()
- {
- return null;
- }
-
- public boolean isAssignableTo(Bundle bundle, String className)
- {
- return false;
- }
-
- @Override
- public String toString()
- {
- return "Test ConfigAdmin @ 0x" + System.identityHashCode(this);
- }
- }
-
- private File m_tempDir;
- private LogServiceImpl m_logger;
-
- /** Go through a simple session, containing two empty configurations. */
- public void testBasicConfigurationSession() throws Throwable
- {
- AutoConfResourceProcessor p = createAutoConfRP();
-
- createNewSession(p);
- String config = "<MetaData xmlns:metatype='http://www.osgi.org/xmlns/metatype/v1.0.0'>\n" +
- " <OCD name='ocd' id='ocd'>\n" +
- " <AD id='name' type='STRING' cardinality='0' />\n" +
- " </OCD>\n" +
- " <Designate pid='simple' bundle='osgi-dp:location'>\n" +
- " <Object ocdref='ocd'>\n" +
- " <Attribute adref='name'>\n" +
- " <Value><![CDATA[test]]></Value>\n" +
- " </Attribute>\n" +
- " </Object>\n" +
- " </Designate>\n" +
- "</MetaData>\n";
- p.process("basic", new ByteArrayInputStream(config.getBytes()));
- p.prepare();
- p.commit();
- p.addConfigurationAdmin(new ServiceReferenceImpl(), new ConfigurationAdminImpl("simple"));
- p.postcommit();
- m_logger.failOnException();
- }
-
- /** Go through a simple session, containing two empty configurations. */
- public void testFilteredConfigurationSession() throws Throwable
- {
- AutoConfResourceProcessor p = createAutoConfRP();
-
- createNewSession(p);
- String config = "<MetaData xmlns:metatype='http://www.osgi.org/xmlns/metatype/v1.0.0' filter='(id=42)'>\n" +
- " <OCD name='ocd' id='ocd'>\n" +
- " <AD id='name' type='STRING' cardinality='0' />\n" +
- " </OCD>\n" +
- " <Designate pid='simple' bundle='osgi-dp:location'>\n" +
- " <Object ocdref='ocd'>\n" +
- " <Attribute adref='name'>\n" +
- " <Value><![CDATA[test]]></Value>\n" +
- " </Attribute>\n" +
- " </Object>\n" +
- " </Designate>\n" +
- "</MetaData>\n";
- p.process("basic", new ByteArrayInputStream(config.getBytes()));
- p.prepare();
- p.commit();
-
- Properties props = new Properties();
- props.put("id", Integer.valueOf(42));
-
- ConfigurationAdminImpl ca1 = new ConfigurationAdminImpl("simple");
- ConfigurationAdminImpl ca2 = new ConfigurationAdminImpl();
-
- p.addConfigurationAdmin(new ServiceReferenceImpl(props), ca1);
- p.addConfigurationAdmin(new ServiceReferenceImpl(), ca2);
- p.postcommit();
-
- m_logger.failOnException();
-
- assertEquals("test", ca1.m_configs.get("simple").getProperties().get("name"));
- assertTrue(ca2.m_configs.isEmpty());
- }
-
- /** Go through a simple session, containing two empty configurations. */
- public void testMissingMandatoryValueInConfig() throws Throwable
- {
- AutoConfResourceProcessor p = createAutoConfRP();
-
- createNewSession(p);
-
- String config = "<MetaData xmlns:metatype='http://www.osgi.org/xmlns/metatype/v1.1.0' filter='(id=42)'>\n" +
- " <OCD name='ocd' id='ocd'>\n" +
- " <AD id='name' type='Integer' />\n" +
- " </OCD>\n" +
- " <Designate pid='simple' bundle='osgi-dp:location'>\n" +
- " <Object ocdref='ocd'>\n" +
- " <Attribute adref='name'>\n" +
- " <Value><![CDATA[]]></Value>\n" +
- " </Attribute>\n" +
- " </Object>\n" +
- " </Designate>\n" +
- "</MetaData>\n";
-
- try
- {
- p.process("missing-value", new ByteArrayInputStream(config.getBytes()));
- fail("Expected ResourceProcessorException for missing value!");
- }
- catch (ResourceProcessorException e)
- {
- // Ok; expected...
- assertEquals("Unable to parse value for definition: adref=name", e.getMessage());
- }
- }
-
- /** Make sure the processor does not accept a 'null' session. */
- public void testNullSession() throws Exception
- {
- AutoConfResourceProcessor p = new AutoConfResourceProcessor();
- try
- {
- p.begin(null);
- fail("Should have gotten an exception when trying to begin with null session.");
- }
- catch (Exception e)
- {
- // expected
- }
- }
-
- /** Go through a simple session, containing two empty configurations. */
- public void testSimpleInstallAndUninstallSession() throws Throwable
- {
- AutoConfResourceProcessor p = createAutoConfRP();
-
- createNewSession(p);
-
- p.process("a", new ByteArrayInputStream("<MetaData />".getBytes()));
- p.prepare();
- p.commit();
- p.postcommit();
- m_logger.failOnException();
-
- createNewSession(p);
-
- p.dropAllResources();
- p.prepare();
- p.commit();
- p.postcommit();
- m_logger.failOnException();
- }
-
- /** Go through a simple session, containing two empty configurations. */
- public void testSimpleSession() throws Throwable
- {
- AutoConfResourceProcessor p = createAutoConfRP();
-
- createNewSession(p);
- p.process("a", new ByteArrayInputStream("<MetaData />".getBytes()));
- p.process("b", new ByteArrayInputStream("<MetaData />".getBytes()));
- p.prepare();
- p.commit();
- p.postcommit();
- m_logger.failOnException();
- }
-
- /** Tests that we can update an existing configuration and properly handling deleted & updated configurations. */
- public void testUpdateConfigurationSession() throws Throwable
- {
- AutoConfResourceProcessor p = createAutoConfRP();
-
- createNewSession(p);
-
- String config1 = "<MetaData xmlns:metatype='http://www.osgi.org/xmlns/metatype/v1.0.0'>" +
- "<OCD name='ocd1' id='ocd1'>" +
- " <AD id='nameA' type='STRING' cardinality='0' />" +
- "</OCD>" +
- "<OCD name='ocd2' id='ocd2'>" +
- " <AD id='nameB' type='STRING' cardinality='0' />" +
- "</OCD>" +
- "<Designate pid='pid2' bundle='osgi-dp:location2'>" +
- " <Object ocdref='ocd2'>" +
- " <Attribute adref='nameB'>" +
- " <Value><![CDATA[test2]]></Value>" +
- " </Attribute>" +
- " </Object>" +
- "</Designate>" +
- "<Designate pid='pid1' bundle='osgi-dp:location1'>" +
- " <Object ocdref='ocd1'>" +
- " <Attribute adref='nameA'>" +
- " <Value><![CDATA[test1]]></Value>" +
- " </Attribute>" +
- " </Object>" +
- "</Designate>" +
- "</MetaData>";
-
- ConfigurationAdminImpl ca = new ConfigurationAdminImpl("pid1", "pid2", "pid3");
-
- p.process("update", new ByteArrayInputStream(config1.getBytes()));
- p.prepare();
- p.commit();
- p.addConfigurationAdmin(new ServiceReferenceImpl(), ca);
- p.postcommit();
- m_logger.failOnException();
-
- assertEquals(2, ca.m_configs.size());
- assertTrue(ca.m_configs.containsKey("pid1"));
- assertFalse(ca.m_configs.get("pid1").m_deleted);
- assertEquals("test1", ca.m_configs.get("pid1").getProperties().get("nameA"));
-
- assertTrue(ca.m_configs.containsKey("pid2"));
- assertFalse(ca.m_configs.get("pid2").m_deleted);
- assertEquals("test2", ca.m_configs.get("pid2").getProperties().get("nameB"));
-
- String config2 = "<MetaData xmlns:metatype='http://www.osgi.org/xmlns/metatype/v1.0.0'>" +
- "<OCD name='ocd3' id='ocd3'>" +
- " <AD id='nameC' type='STRING' cardinality='0' />" +
- "</OCD>" +
- "<OCD name='ocd2' id='ocd2'>" +
- " <AD id='nameB' type='STRING' cardinality='0' />" +
- "</OCD>" +
- "<Designate pid='pid2' bundle='osgi-dp:location2'>" +
- " <Object ocdref='ocd2'>" +
- " <Attribute adref='nameB'>" +
- " <Value><![CDATA[test4]]></Value>" +
- " </Attribute>" +
- " </Object>" +
- "</Designate>" +
- "<Designate pid='pid3' bundle='osgi-dp:location3'>" +
- " <Object ocdref='ocd3'>" +
- " <Attribute adref='nameC'>" +
- " <Value><![CDATA[test3]]></Value>" +
- " </Attribute>" +
- " </Object>" +
- "</Designate>" +
- "</MetaData>";
-
- createNewSession(p);
-
- p.process("update", new ByteArrayInputStream(config2.getBytes()));
- p.prepare();
- p.commit();
- p.addConfigurationAdmin(new ServiceReferenceImpl(), ca);
- p.postcommit();
- m_logger.failOnException();
-
- assertEquals(3, ca.m_configs.size());
- assertTrue(ca.m_configs.containsKey("pid1"));
- assertTrue(ca.m_configs.get("pid1").m_deleted);
- assertEquals("test1", ca.m_configs.get("pid1").getProperties().get("nameA"));
-
- assertTrue(ca.m_configs.containsKey("pid2"));
- assertFalse(ca.m_configs.get("pid2").m_deleted);
- assertEquals("test4", ca.m_configs.get("pid2").getProperties().get("nameB"));
-
- assertTrue(ca.m_configs.containsKey("pid3"));
- assertFalse(ca.m_configs.get("pid3").m_deleted);
- assertEquals("test3", ca.m_configs.get("pid3").getProperties().get("nameC"));
- }
-
- @Override
- protected void setUp() throws IOException
- {
- m_tempDir = File.createTempFile("persistence", "dir");
- m_tempDir.delete();
- m_tempDir.mkdirs();
-
- m_logger = new LogServiceImpl();
- }
-
- @Override
- protected void tearDown() throws Exception
- {
- Utils.removeDirectoryWithContent(m_tempDir);
- }
-
- private AutoConfResourceProcessor createAutoConfRP()
- {
- AutoConfResourceProcessor p = new AutoConfResourceProcessor();
- Utils.configureObject(p, LogService.class, m_logger);
- Utils.configureObject(p, DependencyManager.class, createMockDM());
- Utils.configureObject(p, PersistencyManager.class, new PersistencyManager(m_tempDir));
- return p;
- }
-
- @SuppressWarnings("unused")
- private BundleContext createMockBundleContext()
- {
- return Utils.createMockObjectAdapter(BundleContext.class, new Object()
- {
- public Filter createFilter(String condition)
- {
- return Utils.createMockObjectAdapter(Filter.class, new Object()
- {
- public boolean match(ServiceReference ref)
- {
- Object id = ref.getProperty("id");
- if (id != null && id.equals(Integer.valueOf(42)))
- {
- return true;
- }
- return false;
- }
-
- public void remove(Component service)
- {
- }
- });
- }
- });
- }
-
- @SuppressWarnings("unused")
- private Component createMockComponent()
- {
- return Utils.createMockObjectAdapter(Component.class, new Object()
- {
- public DependencyManager getDependencyManager()
- {
- return new DependencyManager(createMockBundleContext());
- }
- });
- }
-
- private DependencyManager createMockDM()
- {
- return new DependencyManager(createMockBundleContext())
- {
- public void remove(Component service)
- {
- }
- };
- }
-
- private DeploymentSession createNewSession(AutoConfResourceProcessor p)
- {
- DeploymentSessionImpl s = new DeploymentSessionImpl();
- p.begin(s);
- Utils.configureObject(p, Component.class, createMockComponent());
- return s;
- }
-}
diff --git a/deploymentadmin/autoconf/src/test/java/org/apache/felix/deployment/rp/autoconf/DefaultNullObject.java b/deploymentadmin/autoconf/src/test/java/org/apache/felix/deployment/rp/autoconf/DefaultNullObject.java
deleted file mode 100644
index e6b827c3af..0000000000
--- a/deploymentadmin/autoconf/src/test/java/org/apache/felix/deployment/rp/autoconf/DefaultNullObject.java
+++ /dev/null
@@ -1,80 +0,0 @@
-/*
- * 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.deployment.rp.autoconf;
-
-import java.lang.reflect.InvocationHandler;
-import java.lang.reflect.Method;
-
-/**
- * Default null object implementation. Uses a dynamic proxy. Null objects are used
- * as placeholders for services that are not available.
- *
- * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
- */
-public class DefaultNullObject implements InvocationHandler
-{
- private static final Boolean DEFAULT_BOOLEAN = Boolean.FALSE;
- private static final Byte DEFAULT_BYTE = new Byte((byte) 0);
- private static final Short DEFAULT_SHORT = new Short((short) 0);
- private static final Integer DEFAULT_INT = new Integer(0);
- private static final Long DEFAULT_LONG = new Long(0);
- private static final Float DEFAULT_FLOAT = new Float(0.0f);
- private static final Double DEFAULT_DOUBLE = new Double(0.0);
-
- /**
- * Invokes a method on this null object. The method will return a default
- * value without doing anything.
- */
- public Object invoke(Object proxy, Method method, Object[] args) throws Throwable
- {
- Class returnType = method.getReturnType();
- if (returnType.equals(Boolean.class) || returnType.equals(Boolean.TYPE))
- {
- return DEFAULT_BOOLEAN;
- }
- else if (returnType.equals(Byte.class) || returnType.equals(Byte.TYPE))
- {
- return DEFAULT_BYTE;
- }
- else if (returnType.equals(Short.class) || returnType.equals(Short.TYPE))
- {
- return DEFAULT_SHORT;
- }
- else if (returnType.equals(Integer.class) || returnType.equals(Integer.TYPE))
- {
- return DEFAULT_INT;
- }
- else if (returnType.equals(Long.class) || returnType.equals(Long.TYPE))
- {
- return DEFAULT_LONG;
- }
- else if (returnType.equals(Float.class) || returnType.equals(Float.TYPE))
- {
- return DEFAULT_FLOAT;
- }
- else if (returnType.equals(Double.class) || returnType.equals(Double.TYPE))
- {
- return DEFAULT_DOUBLE;
- }
- else
- {
- return null;
- }
- }
-}
\ No newline at end of file
diff --git a/deploymentadmin/autoconf/src/test/java/org/apache/felix/deployment/rp/autoconf/PersistencyManagerTest.java b/deploymentadmin/autoconf/src/test/java/org/apache/felix/deployment/rp/autoconf/PersistencyManagerTest.java
deleted file mode 100644
index 07bfe30700..0000000000
--- a/deploymentadmin/autoconf/src/test/java/org/apache/felix/deployment/rp/autoconf/PersistencyManagerTest.java
+++ /dev/null
@@ -1,99 +0,0 @@
-/*
- * 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.deployment.rp.autoconf;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.Arrays;
-import java.util.Hashtable;
-
-import org.osgi.framework.Filter;
-import org.osgi.framework.FrameworkUtil;
-
-import junit.framework.TestCase;
-
-/**
- * Test cases for {@link PersistencyManager}.
- */
-public class PersistencyManagerTest extends TestCase
-{
- private File m_tempDir;
-
- public void testHandleNonExistingDirectory() throws Exception
- {
- PersistencyManager pm = new PersistencyManager(new File("/does/not/exist"));
- assertNotNull(pm);
-
- assertEquals(0, pm.getResourceNames().size());
- }
-
- public void testHandleEmptyExistingDirectory() throws Exception
- {
- PersistencyManager pm = new PersistencyManager(m_tempDir);
- assertNotNull(pm);
-
- assertEquals(0, pm.getResourceNames().size());
- }
-
- public void testLoadNonExistingResource() throws Exception
- {
- PersistencyManager pm = new PersistencyManager(m_tempDir);
- assertEquals(0, pm.load("doesNotExist").size());
- }
-
- public void testSaveResourceWithoutFilter() throws Exception
- {
- AutoConfResource res1 = new AutoConfResource("res1", "pid1", null, "osgi-dp:locationA", false, new Hashtable<String, Object>(), null);
- AutoConfResource res2 = new AutoConfResource("res2", "pid2", null, "osgi-dp:locationB", false, new Hashtable<String, Object>(), null);
-
- PersistencyManager pm = new PersistencyManager(m_tempDir);
- pm.store("test1", Arrays.asList(res1, res2));
-
- assertEquals(2, pm.load("test1").size());
- }
-
- public void testSaveResourceWithFilter() throws Exception
- {
- Filter f = FrameworkUtil.createFilter("(name=test)");
-
- AutoConfResource res1 = new AutoConfResource("res1", "pid1", null, "osgi-dp:locationA", false, new Hashtable<String, Object>(), f);
- AutoConfResource res2 = new AutoConfResource("res2", "pid2", null, "osgi-dp:locationB", false, new Hashtable<String, Object>(), null);
-
- PersistencyManager pm = new PersistencyManager(m_tempDir);
- pm.store("test1", Arrays.asList(res1, res2));
-
- assertEquals(2, pm.load("test1").size());
- }
-
- @Override
- protected void setUp() throws IOException
- {
- m_tempDir = File.createTempFile("persistence", "dir");
- m_tempDir.delete();
- m_tempDir.mkdirs();
- }
-
- @Override
- protected void tearDown() throws Exception
- {
- Utils.removeDirectoryWithContent(m_tempDir);
- }
-
-}
diff --git a/deploymentadmin/autoconf/src/test/java/org/apache/felix/deployment/rp/autoconf/Utils.java b/deploymentadmin/autoconf/src/test/java/org/apache/felix/deployment/rp/autoconf/Utils.java
deleted file mode 100644
index a13d5e79c3..0000000000
--- a/deploymentadmin/autoconf/src/test/java/org/apache/felix/deployment/rp/autoconf/Utils.java
+++ /dev/null
@@ -1,148 +0,0 @@
-/*
- * 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.deployment.rp.autoconf;
-
-import java.io.File;
-import java.lang.reflect.AccessibleObject;
-import java.lang.reflect.Field;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.lang.reflect.Proxy;
-
-/**
- * Utility class that injects dependencies. Can be used to unit test service implementations.
- */
-public class Utils
-{
- /**
- * Configures an object to use a null object for the specified service interface.
- *
- * @param object the object
- * @param iface the service interface
- */
- public static void configureObject(Object object, Class iface)
- {
- configureObject(object, iface, createNullObject(iface));
- }
-
- /**
- * Creates a null object for a service interface.
- *
- * @param iface the service interface
- * @return a null object
- */
- public static <T> T createNullObject(Class<T> iface)
- {
- return (T) Proxy.newProxyInstance(iface.getClassLoader(), new Class[] { iface }, new DefaultNullObject());
- }
-
- /**
- * Wraps the given handler in an adapter that will try to pass on received invocations to the hander if that has
- * an applicable methods else it defaults to a NullObject.
- *
- * @param iface the service interface
- * @param handler the handler to pass invocations to.
- * @return an adapter that will try to pass on received invocations to the given handler
- */
- public static <T> T createMockObjectAdapter(Class<T> iface, final Object handler)
- {
- return (T) Proxy.newProxyInstance(iface.getClassLoader(), new Class[] { iface }, new DefaultNullObject()
- {
- public Object invoke(Object proxy, Method method, Object[] args) throws Throwable
- {
- try
- {
- Method bridge = handler.getClass().getMethod(method.getName(), method.getParameterTypes());
- bridge.setAccessible(true);
- return bridge.invoke(handler, args);
- }
- catch (NoSuchMethodException ex)
- {
- return super.invoke(proxy, method, args);
- }
- catch (InvocationTargetException ex)
- {
- throw ex.getCause();
- }
- }
- });
- }
-
- /**
- * Configures an object to use a specific implementation for the specified service interface.
- *
- * @param object the object
- * @param iface the service interface
- * @param instance the implementation
- */
- public static void configureObject(Object object, Class iface, Object instance)
- {
- Class serviceClazz = object.getClass();
-
- while (serviceClazz != null)
- {
- Field[] fields = serviceClazz.getDeclaredFields();
- AccessibleObject.setAccessible(fields, true);
- for (int j = 0; j < fields.length; j++)
- {
- if (fields[j].getType().equals(iface))
- {
- try
- {
- // synchronized makes sure the field is actually written to immediately
- synchronized (new Object())
- {
- fields[j].set(object, instance);
- }
- }
- catch (Exception e)
- {
- throw new IllegalStateException("Could not set field " + fields[j].getName() + " on " + object);
- }
- }
- }
- serviceClazz = serviceClazz.getSuperclass();
- }
- }
-
- /**
- * Remove the given directory and all it's files and subdirectories
- *
- * @param directory the name of the directory to remove
- */
- public static void removeDirectoryWithContent(File directory)
- {
- if ((directory == null) || !directory.exists())
- {
- return;
- }
- File[] filesAndSubDirs = directory.listFiles();
- for (int i = 0; i < filesAndSubDirs.length; i++)
- {
- File file = filesAndSubDirs[i];
- if (file.isDirectory())
- {
- removeDirectoryWithContent(file);
- }
- // else just remove the file
- file.delete();
- }
- directory.delete();
- }
-}
diff --git a/deploymentadmin/deploymentadmin/DEPENDENCIES b/deploymentadmin/deploymentadmin/DEPENDENCIES
deleted file mode 100644
index 06bd39ade6..0000000000
--- a/deploymentadmin/deploymentadmin/DEPENDENCIES
+++ /dev/null
@@ -1,24 +0,0 @@
-Apache Felix Deployment Admin
-Copyright 2011-2016 The Apache Software Foundation
-
-This software was developed at the Apache Software Foundation
-(http://www.apache.org) and may have dependencies on other
-Apache software licensed under Apache License 2.0.
-
-I. Included Third-Party Software
-
-This product includes software developed at
-The OSGi Alliance (http://www.osgi.org/).
-Copyright (c) OSGi Alliance (2000, 2009).
-Licensed under the Apache License 2.0.
-
-II. Used Third-Party Software
-
-This product uses software developed at
-The OSGi Alliance (http://www.osgi.org/).
-Copyright (c) OSGi Alliance (2000, 2009).
-Licensed under the Apache License 2.0.
-
-III. Overall License Summary
-
-- Apache License 2.0
diff --git a/deploymentadmin/deploymentadmin/LICENSE b/deploymentadmin/deploymentadmin/LICENSE
deleted file mode 100644
index d645695673..0000000000
--- a/deploymentadmin/deploymentadmin/LICENSE
+++ /dev/null
@@ -1,202 +0,0 @@
-
- Apache License
- Version 2.0, January 2004
- http://www.apache.org/licenses/
-
- TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
-
- 1. Definitions.
-
- "License" shall mean the terms and conditions for use, reproduction,
- and distribution as defined by Sections 1 through 9 of this document.
-
- "Licensor" shall mean the copyright owner or entity authorized by
- the copyright owner that is granting the License.
-
- "Legal Entity" shall mean the union of the acting entity and all
- other entities that control, are controlled by, or are under common
- control with that entity. For the purposes of this definition,
- "control" means (i) the power, direct or indirect, to cause the
- direction or management of such entity, whether by contract or
- otherwise, or (ii) ownership of fifty percent (50%) or more of the
- outstanding shares, or (iii) beneficial ownership of such entity.
-
- "You" (or "Your") shall mean an individual or Legal Entity
- exercising permissions granted by this License.
-
- "Source" form shall mean the preferred form for making modifications,
- including but not limited to software source code, documentation
- source, and configuration files.
-
- "Object" form shall mean any form resulting from mechanical
- transformation or translation of a Source form, including but
- not limited to compiled object code, generated documentation,
- and conversions to other media types.
-
- "Work" shall mean the work of authorship, whether in Source or
- Object form, made available under the License, as indicated by a
- copyright notice that is included in or attached to the work
- (an example is provided in the Appendix below).
-
- "Derivative Works" shall mean any work, whether in Source or Object
- form, that is based on (or derived from) the Work and for which the
- editorial revisions, annotations, elaborations, or other modifications
- represent, as a whole, an original work of authorship. For the purposes
- of this License, Derivative Works shall not include works that remain
- separable from, or merely link (or bind by name) to the interfaces of,
- the Work and Derivative Works thereof.
-
- "Contribution" shall mean any work of authorship, including
- the original version of the Work and any modifications or additions
- to that Work or Derivative Works thereof, that is intentionally
- submitted to Licensor for inclusion in the Work by the copyright owner
- or by an individual or Legal Entity authorized to submit on behalf of
- the copyright owner. For the purposes of this definition, "submitted"
- means any form of electronic, verbal, or written communication sent
- to the Licensor or its representatives, including but not limited to
- communication on electronic mailing lists, source code control systems,
- and issue tracking systems that are managed by, or on behalf of, the
- Licensor for the purpose of discussing and improving the Work, but
- excluding communication that is conspicuously marked or otherwise
- designated in writing by the copyright owner as "Not a Contribution."
-
- "Contributor" shall mean Licensor and any individual or Legal Entity
- on behalf of whom a Contribution has been received by Licensor and
- subsequently incorporated within the Work.
-
- 2. Grant of Copyright License. Subject to the terms and conditions of
- this License, each Contributor hereby grants to You a perpetual,
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
- copyright license to reproduce, prepare Derivative Works of,
- publicly display, publicly perform, sublicense, and distribute the
- Work and such Derivative Works in Source or Object form.
-
- 3. Grant of Patent License. Subject to the terms and conditions of
- this License, each Contributor hereby grants to You a perpetual,
- worldwide, non-exclusive, no-charge, royalty-free, irrevocable
- (except as stated in this section) patent license to make, have made,
- use, offer to sell, sell, import, and otherwise transfer the Work,
- where such license applies only to those patent claims licensable
- by such Contributor that are necessarily infringed by their
- Contribution(s) alone or by combination of their Contribution(s)
- with the Work to which such Contribution(s) was submitted. If You
- institute patent litigation against any entity (including a
- cross-claim or counterclaim in a lawsuit) alleging that the Work
- or a Contribution incorporated within the Work constitutes direct
- or contributory patent infringement, then any patent licenses
- granted to You under this License for that Work shall terminate
- as of the date such litigation is filed.
-
- 4. Redistribution. You may reproduce and distribute copies of the
- Work or Derivative Works thereof in any medium, with or without
- modifications, and in Source or Object form, provided that You
- meet the following conditions:
-
- (a) You must give any other recipients of the Work or
- Derivative Works a copy of this License; and
-
- (b) You must cause any modified files to carry prominent notices
- stating that You changed the files; and
-
- (c) You must retain, in the Source form of any Derivative Works
- that You distribute, all copyright, patent, trademark, and
- attribution notices from the Source form of the Work,
- excluding those notices that do not pertain to any part of
- the Derivative Works; and
-
- (d) If the Work includes a "NOTICE" text file as part of its
- distribution, then any Derivative Works that You distribute must
- include a readable copy of the attribution notices contained
- within such NOTICE file, excluding those notices that do not
- pertain to any part of the Derivative Works, in at least one
- of the following places: within a NOTICE text file distributed
- as part of the Derivative Works; within the Source form or
- documentation, if provided along with the Derivative Works; or,
- within a display generated by the Derivative Works, if and
- wherever such third-party notices normally appear. The contents
- of the NOTICE file are for informational purposes only and
- do not modify the License. You may add Your own attribution
- notices within Derivative Works that You distribute, alongside
- or as an addendum to the NOTICE text from the Work, provided
- that such additional attribution notices cannot be construed
- as modifying the License.
-
- You may add Your own copyright statement to Your modifications and
- may provide additional or different license terms and conditions
- for use, reproduction, or distribution of Your modifications, or
- for any such Derivative Works as a whole, provided Your use,
- reproduction, and distribution of the Work otherwise complies with
- the conditions stated in this License.
-
- 5. Submission of Contributions. Unless You explicitly state otherwise,
- any Contribution intentionally submitted for inclusion in the Work
- by You to the Licensor shall be under the terms and conditions of
- this License, without any additional terms or conditions.
- Notwithstanding the above, nothing herein shall supersede or modify
- the terms of any separate license agreement you may have executed
- with Licensor regarding such Contributions.
-
- 6. Trademarks. This License does not grant permission to use the trade
- names, trademarks, service marks, or product names of the Licensor,
- except as required for reasonable and customary use in describing the
- origin of the Work and reproducing the content of the NOTICE file.
-
- 7. Disclaimer of Warranty. Unless required by applicable law or
- agreed to in writing, Licensor provides the Work (and each
- Contributor provides its Contributions) on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
- implied, including, without limitation, any warranties or conditions
- of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
- PARTICULAR PURPOSE. You are solely responsible for determining the
- appropriateness of using or redistributing the Work and assume any
- risks associated with Your exercise of permissions under this License.
-
- 8. Limitation of Liability. In no event and under no legal theory,
- whether in tort (including negligence), contract, or otherwise,
- unless required by applicable law (such as deliberate and grossly
- negligent acts) or agreed to in writing, shall any Contributor be
- liable to You for damages, including any direct, indirect, special,
- incidental, or consequential damages of any character arising as a
- result of this License or out of the use or inability to use the
- Work (including but not limited to damages for loss of goodwill,
- work stoppage, computer failure or malfunction, or any and all
- other commercial damages or losses), even if such Contributor
- has been advised of the possibility of such damages.
-
- 9. Accepting Warranty or Additional Liability. While redistributing
- the Work or Derivative Works thereof, You may choose to offer,
- and charge a fee for, acceptance of support, warranty, indemnity,
- or other liability obligations and/or rights consistent with this
- License. However, in accepting such obligations, You may act only
- on Your own behalf and on Your sole responsibility, not on behalf
- of any other Contributor, and only if You agree to indemnify,
- defend, and hold each Contributor harmless for any liability
- incurred by, or claims asserted against, such Contributor by reason
- of your accepting any such warranty or additional liability.
-
- END OF TERMS AND CONDITIONS
-
- APPENDIX: How to apply the Apache License to your work.
-
- To apply the Apache License to your work, attach the following
- boilerplate notice, with the fields enclosed by brackets "[]"
- replaced with your own identifying information. (Don't include
- the brackets!) The text should be enclosed in the appropriate
- comment syntax for the file format. We also recommend that a
- file or class name and description of purpose be included on the
- same "printed page" as the copyright notice for easier
- identification within third-party archives.
-
- Copyright [yyyy] [name of copyright owner]
-
- 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.
diff --git a/deploymentadmin/deploymentadmin/NOTICE b/deploymentadmin/deploymentadmin/NOTICE
deleted file mode 100644
index 0b50d4ea6a..0000000000
--- a/deploymentadmin/deploymentadmin/NOTICE
+++ /dev/null
@@ -1,11 +0,0 @@
-Apache Felix Deployment Admin
-Copyright 2011-2016 The Apache Software Foundation
-
-This product includes software developed at
-The Apache Software Foundation (http://www.apache.org/).
-Licensed under the Apache License 2.0.
-
-This product includes software developed at
-The OSGi Alliance (http://www.osgi.org/).
-Copyright (c) OSGi Alliance (2000, 2009).
-Licensed under the Apache License 2.0.
diff --git a/deploymentadmin/deploymentadmin/changelog.txt b/deploymentadmin/deploymentadmin/changelog.txt
deleted file mode 100644
index 72f74ffc3b..0000000000
--- a/deploymentadmin/deploymentadmin/changelog.txt
+++ /dev/null
@@ -1,39 +0,0 @@
-Release 0.9.8
--------------
-
-FELIX-4912 Upgrade autoconf to Dependency Manager 4
-FELIX-4719 SnapshotCommand never properly restores archived data-areas
-FELIX-4718 SnapshotCommand creates invalid snapshot archives
-FELIX-4491 ResourceProcessors should be optional for processed resources
-FELIX-4486 Possible thread leakage in DA
-FELIX-4485 Incorrect version of exported API
-FELIX-4484 uninstall incorrectly marks a DP as stale when its uninstallation fails
-FELIX-518 Wrong processing order of Localization-, Bundle and Processed-Resources
-FELIX-3780 Allow using configuration admin in addition to system properties
-
-Release 0.9.6
--------------
-
-FELIX-1835 Installing of deployment package fails if has it's bundles in subdirectory
-FELIX-4409 Improve exception messages to be more explicit and helpful
-FELIX-4410 Exceptions during rollback are not always properly handled
-FELIX-4463 DA does not consistently handle non-unique resources
-FELIX-4466 Deployment Admin does not always fire events
-
-Release 0.9.4
--------------
-
-FELIX-3336 Exceptions related to the pipe used in deployment admin
-FELIX-3272 Add property to allow foreign resource processors
-FELIX-3515 DeploymentAdmin triggers IOException on install
-FELIX-1307 Log situation in DeploymentAdmin impl very unclear
-FELIX-3270 Deployment admin incorrectly takes snapshots of bundle data areas
-FELIX-3526 DeploymentAdmin fails on windows due to unclosed iostreams
-FELIX-1828 Mistake in code of the class UpdateCommand
-FELIX-1829 Method AbstractDeploymentPackage.getBundle(...) throws NullPointerException
-FELIX-3678 org.apache.felix.deploymentadmin imports wrong version of org.osgi.service.deploymentadmin
-FELIX-3139 Implement uninstall() for deployment admin.
-
-
-Initial Release 0.9.0
----------------------
diff --git a/deploymentadmin/deploymentadmin/pom.xml b/deploymentadmin/deploymentadmin/pom.xml
deleted file mode 100644
index 7ed4383491..0000000000
--- a/deploymentadmin/deploymentadmin/pom.xml
+++ /dev/null
@@ -1,96 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!-- 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. -->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
- <modelVersion>4.0.0</modelVersion>
- <parent>
- <groupId>org.apache.felix</groupId>
- <artifactId>felix-parent</artifactId>
- <version>3</version>
- <relativePath>../../pom/pom.xml</relativePath>
- </parent>
- <properties>
- <osgi.version>4.2.0</osgi.version>
- </properties>
- <name>Apache Felix Deployment Admin</name>
- <groupId>org.apache.felix</groupId>
- <artifactId>org.apache.felix.deploymentadmin</artifactId>
- <version>0.9.12-SNAPSHOT</version>
- <packaging>bundle</packaging>
- <dependencies>
- <dependency>
- <groupId>org.osgi</groupId>
- <artifactId>org.osgi.core</artifactId>
- <version>${osgi.version}</version>
- </dependency>
- <dependency>
- <groupId>org.osgi</groupId>
- <artifactId>org.osgi.compendium</artifactId>
- <version>${osgi.version}</version>
- </dependency>
- <dependency>
- <groupId>org.apache.felix</groupId>
- <artifactId>org.apache.felix.dependencymanager</artifactId>
- <version>4.1.1</version>
- </dependency>
- <dependency>
- <groupId>org.mockito</groupId>
- <artifactId>mockito-all</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <scope>test</scope>
- </dependency>
- </dependencies>
- <build>
- <resources>
- <resource>
- <directory>.</directory>
- <targetPath>META-INF</targetPath>
- <includes>
- <include>LICENSE*</include>
- <include>NOTICE*</include>
- <include>DEPENDENCIES*</include>
- <include>*.txt</include>
- </includes>
- </resource>
- </resources>
- <plugins>
- <plugin>
- <groupId>org.apache.felix</groupId>
- <artifactId>maven-bundle-plugin</artifactId>
- <version>2.3.4</version>
- <extensions>true</extensions>
- <configuration>
- <instructions>
- <Bundle-SymbolicName>org.apache.felix.deploymentadmin</Bundle-SymbolicName>
- <Bundle-Activator>org.apache.felix.deploymentadmin.Activator</Bundle-Activator>
- <Bundle-Name>Apache Felix Deployment Admin</Bundle-Name>
- <Bundle-Description>A bundle that implements the Deployment Admin.</Bundle-Description>
- <Bundle-Vendor>The Apache Software Foundation</Bundle-Vendor>
- <Private-Package>org.apache.felix.deploymentadmin.*</Private-Package>
- <Export-Package>org.osgi.service.deploymentadmin;version="1.1",
- org.osgi.service.deploymentadmin.spi;version="1.0"</Export-Package>
- <Import-Package>org.osgi.service.deploymentadmin;version="[1.1,2.0)",
- org.osgi.service.deploymentadmin.spi;version="[1.0,2.0)",*</Import-Package>
- </instructions>
- </configuration>
- </plugin>
- </plugins>
- </build>
- <scm>
- <connection>scm:git:https://github.com/apache/felix-dev.git</connection>
- <developerConnection>scm:git:https://github.com/apache/felix-dev.git</developerConnection>
- <url>https://gitbox.apache.org/repos/asf?p=felix-dev.git</url>
- </scm>
-</project>
diff --git a/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/AbstractDeploymentPackage.java b/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/AbstractDeploymentPackage.java
deleted file mode 100644
index 512381b93a..0000000000
--- a/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/AbstractDeploymentPackage.java
+++ /dev/null
@@ -1,516 +0,0 @@
-/*
- * 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.IOException;
-import java.io.InputStream;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Locale;
-import java.util.Map;
-import java.util.jar.Manifest;
-
-import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.InvalidSyntaxException;
-import org.osgi.framework.ServiceReference;
-import org.osgi.framework.Version;
-import org.osgi.service.deploymentadmin.BundleInfo;
-import org.osgi.service.deploymentadmin.DeploymentException;
-import org.osgi.service.deploymentadmin.DeploymentPackage;
-import org.osgi.service.deploymentadmin.spi.ResourceProcessor;
-import org.osgi.service.log.LogService;
-
-/**
- * Base class for various types of deployment packages. Indifferent in regard to
- * how the deployment package data is obtained, this should be handled by
- * extending classes.
- */
-public abstract class AbstractDeploymentPackage implements DeploymentPackage, Constants {
- /**
- * Represents an empty deployment package.
- */
- private static final class EmptyDeploymentPackage extends AbstractDeploymentPackage {
- private static final String[] STRINGS = new String[] {};
- private static final ResourceInfoImpl[] RESOURCE_INFO_IMPLS = new ResourceInfoImpl[] {};
- private static final BundleInfoImpl[] BUNDLE_INFO_IMPLS = new BundleInfoImpl[] {};
-
- public Bundle getBundle(String symbolicName) {
- return null;
- }
-
- public BundleInfoImpl[] getBundleInfoImpls() {
- return BUNDLE_INFO_IMPLS;
- }
-
- public BundleInfo[] getBundleInfos() {
- return BUNDLE_INFO_IMPLS;
- }
-
- public InputStream getBundleStream(String symbolicName) throws IOException {
- return null;
- }
-
- public InputStream getCurrentEntryStream() {
- throw new UnsupportedOperationException();
- }
-
- public String getDisplayName() {
- return "";
- }
-
- public String getHeader(String header) {
- if (DEPLOYMENTPACKAGE_SYMBOLICMAME.equals(header)) {
- return "";
- }
- else if (DEPLOYMENTPACKAGE_VERSION.equals(header)) {
- return Version.emptyVersion.toString();
- }
- else {
- return null;
- }
- }
-
- public URL getIcon() {
- return null;
- }
-
- public String getName() {
- return "";
- }
-
- public AbstractInfo getNextEntry() throws IOException {
- throw new UnsupportedOperationException();
- }
-
- public BundleInfoImpl[] getOrderedBundleInfos() {
- return BUNDLE_INFO_IMPLS;
- }
-
- public ResourceInfoImpl[] getOrderedResourceInfos() {
- return RESOURCE_INFO_IMPLS;
- }
-
- public String getResourceHeader(String resource, String header) {
- return null;
- }
-
- public ResourceInfoImpl[] getResourceInfos() {
- return RESOURCE_INFO_IMPLS;
- }
-
- public ServiceReference getResourceProcessor(String resource) {
- return null;
- }
-
- public String[] getResources() {
- return STRINGS;
- }
-
- public Version getVersion() {
- return Version.emptyVersion;
- }
-
- public boolean isStale() {
- return true;
- }
-
- public void uninstall() throws DeploymentException {
- throw new IllegalStateException("Can not uninstall stale DeploymentPackage");
- }
-
- public boolean uninstallForced() throws DeploymentException {
- throw new IllegalStateException("Can not uninstall stale DeploymentPackage");
- }
- }
-
- protected static final AbstractDeploymentPackage EMPTY_PACKAGE = new EmptyDeploymentPackage();
-
- private final BundleContext m_bundleContext;
- private final DeploymentAdminImpl m_deploymentAdmin;
- private final DeploymentPackageManifest m_manifest;
- private final Map m_nameToBundleInfo = new HashMap();
- private final Map m_pathToEntry = new HashMap();
- private final BundleInfoImpl[] m_bundleInfos;
- private final ResourceInfoImpl[] m_resourceInfos;
- private final String[] m_resourcePaths;
- private final boolean m_isFixPackage;
- private boolean m_isStale;
-
- /**
- * Creates an instance of this class.
- *
- * @param manifest The manifest of the deployment package.
- * @param bundleContext The bundle context.
- * @throws DeploymentException Thrown if the specified manifest does not
- * describe a valid deployment package.
- */
- public AbstractDeploymentPackage(Manifest manifest, BundleContext bundleContext, DeploymentAdminImpl deploymentAdmin) throws DeploymentException {
- m_manifest = new DeploymentPackageManifest(manifest);
- m_isFixPackage = m_manifest.getFixPackage() != null;
- m_bundleContext = bundleContext;
- m_deploymentAdmin = deploymentAdmin;
-
- List bundleInfos = m_manifest.getBundleInfos();
- m_bundleInfos = (BundleInfoImpl[]) bundleInfos.toArray(new BundleInfoImpl[bundleInfos.size()]);
-
- for (int i = 0; i < m_bundleInfos.length; i++) {
- String bsn = m_bundleInfos[i].getSymbolicName();
- if (m_nameToBundleInfo.put(bsn, m_bundleInfos[i]) != null) {
- // FELIX-4463: make sure that the DP is consistent...
- throw new DeploymentException(CODE_OTHER_ERROR, "Duplicate bundle present in deployment package: " + bsn);
- }
-
- String path = m_bundleInfos[i].getPath();
- if (m_pathToEntry.put(path, m_bundleInfos[i]) != null) {
- // FELIX-4463: make sure that the DP is consistent...
- throw new DeploymentException(CODE_OTHER_ERROR, "Non-unique path present in deployment package: " + path);
- }
- }
-
- List resourceInfos = m_manifest.getResourceInfos();
- m_resourceInfos = (ResourceInfoImpl[]) resourceInfos.toArray(new ResourceInfoImpl[resourceInfos.size()]);
-
- for (int i = 0; i < m_resourceInfos.length; i++) {
- String path = m_resourceInfos[i].getPath();
- if (m_pathToEntry.put(path, m_resourceInfos[i]) != null) {
- // FELIX-4463: make sure that the DP is consistent...
- throw new DeploymentException(CODE_OTHER_ERROR, "Non-unique path present in deployment package: " + path);
- }
- }
- m_resourcePaths = (String[]) m_pathToEntry.keySet().toArray(new String[m_pathToEntry.size()]);
- }
-
- /* Constructor only for use by the emptyPackage static variable */
- private AbstractDeploymentPackage() {
- m_bundleContext = null;
- m_manifest = null;
- m_bundleInfos = null;
- m_resourceInfos = null;
- m_resourcePaths = null;
- m_isFixPackage = false;
- m_deploymentAdmin = null;
- }
-
- public Bundle getBundle(String symbolicName) {
- if (isStale()) {
- throw new IllegalStateException("Can not get bundle from stale deployment package.");
- }
-
- BundleInfo bundleInfo = (BundleInfo) m_nameToBundleInfo.get(symbolicName);
- if (bundleInfo != null) {
- Version version = bundleInfo.getVersion();
-
- Bundle[] bundles = m_bundleContext.getBundles();
- for (int i = 0; i < bundles.length; i++) {
- if (symbolicName.equals(bundles[i].getSymbolicName()) && version.equals(bundles[i].getVersion())) {
- return bundles[i];
- }
- }
- }
- return null;
- }
-
- /**
- * Determines the info about a bundle resource based on the bundle symbolic
- * name.
- *
- * @param symbolicName String containing a bundle symbolic name
- * @return <code>BundleInfoImpl</code> for the bundle identified by the
- * specified symbolic name or null if the symbolic name is unknown
- */
- public BundleInfoImpl getBundleInfoByName(String symbolicName) {
- return (BundleInfoImpl) m_nameToBundleInfo.get(symbolicName);
- }
-
- /**
- * Determines the info about a bundle based on it's path/resource-id.
- *
- * @param path String containing a bundle path
- * @return <code>BundleInfoImpl</code> for the bundle resource identified by
- * the specified path or null if the path is unknown or does not
- * describe a bundle resource
- */
- public BundleInfoImpl getBundleInfoByPath(String path) {
- AbstractInfo info = (AbstractInfo) m_pathToEntry.get(path);
- if (info instanceof BundleInfoImpl) {
- return (BundleInfoImpl) info;
- }
- return null;
- }
-
- /**
- * Returns the bundles of this deployment package as an array of
- * <code>BundleInfoImpl</code> objects.
- *
- * @return Array containing <code>BundleInfoImpl</code> objects for each
- * bundle this deployment package.
- */
- public BundleInfoImpl[] getBundleInfoImpls() {
- return (BundleInfoImpl[]) m_bundleInfos.clone();
- }
-
- public BundleInfo[] getBundleInfos() {
- return (BundleInfo[]) m_bundleInfos.clone();
- }
-
- /**
- * Determines the data stream of a bundle resource based on the bundle
- * symbolic name
- *
- * @param symbolicName Bundle symbolic name
- * @return Stream to the bundle identified by the specified symbolic name or
- * null if no such bundle exists in this deployment package.
- * @throws IOException If the bundle can not be properly offered as an
- * inputstream
- */
- public abstract InputStream getBundleStream(String symbolicName) throws IOException;
-
- /**
- * Determines the data stream to the current entry of this deployment
- * package, use this together with the <code>getNextEntry</code> method.
- *
- * @return Stream to the current resource in the deployment package (as
- * determined by the order in which the deployment package was
- * received originally) or null if there is no entry
- */
- public abstract InputStream getCurrentEntryStream();
-
- public String getDisplayName() {
- return getHeader(DEPLOYMENTPACKAGE_NAME);
- }
-
- public String getHeader(String header) {
- return m_manifest.getHeader(header);
- }
-
- public URL getIcon() {
- String icon = getHeader(DEPLOYMENTPACKAGE_ICON);
- if (icon == null) {
- return null;
- }
- else {
- try {
- // TODO spec states this must be a local resource, but we don't make sure of that yet
- return new URL(icon);
- }
- catch (MalformedURLException e) {
- return null;
- }
- }
- }
-
- public String getName() {
- return m_manifest.getSymbolicName();
- }
-
- /**
- * Determines the next resource entry in this deployment package based on
- * the order in which the resources appeared when the package was originally
- * received.
- *
- * @return <code>AbstractInfo</code> describing the next resource entry (as
- * determined by the order in which the deployment package was
- * received originally) or null if there is no next entry
- * @throws IOException if the next entry can not be properly determined
- */
- public abstract AbstractInfo getNextEntry() throws IOException;
-
- /**
- * Determines the bundles of this deployment package in the order in which
- * they were originally received.
- *
- * @return Array containing <code>BundleInfoImpl</code> objects of the
- * bundles in this deployment package, ordered in the way they
- * appeared when the deployment package was first received.
- */
- public abstract BundleInfoImpl[] getOrderedBundleInfos();
-
- /**
- * Determines the resources of this deployment package in the order in which
- * they were originally received.
- *
- * @return Array containing <code>ResourceInfoImpl</code> objects of all
- * processed resources in this deployment package, ordered in the
- * way they appeared when the deployment package was first received
- */
- public abstract ResourceInfoImpl[] getOrderedResourceInfos();
-
- public String getResourceHeader(String resource, String header) {
- AbstractInfo info = (AbstractInfo) m_pathToEntry.get(resource);
- if (info != null) {
- return info.getHeader(header);
- }
- return null;
- }
-
- /**
- * Determines the info about a processed resource based on it's
- * path/resource-id.
- *
- * @param path String containing a (processed) resource path
- * @return <code>ResourceInfoImpl</code> for the resource identified by the
- * specified path or null if the path is unknown or does not
- * describe a processed resource
- */
- public ResourceInfoImpl getResourceInfoByPath(String path) {
- AbstractInfo info = (AbstractInfo) m_pathToEntry.get(path);
- if (info instanceof ResourceInfoImpl) {
- return (ResourceInfoImpl) info;
- }
- return null;
- }
-
- /**
- * Returns the processed resources of this deployment package as an array of
- * <code>ResourceInfoImpl</code> objects.
- *
- * @return Array containing <code>ResourceInfoImpl</code> objects for each
- * processed resource of this deployment package.
- */
- public ResourceInfoImpl[] getResourceInfos() {
- return (ResourceInfoImpl[]) m_resourceInfos.clone();
- }
-
- public ServiceReference getResourceProcessor(String resource) {
- if (isStale()) {
- throw new IllegalStateException("Can not get bundle from stale deployment package.");
- }
- AbstractInfo info = (AbstractInfo) m_pathToEntry.get(resource);
- if (info instanceof ResourceInfoImpl) {
- String processor = ((ResourceInfoImpl) info).getResourceProcessor();
- if (processor != null) {
- try {
- ServiceReference[] services = m_bundleContext.getServiceReferences(ResourceProcessor.class.getName(), "(" + SERVICE_PID + "=" + processor + ")");
- if (services != null && services.length > 0) {
- return services[0];
- }
- else {
- return null;
- }
- }
- catch (InvalidSyntaxException e) {
- m_deploymentAdmin.getLog().log(LogService.LOG_WARNING, "Invalid resource processor name: " + processor, e);
- return null;
- }
- }
- }
- return null;
- }
-
- public String[] getResources() {
- return (String[]) m_resourcePaths.clone();
- }
-
- public Version getVersion() {
- return m_manifest.getVersion();
- }
-
- /**
- * If this deployment package is a fix package this method determines the
- * version range this deployment package can be applied to.
- *
- * @return <code>VersionRange</code> the fix package can be applied to or
- * <code>null</code> if it is not a fix package.
- */
- public VersionRange getVersionRange() {
- return m_manifest.getFixPackage();
- }
-
- /**
- * Determines whether this deployment package is a fix package.
- *
- * @return True if this deployment package is a fix package, false
- * otherwise.
- */
- public boolean isFixPackage() {
- return m_isFixPackage;
- }
-
- /**
- * @return <code>true</code> if this package is actually an empty package
- * used for installing new deployment packages, <code>false</code>
- * otherwise.
- */
- public boolean isNew() {
- return this == EMPTY_PACKAGE;
- }
-
- public boolean isStale() {
- return m_isStale;
- }
-
- public void setStale(boolean isStale) {
- m_isStale = isStale;
- }
-
- public void uninstall() throws DeploymentException {
- if (isStale()) {
- throw new IllegalStateException("Deployment package is stale, cannot uninstall!");
- }
-
- m_deploymentAdmin.uninstallDeploymentPackage(this, false /* force */);
- // FELIX-4484: only mark a DP as stale when it is *successfully* uninstalled...
- setStale(true);
- }
-
- public boolean uninstallForced() throws DeploymentException {
- if (isStale()) {
- throw new IllegalStateException("Deployment package is stale, cannot force uninstallation!");
- }
-
- try {
- m_deploymentAdmin.uninstallDeploymentPackage(this, true /* force */);
- }
- finally {
- // FELIX-4484: this is a best-effort method, if it fails, we cannot do anything about it anymore...
- setStale(true);
- }
- return true;
- }
-
- /**
- * Determines the info about either a bundle or processed resource based on
- * it's path/resource-id.
- *
- * @param path String containing a resource path (either bundle or processed
- * resource)
- * @return <code>AbstractInfoImpl</code> for the resource identified by the
- * specified path or null if the path is unknown
- */
- protected AbstractInfo getAbstractInfoByPath(String path) {
- return (AbstractInfo) m_pathToEntry.get(path);
- }
-
- /**
- * Returns whether the given name (which is expected to be the name of a
- * JarEntry) is a signature file or the JAR index file.
- *
- * @param name the name of the JAR entry to test, cannot be
- * <code>null</code>.
- * @return <code>true</code> if the given JAR entry name is a signature file
- * or JAR index file, <code>false</code> otherwise.
- */
- protected boolean isMetaInfFile(String name) {
- name = name.toUpperCase(Locale.US);
- return name.startsWith("META-INF/") && (name.endsWith("/INDEX.LIST") || name.endsWith(".SF") || name.endsWith(".DSA") || name.endsWith(".RSA") || name.endsWith(".EC"));
- }
-}
diff --git a/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/AbstractInfo.java b/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/AbstractInfo.java
deleted file mode 100644
index f0b2af11f7..0000000000
--- a/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/AbstractInfo.java
+++ /dev/null
@@ -1,139 +0,0 @@
-/*
- * 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.util.BitSet;
-import java.util.jar.Attributes;
-
-import org.osgi.service.deploymentadmin.DeploymentException;
-
-/**
- * Objects of this class represent the meta data for a resource from a deployment package, this
- * can be either bundle resources or processed resources.
- */
-public class AbstractInfo implements Constants {
-
- private static final BitSet VALID_RESOURCE_PATH_CHARS;
- static {
- VALID_RESOURCE_PATH_CHARS = new BitSet();
- for (int i = 'a'; i <= 'z'; i++) {
- VALID_RESOURCE_PATH_CHARS.set(i);
- }
- for (int i = 'A'; i <= 'Z'; i++) {
- VALID_RESOURCE_PATH_CHARS.set(i);
- }
- for (int i = '0'; i <= '9'; i++) {
- VALID_RESOURCE_PATH_CHARS.set(i);
- }
- VALID_RESOURCE_PATH_CHARS.set('.');
- VALID_RESOURCE_PATH_CHARS.set('-');
- VALID_RESOURCE_PATH_CHARS.set('_');
- VALID_RESOURCE_PATH_CHARS.set('/');
- }
-
- private final String m_path;
- private final Attributes m_attributes;
- private final boolean m_missing;
-
- /**
- * Create an instance
- *
- * @param path Resource-id aka path of the resource
- * @param attributes Attributes containing the meta data of the resource
- * @throws DeploymentException If the specified attributes do not match the correct syntax for a deployment package resource.
- */
- public AbstractInfo(String path, Attributes attributes) throws DeploymentException {
- verifyEntryName(path);
- m_path = path;
- m_attributes = attributes;
- m_missing = parseBooleanHeader(attributes, DEPLOYMENTPACKAGE_MISSING);
- }
-
- /**
- * @return The path of the resource
- */
- public String getPath() {
- return m_path;
- }
-
- /**
- * Return the value of a header for this resource
- *
- * @param header Name of the header
- * @return Value of the header specified by the given header name
- */
- public String getHeader(String header) {
- return m_attributes.getValue(header);
- }
-
- private void verifyEntryName(String name) throws DeploymentException {
- byte[] bytes = name.getBytes();
- boolean delimiterSeen = false;
- for (int j = 0; j < bytes.length; j++) {
- if (!VALID_RESOURCE_PATH_CHARS.get(bytes[j])) {
- throw new DeploymentException(CODE_BAD_HEADER, "Resource ID '" + name + "' contains invalid character(s)");
- }
- if (bytes[j] == '/') {
- if (delimiterSeen) {
- throw new DeploymentException(CODE_BAD_HEADER, "Resource ID '" + name + "' contains multiple consequetive path seperators");
- }
- else {
- delimiterSeen = true;
- }
- }
- else {
- delimiterSeen = false;
- }
- }
- }
-
- /**
- * Determine if a resource is missing or not
- *
- * @return True if the actual data for this resource is not present, false otherwise
- */
- public boolean isMissing() {
- return m_missing;
- }
-
- /**
- * Parses a header that is allowed to have only boolean values.
- *
- * @param attributes Set of attributes containing the header
- * @param header The header to verify
- * @return true if the value of the header was "true", false if the value was "false"
- * @throws DeploymentException if the value was not "true" or "false"
- */
- protected boolean parseBooleanHeader(Attributes attributes, String header) throws DeploymentException {
- String value = attributes.getValue(header);
- if (value != null) {
- if ("true".equals(value)) {
- return true;
- }
- else if ("false".equals(value)) {
- return false;
- }
- else {
- throw new DeploymentException(CODE_BAD_HEADER, "Invalid '" + header + "' header for manifest " + "entry '" + getPath() + "' header, should be either 'true' or 'false' or not present");
- }
- }
- return false;
- }
-
-}
diff --git a/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/Activator.java b/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/Activator.java
deleted file mode 100644
index 7013e78bad..0000000000
--- a/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/Activator.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * 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 org.apache.felix.dm.DependencyActivatorBase;
-import org.apache.felix.dm.DependencyManager;
-import org.osgi.framework.BundleContext;
-import org.osgi.service.deploymentadmin.DeploymentAdmin;
-import org.osgi.service.event.EventAdmin;
-import org.osgi.service.log.LogService;
-import org.osgi.service.packageadmin.PackageAdmin;
-
-/**
- * Bundle activator for the deployment admin bundle
- *
- * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
- */
-public class Activator extends DependencyActivatorBase {
-
- public void init(BundleContext context, DependencyManager manager) throws Exception {
- manager.add(createComponent()
- .setInterface(DeploymentAdmin.class.getName(), null)
- .setImplementation(DeploymentAdminImpl.class)
- .add(createServiceDependency()
- .setService(PackageAdmin.class)
- .setRequired(true))
- .add(createServiceDependency()
- .setService(EventAdmin.class)
- .setRequired(false))
- .add(createServiceDependency()
- .setService(LogService.class)
- .setRequired(false)));
- }
-
- public void destroy(BundleContext context, DependencyManager manager) throws Exception {
- // do nothing
- }
-}
diff --git a/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/BundleInfoImpl.java b/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/BundleInfoImpl.java
deleted file mode 100644
index bdfa8c119d..0000000000
--- a/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/BundleInfoImpl.java
+++ /dev/null
@@ -1,112 +0,0 @@
-/*
- * 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.util.StringTokenizer;
-import java.util.jar.Attributes;
-
-import org.osgi.framework.Version;
-import org.osgi.service.deploymentadmin.BundleInfo;
-import org.osgi.service.deploymentadmin.DeploymentException;
-
-/**
- * Implementation of the <code>BundleInfo</code> interface as defined by the OSGi mobile specification.
- */
-public class BundleInfoImpl extends AbstractInfo implements BundleInfo {
-
- private final Version m_version;
- private final String m_symbolicName;
- private final boolean m_customizer;
-
- /**
- * Creates an instance of this class.
- *
- * @param path The path / resource-id of the bundle resource.
- * @param attributes Set of attributes describing the bundle resource.
- * @throws DeploymentException If the specified attributes do not describe a valid bundle.
- */
- public BundleInfoImpl(String path, Attributes attributes) throws DeploymentException {
- super(path, attributes);
-
- String bundleSymbolicName = attributes.getValue(BUNDLE_SYMBOLICNAME);
- if (bundleSymbolicName == null) {
- throw new DeploymentException(CODE_MISSING_HEADER, "Missing '" + BUNDLE_SYMBOLICNAME + "' header for manifest entry '" + getPath() + "'");
- }
- else if (bundleSymbolicName.trim().equals("")) {
- throw new DeploymentException(CODE_BAD_HEADER, "Invalid '" + BUNDLE_SYMBOLICNAME + "' header for manifest entry '" + getPath() + "'");
- }
- else {
- m_symbolicName = parseSymbolicName(bundleSymbolicName);
- }
-
- String version = attributes.getValue(BUNDLE_VERSION);
- if (version == null || version == "") {
- throw new DeploymentException(CODE_BAD_HEADER, "Invalid '" + BUNDLE_VERSION + "' header for manifest entry '" + getPath() + "'");
- }
- try {
- m_version = Version.parseVersion(version);
- }
- catch (IllegalArgumentException e) {
- throw new DeploymentException(CODE_BAD_HEADER, "Invalid '" + BUNDLE_VERSION + "' header for manifest entry '" + getPath() + "'");
- }
-
- m_customizer = parseBooleanHeader(attributes, DEPLOYMENTPACKAGE_CUSTOMIZER);
- }
-
- /**
- * Strips parameters from the bundle symbolic name such as "foo;singleton:=true".
- *
- * @param name full name as found in the manifest of the deployment package
- * @return name without parameters
- */
- private String parseSymbolicName(String name) {
- // note that we don't explicitly check if there are tokens, because that
- // check has already been made before we are invoked here
- StringTokenizer st = new StringTokenizer(name, ";");
- return st.nextToken();
- }
-
- public String getSymbolicName() {
- return m_symbolicName;
- }
-
- public Version getVersion() {
- return m_version;
- }
-
- /**
- * Determine whether this bundle resource is a customizer bundle.
- *
- * @return True if the bundle is a customizer bundle, false otherwise.
- */
- public boolean isCustomizer() {
- return m_customizer;
- }
-
- /**
- * Verify if the specified attributes describe a bundle resource.
- *
- * @param attributes Attributes describing the resource
- * @return true if the attributes describe a bundle resource, false otherwise
- */
- public static boolean isBundleResource(Attributes attributes) {
- return (attributes.getValue(BUNDLE_SYMBOLICNAME) != null);
- }
-
-}
diff --git a/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/Constants.java b/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/Constants.java
deleted file mode 100644
index 7a524b3b9a..0000000000
--- a/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/Constants.java
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * 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 org.osgi.service.deploymentadmin.DeploymentException;
-import org.osgi.service.deploymentadmin.DeploymentPackage;
-
-public interface Constants extends org.osgi.framework.Constants {
-
- // manifest main attribute header constants
- String DEPLOYMENTPACKAGE_SYMBOLICMAME = "DeploymentPackage-SymbolicName";
- String DEPLOYMENTPACKAGE_VERSION = "DeploymentPackage-Version";
- String DEPLOYMENTPACKAGE_FIXPACK = "DeploymentPackage-FixPack";
- String DEPLOYMENTPACKAGE_NAME = "DeploymentPackage-Name";
- String DEPLOYMENTPACKAGE_ICON = "DeploymentPackage-Icon";
-
- // manifest 'name' section header constants
- String RESOURCE_PROCESSOR = "Resource-Processor";
- String DEPLOYMENTPACKAGE_MISSING = "DeploymentPackage-Missing";
- String DEPLOYMENTPACKAGE_CUSTOMIZER = "DeploymentPackage-Customizer";
-
- // event topics and properties
- String EVENTTOPIC_INSTALL = "org/osgi/service/deployment/INSTALL";
- String EVENTTOPIC_UNINSTALL = "org/osgi/service/deployment/UNINSTALL";
- String EVENTTOPIC_COMPLETE = "org/osgi/service/deployment/COMPLETE";
-
- String EVENTPROPERTY_DEPLOYMENTPACKAGE_NAME = DeploymentPackage.EVENT_DEPLOYMENTPACKAGE_NAME;
- String EVENTPROPERTY_DEPLOYMENTPACKAGE_READABLENAME = DeploymentPackage.EVENT_DEPLOYMENTPACKAGE_READABLENAME;
- String EVENTPROPERTY_DEPLOYMENTPACKAGE_CURRENTVERSION = DeploymentPackage.EVENT_DEPLOYMENTPACKAGE_CURRENTVERSION;
- String EVENTPROPERTY_DEPLOYMENTPACKAGE_NEXTVERSION = DeploymentPackage.EVENT_DEPLOYMENTPACKAGE_NEXTVERSION;
- String EVENTPROPERTY_SUCCESSFUL = "successful";
-
- // miscellaneous constants
- String BUNDLE_LOCATION_PREFIX = "osgi-dp:";
-
- // inlined constants for convenience & readability
- int CODE_CANCELLED = DeploymentException.CODE_CANCELLED;
- int CODE_NOT_A_JAR = DeploymentException.CODE_NOT_A_JAR;
- int CODE_ORDER_ERROR = DeploymentException.CODE_ORDER_ERROR;
- int CODE_MISSING_HEADER = DeploymentException.CODE_MISSING_HEADER;
- int CODE_BAD_HEADER = DeploymentException.CODE_BAD_HEADER;
- int CODE_MISSING_FIXPACK_TARGET = DeploymentException.CODE_MISSING_FIXPACK_TARGET;
- int CODE_MISSING_BUNDLE = DeploymentException.CODE_MISSING_BUNDLE;
- int CODE_MISSING_RESOURCE = DeploymentException.CODE_MISSING_RESOURCE;
- int CODE_SIGNING_ERROR = DeploymentException.CODE_SIGNING_ERROR;
- int CODE_BUNDLE_NAME_ERROR = DeploymentException.CODE_BUNDLE_NAME_ERROR;
- int CODE_FOREIGN_CUSTOMIZER = DeploymentException.CODE_FOREIGN_CUSTOMIZER;
- int CODE_BUNDLE_SHARING_VIOLATION = DeploymentException.CODE_BUNDLE_SHARING_VIOLATION;
- int CODE_RESOURCE_SHARING_VIOLATION = DeploymentException.CODE_RESOURCE_SHARING_VIOLATION;
- int CODE_COMMIT_ERROR = DeploymentException.CODE_COMMIT_ERROR;
- int CODE_OTHER_ERROR = DeploymentException.CODE_OTHER_ERROR;
- int CODE_PROCESSOR_NOT_FOUND = DeploymentException.CODE_PROCESSOR_NOT_FOUND;
- int CODE_TIMEOUT = DeploymentException.CODE_TIMEOUT;
-
- String BUNDLE_SYMBOLICNAME = org.osgi.framework.Constants.BUNDLE_SYMBOLICNAME;
- String BUNDLE_VERSION = org.osgi.framework.Constants.BUNDLE_VERSION;
- String SERVICE_PID = org.osgi.framework.Constants.SERVICE_PID;
-
-}
\ No newline at end of file
diff --git a/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/ContentCopyingJarInputStream.java b/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/ContentCopyingJarInputStream.java
deleted file mode 100644
index 7dff1da06a..0000000000
--- a/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/ContentCopyingJarInputStream.java
+++ /dev/null
@@ -1,151 +0,0 @@
-/*
- * 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 static org.apache.felix.deploymentadmin.Utils.closeSilently;
-
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.FileWriter;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.io.PrintWriter;
-import java.util.jar.JarFile;
-import java.util.jar.JarInputStream;
-import java.util.jar.Manifest;
-import java.util.zip.GZIPOutputStream;
-import java.util.zip.ZipEntry;
-
-/**
- * Provides a custom {@link JarInputStream} that copies all entries read from the original {@link InputStream} to a
- * given directory and index file. It does this by tracking thecommon usage of the {@link JarInputStream} API. For each
- * entry that is read it streams all read bytes to a separate file compressing it on the fly. The caller does not notice
- * anything, although it might be that the {@link #read(byte[], int, int)} is blocked for a little while during the
- * writing of the file contents.
- * <p>
- * This implementation replaces the old <tt>ExplodingOutputtingInputStream</tt> that used
- * at least two threads and was difficult to understand and maintain. See FELIX-4486.
- * </p>
- */
-class ContentCopyingJarInputStream extends JarInputStream {
- private static final String MANIFEST_FILE = JarFile.MANIFEST_NAME;
-
- private final File m_contentDir;
-
- private PrintWriter m_indexFileWriter;
- /** Used to copy the contents of the *next* entry. */
- private OutputStream m_entryOS;
-
- public ContentCopyingJarInputStream(InputStream in, File indexFile, File contentDir) throws IOException {
- super(in, true /* verify */);
-
- m_contentDir = contentDir;
-
- m_indexFileWriter = new PrintWriter(new FileWriter(indexFile));
- m_entryOS = null;
-
- // the manifest of the JAR is already read by JarInputStream, so we need to write this one as well...
- Manifest manifest = getManifest();
- if (manifest != null) {
- copyManifest(manifest);
- }
- }
-
- public void close() throws IOException {
- closeCopy();
- closeIndex();
- // Do NOT close our parent, as it is the original input stream which is not under our control...
- }
-
- public void closeEntry() throws IOException {
- closeCopy();
- super.closeEntry();
- }
-
- public ZipEntry getNextEntry() throws IOException {
- closeCopy();
-
- ZipEntry entry = super.getNextEntry();
- if (entry != null) {
- File current = new File(m_contentDir, entry.getName());
- if (!entry.isDirectory()) {
- addToIndex(entry.getName());
-
- m_entryOS = createOutputStream(current);
- }
- }
-
- return entry;
- }
-
- public int read(byte[] b, int off, int len) throws IOException {
- int r = super.read(b, off, len);
- if (m_entryOS != null) {
- if (r > 0) {
- m_entryOS.write(b, off, r);
- }
- else {
- closeCopy();
- }
- }
- return r;
- }
-
- private void addToIndex(String name) throws IOException {
- m_indexFileWriter.println(name);
- m_indexFileWriter.flush();
- }
-
- private void closeCopy() {
- closeSilently(m_entryOS);
- m_entryOS = null;
- }
-
- private void closeIndex() {
- closeSilently(m_indexFileWriter);
- m_indexFileWriter = null;
- }
-
- /**
- * Creates a verbatim copy of the manifest, when it is read from the original JAR.
- */
- private void copyManifest(Manifest manifest) throws IOException {
- addToIndex(MANIFEST_FILE);
-
- OutputStream os = createOutputStream(new File(m_contentDir, MANIFEST_FILE));
- try {
- manifest.write(os);
- }
- finally {
- closeSilently(os);
- }
- }
-
- private OutputStream createOutputStream(File file) throws IOException {
- File parent = file.getParentFile();
- if (parent != null) {
- parent.mkdirs();
- }
- if (!file.createNewFile()) {
- throw new IOException("Attempt to overwrite file: " + file);
- }
- return new GZIPOutputStream(new FileOutputStream(file));
- }
-}
diff --git a/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/DeploymentAdminConfig.java b/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/DeploymentAdminConfig.java
deleted file mode 100644
index bdafcbb445..0000000000
--- a/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/DeploymentAdminConfig.java
+++ /dev/null
@@ -1,92 +0,0 @@
-/*
- * 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 org.osgi.framework.BundleContext;
-
-/**
- * Provides the configuration options for this DeploymentAdmin implementation.
- */
-public class DeploymentAdminConfig {
- /** Prefix used for the configuration properties of DA. */
- private static final String PREFIX = "org.apache.felix.deploymentadmin.";
-
- /**
- * Configuration key used to stop only bundles mentioned in a DP instead of all bundles.
- * @deprecated incorrect name append the 's'
- */
- static final String KEY_STOP_UNAFFECTED_BUNDLE = PREFIX.concat("stopUnaffectedBundle");
- /** Configuration key used to stop only bundles mentioned in a DP instead of all bundles. */
- static final String KEY_STOP_UNAFFECTED_BUNDLES = PREFIX.concat("stopUnaffectedBundles");
- /** Configuration key used to allow usage of customizers outside a DP. */
- static final String KEY_ALLOW_FOREIGN_CUSTOMIZERS = PREFIX.concat("allowForeignCustomizers");
-
- static final boolean DEFAULT_STOP_UNAFFECTED_BUNDLES = true;
- static final boolean DEFAULT_ALLOW_FOREIGN_CUSTOMIZERS = false;
-
- private final boolean m_stopUnaffectedBundles;
- private final boolean m_allowForeignCustomizers;
-
- /**
- * Creates a new {@link DeploymentAdminConfig} instance with the default settings.
- */
- public DeploymentAdminConfig(BundleContext context) {
- // Allow the constant to be used in singular or plural form...
- String value = getFrameworkProperty(context, KEY_STOP_UNAFFECTED_BUNDLE);
- if (value == null) {
- value = getFrameworkProperty(context, KEY_STOP_UNAFFECTED_BUNDLES);
- }
- m_stopUnaffectedBundles = parseBoolean(value, DEFAULT_STOP_UNAFFECTED_BUNDLES);
-
- value = getFrameworkProperty(context, KEY_ALLOW_FOREIGN_CUSTOMIZERS);
- m_allowForeignCustomizers = parseBoolean(value, DEFAULT_ALLOW_FOREIGN_CUSTOMIZERS);
- }
-
- /**
- * @return <code>true</code> if foreign customizers (that are not part of a DP) are allowed, <code>false</code> if
- * all customizers should be provided by this or an earlier DP.
- */
- public boolean isAllowForeignCustomizers() {
- return m_allowForeignCustomizers;
- }
-
- /**
- * @return <code>true</code> if all bundles should be stopped during the installation of a DP, <code>false</code> if
- * only affected bundles should be stopped.
- */
- public boolean isStopUnaffectedBundles() {
- return m_stopUnaffectedBundles;
- }
-
- private static boolean parseBoolean(String value, boolean dflt) {
- if (value == null || "".equals(value.trim())) {
- return dflt;
- }
- return Boolean.parseBoolean(value);
- }
-
- private static String getFrameworkProperty(BundleContext context, String key) {
- String prop = context.getProperty(key);
- if (prop == null) {
- // be lenient wrt the naming...
- prop = context.getProperty(key.toLowerCase());
- }
- return prop;
- }
-}
diff --git a/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/DeploymentAdminImpl.java b/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/DeploymentAdminImpl.java
deleted file mode 100644
index 42f2c3292e..0000000000
--- a/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/DeploymentAdminImpl.java
+++ /dev/null
@@ -1,617 +0,0 @@
-/*
- * 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.IOException;
-import java.io.InputStream;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Dictionary;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Properties;
-import java.util.jar.JarInputStream;
-
-import org.apache.felix.deploymentadmin.spi.CommitResourceCommand;
-import org.apache.felix.deploymentadmin.spi.DeploymentSessionImpl;
-import org.apache.felix.deploymentadmin.spi.DropAllBundlesCommand;
-import org.apache.felix.deploymentadmin.spi.DropAllResourcesCommand;
-import org.apache.felix.deploymentadmin.spi.DropBundleCommand;
-import org.apache.felix.deploymentadmin.spi.DropResourceCommand;
-import org.apache.felix.deploymentadmin.spi.GetStorageAreaCommand;
-import org.apache.felix.deploymentadmin.spi.ProcessResourceCommand;
-import org.apache.felix.deploymentadmin.spi.SnapshotCommand;
-import org.apache.felix.deploymentadmin.spi.StartBundleCommand;
-import org.apache.felix.deploymentadmin.spi.StartCustomizerCommand;
-import org.apache.felix.deploymentadmin.spi.StopBundleCommand;
-import org.apache.felix.deploymentadmin.spi.UpdateCommand;
-import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleContext;
-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.osgi.service.event.Event;
-import org.osgi.service.event.EventAdmin;
-import org.osgi.service.log.LogService;
-import org.osgi.service.packageadmin.PackageAdmin;
-
-public class DeploymentAdminImpl implements DeploymentAdmin, Constants {
- public static final String PACKAGE_DIR = "packages";
- public static final String TEMP_DIR = "temp";
- public static final String PACKAGECONTENTS_DIR = "contents";
- public static final String PACKAGEINDEX_FILE = "index.txt";
- public static final String TEMP_PREFIX = "pkg";
- public static final String TEMP_POSTFIX = "";
-
- private static final long TIMEOUT = 10000;
-
- private volatile BundleContext m_context; /* will be injected by dependencymanager */
- private volatile PackageAdmin m_packageAdmin; /* will be injected by dependencymanager */
- private volatile EventAdmin m_eventAdmin; /* will be injected by dependencymanager */
- private volatile LogService m_log; /* will be injected by dependencymanager */
- private volatile DeploymentSessionImpl m_session;
-
- private final Map /* BSN -> DeploymentPackage */m_packages = new HashMap();
- private final Semaphore m_semaphore = new Semaphore();
-
- /**
- * Creates a new {@link DeploymentAdminImpl} instance.
- */
- public DeploymentAdminImpl() {
- // Nop
- }
-
- /**
- * Creates a new {@link DeploymentAdminImpl} instance.
- */
- DeploymentAdminImpl(BundleContext context) {
- m_context = context;
- }
-
- public boolean cancel() {
- DeploymentSessionImpl session = m_session;
- if (session != null) {
- session.cancel();
- return true;
- }
- return false;
- }
-
- /**
- * Returns reference to this bundle's <code>BundleContext</code>
- *
- * @return This bundle's <code>BundleContext</code>
- */
- public BundleContext getBundleContext() {
- return m_context;
- }
-
- public DeploymentPackage getDeploymentPackage(Bundle bundle) {
- if (bundle == null) {
- throw new IllegalArgumentException("Bundle can not be null");
- }
- return getDeploymentPackageContainingBundleWithSymbolicName(bundle.getSymbolicName());
- }
-
- public DeploymentPackage getDeploymentPackage(String symbName) {
- if (symbName == null) {
- throw new IllegalArgumentException("Symbolic name may not be null");
- }
- return (DeploymentPackage) m_packages.get(symbName);
- }
-
- /**
- * Returns reference to the current logging service defined in the framework.
- *
- * @return Currently active <code>LogService</code>.
- */
- public LogService getLog() {
- return m_log;
- }
-
- /**
- * Returns reference to the current package admin defined in the framework.
- *
- * @return Currently active <code>PackageAdmin</code>.
- */
- public PackageAdmin getPackageAdmin() {
- return m_packageAdmin;
- }
-
- public DeploymentPackage installDeploymentPackage(InputStream sourceInput) throws DeploymentException {
- if (sourceInput == null) {
- throw new IllegalArgumentException("Inputstream may not be null");
- }
-
- try {
- if (!m_semaphore.tryAcquire(TIMEOUT)) {
- throw new DeploymentException(CODE_TIMEOUT, "Timeout exceeded while waiting to install deployment package (" + TIMEOUT + " ms)");
- }
- }
- catch (InterruptedException ie) {
- throw new DeploymentException(CODE_TIMEOUT, "Thread interrupted");
- }
-
- File tempPackage = null;
- StreamDeploymentPackage source = null;
- AbstractDeploymentPackage target = null;
- boolean succeeded = false;
-
- try {
- JarInputStream jarInput = null;
- File tempIndex = null;
- File tempContents = null;
- try {
- File tempDir = m_context.getDataFile(TEMP_DIR);
- tempDir.mkdirs();
- tempPackage = File.createTempFile(TEMP_PREFIX, TEMP_POSTFIX, tempDir);
- tempPackage.delete();
- tempPackage.mkdirs();
- tempIndex = new File(tempPackage, PACKAGEINDEX_FILE);
- tempContents = new File(tempPackage, PACKAGECONTENTS_DIR);
- tempContents.mkdirs();
- }
- catch (IOException e) {
- m_log.log(LogService.LOG_ERROR, "Error writing package to disk", e);
- throw new DeploymentException(CODE_OTHER_ERROR, "Error writing package to disk", e);
- }
-
- try {
- jarInput = new ContentCopyingJarInputStream(sourceInput, tempIndex, tempContents);
-
- if (jarInput.getManifest() == null) {
- Utils.closeSilently(jarInput);
-
- m_log.log(LogService.LOG_ERROR, "Stream does not contain a valid deployment package: missing manifest!");
- throw new DeploymentException(CODE_MISSING_HEADER, "No manifest present in deployment package!");
- }
- }
- catch (IOException e) {
- m_log.log(LogService.LOG_ERROR, "Stream does not contain a valid Jar", e);
- throw new DeploymentException(CODE_NOT_A_JAR, "Stream does not contain a valid Jar", e);
- }
-
- source = new StreamDeploymentPackage(jarInput, m_context, this);
- String dpSymbolicName = source.getName();
-
- target = getExistingOrEmptyDeploymentPackage(dpSymbolicName);
-
- // Fire an event that we're about to install a new package
- sendStartedEvent(source, target);
-
- // Assert that:
- // the source has no bundles that exists in other packages than the target.
- verifyNoResourcesShared(source, target);
-
- if (source.isFixPackage()) {
- // Assert that:
- // a. the version of the target matches the required fix-package range;
- // b. all missing source bundles are present in the target.
- verifyFixPackage(source, target);
- }
- else {
- // Assert that:
- // no missing resources or bundles are declared.
- verifySourcePackage(source);
- }
-
- try {
- m_session = new DeploymentSessionImpl(source, target, createInstallCommandChain(), this, new DeploymentAdminConfig(m_context));
- m_session.call(false /* ignoreExceptions */);
- }
- catch (DeploymentException de) {
- throw de;
- }
- finally {
- // We're done at this point with the JAR input stream, close it here as to avoid keeping
- // files open unnecessary (otherwise it fails on Windows)...
- Utils.closeSilently(jarInput);
- }
-
- String dpInstallBaseDirectory = PACKAGE_DIR + File.separator + dpSymbolicName;
-
- File targetContents = m_context.getDataFile(dpInstallBaseDirectory + File.separator + PACKAGECONTENTS_DIR);
- File targetIndex = m_context.getDataFile(dpInstallBaseDirectory + File.separator + PACKAGEINDEX_FILE);
-
- if (source.isFixPackage()) {
- try {
- Utils.merge(targetIndex, targetContents, tempIndex, tempContents);
- }
- catch (IOException e) {
- m_log.log(LogService.LOG_ERROR, "Could not merge source fix package with target deployment package", e);
- throw new DeploymentException(CODE_OTHER_ERROR, "Could not merge source fix package with target deployment package", e);
- }
- }
- else {
- File targetPackage = m_context.getDataFile(dpInstallBaseDirectory);
- targetPackage.mkdirs();
- if (!Utils.replace(targetPackage, tempPackage)) {
- throw new DeploymentException(CODE_OTHER_ERROR, "Could not replace " + targetPackage + " with " + tempPackage);
- }
- }
-
- FileDeploymentPackage fileDeploymentPackage = null;
- try {
- fileDeploymentPackage = new FileDeploymentPackage(targetIndex, targetContents, m_context, this);
- m_packages.put(dpSymbolicName, fileDeploymentPackage);
- }
- catch (IOException e) {
- m_log.log(LogService.LOG_ERROR, "Could not create installed deployment package from disk", e);
- throw new DeploymentException(CODE_OTHER_ERROR, "Could not create installed deployment package from disk", e);
- }
-
- // Since we're here, it means everything went OK, so we might as well raise our success flag...
- succeeded = true;
-
- return fileDeploymentPackage;
- }
- finally {
- if (tempPackage != null) {
- if (!Utils.delete(tempPackage, true)) {
- m_log.log(LogService.LOG_ERROR, "Could not delete temporary deployment package from disk");
- succeeded = false;
- }
- }
-
- sendCompleteEvent(source, target, succeeded);
- m_semaphore.release();
- }
- }
-
- public DeploymentPackage[] listDeploymentPackages() {
- Collection packages = m_packages.values();
- return (DeploymentPackage[]) packages.toArray(new DeploymentPackage[packages.size()]);
- }
-
- /**
- * Called by dependency manager upon start of this component.
- */
- public void start() throws DeploymentException {
- File packageDir = m_context.getDataFile(PACKAGE_DIR);
- if (packageDir == null) {
- throw new DeploymentException(CODE_OTHER_ERROR, "Could not create directories needed for deployment package persistence");
- }
- else if (packageDir.isDirectory()) {
- File[] dpPackages = packageDir.listFiles();
- for (int i = 0; i < dpPackages.length; i++) {
- File dpPackageDir = dpPackages[i];
- if (!dpPackageDir.isDirectory()) {
- continue;
- }
-
- try {
- File index = new File(dpPackageDir, PACKAGEINDEX_FILE);
- File contents = new File(dpPackageDir, PACKAGECONTENTS_DIR);
- FileDeploymentPackage dp = new FileDeploymentPackage(index, contents, m_context, this);
- m_packages.put(dp.getName(), dp);
- }
- catch (IOException e) {
- m_log.log(LogService.LOG_WARNING, "Could not read deployment package from disk, skipping: '" + dpPackageDir.getAbsolutePath() + "'");
- }
- }
- }
- }
-
- /**
- * Called by dependency manager when stopping this component.
- */
- public void stop() {
- cancel();
- }
-
- /**
- * Uninstalls the given deployment package from the system.
- *
- * @param dp the deployment package to uninstall, cannot be <code>null</code>;
- * @param forced <code>true</code> to force the uninstall, meaning that any exceptions are ignored during the
- * uninstallation.
- * @throws DeploymentException in case the uninstall failed.
- */
- public void uninstallDeploymentPackage(DeploymentPackage dp, boolean forced) throws DeploymentException {
- try {
- if (!m_semaphore.tryAcquire(TIMEOUT)) {
- throw new DeploymentException(CODE_TIMEOUT, "Timeout exceeded while waiting to uninstall deployment package (" + TIMEOUT + " ms)");
- }
- }
- catch (InterruptedException ie) {
- throw new DeploymentException(CODE_TIMEOUT, "Thread interrupted");
- }
-
- boolean succeeded = false;
- AbstractDeploymentPackage source = AbstractDeploymentPackage.EMPTY_PACKAGE;
- AbstractDeploymentPackage target = (AbstractDeploymentPackage) dp;
-
- // Notify listeners that we've about to uninstall the deployment package...
- sendUninstallEvent(source, target);
-
- try {
- try {
- m_session = new DeploymentSessionImpl(source, target, createUninstallCommandChain(), this, new DeploymentAdminConfig(m_context));
- m_session.call(forced /* ignoreExceptions */);
- }
- catch (DeploymentException de) {
- throw de;
- }
-
- File targetPackage = m_context.getDataFile(PACKAGE_DIR + File.separator + source.getName());
- if (!Utils.delete(targetPackage, true)) {
- m_log.log(LogService.LOG_ERROR, "Could not delete deployment package from disk");
- throw new DeploymentException(CODE_OTHER_ERROR, "Could not delete deployment package from disk");
- }
-
- m_packages.remove(dp.getName());
-
- succeeded = true;
- }
- finally {
- sendCompleteEvent(source, target, succeeded);
- m_semaphore.release();
- }
- }
-
- /**
- * Creates the properties for a new event.
- *
- * @param source the source package being installed;
- * @param target the current installed package (can be new).
- * @return the event properties, never <code>null</code>.
- */
- private Dictionary createEventProperties(AbstractDeploymentPackage source, AbstractDeploymentPackage target) {
- Dictionary props = new Properties();
- if (source != null) {
- String displayName = source.getDisplayName();
- if (displayName == null) {
- displayName = source.getName();
- }
-
- props.put(EVENTPROPERTY_DEPLOYMENTPACKAGE_NAME, source.getName());
- props.put(EVENTPROPERTY_DEPLOYMENTPACKAGE_READABLENAME, displayName);
- if (!source.isNew()) {
- props.put(EVENTPROPERTY_DEPLOYMENTPACKAGE_NEXTVERSION, source.getVersion());
- }
- }
- if ((target != null) && !target.isNew()) {
- props.put(EVENTPROPERTY_DEPLOYMENTPACKAGE_CURRENTVERSION, target.getVersion());
- }
- return props;
- }
-
- private List createInstallCommandChain() {
- List commandChain = new ArrayList();
-
- GetStorageAreaCommand getStorageAreaCommand = new GetStorageAreaCommand();
- commandChain.add(getStorageAreaCommand);
- commandChain.add(new StopBundleCommand());
- commandChain.add(new SnapshotCommand(getStorageAreaCommand));
- commandChain.add(new UpdateCommand());
- commandChain.add(new StartCustomizerCommand());
- CommitResourceCommand commitCommand = new CommitResourceCommand();
- commandChain.add(new ProcessResourceCommand(commitCommand));
- commandChain.add(new DropResourceCommand(commitCommand));
- commandChain.add(new DropBundleCommand());
- commandChain.add(commitCommand);
- commandChain.add(new StartBundleCommand());
-
- return commandChain;
- }
-
- private List createUninstallCommandChain() {
- List commandChain = new ArrayList();
-
- GetStorageAreaCommand getStorageAreaCommand = new GetStorageAreaCommand();
- commandChain.add(getStorageAreaCommand);
- commandChain.add(new StopBundleCommand());
- commandChain.add(new SnapshotCommand(getStorageAreaCommand));
- commandChain.add(new StartCustomizerCommand());
- CommitResourceCommand commitCommand = new CommitResourceCommand();
- commandChain.add(new DropAllResourcesCommand(commitCommand));
- commandChain.add(commitCommand);
- commandChain.add(new DropAllBundlesCommand());
-
- return commandChain;
- }
-
- /**
- * Searches for a deployment package that contains a bundle with the given symbolic name.
- *
- * @param symbolicName the symbolic name of the <em>bundle</em> to return the containing deployment package for,
- * cannot be <code>null</code>.
- * @return the deployment package containing the given bundle, or <code>null</code> if no deployment package
- * contained such bundle.
- */
- private AbstractDeploymentPackage getDeploymentPackageContainingBundleWithSymbolicName(String symbolicName) {
- for (Iterator i = m_packages.values().iterator(); i.hasNext();) {
- AbstractDeploymentPackage dp = (AbstractDeploymentPackage) i.next();
- if (dp.getBundle(symbolicName) != null) {
- return dp;
- }
- }
- return null;
- }
-
- /**
- * Returns either an existing deployment package, or if no such package exists, an empty package.
- *
- * @param symbolicName the name of the deployment package to retrieve, cannot be <code>null</code>.
- * @return a deployment package, never <code>null</code>.
- */
- private AbstractDeploymentPackage getExistingOrEmptyDeploymentPackage(String symbolicName) {
- AbstractDeploymentPackage result = (AbstractDeploymentPackage) m_packages.get(symbolicName);
- if (result == null) {
- result = AbstractDeploymentPackage.EMPTY_PACKAGE;
- }
- return result;
- }
-
- /**
- * Returns all bundles that are not present in any deployment package. Ultimately, this should only
- * be one bundle, the system bundle, but this is not enforced in any way by the specification.
- *
- * @return an array of non-deployment packaged bundles, never <code>null</code>.
- */
- private Bundle[] getNonDeploymentPackagedBundles() {
- List result = new ArrayList(Arrays.asList(m_context.getBundles()));
-
- Iterator iter = result.iterator();
- while (iter.hasNext()) {
- Bundle suspect = (Bundle) iter.next();
- if (suspect.getLocation().startsWith(BUNDLE_LOCATION_PREFIX)) {
- iter.remove();
- }
- }
-
- return (Bundle[]) result.toArray(new Bundle[result.size()]);
- }
-
- /**
- * Sends out an event that the {@link #installDeploymentPackage(InputStream)} is
- * completed its installation of a deployment package.
- *
- * @param source the source package being installed;
- * @param target the current installed package (can be new);
- * @param success <code>true</code> if the installation was successful, <code>false</code> otherwise.
- */
- private void sendCompleteEvent(AbstractDeploymentPackage source, AbstractDeploymentPackage target, boolean success) {
- Dictionary props = createEventProperties(source, target);
- props.put(EVENTPROPERTY_SUCCESSFUL, Boolean.valueOf(success));
-
- m_eventAdmin.postEvent(new Event(EVENTTOPIC_COMPLETE, props));
- }
-
- /**
- * Sends out an event that the {@link #installDeploymentPackage(InputStream)} is about
- * to install a new deployment package.
- *
- * @param source the source package being installed;
- * @param target the current installed package (can be new).
- */
- private void sendStartedEvent(AbstractDeploymentPackage source, AbstractDeploymentPackage target) {
- Dictionary props = createEventProperties(source, target);
-
- m_eventAdmin.postEvent(new Event(EVENTTOPIC_INSTALL, props));
- }
-
- /**
- * Sends out an event that the {@link #uninstallDeploymentPackage(DeploymentPackage)} is about
- * to uninstall a deployment package.
- *
- * @param source the source package being uninstalled;
- * @param target the current installed package (can be new).
- */
- private void sendUninstallEvent(AbstractDeploymentPackage source, AbstractDeploymentPackage target) {
- Dictionary props = createEventProperties(source, target);
-
- m_eventAdmin.postEvent(new Event(EVENTTOPIC_UNINSTALL, props));
- }
-
- /**
- * Verifies that the version of the target matches the required source version range, and
- * whether all missing source resources are available in the target.
- *
- * @param source the fix-package source to verify;
- * @param target the target package to verify against.
- * @throws DeploymentException in case verification failed.
- */
- private void verifyFixPackage(AbstractDeploymentPackage source, AbstractDeploymentPackage target) throws DeploymentException {
- boolean newPackage = target.isNew();
-
- // Verify whether the target package exists, and if so, falls in the requested fix-package range...
- if (newPackage || (!source.getVersionRange().isInRange(target.getVersion()))) {
- m_log.log(LogService.LOG_ERROR, "Target package version '" + target.getVersion() + "' is not in source range '" + source.getVersionRange() + "'");
- throw new DeploymentException(CODE_MISSING_FIXPACK_TARGET, "Target package version '" + target.getVersion() + "' is not in source range '" + source.getVersionRange() + "'");
- }
-
- // Verify whether all missing bundles are available in the target package...
- BundleInfoImpl[] bundleInfos = source.getBundleInfoImpls();
- for (int i = 0; i < bundleInfos.length; i++) {
- if (bundleInfos[i].isMissing()) {
- // Check whether the bundle exists in the target package...
- BundleInfoImpl targetBundleInfo = target.getBundleInfoByPath(bundleInfos[i].getPath());
- if (targetBundleInfo == null) {
- m_log.log(LogService.LOG_ERROR, "Missing bundle '" + bundleInfos[i].getSymbolicName() + "/" + bundleInfos[i].getVersion() + " does not exist in target package!");
- throw new DeploymentException(CODE_MISSING_BUNDLE, "Missing bundle '" + bundleInfos[i].getSymbolicName() + "/" + bundleInfos[i].getVersion() + " does not exist in target package!");
- }
- }
- }
-
- // Verify whether all missing resources are available in the target package...
- ResourceInfoImpl[] resourceInfos = source.getResourceInfos();
- for (int i = 0; i < resourceInfos.length; i++) {
- if (resourceInfos[i].isMissing()) {
- // Check whether the resource exists in the target package...
- ResourceInfoImpl targetResourceInfo = target.getResourceInfoByPath(resourceInfos[i].getPath());
- if (targetResourceInfo == null) {
- m_log.log(LogService.LOG_ERROR, "Missing resource '" + resourceInfos[i].getPath() + " does not exist in target package!");
- throw new DeploymentException(CODE_MISSING_RESOURCE, "Missing resource '" + resourceInfos[i].getPath() + " does not exist in target package!");
- }
- }
- }
- }
-
- /**
- * Verifies whether none of the mentioned resources in the source package are present in
- * deployment packages other than the given target.
- *
- * @param source the source package to verify;
- * @param target the target package to verify against.
- * @throws DeploymentException in case verification fails.
- */
- private void verifyNoResourcesShared(AbstractDeploymentPackage source, AbstractDeploymentPackage target) throws DeploymentException {
- Bundle[] foreignBundles = getNonDeploymentPackagedBundles();
-
- // Verify whether all source bundles are available in the target package or absent...
- BundleInfoImpl[] bundleInfos = source.getBundleInfoImpls();
- for (int i = 0; i < bundleInfos.length; i++) {
- String symbolicName = bundleInfos[i].getSymbolicName();
- Version version = bundleInfos[i].getVersion();
-
- DeploymentPackage targetPackage = getDeploymentPackageContainingBundleWithSymbolicName(symbolicName);
- // If found, it should match the given target DP; not found is also ok...
- if ((targetPackage != null) && !targetPackage.equals(target)) {
- m_log.log(LogService.LOG_ERROR, "Bundle '" + symbolicName + "/" + version + " already present in other deployment packages!");
- throw new DeploymentException(CODE_BUNDLE_SHARING_VIOLATION, "Bundle '" + symbolicName + "/" + version + " already present in other deployment packages!");
- }
-
- if (targetPackage == null) {
- // Maybe the bundle is installed without deployment admin...
- for (int j = 0; j < foreignBundles.length; j++) {
- if (symbolicName.equals(foreignBundles[j].getSymbolicName()) && version.equals(foreignBundles[j].getVersion())) {
- m_log.log(LogService.LOG_ERROR, "Bundle '" + symbolicName + "/" + version + " already present!");
- throw new DeploymentException(CODE_BUNDLE_SHARING_VIOLATION, "Bundle '" + symbolicName + "/" + version + " already present!");
- }
- }
- }
- }
-
- // TODO verify other resources as well...
- }
-
- private void verifySourcePackage(AbstractDeploymentPackage source) throws DeploymentException {
- // TODO this method should do a X-ref check between DP-manifest and JAR-entries...
-// m_log.log(LogService.LOG_ERROR, "Missing bundle '" + symbolicName + "/" + bundleInfos[i].getVersion() +
-// " does not exist in target package!");
-// throw new DeploymentException(CODE_OTHER_ERROR, "Missing bundle '" + symbolicName + "/" + bundleInfos[i].getVersion()
-// + " is not part of target package!");
- }
-}
\ No newline at end of file
diff --git a/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/DeploymentPackageManifest.java b/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/DeploymentPackageManifest.java
deleted file mode 100644
index 00ac13bbf6..0000000000
--- a/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/DeploymentPackageManifest.java
+++ /dev/null
@@ -1,167 +0,0 @@
-/*
- * 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.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.jar.Attributes;
-import java.util.jar.Manifest;
-
-import org.osgi.framework.Version;
-import org.osgi.service.deploymentadmin.DeploymentException;
-
-/**
- * This class represents a manifest file used to describe the contents of a deployment package. It can verify the correctness of a
- * deployment package manifest and can interpret the various manifest entries and headers the OSGi specification defines.
- */
-public class DeploymentPackageManifest implements Constants {
- private final Manifest m_manifest;
- private final Version m_version;
- private final List m_bundleInfos = new ArrayList();
- private final List m_resourceInfos = new ArrayList();
- private final String m_symbolicName;
- private final VersionRange m_fixPackage;
-
- /**
- * Creates an instance of this class.
- *
- * @param manifest The manifest file to be used as deployment manifest
- * @throws DeploymentException If the specified manifest is not a valid deployment package manifest file.
- */
- public DeploymentPackageManifest(Manifest manifest) throws DeploymentException {
- if ((manifest == null) || (manifest.getMainAttributes() == null)) {
- throw new DeploymentException(CODE_BAD_HEADER);
- }
- m_manifest = manifest;
-
- Attributes mainAttributes = m_manifest.getMainAttributes();
-
- // TODO: verify symbolic name and entry-names for valid format/chars
- m_symbolicName = getNonNullHeader(mainAttributes.getValue(DEPLOYMENTPACKAGE_SYMBOLICMAME));
-
- String version = getNonNullHeader(mainAttributes.getValue(DEPLOYMENTPACKAGE_VERSION));
- try {
- m_version = new Version(version);
- }
- catch (IllegalArgumentException e) {
- throw new DeploymentException(CODE_BAD_HEADER);
- }
-
- String fixPackage = mainAttributes.getValue(DEPLOYMENTPACKAGE_FIXPACK);
- if (fixPackage != null) {
- try {
- m_fixPackage = VersionRange.parse(fixPackage);
- }
- catch (IllegalArgumentException iae) {
- throw new DeploymentException(CODE_BAD_HEADER, "Invalid version range for header: " + DEPLOYMENTPACKAGE_FIXPACK);
- }
- }
- else {
- m_fixPackage = null;
- }
-
- Map entries = m_manifest.getEntries();
- for (Iterator i = entries.keySet().iterator(); i.hasNext();) {
- String key = (String) i.next();
- processEntry(key, (Attributes) entries.get(key), (m_fixPackage != null));
- }
- }
-
- /**
- * Determines the value of a header in the main section of the manifest.
- *
- * @param header Name of the header to retrieve.
- * @return Value of the header or null if the header was not defined.
- */
- public String getHeader(String header) {
- return m_manifest.getMainAttributes().getValue(header);
- }
-
- /**
- * Determines the version range a fix package can be applied to
- *
- * @return A VersionRange describing the versions the fixpackage applies to, null if the package is not a fix package.
- */
- public VersionRange getFixPackage() {
- return m_fixPackage;
- }
-
- /**
- * Determines the symbolic name of the deployment package.
- *
- * @return String containing the symbolic name of the deployment package.
- */
- public String getSymbolicName() {
- return m_symbolicName;
- }
-
- /**
- * Determines the version of the deployment package.
- *
- * @return Version of the deployment package.
- */
- public Version getVersion() {
- return m_version;
- }
-
- /**
- * Determines which bundle resources are part of the deployment package, this includes customizer bundles.
- *
- * @return A List of <code>BundleInfoImpl</code> objects describing the bundle resources of the deployment package.
- */
- public List getBundleInfos() {
- return m_bundleInfos;
- }
-
- /**
- * Determines which processed resources are part of the deployment package.
- *
- * @return A list of <code>ResourceInfoImpl</code> objects describing the processed resources of the deployment package.
- */
- public List getResourceInfos() {
- return m_resourceInfos;
- }
-
- private void processEntry(String key, Attributes attributes, boolean isFixPack) throws DeploymentException {
- if (BundleInfoImpl.isBundleResource(attributes)) {
- BundleInfoImpl bundleInfo = new BundleInfoImpl(key, attributes);
- if (bundleInfo.isMissing() && !isFixPack) {
- throw new DeploymentException(CODE_BAD_HEADER, "Header '" + DEPLOYMENTPACKAGE_MISSING + "' for manifest entry '" + key + "' may only be 'true' if " + DEPLOYMENTPACKAGE_FIXPACK
- + " manifest header is 'true'");
- }
- m_bundleInfos.add(bundleInfo);
- }
- else {
- m_resourceInfos.add(new ResourceInfoImpl(key, attributes));
- }
- }
-
- private String getNonNullHeader(String header) throws DeploymentException {
- if (header == null) {
- throw new DeploymentException(CODE_MISSING_HEADER);
- }
- else if ("".equals(header.trim())) {
- throw new DeploymentException(CODE_BAD_HEADER);
- }
- return header;
- }
-
-}
diff --git a/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/FileDeploymentPackage.java b/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/FileDeploymentPackage.java
deleted file mode 100644
index f2a0454a84..0000000000
--- a/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/FileDeploymentPackage.java
+++ /dev/null
@@ -1,96 +0,0 @@
-/*
- * 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.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-import java.util.zip.GZIPInputStream;
-
-import org.osgi.framework.BundleContext;
-import org.osgi.service.deploymentadmin.DeploymentException;
-
-/**
- * Implementation of a <code>DeploymentPackage</code> that is persisted on disk.
- */
-public class FileDeploymentPackage extends AbstractDeploymentPackage {
- private final List m_index;
- private final File m_contentsDir;
-
- /**
- * Creates a new instance of a deployment package stored on disk.
- *
- * @param index Reference to the index file that contains the order in which all the resources of this deployment package were received
- * @param packageDir Reference to the directory in which the index and package contents are stored.
- * @param bundleContext The bundle context
- * @throws DeploymentException Thrown if the disk contents do not resemble a valid deployment package.
- * @throws IOException Thrown if there was a problem reading the resources from disk.
- */
- public FileDeploymentPackage(File index, File packageDir, BundleContext bundleContext, DeploymentAdminImpl deploymentAdmin) throws DeploymentException, IOException {
- this(Utils.readIndex(index), packageDir, bundleContext, deploymentAdmin);
- }
-
- private FileDeploymentPackage(List index, File packageDir, BundleContext bundleContext, DeploymentAdminImpl deploymentAdmin) throws DeploymentException, IOException {
- super(Utils.readManifest(new File(packageDir, (String) index.remove(0))), bundleContext, deploymentAdmin);
- m_index = index;
- m_contentsDir = packageDir;
- }
-
- public InputStream getBundleStream(String symbolicName) throws IOException {
- BundleInfoImpl bundleInfo = getBundleInfoByName(symbolicName);
- if (bundleInfo != null) {
- return new GZIPInputStream(new FileInputStream(new File(m_contentsDir, bundleInfo.getPath())));
- }
- return null;
- }
-
- public InputStream getCurrentEntryStream() {
- throw new UnsupportedOperationException("Not implemented for file-based deployment package");
- }
-
- public AbstractInfo getNextEntry() throws IOException {
- throw new UnsupportedOperationException("Not implemented for file-based deployment package");
- }
-
- public BundleInfoImpl[] getOrderedBundleInfos() {
- List result = new ArrayList();
- for (Iterator i = m_index.iterator(); i.hasNext();) {
- AbstractInfo bundleInfo = getBundleInfoByPath((String) i.next());
- if (bundleInfo != null) {
- result.add(bundleInfo);
- }
- }
- return (BundleInfoImpl[]) result.toArray(new BundleInfoImpl[result.size()]);
- }
-
- public ResourceInfoImpl[] getOrderedResourceInfos() {
- List result = new ArrayList();
- for (Iterator i = m_index.iterator(); i.hasNext();) {
- AbstractInfo resourceInfo = getResourceInfoByPath((String) i.next());
- if (resourceInfo != null) {
- result.add(resourceInfo);
- }
- }
- return (ResourceInfoImpl[]) result.toArray(new ResourceInfoImpl[result.size()]);
- }
-}
\ No newline at end of file
diff --git a/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/NonCloseableStream.java b/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/NonCloseableStream.java
deleted file mode 100644
index 7c68997ecb..0000000000
--- a/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/NonCloseableStream.java
+++ /dev/null
@@ -1,95 +0,0 @@
-/*
- * 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.IOException;
-import java.io.InputStream;
-
-/**
- * Stream that does nothing when close() is invoked, calls to one of the read methods will throw an <code>IOException</code>
- * after close() is called. Also, mark/reset is not supported. Deployment Admin can use this class to pass on as an <code>InputStream</code>
- * to a resource processor.
- *
- */
-public class NonCloseableStream extends InputStream {
- private final InputStream m_input;
- private volatile boolean m_closed;
-
- public NonCloseableStream(InputStream input) {
- m_input = input;
- }
-
- public int available() throws IOException {
- return m_input.available();
- }
-
- public void close() throws IOException {
- // stream should not be actually closed, subsequent calls to read methods will throw an exception though
- assertOpen();
- m_closed = true;
- }
-
- public boolean equals(Object obj) {
- return m_input.equals(obj);
- }
-
- public int hashCode() {
- return m_input.hashCode();
- }
-
- public void mark(int readlimit) {
- // do nothing
- }
-
- public boolean markSupported() {
- return false;
- }
-
- public int read() throws IOException {
- return m_input.read();
- }
-
- public int read(byte[] b) throws IOException {
- assertOpen();
- return m_input.read(b);
- }
-
- public int read(byte[] b, int off, int len) throws IOException {
- assertOpen();
- return m_input.read(b, off, len);
- }
-
- public void reset() throws IOException {
- throw new IOException("Mark and reset are not available on this type of stream.");
- }
-
- public long skip(long n) throws IOException {
- return m_input.skip(n);
- }
-
- public String toString() {
- return m_input.toString();
- }
-
- private void assertOpen() throws IOException {
- if (m_closed) {
- throw new IOException("Unable to read, stream is closed.");
- }
- }
-}
diff --git a/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/ResourceInfoImpl.java b/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/ResourceInfoImpl.java
deleted file mode 100644
index dc43c3800b..0000000000
--- a/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/ResourceInfoImpl.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * 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.util.jar.Attributes;
-
-import org.osgi.service.deploymentadmin.DeploymentException;
-
-/**
- * This class represents the meta data of a processed resource as used by the Deployment Admin.
- */
-public class ResourceInfoImpl extends AbstractInfo {
-
- private final String m_resourceProcessor;
-
- /**
- * Create an instance of this class.
- *
- * @param path String containing the path / resource-id of the processed resource.
- * @param attributes Attributes containing the meta data of the resource.
- * @throws DeploymentException If the specified attributes do not describe a processed resource.
- */
- public ResourceInfoImpl(String path, Attributes attributes) throws DeploymentException {
- super(path, attributes);
-
- String rp = attributes.getValue(RESOURCE_PROCESSOR);
- if (rp != null && "".equals(rp.trim())) {
- rp = null;
- }
-
- m_resourceProcessor = rp;
- }
-
- /**
- * @return <code>true</code> if this resource needs to be processed by a customizer/resource processor,
- * <code>false</code> otherwise.
- */
- public boolean isProcessedResource() {
- return m_resourceProcessor != null;
- }
-
- /**
- * Determines the resource processor for this processed resource.
- *
- * @return String containing the PID of the resource processor that should handle this processed resource.
- */
- public String getResourceProcessor() {
- return m_resourceProcessor;
- }
-}
diff --git a/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/Semaphore.java b/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/Semaphore.java
deleted file mode 100644
index a9f20e201d..0000000000
--- a/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/Semaphore.java
+++ /dev/null
@@ -1,121 +0,0 @@
-/*
- * 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;
-
-/**
- * A semaphore, that maintains one single permit. An <code>acquire()</code> blocks until a permit is
- * available, whilst <code>release()</code> will unblock it.
- */
-public class Semaphore {
- private boolean m_available;
-
- /**
- * Creates a new semaphore that is available.
- */
- public Semaphore() {
- m_available = true;
- }
-
- /**
- * Creates a new semaphore and allows you to specify if it's available or not.
- *
- * @param isAvailable should the semaphore be available or not
- */
- public Semaphore(boolean isAvailable) {
- m_available = isAvailable;
- }
-
- /**
- * Acquires the semaphore, or blocks until it's available or the thread is interrupted.
- *
- * @throws InterruptedException when the thread is interrupted
- */
- public void acquire() throws InterruptedException {
- if (Thread.interrupted()) {
- throw new InterruptedException();
- }
- synchronized (this) {
- try {
- if (!m_available) {
- wait();
- }
- m_available = false;
- }
- catch (InterruptedException ie) {
- notify();
- throw ie;
- }
- }
- }
-
- /**
- * Tries to acquire the semaphore and waits for the duration of the specified timeout
- * until it becomes available.
- *
- * @param timeout the number of milliseconds to wait
- * @return <code>true</code> if the semaphore was acquired, <code>false</code> if it was
- * not after waiting for the specified amount of time
- * @throws InterruptedException when the thread is interrupted
- */
- public boolean tryAcquire(long timeout) throws InterruptedException {
- if (Thread.interrupted()) {
- throw new InterruptedException();
- }
- synchronized (this) {
- if (m_available) {
- m_available = false;
- return true;
- }
- else if (timeout <= 0) {
- return false;
- }
- else {
- long startTime = System.currentTimeMillis();
- try {
- while (true) {
- wait(timeout);
- if (m_available) {
- m_available = false;
- return true;
- }
- else {
- timeout -= (System.currentTimeMillis() - startTime);
- if (timeout <= 0) {
- return false;
- }
- }
- }
- }
- catch (InterruptedException ie) {
- notify();
- throw ie;
- }
- }
- }
- }
-
- /**
- * Releases the semaphore. If threads were waiting, one of them is
- * notified.
- */
- public synchronized void release() {
- m_available = true;
- notify();
- }
-}
diff --git a/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/StreamDeploymentPackage.java b/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/StreamDeploymentPackage.java
deleted file mode 100644
index 4c88d9c722..0000000000
--- a/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/StreamDeploymentPackage.java
+++ /dev/null
@@ -1,117 +0,0 @@
-/*
- * 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.IOException;
-import java.io.InputStream;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-import java.util.jar.JarInputStream;
-import java.util.zip.ZipEntry;
-
-import org.osgi.framework.BundleContext;
-import org.osgi.service.deploymentadmin.DeploymentException;
-
-/**
- * This class represents a deployment package that is read from a jar stream.
- */
-public class StreamDeploymentPackage extends AbstractDeploymentPackage {
- private final JarInputStream m_input;
- private final List m_names = new ArrayList();
- private boolean m_inMetaInf = true;
-
- /**
- * Creates an instance of this class.
- *
- * @param input The stream from which the deployment package can be read.
- * @param bundleContext The bundle context.
- * @throws DeploymentException If it was not possible to read a valid deployment package from the specified stream.
- */
- public StreamDeploymentPackage(JarInputStream input, BundleContext bundleContext, DeploymentAdminImpl deploymentAdmin) throws DeploymentException {
- super(input.getManifest(), bundleContext, deploymentAdmin);
- m_input = input;
- }
-
- public InputStream getBundleStream(String symbolicName) {
- throw new UnsupportedOperationException("Not applicable for stream-based deployment package");
- }
-
- public InputStream getCurrentEntryStream() {
- return new NonCloseableStream(m_input);
- }
-
- public AbstractInfo getNextEntry() throws IOException {
- String name;
-
- boolean metaInfFile = true;
- do {
- ZipEntry nextEntry = m_input.getNextJarEntry();
- if (nextEntry == null) {
- return null;
- }
- name = nextEntry.getName();
-
- // FELIX-518: do not try to process signature or localization files...
- metaInfFile = isMetaInfFile(name);
- if (metaInfFile) {
- if (!m_inMetaInf) {
- throw new IOException("Unexpected signature file found after manifest files: " + name);
- }
- else {
- continue;
- }
- }
- }
- while (metaInfFile);
-
- m_inMetaInf = false;
- m_names.add(name);
-
- return getAbstractInfoByPath(name);
- }
-
- // This only works for those resources that have been read from the stream already, no guarantees for remainder of
- // stream
- public BundleInfoImpl[] getOrderedBundleInfos() {
- List result = new ArrayList();
-
- // add all bundle resources ordered by location in stream
- for (Iterator i = m_names.iterator(); i.hasNext();) {
- String indexEntry = (String) i.next();
- AbstractInfo bundleInfo = getBundleInfoByPath(indexEntry);
- if (bundleInfo != null) {
- result.add(bundleInfo);
- }
- }
-
- // add bundle resources marked missing to the end of the result
- BundleInfoImpl[] bundleInfoImpls = getBundleInfoImpls();
- for (int i = 0; i < bundleInfoImpls.length; i++) {
- if (bundleInfoImpls[i].isMissing()) {
- result.add(bundleInfoImpls[i]);
- }
- }
- return (BundleInfoImpl[]) result.toArray(new BundleInfoImpl[result.size()]);
- }
-
- public ResourceInfoImpl[] getOrderedResourceInfos() {
- throw new UnsupportedOperationException("Not applicable for stream-based deployment package");
- }
-}
\ No newline at end of file
diff --git a/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/Utils.java b/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/Utils.java
deleted file mode 100644
index daebd3edb6..0000000000
--- a/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/Utils.java
+++ /dev/null
@@ -1,241 +0,0 @@
-/*
- * 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.BufferedReader;
-import java.io.Closeable;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.FileReader;
-import java.io.FileWriter;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.io.PrintWriter;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-import java.util.jar.Attributes;
-import java.util.jar.JarFile;
-import java.util.jar.Manifest;
-import java.util.jar.Attributes.Name;
-import java.util.zip.GZIPInputStream;
-import java.util.zip.GZIPOutputStream;
-
-public class Utils {
- private static final String MANIFEST_NAME = JarFile.MANIFEST_NAME;
-
- 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 {
- closeSilently(is);
- }
- return mf;
- }
-
- public static boolean replace(File target, File source) {
- return delete(target, true /* deleteRoot */) && rename(source, target);
- }
-
- public static boolean copy(File from, File to) {
- boolean result = true;
- if (from.isDirectory()) {
- if (!to.isDirectory()) {
- if (!to.mkdirs()) {
- return false;
- }
- File[] files = from.listFiles();
- if (files == null) {
- return false;
- }
- for (int i = 0; i < files.length; i++) {
- result &= copy(files[i], new File(to, files[i].getName()));
- }
- }
- }
- else {
- InputStream input = null;
- OutputStream output = null;
- try {
- input = new FileInputStream(from);
- output = new FileOutputStream(to);
- byte[] buffer = new byte[4096];
- for (int i = input.read(buffer); i > -1; i = input.read(buffer)) {
- output.write(buffer, 0, i);
- }
- }
- catch (IOException e) {
- return false;
- }
- finally {
- if (!closeSilently(output)) {
- result = false;
- }
- if (!closeSilently(input)) {
- result = false;
- }
- }
- }
- return result;
- }
-
- public static boolean rename(File from, File to) {
- if (!from.renameTo(to)) {
- if (copy(from, to)) {
- if (!delete(from, true /* deleteRoot */)) {
- return false;
- }
- }
- else {
- return false;
- }
- }
- return true;
- }
-
- public static boolean delete(File root, boolean deleteRoot) {
- boolean result = true;
- if (root.isDirectory()) {
- File[] files = root.listFiles();
- for (int i = 0; i < files.length; i++) {
- if (files[i].isDirectory()) {
- result &= delete(files[i], true);
- }
- else {
- result &= files[i].delete();
- }
- }
- }
- if (deleteRoot) {
- if (root.exists()) {
- result &= root.delete();
- }
- }
- return result;
- }
-
- public static void merge(File targetIndex, File target, File sourceIndex, File source) throws IOException {
- List targetFiles = readIndex(targetIndex);
- List sourceFiles = readIndex(sourceIndex);
- List result = new ArrayList(targetFiles);
-
- File manifestFile = new File(source, (String) sourceFiles.remove(0));
- Manifest resultManifest = Utils.readManifest(manifestFile);
-
- resultManifest.getMainAttributes().remove(new Name(Constants.DEPLOYMENTPACKAGE_FIXPACK));
-
- for (Iterator i = result.iterator(); i.hasNext();) {
- String targetFile = (String) i.next();
- if (!MANIFEST_NAME.equals(targetFile) && !resultManifest.getEntries().containsKey(targetFile)) {
- i.remove();
- }
- }
-
- for (Iterator iter = sourceFiles.iterator(); iter.hasNext();) {
- String path = (String) iter.next();
- File from = new File(source, path);
- File to = new File(target, path);
- if (targetFiles.contains(path)) {
- if (!to.delete()) {
- throw new IOException("Could not delete " + to);
- }
- }
- else {
- result.add(path);
- }
- if (!rename(from, to)) {
- throw new IOException("Could not rename " + from + " to " + to);
- }
- }
-
- targetFiles.removeAll(sourceFiles);
-
- for (Iterator iter = resultManifest.getEntries().keySet().iterator(); iter.hasNext();) {
- String path = (String) iter.next();
- Attributes sourceAttribute = (Attributes) resultManifest.getEntries().get(path);
- if ("true".equals(sourceAttribute.remove(new Name(Constants.DEPLOYMENTPACKAGE_MISSING)))) {
- targetFiles.remove(path);
- }
- }
-
- for (Iterator iter = targetFiles.iterator(); iter.hasNext();) {
- String path = (String) iter.next();
- File targetFile = new File(target, path);
- if (!targetFile.delete()) {
- throw new IOException("Could not delete " + targetFile);
- }
- }
-
- GZIPOutputStream outputStream = new GZIPOutputStream(new FileOutputStream(new File(target, MANIFEST_NAME)));
- try {
- resultManifest.write(outputStream);
- }
- finally {
- outputStream.close();
- }
- writeIndex(targetIndex, result);
- }
-
- public static List readIndex(File index) throws IOException {
- BufferedReader reader = null;
- try {
- reader = new BufferedReader(new FileReader(index));
- List result = new ArrayList();
- for (String line = reader.readLine(); line != null; line = reader.readLine()) {
- result.add(line);
- }
- return result;
- }
- finally {
- closeSilently(reader);
- }
- }
-
- static boolean closeSilently(Closeable closeable) {
- if (closeable != null) {
- try {
- closeable.close();
- }
- catch (IOException exception) {
- // Ignore; nothing we can do about this...
- return false;
- }
- }
- return true;
- }
-
- private static void writeIndex(File index, List input) throws IOException {
- PrintWriter writer = null;
- try {
- writer = new PrintWriter(new FileWriter(index));
- for (Iterator iterator = input.iterator(); iterator.hasNext();) {
- writer.println(iterator.next());
- }
- }
- finally {
- closeSilently(writer);
- }
- }
-}
diff --git a/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/VersionRange.java b/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/VersionRange.java
deleted file mode 100644
index f1e28382eb..0000000000
--- a/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/VersionRange.java
+++ /dev/null
@@ -1,156 +0,0 @@
-/*
- * 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 org.osgi.framework.Version;
-
-/**
- * This class represents a version range as defined in section 3.2.5 of the OSGi r4 specification.
- */
-public class VersionRange {
-
- public static final VersionRange infiniteRange = new VersionRange(Version.emptyVersion, true, null, true);
-
- private Version m_low = null;
- private boolean m_isLowInclusive = false;
- private Version m_high = null;
- private boolean m_isHighInclusive = false;
- private String m_toString = null;
-
- /**
- * Create an instance of the VersionRange class.
- *
- * @param low Lower bound version
- * @param isLowInclusive True if lower bound should be included in the range
- * @param high Upper bound version
- * @param isHighInclusive True if upper bound should be included in the range
- */
- public VersionRange(Version low, boolean isLowInclusive, Version high, boolean isHighInclusive) {
- m_low = low;
- m_isLowInclusive = isLowInclusive;
- m_high = high;
- m_isHighInclusive = isHighInclusive;
- }
-
- /**
- * Creates an instance of the VersionRange class which resembles [version,*)
- *
- * @param version The lower boundary of the version range
- */
- public VersionRange(Version version) {
- this(version, true, null, false);
- }
-
- /**
- * Get the lower boundary of the version range, the boundary being inclusive or not is not taken into account.
- *
- * @return Version resembling the lower boundary of the version range
- */
- public Version getLow() {
- return m_low;
- }
-
- /**
- * Determines whether the lower boundary is inclusive or not.
- *
- * @return True if the lower boundary is inclusive, false otherwise.
- */
- public boolean isLowInclusive() {
- return m_isLowInclusive;
- }
-
- /**
- * Get the upper boundary of the version range, the boundary being inclusive or not is not taken in to account.
- *
- * @return Version resembling the upper boundary of the version range.
- */
- public Version getHigh() {
- return m_high;
- }
-
- /**
- * Determines whether the upper boundary is inclusive or not.
- *
- * @return True if the upper boundary is inclusive, false otherwise.
- */
- public boolean isHighInclusive() {
- return m_isHighInclusive;
- }
-
- /**
- * Determine if the specified version is part of the version range or not.
- *
- * @param version The version to verify
- * @return True if the specified version is included in this version range, false otherwise.
- */
- public boolean isInRange(Version version) {
- // We might not have an upper end to the range.
- if (m_high == null) {
- return (version.compareTo(m_low) >= 0);
- }
- else if (isLowInclusive() && isHighInclusive()) {
- return (version.compareTo(m_low) >= 0) && (version.compareTo(m_high) <= 0);
- }
- else if (isHighInclusive()) {
- return (version.compareTo(m_low) > 0) && (version.compareTo(m_high) <= 0);
- }
- else if (isLowInclusive()) {
- return (version.compareTo(m_low) >= 0) && (version.compareTo(m_high) < 0);
- }
- return (version.compareTo(m_low) > 0) && (version.compareTo(m_high) < 0);
- }
-
- /**
- * Parses a version range from the specified string.
- *
- * @param range String representation of the version range.
- * @return A <code>VersionRange</code> object representing the version range.
- * @throws IllegalArgumentException If <code>range</code> is improperly formatted.
- */
- public static VersionRange parse(String range) throws IllegalArgumentException {
- // Check if the version is an interval.
- if (range.indexOf(',') >= 0) {
- String s = range.substring(1, range.length() - 1);
- String vlo = s.substring(0, s.indexOf(',')).trim();
- String vhi = s.substring(s.indexOf(',') + 1, s.length()).trim();
- return new VersionRange(new Version(vlo), (range.charAt(0) == '['), new Version(vhi), (range.charAt(range.length() - 1) == ']'));
- }
- else {
- return new VersionRange(new Version(range), true, null, false);
- }
- }
-
- public String toString() {
- if (m_toString == null) {
- if (m_high != null) {
- StringBuffer sb = new StringBuffer();
- sb.append(m_isLowInclusive ? '[' : '(');
- sb.append(m_low.toString());
- sb.append(',');
- sb.append(m_high.toString());
- sb.append(m_isHighInclusive ? ']' : ')');
- m_toString = sb.toString();
- }
- else {
- m_toString = m_low.toString();
- }
- }
- return m_toString;
- }
-}
diff --git a/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/AbstractAction.java b/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/AbstractAction.java
deleted file mode 100644
index 44d1c9499f..0000000000
--- a/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/AbstractAction.java
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * 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.spi;
-
-/**
- * Base implementation for commit/rollback actions with proper error handling.
- *
- * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
- */
-abstract class AbstractAction implements Runnable {
- /**
- * Runs this action by calling {@link #doRun()} and in case of failure, {@link #onFailure(Exception)}.
- */
- public final void run() {
- try {
- doRun();
- }
- catch (Exception e) {
- onFailure(e);
- }
- }
-
- protected abstract void doRun() throws Exception;
-
- protected void onFailure(Exception e) {
- // Nop
- }
-}
diff --git a/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/Command.java b/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/Command.java
deleted file mode 100644
index 4529de00ff..0000000000
--- a/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/Command.java
+++ /dev/null
@@ -1,186 +0,0 @@
-/*
- * 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.spi;
-
-import java.io.Closeable;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.ListIterator;
-
-import org.apache.felix.deploymentadmin.Constants;
-import org.osgi.framework.Bundle;
-import org.osgi.service.deploymentadmin.DeploymentException;
-
-/**
- * Commands describe a group of tasks to be executed within the execution a
- * deployment session. A command that has already executed can be rolled back
- * and a command that is currently in progress can be signaled to stop it's
- * activities by canceling it.
- */
-public abstract class Command implements Constants {
-
- private final List m_rollback = new ArrayList();
- private final List m_commit = new ArrayList();
-
- private volatile boolean m_cancelled;
-
- /**
- * Executes the command, the specified <code>DeploymentSession</code> can be
- * used to obtain various information about the deployment session which the
- * command is part of.
- *
- * @param session The deployment session this command is part of.
- * @throws DeploymentException Thrown if the command could not successfully
- * execute.
- */
- public final void execute(DeploymentSessionImpl session) throws DeploymentException {
- try {
- doExecute(session);
- }
- catch (Exception e) {
- if (e instanceof DeploymentException) {
- throw (DeploymentException) e;
- }
- throw new DeploymentException(CODE_OTHER_ERROR, "Command failed!", e);
- }
- }
-
- /**
- * Executes the command, the specified <code>DeploymentSession</code> can be
- * used to obtain various information about the deployment session which the
- * command is part of.
- *
- * @param session The deployment session this command is part of.
- * @throws Exception in case of this command could not terminate
- * successfully.
- */
- protected abstract void doExecute(DeploymentSessionImpl session) throws Exception;
-
- /**
- * Rolls back all actions that were added through the
- * <code>addRollback(Runnable r)</code> method (in reverse adding order). It
- * is not guaranteed that the state of everything related to the command
- * will be as if the command was never executed, a best effort should be
- * made though.
- *
- * @param session the deployment session to rollback, should be used for
- * logging purposes.
- */
- protected void rollback(DeploymentSessionImpl session) {
- try {
- for (ListIterator i = m_rollback.listIterator(m_rollback.size()); i.hasPrevious();) {
- Runnable runnable = (Runnable) i.previous();
- runnable.run();
- }
- }
- finally {
- cleanUp();
- }
- }
-
- /**
- * Commits all changes the command may have defined when it was executed by
- * calling the <code>execute()</code> method.
- *
- * @param session the deployment session to commit, should be used for
- * logging purposes.
- */
- protected final void commit(DeploymentSessionImpl session) {
- try {
- for (ListIterator i = m_commit.listIterator(); i.hasNext();) {
- Runnable runnable = (Runnable) i.next();
- runnable.run();
- }
- }
- finally {
- cleanUp();
- }
- }
-
- private void cleanUp() {
- m_rollback.clear();
- m_commit.clear();
- m_cancelled = false;
- }
-
- /**
- * Determines if the command was canceled. This method should be used
- * regularly by implementing classes to determine if their command was
- * canceled, if so they should return as soon as possible from their
- * operations.
- *
- * @return true if the command was canceled, false otherwise.
- */
- protected boolean isCancelled() {
- return m_cancelled;
- }
-
- /**
- * Adds an action to be executed in case of a roll back.
- *
- * @param runnable The runnable to be executed in case of a roll back.
- */
- protected void addRollback(AbstractAction runnable) {
- m_rollback.add(runnable);
- }
-
- /**
- * Adds an action to be executed in case of a commit
- *
- * @param runnable The runnable to be executes in case of a commit.
- */
- protected void addCommit(AbstractAction runnable) {
- m_commit.add(runnable);
- }
-
- /**
- * Sets the command to being cancelled, this does not have an immediate
- * effect. Commands that are executing should check regularly if they were
- * cancelled and if so they should make an effort to stop their operations
- * as soon as possible followed by throwing an
- * <code>DeploymentException.CODE_CANCELLED</code> exception.
- */
- public void cancel() {
- m_cancelled = true;
- }
-
- /**
- * Determines whether a given bundle is actually a fragment bundle.
- *
- * @param bundle the bundle to test, cannot be <code>null</code>.
- * @return <code>true</code> if the given bundle is actually a fragment
- * bundle, <code>false</code> otherwise.
- */
- static final boolean isFragmentBundle(Bundle bundle) {
- Object fragmentHost = bundle.getHeaders().get(FRAGMENT_HOST);
- return fragmentHost != null;
- }
-
- static final void closeSilently(Closeable resource) {
- if (resource != null) {
- try {
- resource.close();
- }
- catch (IOException e) {
- // Not much we can do...
- }
- }
- }
-}
diff --git a/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/CommitResourceCommand.java b/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/CommitResourceCommand.java
deleted file mode 100644
index 171337a02c..0000000000
--- a/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/CommitResourceCommand.java
+++ /dev/null
@@ -1,105 +0,0 @@
-/*
- * 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.spi;
-
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-import java.util.ListIterator;
-
-import org.osgi.service.deploymentadmin.DeploymentException;
-import org.osgi.service.deploymentadmin.spi.ResourceProcessor;
-import org.osgi.service.deploymentadmin.spi.ResourceProcessorException;
-import org.osgi.service.log.LogService;
-
-/**
- * Command that commits all the resource processors that were added to the
- * command.
- */
-public class CommitResourceCommand extends Command {
-
- private final List m_processors = new ArrayList();
-
- protected void doExecute(DeploymentSessionImpl session) throws Exception {
- for (ListIterator i = m_processors.listIterator(m_processors.size()); i.hasPrevious();) {
- ResourceProcessor processor = (ResourceProcessor) i.previous();
- try {
- processor.prepare();
- }
- catch (ResourceProcessorException e) {
- session.getLog().log(LogService.LOG_ERROR, "Preparing commit for resource processor failed", e);
- // Check what error code we got...
- if (e.getCode() == ResourceProcessorException.CODE_PREPARE) {
- throw new DeploymentException(CODE_COMMIT_ERROR, "Preparing commit for resource processor failed!", e);
- }
- throw new DeploymentException(e.getCode(), "Preparing commit for resource processor failed!", e);
- }
- catch (Exception e) {
- session.getLog().log(LogService.LOG_ERROR, "Preparing commit for resource processor failed", e);
- throw new DeploymentException(CODE_OTHER_ERROR, "Preparing commit for resource processor failed", e);
- }
- }
- for (ListIterator i = m_processors.listIterator(m_processors.size()); i.hasPrevious();) {
- ResourceProcessor processor = (ResourceProcessor) i.previous();
- try {
- processor.commit();
- }
- catch (Exception e) {
- // We cannot throw an exception, see OSGi spec.
- session.getLog().log(LogService.LOG_ERROR, "Committing resource processor '" + processor + "' failed", e);
- }
- }
- m_processors.clear();
- }
-
- protected void rollback(DeploymentSessionImpl session) {
- for (ListIterator i = m_processors.listIterator(m_processors.size()); i.hasPrevious();) {
- ResourceProcessor processor = (ResourceProcessor) i.previous();
- try {
- processor.rollback();
- }
- catch (Exception e) {
- // We cannot throw an exception, see OSGi spec.
- session.getLog().log(LogService.LOG_ERROR, "Rollback of resource processor '" + processor + "' failed", e);
- }
- finally {
- i.remove();
- }
- }
- }
-
- /**
- * Add a resource processor, all resource processors that are added will be
- * committed when the command is executed.
- *
- * @param processor The resource processor to add.
- * @return true if the resource processor was added, false if it was already
- * added.
- */
- public boolean addResourceProcessor(ResourceProcessor processor) {
- for (Iterator i = m_processors.iterator(); i.hasNext();) {
- ResourceProcessor proc = (ResourceProcessor) i.next();
- if (proc == processor) {
- return false;
- }
- }
- m_processors.add(processor);
- return true;
- }
-}
diff --git a/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/DeploymentSessionImpl.java b/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/DeploymentSessionImpl.java
deleted file mode 100644
index 3c8cc1da66..0000000000
--- a/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/DeploymentSessionImpl.java
+++ /dev/null
@@ -1,214 +0,0 @@
-/*
- * 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.spi;
-
-import java.io.File;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-import java.util.ListIterator;
-
-import org.apache.felix.deploymentadmin.AbstractDeploymentPackage;
-import org.apache.felix.deploymentadmin.Constants;
-import org.apache.felix.deploymentadmin.DeploymentAdminConfig;
-import org.apache.felix.deploymentadmin.DeploymentAdminImpl;
-import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleContext;
-import org.osgi.service.deploymentadmin.DeploymentException;
-import org.osgi.service.deploymentadmin.DeploymentPackage;
-import org.osgi.service.deploymentadmin.spi.DeploymentSession;
-import org.osgi.service.log.LogService;
-import org.osgi.service.packageadmin.PackageAdmin;
-
-/**
- * Represents a running deployment session.
- */
-public class DeploymentSessionImpl implements DeploymentSession, Constants {
-
- private final AbstractDeploymentPackage m_target;
- private final AbstractDeploymentPackage m_source;
- private final List m_commands;
- private final DeploymentAdminImpl m_admin;
- private final DeploymentAdminConfig m_config;
-
- private volatile Command m_currentCommand = null;
- private volatile boolean m_cancelled;
-
- public DeploymentSessionImpl(AbstractDeploymentPackage source, AbstractDeploymentPackage target, List commands, DeploymentAdminImpl admin, DeploymentAdminConfig config) {
- m_source = source;
- m_target = target;
- m_commands = commands;
- m_admin = admin;
- m_config = config;
- }
-
- /**
- * Calling this method will cause the commands specified for this session to
- * be executed. the commands will be rolled back if the session is canceled
- * or if an exception is caused by one of the commands.
- *
- * @throws DeploymentException If the session was canceled (
- * <code>DeploymentException.CODE_CANCELLED</code>) or if one of the
- * commands caused an exception (<code>DeploymentException.*</code>)
- */
- public void call(boolean ignoreExceptions) throws DeploymentException {
- List executedCommands = new ArrayList();
- for (Iterator i = m_commands.iterator(); i.hasNext();) {
- if (m_cancelled) {
- // previous command did not pick up on cancel
- rollback(executedCommands);
- throw new DeploymentException(CODE_CANCELLED);
- }
- m_currentCommand = (Command) i.next();
- try {
- executedCommands.add(m_currentCommand);
- m_currentCommand.execute(this);
- }
- catch (DeploymentException de) {
- if (!ignoreExceptions) {
- // XXX catch exception and verify whether it is possible to
- // have exceptions during a rollback
- rollback(executedCommands);
- throw de;
- } else {
- m_admin.getLog().log(LogService.LOG_DEBUG, "Ignoring exception as requested!", de);
- }
- }
- }
- for (Iterator i = m_commands.iterator(); i.hasNext();) {
- ((Command) i.next()).commit(this);
- }
- m_currentCommand = null;
- }
-
- /**
- * Cancels the session if it is in progress.
- *
- * @return true if a session was in progress and now canceled, false
- * otherwise.
- */
- public boolean cancel() {
- m_cancelled = true;
-
- Command currentCommand = m_currentCommand;
- if (currentCommand != null) {
- currentCommand.cancel();
- return true;
- }
-
- return false;
- }
-
- /**
- * Returns the bundle context of the bundle this class is part of.
- *
- * @return The <code>BundleContext</code>.
- */
- public BundleContext getBundleContext() {
- return m_admin.getBundleContext();
- }
-
- /**
- * @return the configuration for this session, is guaranteed to remain stable during this session, never
- * <code>null</code>.
- */
- public DeploymentAdminConfig getConfiguration() {
- return m_config;
- }
-
- /**
- * Retrieve the base directory of the persistent storage area according to
- * OSGi Core R4 6.1.6.10 for the given <code>BundleContext</code>.
- *
- * @param bundle of which the storage area will be returned
- * @return a <code>File</code> that represents the base directory of the
- * persistent storage area for the bundle
- */
- public File getDataFile(Bundle bundle) {
- File result = null;
-
- BundleContext context = bundle.getBundleContext();
- if (context != null) {
- result = context.getDataFile("");
- }
- else {
- // TODO this method should not return null or throw an exception; we
- // need to resolve this...
- throw new IllegalStateException("Could not retrieve valid bundle context from bundle " + bundle.getSymbolicName());
- }
-
- if (result == null) {
- throw new IllegalStateException("Could not retrieve base directory for bundle " + bundle.getSymbolicName());
- }
- return result;
- }
-
- /**
- * Returns the currently present log service.
- *
- * @return The <code>LogService</code>.
- */
- public LogService getLog() {
- return m_admin.getLog();
- }
-
- /**
- * Returns the currently present package admin.
- *
- * @return The <code>PackageAdmin</code>
- */
- public PackageAdmin getPackageAdmin() {
- return m_admin.getPackageAdmin();
- }
-
- /**
- * Returns the source deployment package as an
- * <code>AbstractDeploymentPackage</code>.
- *
- * @return The source deployment packge of the session.
- */
- public AbstractDeploymentPackage getSourceAbstractDeploymentPackage() {
- return m_source;
- }
-
- public DeploymentPackage getSourceDeploymentPackage() {
- return m_source;
- }
-
- /**
- * Returns the target deployment package as an
- * <code>AbstractDeploymentPackage</code>.
- *
- * @return The target deployment package of the session.
- */
- public AbstractDeploymentPackage getTargetAbstractDeploymentPackage() {
- return m_target;
- }
-
- public DeploymentPackage getTargetDeploymentPackage() {
- return m_target;
- }
-
- private void rollback(List executedCommands) {
- for (ListIterator i = executedCommands.listIterator(executedCommands.size()); i.hasPrevious();) {
- Command command = (Command) i.previous();
- command.rollback(this);
- }
- }
-}
\ No newline at end of file
diff --git a/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/DropAllBundlesCommand.java b/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/DropAllBundlesCommand.java
deleted file mode 100644
index 48ca3ffe49..0000000000
--- a/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/DropAllBundlesCommand.java
+++ /dev/null
@@ -1,86 +0,0 @@
-/*
- * 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.spi;
-
-import java.io.InputStream;
-
-import org.apache.felix.deploymentadmin.AbstractDeploymentPackage;
-import org.apache.felix.deploymentadmin.BundleInfoImpl;
-import org.osgi.framework.Bundle;
-import org.osgi.service.log.LogService;
-
-/**
- * Command that uninstalls all bundles, if rolled back the bundles are restored.
- */
-public class DropAllBundlesCommand extends Command {
-
- protected void doExecute(DeploymentSessionImpl session) throws Exception {
- AbstractDeploymentPackage target = session.getTargetAbstractDeploymentPackage();
- LogService log = session.getLog();
-
- BundleInfoImpl[] orderedTargetBundles = target.getOrderedBundleInfos();
- for (int i = orderedTargetBundles.length - 1; i >= 0; i--) {
- BundleInfoImpl bundleInfo = orderedTargetBundles[i];
- // stale bundle, save a copy for rolling back and uninstall it
- String symbolicName = bundleInfo.getSymbolicName();
- try {
- Bundle bundle = target.getBundle(symbolicName);
- if (bundle != null) {
- bundle.uninstall();
- addRollback(new InstallBundleRunnable(bundle, target, log));
- }
- }
- catch (Exception be) {
- log.log(LogService.LOG_WARNING, "Bundle '" + symbolicName + "' could not be uninstalled", be);
- }
- }
- }
-
- private static class InstallBundleRunnable extends AbstractAction {
- private final AbstractDeploymentPackage m_target;
- private final Bundle m_bundle;
- private final LogService m_log;
-
- public InstallBundleRunnable(Bundle bundle, AbstractDeploymentPackage target, LogService log) {
- m_bundle = bundle;
- m_target = target;
- m_log = log;
- }
-
- protected void doRun() throws Exception {
- InputStream is = null;
- try {
- is = m_target.getBundleStream(m_bundle.getSymbolicName());
- if (is != null) {
- m_bundle.update(is);
- }
- else {
- throw new RuntimeException("Unable to get inputstream for bundle '" + m_bundle.getSymbolicName() + "'");
- }
- }
- finally {
- closeSilently(is);
- }
- }
-
- protected void onFailure(Exception e) {
- m_log.log(LogService.LOG_WARNING, "Could not rollback uninstallation of bundle '" + m_bundle.getSymbolicName() + "'", e);
- }
- }
-}
diff --git a/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/DropAllResourcesCommand.java b/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/DropAllResourcesCommand.java
deleted file mode 100644
index 105faa09da..0000000000
--- a/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/DropAllResourcesCommand.java
+++ /dev/null
@@ -1,115 +0,0 @@
-/*
- * 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.spi;
-
-import java.util.HashSet;
-import java.util.Set;
-
-import org.apache.felix.deploymentadmin.AbstractDeploymentPackage;
-import org.apache.felix.deploymentadmin.ResourceInfoImpl;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.ServiceReference;
-import org.osgi.service.deploymentadmin.DeploymentException;
-import org.osgi.service.deploymentadmin.spi.ResourceProcessor;
-import org.osgi.service.log.LogService;
-
-/**
- * Command that drops resources.
- */
-public class DropAllResourcesCommand extends Command {
- private final CommitResourceCommand m_commitCommand;
-
- /**
- * Creates an instance of this command. The commit command is used to make
- * sure the resource processors used to drop all resources will be committed
- * at a later stage in the process.
- *
- * @param commitCommand The commit command that will be executed at a later
- * stage in the process.
- */
- public DropAllResourcesCommand(CommitResourceCommand commitCommand) {
- m_commitCommand = commitCommand;
- }
-
- protected void doExecute(DeploymentSessionImpl session) throws Exception {
- // Allow proper rollback in case the drop fails...
- addRollback(new RollbackCommitAction(session));
-
- AbstractDeploymentPackage target = session.getTargetAbstractDeploymentPackage();
- BundleContext context = session.getBundleContext();
- LogService log = session.getLog();
-
- // Collect all unique paths of all processed resources...
- Set resourceProcessors = new HashSet();
-
- ResourceInfoImpl[] orderedTargetResources = target.getOrderedResourceInfos();
- for (int i = orderedTargetResources.length - 1; i >= 0; i--) {
- ResourceInfoImpl resourceInfo = orderedTargetResources[i];
- // FELIX-4491: only resources that need to be processed should be handled...
- if (!resourceInfo.isProcessedResource()) {
- session.getLog().log(LogService.LOG_INFO, "Ignoring non-processed resource: " + resourceInfo.getPath());
- continue;
- }
-
- String rpName = resourceInfo.getResourceProcessor();
- String path = resourceInfo.getPath();
-
- // Keep track of which resource processors we've seen already...
- if (!resourceProcessors.add(rpName)) {
- // Already seen this RP; continue on the next one...
- continue;
- }
-
- ServiceReference ref = target.getResourceProcessor(path);
- if (ref == null) {
- log.log(LogService.LOG_ERROR, "Failed to find resource processor for '" + rpName + "'!");
- throw new DeploymentException(CODE_PROCESSOR_NOT_FOUND, "Failed to find resource processor '" + rpName + "'!");
- }
-
- ResourceProcessor resourceProcessor = (ResourceProcessor) context.getService(ref);
- if (resourceProcessor == null) {
- log.log(LogService.LOG_ERROR, "Failed to find resource processor for '" + rpName + "'!");
- throw new DeploymentException(CODE_PROCESSOR_NOT_FOUND, "Failed to find resource processor '" + rpName + "'!");
- }
-
- try {
- if (m_commitCommand.addResourceProcessor(resourceProcessor)) {
- resourceProcessor.begin(session);
- }
- resourceProcessor.dropAllResources();
- }
- catch (Exception e) {
- log.log(LogService.LOG_ERROR, "Failed to drop all resources for resource processor '" + rpName + "'!", e);
- throw new DeploymentException(CODE_OTHER_ERROR, "Failed to drop all resources for resource processor '" + rpName + "'!", e);
- }
- }
- }
-
- private class RollbackCommitAction extends AbstractAction {
- private final DeploymentSessionImpl m_session;
-
- public RollbackCommitAction(DeploymentSessionImpl session) {
- m_session = session;
- }
-
- protected void doRun() {
- m_commitCommand.rollback(m_session);
- }
- }
-}
diff --git a/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/DropBundleCommand.java b/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/DropBundleCommand.java
deleted file mode 100644
index 7ad59c24ca..0000000000
--- a/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/DropBundleCommand.java
+++ /dev/null
@@ -1,88 +0,0 @@
-/*
- * 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.spi;
-
-import java.io.InputStream;
-
-import org.apache.felix.deploymentadmin.AbstractDeploymentPackage;
-import org.apache.felix.deploymentadmin.BundleInfoImpl;
-import org.osgi.framework.Bundle;
-import org.osgi.service.log.LogService;
-
-/**
- * Command that uninstalls bundles, if rolled back the bundles are restored.
- */
-public class DropBundleCommand extends Command {
-
- protected void doExecute(DeploymentSessionImpl session) throws Exception {
- AbstractDeploymentPackage target = session.getTargetAbstractDeploymentPackage();
- AbstractDeploymentPackage source = session.getSourceAbstractDeploymentPackage();
- LogService log = session.getLog();
-
- BundleInfoImpl[] orderedTargetBundles = target.getOrderedBundleInfos();
- for (int i = orderedTargetBundles.length - 1; i >= 0; i--) {
- BundleInfoImpl bundleInfo = orderedTargetBundles[i];
- String symbolicName = bundleInfo.getSymbolicName();
-
- if (!bundleInfo.isCustomizer() && source.getBundleInfoByName(symbolicName) == null) {
- // stale bundle, save a copy for rolling back and uninstall it
- try {
- Bundle bundle = target.getBundle(symbolicName);
- bundle.uninstall();
- addRollback(new InstallBundleRunnable(bundle, target, log));
- }
- catch (Exception be) {
- log.log(LogService.LOG_WARNING, "Bundle '" + symbolicName + "' could not be uninstalled", be);
- }
- }
- }
- }
-
- private static class InstallBundleRunnable extends AbstractAction {
- private final AbstractDeploymentPackage m_target;
- private final Bundle m_bundle;
- private final LogService m_log;
-
- public InstallBundleRunnable(Bundle bundle, AbstractDeploymentPackage target, LogService log) {
- m_bundle = bundle;
- m_target = target;
- m_log = log;
- }
-
- protected void doRun() throws Exception {
- InputStream is = null;
- try {
- is = m_target.getBundleStream(m_bundle.getSymbolicName());
- if (is != null) {
- m_bundle.update(is);
- }
- else {
- throw new RuntimeException("Unable to get Inputstream for bundle '" + m_bundle.getSymbolicName() + "'");
- }
- }
- finally {
- closeSilently(is);
- }
- }
-
- protected void onFailure(Exception e) {
- m_log.log(LogService.LOG_WARNING, "Could not rollback uninstallation of bundle '" + m_bundle.getSymbolicName() + "'", e);
- }
- }
-}
diff --git a/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/DropResourceCommand.java b/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/DropResourceCommand.java
deleted file mode 100644
index 7f86867397..0000000000
--- a/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/DropResourceCommand.java
+++ /dev/null
@@ -1,97 +0,0 @@
-/*
- * 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.spi;
-
-import org.apache.felix.deploymentadmin.AbstractDeploymentPackage;
-import org.apache.felix.deploymentadmin.ResourceInfoImpl;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.ServiceReference;
-import org.osgi.service.deploymentadmin.spi.ResourceProcessor;
-import org.osgi.service.log.LogService;
-
-/**
- * Command that drops resources.
- */
-public class DropResourceCommand extends Command {
-
- private final CommitResourceCommand m_commitCommand;
-
- /**
- * Creates an instance of this command. The commit command is used to make
- * sure the resource processors used to drop resources will be committed at
- * a later stage in the process.
- *
- * @param commitCommand The commit command that will be executed at a later
- * stage in the process.
- */
- public DropResourceCommand(CommitResourceCommand commitCommand) {
- m_commitCommand = commitCommand;
- }
-
- protected void doExecute(DeploymentSessionImpl session) throws Exception {
- // Allow proper rollback in case the drop fails...
- addRollback(new RollbackCommitAction(session));
-
- AbstractDeploymentPackage target = session.getTargetAbstractDeploymentPackage();
- AbstractDeploymentPackage source = session.getSourceAbstractDeploymentPackage();
- BundleContext context = session.getBundleContext();
- LogService log = session.getLog();
-
- ResourceInfoImpl[] orderedTargetResources = target.getOrderedResourceInfos();
- for (int i = orderedTargetResources.length - 1; i >= 0; i--) {
- ResourceInfoImpl resourceInfo = orderedTargetResources[i];
- // FELIX-4491: only resources that need to be processed should be handled...
- if (!resourceInfo.isProcessedResource()) {
- session.getLog().log(LogService.LOG_INFO, "Ignoring non-processed resource: " + resourceInfo.getPath());
- continue;
- }
-
- String path = resourceInfo.getPath();
- if (source.getResourceInfoByPath(path) == null) {
- ServiceReference ref = target.getResourceProcessor(path);
- if (ref != null) {
- ResourceProcessor resourceProcessor = (ResourceProcessor) context.getService(ref);
- if (resourceProcessor != null) {
- try {
- if (m_commitCommand.addResourceProcessor(resourceProcessor)) {
- resourceProcessor.begin(session);
- }
- resourceProcessor.dropped(path);
- }
- catch (Exception e) {
- log.log(LogService.LOG_WARNING, "Not allowed to drop resource '" + path + "'", e);
- }
- }
- }
- }
- }
- }
-
- private class RollbackCommitAction extends AbstractAction {
- private final DeploymentSessionImpl m_session;
-
- public RollbackCommitAction(DeploymentSessionImpl session) {
- m_session = session;
- }
-
- protected void doRun() {
- m_commitCommand.rollback(m_session);
- }
- }
-}
diff --git a/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/GetStorageAreaCommand.java b/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/GetStorageAreaCommand.java
deleted file mode 100644
index d75c6197c8..0000000000
--- a/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/GetStorageAreaCommand.java
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- * 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.spi;
-
-import java.io.File;
-import java.util.HashMap;
-import java.util.Map;
-
-import org.osgi.framework.Bundle;
-import org.osgi.service.deploymentadmin.BundleInfo;
-import org.osgi.service.deploymentadmin.DeploymentException;
-import org.osgi.service.deploymentadmin.DeploymentPackage;
-import org.osgi.service.log.LogService;
-
-/**
- * Command that determines the storage area's of all bundles in the source
- * deployment package of a deployment session.
- */
-public class GetStorageAreaCommand extends Command {
-
- private final Map m_storageAreas = new HashMap();
-
- protected void doExecute(DeploymentSessionImpl session) throws Exception {
- DeploymentPackage target = session.getTargetDeploymentPackage();
- BundleInfo[] infos = target.getBundleInfos();
- for (int i = 0; i < infos.length; i++) {
- if (isCancelled()) {
- throw new DeploymentException(CODE_CANCELLED);
- }
- Bundle bundle = target.getBundle(infos[i].getSymbolicName());
- if (bundle != null) {
- try {
- File root = session.getDataFile(bundle);
- m_storageAreas.put(bundle.getSymbolicName(), root);
- }
- catch (IllegalStateException ise) {
- session.getLog().log(LogService.LOG_WARNING, "Could not get reference to storage area of bundle '" + bundle.getSymbolicName() + "'");
- }
- }
- }
- }
-
- /**
- * Determines the storage area's of all bundles in the source deployment
- * package of a deployment session.
- *
- * @return <code>Map</code> with <code>File</code> object references to the
- * storage area's, they bundle symbolic name is used as a key in the
- * <code>Map</code>.
- */
- public Map getStorageAreas() {
- return m_storageAreas;
- }
-}
diff --git a/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/ProcessResourceCommand.java b/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/ProcessResourceCommand.java
deleted file mode 100644
index 9c0674b7a4..0000000000
--- a/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/ProcessResourceCommand.java
+++ /dev/null
@@ -1,151 +0,0 @@
-/*
- * 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.spi;
-
-import java.io.IOException;
-import java.util.HashMap;
-import java.util.Map;
-
-import org.apache.felix.deploymentadmin.AbstractDeploymentPackage;
-import org.apache.felix.deploymentadmin.AbstractInfo;
-import org.apache.felix.deploymentadmin.ResourceInfoImpl;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.ServiceReference;
-import org.osgi.service.deploymentadmin.DeploymentException;
-import org.osgi.service.deploymentadmin.spi.ResourceProcessor;
-import org.osgi.service.deploymentadmin.spi.ResourceProcessorException;
-import org.osgi.service.log.LogService;
-
-/**
- * Command that processes all the processed resources in the source deployment
- * package of a deployment session by finding their Resource Processors and
- * having those process the resources. System property
- * <code>org.apache.felix.deploymentadmin.allowforeigncustomizers</code> allows
- * you to skip the source handling of resource processors, allowing the use of
- * processors already on the system. Defaults to <code>false</code>.
- */
-public class ProcessResourceCommand extends Command {
-
- private final CommitResourceCommand m_commitCommand;
-
- /**
- * Creates an instance of this command, the <code>CommitCommand</code> is
- * used to ensure that all used <code>ResourceProcessor</code>s will be
- * committed at a later stage in the deployment session.
- *
- * @param commitCommand The <code>CommitCommand</code> that will commit all
- * resource processors used in this command.
- */
- public ProcessResourceCommand(CommitResourceCommand commitCommand) {
- m_commitCommand = commitCommand;
- }
-
- protected void doExecute(DeploymentSessionImpl session) throws Exception {
- // Allow proper rollback in case the drop fails...
- addRollback(new RollbackCommitAction(session));
-
- AbstractDeploymentPackage source = session.getSourceAbstractDeploymentPackage();
- BundleContext context = session.getBundleContext();
-
- Map expectedResources = new HashMap();
- AbstractInfo[] resourceInfos = (AbstractInfo[]) source.getResourceInfos();
- for (int i = 0; i < resourceInfos.length; i++) {
- AbstractInfo resourceInfo = resourceInfos[i];
- if (!resourceInfo.isMissing()) {
- expectedResources.put(resourceInfo.getPath(), resourceInfo);
- }
- }
-
- try {
- while (!expectedResources.isEmpty()) {
- AbstractInfo jarEntry = source.getNextEntry();
- if (jarEntry == null) {
- throw new DeploymentException(CODE_OTHER_ERROR, "Expected more resources in the stream: " + expectedResources.keySet());
- }
-
- String name = jarEntry.getPath();
-
- ResourceInfoImpl resourceInfo = (ResourceInfoImpl) expectedResources.remove(name);
- if (resourceInfo == null) {
- throw new DeploymentException(CODE_OTHER_ERROR, "Resource '" + name + "' is not described in the manifest.");
- }
- // FELIX-4491: only resources that need to be processed should be handled...
- if (!resourceInfo.isProcessedResource()) {
- session.getLog().log(LogService.LOG_INFO, "Ignoring non-processed resource: " + resourceInfo.getPath());
- continue;
- }
-
- ServiceReference ref = source.getResourceProcessor(name);
- if (ref == null) {
- throw new DeploymentException(CODE_PROCESSOR_NOT_FOUND, "No resource processor for resource: '" + name + "'");
- }
- if (!isValidCustomizer(session, ref)) {
- throw new DeploymentException(CODE_FOREIGN_CUSTOMIZER, "Resource processor for resource '" + name + "' belongs to foreign deployment package");
- }
-
- ResourceProcessor resourceProcessor = (ResourceProcessor) context.getService(ref);
- if (resourceProcessor == null) {
- throw new DeploymentException(CODE_PROCESSOR_NOT_FOUND, "No resource processor for resource: '" + name + "'");
- }
-
- try {
- if (m_commitCommand.addResourceProcessor(resourceProcessor)) {
- resourceProcessor.begin(session);
- }
- resourceProcessor.process(name, source.getCurrentEntryStream());
- }
- catch (ResourceProcessorException rpe) {
- if (rpe.getCode() == ResourceProcessorException.CODE_RESOURCE_SHARING_VIOLATION) {
- throw new DeploymentException(CODE_RESOURCE_SHARING_VIOLATION, "Sharing violation while processing resource '" + name + "'", rpe);
- }
- else {
- throw new DeploymentException(CODE_OTHER_ERROR, "Error while processing resource '" + name + "'", rpe);
- }
- }
- }
- }
- catch (IOException e) {
- throw new DeploymentException(CODE_OTHER_ERROR, "Problem while reading stream", e);
- }
- }
-
- private boolean isValidCustomizer(DeploymentSessionImpl session, ServiceReference ref) {
- if (session.getConfiguration().isAllowForeignCustomizers()) {
- // If foreign customizers are allowed, any non-null customizer will do...
- return ref != null;
- }
-
- AbstractDeploymentPackage source = session.getSourceAbstractDeploymentPackage();
- String serviceOwnerSymName = ref.getBundle().getSymbolicName();
- // If only local customizers are allowed, we must be able to find this customizer in our DP...
- return source.getBundleInfoByName(serviceOwnerSymName) != null;
- }
-
- private class RollbackCommitAction extends AbstractAction {
- private final DeploymentSessionImpl m_session;
-
- public RollbackCommitAction(DeploymentSessionImpl session) {
- m_session = session;
- }
-
- protected void doRun() {
- m_commitCommand.rollback(m_session);
- }
- }
-}
diff --git a/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/SnapshotCommand.java b/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/SnapshotCommand.java
deleted file mode 100644
index 29c2c2c2b3..0000000000
--- a/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/SnapshotCommand.java
+++ /dev/null
@@ -1,226 +0,0 @@
-/*
- * 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.spi;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.util.Map;
-import java.util.zip.ZipEntry;
-import java.util.zip.ZipInputStream;
-import java.util.zip.ZipOutputStream;
-
-import org.apache.felix.deploymentadmin.AbstractDeploymentPackage;
-import org.apache.felix.deploymentadmin.Utils;
-import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleContext;
-import org.osgi.service.deploymentadmin.BundleInfo;
-import org.osgi.service.deploymentadmin.DeploymentException;
-import org.osgi.service.log.LogService;
-
-public class SnapshotCommand extends Command {
- /** The ZIP specification mandates that directory-entries end with a forward slash (on all platforms). */
- static final String FORWARD_SLASH = "/";
-
- private final GetStorageAreaCommand m_getStorageAreaCommand;
-
- public SnapshotCommand(GetStorageAreaCommand getStorageAreaCommand) {
- m_getStorageAreaCommand = getStorageAreaCommand;
- }
-
- protected void doExecute(DeploymentSessionImpl session) throws Exception {
- AbstractDeploymentPackage target = session.getTargetAbstractDeploymentPackage();
- BundleContext context = session.getBundleContext();
-
- BundleInfo[] infos = target.getBundleInfos();
- Map storageAreas = m_getStorageAreaCommand.getStorageAreas();
- for (int i = 0; i < infos.length; i++) {
- if (isCancelled()) {
- throw new DeploymentException(CODE_CANCELLED);
- }
-
- String symbolicName = infos[i].getSymbolicName();
- Bundle bundle = target.getBundle(symbolicName);
- if (bundle != null) {
- File root = (File) storageAreas.get(symbolicName);
- if (root != null) {
- File snapshot = context.getDataFile("snapshots");
- snapshot.mkdirs();
- snapshot = new File(snapshot, infos[i].getSymbolicName());
- try {
- snapshot.createNewFile();
- store(root, snapshot);
- addRollback(new RestoreSnapshotRunnable(session, snapshot, root));
- addCommit(new DeleteSnapshotRunnable(session, snapshot));
- }
- catch (Exception e) {
- session.getLog().log(LogService.LOG_WARNING, "Could not access storage area of bundle '" + symbolicName + "'!", e);
- snapshot.delete();
- }
- }
- else {
- session.getLog().log(LogService.LOG_WARNING, "Could not retrieve storage area of bundle '" + symbolicName + "', skipping it.");
- }
- }
- }
- }
-
- protected static void restore(File archiveFile, File targetDir) throws IOException {
- ZipInputStream input = null;
- try {
- input = new ZipInputStream(new FileInputStream(archiveFile));
-
- ZipEntry entry;
- while ((entry = input.getNextEntry()) != null) {
- File targetEntry = new File(targetDir, entry.getName());
-
- if (entry.isDirectory()) {
- if (!targetEntry.mkdirs()) {
- throw new IOException("Failed to create one or more sub-directories!");
- }
- }
- else {
- OutputStream output = null;
- try {
- output = new FileOutputStream(targetEntry);
- copy(input, output);
- }
- finally {
- closeSilently(output);
- }
- }
-
- input.closeEntry();
- }
- }
- finally {
- closeSilently(input);
- }
- }
-
- protected static void store(File sourceDir, File archiveFile) throws IOException {
- ZipOutputStream output = null;
- try {
- output = new ZipOutputStream(new FileOutputStream(archiveFile));
- // Traverse source directory recursively, and store all entries...
- store(output, sourceDir, "");
- }
- finally {
- closeSilently(output);
- }
- }
-
- protected static void copy(InputStream is, OutputStream os) throws IOException {
- byte[] buffer = new byte[8192];
- int read;
- try {
- while ((read = is.read(buffer)) != -1) {
- os.write(buffer, 0, read);
- }
- }
- finally {
- os.flush();
- }
- }
-
- private static void store(ZipOutputStream output, File sourceDir, String entryName) throws IOException {
- File entry = new File(sourceDir, entryName);
-
- if (entry.isFile()) {
- ZipEntry zipEntry = new ZipEntry(entryName);
- zipEntry.setSize(entry.length());
- zipEntry.setTime(entry.lastModified());
-
- output.putNextEntry(zipEntry);
-
- InputStream input = null;
- try {
- input = new FileInputStream(entry);
- copy(input, output);
- }
- finally {
- closeSilently(input);
- output.closeEntry();
- }
- }
- else if (entry.isDirectory()) {
- String baseDir = "";
- if (!"".equals(entryName)) {
- baseDir = entryName;
- // Directories *must* use forward slashes...
- if (!baseDir.endsWith(FORWARD_SLASH)) {
- baseDir = baseDir.concat(FORWARD_SLASH);
- }
-
- output.putNextEntry(new ZipEntry(baseDir));
- output.closeEntry();
- }
-
- String[] entries = entry.list();
- for (int i = 0; i < entries.length; i++) {
- store(output, sourceDir, baseDir.concat(entries[i]));
- }
- }
- }
-
- private static class DeleteSnapshotRunnable extends AbstractAction {
- private final DeploymentSessionImpl m_session;
- private final File m_snapshot;
-
- private DeleteSnapshotRunnable(DeploymentSessionImpl session, File snapshot) {
- m_session = session;
- m_snapshot = snapshot;
- }
-
- protected void doRun() {
- if (!m_snapshot.delete()) {
- m_session.getLog().log(LogService.LOG_WARNING, "Failed to delete snapshot in " + m_snapshot + "!");
- }
- }
- }
-
- private static class RestoreSnapshotRunnable extends AbstractAction {
- private final DeploymentSessionImpl m_session;
- private final File m_snapshot;
- private final File m_root;
-
- private RestoreSnapshotRunnable(DeploymentSessionImpl session, File snapshot, File root) {
- m_session = session;
- m_snapshot = snapshot;
- m_root = root;
- }
-
- protected void doRun() throws Exception {
- try {
- Utils.delete(m_root, false /* deleteRoot */);
- restore(m_snapshot, m_root);
- }
- finally {
- m_snapshot.delete();
- }
- }
-
- protected void onFailure(Exception e) {
- m_session.getLog().log(LogService.LOG_WARNING, "Failed to restore snapshot!", e);
- }
- }
-}
\ No newline at end of file
diff --git a/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/StartBundleCommand.java b/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/StartBundleCommand.java
deleted file mode 100644
index edb4502a8c..0000000000
--- a/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/StartBundleCommand.java
+++ /dev/null
@@ -1,131 +0,0 @@
-/*
- * 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.spi;
-
-import org.apache.felix.deploymentadmin.AbstractDeploymentPackage;
-import org.apache.felix.deploymentadmin.BundleInfoImpl;
-import org.osgi.framework.Bundle;
-import org.osgi.framework.FrameworkEvent;
-import org.osgi.framework.FrameworkListener;
-import org.osgi.service.log.LogService;
-import org.osgi.service.packageadmin.PackageAdmin;
-
-/**
- * Command that starts all bundles described in the source deployment package of
- * a deployment session.
- */
-public class StartBundleCommand extends Command {
- private final RefreshPackagesMonitor m_refreshMonitor = new RefreshPackagesMonitor();
-
- protected void doExecute(DeploymentSessionImpl session) throws Exception {
- AbstractDeploymentPackage source = session.getSourceAbstractDeploymentPackage();
- PackageAdmin packageAdmin = session.getPackageAdmin();
- RefreshPackagesListener listener = new RefreshPackagesListener();
- LogService log = session.getLog();
-
- session.getBundleContext().addFrameworkListener(listener);
- packageAdmin.refreshPackages(null);
- m_refreshMonitor.waitForRefresh();
- session.getBundleContext().removeFrameworkListener(listener);
-
- // start source bundles
- BundleInfoImpl[] bundleInfos = source.getOrderedBundleInfos();
- for (int i = 0; i < bundleInfos.length; i++) {
- BundleInfoImpl bundleInfoImpl = bundleInfos[i];
- if (!bundleInfoImpl.isCustomizer()) {
- String symbolicName = bundleInfoImpl.getSymbolicName();
-
- Bundle bundle = source.getBundle(symbolicName);
- if (bundle != null) {
- if (isFragmentBundle(bundle)) {
- log.log(LogService.LOG_INFO, "Skipping fragment bundle '" + symbolicName + "'");
- }
- else {
- try {
- bundle.start();
- }
- catch (Exception be) {
- log.log(LogService.LOG_WARNING, "Could not start bundle '" + symbolicName + "'", be);
- }
- }
- }
- else {
- log.log(LogService.LOG_WARNING, "Could not start bundle '" + symbolicName + "' because it is not present in the framework");
- }
- }
- }
- }
-
- /**
- * RefreshPackagesListener is only listing to FrameworkEvents of the type
- * PACKAGES_REFRESHED. It will notify any object waiting the completion of a
- * refreshpackages() call.
- */
- private class RefreshPackagesListener implements FrameworkListener {
- public void frameworkEvent(FrameworkEvent event) {
- if (event.getType() == FrameworkEvent.PACKAGES_REFRESHED) {
- m_refreshMonitor.proceed();
- }
- }
- }
-
- /**
- * Use this monitor when its desired to wait for the completion of the
- * asynchronous PackageAdmin.refreshPackages() call.
- */
- private static class RefreshPackagesMonitor {
- private static final int REFRESH_TIMEOUT = 10000;
-
- private volatile boolean m_alreadyNotified = false;
-
- /**
- * Waits for the completion of the PackageAdmin.refreshPackages() call.
- * Because its not sure whether all OSGi framework implementations
- * implement this method as specified we have build in a timeout. So if
- * a event about the completion of the refreshpackages() is never
- * received, we continue after the timeout whether the refresh was done
- * or not.
- */
- public synchronized void waitForRefresh() {
- if (!m_alreadyNotified) {
- try {
- wait(REFRESH_TIMEOUT);
- }
- catch (InterruptedException ie) {}
- finally {
- m_alreadyNotified = false;
- }
- }
- else {
- // just reset the misted notification variable, this Monitor
- // object might be reused.
- m_alreadyNotified = false;
- }
- }
-
- /**
- * After a PACKAGES_REFRESHED event notify all the parties interested in
- * the completion of the PackageAdmin.refreshPackages() call.
- */
- public synchronized void proceed() {
- m_alreadyNotified = true;
- notifyAll();
- }
- }
-}
diff --git a/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/StartCustomizerCommand.java b/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/StartCustomizerCommand.java
deleted file mode 100644
index 610e9ab269..0000000000
--- a/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/StartCustomizerCommand.java
+++ /dev/null
@@ -1,97 +0,0 @@
-/*
- * 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.spi;
-
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.Set;
-
-import org.apache.felix.deploymentadmin.AbstractDeploymentPackage;
-import org.apache.felix.deploymentadmin.BundleInfoImpl;
-import org.osgi.framework.Bundle;
-import org.osgi.service.deploymentadmin.DeploymentException;
-import org.osgi.service.log.LogService;
-
-/**
- * Command that starts all customizer bundles defined in the source deployment
- * packages of a deployment session. In addition all customizer bundles of the
- * target deployment package that are not present in the source deployment
- * package are started as well.
- */
-public class StartCustomizerCommand extends Command {
-
- protected void doExecute(DeploymentSessionImpl session) throws Exception {
- AbstractDeploymentPackage target = session.getTargetAbstractDeploymentPackage();
- AbstractDeploymentPackage source = session.getSourceAbstractDeploymentPackage();
-
- Set bundles = new HashSet();
- Set sourceBundlePaths = new HashSet();
-
- BundleInfoImpl[] targetInfos = target.getBundleInfoImpls();
- BundleInfoImpl[] sourceInfos = source.getBundleInfoImpls();
- for (int i = 0; i < sourceInfos.length; i++) {
- if (sourceInfos[i].isCustomizer()) {
- sourceBundlePaths.add(sourceInfos[i].getPath());
- Bundle bundle = source.getBundle(sourceInfos[i].getSymbolicName());
- if (bundle != null) {
- bundles.add(bundle);
- }
- }
- }
-
- for (int i = 0; i < targetInfos.length; i++) {
- if (targetInfos[i].isCustomizer() && !sourceBundlePaths.contains(targetInfos[i].getPath())) {
- Bundle bundle = target.getBundle(targetInfos[i].getSymbolicName());
- if (bundle != null) {
- bundles.add(bundle);
- }
- }
- }
-
- for (Iterator i = bundles.iterator(); i.hasNext();) {
- Bundle bundle = (Bundle) i.next();
- try {
- bundle.start();
- }
- catch (Exception be) {
- throw new DeploymentException(CODE_OTHER_ERROR, "Could not start customizer bundle '" + bundle.getSymbolicName() + "'", be);
- }
- addRollback(new StopCustomizerRunnable(session, bundle));
- }
- }
-
- private static class StopCustomizerRunnable extends AbstractAction {
- private final DeploymentSessionImpl m_session;
-
- private final Bundle m_bundle;
-
- public StopCustomizerRunnable(DeploymentSessionImpl session, Bundle bundle) {
- m_session = session;
- m_bundle = bundle;
- }
-
- protected void doRun() throws Exception {
- m_bundle.stop();
- }
-
- protected void onFailure(Exception e) {
- m_session.getLog().log(LogService.LOG_WARNING, "Failed to stop bundle '" + m_bundle.getSymbolicName() + "'", e);
- }
- }
-}
diff --git a/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/StopBundleCommand.java b/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/StopBundleCommand.java
deleted file mode 100644
index 1991ce5786..0000000000
--- a/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/StopBundleCommand.java
+++ /dev/null
@@ -1,124 +0,0 @@
-/*
- * 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.spi;
-
-import org.apache.felix.deploymentadmin.AbstractDeploymentPackage;
-import org.apache.felix.deploymentadmin.BundleInfoImpl;
-import org.osgi.framework.Bundle;
-import org.osgi.service.deploymentadmin.BundleInfo;
-import org.osgi.service.deploymentadmin.DeploymentException;
-import org.osgi.service.log.LogService;
-
-/**
- * Command that stops all bundles described in the target deployment package of
- * a deployment session.
- *
- * By spec every single bundle of the target package should be stopped, even if
- * this is not strictly necessary because of bundles being unaffected by an
- * update. To be able to skip the stopping of unaffected bundles the following
- * system property can be defined:
- * <code>org.apache.felix.deploymentadmin.stopunaffectedbundle</code>. If this
- * property has value <code>false</code> (case insensitive) then unaffected
- * bundles will not be stopped, in all other cases the bundles will be stopped
- * according to the OSGi specification.
- */
-public class StopBundleCommand extends Command {
-
- protected void doExecute(DeploymentSessionImpl session) throws Exception {
- LogService log = session.getLog();
-
- AbstractDeploymentPackage target = session.getTargetAbstractDeploymentPackage();
- BundleInfo[] bundleInfos = target.getOrderedBundleInfos();
- for (int i = 0; i < bundleInfos.length; i++) {
- if (isCancelled()) {
- throw new DeploymentException(CODE_CANCELLED);
- }
-
- String symbolicName = bundleInfos[i].getSymbolicName();
- Bundle bundle = target.getBundle(symbolicName);
- if (bundle != null) {
- if (omitBundleStop(session, symbolicName)) {
- continue;
- }
- if (isFragmentBundle(bundle)) {
- log.log(LogService.LOG_INFO, "Skipping fragment bundle '" + symbolicName + "'");
- }
- else {
- addRollback(new StartBundleRunnable(session, bundle));
- try {
- bundle.stop();
- }
- catch (Exception e) {
- log.log(LogService.LOG_WARNING, "Could not stop bundle '" + symbolicName + "'", e);
- }
- }
- }
- else {
- log.log(LogService.LOG_WARNING, "Could not stop bundle '" + symbolicName + "' because it was not present in the framework");
- }
- }
- }
-
- /**
- * Determines whether stopping a bundle is strictly needed.
- *
- * @param session The current deployment session.
- * @param symbolicName The symbolic name of the bundle to inspect.
- *
- * @return Returns <code>true</code> if
- * <code>Constants.DEPLOYMENTPACKAGE_MISSING</code> is true for the
- * specified bundle in the source deployment package or if the
- * version of the bundle is the same in both source and target
- * deployment package. Returns <code>false</code> otherwise.
- */
- private boolean omitBundleStop(DeploymentSessionImpl session, String symbolicName) {
- boolean stopUnaffectedBundles = session.getConfiguration().isStopUnaffectedBundles();
- if (stopUnaffectedBundles) {
- // Default behavior: stop all bundles (see spec)...
- return false;
- }
-
- BundleInfoImpl sourceBundleInfo = session.getSourceAbstractDeploymentPackage().getBundleInfoByName(symbolicName);
- BundleInfoImpl targetBundleInfo = session.getTargetAbstractDeploymentPackage().getBundleInfoByName(symbolicName);
-
- boolean fixPackageMissing = sourceBundleInfo != null && sourceBundleInfo.isMissing();
- boolean sameVersion = (targetBundleInfo != null && sourceBundleInfo != null && targetBundleInfo.getVersion().equals(sourceBundleInfo.getVersion()));
-
- return (fixPackageMissing || sameVersion);
- }
-
- private static class StartBundleRunnable extends AbstractAction {
- private final DeploymentSessionImpl m_session;
-
- private final Bundle m_bundle;
-
- public StartBundleRunnable(DeploymentSessionImpl session, Bundle bundle) {
- m_session = session;
- m_bundle = bundle;
- }
-
- protected void doRun() throws Exception {
- m_bundle.start();
- }
-
- protected void onFailure(Exception e) {
- m_session.getLog().log(LogService.LOG_WARNING, "Failed to start bundle '" + m_bundle.getSymbolicName() + "'", e);
- }
- }
-}
diff --git a/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/UpdateCommand.java b/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/UpdateCommand.java
deleted file mode 100644
index bda044958a..0000000000
--- a/deploymentadmin/deploymentadmin/src/main/java/org/apache/felix/deploymentadmin/spi/UpdateCommand.java
+++ /dev/null
@@ -1,203 +0,0 @@
-/*
- * 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.spi;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.HashMap;
-import java.util.Map;
-
-import org.apache.felix.deploymentadmin.AbstractDeploymentPackage;
-import org.apache.felix.deploymentadmin.AbstractInfo;
-import org.apache.felix.deploymentadmin.BundleInfoImpl;
-import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleContext;
-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 session. If a bundle was already defined in the target
- * deployment package of the same session it is updated, otherwise the bundle is
- * simply installed.
- */
-public class UpdateCommand extends Command {
-
- protected void doExecute(DeploymentSessionImpl session) throws Exception {
- 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();
- for (int i = 0; i < bundleInfos.length; i++) {
- AbstractInfo bundleInfo = bundleInfos[i];
- if (!bundleInfo.isMissing()) {
- expectedBundles.put(bundleInfo.getPath(), bundleInfo);
- }
- }
-
- try {
- while (!expectedBundles.isEmpty()) {
- AbstractInfo entry = source.getNextEntry();
- if (entry == null) {
- throw new DeploymentException(CODE_OTHER_ERROR, "Expected more bundles in the stream: " + expectedBundles.keySet());
- }
-
- String name = entry.getPath();
- BundleInfoImpl bundleInfo = (BundleInfoImpl) expectedBundles.remove(name);
- if (bundleInfo == null) {
- if (isLocalizationFile(name)) {
- // FELIX-518: do not try to process signature or localization files...
- continue;
- }
- throw new DeploymentException(CODE_OTHER_ERROR, "Resource '" + name + "' is not described in the manifest.");
- }
-
- String bsn = bundleInfo.getSymbolicName();
- Version sourceVersion = bundleInfo.getVersion();
-
- Bundle bundle = targetPackage.getBundle(bsn);
- try {
- if (bundle == null) {
- // new bundle, install it
- bundle = context.installBundle(BUNDLE_LOCATION_PREFIX + bsn, new BundleInputStream(source.getCurrentEntryStream()));
- addRollback(new UninstallBundleRunnable(bundle, log));
- }
- else {
- // existing bundle, update it
- Version currentVersion = getVersion(bundle);
- if (!sourceVersion.equals(currentVersion)) {
- bundle.update(new BundleInputStream(source.getCurrentEntryStream()));
- addRollback(new UpdateBundleRunnable(bundle, targetPackage, log));
- }
- }
- }
- catch (Exception be) {
- if (isCancelled()) {
- return;
- }
- throw new DeploymentException(CODE_OTHER_ERROR, "Could not install new bundle '" + name + "' (" + bsn + ")", be);
- }
-
- if (!bundle.getSymbolicName().equals(bsn)) {
- throw new DeploymentException(CODE_BUNDLE_NAME_ERROR, "Installed/updated bundle symbolicname (" + bundle.getSymbolicName() + ") do not match what was installed/updated: " + bsn);
- }
-
- Version targetVersion = getVersion(bundle);
- if (!sourceVersion.equals(targetVersion)) {
- throw new DeploymentException(CODE_OTHER_ERROR,
- "Installed/updated bundle version (" + targetVersion + ") do not match what was installed/updated: " + sourceVersion + ", offending bundle = " + bsn);
- }
- }
- }
- catch (IOException e) {
- throw new DeploymentException(CODE_OTHER_ERROR, "Problem while reading stream", e);
- }
- }
-
- private Version getVersion(Bundle bundle) {
- return Version.parseVersion((String) bundle.getHeaders().get(BUNDLE_VERSION));
- }
-
- private boolean isLocalizationFile(String name) {
- return name.startsWith("OSGI-INF/l10n/");
- }
-
- private static class UninstallBundleRunnable extends AbstractAction {
- private final Bundle m_bundle;
- private final LogService m_log;
-
- public UninstallBundleRunnable(Bundle bundle, LogService log) {
- m_bundle = bundle;
- m_log = log;
- }
-
- protected void doRun() throws Exception {
- m_bundle.uninstall();
- }
-
- protected void onFailure(Exception e) {
- m_log.log(LogService.LOG_WARNING, "Could not rollback update of bundle '" + m_bundle.getSymbolicName() + "'", e);
- }
- }
-
- private static class UpdateBundleRunnable extends AbstractAction {
- private final AbstractDeploymentPackage m_targetPackage;
- private final Bundle m_bundle;
- private final LogService m_log;
-
- public UpdateBundleRunnable(Bundle bundle, AbstractDeploymentPackage targetPackage, LogService log) {
- m_bundle = bundle;
- m_targetPackage = targetPackage;
- m_log = log;
- }
-
- protected void doRun() throws Exception {
- InputStream is = null;
- try {
- is = m_targetPackage.getBundleStream(m_bundle.getSymbolicName());
- if (is != null) {
- m_bundle.update(is);
- }
- else {
- throw new RuntimeException("Unable to get inputstream for bundle " + m_bundle.getSymbolicName());
- }
- }
- finally {
- closeSilently(is);
- }
- }
-
- protected void onFailure(Exception e) {
- m_log.log(LogService.LOG_WARNING, "Could not rollback update of bundle '" + m_bundle.getSymbolicName() + "'", e);
- }
- }
-
- private final class BundleInputStream extends InputStream {
- private final InputStream m_inputStream;
-
- private BundleInputStream(InputStream jarInputStream) {
- m_inputStream = jarInputStream;
- }
-
- public int read() throws IOException {
- checkCancel();
- return m_inputStream.read();
- }
-
- public int read(byte[] buffer) throws IOException {
- checkCancel();
- return m_inputStream.read(buffer);
- }
-
- public int read(byte[] buffer, int off, int len) throws IOException {
- checkCancel();
- return m_inputStream.read(buffer, off, len);
- }
-
- private void checkCancel() throws IOException {
- if (isCancelled()) {
- throw new IOException("Stream was cancelled");
- }
- }
- }
-}
diff --git a/deploymentadmin/deploymentadmin/src/test/java/org/apache/felix/deploymentadmin/ContentCopyingJarInputStreamTest.java b/deploymentadmin/deploymentadmin/src/test/java/org/apache/felix/deploymentadmin/ContentCopyingJarInputStreamTest.java
deleted file mode 100644
index d2354a317a..0000000000
--- a/deploymentadmin/deploymentadmin/src/test/java/org/apache/felix/deploymentadmin/ContentCopyingJarInputStreamTest.java
+++ /dev/null
@@ -1,257 +0,0 @@
-/*
- * 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.FileOutputStream;
-import java.io.IOException;
-import java.util.jar.JarEntry;
-import java.util.jar.JarFile;
-import java.util.jar.JarInputStream;
-import java.util.jar.JarOutputStream;
-import java.util.jar.Manifest;
-import java.util.zip.GZIPInputStream;
-import java.util.zip.ZipEntry;
-
-import junit.framework.TestCase;
-
-/**
- * Test cases for {@link ContentCopyingJarInputStream}.
- */
-public class ContentCopyingJarInputStreamTest extends TestCase
-{
- private static final String MANIFEST_NAME = JarFile.MANIFEST_NAME;
- private static final String INDEX_NAME = "META-INF/INDEX.LIST";
-
- private File m_tempDir;
- private File m_jarFile;
-
- /**
- * Tests that we can copy a {@link JarInputStream} containing only a manifest.
- */
- public void testCopyEmptyJarWithManifestOnlyOk() throws Exception
- {
- Manifest man = createManifest();
-
- createEmptyJar(man);
-
- assertJarContents(man);
- }
-
- /**
- * Tests that we can copy a simple {@link JarInputStream}.
- */
- public void testCopyJarWithIndexAndWithManifestOk() throws Exception
- {
- Manifest man = createManifest();
-
- createJar(man, true /* includeIndex */);
-
- assertJarContents(man);
- }
-
- /**
- * Tests that we can copy a {@link JarInputStream} even if it does not contains a manifest file.
- */
- public void testCopyJarWithIndexAndWithoutManifestOk() throws Exception
- {
- Manifest man = null;
-
- createJar(man, true /* includeIndex */);
-
- assertJarContents(man);
- }
-
- /**
- * Tests that we can copy a simple {@link JarInputStream}.
- */
- public void testCopyJarWithoutIndexAndWithManifestOk() throws Exception
- {
- Manifest man = createManifest();
-
- createJar(man, false /* includeIndex */);
-
- assertJarContents(man);
- }
-
- /**
- * Tests that we can copy a {@link JarInputStream} even if it does not contains a manifest file.
- */
- public void testCopyJarWithoutIndexAndWithoutManifestOk() throws Exception
- {
- Manifest man = null;
-
- createJar(man, false /* includeIndex */);
-
- assertJarContents(man);
- }
-
- protected void setUp() throws IOException
- {
- m_tempDir = createTempDir();
- m_jarFile = new File(m_tempDir, "input.jar");
- }
-
- protected void tearDown()
- {
- Utils.delete(m_tempDir, true);
- }
-
- private void appendFiles(JarOutputStream jos, int count) throws IOException
- {
- int size = 1024;
-
- for (int i = 0, j = 1; i < count; i++, j++)
- {
- JarEntry entry = new JarEntry("sub/" + j);
- jos.putNextEntry(entry);
- for (int k = 0; k < size; k++)
- {
- jos.write('0' + j);
- }
- jos.closeEntry();
- }
- }
-
- private void assertJarContents(Manifest man) throws IOException
- {
- File indexFile = new File(m_tempDir, "index.txt");
-
- FileInputStream fis = new FileInputStream(m_jarFile);
- JarInputStream jis = new ContentCopyingJarInputStream(fis, indexFile, m_tempDir);
-
- try
- {
- JarEntry entry;
- while ((entry = jis.getNextJarEntry()) != null)
- {
- File f = new File(m_tempDir, entry.getName());
-
- // Without reading the actual contents, the copy should already exist...
- assertTrue(entry.getName() + " does not exist?!", f.exists());
-
- int size = (INDEX_NAME.equals(entry.getName()) ? 33 : 1024);
-
- byte[] input = new byte[size];
- int read = jis.read(input);
-
- assertEquals("Not all bytes were read: " + entry.getName(), size, read);
-
- // Contents will only be completely written after closing the JAR entry itself...
- jis.closeEntry();
-
- verifyContents(f, input);
- }
-
- assertEquals("Manifest not as expected", man, jis.getManifest());
- }
- finally
- {
- jis.close();
- }
- }
-
- private void createEmptyJar(Manifest man) throws IOException
- {
- FileOutputStream fos = new FileOutputStream(m_jarFile);
- JarOutputStream jos = new JarOutputStream(fos, man);
- jos.close();
- }
-
- private void createJar(Manifest man, boolean includeIndex) throws IOException
- {
- FileOutputStream fos = new FileOutputStream(m_jarFile);
- JarOutputStream jos;
-
- if (man == null || includeIndex)
- {
- jos = new JarOutputStream(fos);
- }
- else
- {
- jos = new JarOutputStream(fos, man);
- }
-
- if (includeIndex)
- {
- // Write the INDEX.LIST file as first entry...
- jos.putNextEntry(new ZipEntry(INDEX_NAME));
- jos.write(("JarIndex-Version: 1.0\n\n" + m_jarFile.getName() + "\n").getBytes());
- jos.closeEntry();
-
- if (man != null)
- {
- jos.putNextEntry(new ZipEntry(MANIFEST_NAME));
- man.write(jos);
- jos.closeEntry();
- }
- }
-
- try
- {
- appendFiles(jos, 5);
- }
- finally
- {
- jos.close();
- }
- }
-
- private Manifest createManifest()
- {
- Manifest mf = new Manifest();
- mf.getMainAttributes().putValue("Manifest-Version", "1.0");
- mf.getMainAttributes().putValue("Bundle-ManifestVersion", "2");
- mf.getMainAttributes().putValue("Bundle-Version", "1.0.0");
- mf.getMainAttributes().putValue("Bundle-SymbolicName", "com.foo.bar");
- return mf;
- }
-
- private File createTempDir() throws IOException
- {
- File tmpFile = File.createTempFile("ccjis_test", null);
- tmpFile.delete();
- tmpFile.mkdir();
- return tmpFile;
- }
-
- private void verifyContents(File file, byte[] expected) throws IOException
- {
- FileInputStream fis = new FileInputStream(file);
- GZIPInputStream gis = new GZIPInputStream(fis);
- try
- {
- byte[] b = new byte[expected.length];
-
- int read = gis.read(b);
- assertEquals(b.length, read);
-
- for (int i = 0; i < expected.length; i++)
- {
- assertEquals(expected[i], b[i]);
- }
- }
- finally
- {
- gis.close();
- fis.close();
- }
- }
-}
diff --git a/deploymentadmin/deploymentadmin/src/test/java/org/apache/felix/deploymentadmin/DeploymentAdminConfigTest.java b/deploymentadmin/deploymentadmin/src/test/java/org/apache/felix/deploymentadmin/DeploymentAdminConfigTest.java
deleted file mode 100644
index f2040e40d4..0000000000
--- a/deploymentadmin/deploymentadmin/src/test/java/org/apache/felix/deploymentadmin/DeploymentAdminConfigTest.java
+++ /dev/null
@@ -1,139 +0,0 @@
-/*
- * 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.util.HashMap;
-import java.util.Map;
-
-import junit.framework.TestCase;
-
-import org.mockito.Matchers;
-import org.mockito.Mockito;
-import org.mockito.invocation.InvocationOnMock;
-import org.mockito.stubbing.Answer;
-import org.osgi.framework.BundleContext;
-import org.osgi.service.cm.ConfigurationException;
-
-/**
- * Test cases for {@link DeploymentAdminConfig}.
- */
-public class DeploymentAdminConfigTest extends TestCase {
- private static final String KEY_STOP_UNAFFECTED_BUNDLE = DeploymentAdminConfig.KEY_STOP_UNAFFECTED_BUNDLE;
- private static final String KEY_STOP_UNAFFECTED_BUNDLES = DeploymentAdminConfig.KEY_STOP_UNAFFECTED_BUNDLES;
- private static final String KEY_ALLOW_FOREIGN_CUSTOMIZERS = DeploymentAdminConfig.KEY_ALLOW_FOREIGN_CUSTOMIZERS;
-
- private static final boolean DEFAULT_STOP_UNAFFECTED_BUNDLES = DeploymentAdminConfig.DEFAULT_STOP_UNAFFECTED_BUNDLES;
- private static final boolean DEFAULT_ALLOW_FOREIGN_CUSTOMIZERS = DeploymentAdminConfig.DEFAULT_ALLOW_FOREIGN_CUSTOMIZERS;
-
- private final Map m_fwProperties = new HashMap();
-
- /**
- * Tests the configuration values of {@link DeploymentAdminImpl} without any explicit configuration.
- */
- public void testDefaultConfigurationOk() throws ConfigurationException {
- DeploymentAdminConfig config = createDeploymentAdminConfig();
-
- assertEquals(DEFAULT_STOP_UNAFFECTED_BUNDLES, config.isStopUnaffectedBundles());
- assertEquals(DEFAULT_ALLOW_FOREIGN_CUSTOMIZERS, config.isAllowForeignCustomizers());
- }
-
- /**
- * Tests the configuration values of {@link DeploymentAdminImpl} without any explicit configuration.
- */
- public void testFrameworkConfigurationOk() throws ConfigurationException {
- m_fwProperties.put(KEY_STOP_UNAFFECTED_BUNDLES, Boolean.toString(!DEFAULT_STOP_UNAFFECTED_BUNDLES));
- m_fwProperties.put(KEY_ALLOW_FOREIGN_CUSTOMIZERS, Boolean.toString(!DEFAULT_ALLOW_FOREIGN_CUSTOMIZERS));
-
- DeploymentAdminConfig config = createDeploymentAdminConfig();
-
- assertEquals(!DEFAULT_STOP_UNAFFECTED_BUNDLES, config.isStopUnaffectedBundles());
- assertEquals(!DEFAULT_ALLOW_FOREIGN_CUSTOMIZERS, config.isAllowForeignCustomizers());
- }
-
- /**
- * Tests the configuration values of {@link DeploymentAdminImpl} without any explicit configuration.
- */
- public void testFrameworkConfigurationDeprecatedKeyOk() throws ConfigurationException {
- m_fwProperties.put(KEY_STOP_UNAFFECTED_BUNDLE, Boolean.toString(!DEFAULT_STOP_UNAFFECTED_BUNDLES));
-
- DeploymentAdminConfig config = createDeploymentAdminConfig();
-
- assertEquals(!DEFAULT_STOP_UNAFFECTED_BUNDLES, config.isStopUnaffectedBundles());
- }
-
- /**
- * Tests the configuration values of {@link DeploymentAdminImpl} without any explicit configuration.
- */
- public void testSystemConfigurationOk() throws ConfigurationException {
- String stopUnaffectedBundle = KEY_STOP_UNAFFECTED_BUNDLES;
- String allowForeignCustomizers = KEY_ALLOW_FOREIGN_CUSTOMIZERS;
-
- System.setProperty(stopUnaffectedBundle, Boolean.toString(!DEFAULT_STOP_UNAFFECTED_BUNDLES));
- System.setProperty(allowForeignCustomizers, Boolean.toString(!DEFAULT_ALLOW_FOREIGN_CUSTOMIZERS));
-
- try {
- DeploymentAdminConfig config = createDeploymentAdminConfig();
-
- assertEquals(!DEFAULT_STOP_UNAFFECTED_BUNDLES, config.isStopUnaffectedBundles());
- assertEquals(!DEFAULT_ALLOW_FOREIGN_CUSTOMIZERS, config.isAllowForeignCustomizers());
- }
- finally {
- System.clearProperty(stopUnaffectedBundle);
- System.clearProperty(allowForeignCustomizers);
- }
-
- System.setProperty(stopUnaffectedBundle.toLowerCase(), Boolean.toString(!DEFAULT_STOP_UNAFFECTED_BUNDLES));
- System.setProperty(allowForeignCustomizers.toLowerCase(), Boolean.toString(!DEFAULT_ALLOW_FOREIGN_CUSTOMIZERS));
-
- try {
- DeploymentAdminConfig config = createDeploymentAdminConfig();
-
- assertEquals(!DEFAULT_STOP_UNAFFECTED_BUNDLES, config.isStopUnaffectedBundles());
- assertEquals(!DEFAULT_ALLOW_FOREIGN_CUSTOMIZERS, config.isAllowForeignCustomizers());
- }
- finally {
- System.clearProperty(stopUnaffectedBundle.toLowerCase());
- System.clearProperty(allowForeignCustomizers.toLowerCase());
- }
- }
-
- protected void setUp() throws Exception {
- m_fwProperties.clear();
- }
-
- private DeploymentAdminConfig createDeploymentAdminConfig() throws ConfigurationException {
- return new DeploymentAdminConfig(createMockBundleContext());
- }
-
- private BundleContext createMockBundleContext() {
- BundleContext result = (BundleContext) Mockito.mock(BundleContext.class);
- Mockito.when(result.getProperty(Matchers.anyString())).thenAnswer(new Answer() {
- public Object answer(InvocationOnMock invocation) throws Throwable {
- String prop = (String) invocation.getArguments()[0];
-
- Object result = m_fwProperties.get(prop);
- if (result == null) {
- result = System.getProperty(prop);
- }
- return result;
- }
- });
- return result;
- }
-}
diff --git a/deploymentadmin/deploymentadmin/src/test/java/org/apache/felix/deploymentadmin/spi/SnapshotCommandTest.java b/deploymentadmin/deploymentadmin/src/test/java/org/apache/felix/deploymentadmin/spi/SnapshotCommandTest.java
deleted file mode 100644
index 87b27d539b..0000000000
--- a/deploymentadmin/deploymentadmin/src/test/java/org/apache/felix/deploymentadmin/spi/SnapshotCommandTest.java
+++ /dev/null
@@ -1,229 +0,0 @@
-/*
- * 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.spi;
-
-import java.io.Closeable;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Random;
-import java.util.zip.ZipEntry;
-import java.util.zip.ZipInputStream;
-
-import junit.framework.TestCase;
-
-import org.apache.felix.deploymentadmin.Utils;
-
-/**
- * Test cases for {@link SnapshotCommand}.
- *
- * @author <a href="mailto:dev@felix.apache.org">Felix Project Team</a>
- */
-public class SnapshotCommandTest extends TestCase {
- private final List m_cleanup = new ArrayList();
-
- /**
- * Tests that an archive can be correctly restored.
- * <p>
- * This tests FELIX-4719.
- * </p>
- */
- public void testRestoreArchiveOk() throws Exception {
- // Set up a file-hierarchy we can archive...
- File baseDir = createFileHierarchy();
-
- File archiveFile = new File(baseDir, "../archive.zip");
- m_cleanup.add(archiveFile.getCanonicalFile());
-
- SnapshotCommand.store(baseDir, archiveFile);
- assertTrue("Archive not created?!", archiveFile.exists());
-
- File targetDir = createTempDir();
- SnapshotCommand.restore(archiveFile, targetDir);
-
- verifyDirContents(baseDir, targetDir);
- }
-
- /**
- * Tests that a directory (data-area) is correctly archived, and that the contents of that archive are as expected.
- * <p>
- * This tests FELIX-4718.
- * </p>
- */
- public void testStoreDataAreaOk() throws Exception {
- // Set up a file-hierarchy we can archive...
- File baseDir = createFileHierarchy();
-
- File archiveFile = new File(baseDir, "../archive.zip");
- m_cleanup.add(archiveFile.getCanonicalFile());
-
- SnapshotCommand.store(baseDir, archiveFile);
- assertTrue("Archive not created?!", archiveFile.exists());
-
- verifyArchiveContents(archiveFile, 3 /* dirs */, 6 /* files */);
- }
-
- protected void tearDown() throws Exception {
- Iterator iter = m_cleanup.iterator();
- while (iter.hasNext()) {
- File file = (File) iter.next();
- if (file.isFile()) {
- file.delete();
- }
- else if (file.isDirectory()) {
- Utils.delete(file, true /* deleteRoot */);
- }
- iter.remove();
- }
- }
-
- private void close(Closeable resource) throws IOException {
- if (resource != null) {
- resource.close();
- }
- }
-
- private void createFile(File file, int size) throws IOException {
- assertTrue(file.createNewFile());
- FileOutputStream fos = null;
- try {
- fos = new FileOutputStream(file);
-
- byte[] data = new byte[size];
- new Random().nextBytes(data);
-
- fos.write(data);
- }
- finally {
- close(fos);
- }
- }
-
- /**
- * Creates a simple file hierarchy with a couple of files and directories (6 files and 3 directories).
- *
- * @return the base directory where the file hierarchy is stored, never <code>null</code>.
- */
- private File createFileHierarchy() throws IOException {
- File base = createTempDir();
-
- File dir1 = new File(base, "dir1");
- assertTrue(dir1.mkdir());
-
- File dir2 = new File(dir1, "dir1a");
- assertTrue(dir2.mkdir());
-
- File dir3 = new File(dir1, "dir1b");
- assertTrue(dir3.mkdir());
-
- createFile(new File(base, "file1"), 1024);
- createFile(new File(dir1, "file2"), 2048);
- createFile(new File(dir2, "file3"), 4096);
- createFile(new File(base, "file4"), 8192);
- createFile(new File(dir2, "file5"), 16384);
- createFile(new File(dir3, "file6"), 32768);
-
- return base;
- }
-
- private File createTempDir() throws IOException {
- File dir = File.createTempFile("felix4718-", "");
- assertTrue(dir.delete());
- assertTrue(dir.mkdirs());
- // For test cleanup...
- m_cleanup.add(dir);
- return dir;
- }
-
- private void verifyArchiveContents(File archive, int expectedDirCount, int expectedFileCount) throws IOException {
- FileInputStream fis = null;
- ZipInputStream zis = null;
-
- try {
- fis = new FileInputStream(archive);
- zis = new ZipInputStream(fis);
-
- int dirCount = 0;
- int fileCount = 0;
-
- ZipEntry entry;
- while ((entry = zis.getNextEntry()) != null) {
- if (entry.isDirectory()) {
- dirCount++;
- }
- else {
- fileCount++;
- }
- zis.closeEntry();
- }
-
- assertEquals("Unexpected number of files", expectedFileCount, fileCount);
- assertEquals("Unexpected number of directories", expectedDirCount, dirCount);
- }
- finally {
- close(fis);
- close(zis);
- }
- }
-
- private void verifyDirContents(File expectedBase, File actualBase) throws IOException {
- String[] expectedFiles = expectedBase.list();
- for (int i = 0; i < expectedFiles.length; i++) {
- File expected = new File(expectedBase, expectedFiles[i]);
- File actual = new File(actualBase, expectedFiles[i]);
-
- if (expected.isDirectory()) {
- assertTrue("Directory '" + expectedFiles[i] + "' does not exist in " + actualBase, actual.isDirectory());
- verifyDirContents(expected, actual);
- }
- else if (expected.isFile()) {
- assertTrue("File '" + expectedFiles[i] + "' does not exist in " + actualBase, actual.isFile());
- verifyFileContents(expected, actual);
- }
- else {
- fail("Unknown entity: '" + expectedFiles[i] + "'");
- }
- }
- }
-
- private void verifyFileContents(File expected, File actual) throws IOException {
- assertEquals("File size mismatch!", expected.length(), actual.length());
-
- FileInputStream fis1 = null;
- FileInputStream fis2 = null;
- try {
- fis1 = new FileInputStream(expected);
- fis2 = new FileInputStream(actual);
-
- int eb;
- while ((eb = fis1.read()) != -1) {
- int ab = fis2.read();
- assertEquals(eb, ab);
- }
- }
- finally {
- close(fis2);
- close(fis1);
- }
- }
-}
diff --git a/deploymentadmin/itest/pom.xml b/deploymentadmin/itest/pom.xml
deleted file mode 100644
index bf8d751b2c..0000000000
--- a/deploymentadmin/itest/pom.xml
+++ /dev/null
@@ -1,214 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!-- 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. -->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
- <modelVersion>4.0.0</modelVersion>
- <parent>
- <groupId>org.apache.felix</groupId>
- <artifactId>felix-parent</artifactId>
- <version>3</version>
- <relativePath>../../pom/pom.xml</relativePath>
- </parent>
- <properties>
- <osgi.version>4.2.0</osgi.version>
- <pax.exam.version>3.6.0</pax.exam.version>
- <pax.url.version>2.6.2</pax.url.version>
- </properties>
- <name>Apache Felix DeploymentAdmin Integration Tests</name>
- <version>0.1.1-SNAPSHOT</version>
- <artifactId>org.apache.felix.deploymentadmin.itest</artifactId>
- <packaging>jar</packaging>
- <dependencies>
-
- <dependency>
- <groupId>org.apache.felix</groupId>
- <artifactId>org.apache.felix.framework</artifactId>
- <version>4.4.1</version>
- <scope>test</scope>
- </dependency>
-
- <dependency>
- <groupId>javax.inject</groupId>
- <artifactId>javax.inject</artifactId>
- <version>1</version>
- <scope>test</scope>
- </dependency>
-
- <dependency>
- <groupId>org.osgi</groupId>
- <artifactId>org.osgi.compendium</artifactId>
- <version>${osgi.version}</version>
- <scope>test</scope>
- </dependency>
-
- <dependency>
- <groupId>org.apache.felix</groupId>
- <artifactId>org.apache.felix.dependencymanager</artifactId>
- <version>4.1.1</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.felix</groupId>
- <artifactId>org.apache.felix.deploymentadmin</artifactId>
- <version>0.9.8-SNAPSHOT</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.felix</groupId>
- <artifactId>org.apache.felix.metatype</artifactId>
- <version>1.1.2</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.felix</groupId>
- <artifactId>org.apache.felix.configadmin</artifactId>
- <version>1.8.0</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.felix</groupId>
- <artifactId>org.apache.felix.eventadmin</artifactId>
- <version>1.3.2</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.apache.felix</groupId>
- <artifactId>org.apache.felix.log</artifactId>
- <version>1.0.1</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>commons-codec</groupId>
- <artifactId>commons-codec</artifactId>
- <version>1.10</version>
- <scope>test</scope>
- </dependency>
-
- <dependency>
- <groupId>org.ops4j.pax.exam</groupId>
- <artifactId>pax-exam-junit4</artifactId>
- <version>${pax.exam.version}</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.ops4j.pax.exam</groupId>
- <artifactId>pax-exam-container-native</artifactId>
- <version>${pax.exam.version}</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.ops4j.pax.exam</groupId>
- <artifactId>pax-exam-link-mvn</artifactId>
- <version>${pax.exam.version}</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.ops4j.pax.url</groupId>
- <artifactId>pax-url-aether</artifactId>
- <version>${pax.url.version}</version>
- <scope>test</scope>
- </dependency>
-
- <dependency>
- <groupId>org.bouncycastle</groupId>
- <artifactId>bcprov-jdk15on</artifactId>
- <version>1.67</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.bouncycastle</groupId>
- <artifactId>bcpkix-jdk15on</artifactId>
- <version>1.64</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>ch.qos.logback</groupId>
- <artifactId>logback-core</artifactId>
- <version>1.2.9</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>ch.qos.logback</groupId>
- <artifactId>logback-classic</artifactId>
- <version>1.2.0</version>
- <scope>test</scope>
- </dependency>
-
- </dependencies>
- <build>
- <plugins>
- <plugin>
- <groupId>org.apache.servicemix.tooling</groupId>
- <artifactId>depends-maven-plugin</artifactId>
- <executions>
- <execution>
- <id>generate-depends-file</id>
- <goals>
- <goal>generate-depends-file</goal>
- </goals>
- </execution>
- </executions>
- </plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-compiler-plugin</artifactId>
- <configuration>
- <source>1.7</source>
- <target>1.7</target>
- </configuration>
- </plugin>
- </plugins>
- <pluginManagement>
- <plugins>
- <!--This plugin's configuration is used to store Eclipse m2e settings
- only. It has no influence on the Maven build itself. -->
- <plugin>
- <groupId>org.eclipse.m2e</groupId>
- <artifactId>lifecycle-mapping</artifactId>
- <version>1.0.0</version>
- <configuration>
- <lifecycleMappingMetadata>
- <pluginExecutions>
- <pluginExecution>
- <pluginExecutionFilter>
- <groupId>
- org.apache.servicemix.tooling
- </groupId>
- <artifactId>
- depends-maven-plugin
- </artifactId>
- <versionRange>
- [1.2,)
- </versionRange>
- <goals>
- <goal>
- generate-depends-file
- </goal>
- </goals>
- </pluginExecutionFilter>
- <action>
- <ignore></ignore>
- </action>
- </pluginExecution>
- </pluginExecutions>
- </lifecycleMappingMetadata>
- </configuration>
- </plugin>
- </plugins>
- </pluginManagement>
- </build>
-</project>
diff --git a/deploymentadmin/itest/src/test/java/org/apache/felix/deploymentadmin/itest/BaseIntegrationTest.java b/deploymentadmin/itest/src/test/java/org/apache/felix/deploymentadmin/itest/BaseIntegrationTest.java
deleted file mode 100644
index 546956a45d..0000000000
--- a/deploymentadmin/itest/src/test/java/org/apache/felix/deploymentadmin/itest/BaseIntegrationTest.java
+++ /dev/null
@@ -1,317 +0,0 @@
-/*
- * 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.itest;
-
-import static org.ops4j.pax.exam.CoreOptions.*;
-
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.security.Security;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.atomic.AtomicInteger;
-
-import javax.inject.Inject;
-
-import junit.framework.TestCase;
-
-import org.apache.felix.deploymentadmin.itest.util.DeploymentPackageBuilder;
-import org.bouncycastle.jce.provider.BouncyCastleProvider;
-import org.junit.After;
-import org.junit.Before;
-import org.ops4j.pax.exam.Configuration;
-import org.ops4j.pax.exam.Option;
-import org.osgi.framework.Bundle;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.FrameworkEvent;
-import org.osgi.framework.FrameworkListener;
-import org.osgi.framework.Version;
-import org.osgi.framework.wiring.FrameworkWiring;
-import org.osgi.service.cm.ConfigurationAdmin;
-import org.osgi.service.deploymentadmin.DeploymentAdmin;
-import org.osgi.service.deploymentadmin.DeploymentException;
-import org.osgi.service.deploymentadmin.DeploymentPackage;
-import org.osgi.util.tracker.ServiceTracker;
-
-/**
- * Provides a common base class for all deployment admin related integration tests.
- */
-public abstract class BaseIntegrationTest extends TestCase {
-
- protected static final int DEFAULT_TIMEOUT = 10000;
-
- protected static final String TEST_SERVICE_NAME = "org.apache.felix.deploymentadmin.test.bundle1.TestService";
- protected static final String TEST_FAILING_BUNDLE_RP1 = "org.apache.felix.deploymentadmin.test.rp1";
-
- @Inject
- protected volatile BundleContext m_context;
- @Inject
- protected volatile DeploymentAdmin m_deploymentAdmin;
- @Inject
- protected volatile ConfigurationAdmin m_configAdmin;
-
- protected volatile AtomicInteger m_gate = new AtomicInteger(0);
- protected volatile String m_testBundleBasePath;
- protected volatile Map<String, List<Version>> m_initialBundles;
-
- private int cnt = 0;
-
- @Configuration
- public Option[] config() throws Exception {
- return options(bootDelegationPackage("sun.*"), systemProperty("org.ops4j.pax.logging.DefaultServiceLog.level").value("ERROR"),
-
- mavenBundle("org.apache.felix", "org.apache.felix.metatype").versionAsInProject(),
- mavenBundle("org.apache.felix", "org.apache.felix.dependencymanager").versionAsInProject(),
- mavenBundle("org.apache.felix", "org.apache.felix.deploymentadmin").versionAsInProject(),
- mavenBundle("org.apache.felix", "org.apache.felix.eventadmin").versionAsInProject(),
- mavenBundle("org.apache.felix", "org.apache.felix.configadmin").versionAsInProject(),
- mavenBundle("commons-codec", "commons-codec").versionAsInProject(),
- mavenBundle("org.bouncycastle", "bcprov-jdk15on").versionAsInProject(),
- mavenBundle("org.bouncycastle", "bcpkix-jdk15on").versionAsInProject(),
-
- junitBundles());
- }
-
- @Before
- public void setUp() throws Exception {
- assertNotNull("No bundle context?!", m_context);
-
- File f = new File("../testbundles").getAbsoluteFile();
- assertTrue("Failed to find test bundles directory?!", f.exists() && f.isDirectory());
-
- m_testBundleBasePath = f.getAbsolutePath();
-
- m_context.addFrameworkListener(new FrameworkListener() {
- public void frameworkEvent(FrameworkEvent event) {
- if (event.getType() == FrameworkEvent.PACKAGES_REFRESHED) {
- m_gate.getAndIncrement();
- }
- }
- });
-
- m_initialBundles = new HashMap<String, List<Version>>();
-
- for (Bundle bundle : m_context.getBundles()) {
- List<Version> versions = m_initialBundles.get(bundle.getSymbolicName());
- if (versions == null) {
- versions = new ArrayList<Version>();
- m_initialBundles.put(bundle.getSymbolicName(), versions);
- }
- versions.add(bundle.getVersion());
- }
-
- Security.addProvider(new BouncyCastleProvider());
- }
-
- @After
- public void tearDown() throws Exception {
- System.setProperty("rp1", "");
- System.setProperty("bundle3", "");
-
- Security.removeProvider(BouncyCastleProvider.PROVIDER_NAME);
- }
-
- protected void assertBundleExists(String symbolicName, String version) {
- boolean result = isBundleAdded(symbolicName, version);
- if (!result) {
- fail("Bundle " + symbolicName + ", v" + version + " does not exist?!\nCurrent additional bundles are: " + getCurrentBundles());
- }
- }
-
- protected void assertBundleNotExists(String symbolicName, String version) {
- boolean result = isBundleAdded(symbolicName, version);
- if (result) {
- fail("Bundle " + symbolicName + ", v" + version + " does (still) exist?!\nCurrent additional bundles are: " + getCurrentBundles());
- }
- }
-
- protected void assertDeploymentException(int expectedCode, DeploymentException exception) {
- assertEquals("Invalid exception code?!\nException = " + exception, expectedCode, exception.getCode());
- }
-
- protected void awaitRefreshPackagesEvent() throws Exception {
- long start = System.currentTimeMillis();
- while ((m_gate.get() == 0) && ((System.currentTimeMillis() - start) < DEFAULT_TIMEOUT)) {
- TimeUnit.MILLISECONDS.sleep(100);
- }
- assertTrue("Failed to obtain refresh packages event?! " + m_gate.get(), m_gate.get() > 0);
- m_gate.set(0);
- }
-
- protected <T> T awaitService(String serviceName) throws Exception {
- ServiceTracker tracker = new ServiceTracker(m_context, serviceName, null);
- tracker.open();
- T result;
- try {
- result = (T) tracker.waitForService(DEFAULT_TIMEOUT);
- }
- finally {
- tracker.close();
- }
- return result;
- }
-
- protected final DeploymentPackage installDeploymentPackage(DeploymentPackageBuilder dpBuilder) throws Exception {
- return installDeploymentPackage(dpBuilder.generate());
- }
-
- protected final DeploymentPackage installDeploymentPackage(InputStream is) throws Exception {
- try {
- return m_deploymentAdmin.installDeploymentPackage(is);
- }
- finally {
- try {
- is.close();
- }
- catch (IOException e) {
- // Nothing we can do about this, but log it...
- e.printStackTrace();
- }
- }
- }
-
- protected final int countDeploymentPackages() {
- return m_deploymentAdmin.listDeploymentPackages().length;
- }
-
- protected DeploymentPackageBuilder createNewDeploymentPackageBuilder(String version) {
- return createDeploymentPackageBuilder(String.format("itest%d", ++cnt), version);
- }
-
- protected DeploymentPackageBuilder createDeploymentPackageBuilder(String symName, String version) {
- return DeploymentPackageBuilder.create(symName, version);
- }
-
- protected Map<String, List<Version>> getCurrentBundles() {
- Map<String, List<Version>> bundles = new HashMap<String, List<Version>>();
- for (Bundle bundle : m_context.getBundles()) {
- String symbolicName = bundle.getSymbolicName();
- Version version = bundle.getVersion();
-
- // Is is not part of any of the initially provisioned bundles?
- List<Version> versions = m_initialBundles.get(symbolicName);
- if ((versions == null) || !versions.contains(version)) {
- List<Version> versions2 = bundles.get(symbolicName);
- if (versions2 == null) {
- versions2 = new ArrayList<Version>();
- bundles.put(symbolicName, versions2);
- }
- versions2.add(version);
- }
- }
- return bundles;
- }
-
- protected String getSymbolicName(String baseName) {
- return "testbundles.".concat(baseName);
- }
-
- protected URL getTestResource(String resourceName) {
- if (!resourceName.startsWith("/")) {
- resourceName = "/".concat(resourceName);
- }
- URL resource = getClass().getResource(resourceName);
- assertNotNull("No such resource: " + resourceName, resource);
- return resource;
- }
-
- protected Bundle getBundle(String bsn) {
- for (Bundle b : m_context.getBundles()) {
- if (bsn.equals(b.getSymbolicName())) {
- return b;
- }
- }
- return null;
- }
-
- protected URL getTestBundleURL(String baseName) throws MalformedURLException {
- return getTestBundleURL(baseName, "1.0.0");
- }
-
- protected URL getTestBundleURL(String baseName, String version) throws MalformedURLException {
- return getTestBundleURL(baseName, baseName, version);
- }
-
- protected URL getTestBundleURL(String artifactName, String baseName, String version) throws MalformedURLException {
- assertNotNull("Version cannot be null!", version);
- File f = new File(m_testBundleBasePath, String.format("%1$s/target/org.apache.felix.deploymentadmin.test.%2$s-%3$s.jar", artifactName, baseName, version));
- assertTrue("No such bundle: " + f, f.exists() && f.isFile());
- return f.toURI().toURL();
- }
-
- protected boolean isBundleActive(Bundle bundle) {
- return isBundleInState(bundle, Bundle.ACTIVE);
- }
-
- protected boolean isBundleAdded(String symbolicName, String version) {
- return isBundleAdded(symbolicName, new Version(version));
- }
-
- protected boolean isBundleAdded(String symbolicName, Version version) {
- Map<String, List<Version>> bundles = getCurrentBundles();
-
- List<Version> availableVersions = bundles.get(symbolicName);
- return (availableVersions != null) && availableVersions.contains(version);
- }
-
- protected boolean isBundleInstalled(Bundle bundle) {
- return isBundleInState(bundle, Bundle.INSTALLED);
- }
-
- protected boolean isBundleInState(Bundle bundle, int state) {
- return ((bundle.getState() & state) != 0);
- }
-
- protected boolean isBundleRemoved(String symbolicName, String version) {
- return isBundleRemoved(symbolicName, new Version(version));
- }
-
- protected boolean isBundleRemoved(String symbolicName, Version version) {
- Map<String, List<Version>> bundles = getCurrentBundles();
-
- List<Version> availableVersions = bundles.get(symbolicName);
- return (availableVersions == null) || !availableVersions.contains(version);
- }
-
- protected boolean isBundleResolved(Bundle bundle) {
- return isBundleInState(bundle, Bundle.RESOLVED);
- }
-
- protected boolean resolveBundles(Bundle... bundles) throws Exception {
- Bundle systemBundle = m_context.getBundle(0L);
-
- FrameworkWiring frameworkWiring = systemBundle.adapt(FrameworkWiring.class);
- frameworkWiring.resolveBundles(Arrays.asList(bundles));
-
- for (Bundle bundle : bundles) {
- if ((bundle.getState() & Bundle.RESOLVED) == 0) {
- return false;
- }
- }
-
- return true;
- }
-}
diff --git a/deploymentadmin/itest/src/test/java/org/apache/felix/deploymentadmin/itest/CustomizerTest.java b/deploymentadmin/itest/src/test/java/org/apache/felix/deploymentadmin/itest/CustomizerTest.java
deleted file mode 100644
index 44c94d1cb0..0000000000
--- a/deploymentadmin/itest/src/test/java/org/apache/felix/deploymentadmin/itest/CustomizerTest.java
+++ /dev/null
@@ -1,254 +0,0 @@
-/*
- * 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.itest;
-
-import static org.osgi.service.deploymentadmin.DeploymentException.CODE_FOREIGN_CUSTOMIZER;
-import static org.osgi.service.deploymentadmin.DeploymentException.CODE_OTHER_ERROR;
-import static org.osgi.service.deploymentadmin.DeploymentException.CODE_PROCESSOR_NOT_FOUND;
-
-import org.apache.felix.deploymentadmin.itest.util.DeploymentPackageBuilder;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.ops4j.pax.exam.junit.PaxExam;
-import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
-import org.ops4j.pax.exam.spi.reactors.PerMethod;
-import org.osgi.service.deploymentadmin.DeploymentException;
-import org.osgi.service.deploymentadmin.DeploymentPackage;
-
-/**
- * Provides test cases on the use of customizers in Deployment Admin.
- */
-@RunWith(PaxExam.class)
-@ExamReactorStrategy(PerMethod.class)
-public class CustomizerTest extends BaseIntegrationTest {
-
- /**
- * FELIX-4491 - Only resources with a resource processor defined should be processed.
- */
- @Test
- public void testInstallBundleWithNonProcessedResourcesOk() throws Exception {
- DeploymentPackageBuilder dpBuilder = createNewDeploymentPackageBuilder("1.0.0");
- dpBuilder
- .add(dpBuilder.createResource().setNeedResourceProcessor(false).setUrl(getTestResource("LICENSE")))
- .add(dpBuilder.createResourceProcessorResource().setUrl(getTestBundleURL("rp1")))
- .add(dpBuilder.createResource().setResourceProcessorPID(TEST_FAILING_BUNDLE_RP1).setUrl(getTestResource("test-config1.xml")))
- .add(dpBuilder.createBundleResource().setUrl(getTestBundleURL("bundle1")));
-
- DeploymentPackage dp = installDeploymentPackage(dpBuilder);
- assertNotNull("No deployment package returned?!", dp);
-
- assertEquals("Expected a single deployment package?!", 1, countDeploymentPackages());
-
- awaitRefreshPackagesEvent();
-
- assertBundleExists(getSymbolicName("bundle1"), "1.0.0");
-
- // Check that only the processed resources are dropped...
- dp.uninstall();
-
- assertEquals("Expected no deployment package?!", 0, countDeploymentPackages());
-
- awaitRefreshPackagesEvent();
-
- assertBundleNotExists(getSymbolicName("bundle1"), "1.0.0");
- }
-
- /**
- * Tests that if an exception is thrown during the commit-phase, the installation proceeds and succeeds.
- */
- @Test
- public void testInstallBundleWithExceptionThrowingInCommitCauseNoRollbackOk() throws Exception {
- System.setProperty("rp1", "commit");
-
- DeploymentPackageBuilder dpBuilder = createNewDeploymentPackageBuilder("1.0.0");
- dpBuilder
- .add(dpBuilder.createResourceProcessorResource().setUrl(getTestBundleURL("rp1")))
- .add(dpBuilder.createResource().setResourceProcessorPID(TEST_FAILING_BUNDLE_RP1).setUrl(getTestResource("test-config1.xml")))
- .add(dpBuilder.createBundleResource().setUrl(getTestBundleURL("bundle3")));
-
- DeploymentPackage dp = installDeploymentPackage(dpBuilder);
- assertNotNull("No deployment package returned?!", dp);
-
- awaitRefreshPackagesEvent();
-
- // Though the commit failed; the package should be installed...
- assertBundleExists(getSymbolicName("rp1"), "1.0.0");
- assertBundleExists(getSymbolicName("bundle3"), "1.0.0");
-
- assertEquals("Expected a single deployment package?!", 1, countDeploymentPackages());
- }
-
- /**
- * Tests that if an exception is thrown during the prepare-phase, the installation is cancelled and rolled back.
- */
- @Test
- public void testInstallBundleWithExceptionThrowingInPrepareCausesRollbackOk() throws Exception {
- System.setProperty("rp1", "prepare");
-
- DeploymentPackageBuilder dpBuilder = createNewDeploymentPackageBuilder("1.0.0");
- dpBuilder
- .add(dpBuilder.createResourceProcessorResource().setUrl(getTestBundleURL("rp1")))
- .add(dpBuilder.createResource().setResourceProcessorPID(TEST_FAILING_BUNDLE_RP1).setUrl(getTestResource("test-config1.xml")));
-
- try {
- installDeploymentPackage(dpBuilder);
- fail("Succeeded into installing a failing deployment package?!");
- }
- catch (DeploymentException exception) {
- // Ok; expected
- assertDeploymentException(DeploymentException.CODE_COMMIT_ERROR, exception);
- }
-
- assertTrue("No bundles should be started!", getCurrentBundles().isEmpty());
-
- assertEquals("Expected no deployment package?!", 0, countDeploymentPackages());
- }
-
- /**
- * Tests that if an exception is thrown during the processing of a resource, the installation is cancelled and rolled back.
- */
- @Test
- public void testInstallResourceWithExceptionThrowingInProcessCausesRollbackOk() throws Exception {
- System.setProperty("rp1", "process");
-
- DeploymentPackageBuilder dpBuilder = createNewDeploymentPackageBuilder("1.0.0");
- dpBuilder
- .add(dpBuilder.createResourceProcessorResource().setUrl(getTestBundleURL("rp1")))
- .add(dpBuilder.createResource().setResourceProcessorPID(TEST_FAILING_BUNDLE_RP1).setUrl(getTestResource("test-config1.xml")));
-
- try {
- installDeploymentPackage(dpBuilder);
- fail("Succeeded into installing a failing deployment package?!");
- }
- catch (DeploymentException exception) {
- // Ok; expected
- assertDeploymentException(DeploymentException.CODE_RESOURCE_SHARING_VIOLATION, exception);
- }
-
- assertTrue("No bundles should be started!", getCurrentBundles().isEmpty());
-
- assertEquals("Expected no deployment package?!", 0, countDeploymentPackages());
- }
-
- /**
- * Tests that if an exception is thrown during the dropping of a resource, the installation is continued and finishes normally.
- */
- @Test
- public void testDropResourceWithExceptionThrowingInDroppedCausesRollbackOk() throws Exception {
- System.setProperty("rp1", "dropped");
-
- DeploymentPackageBuilder dpBuilder = createNewDeploymentPackageBuilder("1.0.0");
- dpBuilder
- .add(dpBuilder.createResourceProcessorResource().setUrl(getTestBundleURL("rp1")))
- .add(dpBuilder.createResource().setResourceProcessorPID(TEST_FAILING_BUNDLE_RP1).setUrl(getTestResource("test-config1.xml")));
-
- DeploymentPackage dp = installDeploymentPackage(dpBuilder);
- assertNotNull("No deployment package returned?!", dp);
-
- awaitRefreshPackagesEvent();
-
- assertTrue("One bundle should be started!", getCurrentBundles().size() == 1);
-
- assertEquals("Expected no deployment package?!", 1, countDeploymentPackages());
- }
-
- /**
- * Tests that if an exception is thrown during the commit-phase, the installation proceeds and succeeds.
- */
- @Test
- public void testInstallResourceProcessorWithExceptionThrowingInStartCausesRollbackOk() throws Exception {
- System.setProperty("rp1", "start");
-
- DeploymentPackageBuilder dpBuilder = createNewDeploymentPackageBuilder("1.0.0");
- dpBuilder
- .add(dpBuilder.createResourceProcessorResource().setUrl(getTestBundleURL("rp1")))
- .add(dpBuilder.createResource().setResourceProcessorPID(TEST_FAILING_BUNDLE_RP1).setUrl(getTestResource("test-config1.xml")))
- .add(dpBuilder.createBundleResource().setUrl(getTestBundleURL("bundle3")));
-
- try {
- installDeploymentPackage(dpBuilder);
- fail("Succeeded into installing a failing RP?!");
- }
- catch (DeploymentException exception) {
- // Ok; expected...
- assertDeploymentException(CODE_OTHER_ERROR, exception);
- }
-
- assertEquals("Expected no deployment package?!", 0, countDeploymentPackages());
- assertTrue("Expected no artifacts to be installed?!", getCurrentBundles().isEmpty());
- }
-
- /**
- * Tests that if a resource is installed which mentions a RP that does not belong to the same package, a rollback takes place.
- */
- @Test
- public void testInstallResourceWithForeignCustomizerFail() throws Exception {
- DeploymentPackageBuilder dpBuilder = createNewDeploymentPackageBuilder("1.0.0");
- dpBuilder
- .add(dpBuilder.createResourceProcessorResource().setUrl(getTestBundleURL("rp1")));
-
- installDeploymentPackage(dpBuilder);
-
- awaitRefreshPackagesEvent();
-
- assertEquals("Expected no deployment package?!", 1, countDeploymentPackages());
- assertBundleExists(getSymbolicName("rp1"), "1.0.0");
-
- dpBuilder = createNewDeploymentPackageBuilder("1.0.0");
- dpBuilder
- .disableVerification()
- .add(dpBuilder.createResource().setResourceProcessorPID(TEST_FAILING_BUNDLE_RP1).setUrl(getTestResource("test-config1.xml")));
-
- try {
- installDeploymentPackage(dpBuilder);
- fail("Succeeded into installing a resource with an non-existing RP?!");
- }
- catch (DeploymentException exception) {
- // Ok; expected...
- assertDeploymentException(CODE_FOREIGN_CUSTOMIZER, exception);
- }
-
- assertEquals("Expected no deployment package?!", 1, countDeploymentPackages());
- assertTrue("Expected no additional artifacts to be installed?!", getCurrentBundles().size() == 1);
- }
-
- /**
- * Tests that if a resource is installed which mentions a RP that does not exist a rollback takes place.
- */
- @Test
- public void testInstallResourceWithNonAvailableCustomizerFail() throws Exception {
- DeploymentPackageBuilder dpBuilder = createNewDeploymentPackageBuilder("1.0.0");
- dpBuilder
- .disableVerification()
- .add(dpBuilder.createResource().setResourceProcessorPID("my.unknown.rp").setUrl(getTestResource("test-config1.xml")));
-
- try {
- installDeploymentPackage(dpBuilder);
- fail("Succeeded into installing a resource with an non-existing RP?!");
- }
- catch (DeploymentException exception) {
- // Ok; expected...
- assertDeploymentException(CODE_PROCESSOR_NOT_FOUND, exception);
- }
-
- assertEquals("Expected no deployment package?!", 0, countDeploymentPackages());
- assertTrue("Expected no artifacts to be installed?!", getCurrentBundles().isEmpty());
- }
-
-}
diff --git a/deploymentadmin/itest/src/test/java/org/apache/felix/deploymentadmin/itest/DPSignerTest.java b/deploymentadmin/itest/src/test/java/org/apache/felix/deploymentadmin/itest/DPSignerTest.java
deleted file mode 100644
index 499906bd58..0000000000
--- a/deploymentadmin/itest/src/test/java/org/apache/felix/deploymentadmin/itest/DPSignerTest.java
+++ /dev/null
@@ -1,84 +0,0 @@
-/*
- * 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.itest;
-
-import static junit.framework.TestCase.assertNotNull;
-import static org.apache.felix.deploymentadmin.itest.BaseIntegrationTest.TEST_FAILING_BUNDLE_RP1;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.net.URL;
-import java.security.Security;
-import java.util.jar.JarEntry;
-import java.util.jar.JarInputStream;
-
-import org.apache.felix.deploymentadmin.itest.util.CertificateUtil;
-import org.apache.felix.deploymentadmin.itest.util.CertificateUtil.KeyType;
-import org.apache.felix.deploymentadmin.itest.util.CertificateUtil.SignerInfo;
-import org.apache.felix.deploymentadmin.itest.util.DPSigner;
-import org.apache.felix.deploymentadmin.itest.util.DeploymentPackageBuilder;
-import org.bouncycastle.jce.provider.BouncyCastleProvider;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-
-/**
- * Test cases for {@link DPSigner}.
- */
... 5753 lines suppressed ...