/**
   * Glassfish jsp requires that we set up the list of system jars that have tlds in them.
   *
   * <p>This method is a little fragile, as it relies on knowing that the jstl jars are the only
   * ones in the system path that contain tlds.
   *
   * @return
   * @throws Exception
   */
  private List<URL> getSystemJarsWithTlds() throws Exception {
    final List<URL> list = new ArrayList<URL>();
    List<URI> artifactUris = new ArrayList<URI>();
    Pattern pattern = Pattern.compile(tldJarNamePatterns);
    for (Iterator<Artifact> iter = pluginArtifacts.iterator(); iter.hasNext(); ) {
      Artifact pluginArtifact = iter.next();
      artifactUris.add(Resource.newResource(pluginArtifact.getFile()).getURI());
    }

    PatternMatcher matcher =
        new PatternMatcher() {
          public void matched(URI uri) throws Exception {
            // uri of system artifact matches pattern defining list of jars known to contain tlds
            list.add(uri.toURL());
          }
        };
    matcher.match(pattern, artifactUris.toArray(new URI[artifactUris.size()]), false);

    return list;
  }
Exemplo n.º 2
0
  @Override
  public void preConfigure(final WebAppContext context) throws Exception {
    // Look for a work directory
    File work = findWorkDirectory(context);
    if (work != null) makeTempDirectory(work, context, false);

    // Make a temp directory for the webapp if one is not already set
    resolveTempDirectory(context);

    // Extract webapp if necessary
    unpack(context);

    // Apply an initial ordering to the jars which governs which will be scanned for META-INF
    // info and annotations. The ordering is based on inclusion patterns.
    String tmp = (String) context.getAttribute(WEBINF_JAR_PATTERN);
    Pattern webInfPattern = (tmp == null ? null : Pattern.compile(tmp));
    tmp = (String) context.getAttribute(CONTAINER_JAR_PATTERN);
    Pattern containerPattern = (tmp == null ? null : Pattern.compile(tmp));

    // Apply ordering to container jars - if no pattern is specified, we won't
    // match any of the container jars
    PatternMatcher containerJarNameMatcher =
        new PatternMatcher() {
          public void matched(URI uri) throws Exception {
            context.getMetaData().addContainerJar(Resource.newResource(uri));
          }
        };
    ClassLoader loader = context.getClassLoader();
    while (loader != null && (loader instanceof URLClassLoader)) {
      URL[] urls = ((URLClassLoader) loader).getURLs();
      if (urls != null) {
        URI[] containerUris = new URI[urls.length];
        int i = 0;
        for (URL u : urls) {
          try {
            containerUris[i] = u.toURI();
          } catch (URISyntaxException e) {
            containerUris[i] = new URI(u.toString().replaceAll(" ", "%20"));
          }
          i++;
        }
        containerJarNameMatcher.match(containerPattern, containerUris, false);
      }
      loader = loader.getParent();
    }

    // Apply ordering to WEB-INF/lib jars
    PatternMatcher webInfJarNameMatcher =
        new PatternMatcher() {
          @Override
          public void matched(URI uri) throws Exception {
            context.getMetaData().addWebInfJar(Resource.newResource(uri));
          }
        };
    List<Resource> jars = findJars(context);

    // Convert to uris for matching
    URI[] uris = null;
    if (jars != null) {
      uris = new URI[jars.size()];
      int i = 0;
      for (Resource r : jars) {
        uris[i++] = r.getURI();
      }
    }
    webInfJarNameMatcher.match(
        webInfPattern, uris, true); // null is inclusive, no pattern == all jars match
  }
Exemplo n.º 3
0
 /**
  * Find jar names from the provided list matching a pattern.
  *
  * <p>If the pattern is null and isNullInclusive is true, then all jar names will match.
  *
  * <p>A pattern is a set of acceptable jar names. Each acceptable jar name is a regex. Each regex
  * can be separated by either a "," or a "|". If you use a "|" this or's together the jar name
  * patterns. This means that ordering of the matches is unimportant to you. If instead, you want
  * to match particular jar names, and you want to match them in order, you should separate the
  * regexs with "," instead.
  *
  * <p>Eg "aaa-.*\\.jar|bbb-.*\\.jar" Will iterate over the jar names and match in any order.
  *
  * <p>Eg "aaa-*\\.jar,bbb-.*\\.jar" Will iterate over the jar names, matching all those starting
  * with "aaa-" first, then "bbb-".
  *
  * @param pattern
  * @param uris
  * @param isNullInclusive if true, an empty pattern means all names match, if false, none match
  * @throws Exception
  */
 public void scan(Pattern pattern, URI[] uris, boolean isNullInclusive) throws Exception {
   super.match(pattern, uris, isNullInclusive);
 }