protected Node fromRepository(
      CmrRepository repository, ArtifactContext context, boolean addLeaf) {
    log.debug(" Trying repository " + repository.getDisplayString());
    Node node = repository.findParent(context);
    if (node != null) {
      if (addLeaf) {
        Node parent = node;
        context.toNode(parent);
        NodeUtils.keepRepository(parent, repository);
        try {
          String[] names = repository.getArtifactNames(context);
          for (String name : names) {
            node = parent.getChild(name);
            if (node != null) {
              break;
            }
          }
        } finally {
          ArtifactContext.removeNode(parent);
        }
      }

      if (node != null) {
        NodeUtils.keepRepository(node, repository);
        log.debug("  -> Found at " + NodeUtils.getFullPath(node));
      }
    }
    return node;
  }
 private synchronized ArtifactResult getDelegate() {
   if (delegate == null) {
     final ArtifactContext context = new ArtifactContext(name(), version());
     context.setThrowErrorIfMissing(importType() != ImportType.OPTIONAL);
     delegate = manager.getArtifactResult(context);
   }
   return delegate;
 }
  protected Node getLeafNode(ArtifactContext context) {
    final Node node = getFromAllRoots(context, true);
    if (node == null) {
      if (context.isThrowErrorIfMissing())
        throw new IllegalArgumentException("No such artifact: " + context);
      return null;
    }

    // save the context info
    context.toNode(node);

    return node;
  }
Esempio n. 4
0
 protected void loadModuleFromMap(
     ArtifactResult artifact,
     Module module,
     ModuleImport moduleImport,
     LinkedList<Module> dependencyTree,
     List<PhasedUnits> phasedUnitsOfDependencies,
     boolean forCompiledModule,
     Map<String, Object> model) {
   @SuppressWarnings("unchecked")
   List<String> deps = (List<String>) model.get("$mod-deps");
   if (deps != null) {
     for (String s : deps) {
       int p = s.indexOf('/');
       String depname = null;
       String depv = null;
       if (p > 0) {
         depname = s.substring(0, p);
         depv = s.substring(p + 1);
         if (depv.isEmpty()) depv = null;
       } else {
         depname = s;
       }
       // This will cause the dependency to be loaded later
       JsonModule dep = (JsonModule) getOrCreateModule(splitModuleName(depname), depv);
       ModuleImport imp = new ModuleImport(dep, false, false);
       module.getImports().add(imp);
     }
   }
   ((JsonModule) module).setModel(model);
   for (ModuleImport imp : module.getImports()) {
     if (!imp.getModule().getNameAsString().equals("ceylon.language")) {
       ArtifactContext ac =
           new ArtifactContext(imp.getModule().getNameAsString(), imp.getModule().getVersion());
       ac.setSuffix(".js");
       artifact = getContext().getRepositoryManager().getArtifactResult(ac);
       if (artifact != null) {
         resolveModule(
             artifact,
             imp.getModule(),
             imp,
             dependencyTree,
             phasedUnitsOfDependencies,
             forCompiledModule & imp.isExport());
       }
     }
   }
   ((JsonModule) module).loadDeclarations();
   // module.setAvailable(true);
   return;
 }
 private ArtifactResult downloadZipped(Node node, ArtifactContext context) {
   ArtifactContext zippedContext = context.getZipContext();
   ArtifactResult zipResult = getArtifactResult(zippedContext);
   if (zipResult != null) {
     String zipName = zipResult.artifact().getName();
     File unzippedFolder =
         new File(
             zipResult.artifact().getParentFile(), zipName.substring(0, zipName.length() - 4));
     try {
       IOUtils.extractArchive(zipResult.artifact(), unzippedFolder);
     } catch (IOException e) {
       throw new RepositoryException(
           "Failed to unzip folder downloaded from Herd: " + zipResult.artifact(), e);
     }
     return new FileArtifactResult(
         zipResult.repository(),
         this,
         zipResult.name(),
         zipResult.version(),
         unzippedFolder,
         zipResult.repositoryDisplayString());
   } else {
     return null;
   }
 }
 private ArtifactResult handleNotFound(ArtifactContext context, String foundSuffix) {
   String[] suffixes = context.getSuffixes();
   for (String suffix : suffixes) {
     if (suffix.equals(foundSuffix)) {
       break;
     }
     context.setSuffixes(suffix); // Make sure we'll have only one suffix
     ArtifactResult result = artifactNotFound(context);
     if (result != null) {
       // Seems we were able to find this artifact anyway, so lets return it
       return result;
     }
   }
   context.setSuffixes(suffixes); // Restore the original suffixes
   return null;
 }
