Search in sources :

Example 31 with CmrRepository

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

the class AetherTestCase method testScopes.

@Test
public void testScopes() throws Throwable {
    CmrRepository repository = AetherRepository.createRepository(log, false, 60000);
    RepositoryManager manager = new SimpleRepositoryManager(repository, log);
    ArtifactResult artifact = manager.getArtifactResult(MavenArtifactContext.NAMESPACE, "org.jboss.xnio:xnio-api", "3.1.0.Beta7");
    File file = null;
    try {
        Assert.assertNotNull(artifact);
        file = artifact.artifact();
        Assert.assertTrue(file.exists());
        // http://search.maven.org/remotecontent?filepath=org/jboss/xnio/xnio-api/3.1.0.Beta7/xnio-api-3.1.0.Beta7.pom
        // there should be org.jboss.logging:jboss-logging
        Assert.assertTrue(artifact.dependencies().size() > 0);
    } finally {
        if (file != null && file.exists()) {
            // delete this one
            Assert.assertTrue(file.delete());
        }
    }
}
Also used : SimpleRepositoryManager(org.eclipse.ceylon.cmr.impl.SimpleRepositoryManager) RepositoryManager(org.eclipse.ceylon.cmr.api.RepositoryManager) SimpleRepositoryManager(org.eclipse.ceylon.cmr.impl.SimpleRepositoryManager) CmrRepository(org.eclipse.ceylon.cmr.api.CmrRepository) File(java.io.File) ArtifactResult(org.eclipse.ceylon.model.cmr.ArtifactResult) Test(org.junit.Test)

Example 32 with CmrRepository

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

the class AetherTestCase method testAetherWithExternalSettings.

@Test
public void testAetherWithExternalSettings() throws Throwable {
    CmrRepository repository = createAetherRepository();
    RepositoryManager manager = new SimpleRepositoryManager(repository, log);
    ArtifactResult result = manager.getArtifactResult(MavenArtifactContext.NAMESPACE, "org.apache.camel:camel-core", "2.9.2");
    Assert.assertNotNull(result);
    Assert.assertEquals(result.name(), "org.apache.camel:camel-core");
    File artifact = result.artifact();
    boolean exists = false;
    try {
        Assert.assertNotNull(artifact);
        Assert.assertTrue(artifact.exists());
        exists = true;
        List<ArtifactResult> deps = result.dependencies();
        log.debug("deps = " + deps);
        List<ArtifactResult> compileDeps = new ArrayList<>(deps.size());
        for (ArtifactResult dep : deps) {
            if (dep.moduleScope() == ModuleScope.COMPILE || dep.moduleScope() == ModuleScope.PROVIDED)
                compileDeps.add(dep);
        }
        Assert.assertEquals(2, compileDeps.size());
        Assert.assertEquals("org.slf4j:slf4j-api", compileDeps.get(0).name());
        Assert.assertEquals("1.6.1", compileDeps.get(0).version());
        Assert.assertEquals("org.osgi:org.osgi.core", compileDeps.get(1).name());
        Assert.assertEquals("4.2.0", compileDeps.get(1).version());
        Assert.assertTrue(compileDeps.get(1).optional());
        log.debug("deps = " + compileDeps);
    } finally {
        if (exists) {
            // delete this one
            Assert.assertTrue(artifact.delete());
        }
    }
}
Also used : SimpleRepositoryManager(org.eclipse.ceylon.cmr.impl.SimpleRepositoryManager) ArrayList(java.util.ArrayList) RepositoryManager(org.eclipse.ceylon.cmr.api.RepositoryManager) SimpleRepositoryManager(org.eclipse.ceylon.cmr.impl.SimpleRepositoryManager) CmrRepository(org.eclipse.ceylon.cmr.api.CmrRepository) File(java.io.File) ArtifactResult(org.eclipse.ceylon.model.cmr.ArtifactResult) Test(org.junit.Test)

Example 33 with CmrRepository

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

the class AetherTestCase method testWithSources.

@Test
public void testWithSources() throws Throwable {
    CmrRepository repository = AetherRepository.createRepository(log, false, 60000);
    RepositoryManager manager = new SimpleRepositoryManager(repository, log);
    ArtifactResult result = manager.getArtifactResult(new ArtifactContext(MavenRepository.NAMESPACE, "org.slf4j:slf4j-api", "1.6.4", ArtifactContext.LEGACY_SRC));
    Assert.assertNotNull(result);
    File artifact = result.artifact();
    boolean exists = false;
    try {
        Assert.assertNotNull(artifact);
        Assert.assertTrue(artifact.exists());
        exists = true;
    } finally {
        if (exists) {
            // delete this one
            Assert.assertTrue(artifact.delete());
        }
    }
}
Also used : SimpleRepositoryManager(org.eclipse.ceylon.cmr.impl.SimpleRepositoryManager) RepositoryManager(org.eclipse.ceylon.cmr.api.RepositoryManager) SimpleRepositoryManager(org.eclipse.ceylon.cmr.impl.SimpleRepositoryManager) MavenArtifactContext(org.eclipse.ceylon.cmr.api.MavenArtifactContext) ArtifactContext(org.eclipse.ceylon.cmr.api.ArtifactContext) CmrRepository(org.eclipse.ceylon.cmr.api.CmrRepository) File(java.io.File) ArtifactResult(org.eclipse.ceylon.model.cmr.ArtifactResult) Test(org.junit.Test)

