Search in sources :

Example 1 with ArtifactResult

use of com.redhat.ceylon.model.cmr.ArtifactResult in project ceylon-compiler by ceylon.

the class CeylonP2Tool method collectModules.

private void collectModules(RepositoryManager repoManager, String name, String version, Map<String, ModuleInfo> allModules) throws IOException {
    // ignore JDK dependencies
    if (CeylonP2Tool.skipModule(name))
        return;
    String key = name + "/" + version;
    if (allModules.containsKey(key))
        return;
    ArtifactResult artifact = repoManager.getArtifactResult(new ArtifactContext(name, version, ArtifactContext.CAR, ArtifactContext.JAR));
    File artifactJar = null;
    if (artifact == null) {
        // try to find it in the plugins folder
        File pluginJar = new File(out, "plugins/" + name + "_" + version + ".jar");
        if (pluginJar.exists()) {
            artifactJar = pluginJar;
        }
    } else {
        artifactJar = artifact.artifact();
    }
    allModules.put(key, artifactJar != null ? new ModuleInfo(name, version, artifactJar) : null);
    if (artifact == null) {
        errorMsg("module.not.found", name + "/" + version, out + "/plugins");
    } else {
        msg("module.found", name + "/" + version, artifact != null ? artifact.repositoryDisplayString() : artifactJar.getPath());
        newline();
        for (ArtifactResult dep : artifact.dependencies()) {
            // FIXME: deal with optionals
            collectModules(repoManager, dep.name(), dep.version(), allModules);
        }
    }
}
Also used : ArtifactContext(com.redhat.ceylon.cmr.api.ArtifactContext) File(java.io.File) ArtifactResult(com.redhat.ceylon.model.cmr.ArtifactResult)

Example 2 with ArtifactResult

use of com.redhat.ceylon.model.cmr.ArtifactResult in project ceylon-compiler by ceylon.

the class CeylonWarTool method addLibEntries.

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"));
}
Also used : ArrayList(java.util.ArrayList) ToolUsageError(com.redhat.ceylon.common.tool.ToolUsageError) Map(java.util.Map) File(java.io.File) ArtifactResult(com.redhat.ceylon.model.cmr.ArtifactResult)

Example 3 with ArtifactResult

use of com.redhat.ceylon.model.cmr.ArtifactResult in project ceylon-compiler by ceylon.

the class CeylonSrcTool method run.

@Override
public void run() throws Exception {
    // First check if all the arguments point to source archives
    for (ModuleSpec module : modules) {
        if (module != ModuleSpec.DEFAULT_MODULE && !module.isVersioned()) {
            if (checkModuleVersionsOrShowSuggestions(getRepositoryManager(), module.getName(), null, ModuleQuery.Type.SRC, null, null) == null) {
                return;
            }
        }
    }
    // If all are correct we unpack them
    for (ModuleSpec module : modules) {
        String version = module.getVersion();
        if (module != ModuleSpec.DEFAULT_MODULE && !module.isVersioned()) {
            version = checkModuleVersionsOrShowSuggestions(getRepositoryManager(), module.getName(), null, ModuleQuery.Type.SRC, null, null);
        }
        msg("retrieving.module", module).newline();
        ArtifactContext allArtifacts = new ArtifactContext(module.getName(), version, ArtifactContext.SRC, ArtifactContext.RESOURCES, ArtifactContext.DOCS, ArtifactContext.SCRIPTS_ZIPPED);
        List<ArtifactResult> results = getRepositoryManager().getArtifactResults(allArtifacts);
        if (results == null) {
            String err = getModuleNotFoundErrorMessage(getRepositoryManager(), module.getName(), module.getVersion());
            errorAppend(err);
            errorNewline();
            continue;
        }
        String modFolder = module.getName().replace('.', File.separatorChar);
        boolean hasSources = false;
        for (ArtifactResult result : results) {
            String suffix = ArtifactContext.getSuffixFromFilename(result.artifact().getName());
            if (ArtifactContext.SRC.equals(suffix)) {
                append("    ").msg("extracting.sources").newline();
                extractArchive(result, applyCwd(src), "source");
                hasSources = true;
            } else if (ArtifactContext.SCRIPTS_ZIPPED.equals(suffix)) {
                append("    ").msg("extracting.scripts").newline();
                extractArchive(result, new File(applyCwd(script), modFolder), "script");
            } else if (ArtifactContext.RESOURCES.equals(suffix)) {
                append("    ").msg("extracting.resources").newline();
                copyResources(result, applyCwd(resource));
            } else if (ArtifactContext.DOCS.equals(suffix)) {
                append("    ").msg("extracting.docs").newline();
                copyFiles(result, "doc", new File(applyCwd(doc), modFolder), "doc");
            }
        }
        if (!hasSources) {
            msg("no.sources.found", module).newline();
        }
    }
}
Also used : ModuleSpec(com.redhat.ceylon.common.tools.ModuleSpec) ArtifactContext(com.redhat.ceylon.cmr.api.ArtifactContext) File(java.io.File) ArtifactResult(com.redhat.ceylon.model.cmr.ArtifactResult)

