Search in sources :

Example 16 with CmrRepository

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

the class RepositoryBuilderImpl method buildRepository.

public CmrRepository[] buildRepository(String token, RepositoryBuilderConfig config) throws Exception {
    if (token == null)
        throw new IllegalArgumentException("Null repository");
    final String key = (token.startsWith("${") ? token.substring(2, token.length() - 1) : token);
    final String temp = SecurityActions.getProperty(key);
    if (temp != null)
        token = temp;
    for (RepositoryBuilder builder : builders) {
        CmrRepository[] repos = builder.buildRepository(token, config);
        if (repos != null) {
            return repos;
        }
    }
    return localBuilder.buildRepository(token, config);
}
Also used : RepositoryBuilder(org.eclipse.ceylon.cmr.api.RepositoryBuilder) CmrRepository(org.eclipse.ceylon.cmr.api.CmrRepository)

Example 17 with CmrRepository

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

the class CeylonRunJsTool method run.

@Override
public void run() throws Exception {
    // The timeout is to have enough time to start reading on the process streams
    if (systemRepo == null) {
        systemRepo = getCeylonRepo();
    }
    final boolean isDefault = ModuleUtil.isDefaultModule(module);
    String version;
    final String modname;
    if (isDefault) {
        modname = module;
        version = "";
    } else {
        version = ModuleUtil.moduleVersion(module);
        modname = ModuleUtil.moduleName(module);
    }
    compileFlags = processCompileFlags(compileFlags, DefaultToolOptions.getRunToolCompileFlags(org.eclipse.ceylon.common.Backend.JavaScript));
    version = checkModuleVersionsOrShowSuggestions(modname, version, ModuleQuery.Type.JS, // JVM binary but don't care since JS
    null, null, Versions.JS_BINARY_MAJOR_VERSION, Versions.JS_BINARY_MINOR_VERSION, compileFlags);
    if (version == null) {
        return;
    }
    File jsmod = getArtifact(getRepositoryManager(), modname, version, false);
    // NB localRepos will contain a set of files pointing to the module repositories
    // where all the needed modules can be found
    List<File> localRepos = new ArrayList<>();
    for (CmrRepository r : getRepositoryManager().getRepositories()) {
        if (!r.getRoot().isRemote()) {
            File f = new File(r.getDisplayString());
            if (!localRepos.contains(f)) {
                localRepos.add(f);
            }
        }
    }
    File rd = getRepoDir(modname, jsmod);
    if (!localRepos.contains(rd)) {
        localRepos.add(rd);
    }
    final Set<String> loadedDependencies = new HashSet<>();
    loadedDependencies.add(module);
    loadDependencies(localRepos, getRepositoryManager(), jsmod, loadedDependencies);
    customizeDependencies(localRepos, getRepositoryManager(), loadedDependencies);
    func = func != null ? func : "run";
    final ProcessBuilder proc = buildProcess(modname, version, func, args, exepath, localRepos, output);
    final Process nodeProcess = proc.start();
    // All this shit because inheritIO doesn't work on fucking Windows
    new ReadStream(nodeProcess.getInputStream(), output == null ? System.out : output).start();
    if (output == null) {
        new ReadErrorStream(nodeProcess.getErrorStream(), System.err, debug).start();
    }
    Thread stopThread = new Thread() {

        public void run() {
            try {
                nodeProcess.destroy();
            } catch (Throwable t) {
            }
        }
    };
    try {
        try {
            Runtime.getRuntime().addShutdownHook(stopThread);
        } catch (Throwable t) {
        }
        int exitCode = nodeProcess.waitFor();
        if (exitCode != 0) {
            if (exitCode == 11)
                exitCode = 2;
            throw new CeylonRunJsException("Node process exited with non-zero exit code: " + exitCode, exitCode);
        }
    } finally {
        try {
            Runtime.getRuntime().removeShutdownHook(stopThread);
        } catch (Throwable t) {
        }
    }
}
Also used : ArrayList(java.util.ArrayList) CmrRepository(org.eclipse.ceylon.cmr.api.CmrRepository) JarFile(java.util.jar.JarFile) File(java.io.File) HashSet(java.util.HashSet)

Example 18 with CmrRepository

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

the class CallbackTestCase method doTest.

