/**
  * Checks whether the dependencies among the given Packs. Specifically it checks that no pack
  * point to a non existent pack and also that there are no circular dependencies in the packs.
  *
  * @param packs - List<Pack> representing the packs in the installation
  */
 public void checkDependencies(List packs) throws CompilerException {
   // Because we use package names in the configuration file we assosiate
   // the names with the objects
   Map names = new HashMap();
   for (int i = 0; i < packs.size(); i++) {
     PackInfo pack = (PackInfo) packs.get(i);
     names.put(pack.getPack().name, pack);
   }
   int result = dfs(packs, names);
   // @todo More informative messages to include the source of the error
   if (result == -2) parseError("Circular dependency detected");
   else if (result == -1) parseError("A dependency doesn't exist");
 }
 /**
  * Recursive method to add files in a pack.
  *
  * @param file The file to add.
  * @param targetdir The relative path to the parent.
  * @param osList The target OS constraints.
  * @param override Overriding behaviour.
  * @param pack Pack to be packed into
  * @param additionals Map which contains additional data
  * @exception FileNotFoundException if the file does not exist
  */
 protected void addRecursively(
     File file, String targetdir, List osList, int override, PackInfo pack, Map additionals)
     throws IOException {
   String targetfile = targetdir + "/" + file.getName();
   if (!file.isDirectory()) pack.addFile(file, targetfile, osList, override, additionals);
   else {
     File[] files = file.listFiles();
     if (files.length == 0) // The directory is empty so must be added
     pack.addFile(file, targetfile, osList, override, additionals);
     else {
       // new targetdir = targetfile;
       for (int i = 0; i < files.length; i++)
         addRecursively(files[i], targetfile, osList, override, pack, additionals);
     }
   }
 }
  private int dfsVisit(PackInfo u, Map names, Map edges) {
    u.colour = PackInfo.GREY;
    List deps = u.getDependencies();
    if (deps != null) {
      for (int i = 0; i < deps.size(); i++) {
        String name = (String) deps.get(i);
        PackInfo v = (PackInfo) names.get(name);
        if (v == null) {
          System.out.println("Failed to find dependency: " + name);
          return -1;
        }
        Edge edge = new Edge(u, v);
        if (edges.get(edge) == null) edges.put(edge, new Integer(v.colour));

        if (v.colour == PackInfo.WHITE) {

          final int result = dfsVisit(v, names, edges);
          if (result != 0) return result;
        }
      }
    }
    u.colour = PackInfo.BLACK;
    return 0;
  }
Beispiel #4
0
  private Set<String> scanPackages() {

    if (packages.isEmpty()) {
      return Collections.emptySet();
    }

    Set<String> foundClasses = new HashSet<String>();

    for (PackInfo packInfo : packages) {

      ClassLoader cl = packInfo.getClassLoaderRef().get();
      if (cl == null) {
        continue;
      }
      String packName = packInfo.getPackName();
      URL resourceUrl =
          cl.getResource(
              packInfo.getPackClassName().replace('.', '/') + Files.CLASS_FILE_EXTENSION);

      if (resourceUrl != null) {

        WeldSELogger.LOG.scanningPackage(packName, resourceUrl);

        try {
          URI resourceUri = resourceUrl.toURI();

          if (PROCOTOL_FILE.equals(resourceUrl.getProtocol())) {
            // Get the package directory, e.g. "file:///home/weld/org/jboss
            handleDir(
                new File(resourceUri).getParentFile(),
                packInfo.isScanRecursively(),
                packName,
                foundClasses);
          } else if (PROCOTOL_JAR.equals(resourceUrl.getProtocol())) {
            handleJar(resourceUri, packInfo.isScanRecursively(), packName, foundClasses);
          } else {
            WeldSELogger.LOG.resourceUrlProtocolNotSupported(resourceUrl);
          }

        } catch (URISyntaxException e) {
          CommonLogger.LOG.couldNotReadResource(resourceUrl, e);
        }
      } else {
        WeldSELogger.LOG.packageNotFound(packName);
      }
    }
    return foundClasses;
  }