Example 34 with CmrRepository

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

the class ResolverTestCase method doTest.

private void doTest(Tester tester) throws Exception {
    CmrRepository repository = createAetherRepository();
    RepositoryManager manager = new SimpleRepositoryManager(repository, log);
    ArtifactResult result = manager.getArtifactResult(MavenArtifactContext.NAMESPACE, "org.apache.camel:camel-core", "2.9.2");
    Assert.assertNotNull(result);
    Assert.assertEquals(result.name(), "org.apache.camel:camel-core");
    File artifact = result.artifact();
    boolean exists = false;
    try {
        Assert.assertNotNull(artifact);
        Assert.assertTrue(artifact.exists());
        exists = true;
        tester.run(repository, artifact);
    } finally {
        if (exists) {
            // delete this one
            Assert.assertTrue(artifact.delete());
        }
    }
}
Also used : SimpleRepositoryManager(org.eclipse.ceylon.cmr.impl.SimpleRepositoryManager) SimpleRepositoryManager(org.eclipse.ceylon.cmr.impl.SimpleRepositoryManager) RepositoryManager(org.eclipse.ceylon.cmr.api.RepositoryManager) CmrRepository(org.eclipse.ceylon.cmr.api.CmrRepository) File(java.io.File) ArtifactResult(org.eclipse.ceylon.model.cmr.ArtifactResult) AbstractArtifactResult(org.eclipse.ceylon.cmr.impl.AbstractArtifactResult)

Example 35 with CmrRepository

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

the class RootRepositoryManager method artifactNotFound.

@Override
protected ArtifactResult artifactNotFound(ArtifactContext context) throws RepositoryException {
    boolean hasRemote = false;
    StringBuilder reps = new StringBuilder();
    for (CmrRepository rep : getRepositories()) {
        if (rep.getRoot().isRemote() && !isOffline(rep)) {
            hasRemote = true;
            reps.append(rep.getDisplayString());
            reps.append('\n');
        }
    }
    if (hasRemote && cache != null) {
        // Create a .missing file in the cache to mark that we tried to locate the file but it didn't exist
        Node parent = cache.findParent(context);
        if (parent != null) {
            context.toNode(parent);
            try {
                // fileContentStore cannot be null if we have a cache
                File parentDir = fileContentStore.getFile(parent);
                String[] names = cache.getArtifactNames(context);
                File missingFile = new File(parentDir, names[0].concat(MISSING));
                if (!missingFile.exists()) {
                    if (context.getSearchRepository() == cache) {
                        ArtifactContext unpreferred = new ArtifactContext(context.getNamespace(), context.getName(), context.getVersion(), context.getSuffixes());
                        unpreferred.copySettingsFrom(context);
                        return getArtifactResult(unpreferred);
                    } else {
                        FileUtil.mkdirs(parentDir);
                        try (FileWriter writer = new FileWriter(missingFile, false)) {
                            // We write the list of remote repositories we tried
                            // This is not currently used but might be useful in the future
                            writer.write(reps.toString());
                        } catch (IOException e) {
                            log.error(e.toString());
                        }
                    }
                }
            } finally {
                ArtifactContext.removeNode(parent);
            }
        }
    }
    return super.artifactNotFound(context);
}
Also used : OpenNode(org.eclipse.ceylon.cmr.spi.OpenNode) Node(org.eclipse.ceylon.cmr.spi.Node) FileWriter(java.io.FileWriter) ArtifactContext(org.eclipse.ceylon.cmr.api.ArtifactContext) IOException(java.io.IOException) CmrRepository(org.eclipse.ceylon.cmr.api.CmrRepository) File(java.io.File)

Aggregations

CmrRepository (org.eclipse.ceylon.cmr.api.CmrRepository)43 File (java.io.File)26 RepositoryManager (org.eclipse.ceylon.cmr.api.RepositoryManager)26 SimpleRepositoryManager (org.eclipse.ceylon.cmr.impl.SimpleRepositoryManager)24 Test (org.junit.Test)24 ArtifactResult (org.eclipse.ceylon.model.cmr.ArtifactResult)15 ArtifactContext (org.eclipse.ceylon.cmr.api.ArtifactContext)9 RepositoryManagerBuilder (org.eclipse.ceylon.cmr.api.RepositoryManagerBuilder)8 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)5 OpenNode (org.eclipse.ceylon.cmr.spi.OpenNode)5 DefaultRepository (org.eclipse.ceylon.cmr.impl.DefaultRepository)4 Node (org.eclipse.ceylon.cmr.spi.Node)3 IOException (java.io.IOException)2 URL (java.net.URL)2 TreeSet (java.util.TreeSet)2 MavenArtifactContext (org.eclipse.ceylon.cmr.api.MavenArtifactContext)2 ModuleSearchResult (org.eclipse.ceylon.cmr.api.ModuleSearchResult)2 ModuleVersionDetails (org.eclipse.ceylon.cmr.api.ModuleVersionDetails)2 ModuleVersionQuery (org.eclipse.ceylon.cmr.api.ModuleVersionQuery)2