felix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From clem...@apache.org
Subject svn commit: r767196 - in /felix/sandbox/clement/ipojo-utils/org.apache.felix.ipojo.online.manipulator: ./ src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/felix/ src/main/java/org/apache/felix/org/ src...
Date Tue, 21 Apr 2009 15:59:11 GMT
Author: clement
Date: Tue Apr 21 15:59:10 2009
New Revision: 767196

URL: http://svn.apache.org/viewvc?rev=767196&view=rev
Log:
Initial commit of the online manipulator:
To manipulate a bundle at install-tome, just use an url beginning by ipojo://
For example install ipojo://file:/Users/clement/mybundle.jar

The specified bundle is not already manipulated, it will be during the installation phase.


The manipulator will look for metadata inside the bundle (metadata.xml file in the root of
in META-INF), or you can specify the metadata file:
ipojo://file:/.../bundle.jar!file:/.../metadata.xml

Of course,  annotations, XML-Schema are supported ...

Added:
    felix/sandbox/clement/ipojo-utils/org.apache.felix.ipojo.online.manipulator/
    felix/sandbox/clement/ipojo-utils/org.apache.felix.ipojo.online.manipulator/metadata.xml
  (with props)
    felix/sandbox/clement/ipojo-utils/org.apache.felix.ipojo.online.manipulator/pom.xml  
(with props)
    felix/sandbox/clement/ipojo-utils/org.apache.felix.ipojo.online.manipulator/src/
    felix/sandbox/clement/ipojo-utils/org.apache.felix.ipojo.online.manipulator/src/main/
    felix/sandbox/clement/ipojo-utils/org.apache.felix.ipojo.online.manipulator/src/main/java/
    felix/sandbox/clement/ipojo-utils/org.apache.felix.ipojo.online.manipulator/src/main/java/org/
    felix/sandbox/clement/ipojo-utils/org.apache.felix.ipojo.online.manipulator/src/main/java/org/apache/
    felix/sandbox/clement/ipojo-utils/org.apache.felix.ipojo.online.manipulator/src/main/java/org/apache/felix/
    felix/sandbox/clement/ipojo-utils/org.apache.felix.ipojo.online.manipulator/src/main/java/org/apache/felix/org/
    felix/sandbox/clement/ipojo-utils/org.apache.felix.ipojo.online.manipulator/src/main/java/org/apache/felix/org/apache/
    felix/sandbox/clement/ipojo-utils/org.apache.felix.ipojo.online.manipulator/src/main/java/org/apache/felix/org/apache/felix/
    felix/sandbox/clement/ipojo-utils/org.apache.felix.ipojo.online.manipulator/src/main/java/org/apache/felix/org/apache/felix/ipojo/
    felix/sandbox/clement/ipojo-utils/org.apache.felix.ipojo.online.manipulator/src/main/java/org/apache/felix/org/apache/felix/ipojo/online/
    felix/sandbox/clement/ipojo-utils/org.apache.felix.ipojo.online.manipulator/src/main/java/org/apache/felix/org/apache/felix/ipojo/online/manipulator/
    felix/sandbox/clement/ipojo-utils/org.apache.felix.ipojo.online.manipulator/src/main/java/org/apache/felix/org/apache/felix/ipojo/online/manipulator/IPOJOURLHandler.java
  (with props)
    felix/sandbox/clement/ipojo-utils/org.apache.felix.ipojo.online.manipulator/src/main/resources/

Added: felix/sandbox/clement/ipojo-utils/org.apache.felix.ipojo.online.manipulator/metadata.xml
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/ipojo-utils/org.apache.felix.ipojo.online.manipulator/metadata.xml?rev=767196&view=auto
==============================================================================
--- felix/sandbox/clement/ipojo-utils/org.apache.felix.ipojo.online.manipulator/metadata.xml
(added)
+++ felix/sandbox/clement/ipojo-utils/org.apache.felix.ipojo.online.manipulator/metadata.xml
Tue Apr 21 15:59:10 2009
@@ -0,0 +1,11 @@
+<ipojo>
+<component classname="org.apache.felix.org.apache.felix.ipojo.online.manipulator.IPOJOURLHandler"

+	public="false"
+	immediate="true">
+	<provides>
+		<property name="url.handler.protocol" type="java.lang.String" value="ipojo"/>
+	</provides>
+	<callback transition="invalidate" method="stop"/>
+</component>
+<instance component="org.apache.felix.org.apache.felix.ipojo.online.manipulator.IPOJOURLHandler"/>
+</ipojo>
\ No newline at end of file

