[jboss-cvs] JBossAS SVN: r95932 - in projects/demos/microcontainer/trunk: classloader and 8 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Nov 2 17:48:05 EST 2009


Author: alesj
Date: 2009-11-02 17:48:04 -0500 (Mon, 02 Nov 2009)
New Revision: 95932

Added:
   projects/demos/microcontainer/trunk/classloader/
   projects/demos/microcontainer/trunk/classloader/pom.xml
   projects/demos/microcontainer/trunk/classloader/src/
   projects/demos/microcontainer/trunk/classloader/src/main/
   projects/demos/microcontainer/trunk/classloader/src/main/java/
   projects/demos/microcontainer/trunk/classloader/src/main/java/org/
   projects/demos/microcontainer/trunk/classloader/src/main/java/org/jboss/
   projects/demos/microcontainer/trunk/classloader/src/main/java/org/jboss/demos/
   projects/demos/microcontainer/trunk/classloader/src/main/java/org/jboss/demos/classloader/
   projects/demos/microcontainer/trunk/classloader/src/main/java/org/jboss/demos/classloader/crypt/
   projects/demos/microcontainer/trunk/classloader/src/main/java/org/jboss/demos/classloader/crypt/CryptVisitor.java
   projects/demos/microcontainer/trunk/classloader/src/main/java/org/jboss/demos/classloader/crypt/Crypter.java
   projects/demos/microcontainer/trunk/classloader/src/main/java/org/jboss/demos/classloader/crypt/Tools.java
Modified:
   projects/demos/microcontainer/trunk/pom.xml
Log:
Add initial ClassLoader demo.

Added: projects/demos/microcontainer/trunk/classloader/pom.xml
===================================================================
--- projects/demos/microcontainer/trunk/classloader/pom.xml	                        (rev 0)
+++ projects/demos/microcontainer/trunk/classloader/pom.xml	2009-11-02 22:48:04 UTC (rev 95932)
@@ -0,0 +1,69 @@
+<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">
+  <parent>
+    <groupId>org.jboss.demos</groupId>
+    <artifactId>jboss-demos</artifactId>
+    <version>2.0.0-SNAPSHOT</version>
+  </parent>
+  <modelVersion>4.0.0</modelVersion>
+  <groupId>org.jboss.demos</groupId>
+  <artifactId>jboss-demos-classloader</artifactId>
+  <packaging>jar</packaging>
+  <name>JBoss MC Demos Classloader</name>
+  <url>http://www.jboss.org/jbossmc</url>
+  <description>JBoss MC Demos</description>
+
+  <dependencies>
+    <dependency>
+      <groupId>org.jboss.demos</groupId>
+      <artifactId>jboss-demos-bootstrap</artifactId>
+    </dependency>
+    <!-- Compile (global dependencies) -->
+    <dependency>
+      <groupId>org.jboss.deployers</groupId>
+      <artifactId>jboss-deployers-vfs</artifactId>
+      <exclusions>
+        <exclusion>
+          <groupId>jboss</groupId>
+          <artifactId>jboss-vfs</artifactId>
+        </exclusion>
+      </exclusions>
+    </dependency>
+    <dependency>
+      <groupId>apache-xerces</groupId>
+      <artifactId>xml-apis</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.jboss</groupId>
+      <artifactId>jboss-vfs</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.jboss</groupId>
+      <artifactId>jboss-common-core</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.jboss.logging</groupId>
+      <artifactId>jboss-logging-spi</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.jboss.microcontainer</groupId>
+      <artifactId>jboss-dependency</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.jboss.deployers</groupId>
+      <artifactId>jboss-deployers-spi</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.jboss.deployers</groupId>
+      <artifactId>jboss-deployers-structure-spi</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.jboss.microcontainer</groupId>
+      <artifactId>jboss-kernel</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.jboss.deployers</groupId>
+      <artifactId>jboss-deployers-core-spi</artifactId>
+    </dependency>
+  </dependencies>
+
+</project>
\ No newline at end of file

