Search in sources :

Example 11 with ArtifactResult

use of org.eclipse.ceylon.model.cmr.ArtifactResult 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 12 with ArtifactResult

use of org.eclipse.ceylon.model.cmr.ArtifactResult in project ceylon by eclipse.

the class AbstractNodeRepositoryManager method getArtifactResult.

public ArtifactResult getArtifactResult(ArtifactContext context) throws RepositoryException {
    context = applyOverrides(context);
    final Node node = getLeafNode(context);
    if (node != null) {
        String foundSuffix = ArtifactContext.getSuffixFromNode(node);
        // First handle all the artifact we didn't find
        ArtifactResult result = handleNotFound(context, foundSuffix);
        if (result != null) {
            // Seems we were able to find this artifact anyway, so lets return it
            return result;
        } else {
            // Now return the artifact we found
            // Make sure we'll have only one suffix
            context.setSuffixes(foundSuffix);
            if (ArtifactContext.isDirectoryName(node.getLabel())) {
                return getFolder(context, node);
            } else {
                return getArtifactResult(context, node);
            }
        }
    } else {
        return handleNotFound(context, null);
    }
}
Also used : OpenNode(org.eclipse.ceylon.cmr.spi.OpenNode) Node(org.eclipse.ceylon.cmr.spi.Node) ArtifactResult(org.eclipse.ceylon.model.cmr.ArtifactResult)

Example 13 with ArtifactResult

use of org.eclipse.ceylon.model.cmr.ArtifactResult in project ceylon by eclipse.

the class AbstractNodeRepositoryManager method handleNotFound.

private ArtifactResult handleNotFound(ArtifactContext context, String foundSuffix) {
    String[] suffixes = context.getSuffixes();
    for (String suffix : suffixes) {
        if (suffix.equals(foundSuffix)) {
            break;
        }
        // Make sure we'll have only one suffix
        context.setSuffixes(suffix);
        ArtifactResult result = artifactNotFound(context);
        if (result != null) {
            // Seems we were able to find this artifact anyway, so lets return it
            return result;
        }
    }
    // Restore the original suffixes
    context.setSuffixes(suffixes);
    return null;
}
Also used : ArtifactResult(org.eclipse.ceylon.model.cmr.ArtifactResult)

Example 14 with ArtifactResult

use of org.eclipse.ceylon.model.cmr.ArtifactResult in project ceylon by eclipse.

the class BytecodeUtils 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 && IOUtils.isZipFile(mod)) {
        return readModuleInformation(result.name(), result.artifact(), overrides);
    } else {
        return null;
    }
}
Also used : JarFile(java.util.jar.JarFile) File(java.io.File) ClassFile(org.eclipse.ceylon.langtools.classfile.ClassFile) ArtifactResult(org.eclipse.ceylon.model.cmr.ArtifactResult)

Example 15 with ArtifactResult

use of org.eclipse.ceylon.model.cmr.ArtifactResult 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)

Aggregations

ArtifactResult (org.eclipse.ceylon.model.cmr.ArtifactResult)79 File (java.io.File)40 RepositoryManager (org.eclipse.ceylon.cmr.api.RepositoryManager)32 SimpleRepositoryManager (org.eclipse.ceylon.cmr.impl.SimpleRepositoryManager)28 Test (org.junit.Test)28 ArtifactContext (org.eclipse.ceylon.cmr.api.ArtifactContext)25 IOException (java.io.IOException)17 ArrayList (java.util.ArrayList)17 CmrRepository (org.eclipse.ceylon.cmr.api.CmrRepository)15 ModuleSpec (org.eclipse.ceylon.common.ModuleSpec)13 FileOutputStream (java.io.FileOutputStream)6 InputStream (java.io.InputStream)5 ToolUsageError (org.eclipse.ceylon.common.tool.ToolUsageError)5 Module (org.eclipse.ceylon.model.typechecker.model.Module)5 LinkedList (java.util.LinkedList)4 List (java.util.List)4 ZipEntry (java.util.zip.ZipEntry)4 FileInputStream (java.io.FileInputStream)3 OutputStream (java.io.OutputStream)3 OutputStreamWriter (java.io.OutputStreamWriter)3