コード例 #1
0
  public void connect(String connectThis, String toThis) {
    List<DependentLoaderImplementation> connectLoaders =
        new ArrayList<DependentLoaderImplementation>();
    List<DependentLoaderImplementation> toLoaders = new ArrayList<DependentLoaderImplementation>();

    for (String stringKey : loaderMap.keySet()) {
      if (stringKey.startsWith(connectThis)) {
        connectLoaders.add(loaderMap.get(stringKey));
      }
      if (stringKey.startsWith(toThis)) {
        toLoaders.add(loaderMap.get(stringKey));
      }
    }

    for (DependentLoaderImplementation connectLoader : connectLoaders) {
      DependentLoaderImplementation[] newDependents =
          new DependentLoaderImplementation[connectLoader.dependencies.length + toLoaders.size()];

      int i = 0;
      for (DependentLoaderImplementation oldDependency : connectLoader.dependencies) {
        newDependents[i++] = oldDependency;
      }
      for (DependentLoaderImplementation toLoader : toLoaders) {
        newDependents[i++] = toLoader;
      }
      connectLoader.dependencies = newDependents;
    }
  }
コード例 #2
0
  public void nameClassLoader(Artifact artifactId, ClassLoader loader, boolean recursive) {
    DependentLoaderImplementation theLoader = null;
    theLoader = new DependentLoaderImplementation(artifactId, loader, exposed, parentLoader);

    if (artifactId != null) {
      assert (theLoader != null);
      setLoader(theLoader);
      assert (loaderMap.get(toString(artifactId)) != null);
    }
    if (recursive) {
      OutputBouble bouble = OutputBouble.push();

      try {
        List<Artifact> dependencies = dependencyManager.getDirectDependencies(artifactId);
        for (Artifact dependency : dependencies) {
          if (!loaderMap.containsKey(toString(dependency))) {
            nameClassLoader(dependency, theLoader, recursive);
          }
        }
      } catch (Exception e) {
        OutputBouble.reportError(e);
      } finally {
        bouble.pop();
        if (bouble.isError) bouble.writeToParent();
      }
    }
    visitLoader(theLoader);
  }
コード例 #3
0
  private Artifact unify(Artifact dependent, Artifact dependency) {
    for (Entry<String, String> unification : unified.entrySet()) {
      String groupFilter = unification.getKey();
      String version = unification.getValue();
      String artifactId = dependency.toString();

      if ("".equals(version)) {
        version = dependent.getVersion();
      }
      if (artifactId.startsWith(groupFilter) && (!"".equals(version))) {
        Artifact retVal =
            new DefaultArtifact(
                dependency.getGroupId(),
                dependency.getArtifactId(),
                dependency.getClassifier(),
                dependency.getExtension(),
                // The important one
                version);
        retVal.setProperties(dependency.getProperties());
        return retVal;
      }
    }

    return dependency;
  }
コード例 #4
0
  public DependentLoaderImplementation nameArtifact(
      Artifact artifactId, URL[] jar, Object... dependsOn) {
    DependentLoaderImplementation theLoader = null;
    if (jar == null)
      theLoader = new DependentLoaderImplementation(artifactId, exposed, parentLoader);
    else theLoader = new DependentLoaderImplementation(artifactId, jar, exposed, parentLoader);

    List<DependentLoaderImplementation> dependencies =
        new ArrayList<DependentLoaderImplementation>();

    for (Object dependency : dependsOn) {
      if (dependency instanceof DependentLoaderImplementation) {
        dependencies.add((DependentLoaderImplementation) dependency);
      } else if (dependency instanceof String) {
        DependentLoaderImplementation candidate =
            enshureDependencyJarLoaded(artifactId, new DefaultArtifact((String) dependency));
        if (candidate != null) dependencies.add((DependentLoaderImplementation) dependency);
      } else if (dependency instanceof Artifact) {
        DependentLoaderImplementation candidate =
            enshureDependencyJarLoaded(artifactId, (Artifact) dependency);
        if (candidate != null) dependencies.add((DependentLoaderImplementation) dependency);
      }
    }
    theLoader.setDependencies(
        dependencies.toArray(new DependentLoaderImplementation[dependencies.size()]));

    if (artifactId != null) {
      assert (theLoader != null);
      setLoader(theLoader);
      assert (loaderMap.get(toString(artifactId)) != null);
    }
    visitLoader(theLoader);
    return theLoader;
  }
