Search in sources :

Example 1 with ArtifactCreator

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

the class JsCompiler method finish.

/**
 * Closes all output writers and puts resulting artifacts in the output repo.
 */
protected int finish() throws IOException {
    int result = 0;
    String outDir = CeylonUtils.resolveRepoUrl(opts.getOutRepo());
    if (!isURL(outDir)) {
        File root = new File(outDir);
        if (root.exists()) {
            if (!(root.isDirectory() && root.canWrite())) {
                logger.error("Cannot write to " + root + ". Stop.");
                result = 1;
            }
        } else {
            if (!FileUtil.mkdirs(root)) {
                logger.error("Cannot create " + root + ". Stop.");
                result = 1;
            }
        }
    }
    for (Map.Entry<Module, JsOutput> entry : output.entrySet()) {
        JsOutput jsout = entry.getValue();
        if (!compilingLanguageModule) {
            jsout.publishUnsharedDeclarations(names);
        }
        if (opts.isModulify()) {
            jsout.closeWrapper();
        }
        String moduleName = entry.getKey().getNameAsString();
        String moduleVersion = entry.getKey().getVersion();
        if (opts.getDiagnosticListener() != null)
            opts.getDiagnosticListener().moduleCompiled(moduleName, moduleVersion);
        // Create the JS file
        final File jsart = jsout.close();
        final File modart = jsout.getModelFile();
        if (entry.getKey().isDefaultModule()) {
            logger.info("Created module " + moduleName);
        } else if (!compilingLanguageModule) {
            logger.info("Created module " + moduleName + "/" + moduleVersion);
        }
        if (compilingLanguageModule) {
            ArtifactContext artifact = new ArtifactContext(null, "delete", "me", ArtifactContext.JS);
            artifact.setForceOperation(true);
            outRepo.putArtifact(artifact, jsart);
        } else {
            final ArtifactContext artifact = new ArtifactContext(null, moduleName, moduleVersion, ArtifactContext.JS);
            artifact.setForceOperation(true);
            outRepo.putArtifact(artifact, jsart);
            final ArtifactContext martifact = new ArtifactContext(null, moduleName, moduleVersion, ArtifactContext.JS_MODEL);
            martifact.setForceOperation(true);
            outRepo.putArtifact(martifact, modart);
            // js file signature
            ShaSigner.signArtifact(outRepo, artifact, jsart, logger);
            ShaSigner.signArtifact(outRepo, martifact, modart, logger);
            // Create the src archive
            if (opts.isGenerateSourceArchive()) {
                ArtifactCreator sac = CeylonUtils.makeSourceArtifactCreator(outRepo, opts.getSrcDirs(), moduleName, moduleVersion, opts.hasVerboseFlag("cmr"), logger);
                sac.copy(FileUtil.filesToPathList(jsout.getSources()));
            }
            if (resFiles != null && !resFiles.isEmpty()) {
                ArtifactCreator sac = CeylonUtils.makeResourceArtifactCreator(outRepo, opts.getSrcDirs(), opts.getResourceDirs(), opts.getResourceRootName(), moduleName, moduleVersion, opts.hasVerboseFlag("cmr"), logger);
                sac.copy(FileUtil.filesToPathList(filterForModule(resFiles, opts.getResourceDirs(), moduleName)));
            }
            if (!entry.getKey().isDefaultModule()) {
                String npmdesc = new NpmDescriptorGenerator(entry.getKey(), opts.isGenerateSourceArchive(), resFiles != null && !resFiles.isEmpty()).generateDescriptor();
                File npmfile = File.createTempFile("npm", "json");
                try {
                    try (FileWriter fw = new FileWriter(npmfile)) {
                        fw.write(npmdesc);
                    }
                    final ArtifactContext npmArtifact = new ArtifactContext(null, moduleName, moduleVersion, ArtifactContext.NPM_DESCRIPTOR);
                    npmArtifact.setForceOperation(true);
                    outRepo.putArtifact(npmArtifact, npmfile);
                } finally {
                    npmfile.delete();
                }
            }
        }
        FileUtil.deleteQuietly(jsart);
        if (modart != null) {
            FileUtil.deleteQuietly(modart);
        }
    }
    return result;
}
Also used : JsOutput(org.eclipse.ceylon.compiler.js.util.JsOutput) ArtifactCreator(org.eclipse.ceylon.cmr.api.ArtifactCreator) FileWriter(java.io.FileWriter) ArtifactContext(org.eclipse.ceylon.cmr.api.ArtifactContext) NpmDescriptorGenerator(org.eclipse.ceylon.compiler.js.util.NpmDescriptorGenerator) Module(org.eclipse.ceylon.model.typechecker.model.Module) VirtualFile(org.eclipse.ceylon.compiler.typechecker.io.VirtualFile) File(java.io.File) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

File (java.io.File)1 FileWriter (java.io.FileWriter)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ArtifactContext (org.eclipse.ceylon.cmr.api.ArtifactContext)1 ArtifactCreator (org.eclipse.ceylon.cmr.api.ArtifactCreator)1 JsOutput (org.eclipse.ceylon.compiler.js.util.JsOutput)1 NpmDescriptorGenerator (org.eclipse.ceylon.compiler.js.util.NpmDescriptorGenerator)1 VirtualFile (org.eclipse.ceylon.compiler.typechecker.io.VirtualFile)1 Module (org.eclipse.ceylon.model.typechecker.model.Module)1