Esempio n. 7
0
 private static String getVersionFromFilename(String moduleName, String name) {
   if (!ModuleUtil.isDefaultModule(moduleName)) {
     String type = ArtifactContext.getSuffixFromFilename(name);
     return name.substring(moduleName.length() + 1, name.length() - type.length());
   } else {
     return "";
   }
 }
 private List<CmrRepository> getRepositoriesForContext(ArtifactContext context) {
   List<CmrRepository> reps = getRepositories();
   CmrRepository rep = (CmrRepository) context.getSearchRepository();
   if (rep != null) {
     if (reps.contains(rep)) {
       return Collections.singletonList(rep);
     } else {
       return Collections.emptyList();
     }
   }
   return reps;
 }
Esempio n. 9
0
  private ArtifactResult findDependencies(
      RepositoryManager manager, Node node, Boolean fetchSingleArtifact) {
    final ArtifactContext ac = ArtifactContext.fromNode(node);
    if (ac == null) return null;

    final String name = ac.getName();
    String[] groupArtifactIds = nameToGroupArtifactIds(name);
    if (groupArtifactIds == null) {
      return null;
    }
    final String groupId = groupArtifactIds[0];
    final String artifactId = groupArtifactIds[1];
    final String version = ac.getVersion();

    String repositoryDisplayString = NodeUtils.getRepositoryDisplayString(node);
    CmrRepository repository = NodeUtils.getRepository(node);

    if (CeylonUtils.arrayContains(ac.getSuffixes(), ArtifactContext.LEGACY_SRC)) {
      return fetchWithClassifier(
          repository, groupId, artifactId, version, "sources", repositoryDisplayString);
    }

    return fetchDependencies(
        manager,
        repository,
        groupId,
        artifactId,
        version,
        fetchSingleArtifact != null ? fetchSingleArtifact : ac.isIgnoreDependencies(),
        repositoryDisplayString);
  }
Esempio n. 10
0
 protected ArtifactResult createArtifactResult(
     RepositoryManager manager,
     CmrRepository repository,
     final ArtifactContext dCo,
     String version,
     final boolean shared,
     boolean optional,
     final String repositoryDisplayString) {
   String[] groupArtifactIds = nameToGroupArtifactIds(dCo.getName());
   if (groupArtifactIds == null)
     return createArtifactResult(
         manager, dCo.getName(), version, shared, optional, repositoryDisplayString);
   return createArtifactResult(
       manager,
       repository,
       groupArtifactIds[0],
       groupArtifactIds[1],
       version,
       shared,
       optional,
       repositoryDisplayString);
 }
  /** Cache is only used for remote repos; see issue #47. */
  private Node fromRepositories(
      Iterable<CmrRepository> repositories, ArtifactContext context, boolean addLeaf) {
    log.debug("Looking for " + context);

    for (CmrRepository repository : repositories) {
      log.debug(" Looking in " + repository);
      if (!repository.supportsNamespace(context.getNamespace())) {
        log.debug(" -> does not support namespace " + context.getNamespace());
        continue;
      }
      Node child = fromRepository(repository, context, addLeaf);
      if (child != null) {
        log.debug(" -> Found");
        return child;
      }

      log.debug("  -> Not Found");
    }

    log.debug(" -> Artifact " + context + " not found in any repository");
    return null;
  }
 public ArtifactResult getArtifactResult(ArtifactContext context) throws RepositoryException {
   context = applyOverrides(context);
   final Node node = getLeafNode(context);
   if (node != null) {
     String foundSuffix = ArtifactContext.getSuffixFromNode(node);
     // First handle all the artifact we didn't find
     ArtifactResult result = handleNotFound(context, foundSuffix);
     if (result != null) {
       // Seems we were able to find this artifact anyway, so lets return it
       return result;
     } else {
       // Now return the artifact we found
       context.setSuffixes(foundSuffix); // Make sure we'll have only one suffix
       if (ArtifactContext.isDirectoryName(node.getLabel())) {
         return getFolder(context, node);
       } else {
         return getArtifactResult(context, node);
       }
     }
   } else {
     return handleNotFound(context, null);
   }
 }
 private void uploadZipped(Node parent, ArtifactContext context, File folder) {
   File zippedFolder = null;
   try {
     try {
       zippedFolder = IOUtils.zipFolder(folder);
     } catch (IOException e) {
       throw new RepositoryException("Failed to zip folder for upload to Herd: " + folder, e);
     }
     ArtifactContext zippedContext = context.getZipContext();
     putArtifact(zippedContext, zippedFolder);
     ShaSigner.signArtifact(this, zippedContext, zippedFolder, log);
   } finally {
     if (zippedFolder != null) {
       FileUtil.deleteQuietly(zippedFolder);
     }
   }
 }
