[jboss-cvs] JBossAS SVN: r97239 - in projects/weld-int/trunk/deployer/src/main/java/org/jboss/weld/integration: util and 1 other directory.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue Dec 1 10:29:01 EST 2009
Author: alesj
Date: 2009-12-01 10:29:01 -0500 (Tue, 01 Dec 2009)
New Revision: 97239
Added:
projects/weld-int/trunk/deployer/src/main/java/org/jboss/weld/integration/util/
projects/weld-int/trunk/deployer/src/main/java/org/jboss/weld/integration/util/AbstractManifestFinder.java
projects/weld-int/trunk/deployer/src/main/java/org/jboss/weld/integration/util/JDKManifestFinder.java
projects/weld-int/trunk/deployer/src/main/java/org/jboss/weld/integration/util/ManifestFinder.java
projects/weld-int/trunk/deployer/src/main/java/org/jboss/weld/integration/util/ManifestUtils.java
projects/weld-int/trunk/deployer/src/main/java/org/jboss/weld/integration/util/VFSManifestFinder.java
Log:
Find manifest from class.
Added: projects/weld-int/trunk/deployer/src/main/java/org/jboss/weld/integration/util/AbstractManifestFinder.java
===================================================================
--- projects/weld-int/trunk/deployer/src/main/java/org/jboss/weld/integration/util/AbstractManifestFinder.java (rev 0)
+++ projects/weld-int/trunk/deployer/src/main/java/org/jboss/weld/integration/util/AbstractManifestFinder.java 2009-12-01 15:29:01 UTC (rev 97239)
@@ -0,0 +1,52 @@
+/*
+ * 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.weld.integration.util;
+
+import java.net.URL;
+import java.util.jar.Manifest;
+import java.security.ProtectionDomain;
+import java.security.CodeSource;
+
+/**
+ * Find manifest info from class - abstract from code source.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+abstract class AbstractManifestFinder implements ManifestFinder
+{
+ public Manifest findManifest(Class<?> clazz) throws Exception
+ {
+ ProtectionDomain domain = clazz.getProtectionDomain();
+ CodeSource source = domain.getCodeSource();
+ URL location = source.getLocation();
+ return findManifest(location);
+ }
+
+ /**
+ * Find manifest from base url.
+ *
+ * @param url the url
+ * @return manifest or null
+ * @throws Exception for any error
+ */
+ protected abstract Manifest findManifest(URL url) throws Exception;
+}
\ No newline at end of file
Added: projects/weld-int/trunk/deployer/src/main/java/org/jboss/weld/integration/util/JDKManifestFinder.java
===================================================================
--- projects/weld-int/trunk/deployer/src/main/java/org/jboss/weld/integration/util/JDKManifestFinder.java (rev 0)
+++ projects/weld-int/trunk/deployer/src/main/java/org/jboss/weld/integration/util/JDKManifestFinder.java 2009-12-01 15:29:01 UTC (rev 97239)
@@ -0,0 +1,82 @@
+/*
+ * 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.weld.integration.util;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.JarURLConnection;
+import java.net.URL;
+import java.net.URLConnection;
+import java.util.jar.JarFile;
+import java.util.jar.Manifest;
+
+/**
+ * Find manifest info from class - plain JDK.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+class JDKManifestFinder extends AbstractManifestFinder
+{
+ protected Manifest findManifest(URL url) throws Exception
+ {
+ URLConnection conn = url.openConnection();
+ if (conn instanceof JarURLConnection)
+ {
+ JarURLConnection jarConn = (JarURLConnection)conn;
+ return jarConn.getManifest();
+ }
+ else
+ {
+ File parent = new File(url.toURI());
+ File child = new File(parent, JarFile.MANIFEST_NAME);
+ if (child.exists())
+ {
+ InputStream fis = new FileInputStream(child);
+ try
+ {
+ return new Manifest(fis);
+ }
+ finally
+ {
+ close(fis);
+ }
+ }
+ else
+ {
+ return null;
+ }
+ }
+ }
+
+ private static void close(InputStream is)
+ {
+ try
+ {
+ is.close();
+ }
+ catch (IOException ignored)
+ {
+ }
+ }
+}
\ No newline at end of file
Added: projects/weld-int/trunk/deployer/src/main/java/org/jboss/weld/integration/util/ManifestFinder.java
===================================================================
--- projects/weld-int/trunk/deployer/src/main/java/org/jboss/weld/integration/util/ManifestFinder.java (rev 0)
+++ projects/weld-int/trunk/deployer/src/main/java/org/jboss/weld/integration/util/ManifestFinder.java 2009-12-01 15:29:01 UTC (rev 97239)
@@ -0,0 +1,41 @@
+/*
+ * 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.weld.integration.util;
+
+import java.util.jar.Manifest;
+
+/**
+ * Find manifest info from class.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+interface ManifestFinder
+{
+ /**
+ * Find manifest.
+ *
+ * @param clazz the class
+ * @return manifest if found, else null
+ * @throws Exception for any error
+ */
+ Manifest findManifest(Class<?> clazz) throws Exception;
+}
\ No newline at end of file
Added: projects/weld-int/trunk/deployer/src/main/java/org/jboss/weld/integration/util/ManifestUtils.java
===================================================================
--- projects/weld-int/trunk/deployer/src/main/java/org/jboss/weld/integration/util/ManifestUtils.java (rev 0)
+++ projects/weld-int/trunk/deployer/src/main/java/org/jboss/weld/integration/util/ManifestUtils.java 2009-12-01 15:29:01 UTC (rev 97239)
@@ -0,0 +1,72 @@
+/*
+ * 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.weld.integration.util;
+
+import java.security.AccessController;
+import java.security.PrivilegedExceptionAction;
+import java.util.jar.Manifest;
+
+/**
+ * Get manifest info from class.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class ManifestUtils
+{
+ /** The manifest finder abstraction */
+ private static ManifestFinder finder;
+
+ static
+ {
+ try
+ {
+ Class<?> vfsFinderClass = Class.forName("org.jboss.weld.integration.util.VFSManifestFinder");
+ finder = (ManifestFinder)vfsFinderClass.newInstance();
+ }
+ catch (Exception e)
+ {
+ finder = new JDKManifestFinder();
+ }
+ }
+
+ /**
+ * Get manifest for class.
+ *
+ * @param clazz the class to check
+ * @return manifest if found, else null
+ * @throws Exception for any error
+ */
+ public static Manifest getManifest(final Class<?> clazz) throws Exception
+ {
+ SecurityManager sm = System.getSecurityManager();
+ if (sm != null)
+ return AccessController.doPrivileged(new PrivilegedExceptionAction<Manifest>()
+ {
+ public Manifest run() throws Exception
+ {
+ return finder.findManifest(clazz);
+ }
+ });
+ else
+ return finder.findManifest(clazz);
+ }
+}
Added: projects/weld-int/trunk/deployer/src/main/java/org/jboss/weld/integration/util/VFSManifestFinder.java
===================================================================
--- projects/weld-int/trunk/deployer/src/main/java/org/jboss/weld/integration/util/VFSManifestFinder.java (rev 0)
+++ projects/weld-int/trunk/deployer/src/main/java/org/jboss/weld/integration/util/VFSManifestFinder.java 2009-12-01 15:29:01 UTC (rev 97239)
@@ -0,0 +1,43 @@
+/*
+ * 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.weld.integration.util;
+
+import java.net.URL;
+import java.util.jar.Manifest;
+
+import org.jboss.virtual.VFS;
+import org.jboss.virtual.VirtualFile;
+import org.jboss.virtual.VFSUtils;
+
+/**
+ * Find manifest info from class - JBoss VFS.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+class VFSManifestFinder extends AbstractManifestFinder
+{
+ protected Manifest findManifest(URL url) throws Exception
+ {
+ VirtualFile root = VFS.getRoot(url);
+ return VFSUtils.getManifest(root);
+ }
+}
\ No newline at end of file
More information about the jboss-cvs-commits
mailing list