use of org.eclipse.ceylon.cmr.api.ArtifactContext in project ceylon by eclipse.
the class CeylonP2Tool method collectModules.
private void collectModules(RepositoryManager repoManager, String name, String version, Map<String, ModuleInfo> allModules) throws IOException {
// ignore JDK dependencies
if (skipModule(name, version))
return;
String key = name + "/" + version;
if (allModules.containsKey(key))
return;
ArtifactResult artifact = null;
try {
artifact = repoManager.getArtifactResult(new ArtifactContext(null, name, version, ArtifactContext.CAR, ArtifactContext.JAR));
} catch (RuntimeException e) {
if (e.getCause() instanceof IOException) {
getLogger().warning(e.toString());
} else {
throw e;
}
}
File artifactJar = null;
if (artifact == null) {
// try to find it in the plugins folder
File pluginJar = new File(out, "plugins/" + name + "_" + version + ".jar");
if (pluginJar.exists()) {
artifactJar = pluginJar;
}
} else {
artifactJar = artifact.artifact();
}
allModules.put(key, artifactJar != null ? new ModuleInfo(this, name, version, artifactJar) : null);
if (artifact == null) {
errorMsg("module.not.found", name + "/" + version, out + "/plugins");
} else {
msg("module.found", name + "/" + version, artifact != null ? artifact.repositoryDisplayString() : artifactJar.getPath());
newline();
for (ArtifactResult dep : artifact.dependencies()) {
// FIXME: deal with optionals
collectModules(repoManager, dep.name(), dep.version(), allModules);
}
}
}
use of org.eclipse.ceylon.cmr.api.ArtifactContext in project ceylon by eclipse.
the class AbstractNodeRepositoryManager method downloadZipped.
private ArtifactResult downloadZipped(Node node, ArtifactContext context) {
ArtifactContext zippedContext = context.getZipContext();
ArtifactResult zipResult = getArtifactResult(zippedContext);
if (zipResult != null) {
String zipName = zipResult.artifact().getName();
File unzippedFolder = new File(zipResult.artifact().getParentFile(), zipName.substring(0, zipName.length() - 4));
try {
IOUtils.extractArchive(zipResult.artifact(), unzippedFolder);
} catch (IOException e) {
throw new RepositoryException("Failed to unzip folder downloaded from Herd: " + zipResult.artifact(), e);
}
return new FileArtifactResult(zipResult.repository(), this, zipResult.name(), zipResult.version(), unzippedFolder, zipResult.repositoryDisplayString());
} else {
return null;
}
}
use of org.eclipse.ceylon.cmr.api.ArtifactContext in project ceylon by eclipse.
the class AbstractNodeRepositoryManager method uploadZipped.
private void uploadZipped(Node parent, ArtifactContext context, File folder) {
File zippedFolder = null;
try {
try {
zippedFolder = IOUtils.zipFolder(folder);
} catch (IOException e) {
throw new RepositoryException("Failed to zip folder for upload to Herd: " + folder, e);
}
ArtifactContext zippedContext = context.getZipContext();
putArtifact(zippedContext, zippedFolder);
ShaSigner.signArtifact(this, zippedContext, zippedFolder, log);
} finally {
if (zippedFolder != null) {
FileUtil.deleteQuietly(zippedFolder);
}
}
}
use of org.eclipse.ceylon.cmr.api.ArtifactContext in project ceylon by eclipse.
the class LegacyImporter method addTransitiveDependenciesClasses.
private void addTransitiveDependenciesClasses(ArtifactResult result, Set<String> classes, Set<String> visited, ModuleDependencyInfo originalDependency) throws Exception {
log.info("Visiting transitive dependencies for " + result.name() + "/" + result.version());
try {
for (ArtifactResult dep : result.dependencies()) {
// Skip Test modules
if (dep.moduleScope() == ModuleScope.TEST)
continue;
// skip non-shared dependencies
if (dep.exported()) {
// skip already-visited dependencies
if (!visited.add(dep.name() + "/" + dep.version()))
continue;
/* FIXME: this is just wrong:
* - We should check for JDK
* - We should report errors with transitive paths
* - Finding a dep transitively puts it in the visited set and prevents toplevel imports from
* being checked
*/
// skip JDK checks
String name = dep.name();
if (JDKUtils.jdk.providesVersion(JDK.JDK9.version)) {
// unalias jdk7-8 module names if we're running on jdk9+
name = JDKUtils.getJava9ModuleName(name, dep.version());
}
if (jdkProvider.isJDKModule(name))
continue;
log.info(" dep " + dep.name() + "/" + dep.version());
// look it up
ArtifactContext context = new ArtifactContext(dep.namespace(), dep.name(), dep.version(), ArtifactContext.CAR, ArtifactContext.JAR);
ArtifactResult depResult = lookupRepoman.getArtifactResult(context);
File artifact = depResult != null ? depResult.artifact() : null;
log.info("Result: " + depResult);
if (artifact != null && artifact.exists()) {
try {
Set<String> importedClasses = JarUtils.gatherClassnamesFromJar(artifact);
classes.addAll(importedClasses);
addTransitiveDependenciesClasses(depResult, classes, visited, originalDependency);
} catch (IOException x) {
feedback.dependency(DependencyResults.DEP_TRANSITIVE_ERROR, originalDependency);
hasErrors = true;
}
} else {
feedback.dependency(DependencyResults.DEP_TRANSITIVE_ERROR, originalDependency);
hasErrors = true;
}
}
}
} catch (Throwable t) {
t.printStackTrace();
}
}
use of org.eclipse.ceylon.cmr.api.ArtifactContext in project ceylon by eclipse.
the class LegacyImporter method publish.
/**
* Publishes the JAR and accompanying module descriptor (if defined) to the
* <code>outputRepository</code> specified in the constructor using the given
* module name and version.
*/
public LegacyImporter publish() {
ArtifactContext context = new ArtifactContext(null, moduleName, moduleVersion, ArtifactContext.JAR);
context.setForceOperation(true);
outRepoman.putArtifact(context, jarFile);
ShaSigner.signArtifact(outRepoman, context, jarFile, log);
if (sourceJarFile != null) {
ArtifactContext sourceJarContext = new ArtifactContext(null, moduleName, moduleVersion, ArtifactContext.LEGACY_SRC);
context.setForceOperation(true);
outRepoman.putArtifact(sourceJarContext, sourceJarFile);
ShaSigner.signArtifact(outRepoman, sourceJarContext, sourceJarFile, log);
}
if (descriptorFile != null) {
ArtifactContext descriptorContext = null;
if (descriptorFile.toString().toLowerCase().endsWith(".xml")) {
descriptorContext = new ArtifactContext(null, moduleName, moduleVersion, ArtifactContext.MODULE_XML);
} else if (descriptorFile.toString().toLowerCase().endsWith(".properties")) {
descriptorContext = new ArtifactContext(null, moduleName, moduleVersion, ArtifactContext.MODULE_PROPERTIES);
}
descriptorContext.setForceOperation(true);
outRepoman.putArtifact(descriptorContext, descriptorFile);
ShaSigner.signArtifact(outRepoman, descriptorContext, descriptorFile, log);
}
return this;
}
Aggregations