Search in sources :

Example 6 with ArtifactContext

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);
        }
    }
}
Also used : ArtifactContext(org.eclipse.ceylon.cmr.api.ArtifactContext) IOException(java.io.IOException) File(java.io.File) ArtifactResult(org.eclipse.ceylon.model.cmr.ArtifactResult)

Example 7 with ArtifactContext

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;
    }
}
Also used : ArtifactContext(org.eclipse.ceylon.cmr.api.ArtifactContext) RepositoryException(org.eclipse.ceylon.model.cmr.RepositoryException) IOException(java.io.IOException) File(java.io.File) ArtifactResult(org.eclipse.ceylon.model.cmr.ArtifactResult)

Example 8 with ArtifactContext

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);
        }
    }
}
Also used : RepositoryException(org.eclipse.ceylon.model.cmr.RepositoryException) ArtifactContext(org.eclipse.ceylon.cmr.api.ArtifactContext) IOException(java.io.IOException) File(java.io.File)

Example 9 with ArtifactContext

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();
    }
}
Also used : ArtifactContext(org.eclipse.ceylon.cmr.api.ArtifactContext) IOException(java.io.IOException) File(java.io.File) ArtifactResult(org.eclipse.ceylon.model.cmr.ArtifactResult)

Example 10 with ArtifactContext

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;
}
Also used : ArtifactContext(org.eclipse.ceylon.cmr.api.ArtifactContext)

Aggregations

ArtifactContext (org.eclipse.ceylon.cmr.api.ArtifactContext)62 File (java.io.File)33 ArtifactResult (org.eclipse.ceylon.model.cmr.ArtifactResult)25 RepositoryManager (org.eclipse.ceylon.cmr.api.RepositoryManager)22 Test (org.junit.Test)20 SimpleRepositoryManager (org.eclipse.ceylon.cmr.impl.SimpleRepositoryManager)17 IOException (java.io.IOException)13 CmrRepository (org.eclipse.ceylon.cmr.api.CmrRepository)9 MavenArtifactContext (org.eclipse.ceylon.cmr.api.MavenArtifactContext)7 ModuleSpec (org.eclipse.ceylon.common.ModuleSpec)6 ArrayList (java.util.ArrayList)5 RepositoryManagerBuilder (org.eclipse.ceylon.cmr.api.RepositoryManagerBuilder)5 Manifest (java.util.jar.Manifest)4 ModuleVersionDetails (org.eclipse.ceylon.cmr.api.ModuleVersionDetails)4 Module (org.eclipse.ceylon.model.typechecker.model.Module)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 FileWriter (java.io.FileWriter)3 HashMap (java.util.HashMap)3 HashSet (java.util.HashSet)3 Map (java.util.Map)3