Search in sources :

Example 36 with ArtifactContext

use of org.eclipse.ceylon.cmr.api.ArtifactContext in project ceylon by eclipse.

the class LanguageCompiler method addDependenciesToAptPath.

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);
    }
}
Also used : ModuleSpec(org.eclipse.ceylon.common.ModuleSpec) ArtifactContext(org.eclipse.ceylon.cmr.api.ArtifactContext) ArtifactResult(org.eclipse.ceylon.model.cmr.ArtifactResult)

Example 37 with ArtifactContext

use of org.eclipse.ceylon.cmr.api.ArtifactContext in project ceylon by eclipse.

the class CeylonDocToolTests method compileSdkJavaFiles.

/**
 * This is disgusting, but the current CeylonDoc doesn't handle source files, so we need to compile them first,
 * and we do it using javac to avoid compiling the whole SDK for one java file.
 */
private void compileSdkJavaFiles() throws FileNotFoundException, IOException {
    // put it all in a special folder
    File dir = new File("build", "CeylonDocToolTest/" + name.getMethodName());
    if (dir.exists()) {
        FileUtil.delete(dir);
    }
    dir.mkdirs();
    // download a required jar
    RepositoryManager repoManager = CeylonUtils.repoManager().systemRepo("../dist/dist/repo").buildManager();
    File jbossModulesModule = repoManager.getArtifact(new ArtifactContext(null, "org.jboss.modules", Versions.DEPENDENCY_JBOSS_MODULES_VERSION, ".jar"));
    File runtimeModule = repoManager.getArtifact(new ArtifactContext(null, "ceylon.runtime", Versions.CEYLON_VERSION_NUMBER, ".jar"));
    File modelModule = repoManager.getArtifact(new ArtifactContext(null, "org.eclipse.ceylon.model", Versions.CEYLON_VERSION_NUMBER, ".jar"));
    File undertowCoreModule = repoManager.getArtifact(new ArtifactContext(null, "io.undertow.core", "1.3.5.Final", ".jar"));
    File languageModule = repoManager.getArtifact(new ArtifactContext(null, AbstractModelLoader.CEYLON_LANGUAGE, TypeChecker.LANGUAGE_MODULE_VERSION, ".car"));
    // fire up the java compiler
    JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
    assertNotNull("Missing Java compiler, this test is probably being run with a JRE instead of a JDK!", compiler);
    List<String> options = Arrays.asList("-sourcepath", "../../ceylon-sdk/source", "-d", dir.getAbsolutePath(), "-classpath", undertowCoreModule.getAbsolutePath() + File.pathSeparator + jbossModulesModule.getAbsolutePath() + File.pathSeparator + runtimeModule.getAbsolutePath() + File.pathSeparator + modelModule.getAbsolutePath() + File.pathSeparator + languageModule.getAbsolutePath());
    StandardJavaFileManager fileManager = compiler.getStandardFileManager(null, null, null);
    String[] fileNames = new String[] { "ceylon/interop/java/internal/javaBooleanArray_.java", "ceylon/interop/java/internal/javaByteArray_.java", "ceylon/interop/java/internal/javaCharArray_.java", "ceylon/interop/java/internal/javaDoubleArray_.java", "ceylon/interop/java/internal/javaFloatArray_.java", "ceylon/interop/java/internal/javaIntArray_.java", "ceylon/interop/java/internal/javaLongArray_.java", "ceylon/interop/java/internal/javaObjectArray_.java", "ceylon/interop/java/internal/javaShortArray_.java", "ceylon/interop/java/internal/javaStringArray_.java", "ceylon/interop/java/internal/synchronize_.java" };
    List<String> qualifiedNames = new ArrayList<String>(fileNames.length);
    for (String name : fileNames) {
        qualifiedNames.add("../../ceylon-sdk/source/" + name);
    }
    Iterable<? extends JavaFileObject> fileObjects = fileManager.getJavaFileObjectsFromStrings(qualifiedNames);
    CompilationTask task = compiler.getTask(null, null, null, options, null, fileObjects);
    Boolean ret = task.call();
    Assert.assertEquals("Compilation failed", Boolean.TRUE, ret);
    // now we need to zip it up
    makeCarFromClassFiles(dir, fileNames, "ceylon.test", Versions.CEYLON_VERSION_NUMBER);
    makeCarFromClassFiles(dir, fileNames, "ceylon.http.server", Versions.CEYLON_VERSION_NUMBER);
    makeCarFromClassFiles(dir, fileNames, "ceylon.interop.java", Versions.CEYLON_VERSION_NUMBER);
    makeCarFromClassFiles(dir, fileNames, "ceylon.transaction", Versions.CEYLON_VERSION_NUMBER);
}
Also used : ArrayList(java.util.ArrayList) JavaCompiler(org.eclipse.ceylon.javax.tools.JavaCompiler) StandardJavaFileManager(org.eclipse.ceylon.javax.tools.StandardJavaFileManager) RepositoryManager(org.eclipse.ceylon.cmr.api.RepositoryManager) ArtifactContext(org.eclipse.ceylon.cmr.api.ArtifactContext) File(java.io.File) CompilationTask(org.eclipse.ceylon.javax.tools.JavaCompiler.CompilationTask)

