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