protected void doTest(ArtifactContext context, TestArtifactCallback callback) throws Exception {
    String repoURL = "http://jboss-as7-modules-repository.googlecode.com/svn/trunk/ceylon";
    try {
        new URL(repoURL).openStream();
    } catch (Exception e) {
        log.error(String.format("Cannot connect to repo %s - %s", repoURL, e));
        // probably not on the internet?
        return;
    }
    RepositoryManagerBuilder builder = getRepositoryManagerBuilder(false, 60000, java.net.Proxy.NO_PROXY);
    RemoteContentStore rcs = new RemoteContentStore(repoURL, log, false, 60000, java.net.Proxy.NO_PROXY);
    CmrRepository repo = new DefaultRepository(rcs.createRoot());
    RepositoryManager manager = builder.addRepository(repo).buildRepository();
    try {
        File file = manager.getArtifact(context);
        Assert.assertNotNull(file);
        Assert.assertTrue(callback.size > 0);
        Assert.assertEquals(callback.size, callback.current);
    } catch (Exception re) {
        Assert.assertNotNull(callback.ts);
        Assert.assertNotNull(callback.err);
        Assert.assertEquals(callback.ts, callback.err.getMessage());
    } finally {
        manager.removeArtifact(null, name, version);
        // test if remove really works
        testSearchResults("org.eclipse.fizbiz", ModuleQuery.Type.JVM, new ModuleSearchResult.ModuleDetails[0]);
    }
}
Also used : RepositoryManagerBuilder(org.eclipse.ceylon.cmr.api.RepositoryManagerBuilder) DefaultRepository(org.eclipse.ceylon.cmr.impl.DefaultRepository) RepositoryManager(org.eclipse.ceylon.cmr.api.RepositoryManager) RemoteContentStore(org.eclipse.ceylon.cmr.impl.RemoteContentStore) CmrRepository(org.eclipse.ceylon.cmr.api.CmrRepository) File(java.io.File) ModuleSearchResult(org.eclipse.ceylon.cmr.api.ModuleSearchResult) URL(java.net.URL)

Example 19 with CmrRepository

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

the class SmokeTestCase method testGetMultiple.

@Test
public void testGetMultiple() throws Exception {
    RepositoryManagerBuilder builder = getRepositoryManagerBuilder(false, 60000, java.net.Proxy.NO_PROXY);
    CmrRepository[] externalRepos = builder.repositoryBuilder().buildRepository(Constants.REPO_URL_CEYLON);
    for (CmrRepository repo : externalRepos) {
        builder.addRepository(repo);
    }
    RepositoryManager manager = builder.buildRepository();
    ArtifactContext artifact = new ArtifactContext(null, "ceylon.json", "1.0.0", ArtifactContext.CAR, ArtifactContext.SCRIPTS_ZIPPED, ArtifactContext.JS);
    List<ArtifactResult> json = manager.getArtifactResults(artifact);
    Assert.assertNotNull("Module 'ceylon.json-1.0.0' not found", json);
    Assert.assertEquals("Expected two artifacts for 'ceylon.json-1.0.0'", 2, json.size());
    File root = new File(manager.getRepositories().get(1).getDisplayString());
    File missing = new File(root, "ceylon/json/1.0.0/ceylon.json-1.0.0.scripts.zip.missing");
    Assert.assertTrue("Marker file .missing not found", missing.exists());
}
Also used : RepositoryManagerBuilder(org.eclipse.ceylon.cmr.api.RepositoryManagerBuilder) RepositoryManager(org.eclipse.ceylon.cmr.api.RepositoryManager) SimpleRepositoryManager(org.eclipse.ceylon.cmr.impl.SimpleRepositoryManager) 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 20 with CmrRepository

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

the class SmokeTestCase method testRemoteContent.

@Test
public void testRemoteContent() throws Exception {
    String repoURL = "http://jboss-as7-modules-repository.googlecode.com/svn/trunk/ceylon";
    try {
        new URL(repoURL).openStream();
    } catch (Exception e) {
        log.error(String.format("Cannot connect to repo %s - %s", repoURL, e));
        // probably not on the internet?
        return;
    }
    RepositoryManagerBuilder builder = getRepositoryManagerBuilder(false, 60000, java.net.Proxy.NO_PROXY);
    RemoteContentStore rcs = new RemoteContentStore(repoURL, log, false, 60000, java.net.Proxy.NO_PROXY);
    CmrRepository repo = new DefaultRepository(rcs.createRoot());
    RepositoryManager manager = builder.addRepository(repo).buildRepository();
    String name = "org.eclipse.fizbiz";
    String version = "1.0.0.Beta1";
    File file = null;
    File originFile = null;
    try {
        file = manager.getArtifact(null, name, version);
        Assert.assertNotNull(file);
        originFile = new File(file.getAbsolutePath() + ".origin");
        Assert.assertNotNull(originFile);
        try {
            String line;
            try (BufferedReader reader = new BufferedReader(new FileReader(originFile))) {
                line = reader.readLine();
            }
            assertEquals(repoURL, line);
        } catch (IOException ignored) {
        }
    } finally {
        manager.removeArtifact(null, name, version);
        // test if remove really works
        if (file != null)
            assertFalse(file.exists());
        if (originFile != null)
            assertFalse(originFile.exists());
        testSearchResults("org.eclipse.fizbiz", Type.JVM, new ModuleDetails[0]);
    }
}
Also used : RepositoryManagerBuilder(org.eclipse.ceylon.cmr.api.RepositoryManagerBuilder) DefaultRepository(org.eclipse.ceylon.cmr.impl.DefaultRepository) BufferedReader(java.io.BufferedReader) RepositoryManager(org.eclipse.ceylon.cmr.api.RepositoryManager) SimpleRepositoryManager(org.eclipse.ceylon.cmr.impl.SimpleRepositoryManager) FileReader(java.io.FileReader) RemoteContentStore(org.eclipse.ceylon.cmr.impl.RemoteContentStore) IOException(java.io.IOException) CmrRepository(org.eclipse.ceylon.cmr.api.CmrRepository) File(java.io.File) URL(java.net.URL) IOException(java.io.IOException) Test(org.junit.Test)

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