Example 38 with ArtifactContext

use of org.eclipse.ceylon.cmr.api.ArtifactContext in project ceylon by eclipse.

the class CeylonPluginTool method installScripts.

private boolean installScripts(RepositoryManager repositoryManager, ModuleSpec module, boolean errorIfMissing) throws IOException {
    String version = module.getVersion();
    if ((version == null || version.isEmpty()) && !module.getName().equals(Module.DEFAULT_MODULE_NAME)) {
        version = checkModuleVersionsOrShowSuggestions(module.getName(), null, ModuleQuery.Type.ALL, null, null, null, null);
        if (version == null)
            return false;
    }
    module = new ModuleSpec(module.getNamespace(), module.getName(), version);
    File zipSource = null;
    List<File> existingScriptFolders = null;
    if (isSourceModule(module.getName(), version, applyCwd(sourceFolders))) {
        // copy it directly from the source
        existingScriptFolders = findExistingScriptFolders(module.getName(), errorIfMissing);
        if (existingScriptFolders.isEmpty()) {
            return false;
        }
    } else {
        // obtain it from the repo
        ArtifactContext context = new ArtifactContext(null, module.getName(), version, ArtifactContext.SCRIPTS_ZIPPED);
        ArtifactResult result = repositoryManager.getArtifactResult(context);
        if (result == null) {
            String err = getModuleNotFoundErrorMessage(repositoryManager, module.getName(), version);
            errorAppend(err);
            errorNewline();
            return false;
        }
        zipSource = result.artifact();
    }
    File moduleScriptDir = getModuleScriptDir(module);
    ModuleSpec unversioned = new ModuleSpec(module.getNamespace(), module.getName(), "");
    if (existScripts(unversioned)) {
        if (force) {
            uninstallScripts(unversioned, false);
        } else {
            errorMsg("error.module.already.installed", module.getName(), moduleScriptDir);
            return false;
        }
    }
    if (!FileUtil.mkdirs(moduleScriptDir)) {
        errorMsg("error.unable.create.dest.dir", moduleScriptDir);
        return false;
    }
    if (zipSource != null)
        extractScripts(zipSource, moduleScriptDir);
    else {
        copyScripts(existingScriptFolders, moduleScriptDir);
    }
    msg("success.installed", module.getName(), moduleScriptDir);
    newline();
    return true;
}
Also used : ModuleSpec(org.eclipse.ceylon.common.ModuleSpec) ArtifactContext(org.eclipse.ceylon.cmr.api.ArtifactContext) File(java.io.File) ArtifactResult(org.eclipse.ceylon.model.cmr.ArtifactResult)

Example 39 with ArtifactContext

use of org.eclipse.ceylon.cmr.api.ArtifactContext in project ceylon by eclipse.

the class CeylonPluginTool method addScripts.

private boolean addScripts(RepositoryManager outputRepositoryManager, ModuleSpec module, boolean errorIfMissing) throws IOException {
    // find all doc folders to zip
    List<File> existingScriptFolders = findExistingScriptFolders(module.getName(), errorIfMissing);
    if (existingScriptFolders.isEmpty()) {
        return false;
    }
    String version;
    if (!module.getName().equals(Module.DEFAULT_MODULE_NAME)) {
        ModuleVersionDetails mvd = getModuleVersionDetailsFromSource(module.getName());
        if (mvd == null) {
            errorMsg("error.no.script.version", module.getName());
            return false;
        }
        version = mvd.getVersion();
    } else {
        version = null;
    }
    ArtifactContext artifactScriptsZip = new ArtifactContext(null, module.getName(), version, ArtifactContext.SCRIPTS_ZIPPED);
    // make the doc zip roots
    IOUtils.ZipRoot[] roots = new IOUtils.ZipRoot[existingScriptFolders.size()];
    int d = 0;
    for (File scriptFolder : existingScriptFolders) {
        roots[d] = new IOUtils.ZipRoot(scriptFolder, "");
    }
    File scriptZipFile = IOUtils.zipFolders(roots);
    File scriptZipSha1File = ShaSigner.sign(scriptZipFile, getLogger(), verbose != null);
    if (!repositoryRemoveArtifact(outputRepositoryManager, artifactScriptsZip))
        return true;
    if (!repositoryRemoveArtifact(outputRepositoryManager, artifactScriptsZip.getSha1Context()))
        return true;
    if (!repositoryPutArtifact(outputRepositoryManager, artifactScriptsZip, scriptZipFile))
        return true;
    if (!repositoryPutArtifact(outputRepositoryManager, artifactScriptsZip.getSha1Context(), scriptZipSha1File))
        return true;
    scriptZipFile.delete();
    scriptZipSha1File.delete();
    msg("success.packed", module.getName());
    newline();
    return true;
}
Also used : IOUtils(org.eclipse.ceylon.cmr.impl.IOUtils) ModuleVersionDetails(org.eclipse.ceylon.cmr.api.ModuleVersionDetails) ArtifactContext(org.eclipse.ceylon.cmr.api.ArtifactContext) File(java.io.File)