Esempio n. 14
0
  @Override
  public ModuleVersionDetails readModuleInfo(
      String moduleName,
      String moduleVersion,
      File moduleArchive,
      boolean includeMembers,
      Overrides overrides) {
    Index index = readModuleIndex(moduleArchive, true);
    final AnnotationInstance moduleAnnotation = getAnnotation(index, moduleName, MODULE_ANNOTATION);
    if (moduleAnnotation == null) return null;

    AnnotationValue doc = moduleAnnotation.value("doc");
    AnnotationValue license = moduleAnnotation.value("license");
    AnnotationValue by = moduleAnnotation.value("by");
    AnnotationValue dependencies = moduleAnnotation.value("dependencies");
    String type = ArtifactContext.getSuffixFromFilename(moduleArchive.getName());

    final AnnotationInstance ceylonAnnotation = getAnnotation(index, moduleName, CEYLON_ANNOTATION);
    if (ceylonAnnotation == null) return null;

    AnnotationValue majorVer = ceylonAnnotation.value("major");
    AnnotationValue minorVer = ceylonAnnotation.value("minor");

    ModuleVersionDetails mvd =
        new ModuleVersionDetails(
            moduleName, getVersionFromFilename(moduleName, moduleArchive.getName()));
    mvd.setDoc(doc != null ? doc.asString() : null);
    mvd.setLicense(license != null ? license.asString() : null);
    if (by != null) {
      mvd.getAuthors().addAll(Arrays.asList(by.asStringArray()));
    }
    mvd.getDependencies()
        .addAll(getDependencies(dependencies, moduleName, mvd.getVersion(), overrides));
    ModuleVersionArtifact mva =
        new ModuleVersionArtifact(
            type, majorVer != null ? majorVer.asInt() : 0, minorVer != null ? minorVer.asInt() : 0);
    mvd.getArtifactTypes().add(mva);

    if (includeMembers) {
      mvd.setMembers(getMembers(index));
    }

    return mvd;
  }
  @Override
  public void run() throws Exception {
    Set<String> artifacts = new LinkedHashSet<String>();
    boolean defaults =
        js == null && jvm == null && src == null && scripts == null && docs == null && all == null;
    if (BooleanUtil.isTrue(all)) {
      artifacts.addAll(Arrays.asList(ArtifactContext.allSuffixes()));
    }
    if (BooleanUtil.isTrue(js) || defaults) {
      artifacts.add(ArtifactContext.JS);
      artifacts.add(ArtifactContext.JS_MODEL);
      artifacts.add(ArtifactContext.RESOURCES);
    } else if (BooleanUtil.isFalse(js)) {
      artifacts.remove(ArtifactContext.JS);
      artifacts.remove(ArtifactContext.JS_MODEL);
      artifacts.remove(ArtifactContext.RESOURCES);
    }
    if (BooleanUtil.isTrue(jvm) || defaults) {
      // put the CAR first since its presence will shortcut the other three
      artifacts.add(ArtifactContext.CAR);
      artifacts.add(ArtifactContext.JAR);
      artifacts.add(ArtifactContext.MODULE_PROPERTIES);
      artifacts.add(ArtifactContext.MODULE_XML);
    } else if (BooleanUtil.isFalse(jvm)) {
      artifacts.remove(ArtifactContext.CAR);
      artifacts.remove(ArtifactContext.JAR);
      artifacts.remove(ArtifactContext.MODULE_PROPERTIES);
      artifacts.remove(ArtifactContext.MODULE_XML);
    }
    if (BooleanUtil.isTrue(src)) {
      artifacts.add(ArtifactContext.SRC);
    } else if (BooleanUtil.isFalse(src)) {
      artifacts.remove(ArtifactContext.SRC);
    }
    if (BooleanUtil.isTrue(scripts)) {
      artifacts.add(ArtifactContext.SCRIPTS_ZIPPED);
    } else if (BooleanUtil.isFalse(scripts)) {
      artifacts.remove(ArtifactContext.SCRIPTS_ZIPPED);
    }
    if (BooleanUtil.isTrue(docs)) {
      artifacts.add(ArtifactContext.DOCS);
    } else if (BooleanUtil.isFalse(docs)) {
      artifacts.remove(ArtifactContext.DOCS);
    }

    // Create the list of ArtifactContexts to copy
    List<ArtifactContext> acs = new ArrayList<ArtifactContext>();
    String[] artifactsArray = new String[artifacts.size()];
    artifacts.toArray(artifactsArray);
    for (ModuleSpec module : modules) {
      if (module != ModuleSpec.DEFAULT_MODULE && !module.isVersioned()) {
        String version =
            checkModuleVersionsOrShowSuggestions(
                getRepositoryManager(), module.getName(), null, ModuleQuery.Type.ALL, null, null);
        module = new ModuleSpec(module.getName(), version);
      }
      ArtifactContext ac =
          new ArtifactContext(module.getName(), module.getVersion(), artifactsArray);
      ac.setIgnoreDependencies(!withDependencies);
      ac.setForceOperation(true);
      acs.add(ac);
    }

    // Now do the actual copying
    final boolean logArtifacts =
        verbose != null && (verbose.contains("all") || verbose.contains("files"));
    ModuleCopycat copier =
        new ModuleCopycat(
            getRepositoryManager(),
            getOutputRepositoryManager(),
            log,
            new ModuleCopycat.CopycatFeedback() {
              @Override
              public boolean beforeCopyModule(ArtifactContext ac, int count, int max)
                  throws IOException {
                String module = ModuleUtil.makeModuleName(ac.getName(), ac.getVersion());
                msg("copying.module", module, count + 1, max).flush();
                return true;
              }

              @Override
              public void afterCopyModule(ArtifactContext ac, int count, int max, boolean copied)
                  throws IOException {
                if (!logArtifacts) {
                  append(") ").msg((copied) ? "copying.ok" : "copying.skipped").newline().flush();
                }
              }

              @Override
              public boolean beforeCopyArtifact(
                  ArtifactContext ac, ArtifactResult ar, int count, int max) throws IOException {
                if (logArtifacts) {
                  if (count == 0) {
                    append(" -- ");
                    append(ar.repositoryDisplayString());
                    newline().flush();
                  }
                  append("    ")
                      .msg("copying.artifact", ar.artifact().getName(), count + 1, max)
                      .flush();
                } else {
                  if (count > 0) {
                    append(", ");
                  } else {
                    append(" (");
                  }
                  String name = ArtifactContext.getSuffixFromFilename(ar.artifact().getName());
                  if (name.startsWith(".") || name.startsWith("-")) {
                    name = name.substring(1);
                  } else if ("module-doc".equals(name)) {
                    name = "doc";
                  }
                  append(name);
                }
                return true;
              }

              @Override
              public void afterCopyArtifact(
                  ArtifactContext ac, ArtifactResult ar, int count, int max, boolean copied)
                  throws IOException {
                if (logArtifacts) {
                  append(" ").msg((copied) ? "copying.ok" : "copying.skipped").newline().flush();
                }
              }

              @Override
              public void notFound(ArtifactContext ac) throws IOException {
                String err =
                    getModuleNotFoundErrorMessage(
                        getRepositoryManager(), ac.getName(), ac.getVersion());
                errorAppend(err);
                errorNewline();
              }
            });
    copier.copyModules(acs);
  }
