You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by ri...@apache.org on 2006/10/17 20:16:09 UTC

svn commit: r464985 - in /incubator/felix/trunk/simple: ./ doc/ lib/ native/ src/ src/org/ src/org/apache/ src/org/apache/felix/ src/org/apache/felix/simple/ src/org/apache/felix/simple/embedded/

Author: rickhall
Date: Tue Oct 17 11:16:07 2006
New Revision: 464985

URL: http://svn.apache.org/viewvc?view=rev&rev=464985
Log:
Initial commit of "simple" example bundle.

Added:
    incubator/felix/trunk/simple/   (with props)
    incubator/felix/trunk/simple/build.xml   (with props)
    incubator/felix/trunk/simple/doc/
    incubator/felix/trunk/simple/doc/index.html   (with props)
    incubator/felix/trunk/simple/lib/
    incubator/felix/trunk/simple/lib/org.osgi.core-0.8.0-SNAPSHOT.jar   (with props)
    incubator/felix/trunk/simple/lib/servlet-incomplete.jar   (with props)
    incubator/felix/trunk/simple/native/
    incubator/felix/trunk/simple/native/build.txt   (with props)
    incubator/felix/trunk/simple/native/libfoo.so   (with props)
    incubator/felix/trunk/simple/native/org_apache_felix_simple_Activator.h   (with props)
    incubator/felix/trunk/simple/native/simple_bundle_foo_method.c   (with props)
    incubator/felix/trunk/simple/src/
    incubator/felix/trunk/simple/src/org/
    incubator/felix/trunk/simple/src/org/apache/
    incubator/felix/trunk/simple/src/org/apache/felix/
    incubator/felix/trunk/simple/src/org/apache/felix/simple/
    incubator/felix/trunk/simple/src/org/apache/felix/simple/Activator.java   (with props)
    incubator/felix/trunk/simple/src/org/apache/felix/simple/embedded/
    incubator/felix/trunk/simple/src/org/apache/felix/simple/embedded/Embedded.java   (with props)
    incubator/felix/trunk/simple/src/org/apache/felix/simple/manifest.mf   (with props)

Propchange: incubator/felix/trunk/simple/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Tue Oct 17 11:16:07 2006
@@ -0,0 +1,17 @@
+classes
+target
+*.log
+*.ipr
+*.iws
+*.iml
+lib
+bundle
+dist
+.project
+.classpath
+bin
+build
+.settings
+.wtpmodules
+.deployables
+

Added: incubator/felix/trunk/simple/build.xml
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/simple/build.xml?view=auto&rev=464985
==============================================================================
--- incubator/felix/trunk/simple/build.xml (added)
+++ incubator/felix/trunk/simple/build.xml Tue Oct 17 11:16:07 2006
@@ -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>

Propchange: incubator/felix/trunk/simple/build.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/felix/trunk/simple/doc/index.html
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/simple/doc/index.html?view=auto&rev=464985
==============================================================================
--- incubator/felix/trunk/simple/doc/index.html (added)
+++ incubator/felix/trunk/simple/doc/index.html Tue Oct 17 11:16:07 2006
@@ -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>

Propchange: incubator/felix/trunk/simple/doc/index.html
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/felix/trunk/simple/lib/org.osgi.core-0.8.0-SNAPSHOT.jar
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/simple/lib/org.osgi.core-0.8.0-SNAPSHOT.jar?view=auto&rev=464985
==============================================================================
Binary file - no diff available.

Propchange: incubator/felix/trunk/simple/lib/org.osgi.core-0.8.0-SNAPSHOT.jar
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: incubator/felix/trunk/simple/lib/servlet-incomplete.jar
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/simple/lib/servlet-incomplete.jar?view=auto&rev=464985
==============================================================================
Binary file - no diff available.

Propchange: incubator/felix/trunk/simple/lib/servlet-incomplete.jar
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: incubator/felix/trunk/simple/native/build.txt
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/simple/native/build.txt?view=auto&rev=464985
==============================================================================
--- incubator/felix/trunk/simple/native/build.txt (added)
+++ incubator/felix/trunk/simple/native/build.txt Tue Oct 17 11:16:07 2006
@@ -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

Propchange: incubator/felix/trunk/simple/native/build.txt
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/felix/trunk/simple/native/libfoo.so
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/simple/native/libfoo.so?view=auto&rev=464985
==============================================================================
Binary file - no diff available.

Propchange: incubator/felix/trunk/simple/native/libfoo.so
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: incubator/felix/trunk/simple/native/org_apache_felix_simple_Activator.h
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/simple/native/org_apache_felix_simple_Activator.h?view=auto&rev=464985
==============================================================================
--- incubator/felix/trunk/simple/native/org_apache_felix_simple_Activator.h (added)
+++ incubator/felix/trunk/simple/native/org_apache_felix_simple_Activator.h Tue Oct 17 11:16:07 2006
@@ -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

Propchange: incubator/felix/trunk/simple/native/org_apache_felix_simple_Activator.h
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/felix/trunk/simple/native/simple_bundle_foo_method.c
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/simple/native/simple_bundle_foo_method.c?view=auto&rev=464985
==============================================================================
--- incubator/felix/trunk/simple/native/simple_bundle_foo_method.c (added)
+++ incubator/felix/trunk/simple/native/simple_bundle_foo_method.c Tue Oct 17 11:16:07 2006
@@ -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;
+}

Propchange: incubator/felix/trunk/simple/native/simple_bundle_foo_method.c
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/felix/trunk/simple/src/org/apache/felix/simple/Activator.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/simple/src/org/apache/felix/simple/Activator.java?view=auto&rev=464985
==============================================================================
--- incubator/felix/trunk/simple/src/org/apache/felix/simple/Activator.java (added)
+++ incubator/felix/trunk/simple/src/org/apache/felix/simple/Activator.java Tue Oct 17 11:16:07 2006
@@ -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.");
+    }
+}

Propchange: incubator/felix/trunk/simple/src/org/apache/felix/simple/Activator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/felix/trunk/simple/src/org/apache/felix/simple/embedded/Embedded.java
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/simple/src/org/apache/felix/simple/embedded/Embedded.java?view=auto&rev=464985
==============================================================================
--- incubator/felix/trunk/simple/src/org/apache/felix/simple/embedded/Embedded.java (added)
+++ incubator/felix/trunk/simple/src/org/apache/felix/simple/embedded/Embedded.java Tue Oct 17 11:16:07 2006
@@ -0,0 +1,9 @@
+package org.apache.felix.simple.embedded;
+
+public class Embedded
+{
+    public void sayHello()
+    {
+        System.out.println("From embedded JAR: Hello!");
+    }
+}

Propchange: incubator/felix/trunk/simple/src/org/apache/felix/simple/embedded/Embedded.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/felix/trunk/simple/src/org/apache/felix/simple/manifest.mf
URL: http://svn.apache.org/viewvc/incubator/felix/trunk/simple/src/org/apache/felix/simple/manifest.mf?view=auto&rev=464985
==============================================================================
--- incubator/felix/trunk/simple/src/org/apache/felix/simple/manifest.mf (added)
+++ incubator/felix/trunk/simple/src/org/apache/felix/simple/manifest.mf Tue Oct 17 11:16:07 2006
@@ -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.*

Propchange: incubator/felix/trunk/simple/src/org/apache/felix/simple/manifest.mf
------------------------------------------------------------------------------
    svn:eol-style = native