Propchange: felix/sandbox/clement/ipojo-utils/org.apache.felix.ipojo.online.manipulator/metadata.xml
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: felix/sandbox/clement/ipojo-utils/org.apache.felix.ipojo.online.manipulator/pom.xml
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/ipojo-utils/org.apache.felix.ipojo.online.manipulator/pom.xml?rev=767196&view=auto
==============================================================================
--- felix/sandbox/clement/ipojo-utils/org.apache.felix.ipojo.online.manipulator/pom.xml (added)
+++ felix/sandbox/clement/ipojo-utils/org.apache.felix.ipojo.online.manipulator/pom.xml Tue
Apr 21 15:59:10 2009
@@ -0,0 +1,82 @@
+<project>
+  <modelVersion>4.0.0</modelVersion>
+  <packaging>bundle</packaging>
+  <groupId>org.apache.felix</groupId>
+  <artifactId>org.apache.felix.ipojo.online.manipulator</artifactId>
+  <version>1.3.0-SNAPSHOT</version>
+  <name>Apache Felix iPOJO URL Handler</name>
+  
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.felix</groupId>
+        <artifactId>maven-bundle-plugin</artifactId>
+        <version>1.4.3</version>
+        <extensions>true</extensions>
+        <configuration>
+          <instructions>
+            <Bundle-SymbolicName>${pom.artifactId}</Bundle-SymbolicName>
+            <Private-Package>org.apache.felix.org.apache.felix.ipojo.online.manipulator</Private-Package>
+            <Export-Package>
+            				org.apache.felix.ipojo.manipulator,
+            				org.apache.felix.ipojo.xml.parser,
+            				org.apache.felix.ipojo.manipulation,
+							org.apache.felix.ipojo.manipulation.annotations,
+							org.objectweb.asm.commons, org.objectweb.asm
+			</Export-Package>
+			<Import-Package>
+			!org.objectweb.asm.tree, !sun.io,
+							*
+						</Import-Package>
+						<Embed-Dependency>xercesImpl|xml-resolver</Embed-Dependency>
+          </instructions>
+        </configuration>
+      </plugin>
+      <plugin>
+	      <groupId>org.apache.felix</groupId>
+	      <artifactId>maven-ipojo-plugin</artifactId>
+	       <version>1.3.0-SNAPSHOT</version>
+		  <executions>
+          	<execution>
+            	<goals>
+	              <goal>ipojo-bundle</goal>
+               </goals>
+          </execution>
+        </executions>
+      </plugin>
+    </plugins>
+  </build>
+  <dependencies>
+  			<dependency>
+			<groupId>org.apache.felix</groupId>
+			<artifactId>org.apache.felix.ipojo.manipulator</artifactId>
+			<version>1.3.0-SNAPSHOT</version>
+		</dependency>
+		<dependency>
+			<groupId>asm</groupId>
+			<artifactId>asm-all</artifactId>
+			<version>3.0</version>
+			<exclusions>
+				<exclusion>
+					<groupId>asm</groupId>
+					<artifactId>asm-tree</artifactId>
+				</exclusion>
+			</exclusions>
+		</dependency>
+  	<dependency>
+  		<groupId>org.apache.felix</groupId>
+  		<artifactId>org.osgi.core</artifactId>
+  		<version>1.2.0</version>
+  	</dependency>
+  	<dependency>
+  		<groupId>xerces</groupId>
+  		<artifactId>xercesImpl</artifactId>
+  		<version>2.9.1</version>
+  	</dependency>
+  	<dependency>
+  		<groupId>xml-resolver</groupId>
+  		<artifactId>xml-resolver</artifactId>
+  		<version>1.2</version>
+  	</dependency>
+  </dependencies>
+</project>