Esempio n. 16
0
 private void addSearchResult(
     String groupId,
     String artifactId,
     String version,
     ModuleVersionResult result,
     Overrides overrides,
     String repositoryDisplayString)
     throws AetherException {
   ArtifactOverrides artifactOverrides = null;
   if (overrides != null) {
     ArtifactContext ctx =
         new ArtifactContext(MavenRepository.NAMESPACE, groupId + ":" + artifactId, version);
     // see if this artifact is replaced
     ArtifactContext replaceContext = overrides.replace(ctx);
     if (replaceContext != null) {
       String[] groupArtifactIds = nameToGroupArtifactIds(replaceContext.getName());
       if (groupArtifactIds == null) return; // abort
       groupId = groupArtifactIds[0];
       artifactId = groupArtifactIds[1];
       version = replaceContext.getVersion();
       ctx = replaceContext;
     } else if (overrides.isVersionOverridden(ctx)) {
       // perhaps its version is overridden?
       version = overrides.getVersionOverride(ctx);
       ctx.setVersion(version);
     }
     artifactOverrides = overrides.getArtifactOverrides(ctx);
   }
   DependencyDescriptor info =
       impl.getDependencies(groupId, artifactId, version, null, "pom", false);
   if (info != null) {
     StringBuilder description = new StringBuilder();
     StringBuilder licenseBuilder = new StringBuilder();
     collectInfo(info, description, licenseBuilder);
     Set<ModuleDependencyInfo> dependencies = new HashSet<>();
     Set<ModuleVersionArtifact> artifactTypes = new HashSet<>();
     artifactTypes.add(new ModuleVersionArtifact(".jar", null, null));
     Set<String> authors = new HashSet<>();
     for (DependencyDescriptor dep : info.getDependencies()) {
       String namespace = MavenRepository.NAMESPACE;
       String depName = dep.getGroupId() + ":" + dep.getArtifactId();
       String depVersion = dep.getVersion();
       boolean export = false;
       boolean optional = dep.isOptional();
       if (overrides != null) {
         ArtifactContext depCtx = new ArtifactContext(namespace, depName, dep.getVersion());
         if (overrides.isRemoved(depCtx)
             || (artifactOverrides != null
                 && (artifactOverrides.isRemoved(depCtx)
                     || artifactOverrides.isAddedOrUpdated(depCtx)))) continue;
         ArtifactContext replaceCtx = overrides.replace(depCtx);
         if (replaceCtx != null) {
           depCtx = replaceCtx;
           namespace = replaceCtx.getNamespace();
           depName = replaceCtx.getName();
         }
         if (overrides.isVersionOverridden(depCtx))
           depVersion = overrides.getVersionOverride(depCtx);
         if (artifactOverrides != null) {
           if (artifactOverrides.isShareOverridden(depCtx))
             export = artifactOverrides.isShared(depCtx);
           if (artifactOverrides.isOptionalOverridden(depCtx))
             optional = artifactOverrides.isOptional(depCtx);
         }
       }
       ModuleDependencyInfo moduleDependencyInfo =
           new ModuleDependencyInfo(namespace, depName, depVersion, optional, export);
       dependencies.add(moduleDependencyInfo);
     }
     if (artifactOverrides != null) {
       for (DependencyOverride add : artifactOverrides.getAdd()) {
         ArtifactContext ac = add.getArtifactContext();
         ModuleDependencyInfo moduleDependencyInfo =
             new ModuleDependencyInfo(
                 ac.getNamespace(),
                 ac.getName(),
                 ac.getVersion(),
                 add.isOptional(),
                 add.isShared());
         dependencies.add(moduleDependencyInfo);
       }
     }
     ModuleVersionDetails moduleVersionDetails =
         new ModuleVersionDetails(
             MavenRepository.NAMESPACE,
             groupId + ":" + artifactId,
             version,
             description.length() > 0 ? description.toString() : null,
             licenseBuilder.length() > 0 ? licenseBuilder.toString() : null,
             authors,
             dependencies,
             artifactTypes,
             true,
             repositoryDisplayString);
     result.addVersion(moduleVersionDetails);
   }
 }