Example 4 with ArtifactResult

use of com.redhat.ceylon.model.cmr.ArtifactResult in project ceylon-compiler by ceylon.

the class CeylonClasspathTool method run.

@Override
public void run() throws Exception {
    String module = ModuleUtil.moduleName(moduleNameOptVersion);
    String version = checkModuleVersionsOrShowSuggestions(getRepositoryManager(), module, ModuleUtil.moduleVersion(moduleNameOptVersion), ModuleQuery.Type.JVM, Versions.JVM_BINARY_MAJOR_VERSION, Versions.JVM_BINARY_MINOR_VERSION, null);
    if (version == null)
        return;
    loadModule(module, version);
    if (!force)
        errorOnConflictingModule(module, version);
    boolean once = true;
    for (ArtifactResult entry : this.loadedModules.values()) {
        // since we even add missing modules there to avoid seeing them twice, let's skip them now
        if (entry == null)
            continue;
        File file = entry.artifact();
        if (file == null)
            continue;
        // on duplicate, let's only keep the last version
        SortedSet<String> versions = loadedModuleVersions.get(entry.name());
        if (version != null && !versions.isEmpty() && entry.version() != null && !entry.version().equals(versions.last()))
            continue;
        if (once)
            once = false;
        else
            append(File.pathSeparator);
        append(file.getAbsolutePath());
    }
    flush();
}
Also used : File(java.io.File) ArtifactResult(com.redhat.ceylon.model.cmr.ArtifactResult)

Example 5 with ArtifactResult

use of com.redhat.ceylon.model.cmr.ArtifactResult in project ceylon-compiler by ceylon.

the class CeylonEnter method addOutputModuleToClassPath.

public void addOutputModuleToClassPath(Module module) {
    RepositoryManager repositoryManager = fileManager.getOutputRepositoryManager();
    ArtifactResult artifact = null;
    try {
        ArtifactContext ctx = new ArtifactContext(module.getNameAsString(), module.getVersion(), ArtifactContext.CAR, ArtifactContext.JAR);
        artifact = repositoryManager.getArtifactResult(ctx);
    } catch (InvalidArchiveException e) {
        log.error("ceylon", "Module car " + e.getPath() + " obtained from repository " + e.getRepository() + " has an invalid SHA1 signature: you need to remove it and rebuild the archive, since it" + " may be corrupted.");
    } catch (Exception e) {
        String moduleName = module.getNameAsString();
        if (!module.isDefault())
            moduleName += "/" + module.getVersion();
        log.error("ceylon", "Exception occured while trying to resolve module " + moduleName);
        e.printStackTrace();
    }
    addModuleToClassPath(module, false, artifact);
}
Also used : InvalidArchiveException(com.redhat.ceylon.cmr.impl.InvalidArchiveException) RepositoryManager(com.redhat.ceylon.cmr.api.RepositoryManager) ArtifactContext(com.redhat.ceylon.cmr.api.ArtifactContext) InvalidArchiveException(com.redhat.ceylon.cmr.impl.InvalidArchiveException) ArtifactResult(com.redhat.ceylon.model.cmr.ArtifactResult)

Aggregations

ArtifactResult (com.redhat.ceylon.model.cmr.ArtifactResult)10 ArtifactContext (com.redhat.ceylon.cmr.api.ArtifactContext)8 File (java.io.File)5 ArrayList (java.util.ArrayList)3 RepositoryManager (com.redhat.ceylon.cmr.api.RepositoryManager)2 ModuleSpec (com.redhat.ceylon.common.tools.ModuleSpec)2 ModuleDependencyInfo (com.redhat.ceylon.cmr.api.ModuleDependencyInfo)1 ModuleInfo (com.redhat.ceylon.cmr.api.ModuleInfo)1 Overrides (com.redhat.ceylon.cmr.api.Overrides)1 ModuleCopycat (com.redhat.ceylon.cmr.ceylon.ModuleCopycat)1 InvalidArchiveException (com.redhat.ceylon.cmr.impl.InvalidArchiveException)1 Backends (com.redhat.ceylon.common.Backends)1 ToolUsageError (com.redhat.ceylon.common.tool.ToolUsageError)1 LazyModule (com.redhat.ceylon.model.loader.model.LazyModule)1 LazyModuleManager (com.redhat.ceylon.model.loader.model.LazyModuleManager)1 Module (com.redhat.ceylon.model.typechecker.model.Module)1 ModuleImport (com.redhat.ceylon.model.typechecker.model.ModuleImport)1 IOException (java.io.IOException)1 HashSet (java.util.HashSet)1 LinkedHashSet (java.util.LinkedHashSet)1