コード例 #1
0
ファイル: CachedTOCJars.java プロジェクト: ceylon/ceylon
    private List<String> getFileNames(String path) {
      if (artifact instanceof ContentAwareArtifactResult) {
        return ((ContentAwareArtifactResult) artifact).getFileNames(path);
      }

      File jar = artifact.artifact();
      if (jar != null) {
        load();
        // add a trailing / to only list members
        boolean emptyPackage = path.isEmpty();
        // only used for non-empty packages
        path += "/";
        List<String> ret = new ArrayList<String>();
        for (String name : contents) {
          String part = null;
          if (!emptyPackage && name.startsWith(path)) {
            // keep only the part after the package name
            part = name.substring(path.length());
          } else if (emptyPackage) {
            // keep it all, we'll filter later those in subfolders
            part = name;
          }
          // only keep those not in subfolders
          if (part != null && part.indexOf('/') == -1) ret.add(name);
        }
        return ret;
      } else {
        throw new RuntimeException("No file associated with artifact : " + artifact.toString());
      }
    }
コード例 #2
0
ファイル: CeylonWarTool.java プロジェクト: quintesse/ceylon
  protected void addLibEntries() throws MalformedURLException {
    final List<String> libs = new ArrayList<>();

    for (Map.Entry<String, ArtifactResult> entry : this.loadedModules.entrySet()) {
      ArtifactResult module = entry.getValue();
      if (module == null) {
        // it's an optional, missing module (likely java.*)
        continue;
      }

      final File artifact = module.artifact();
      final String moduleName = entry.getKey();

      // use "-" for the version separator
      // use ".jar" so they'll get loaded by the container classloader
      final String name =
          ModuleUtil.moduleName(moduleName) + "-" + ModuleUtil.moduleVersion(moduleName) + ".jar";
      if (name.contains("/") || name.contains("\\") || name.length() == 0) {
        throw new ToolUsageError(CeylonWarMessages.msg("module.name.illegal", name));
      }

      addSpec(new URLEntrySpec(artifact.toURI().toURL(), "WEB-INF/lib/" + name));
      libs.add(name);
    }

    // store the list of added libs so the WarInitializer knows what to copy out
    // to a repo if one has to be created
    final StringBuffer libList = new StringBuffer();
    for (String lib : libs) {
      libList.append(lib).append("\n");
    }
    addSpec(new StringEntrySpec(libList.toString(), "META-INF/libs.txt"));
  }
コード例 #3
0
ファイル: BytecodeUtils.java プロジェクト: lukehutch/ceylon
  @Override
  public ModuleInfo resolve(DependencyContext context, Overrides overrides) {
    if (context.ignoreInner()) {
      return null;
    }

    final ArtifactResult result = context.result();
    return readModuleInformation(result.name(), result.artifact(), overrides);
  }
コード例 #4
0
 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;
   }
 }
コード例 #5
0
ファイル: LanguageCompiler.java プロジェクト: ceylon/ceylon
  private void addDependenciesToAptPath(
      RepositoryManager repositoryManager,
      ModuleSpec moduleSpec,
      Set<ModuleSpec> visited,
      StatusPrinterAptProgressListener progressListener) {
    if (!visited.add(moduleSpec)) return;

    String ns = ModuleUtil.getNamespaceFromUri(moduleSpec.getName());
    String name = ModuleUtil.getModuleNameFromUri(moduleSpec.getName());
    ArtifactContext context =
        new ArtifactContext(
            ns, name, moduleSpec.getVersion(), ArtifactContext.JAR, ArtifactContext.CAR);
    if (progressListener != null) progressListener.retrievingModuleArtifact(moduleSpec, context);
    ArtifactResult result = repositoryManager.getArtifactResult(context);
    if (progressListener != null) {
      if (result == null) {
        progressListener.retrievingModuleArtifactFailed(moduleSpec, context);
      } else {
        progressListener.retrievingModuleArtifactSuccess(moduleSpec, result);
      }
    }
    ceylonEnter.addModuleToAptPath(moduleSpec, result);

    for (ArtifactResult dep : result.dependencies()) {
      if (JDKUtils.isJDKModule(dep.name()) || JDKUtils.isOracleJDKModule(dep.name())) {
        continue;
      }
      // we are running deps, so we need compile/provided/runtime, but not test
      if (dep.moduleScope() == ModuleScope.TEST) continue;
      ModuleSpec depSpec = new ModuleSpec(dep.namespace(), dep.name(), dep.version());
      addDependenciesToAptPath(repositoryManager, depSpec, visited, progressListener);
    }
  }
