Search in sources :

Example 71 with ArtifactResult

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

the class CachingRepositoryManager method getArtifactResult.

protected ArtifactResult getArtifactResult(ArtifactContext context, Node node) throws RepositoryException {
    try {
        ArtifactResult result = caching.getArtifactResult(context);
        if (result != null) {
            boolean valid = false;
            File file = result.artifact();
            if (file.exists()) {
                long lm = node.getLastModified();
                valid = (lm == -1 || lm < file.lastModified());
            }
            if (valid) {
                return result;
            }
        }
        final boolean previous = context.isForceOperation();
        context.setForceOperation(true);
        try {
            // Make sure we'll have only one suffix
            context.setSuffixes(ArtifactContext.getSuffixFromNode(node));
            caching.putArtifact(context, node.getInputStream());
        } finally {
            context.setForceOperation(previous);
        }
        return caching.getArtifactResult(context);
    } catch (IOException e) {
        throw new RepositoryException(e);
    }
}
Also used : RepositoryException(org.eclipse.ceylon.model.cmr.RepositoryException) IOException(java.io.IOException) File(java.io.File) ArtifactResult(org.eclipse.ceylon.model.cmr.ArtifactResult)

Example 72 with ArtifactResult

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

the class JSUtils method resolve.

@Override
public ModuleInfo resolve(DependencyContext context, Overrides overrides) {
    if (context.ignoreInner()) {
        return null;
    }
    ArtifactResult result = context.result();
    File mod = result.artifact();
    if (mod != null && (mod.getName().toLowerCase().endsWith(ArtifactContext.JS_MODEL) || mod.getName().toLowerCase().endsWith(ArtifactContext.JS))) {
        return readModuleInformation(result.name(), mod, overrides);
    } else {
        return null;
    }
}
Also used : File(java.io.File) ArtifactResult(org.eclipse.ceylon.model.cmr.ArtifactResult)

Example 73 with ArtifactResult

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

the class CeylonRunJsTool method getArtifact.

// Make sure JS and JS_MODEL artifacts exist and try to obtain the RESOURCES as well
protected File getArtifact(RepositoryManager repoman, String modName, String modVersion, boolean optional) {
    final int colonIdx = modName.indexOf(':');
    String namespace = null;
    if (colonIdx > 0) {
        namespace = modName.substring(0, colonIdx);
        modName = modName.substring(colonIdx + 1);
    }
    ArtifactContext ac = new ArtifactContext(namespace, modName, modVersion, ArtifactContext.JS, ArtifactContext.JS_MODEL, ArtifactContext.RESOURCES);
    ac.setIgnoreDependencies(true);
    ac.setThrowErrorIfMissing(false);
    List<ArtifactResult> results = repoman.getArtifactResults(ac);
    ArtifactResult code = getArtifactType(results, ArtifactContext.JS);
    ArtifactResult model = getArtifactType(results, ArtifactContext.JS_MODEL);
    if (code == null || model == null) {
        if (optional) {
            return null;
        } else if (code != null && "npm".equals(namespace)) {
            return null;
        }
        throw new CeylonRunJsException("Cannot find module " + ModuleUtil.makeModuleName(modName, modVersion) + " in specified module repositories");
    }
    return model.artifact();
}
Also used : ArtifactContext(org.eclipse.ceylon.cmr.api.ArtifactContext) ArtifactResult(org.eclipse.ceylon.model.cmr.ArtifactResult)

Example 74 with ArtifactResult

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

the class CeylonJigsawTool method run.

