示例#1
0
  // TODO: Do not swallow exception
  public void initializeResources() throws PlexusConfigurationException {
    PlexusConfiguration[] resourceConfigs = configuration.getChild("resources").getChildren();

    for (int i = 0; i < resourceConfigs.length; ++i) {
      try {
        String name = resourceConfigs[i].getName();

        if (name.equals("jar-repository")) {
          addJarRepository(new File(resourceConfigs[i].getValue()));
        } else if (name.equals("directory")) {
          File directory = new File(resourceConfigs[i].getValue());

          if (directory.exists() && directory.isDirectory()) {
            plexusRealm.addConstituent(directory.toURL());
          }
        } else {
          getLogger().warn("Unknown resource type: " + name);
        }
      } catch (MalformedURLException e) {
        getLogger()
            .error(
                "Error configuring resource: "
                    + resourceConfigs[i].getName()
                    + "="
                    + resourceConfigs[i].getValue(),
                e);
      }
    }
  }
  private ClassRealm cloneClassRealm(
      final File jrubyJar, final List<String> classpathElements, final ClassRealm classRealm)
      throws ScriptException {
    // TODO how to reuse the plugin realm ?
    //        for (final String classpath : classpathElements) {
    //            if (classpath.equals(jrubyJar.getAbsolutePath())) {
    //                return null;
    //            }
    //        }
    ClassRealm newClassRealm;
    try {
      ClassRealm jruby;
      try {
        jruby = classRealm.getWorld().getRealm("jruby");
      } catch (final NoSuchRealmException e) {
        jruby = classRealm.getWorld().newRealm("jruby");
        jruby.addConstituent(jrubyJar.toURI().toURL());
      }
      try {
        jruby.getWorld().disposeRealm("pom");
      } catch (final NoSuchRealmException e) {
        // ignored
      }
      newClassRealm = jruby.createChildRealm("pom");
      for (final String classpath : classpathElements) {
        if (!classpath.contains("jruby-complete")) {
          newClassRealm.addConstituent(new File(classpath).toURI().toURL());
        }
      }
    } catch (final DuplicateRealmException e) {
      throw new ScriptException("error in naming realms", e);
    } catch (final MalformedURLException e) {
      throw new ScriptException("hmm. found some malformed URL", e);
    }

    return newClassRealm;
  }
示例#3
0
  public void addJarResource(File jar) throws PlexusContainerException {
    try {
      plexusRealm.addConstituent(jar.toURL());

      if (isStarted()) {
        discoverComponents(plexusRealm);
      }
    } catch (MalformedURLException e) {
      throw new PlexusContainerException("Cannot add jar resource: " + jar + " (bad URL)", e);
    } catch (PlexusConfigurationException e) {
      throw new PlexusContainerException(
          "Cannot add jar resource: " + jar + " (error discovering new components)", e);
    } catch (ComponentRepositoryException e) {
      throw new PlexusContainerException(
          "Cannot add jar resource: " + jar + " (error discovering new components)", e);
    }
  }
  public ScriptFactory(
      final Logger logger,
      final ClassRealm classRealm,
      final File jrubyJar,
      final List<String> classpathElements,
      final boolean fork)
      throws ScriptException, IOException {
    this.logger = logger;
    this.jrubyJar = jrubyJar;
    this.classpathElements =
        classpathElements == null ? NO_CLASSPATH : Collections.unmodifiableList(classpathElements);
    this.fork = fork;
    if (classRealm != null) {
      ClassRealm jruby;
      try {
        jruby = classRealm.getWorld().getRealm("jruby");
      } catch (final NoSuchRealmException e) {
        try {
          jruby = classRealm.getWorld().newRealm("jruby");
          jruby.addConstituent(jrubyJar.toURI().toURL());
        } catch (final DuplicateRealmException ee) {
          throw new ScriptException("could not setup classrealm for jruby", ee);
        }
      }
      this.classRealm = jruby;
    } else {
      this.classRealm = null;
    }

    if (fork) {
      this.launcher = new AntLauncher(logger, this);
    } else {

      this.launcher = new EmbeddedLauncher(logger, this);
    }
  }