Search in sources :

Example 16 with ArtifactContext

use of org.eclipse.ceylon.cmr.api.ArtifactContext in project ceylon by eclipse.

the class ModuleSourceMapper method resolveModule.

public void resolveModule(ArtifactResult artifact, Module module, ModuleImport moduleImport, LinkedList<Module> dependencyTree, List<PhasedUnits> phasedUnitsOfDependencies, boolean forCompiledModule) {
    // This implementation relies on the ability to read the model from source
    // the compiler for example subclasses this to read lazily and from the compiled model
    ArtifactContext artifactContext = new ArtifactContext(null, module.getNameAsString(), module.getVersion(), ArtifactContext.SRC);
    RepositoryManager repositoryManager = context.getRepositoryManager();
    Exception exceptionOnGetArtifact = null;
    ArtifactResult sourceArtifact = null;
    try {
        sourceArtifact = repositoryManager.getArtifactResult(artifactContext);
    } catch (Exception e) {
        exceptionOnGetArtifact = e;
    }
    if (sourceArtifact == null) {
        ModuleHelper.buildErrorOnMissingArtifact(artifactContext, module, moduleImport, dependencyTree, exceptionOnGetArtifact, this, true);
    } else {
        PhasedUnits modulePhasedUnits = createPhasedUnits();
        ClosableVirtualFile virtualArtifact = null;
        try {
            virtualArtifact = context.getVfs().getFromZipFile(sourceArtifact.artifact());
            modulePhasedUnits.parseUnit(virtualArtifact);
            // populate module.getDependencies()
            modulePhasedUnits.visitModules();
            addToPhasedUnitsOfDependencies(modulePhasedUnits, phasedUnitsOfDependencies, module);
        } catch (Exception e) {
            StringBuilder error = new StringBuilder("unable to read source artifact for ");
            error.append(artifactContext.toString());
            error.append("\ndue to connection error: ").append(e.getMessage());
            attachErrorToDependencyDeclaration(moduleImport, dependencyTree, error.toString(), true);
        } finally {
            if (virtualArtifact != null) {
                virtualArtifact.close();
            }
        }
    }
}
Also used : ClosableVirtualFile(org.eclipse.ceylon.compiler.typechecker.io.ClosableVirtualFile) PhasedUnits(org.eclipse.ceylon.compiler.typechecker.context.PhasedUnits) ArtifactContext(org.eclipse.ceylon.cmr.api.ArtifactContext) RepositoryManager(org.eclipse.ceylon.cmr.api.RepositoryManager) ArtifactResult(org.eclipse.ceylon.model.cmr.ArtifactResult)

Example 17 with ArtifactContext

use of org.eclipse.ceylon.cmr.api.ArtifactContext in project ceylon by eclipse.

the class ModuleValidator method resolveModuleIfRequired.