@Override
public void run() throws Exception {
    for (ModuleSpec module : modules) {
        String moduleName = module.getName();
        String version = checkModuleVersionsOrShowSuggestions(moduleName, module.isVersioned() ? module.getVersion() : null, ModuleQuery.Type.JVM, Versions.JVM_BINARY_MAJOR_VERSION, Versions.JVM_BINARY_MINOR_VERSION, // JS binary but don't care since JVM
        null, // JS binary but don't care since JVM
        null, null);
        if (version == null)
            return;
        loadModule(null, moduleName, version);
        if (!force)
            errorOnConflictingModule(moduleName, version);
    }
    // force loading the module which contains the main
    loadModule(null, "org.eclipse.ceylon.java.main", Versions.CEYLON_VERSION_NUMBER);
    loader.resolve();
    if (!out.exists()) {
        if (!out.mkdirs()) {
            throw new ToolUsageError(Messages.msg(bundle, "jigsaw.folder.error", out));
        }
    }
    final List<ArtifactResult> staticMetamodelEntries = new ArrayList<>();
    loader.visitModules(new ModuleGraph.Visitor() {

        @Override
        public void visit(Module module) {
            if (module.artifact != null) {
                File file = module.artifact.artifact();
                try {
                    if (file != null) {
                        append(file.getAbsolutePath());
                        newline();
                        staticMetamodelEntries.add(module.artifact);
                        String name = file.getName();
                        if (name.endsWith(".car"))
                            name = name.substring(0, name.length() - 4) + ".jar";
                        Files.copy(file.toPath(), new File(out, name).toPath(), StandardCopyOption.REPLACE_EXISTING);
                    }
                } catch (IOException x) {
                    // lame
                    throw new RuntimeException(x);
                }
            }
        }
    });
    if (staticMetamodel) {
        JvmBackendUtil.writeStaticMetamodel(out, staticMetamodelEntries, jdkProvider);
    }
    flush();
}
Also used : ArrayList(java.util.ArrayList) IOException(java.io.IOException) ArtifactResult(org.eclipse.ceylon.model.cmr.ArtifactResult) ModuleSpec(org.eclipse.ceylon.common.ModuleSpec) ToolUsageError(org.eclipse.ceylon.common.tool.ToolUsageError) ModuleGraph(org.eclipse.ceylon.cmr.ceylon.loader.ModuleGraph) Module(org.eclipse.ceylon.cmr.ceylon.loader.ModuleGraph.Module) File(java.io.File)

Example 75 with ArtifactResult

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

the class CeylonMavenExportTool method run.

@Override
public void run() throws Exception {
    String firstModuleName = null;
    for (ModuleSpec module : modules) {
        String moduleName = module.getName();
        String version = checkModuleVersionsOrShowSuggestions(moduleName, module.isVersioned() ? module.getVersion() : null, ModuleQuery.Type.JVM, Versions.JVM_BINARY_MAJOR_VERSION, Versions.JVM_BINARY_MINOR_VERSION, // JS binary but don't care since JVM
        null, // JS binary but don't care since JVM
        null, null);
        if (version == null)
            return;
        if (firstModuleName == null) {
            firstModuleName = moduleName;
        }
        System.err.println("Doing " + module);
        loadModule(null, moduleName, version);
    }
    // FIXME: we probably want to allow exporting of multiple versions
    loader.resolve();
    final File outputFolder = applyCwd(out != null ? out : new File("maven-repository"));
    if (!outputFolder.exists()) {
        FileUtil.mkdirs(outputFolder);
    } else {
        // FIXME: error if regular file?
        // FIXME: or add, don't delete?
        FileUtil.delete(outputFolder);
    }
    final List<ArtifactResult> writtenModules = new LinkedList<>();
    final List<ArtifactResult> externalDependencies = new LinkedList<>();
    final Set<String> directImports = new HashSet<>();
    loader.visitModules(new ModuleGraph.Visitor() {

        @Override
        public void visit(ModuleGraph.Module module) {
            if (module.artifact == null || module.artifact.artifact() == null)
                return;
            // FIXME: skip Maven modules?
            if (forImport || forSdkImport) {
                if (forImport && !module.artifact.groupId().equals("org.ceylon-lang")) {
                    externalDependencies.add(module.artifact);
                    return;
                }
                if (forSdkImport && !directlyListed(module.artifact.name())) {
                    if (!module.artifact.groupId().equals("org.ceylon-lang")) {
                        externalDependencies.add(module.artifact);
                    }
                    return;
                }
                makeMavenImportFolder(module, outputFolder, directImports);
                writtenModules.add(module.artifact);
            } else
                makeMavenModule(module, outputFolder, directImports);
        }
    });
    if (forImport || forSdkImport) {
        makeMavenImportSpecialFolders(writtenModules, externalDependencies, outputFolder, directImports);
    }
    flush();
}
Also used : ModuleSpec(org.eclipse.ceylon.common.ModuleSpec) ModuleGraph(org.eclipse.ceylon.cmr.ceylon.loader.ModuleGraph) ZipFile(java.util.zip.ZipFile) File(java.io.File) LinkedList(java.util.LinkedList) ArtifactResult(org.eclipse.ceylon.model.cmr.ArtifactResult) HashSet(java.util.HashSet) Module(org.eclipse.ceylon.cmr.ceylon.loader.ModuleGraph.Module)

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