Esempio n. 17
0
 void loadModule(
     String name,
     String version,
     boolean optional,
     boolean inCurrentClassLoader,
     ModuleGraph.Module dependent)
     throws IOException {
   ArtifactContext artifactContext =
       new ArtifactContext(name, version, ArtifactContext.CAR, ArtifactContext.JAR);
   Overrides overrides = repositoryManager.getOverrides();
   if (overrides != null) {
     if (overrides.isRemoved(artifactContext)) return;
     ArtifactContext replacement = overrides.replace(artifactContext);
     if (replacement != null) {
       artifactContext = replacement;
       name = replacement.getName();
       version = replacement.getVersion();
     }
     if (overrides.isVersionOverridden(artifactContext)) {
       version = overrides.getVersionOverride(artifactContext);
       artifactContext.setVersion(version);
     }
   }
   // skip JDK modules
   if (JDKUtils.isJDKModule(name) || JDKUtils.isOracleJDKModule(name)) return;
   ModuleGraph.Module loadedModule = moduleGraph.findModule(name);
   if (loadedModule != null) {
     String loadedVersion = loadedModule.version;
     // we loaded the module already, but did we load it with the same version?
     if (!Objects.equals(version, loadedVersion)) {
       if (MavenVersionComparator.compareVersions(version, loadedModule.version) > 0) {
         // we want a newer version, keep going
         if (verbose) log("Replacing " + loadedModule + " with newer version " + version);
       } else {
         // we want an older version, just keep the one we have and ignore that
         addDependency(dependent, loadedModule);
         // already resolved and same version, we're good
         return;
       }
     } else if (loadedModule.artifact == null) {
       // now we're sure the version was the same
       // it was resolved to null so it was optional, but perhaps it's required now?
       if (!optional) {
         throw new ModuleNotFoundException(
             "Could not find module: " + ModuleUtil.makeModuleName(name, version));
       }
       addDependency(dependent, loadedModule);
       // already resolved and same version, we're good
       return;
     } else {
       addDependency(dependent, loadedModule);
       // already resolved and same version, we're good
       return;
     }
   }
   if (verbose) log("Resolving " + name + "/" + version);
   ArtifactResult result = repositoryManager.getArtifactResult(artifactContext);
   if (!optional
       && (result == null || result.artifact() == null || !result.artifact().exists())) {
     throw new ModuleNotFoundException(
         "Could not find module: " + ModuleUtil.makeModuleName(name, version));
   }
   // save even missing optional modules as nulls to not re-resolve them
   ModuleGraph.Module mod;
   if (dependent == null) mod = moduleGraph.addRoot(name, version);
   else mod = dependent.addDependency(name, version);
   if (loadedModule != null) loadedModule.replace(mod);
   mod.artifact = result;
   if (result != null) {
     // everything we know should be in the current class loader
     // plus everything from flat repositories
     if (inCurrentClassLoader || result.repository() instanceof FlatRepository) {
       mod.inCurrentClassLoader = true;
     }
     for (ArtifactResult dep : result.dependencies()) {
       // stop if we get removed at any point
       if (mod.replaced) break;
       loadModule(
           dep.name(),
           dep.version(),
           dep.importType() == ImportType.OPTIONAL,
           inCurrentClassLoader,
           mod);
     }
   }
 }
