Initial commit of "simple" example bundle.
git-svn-id: https://svn.apache.org/repos/asf/incubator/felix/trunk@464985 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/simple/build.xml b/simple/build.xml
new file mode 100644
index 0000000..5ec0b7a
--- /dev/null
+++ b/simple/build.xml
@@ -0,0 +1,94 @@
+<project name="simplebundle" default="all" basedir=".">
+
+ <!-- Set global properties. -->
+ <property name="bundle.name" value="simple"/>
+ <property name="src.dir" value="src"/>
+ <property name="lib.dir" value="lib"/>
+ <property name="output.dir" value="classes"/>
+ <property name="bundle.dir" value="."/>
+ <property name="doc.dir" value="doc"/>
+ <property name="apidoc.dir" value="${doc.dir}/api"/>
+ <property name="dist.dir" value="."/>
+ <property name="native.dir" value="native"/>
+ <property name="debug.flag" value="on"/>
+
+ <!-- Create class path from lib and output directories. -->
+ <path id="classpath">
+ <pathelement location="${output.dir}"/>
+ <fileset dir="${lib.dir}">
+ <include name="*.jar"/>
+ </fileset>
+ </path>
+
+ <!-- Create output directory. -->
+ <target name="init">
+ <mkdir dir="${output.dir}"/>
+ </target>
+
+ <!-- Compile and JAR everything -->
+ <target name="all" depends="init">
+ <antcall target="compile"/>
+ <antcall target="jar"/>
+ </target>
+
+ <!-- Compile everything. -->
+ <target name="compile" depends="init">
+ <javac srcdir="${src.dir}" destdir="${output.dir}"
+ debug="${debug.flag}" verbose="no" deprecation="no">
+ <classpath refid="classpath"/>
+ <include name="**/*.java"/>
+ </javac>
+ </target>
+
+ <!-- JAR the bundle. -->
+ <target name="jar" depends="compile">
+ <jar jarfile="${output.dir}/org/apache/felix/${bundle.name}/embedded.jar"
+ basedir="${output.dir}">
+ <include name="org/apache/felix/${bundle.name}/embedded/**"/>
+ </jar>
+
+ <copy todir="${output.dir}">
+ <fileset dir="${native.dir}">
+ <include name="libfoo.so"/>
+ </fileset>
+ </copy>
+
+ <jar manifest="${src.dir}/org/apache/felix/${bundle.name}/manifest.mf"
+ jarfile="${bundle.dir}/${bundle.name}.jar"
+ basedir="${output.dir}">
+ <include name="org/apache/felix/${bundle.name}/**"/>
+ <include name="libfoo.so"/>
+ <exclude name="org/apache/felix/${bundle.name}/embedded/"/>
+ </jar>
+ </target>
+
+ <!-- Create the source distribution JAR file. -->
+ <target name="dist">
+ <!-- Create API doc directory. -->
+ <mkdir dir="${apidoc.dir}"/>
+ <!-- Generate API documentation. -->
+ <javadoc sourcepath="${src.dir}"
+ packagenames="*"
+ destdir="${apidoc.dir}"
+ author="true"
+ windowtitle="${bundle.name} API Documentation"/>
+ <!-- JAR the source and doc trees. -->
+ <jar jarfile="${dist.dir}/${bundle.name}-src.jar"
+ basedir="..">
+ <include name="${bundle.name}/LICENSE.txt"/>
+ <include name="${bundle.name}/build.xml"/>
+ <include name="${bundle.name}/${lib.dir}/**"/>
+ <include name="${bundle.name}/${doc.dir}/**"/>
+ <include name="${bundle.name}/${src.dir}/**"/>
+ </jar>
+ </target>
+
+ <!-- Clean up everything. -->
+ <target name="clean">
+ <delete dir="${output.dir}"/>
+ <delete dir="${apidoc.dir}"/>
+ <delete file="${bundle.dir}/${bundle.name}.jar"/>
+ <delete file="${dist.dir}/${bundle.name}-src.jar"/>
+ </target>
+
+</project>
diff --git a/simple/doc/index.html b/simple/doc/index.html
new file mode 100644
index 0000000..5015338
--- /dev/null
+++ b/simple/doc/index.html
@@ -0,0 +1,36 @@
+<!DOCTYPE doctype PUBLIC "-//w3c//dtd html 4.0 transitional//en">
+<html>
+<head>
+ <meta http-equiv="Content-Type"
+ content="text/html; charset=iso-8859-1">
+ <meta name="Author" content="Richard S. Hall">
+ <title>Simple</title>
+</head>
+<body alink="#ff0000" vlink="#551a8b" link="#0000ee" bgcolor="#ffffff"
+ text="#000000">
+<font face="sans-serif">
+<h1><i><font color="#0000aa">Simple<br>
+</font></i></h1>
+<p><b>Description</b><br>
+A very simple bundle that demonstrates four different issues. It
+demonstrates the basics for creating a bundle. It also
+demonstates how to include an embedded JAR file in a bundle. It
+demonstrates how to include a native library in a bundle; currently the
+example only supports Linux on a PC, but other platforms will work
+similarly. Lastly, it demonstrates dynamic imports.<br>
+</p>
+<p><b>Contributor(s)</b><br>
+Richard S. Hall (<a href="mailto:heavy@ungoverned.org">heavy@ungovenred.org</a>)<br>
+</p>
+<p><b>License</b><br>
+BSD<br>
+</p>
+<p><b>Services</b><br>
+None </p>
+<p> <b>Properties</b><br>
+None </p>
+<p><b>Requirements<br>
+</b>None</p>
+</font>
+</body>
+</html>
diff --git a/simple/lib/org.osgi.core-0.8.0-SNAPSHOT.jar b/simple/lib/org.osgi.core-0.8.0-SNAPSHOT.jar
new file mode 100644
index 0000000..150cf9e
--- /dev/null
+++ b/simple/lib/org.osgi.core-0.8.0-SNAPSHOT.jar
Binary files differ
diff --git a/simple/lib/servlet-incomplete.jar b/simple/lib/servlet-incomplete.jar
new file mode 100644
index 0000000..9bfd8c9
--- /dev/null
+++ b/simple/lib/servlet-incomplete.jar
Binary files differ
diff --git a/simple/native/build.txt b/simple/native/build.txt
new file mode 100644
index 0000000..b79f659
--- /dev/null
+++ b/simple/native/build.txt
@@ -0,0 +1,6 @@
+cd ..; ant ; cd native
+javah -classpath ../simple.jar -jni org.apache.felix.simple.Activator
+gcc -I/usr/java/jdk/include \
+ -I/usr/java/jdk/include/linux \
+ -c simple_bundle_foo_method.c -o simple_bundle_foo_method.o
+ld -G simple_bundle_foo_method.o -o libfoo.so
diff --git a/simple/native/libfoo.so b/simple/native/libfoo.so
new file mode 100644
index 0000000..663cc19
--- /dev/null
+++ b/simple/native/libfoo.so
Binary files differ
diff --git a/simple/native/org_apache_felix_simple_Activator.h b/simple/native/org_apache_felix_simple_Activator.h
new file mode 100644
index 0000000..06fd02d
--- /dev/null
+++ b/simple/native/org_apache_felix_simple_Activator.h
@@ -0,0 +1,21 @@
+/* DO NOT EDIT THIS FILE - it is machine generated */
+#include <jni.h>
+/* Header for class org_apache_felix_simple_Activator */
+
+#ifndef _Included_org_apache_felix_simple_Activator
+#define _Included_org_apache_felix_simple_Activator
+#ifdef __cplusplus
+extern "C" {
+#endif
+/*
+ * Class: org_apache_felix_simple_Activator
+ * Method: foo
+ * Signature: ()Ljava/lang/String;
+ */
+JNIEXPORT jstring JNICALL Java_org_apache_felix_simple_Activator_foo
+ (JNIEnv *, jobject);
+
+#ifdef __cplusplus
+}
+#endif
+#endif
diff --git a/simple/native/simple_bundle_foo_method.c b/simple/native/simple_bundle_foo_method.c
new file mode 100644
index 0000000..a684abe
--- /dev/null
+++ b/simple/native/simple_bundle_foo_method.c
@@ -0,0 +1,10 @@
+#include "org_apache_felix_simple_Activator.h"
+
+JNIEXPORT jstring JNICALL
+ Java_org_apache_felix_simple_Activator_foo
+ (JNIEnv *env, jobject obj)
+{
+ char *cstr = "Hello!";
+ jstring jstr = (*env)->NewStringUTF(env, cstr);
+ return jstr;
+}
diff --git a/simple/src/org/apache/felix/simple/Activator.java b/simple/src/org/apache/felix/simple/Activator.java
new file mode 100644
index 0000000..d344cd2
--- /dev/null
+++ b/simple/src/org/apache/felix/simple/Activator.java
@@ -0,0 +1,68 @@
+package org.apache.felix.simple;
+
+import javax.servlet.Servlet;
+
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+import org.apache.felix.simple.embedded.Embedded;
+
+/**
+ * A very simple bundle that prints out a message when it is started and
+ * stopped; it includes an embedded JAR file which is used on its internal
+ * class path. This bundle is merely a "hello world" example; it does not
+ * implement any services nor does it offer any configurable properties.
+**/
+public class Activator implements BundleActivator
+{
+ private BundleContext context = null;
+
+ public native String foo();
+
+ public void start(BundleContext context) throws Exception
+ {
+ System.out.println("Simple bundle " + context.getBundle().getBundleId()
+ + " has started.");
+
+ this.context = context;
+
+ // Get the OS and processor properties.
+ String os =
+ context.getProperty("org.osgi.framework.os.name").toLowerCase();
+ String processor =
+ context.getProperty("org.osgi.framework.processor").toLowerCase();
+
+ // Load library if correct platform.
+ if (os.equals("linux") && processor.endsWith("86"))
+ {
+ try {
+ System.loadLibrary("foo");
+ } catch (Exception ex) {
+ System.out.println("No library: " + ex);
+ ex.printStackTrace();
+ }
+ System.out.println("From native: " + foo());
+ }
+
+ // Create class from embedded JAR file.
+ Embedded embedded = new Embedded();
+ embedded.sayHello();
+
+ // Access dynamically imported servlet class.
+ try {
+ System.out.println("Class name = " + javax.servlet.http.HttpSession.class);
+ } catch (Throwable ex) {
+ System.out.println("The 'javax.servlet.http' package is not available.");
+ }
+ try {
+ System.out.println("Class name = " + Servlet.class);
+ } catch (Throwable ex) {
+ System.out.println("The 'javax.servlet' package is not available.");
+ }
+ }
+
+ public void stop(BundleContext context)
+ {
+ System.out.println("Simple bundle " + context.getBundle().getBundleId()
+ + " has stopped.");
+ }
+}
diff --git a/simple/src/org/apache/felix/simple/embedded/Embedded.java b/simple/src/org/apache/felix/simple/embedded/Embedded.java
new file mode 100644
index 0000000..69b8de7
--- /dev/null
+++ b/simple/src/org/apache/felix/simple/embedded/Embedded.java
@@ -0,0 +1,9 @@
+package org.apache.felix.simple.embedded;
+
+public class Embedded
+{
+ public void sayHello()
+ {
+ System.out.println("From embedded JAR: Hello!");
+ }
+}
diff --git a/simple/src/org/apache/felix/simple/manifest.mf b/simple/src/org/apache/felix/simple/manifest.mf
new file mode 100644
index 0000000..fdec8f9
--- /dev/null
+++ b/simple/src/org/apache/felix/simple/manifest.mf
@@ -0,0 +1,10 @@
+Bundle-ManifestVersion: 2
+Bundle-SymbolicName: org.apache.felix.simple
+Bundle-Version: 1.0.0
+Bundle-Name: Simple Bundle
+Bundle-Description: Simple bundle that demonstates OSGi features.
+Bundle-Activator: org.apache.felix.simple.Activator
+Bundle-ClassPath: .,org/apache/felix/simple/embedded.jar
+Bundle-NativeCode: /libfoo.so; osname=Linux; processor=x86
+Import-Package: org.osgi.framework
+DynamicImport-Package: javax.servlet.*