Search in sources :

Example 41 with ArtifactResult

use of org.eclipse.ceylon.model.cmr.ArtifactResult 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 42 with ArtifactResult

use of org.eclipse.ceylon.model.cmr.ArtifactResult in project ceylon by eclipse.

the class JvmBackendUtil method finishLoadingModule.

private static void finishLoadingModule(ModuleSpec module, SortedSet<String> packages, List<ArtifactResult> dependencies, final List<String> dexEntries, StaticMetamodelLoader staticMetamodelLoader) {
    final SortedSet<String> packagesCopy = new TreeSet<>(packages);
    final List<ArtifactResult> dependenciesCopy = new ArrayList<>(dependencies);
    final String namespace = ModuleUtil.getNamespaceFromUri(module.getName());
    final String name = ModuleUtil.getModuleNameFromUri(module.getName());
    final String version = module.getVersion();
    ArtifactResult artifact = new ContentAwareArtifactResult() {

        @Override
        public VisibilityType visibilityType() {
            return VisibilityType.STRICT;
        }

        @Override
        public String version() {
            return version;
        }

        @Override
        public ArtifactResultType type() {
            return ArtifactResultType.OTHER;
        }

        @Override
        public String repositoryDisplayString() {
            return "Android repo";
        }

        @Override
        public Repository repository() {
            return null;
        }

        @Override
        public String namespace() {
            return namespace;
        }

        @Override
        public String name() {
            return name;
        }

        @Override
        public String artifactId() {
            return ModuleUtil.getMavenArtifactIdIfMavenModule(name);
        }

        @Override
        public String groupId() {
            return ModuleUtil.getMavenGroupIdIfMavenModule(name);
        }

        @Override
        public String classifier() {
            return ModuleUtil.getMavenClassifierIfMavenModule(name);
        }

        @Override
        public boolean exported() {
            return false;
        }

        @Override
        public boolean optional() {
            return false;
        }

        @Override
        public PathFilter filter() {
            return null;
        }

        @Override
        public List<ArtifactResult> dependencies() throws RepositoryException {
            return dependenciesCopy;
        }

        @Override
        public File artifact() throws RepositoryException {
            return null;
        }

        @Override
        public Collection<String> getPackages() {
            return packagesCopy;
        }

        @Override
        public List<String> getFileNames(String path) {
            return getAndroidFileNames(path);
        }

        private List<String> getAndroidFileNames(String path) {
            path = path + "/";
            List<String> ret = new LinkedList<>();
            for (String entry : dexEntries) {
                if (entry.startsWith(path)) {
                    String part = entry.substring(path.length());
                    // no folders and no subfolders
                    if (!part.isEmpty() && part.indexOf('/') == -1)
                        ret.add(entry);
                }
            }
            return ret;
        }

        @Override
        public Collection<String> getEntries() {
            return getAndroidEntries();
        }

        private Collection<String> getAndroidEntries() {
            List<String> ret = new LinkedList<>();
            for (String entry : dexEntries) {
                for (String pkg : packagesCopy) {
                    String path = pkg.replace('.', '/') + "/";
                    if (entry.startsWith(path)) {
                        ret.add(entry);
                        break;
                    }
                }
            }
            return ret;
        }

        @Override
        public byte[] getContents(String path) {
            // this is used by the metamodel module resource system
            try {
                return IOUtil.readStream(getClass().getClassLoader().getResourceAsStream(path));
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }

        @Override
        public URI getContentUri(String path) {
            try {
                return getClass().getClassLoader().getResource(path).toURI();
            } catch (URISyntaxException e) {
                throw new RuntimeException(e);
            }
        }

        @Override
        public String toString() {
            return "StaticMetamodelArtifact for module " + name + "/" + version;
        }

        @Override
        public ModuleScope moduleScope() {
            return ModuleScope.COMPILE;
        }

        @Override
        public List<Exclusion> getExclusions() {
            return null;
        }
    };
    staticMetamodelLoader.loadModule(module.getName(), module.getVersion(), artifact);
}
Also used : ArrayList(java.util.ArrayList) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) LinkedList(java.util.LinkedList) ArtifactResult(org.eclipse.ceylon.model.cmr.ArtifactResult) TreeSet(java.util.TreeSet) Exclusion(org.eclipse.ceylon.model.cmr.Exclusion)

Example 43 with ArtifactResult

use of org.eclipse.ceylon.model.cmr.ArtifactResult 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 44 with ArtifactResult

use of org.eclipse.ceylon.model.cmr.ArtifactResult 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)

Example 45 with ArtifactResult

use of org.eclipse.ceylon.model.cmr.ArtifactResult in project ceylon by eclipse.

the class RuntimeModuleManager method loadModuleImportsFromArtifact.

private void loadModuleImportsFromArtifact(Module module, ArtifactResult artifact) {
    for (ArtifactResult dep : artifact.dependencies()) {
        Module dependency = getOrCreateModule(splitModuleName(dep.name()), dep.version());
        ModuleImport depImport = findImport(module, dependency);
        // FIXME: exclude optionals and TEST deps?
        if (depImport == null) {
            ModuleImport moduleImport = new ModuleImport(dep.namespace(), dependency, dep.optional(), dep.exported(), Backend.Java);
            module.addImport(moduleImport);
        }
    }
}
Also used : ModuleImport(org.eclipse.ceylon.model.typechecker.model.ModuleImport) LazyModule(org.eclipse.ceylon.model.loader.model.LazyModule) ReflectionModule(org.eclipse.ceylon.model.loader.impl.reflect.model.ReflectionModule) Module(org.eclipse.ceylon.model.typechecker.model.Module) ArtifactResult(org.eclipse.ceylon.model.cmr.ArtifactResult)

Aggregations

ArtifactResult (org.eclipse.ceylon.model.cmr.ArtifactResult)79 File (java.io.File)40 RepositoryManager (org.eclipse.ceylon.cmr.api.RepositoryManager)32 SimpleRepositoryManager (org.eclipse.ceylon.cmr.impl.SimpleRepositoryManager)28 Test (org.junit.Test)28 ArtifactContext (org.eclipse.ceylon.cmr.api.ArtifactContext)25 IOException (java.io.IOException)17 ArrayList (java.util.ArrayList)17 CmrRepository (org.eclipse.ceylon.cmr.api.CmrRepository)15 ModuleSpec (org.eclipse.ceylon.common.ModuleSpec)13 FileOutputStream (java.io.FileOutputStream)6 InputStream (java.io.InputStream)5 ToolUsageError (org.eclipse.ceylon.common.tool.ToolUsageError)5 Module (org.eclipse.ceylon.model.typechecker.model.Module)5 LinkedList (java.util.LinkedList)4 List (java.util.List)4 ZipEntry (java.util.zip.ZipEntry)4 FileInputStream (java.io.FileInputStream)3 OutputStream (java.io.OutputStream)3 OutputStreamWriter (java.io.OutputStreamWriter)3