コード例 #5
0
  public DependentLoaderImplementation[] getLoaded(String filter) {
    DefaultArtifact asArtifact = new DefaultArtifact(filter);
    DependentLoaderImplementation theLoader = findOverride(asArtifact);
    if (theLoader != null) {
      DependentLoaderImplementation[] retVal = {theLoader};
      return retVal;
    }

    if (loaderMap.containsKey(filter)) {
      DependentLoaderImplementation[] retVal = {loaderMap.get(filter)};
      return retVal;
    }

    ArrayList<DependentLoaderImplementation> result = new ArrayList();
    for (String key : loaderMap.keySet()) {
      if (key.startsWith(filter)) {
        result.add(loaderMap.get(key));
      }
    }
    ;
    return Arrays.copyOf(result.toArray(), result.size(), DependentLoaderImplementation[].class);
  }
コード例 #6
0
 public void logGraph(String logFile) {
   PrintWriter writer;
   try {
     writer = new PrintWriter(logFile, "UTF-8");
     writer.println("digraph loaders {");
     for (Entry<String, DependentLoaderImplementation> inMap : loaderMap.entrySet()) {
       DependentLoaderImplementation loader = inMap.getValue();
       for (DependentLoaderImplementation depedent : loader.dependencies) {
         if (depedent != null)
           writer.println("\"" + loader.artifact + "\" -> " + "\"" + depedent.artifact + "\"");
         else writer.println("\"" + loader.artifact + "\" -> null");
       }
     }
     writer.println("}");
     writer.close();
   } catch (Exception e) {
     OutputBouble.reportError(e);
   }
 }
コード例 #7
0
  public void getJar(Artifact artifactId) {
    OutputBouble bouble = OutputBouble.push();
    // Fetch jar and dependencies.
    try {
      Result<File> localFileName = dependencyManager.getLocalFile(artifactId);
      List<Artifact> dependencies = dependencyManager.getDirectDependencies(artifactId);

      int i = 0;
      for (Artifact dependencyId : dependencies) {
        if (!loaderMap.containsKey(toString(dependencyId))) {
          getJar(dependencyId);
        }
      }
    } catch (Exception e) {
      OutputBouble.reportError(e);
    } finally {
      bouble.pop();
      if (bouble.isError) bouble.writeToParent();
    }
  }
コード例 #8
0
 public void unifyGroupVersion(String group, String version) {
   unified.put(group, version);
 }
コード例 #9
0
 public void reloadJar(String artifactId) {
   loaderMap.remove(artifactId);
   enshureJarLoaded(artifactId);
 }
コード例 #10
0
  public DependentLoaderImplementation enshureJarLoaded(Artifact _artifactId) {
    Artifact artifactId = unify(_artifactId);

    if ("dependent".equals(artifactId.getArtifactId())
        && "no.dbwatch".equals(artifactId.getGroupId())) {
      return null;
    }
    DependentLoaderImplementation theLoader = findOverride(artifactId);
    if (theLoader != null) {
      visitLoader(theLoader);
      return theLoader;
    }
    if (loaderMap.containsKey(toString(artifactId))) return loaderMap.get(toString(artifactId));
    // Fetch jar and dependencies.
    OutputBouble bouble = OutputBouble.push();

    try {
      Result<File> localFileName = dependencyManager.getLocalFile(artifactId);

      if (localFileName.success())
        theLoader =
            new DependentLoaderImplementation(
                artifactId,
                localFileName.val.getAbsoluteFile().toURI().toURL(),
                exposed,
                parentLoader);
      else theLoader = new DependentLoaderImplementation(artifactId, exposed, parentLoader);
      setLoader(theLoader);

      List<Artifact> dependencies = dependencyManager.getDirectDependencies(artifactId);

      DependentLoaderImplementation[] actualDependencies =
          new DependentLoaderImplementation[dependencies.size() + theLoader.dependencies.length];
      int i = 0;
      for (DependentLoaderImplementation dependencyFromConf : theLoader.dependencies) {
        actualDependencies[i++] = dependencyFromConf;
      }
      for (Artifact dependencyId : dependencies) {

        DependentLoaderImplementation loader = enshureDependencyJarLoaded(artifactId, dependencyId);
        if (loader == null) {
          OutputBouble.logFile.println(artifactId.toString() + ":");
          OutputBouble.logFile.println("\t Missing dependency " + dependencyId.toString());
          OutputBouble.logFile.println("\t Ignoring");
        } else {
          actualDependencies[i++] = loader;
        }
      }
      if (actualDependencies.length > i) {
        actualDependencies = Arrays.copyOf(actualDependencies, i);
      }

      theLoader.setDependencies(actualDependencies);

      extraDependencies.loaderAdded(theLoader);

      visitLoader(theLoader);
      return theLoader;
    } catch (Exception e) {
      OutputBouble.reportError(e);
      return theLoader;
    } finally {
      bouble.pop();
      if (bouble.isError) bouble.writeToParent();
    }
    // return null;
  }