Search in sources :

Example 41 with CmrRepository

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

the class AbstractNodeRepositoryManager method getRepositories.

@Override
public synchronized List<CmrRepository> getRepositories() {
    if (allRoots == null) {
        allRoots = new ArrayList<>();
        boolean cacheAdded = false;
        for (CmrRepository root : roots) {
            if (!addCacheAsRoot && cache != null && !cacheAdded && root.getRoot().isRemote()) {
                allRoots.add(cache);
                cacheAdded = true;
            }
            allRoots.add(root);
        }
        if (!addCacheAsRoot && cache != null && !cacheAdded) {
            allRoots.add(cache);
        }
    }
    return allRoots;
}
Also used : CmrRepository(org.eclipse.ceylon.cmr.api.CmrRepository)

Example 42 with CmrRepository

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

the class AssemblyRepositoryBuilder method buildRepository.

@Override
public CmrRepository[] buildRepository(String token, RepositoryBuilderConfig config) throws Exception {
    if (token.startsWith("assembly:")) {
        token = token.substring(9);
        // Check if the token has a repo folder element
        String repoFolder = null;
        int p = token.indexOf(SEPARATOR);
        if (p > 0) {
            repoFolder = token.substring(p + 1);
            token = token.substring(0, p);
        }
        // Unpack the assembly (if we haven't already done so before)
        File assemblyFile = new File(token);
        File tmpAssemblyFolder = registerAssembly(assemblyFile);
        // Read the assembly's MANIFEST (if any)
        File manifestFile = new File(new File(tmpAssemblyFolder, "META-INF"), "MANIFEST.MF");
        if (manifestFile.isFile()) {
            Manifest manifest = new Manifest(new FileInputStream(manifestFile));
            Attributes attrs = manifest.getMainAttributes();
            if (repoFolder == null) {
                repoFolder = attrs.getValue(Constants.ATTR_ASSEMBLY_REPOSITORY);
            }
        }
        // The modules might be an a sub-folder of the assembly, not in the root
        File modulesFolder = tmpAssemblyFolder;
        if (repoFolder != null && !repoFolder.isEmpty()) {
            modulesFolder = new File(modulesFolder, repoFolder);
            if (!modulesFolder.isDirectory()) {
                throw new IllegalArgumentException("No such repository folder within the assembly: " + repoFolder);
            }
        }
        // Now create a common file content store using the unpacked assembly
        FileContentStore cs = new FileContentStore(modulesFolder);
        CmrRepository defRepo = new DefaultRepository(cs.createRoot());
        // Not satisfied with the following heuristics yet, but if we
        // have a specific "modules" folder (so the modules are not in
        // the root of the assembly) then we also check to see if there
        // is a "maven" folder and if so we add a MavenRepository for it.
        // We do the same for "node_modules" and the NpmRepository.
        CmrRepository mvnRepo = null;
        CmrRepository npmRepo = null;
        if (repoFolder != null && !repoFolder.isEmpty()) {
            File mavenFolder = new File(tmpAssemblyFolder, "maven");
            if (mavenFolder.isDirectory()) {
                // Now create a Maven repository on top of the unpacked assembly
                mvnRepo = MavenRepositoryBuilder.createMavenRepository(mavenFolder.getAbsolutePath(), config);
            }
            File npmFolder = new File(tmpAssemblyFolder, "node_modules");
            if (npmFolder.isDirectory()) {
                // Now create a NPM repository on top of the unpacked assembly
                String npmtoken = "npm:" + npmFolder.getAbsolutePath();
                npmRepo = NpmRepositoryBuilder.createNpmRepository(npmtoken, config.log, config.offline, config.currentDirectory);
            }
        }
        ArrayList<CmrRepository> repos = new ArrayList<CmrRepository>(3);
        repos.add(defRepo);
        if (mvnRepo != null) {
            repos.add(mvnRepo);
        }
        if (npmRepo != null) {
            repos.add(npmRepo);
        }
        return repos.toArray(new CmrRepository[] {});
    } else {
        return null;
    }
}
Also used : Attributes(java.util.jar.Attributes) ArrayList(java.util.ArrayList) Manifest(java.util.jar.Manifest) CmrRepository(org.eclipse.ceylon.cmr.api.CmrRepository) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 43 with CmrRepository

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

the class LocalRepositoryBuilder method buildRepository.

@Override
public CmrRepository[] buildRepository(String token, RepositoryBuilderConfig config) throws Exception {
    final File file = (token.startsWith("file:") ? new File(new URI(token)) : new File(token));
    if (file.exists() == false)
        throw new IllegalArgumentException("Directory does not exist: " + token);
    if (file.isDirectory() == false)
        throw new IllegalArgumentException("Repository exists but is not a directory: " + token);
    FileContentStore cs = new FileContentStore(file);
    return new CmrRepository[] { new DefaultRepository(cs.createRoot()) };
}
Also used : CmrRepository(org.eclipse.ceylon.cmr.api.CmrRepository) File(java.io.File) URI(java.net.URI)

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