Example 40 with ArtifactContext

use of org.eclipse.ceylon.cmr.api.ArtifactContext in project ceylon by eclipse.

the class JsModuleSourceMapper method resolveModule.

@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 (!(LANGUAGE_MODULE_NAME.equals(artifact.name()) && artifact.artifact().getName().endsWith(ArtifactContext.JS_MODEL))) {
            if (JsModuleManagerFactory.isVerbose()) {
                System.out.println("Loading JS language module before any other modules");
            }
            ArtifactContext ac = new ArtifactContext(null, Module.LANGUAGE_MODULE_NAME, module.getLanguageModule().getVersion(), ArtifactContext.JS_MODEL);
            ac.setIgnoreDependencies(true);
            ac.setThrowErrorIfMissing(true);
            ArtifactResult lmar = getContext().getRepositoryManager().getArtifactResult(ac);
            resolveModule(lmar, module.getLanguageModule(), null, dependencyTree, phasedUnitsOfDependencies, forCompiledModule);
        }
    // Then we continue loading whatever they asked for first.
    }
    // Create a similar artifact but with -model.js extension
    File js = artifact.artifact();
    if (js.getName().endsWith(ArtifactContext.JS) && !js.getName().endsWith(ArtifactContext.JS_MODEL)) {
        ArtifactContext ac = new ArtifactContext(artifact.namespace(), artifact.name(), artifact.version(), ArtifactContext.JS_MODEL);
        ac.setIgnoreDependencies(true);
        ac.setThrowErrorIfMissing(true);
        ArtifactResult lmar = getContext().getRepositoryManager().getArtifactResult(ac);
        js = lmar.artifact();
    }
    if (module instanceof JsonModule) {
        if (((JsonModule) module).getModel() != null) {
            return;
        }
        if (js.exists() && js.isFile() && js.canRead() && js.getName().endsWith(ArtifactContext.JS_MODEL)) {
            if (JsModuleManagerFactory.isVerbose()) {
                System.out.println("Loading model from " + js);
            }
            Map<String, Object> model = loadJsonModel(js);
            if (model == null) {
                if (JsModuleManagerFactory.isVerbose()) {
                    System.out.println("Model not found in " + js);
                }
            } else {
                loadModuleFromMap(artifact, module, dependencyTree, phasedUnitsOfDependencies, forCompiledModule, model);
                return;
            }
        }
        if ("npm".equals(artifact.namespace())) {
            try {
                final File root = ((AbstractRepository) artifact.repository()).getRoot().getContent(File.class);
                final String npmPath = artifact.artifact().getAbsolutePath().replace(File.separator, "/");
                ((JsonModule) module).setNpmPath(npmPath.substring(root.getAbsolutePath().length() + 1));
                module.setJsMajor(Versions.JS_BINARY_MAJOR_VERSION);
                module.setJsMinor(Versions.JS_BINARY_MINOR_VERSION);
            } catch (IOException ex) {
                ex.printStackTrace();
            }
            return;
        }
    }
    super.resolveModule(artifact, module, moduleImport, dependencyTree, phasedUnitsOfDependencies, forCompiledModule);
}
Also used : ArtifactContext(org.eclipse.ceylon.cmr.api.ArtifactContext) IOException(java.io.IOException) File(java.io.File) ArtifactResult(org.eclipse.ceylon.model.cmr.ArtifactResult)

Aggregations

ArtifactContext (org.eclipse.ceylon.cmr.api.ArtifactContext)62 File (java.io.File)33 ArtifactResult (org.eclipse.ceylon.model.cmr.ArtifactResult)25 RepositoryManager (org.eclipse.ceylon.cmr.api.RepositoryManager)22 Test (org.junit.Test)20 SimpleRepositoryManager (org.eclipse.ceylon.cmr.impl.SimpleRepositoryManager)17 IOException (java.io.IOException)13 CmrRepository (org.eclipse.ceylon.cmr.api.CmrRepository)9 MavenArtifactContext (org.eclipse.ceylon.cmr.api.MavenArtifactContext)7 ModuleSpec (org.eclipse.ceylon.common.ModuleSpec)6 ArrayList (java.util.ArrayList)5 RepositoryManagerBuilder (org.eclipse.ceylon.cmr.api.RepositoryManagerBuilder)5 Manifest (java.util.jar.Manifest)4 ModuleVersionDetails (org.eclipse.ceylon.cmr.api.ModuleVersionDetails)4 Module (org.eclipse.ceylon.model.typechecker.model.Module)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 FileWriter (java.io.FileWriter)3 HashMap (java.util.HashMap)3 HashSet (java.util.HashSet)3 Map (java.util.Map)3