Esempio n. 18
0
 @Override
 public void resolveModule(
     final ArtifactResult artifact,
     final Module module,
     final ModuleImport moduleImport,
     LinkedList<Module> dependencyTree,
     List<PhasedUnits> phasedUnitsOfDependencies,
     boolean forCompiledModule) {
   if (!clLoaded) {
     clLoaded = true;
     // If we haven't loaded the language module yet, we need to load it first
     if (!("ceylon.language".equals(artifact.name())
         && artifact.artifact().getName().endsWith(".js"))) {
       if (clmod == null) {
         ArtifactContext ac =
             new ArtifactContext(
                 "ceylon.language", module.getLanguageModule().getVersion(), ".js");
         ac.setFetchSingleArtifact(true);
         ac.setThrowErrorIfMissing(true);
         ArtifactResult lmar = getContext().getRepositoryManager().getArtifactResult(ac);
         resolveModule(
             lmar,
             module.getLanguageModule(),
             null,
             dependencyTree,
             phasedUnitsOfDependencies,
             forCompiledModule);
       } else {
         loadModuleFromMap(
             artifact,
             module,
             moduleImport,
             dependencyTree,
             phasedUnitsOfDependencies,
             forCompiledModule,
             clmod);
       }
     }
     // Then we continue loading whatever they asked for first.
   }
   // Create a similar artifact but with .js extension
   File js = artifact.artifact();
   if (module instanceof JsonModule && js.getName().endsWith(".js")) {
     if (((JsonModule) module).getModel() != null) {
       return;
     }
     if (js.exists() && js.isFile() && js.canRead()) {
       try {
         Map<String, Object> model = loadMetamodel(js);
         if (model != null) {
           loadModuleFromMap(
               artifact,
               module,
               moduleImport,
               dependencyTree,
               phasedUnitsOfDependencies,
               forCompiledModule,
               model);
         }
       } catch (IOException ex) {
         // nothing to do here, will attempt reading .src
       }
     }
   }
   super.resolveModule(
       artifact,
       module,
       moduleImport,
       dependencyTree,
       phasedUnitsOfDependencies,
       forCompiledModule);
 }