Added: projects/demos/microcontainer/trunk/classloader/src/main/java/org/jboss/demos/classloader/crypt/CryptVisitor.java
===================================================================
--- projects/demos/microcontainer/trunk/classloader/src/main/java/org/jboss/demos/classloader/crypt/CryptVisitor.java	                        (rev 0)
+++ projects/demos/microcontainer/trunk/classloader/src/main/java/org/jboss/demos/classloader/crypt/CryptVisitor.java	2009-11-02 22:48:04 UTC (rev 95932)
@@ -0,0 +1,102 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.demos.classloader.crypt;
+
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.util.jar.JarEntry;
+import java.util.jar.JarOutputStream;
+import java.util.jar.Manifest;
+
+import org.jboss.virtual.VFSUtils;
+import org.jboss.virtual.VirtualFile;
+import org.jboss.virtual.VirtualFileVisitor;
+import org.jboss.virtual.VisitorAttributes;
+
+/**
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class CryptVisitor implements VirtualFileVisitor
+{
+   private VirtualFile root;
+   private Crypter crypter;
+   private File file;
+   private JarOutputStream jos;
+
+   public CryptVisitor(VirtualFile root, Crypter crypter) throws Exception
+   {
+      this.root = root;
+      this.crypter = crypter;
+   }
+
+   public File getFile() throws Exception
+   {
+      file = File.createTempFile("crypt-", ".jar");
+      FileOutputStream fos = new FileOutputStream(file);
+      Manifest manifest = VFSUtils.getManifest(root);
+      if (manifest != null)
+         jos = new JarOutputStream(fos, manifest);
+      else
+         jos = new JarOutputStream(fos);
+
+      root.visit(this);
+
+      try
+      {
+         jos.flush();
+      }
+      finally
+      {
+         jos.close();
+      }
+      return file;
+   }
+
+   public VisitorAttributes getAttributes()
+   {
+      return VisitorAttributes.RECURSE_LEAVES_ONLY;
+   }
+
+   public void visit(VirtualFile vf)
+   {
+      try
+      {
+         String path = vf.getPathName();
+         JarEntry entry = new JarEntry(path);
+         jos.putNextEntry(entry);
+         jos.write(encrypt(vf));
+      }
+      catch (Exception e)
+      {
+         throw new IllegalArgumentException(e);
+      }
+   }
+
+   protected byte[] encrypt(VirtualFile vf) throws Exception
+   {
+      ByteArrayOutputStream baos = new ByteArrayOutputStream();
+      VFSUtils.copyStreamAndClose(vf.openStream(), baos);
+      byte[] bytes = baos.toByteArray();
+      return crypter.encrypt(bytes);
+   }
+}

Added: projects/demos/microcontainer/trunk/classloader/src/main/java/org/jboss/demos/classloader/crypt/Crypter.java
===================================================================
--- projects/demos/microcontainer/trunk/classloader/src/main/java/org/jboss/demos/classloader/crypt/Crypter.java	                        (rev 0)
+++ projects/demos/microcontainer/trunk/classloader/src/main/java/org/jboss/demos/classloader/crypt/Crypter.java	2009-11-02 22:48:04 UTC (rev 95932)
@@ -0,0 +1,47 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.demos.classloader.crypt;
+
+import java.io.File;
+
+/**
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class Crypter
+{
+   private File keystore;
+
+   public Crypter(File keystore)
+   {
+      this.keystore = keystore;
+   }
+
+   public byte[] encrypt(byte[] bytes)
+   {
+      return bytes; // TODO - encrypt
+   }
+
+   public byte[] decrypt(byte[] bytes)
+   {
+      return bytes; // TODO - decrypt
+   }
+}

Added: projects/demos/microcontainer/trunk/classloader/src/main/java/org/jboss/demos/classloader/crypt/Tools.java
===================================================================
--- projects/demos/microcontainer/trunk/classloader/src/main/java/org/jboss/demos/classloader/crypt/Tools.java	                        (rev 0)
+++ projects/demos/microcontainer/trunk/classloader/src/main/java/org/jboss/demos/classloader/crypt/Tools.java	2009-11-02 22:48:04 UTC (rev 95932)
@@ -0,0 +1,79 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.demos.classloader.crypt;
+
+import java.io.File;
+import java.util.Arrays;
+
+import org.jboss.virtual.VFS;
+import org.jboss.virtual.VirtualFile;
+
+/**
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class Tools
+{
+   private File jarToCrypt;
+   private File keyStore;
+
+   public Tools(File jarToCrypt, File keyStore)
+   {
+      this.jarToCrypt = jarToCrypt;
+      this.keyStore = keyStore;
+   }
+
+   public static void main(String[] args)
+   {
+      if (args == null || args.length == 0)
+         throw new IllegalArgumentException("Invalid arguments: " + Arrays.toString(args));
+
+      File archive = new File(args[0]);
+      if (archive.exists() == false)
+         throw new IllegalArgumentException("Archive doesn't exist: " + archive);
+
+      File keystore = new File(args[1]);
+      if (keystore.exists() == false)
+         throw new IllegalArgumentException("Keystore doesn't exist: " + keystore);
+
+      Tools tools = new Tools(archive, keystore);
+      tools.crypt();
+   }
+
+   public void crypt()
+   {
+      try
+      {
+         VirtualFile root = VFS.getRoot(jarToCrypt.toURI());
+         Crypter crypter = new Crypter(keyStore);
+         CryptVisitor visitor = new CryptVisitor(root, crypter);
+         File file = visitor.getFile();
+         if (file.renameTo(jarToCrypt))
+         {
+            System.err.println("Cannot rename file: " + file);
+         }
+      }
+      catch (Exception e)
+      {
+         throw new RuntimeException(e);
+      }
+   }
+}
\ No newline at end of file

Modified: projects/demos/microcontainer/trunk/pom.xml
===================================================================
--- projects/demos/microcontainer/trunk/pom.xml	2009-11-02 21:07:14 UTC (rev 95931)
+++ projects/demos/microcontainer/trunk/pom.xml	2009-11-02 22:48:04 UTC (rev 95932)
@@ -25,6 +25,7 @@
     <module>jmx</module>
     <module>models</module>
     <module>ioc</module>
+    <module>classloader</module>
     <module>classloading</module>
     <module>classpath</module>
     <module>igloo</module>




More information about the jboss-cvs-commits mailing list