コード例 #1
0
ファイル: BytecodeUtils.java プロジェクト: lukehutch/ceylon
  /**
   * Read module info from bytecode.
   *
   * @param moduleName the module name
   * @param jarFile the module jar file
   * @return module info list
   */
  private static ModuleInfo readModuleInformation(
      final String moduleName, final File jarFile, Overrides overrides) {
    Index index = readModuleIndex(jarFile, false);
    final AnnotationInstance ai = getAnnotation(index, moduleName, MODULE_ANNOTATION);
    if (ai == null) return null;
    final AnnotationValue version = ai.value("version");
    if (version == null) return null;

    final AnnotationValue dependencies = ai.value("dependencies");
    if (dependencies == null)
      return new ModuleInfo(null, Collections.<ModuleDependencyInfo>emptySet());

    final Set<ModuleDependencyInfo> infos = new LinkedHashSet<ModuleDependencyInfo>();

    final AnnotationInstance[] imports = dependencies.asNestedArray();
    if (imports != null) {
      for (AnnotationInstance im : imports) {
        final String name = asString(im, "name");
        final ModuleDependencyInfo mi =
            new ModuleDependencyInfo(
                name, asString(im, "version"), asBoolean(im, "optional"), asBoolean(im, "export"));
        infos.add(mi);
      }
    }
    ModuleInfo ret = new ModuleInfo(null, infos);
    if (overrides != null) ret = overrides.applyOverrides(moduleName, version.asString(), ret);
    return ret;
  }
コード例 #2
0
ファイル: BytecodeUtils.java プロジェクト: lukehutch/ceylon
  private static Set<ModuleDependencyInfo> getDependencies(
      AnnotationValue dependencies, String module, String version, Overrides overrides) {
    AnnotationInstance[] deps = dependencies.asNestedArray();
    Set<ModuleDependencyInfo> result = new HashSet<ModuleDependencyInfo>(deps.length);
    for (AnnotationInstance dep : deps) {
      AnnotationValue depName = dep.value("name");
      AnnotationValue depVersion = dep.value("version");
      AnnotationValue export = dep.value("export");
      AnnotationValue optional = dep.value("optional");

      result.add(
          new ModuleDependencyInfo(
              depName.asString(),
              depVersion.asString(),
              (optional != null) && optional.asBoolean(),
              (export != null) && export.asBoolean()));
    }
    if (overrides != null)
      return overrides
          .applyOverrides(module, version, new ModuleInfo(null, result))
          .getDependencies();
    return result;
  }
コード例 #3
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);
     }
   }
 }
コード例 #4
0
 public AbstractNodeRepositoryManager(Logger log, Overrides overrides, boolean upgradeDist) {
   super(log, overrides == null ? Overrides.getDistOverrides(upgradeDist) : overrides);
 }
コード例 #5
0
ファイル: AetherUtils.java プロジェクト: ysb33r/ceylon
 private ArtifactContext getArtifactContext(
     String groupId, String artifactId, String version, String packaging, String classifier) {
   if (classifier != null && classifier.isEmpty()) classifier = null;
   return Overrides.createMavenArtifactContext(
       groupId, artifactId, version, packaging, classifier);
 }
コード例 #6
0
ファイル: AetherUtils.java プロジェクト: ysb33r/ceylon
 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);
   }
 }
コード例 #7
0
ファイル: AetherUtils.java プロジェクト: ysb33r/ceylon
  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;
    }
  }