예제 #1
0
  /**
   * Get the path for a dependency
   *
   * @param dependency The dependency
   * @return The path
   */
  protected String getPath(DependencyType dependency) {
    String path =
        dependency.getOrganisation().replace('.', File.separatorChar)
            + File.separatorChar
            + dependency.getArtifact()
            + File.separatorChar
            + dependency.getRevision()
            + File.separatorChar
            + dependency.getArtifact()
            + "-"
            + dependency.getRevision()
            + "."
            + dependency.getExt();

    return path;
  }
예제 #2
0
  /**
   * Download an artifact
   *
   * @param servers The servers
   * @param protocolMap The protocols
   * @param dependency The dependency
   * @param repository The repository
   * @param tracker The dependency tracker
   * @return The list of dependencies downloaded
   * @exception ResolveException Thrown in case of an error
   */
  protected List<DependencyType> downloadArtifact(
      List<ServerType> servers,
      Map<String, Protocol> protocolMap,
      DependencyType dependency,
      File repository,
      DependencyTracker tracker)
      throws ResolveException {
    if (tracker.isTracked(dependency)) return Collections.emptyList();

    if (!tracker.track(dependency)) return Collections.emptyList();

    List<DependencyType> result = getArtifact(repository, dependency);

    if (result != null) return result;

    result = new ArrayList<DependencyType>(1);

    File f = new File(repository, getPath(dependency));

    if (!f.getParentFile().exists() && !f.getParentFile().mkdirs())
      throw new ResolveException(f.getParent() + " couldn't be created");

    Iterator<ServerType> it = servers.iterator();
    while (result.isEmpty() && it.hasNext()) {
      try {
        ServerType server = it.next();
        String path = server.getValue();

        if (!path.endsWith("/")) path = path + "/";

        path +=
            Pattern.resolve(
                server.getPattern(),
                dependency.getOrganisation(),
                dependency.getModule(),
                dependency.getRevision(),
                dependency.getArtifact(),
                dependency.getClassifier(),
                dependency.getExt());

        String protocolKey = server.getProtocol();

        if (protocolKey == null || protocolKey.trim().equals("")) protocolKey = "http";

        Protocol protocol = protocolMap.get(protocolKey);

        if (protocol != null) {
          Protocol copy = protocol.clone();
          if (copy.download(path, f)) result.add(dependency);
        } else {
          throw new ResolveException(
              "Protocol (" + protocolKey + ") not defined for server " + server.getValue());
        }
      } catch (CloneNotSupportedException cnse) {
        // Shouldn't happen
      }
    }

    if (result.isEmpty())
      throw new ResolveException("The dependency couldn't be resolved", dependency);

    return result;
  }