Propchange: felix/sandbox/clement/ipojo-utils/org.apache.felix.ipojo.online.manipulator/pom.xml
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: felix/sandbox/clement/ipojo-utils/org.apache.felix.ipojo.online.manipulator/src/main/java/org/apache/felix/org/apache/felix/ipojo/online/manipulator/IPOJOURLHandler.java
URL: http://svn.apache.org/viewvc/felix/sandbox/clement/ipojo-utils/org.apache.felix.ipojo.online.manipulator/src/main/java/org/apache/felix/org/apache/felix/ipojo/online/manipulator/IPOJOURLHandler.java?rev=767196&view=auto
==============================================================================
--- felix/sandbox/clement/ipojo-utils/org.apache.felix.ipojo.online.manipulator/src/main/java/org/apache/felix/org/apache/felix/ipojo/online/manipulator/IPOJOURLHandler.java
(added)
+++ felix/sandbox/clement/ipojo-utils/org.apache.felix.ipojo.online.manipulator/src/main/java/org/apache/felix/org/apache/felix/ipojo/online/manipulator/IPOJOURLHandler.java
Tue Apr 21 15:59:10 2009
@@ -0,0 +1,155 @@
+package org.apache.felix.org.apache.felix.ipojo.online.manipulator;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.net.URLConnection;
+import java.util.jar.JarEntry;
+import java.util.jar.JarFile;
+
+import org.apache.felix.ipojo.manipulator.Pojoization;
+import org.osgi.framework.BundleContext;
+import org.osgi.service.url.URLStreamHandlerService;
+
+public class IPOJOURLHandler extends org.osgi.service.url.AbstractURLStreamHandlerService
implements URLStreamHandlerService {
+    
+    private BundleContext m_context;
+    private File m_temp;
+    
+    public IPOJOURLHandler(BundleContext bc) {
+        m_context = bc;
+        m_temp = m_context.getDataFile("temp");
+        if (! m_temp.exists()) {
+            m_temp.mkdir();
+        }
+    }
+    
+    public void stop() {
+        File[] files = m_temp.listFiles();
+        for (int i = 0; i < files.length; i++) {
+            files[i].delete();
+        }
+        m_temp.delete();
+    }
+
+    public URLConnection openConnection(URL url) throws IOException {
+        System.out.println("Processing URL : " + url);
+
+       // Parse the url:
+        String full = url.toExternalForm();
+        // Remote ipojo://
+        if (full.startsWith("ipojo:")) {
+            full = full.substring(6);
+        }
+        // Remove '/' or '//'
+        while (full.startsWith("/")) {
+            full = full.substring(1);
+        }
+        
+        full = full.trim();
+        
+        // Now full is like : URL,URL or URL
+        String urls[] = full.split("!");
+        URL bundleURL = null;
+        URL metadataURL = null;
+        if (urls.length == 1) {
+            // URL form
+            System.out.println("Extracted URL : " + urls[0]);
+            bundleURL = new URL(urls[0]);
+        } else if (urls.length == 2){
+            // URL,URL form
+            bundleURL = new URL(urls[0]);
+            metadataURL = new URL(urls[1]);
+        } else {
+            throw new MalformedURLException("The iPOJO url is not formatted correctly, ipojo://bundle_url[!metadata_url]
expected");
+        }
+        
+        File bundle = File.createTempFile("ipojo_", ".jar", m_temp);
+        save(bundleURL, bundle);
+        File metadata = null;
+        if (metadataURL != null) {
+            metadata = File.createTempFile("ipojo_", ".xml", m_temp);
+            save(metadataURL, metadata);   
+        } else {
+            // Check that the metadata are in the jar file
+            JarFile jar = new JarFile(bundle);
+            metadata = findMetadata(jar); 
+        }
+        
+        // Pojoization
+        Pojoization pojoizator = new Pojoization();
+        File out =  new File(m_temp, bundle.getName()+"-ipojo.jar");
+        System.out.println("Pojoization " + bundle.exists() + " - " + metadata.exists());
+        try {
+            pojoizator.pojoization(bundle, out, metadata);
+        } catch (Exception e) {
+            if (! pojoizator.getErrors().isEmpty()) {
+                throw new IOException("Errors occured during the manipulation : " + pojoizator.getErrors());
+            }
+            e.printStackTrace();
+            throw new RuntimeException(e.getMessage());
+        }
+        
+        if (! pojoizator.getErrors().isEmpty()) {
+            throw new IOException("Errors occured during the manipulation : " + pojoizator.getErrors());
+        }
+        if (! pojoizator.getWarnings().isEmpty()) {
+           System.err.println("Warnings occured during the manipulation : " + pojoizator.getWarnings());
+        }
+
+        System.out.println("Manipulation done : " + out.exists());
+        
+        // Cleanup
+        bundle.delete();
+        if (metadata != null) {
+            metadata.delete();
+        }
+        out.deleteOnExit();
+        // Returns the URL Connection
+        return out.toURL().openConnection();
+        
+        
+    }
+
+    private void save(URL url, File file) throws IOException {
+        InputStream is = url.openStream();
+        save(is, file);
+    }
+    
+    private void save(InputStream is, File file) throws IOException {
+        FileOutputStream writer = new FileOutputStream(file);
+        int cc = 0;
+        do {
+            int i = is.read();
+            if (i == -1)
+                break;
+            cc++;
+            writer.write(i);
+        } while (true);
+        System.out.println(cc + " bytes copied");
+        is.close();
+        writer.close();        
+    }
+    
+    private File findMetadata(JarFile jar) throws IOException {
+        JarEntry je = jar.getJarEntry("metadata.xml");
+        if (je == null) {
+            je = jar.getJarEntry("META-INF/metadata.xml");
+        }
+        
+        if (je == null) {
+            return null; // Not Found, use annotation only
+        } else {
+            System.out.println("Metadata file found: " + je.getName());
+            File metadata = File.createTempFile("ipojo_", ".xml", m_temp);
+            save(jar.getInputStream(je), metadata);
+            System.out.println("Metadata file saved to " + metadata.getAbsolutePath());
+            return metadata;
+        }
+        
+    }
+    
+}

Propchange: felix/sandbox/clement/ipojo-utils/org.apache.felix.ipojo.online.manipulator/src/main/java/org/apache/felix/org/apache/felix/ipojo/online/manipulator/IPOJOURLHandler.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message