Esempio n. 19
0
  private ArtifactResult fetchDependencies(
      RepositoryManager manager,
      CmrRepository repository,
      String groupId,
      String artifactId,
      String version,
      boolean fetchSingleArtifact,
      String repositoryDisplayString) {

    String classifier = null;
    Overrides overrides = repository.getRoot().getService(Overrides.class);
    ArtifactOverrides ao = null;
    log.debug("Overrides: " + overrides);
    ArtifactContext context = getArtifactContext(groupId, artifactId, version, null, null);
    if (overrides != null) {
      ao = overrides.getArtifactOverrides(context);
      log.debug(" [" + context + "] => " + ao);
    }
    // entire replacement
    ArtifactContext replacementContext = null;
    if (ao != null && ao.getReplace() != null) {
      replacementContext = ao.getReplace().getArtifactContext();
    } else if (overrides != null) {
      replacementContext = overrides.replace(context);
    }
    if (replacementContext != null) {
      log.debug(
          String.format("[Maven-Overrides] Replacing %s with %s.", context, replacementContext));
      // replace fetched dependency
      String[] nameToGroupArtifactIds = nameToGroupArtifactIds(replacementContext.getName());
      if (nameToGroupArtifactIds != null) {
        groupId = nameToGroupArtifactIds[0];
        artifactId = nameToGroupArtifactIds[1];
        version = replacementContext.getVersion();
        // new AO
        context = getArtifactContext(groupId, artifactId, version, null, null);
        ao = overrides.getArtifactOverrides(context);
      }
    }
    // version replacement
    if (overrides != null && overrides.isVersionOverridden(context)) {
      version = overrides.getVersionOverride(context);
      context.setVersion(version);
    }
    // classifier replacement
    if (ao != null && ao.hasClassifier()) {
      classifier = ao.getClassifier();
      log.debug("Using classifier " + classifier);
    }

    final String name = toCanonicalForm(groupId, artifactId);
    final String coordinates = toCanonicalForm(name, version);
    try {
      DependencyDescriptor info =
          impl.getDependencies(groupId, artifactId, version, classifier, null, fetchSingleArtifact);
      if (info == null) {
        log.debug("No artifact found: " + coordinates);
        return null;
      }

      final SingleArtifactResult result;
      if (fetchSingleArtifact) {
        result =
            new SingleArtifactResult(
                repository, name, version, info.getFile(), repositoryDisplayString);
      } else {
        final List<ArtifactResult> dependencies = new ArrayList<>();

        for (DependencyDescriptor dep : info.getDependencies()) {
          String dGroupId = dep.getGroupId();
          String dArtifactId = dep.getArtifactId();
          String dVersion = dep.getVersion();
          boolean export = false;
          boolean optional = dep.isOptional();
          boolean isCeylon = false;
          ArtifactContext dContext = null;
          if (overrides != null)
            dContext = getArtifactContext(dGroupId, dArtifactId, dVersion, null, null);

          if (overrides != null) {
            if (overrides.isRemoved(dContext) || (ao != null && ao.isRemoved(dContext))) {
              log.debug(String.format("[Maven-Overrides] Removing %s from %s.", dep, context));
              continue; // skip dependency
            }
            if (ao != null && ao.isAddedOrUpdated(dContext)) {
              log.debug(String.format("[Maven-Overrides] Replacing %s from %s.", dep, context));
              continue; // skip dependency
            }
            ArtifactContext replace = overrides.replace(dContext);
            if (replace != null) {
              dContext = replace;
              String[] groupArtifactIds = nameToGroupArtifactIds(replace.getName());
              if (groupArtifactIds == null) {
                isCeylon = true;
              } else {
                dGroupId = groupArtifactIds[0];
                dArtifactId = groupArtifactIds[1];
              }
              dVersion = replace.getVersion();
            }
            if (ao != null) {
              if (ao.isShareOverridden(dContext)) export = ao.isShared(dContext);
              if (ao.isOptionalOverridden(dContext)) optional = ao.isOptional(dContext);
            }
          }

          // do we have a version update?
          if (overrides != null && overrides.isVersionOverridden(dContext)) {
            dVersion = overrides.getVersionOverride(dContext);
          }

          ArtifactResult dr;
          if (isCeylon)
            dr =
                createArtifactResult(
                    manager,
                    dContext.getName(),
                    dVersion,
                    export,
                    optional,
                    repositoryDisplayString);
          else
            dr =
                createArtifactResult(
                    manager,
                    repository,
                    dGroupId,
                    dArtifactId,
                    dVersion,
                    export,
                    optional,
                    repositoryDisplayString);
          dependencies.add(dr);
        }

        if (ao != null) {
          for (DependencyOverride addon : ao.getAdd()) {
            ArtifactContext dContext = addon.getArtifactContext();
            String dVersion = overrides.getVersionOverride(dContext);
            dependencies.add(
                createArtifactResult(
                    manager,
                    repository,
                    dContext,
                    dVersion,
                    addon.isShared(),
                    addon.isOptional(),
                    repositoryDisplayString));
            log.debug(
                String.format(
                    "[Maven-Overrides] Added %s to %s.", addon.getArtifactContext(), context));
          }
        }

        result =
            new AetherArtifactResult(
                repository, name, version, info.getFile(), dependencies, repositoryDisplayString);
      }

      if (ao != null && ao.getFilter() != null) {
        result.setFilter(PathFilterParser.parse(ao.getFilter()));
      }

      return result;
    } catch (IOException e) {
      throw new IllegalStateException(e);
    } catch (AetherException e) {
      log.debug("Could not resolve artifact [" + coordinates + "] : " + e);
      return null;
    }
  }