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;
}
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;
}
}
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()) };
}
Aggregations