All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.testng.internal.protocols.BundledResourceProcessor Maven / Gradle / Ivy

There is a newer version: 7.10.2
Show newest version
package org.testng.internal.protocols;

import static java.nio.charset.StandardCharsets.UTF_8;

import java.lang.reflect.Method;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLDecoder;
import java.util.List;
import org.testng.collections.Lists;

class BundledResourceProcessor extends Processor {
  @Override
  public List process(Input input, URL url) {
    return processBundledResources(
        url,
        input.getIncluded(),
        input.getExcluded(),
        input.getPackageWithoutWildCards(),
        input.isRecursive());
  }

  private static List processBundledResources(
      URL url,
      List included,
      List excluded,
      String packageOnly,
      boolean recursive) {
    try {
      Class[] params = {};
      // BundleURLConnection
      URLConnection connection = url.openConnection();
      Method thisMethod = url.openConnection().getClass().getDeclaredMethod("getFileURL", params);
      Object[] paramsObj = {};
      URL fileUrl = (URL) thisMethod.invoke(connection, paramsObj);
      return findClassesInDirPackage(
          packageOnly, included, excluded, URLDecoder.decode(fileUrl.getFile(), UTF_8), recursive);
    } catch (Exception ex) {
      // ignore - probably not an Eclipse OSGi bundle
    }
    return Lists.newArrayList();
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy