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;
}
Aggregations