Github user mattf-horton commented on a diff in the pull request:

    https://github.com/apache/metron/pull/530#discussion_r132801955
  
    --- Diff: 
bundles-lib/src/main/java/org/apache/metron/bundles/VFSBundleClassLoader.java 
---
    @@ -0,0 +1,515 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements.  See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You under the Apache License, Version 2.0
    + * (the "License"); you may not use this file except in compliance with
    + * the License.  You may obtain a copy of the License at
    + *
    + *      http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +
    +package org.apache.metron.bundles;
    +
    +import java.io.IOException;
    +import java.net.URL;
    +import java.security.CodeSource;
    +import java.security.Permission;
    +import java.security.PermissionCollection;
    +import java.security.Permissions;
    +import java.security.SecureClassLoader;
    +import java.security.cert.Certificate;
    +import java.util.ArrayList;
    +import java.util.Collections;
    +import java.util.Enumeration;
    +import java.util.Iterator;
    +import java.util.List;
    +import java.util.jar.Attributes;
    +import java.util.jar.Attributes.Name;
    +import org.apache.commons.vfs2.FileObject;
    +import org.apache.commons.vfs2.FileSystemException;
    +import org.apache.commons.vfs2.FileSystemManager;
    +import org.apache.commons.vfs2.NameScope;
    +import org.slf4j.Logger;
    +import org.slf4j.LoggerFactory;
    +
    +
    +/**
    + * <p>
    + * A <tt>ClassLoader</tt> for loading BUNDLES (plugin archives). BUNDLEs 
are designed to
    + * allow isolating bundles of code (comprising one-or-more
    + * plugin classes and their
    + * dependencies) from other such bundles; this allows for dependencies and
    + * processors that require conflicting, incompatible versions of the same
    + * dependency to run in a single instance of a given process.</p>
    + *
    + * <p>
    + * <tt>BundleClassLoader</tt> follows the delegation model described in
    + * {@link ClassLoader#findClass(java.lang.String) 
ClassLoader.findClass(...)};
    + * classes are first loaded from the parent <tt>ClassLoader</tt>, and only 
if
    + * they cannot be found there does the <tt>BundleClassLoader</tt> provide a
    + * definition. Specifically, this means that resources are loaded from the 
application's
    + * <tt>conf</tt>
    + * and <tt>lib</tt> directories first, and if they cannot be found there, 
are
    + * loaded from the BUNDLE.</p>
    + *
    + * <p>
    + * The packaging of a BUNDLE is such that it is a ZIP file with the 
following
    + * directory structure:
    + *
    + * <pre>
    + *   +META-INF/
    + *   +-- bundled-dependencies/
    + *   +-- &lt;JAR files&gt;
    + *   +-- MANIFEST.MF
    + * </pre>
    + * </p>
    + *
    + * <p>
    + * The MANIFEST.MF file contains the same information as a typical JAR 
file but
    + * also includes two additional bundle properties: {@code Bundle-Id} and
    + * {@code Bundle-Dependency-Id}.
    + * </p>
    + *
    + * <p>
    + * The {@code Bundle-Id} provides a unique identifier for this BUNDLE.
    + * </p>
    + *
    + * <p>
    + * The {@code Bundle-Dependency-Id} is optional. If provided, it indicates 
that
    + * this BUNDLE should inherit all of the dependencies of the BUNDLE with 
the provided
    + * ID. Often times, the BUNDLE that is depended upon is referred to as the 
Parent.
    + * This is because its ClassLoader will be the parent ClassLoader of the
    + * dependent BUNDLE.
    + * </p>
    + *
    + * <p>
    + * If a BUNDLE is built using the Bundles Maven Plugin, the {@code 
Bundle-Id} property
    + * will be set to the artifactId of the BUNDLE. The {@code 
Bundle-Dependency-Id} will
    + * be set to the artifactId of the BUNDLE that is depended upon. For 
example, if
    + * BUNDLE A is defined as such:
    + *
    + * <pre>
    + * ...
    + * &lt;artifactId&gt;bundle-a&lt;/artifactId&gt;
    + * &lt;packaging&gt;bundle&lt;/packaging&gt;
    + * ...
    + * &lt;dependencies&gt;
    + *   &lt;dependency&gt;
    + *     &lt;groupId&gt;group&lt;/groupId&gt;
    + *     &lt;artifactId&gt;bundle-z&lt;/artifactId&gt;
    + *     <b>&lt;type&gt;bundle&lt;/type&gt;</b>
    + *   &lt;/dependency&gt;
    + * &lt;/dependencies&gt;
    + * </pre>
    + * </p>
    + *
    + *
    + * <p>
    + * Then the MANIFEST.MF file that is created for Bundle A will have the 
following
    + * properties set:
    + * <ul>
    + * <li>{@code {Foo}-Id: bundle-a}</li>
    + * <li>{@code {Foo}-Dependency-Id: bundle-z}</li>
    + * </ul>
    + * Where is configurable by BundleProperty META_ID_PREFIX [ default Bundle 
]
    + * </p>
    + *
    + * <p>
    + * Note, above, that the {@code type} of the dependency is set to {@code 
foo}.
    + * </p>
    + *
    + * <p>
    + * If the Bundle has more than one dependency of {@code type} {@code Foo}, 
then the
    + * Maven Bundle plugin will fail to build the Bundle.
    + * </p>
    + *
    + * This classloader is Metron Bundle aware, in that it understands that 
the passed in root
    + * FileObjects may be Bundles,
    + * This class is adapted from Apache Commons VFS
    + * VFSClassLoader class v.2.1
    + * And the Apache Nifi NarClassLoader v. 1.2
    + *
    + * @see FileSystemManager#createFileSystem
    + */
    +public class VFSBundleClassLoader extends SecureClassLoader {
    --- End diff --
    
    Nice job on the below.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to