Package net.sourceforge.javautil.classloader.impl

Examples of net.sourceforge.javautil.classloader.impl.ClassContext


 
  /**
   * @return The class context for this unit, including any specified transformers
   */
  protected ClassContext createClassContext () {
    return new ClassContext(new StandardClassLoaderHeiarchy(), this.createClassSource())
      .setTransformer(new PersistenceClassTransformer(this.transformers.toArray(new ClassTransformer[this.transformers.size()])));
  }
View Full Code Here


 
  /**
   * @return A special internal classloader for loading the MXJ classes
   */
  protected static ClassLoader createMysqlMXJClassLoader (IVirtualFile mxjJar, IVirtualFile mxjDbFileJar) {
    return new ClassContext(new StandardClassLoaderHeiarchy(),
      new ZipClassSource(mxjJar.getURL()),
      new ZipClassSource(mxjDbFileJar.getURL())
    );
  }
View Full Code Here

  public void main (EntryPointConfiguration config) throws Throwable {
    URL boot = EntryPoint.class.getClassLoader()
      .getResource("META-INF/net/sf/javautil/boot.jar");
   
    ClassContext context = null;
    CompositeClassSource mainSource = new CompositeClassSource();
    ClassSource additional = this.getAdditionalClassSources();
    if (additional != null) mainSource.add(additional);
   
    if (boot != null) {
      mainSource.add( VirtualDirectoryClassSource.createInMemoryJar("boot", "main", boot.openStream()) );
      context = new ClassContext(new StandardClassLoaderHeiarchy(Thread.currentThread().getContextClassLoader()), mainSource);
    } else {
     
      String main = this.getSetting(MAIN_JAR_PROPERTY);
      if (main == null)
        printHelp("No internal uber jar and no main jar specified -D" + MAIN_JAR_PROPERTY + "=''");
     
      File mainFile = new File(main);
      if (!mainFile.exists())
        printHelp("Specified main jar does not exist: " + mainFile);
     
      mainSource.add( new ZipClassSource(mainFile) );
      context = new ClassContext(new StandardClassLoaderHeiarchy(Thread.currentThread().getContextClassLoader()), mainSource);
    }
   
    Thread.currentThread().setContextClassLoader(context);
    this.setupDefaultURLStreamHandlerFactory(context);
   
    String mainClassName = null;
   
    if (mainClassName == null) {
      Manifest manifest = mainSource.getManifest();
      if (manifest == null)
        printHelp("No main jar manifest found in " + mainSource);
     
      mainClassName = manifest.getMainAttributes().getValue("Main-Class");
    }
    Thread.currentThread().setContextClassLoader(context);
   
    if (config.getMainClass() != null)
      this.boot(ClassCache.getFor(context.loadClass(mainClassName)), this);
  }
View Full Code Here

  /**
   * Will detect pom.xml specified by {@link #getPackageDescriptor()}, and load {@link EntryPoint#getAdditionalClassSources()}.
   * It will also load all maven project directories specified by {@link #getProjectDirectory()}.
   */
  public void main(EntryPointConfiguration config) throws Throwable {
    ClassContext context = null;
    ClassSource cs = config.getPoint().getAdditionalClassSources();

    // Load project directories
    String mp = this.getProjectDirectory();
    if (mp == null) mp = "../";

    this.resolver = MavenRepositoryUtil.createStandardResolver();
   
    String[] mps = mp.split(";");
   
    for (String mpd : mps) {
      ((ClassPackageResolverImpl)this.resolver).addLocalRepository(new MavenRepositoryLocalProject( new SystemDirectory(mpd) ));
    }
   
    ((ClassPackageResolverImpl)this.resolver).addLocalRepository(new MavenRepositoryClassLoader());
   
    context = cs != null ?
      new ClassContext(new StandardClassLoaderHeiarchy(), cs) :
      new ClassContext(new StandardClassLoaderHeiarchy());
   
    Thread.currentThread().setContextClassLoader(context);
   
    // Check for a specified or default pom.xml file
    IVirtualFile pomFile = this.locatePOMDescriptor();
   
    if (pomFile != null && pomFile.isExists()) {
     
      ProjectObjectModel pom = ProjectObjectModel.parse(resolver, pomFile);
     
      ProjectObjectModel resolved = (ProjectObjectModel) resolver.getDescriptor(pom);
      if (resolved != null) {
        pom = resolved;
      } else {
        log.info("Unresolvable pom.xml used for bootstrapping: " + pom);
      }
     
      MavenRepositoryUtil.addProjectMainTarget(context.getNonPackageSources(), pom, pomFile.getOwner());
     
      context.setPool(pool = MavenRepositoryUtil.createFrom(resolver, pom, pom.getDependencies()));
     
      Thread.currentThread().setContextClassLoader(context);
     
    } else {

      log.warn("Could not find: " + pomFile.getPath().toString("/"));

    }
   
    new ClassPackageContext(resolver, context.getPool()).setGlobal();
   
    config.getPoint().setupDefaultURLStreamHandlerFactory(context);
   
    if (log.isDebug()) {
      log.debug("Non Package Sources");
      for (ClassSource src : context.getNonPackageSources().getAllNonCompositeSources()) {
        log.debug(" --> " + src);
      }
     
      log.debug("Package Sources");
      for (IClassPackage pkg : context.getPool().getPackages(true)) {
        log.debug(" --> " + pkg.getDescriptor());
      }
     
      this.log.debug("BOOTING MAVEN: " + config.getMainClass() + ": " + System.currentTimeMillis());
    }
   
    config.registerExecuted(this);
   
    // Load the main class and invoke it
    this.settings.refresh();
    if (config.getMainClass() != null)
      config.getPoint().boot(ClassCache.getFor(context.loadClass(config.getMainClass())), this);
  }
View Full Code Here

  /**
   * This will create a linked context and set the internal class loader to use it instead. By default
   * this will also make sure that the current class loader is the parent of the created linked context.
   */
  protected void createLinkedContext (ClassLoader parent) {
    this.linkedContext = new ClassContext(new VirtualDeploymentLinkedClassLoaderHeiarchy(this, parent, this.classLoader));
    this.classLoader = this.linkedContext;
  }
View Full Code Here

TOP

Related Classes of net.sourceforge.javautil.classloader.impl.ClassContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.