コード例 #6
0
ファイル: CachedTOCJars.java プロジェクト: ceylon/ceylon
 URI getContentUri(String path) {
   if (artifact instanceof ContentAwareArtifactResult) {
     return ((ContentAwareArtifactResult) artifact).getContentUri(path);
   }
   File jar = artifact.artifact();
   if (jar != null) {
     load();
     try {
       if (contents.contains(path) || folders.contains(path)) {
         String uripath = FileUtil.absoluteFile(jar).toURI().getSchemeSpecificPart();
         return new URI("classpath", uripath + "!" + path, null);
       }
     } catch (URISyntaxException e) {
       throw new RuntimeException(e);
     }
     throw new RuntimeException("Missing entry: " + path + " in jar file: " + jar.getPath());
   }
   throw new RuntimeException("No file associated with artifact : " + artifact.toString());
 }
コード例 #7
0
ファイル: CachedTOCJars.java プロジェクト: ceylon/ceylon
 byte[] getContents(String path) {
   if (artifact instanceof ContentAwareArtifactResult) {
     return ((ContentAwareArtifactResult) artifact).getContents(path);
   }
   File jar = artifact.artifact();
   if (jar != null) {
     try {
       ZipFile zf = new ZipFile(jar);
       try {
         ZipEntry entry = zf.getEntry(path);
         if (entry != null) return loadFile(zf.getInputStream(entry), (int) entry.getSize());
       } finally {
         zf.close();
       }
     } catch (IOException e) {
       throw new RuntimeException(e);
     }
     throw new RuntimeException("Missing entry: " + path + " in jar file: " + jar.getPath());
   }
   throw new RuntimeException("No file associated with artifact : " + artifact.toString());
 }
コード例 #8
0
ファイル: CachedTOCJars.java プロジェクト: ceylon/ceylon
 private void load() {
   if (loaded) return;
   if (artifact instanceof ContentAwareArtifactResult) {
     // make sure we turn package names into paths
     for (String pkg : ((ContentAwareArtifactResult) artifact).getPackages()) {
       packagePaths.add(pkg.replace('.', '/'));
     }
     contents.addAll(((ContentAwareArtifactResult) artifact).getEntries());
   } else {
     if (artifact.artifact() != null) {
       try {
         ZipFile zf = new ZipFile(artifact.artifact());
         try {
           Enumeration<? extends ZipEntry> entries = zf.entries();
           while (entries.hasMoreElements()) {
             ZipEntry entry = entries.nextElement();
             // only cache class files
             String name = entry.getName();
             if (accept(name)) {
               if (entry.isDirectory()) {
                 folders.add(name);
               } else {
                 if (JvmBackendUtil.definesPackage(name)) packagePaths.add(getPackageName(name));
                 contents.add(name);
               }
             }
           }
         } finally {
           zf.close();
         }
       } catch (IOException e) {
         throw new RuntimeException(e);
       }
     }
   }
   loaded = true;
 }
コード例 #9
0
ファイル: CachedTOCJars.java プロジェクト: ceylon/ceylon
 private boolean accept(String path) {
   PathFilter filter = artifact.filter();
   return filter == null || filter.accept(path);
 }
コード例 #10
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);
     }
   }
 }
コード例 #11
0
 private void registerInMetamodel(ArtifactResult artifact, ClassLoader classLoader) {
   if (verbose)
     log("Registering " + artifact.name() + "/" + artifact.version() + " in metamodel");
   Metamodel.loadModule(artifact.name(), artifact.version(), artifact, classLoader);
 }
コード例 #12
0
ファイル: AetherUtils.java プロジェクト: ysb33r/ceylon
 File findDependency(Node node) {
   final ArtifactResult result = findDependencies(null, node, true);
   return (result != null) ? result.artifact() : null;
 }