You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ace.apache.org by ma...@apache.org on 2010/05/08 20:27:57 UTC
svn commit: r942437 - in /incubator/ace/trunk/ace-util: ./
src/main/java/org/apache/ace/test/utils/deployment/
Author: marrs
Date: Sat May 8 18:27:56 2010
New Revision: 942437
URL: http://svn.apache.org/viewvc?rev=942437&view=rev
Log:
Added some extra deployment related utilities for tests.
Added:
incubator/ace/trunk/ace-util/src/main/java/org/apache/ace/test/utils/deployment/
incubator/ace/trunk/ace-util/src/main/java/org/apache/ace/test/utils/deployment/BundleStreamGenerator.java
incubator/ace/trunk/ace-util/src/main/java/org/apache/ace/test/utils/deployment/TestData.java
incubator/ace/trunk/ace-util/src/main/java/org/apache/ace/test/utils/deployment/TestProvider.java
Modified:
incubator/ace/trunk/ace-util/pom.xml
Modified: incubator/ace/trunk/ace-util/pom.xml
URL: http://svn.apache.org/viewvc/incubator/ace/trunk/ace-util/pom.xml?rev=942437&r1=942436&r2=942437&view=diff
==============================================================================
--- incubator/ace/trunk/ace-util/pom.xml (original)
+++ incubator/ace/trunk/ace-util/pom.xml Sat May 8 18:27:56 2010
@@ -44,6 +44,10 @@
<groupId>org.osgi</groupId>
<artifactId>org.osgi.compendium</artifactId>
</dependency>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>ace-deployment-provider-api</artifactId>
+ <version>${project.version}</version>
+ </dependency>
</dependencies>
-
</project>
\ No newline at end of file
Added: incubator/ace/trunk/ace-util/src/main/java/org/apache/ace/test/utils/deployment/BundleStreamGenerator.java
URL: http://svn.apache.org/viewvc/incubator/ace/trunk/ace-util/src/main/java/org/apache/ace/test/utils/deployment/BundleStreamGenerator.java?rev=942437&view=auto
==============================================================================
--- incubator/ace/trunk/ace-util/src/main/java/org/apache/ace/test/utils/deployment/BundleStreamGenerator.java (added)
+++ incubator/ace/trunk/ace-util/src/main/java/org/apache/ace/test/utils/deployment/BundleStreamGenerator.java Sat May 8 18:27:56 2010
@@ -0,0 +1,67 @@
+/*
+ * 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.ace.test.utils.deployment;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.net.URISyntaxException;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.jar.JarOutputStream;
+import java.util.jar.Manifest;
+
+import org.apache.ace.deployment.provider.ArtifactData;
+import org.osgi.framework.Constants;
+
+public class BundleStreamGenerator {
+
+ public static Manifest getBundleManifest(String symbolicname, String version, Map<String, String> additionalHeaders) {
+ Manifest manifest = new Manifest();
+ manifest.getMainAttributes().putValue("Manifest-Version", "1");
+ manifest.getMainAttributes().putValue(Constants.BUNDLE_MANIFESTVERSION, "2");
+ manifest.getMainAttributes().putValue(Constants.BUNDLE_SYMBOLICNAME, symbolicname);
+ manifest.getMainAttributes().putValue(Constants.BUNDLE_VERSION, version.toString());
+ for (Map.Entry<String, String> entry : additionalHeaders.entrySet()) {
+ manifest.getMainAttributes().putValue(entry.getKey(), entry.getValue());
+ }
+ return manifest;
+ }
+
+ public static void generateBundle(ArtifactData data, Map<String, String> additionalHeaders) throws IOException {
+ OutputStream bundleStream = null;
+ try {
+ File dataFile = new File(data.getUrl().toURI());
+ OutputStream fileStream = new FileOutputStream(dataFile);
+ bundleStream = new JarOutputStream(fileStream, getBundleManifest(data.getSymbolicName(), data.getVersion(), additionalHeaders));
+ bundleStream.flush();
+ } catch (URISyntaxException e) {
+ throw new IOException();
+ } finally {
+ if (bundleStream != null) {
+ bundleStream.close();
+ }
+ }
+ }
+
+ public static void generateBundle(ArtifactData data) throws IOException {
+ generateBundle(data, new HashMap<String, String>());
+ }
+}
Added: incubator/ace/trunk/ace-util/src/main/java/org/apache/ace/test/utils/deployment/TestData.java
URL: http://svn.apache.org/viewvc/incubator/ace/trunk/ace-util/src/main/java/org/apache/ace/test/utils/deployment/TestData.java?rev=942437&view=auto
==============================================================================
--- incubator/ace/trunk/ace-util/src/main/java/org/apache/ace/test/utils/deployment/TestData.java (added)
+++ incubator/ace/trunk/ace-util/src/main/java/org/apache/ace/test/utils/deployment/TestData.java Sat May 8 18:27:56 2010
@@ -0,0 +1,85 @@
+/*
+ * 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.ace.test.utils.deployment;
+
+import java.net.URL;
+import java.util.jar.Attributes;
+
+import org.apache.ace.deployment.provider.ArtifactData;
+
+public class TestData implements ArtifactData {
+ private final String m_fileName;
+ private final String m_symbolicName;
+ private final URL m_url;
+ private final String m_version;
+ private final boolean m_changed;
+
+ public TestData(String fileName, String symbolicName, URL url, String version, boolean changed) {
+ m_fileName = fileName;
+ m_symbolicName = symbolicName;
+ m_url = url;
+ m_version = version;
+ m_changed = changed;
+ }
+
+ public boolean hasChanged() {
+ return m_changed;
+ }
+
+ public String getFilename() {
+ return m_fileName;
+ }
+
+ public String getSymbolicName() {
+ return m_symbolicName;
+ }
+
+ public URL getUrl() {
+ return m_url;
+ }
+
+ public String getVersion() {
+ return m_version;
+ }
+
+ public String getDirective() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public Attributes getManifestAttributes(boolean fixPackage) {
+ Attributes a = new Attributes();
+ a.putValue("Bundle-SymbolicName", getSymbolicName());
+ a.putValue("Bundle-Version", getVersion());
+ return a;
+ }
+
+ public String getProcessorPid() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public boolean isBundle() {
+ return true;
+ }
+
+ public boolean isCustomizer() {
+ return false;
+ }
+}
Added: incubator/ace/trunk/ace-util/src/main/java/org/apache/ace/test/utils/deployment/TestProvider.java
URL: http://svn.apache.org/viewvc/incubator/ace/trunk/ace-util/src/main/java/org/apache/ace/test/utils/deployment/TestProvider.java?rev=942437&view=auto
==============================================================================
--- incubator/ace/trunk/ace-util/src/main/java/org/apache/ace/test/utils/deployment/TestProvider.java (added)
+++ incubator/ace/trunk/ace-util/src/main/java/org/apache/ace/test/utils/deployment/TestProvider.java Sat May 8 18:27:56 2010
@@ -0,0 +1,59 @@
+/*
+ * 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.ace.test.utils.deployment;
+
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import org.apache.ace.deployment.provider.ArtifactData;
+import org.apache.ace.deployment.provider.DeploymentProvider;
+
+public class TestProvider implements DeploymentProvider {
+ private List<ArtifactData> m_collection;
+ private List<String> m_versions;
+
+ public TestProvider() throws Exception {
+ m_collection = new ArrayList<ArtifactData>();
+ m_versions = new ArrayList<String>();
+ }
+
+ public void addData(String fileName, String symbolicName, URL url, String version) {
+ addData(fileName, symbolicName, url, version, true);
+ }
+
+ public void addData(String fileName, String symbolicName, URL url, String version, boolean changed) {
+ m_collection.add(new TestData(fileName, symbolicName, url, version, changed));
+ m_versions.add(version);
+ }
+
+ public List<ArtifactData> getBundleData(String id, String version) {
+ return m_collection;
+ }
+
+ public List<ArtifactData> getBundleData(String id, String versionFrom, String versionTo) {
+ return m_collection;
+ }
+
+ public List<String> getVersions(String id) throws IllegalArgumentException {
+ Collections.sort(m_versions);
+ return m_versions;
+ }
+}