private void resolveModuleIfRequired(Module module, boolean forCompiledModule, ModuleImport moduleImport, ImportDepth importDepth, LinkedList<Module> dependencyTree, Map<Module, ArtifactResult> alreadySearchedArtifacts) {
    if (!module.isAvailable()) {
        ArtifactResult artifact = null;
        boolean firstTime;
        if (alreadySearchedArtifacts.containsKey(module)) {
            artifact = alreadySearchedArtifacts.get(module);
            firstTime = false;
        } else {
            // try and load the module from the repository
            RepositoryManager repositoryManager = context.getRepositoryManager();
            if (repositoryManager.isValidNamespace(moduleImport.getNamespace())) {
                Exception exceptionOnGetArtifact = null;
                Iterable<String> searchedArtifactExtensions = moduleManager.getSearchedArtifactExtensions();
                ArtifactContext artifactContext = new ArtifactContext(moduleImport.getNamespace(), module.getNameAsString(), module.getVersion(), getArtifactSuffixes(searchedArtifactExtensions));
                listener.retrievingModuleArtifact(module, artifactContext);
                try {
                    artifact = repositoryManager.getArtifactResult(artifactContext);
                } catch (Exception e) {
                    exceptionOnGetArtifact = catchIfPossible(e);
                }
                if (artifact == null) {
                    boolean error = true;
                    if (ModuleUtil.isMavenModule(module.getNameAsString()) && !dependencyTree.isEmpty() && ModuleUtil.isMavenModule(dependencyTree.peekLast().getNameAsString()))
                        error = false;
                    // not there => error
                    ModuleHelper.buildErrorOnMissingArtifact(artifactContext, module, moduleImport, dependencyTree, exceptionOnGetArtifact, moduleManagerUtil, error);
                    listener.retrievingModuleArtifactFailed(module, artifactContext);
                } else {
                    listener.retrievingModuleArtifactSuccess(module, artifact);
                }
            } else {
                StringBuilder msg = new StringBuilder().append("unknown import namespace: '").append(moduleImport.getNamespace()).append("' should be one of ");
                TreeSet<String> namespaces = new TreeSet<String>();
                for (CmrRepository repo : repositoryManager.getRepositories()) {
                    namespaces.add(repo.getNamespace());
                }
                boolean first = true;
                for (String namespace : namespaces) {
                    if (first) {
                        first = false;
                    } else {
                        msg.append(", ");
                    }
                    msg.append("'").append(namespace).append("'");
                }
                // if (!MavenRepository.NAMESPACE.equals(moduleImport.getNamespace())) {
                // msg += " (if this is a Maven import make sure to add a 'maven:' prefix)";
                // }
                moduleManagerUtil.attachErrorToDependencyDeclaration(moduleImport, dependencyTree, msg.toString(), true);
            }
            alreadySearchedArtifacts.put(module, artifact);
            firstTime = true;
        }
        // a compiled module, then it MUST resolve it and make it available, so do try in this case.
        if (artifact != null && (firstTime || forCompiledModule)) {
            // parse module units and build module dependency and carry on
            listener.resolvingModuleArtifact(module, artifact);
            Module moduleOverride = moduleManager.overridesModule(artifact, module, moduleImport);
            if (moduleOverride != null) {
                if (importDepth.equals(ImportDepth.First)) {
                    moduleManagerUtil.attachErrorToDependencyDeclaration(moduleImport, dependencyTree, "project source module import is overridden in module overrides file: '" + moduleOverride.getNameAsString() + "/" + moduleOverride.getVersion() + "' overrides '" + module.getNameAsString() + "/" + module.getVersion() + "'", false);
                }
                module = moduleOverride;
            }
            moduleManagerUtil.resolveModule(artifact, module, moduleImport, dependencyTree, phasedUnitsOfDependencies, forCompiledModule);
        }
    }
}
Also used : TreeSet(java.util.TreeSet) RepositoryManager(org.eclipse.ceylon.cmr.api.RepositoryManager) ArtifactContext(org.eclipse.ceylon.cmr.api.ArtifactContext) CmrRepository(org.eclipse.ceylon.cmr.api.CmrRepository) ImportModule(org.eclipse.ceylon.compiler.typechecker.tree.Tree.ImportModule) Module(org.eclipse.ceylon.model.typechecker.model.Module) ArtifactResult(org.eclipse.ceylon.model.cmr.ArtifactResult)

Example 18 with ArtifactContext

use of org.eclipse.ceylon.cmr.api.ArtifactContext in project ceylon by eclipse.

the class CallbackTestCase method testThreadLocal.

@Test
public void testThreadLocal() throws Exception {
    TestArtifactCallback callback = new TestArtifactCallback();
    ArtifactCallbackStream.setCallback(callback);
    try {
        ArtifactContext context = new ArtifactContext(null, name, version);
        doTest(context, callback);
    } finally {
        ArtifactCallbackStream.setCallback(null);
    }
}
Also used : ArtifactContext(org.eclipse.ceylon.cmr.api.ArtifactContext) Test(org.junit.Test)

Example 19 with ArtifactContext

use of org.eclipse.ceylon.cmr.api.ArtifactContext in project ceylon by eclipse.

the class CallbackTestCase method testErr.

@Test
public void testErr() throws Exception {
    TestArtifactCallback callback = new TestArtifactCallback();
    callback.ts = String.valueOf(System.currentTimeMillis());
    ArtifactContext context = new ArtifactContext(null, name, version);
    context.setCallback(callback);
    doTest(context, callback);
}
Also used : ArtifactContext(org.eclipse.ceylon.cmr.api.ArtifactContext) Test(org.junit.Test)

Example 20 with ArtifactContext

use of org.eclipse.ceylon.cmr.api.ArtifactContext in project ceylon by eclipse.

the class SmokeTestCase method testInnerProperties.

@Test
public void testInnerProperties() throws Exception {
    RepositoryManager manager = getRepositoryManager();
    ArtifactContext context = new ArtifactContext(null, "org.mood.lw", "1.0", ArtifactContext.JAR);
    try {
        manager.putArtifact(context, mockJar("META-INF/jbossmodules/org/mood/lw/1.0/module.properties", "moduletest=0.1\n".getBytes()));
        File file = manager.getArtifact(context);
        Assert.assertNotNull(file);
    } finally {
        manager.removeArtifact(context);
    }
}
Also used : RepositoryManager(org.eclipse.ceylon.cmr.api.RepositoryManager) SimpleRepositoryManager(org.eclipse.ceylon.cmr.impl.SimpleRepositoryManager) ArtifactContext(org.eclipse.ceylon.cmr.api.ArtifactContext) File(java.io.File) Test(org.junit.Test)

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