use of org.eclipse.ceylon.cmr.api.ModuleDependencyInfo in project ceylon by eclipse.
the class NpmUtils method readModuleInfo.
@SuppressWarnings("unchecked")
@Override
public ModuleVersionDetails readModuleInfo(String moduleName, String moduleVersion, File moduleArchive, boolean includeMembers, Overrides overrides) {
Map<String, Object> model = loadJsonModel(moduleArchive);
String name = asString(metaModelProperty(model, "name"));
if (!moduleName.equals(name)) {
throw new RuntimeException("Incorrect module");
}
String version = asString(metaModelProperty(model, "version"));
Set<ModuleDependencyInfo> dependencies = getModuleInfo(model, moduleName, version, overrides).getDependencies();
String type = ArtifactContext.getSuffixFromFilename(moduleArchive.getName());
ModuleVersionDetails mvd = new ModuleVersionDetails(NpmRepository.NAMESPACE, moduleName, version, null, null);
mvd.getArtifactTypes().add(new ModuleVersionArtifact(type, null, null));
mvd.getDependencies().addAll(dependencies);
mvd.setDoc(asString(model.get("description")));
mvd.setLicense(asString(model.get("license")));
String author = asString(model.get("author.name"));
if (author != null) {
mvd.getAuthors().add(author);
}
Iterable<Map<String, Object>> contributors = (Iterable<Map<String, Object>>) model.get("contributors");
if (contributors != null) {
for (Map<String, Object> contrib : contributors) {
mvd.getAuthors().add(asString(contrib.get("name")));
}
}
if (includeMembers) {
mvd.setMembers(getMembers(moduleName, moduleArchive));
}
return mvd;
}
use of org.eclipse.ceylon.cmr.api.ModuleDependencyInfo in project ceylon by eclipse.
the class OSGiDependencyResolver method parseRequireBundle.
private ModuleInfo parseRequireBundle(String requireBundle, String name, String version, Overrides overrides) {
Set<ModuleDependencyInfo> infos = new HashSet<>();
requireBundle = requireBundle.replaceAll(";bundle-version=\"\\[([^,]+),[^,]+(\\]|\\))\"", ";bundle-version=$1");
String[] bundles = requireBundle.split(",");
for (String bundle : bundles) {
infos.add(parseModuleInfo(bundle));
}
ModuleInfo ret = new ModuleInfo(null, name, version, // FIXME: does OSGi store this?
ModuleUtil.getMavenGroupIdIfMavenModule(name), ModuleUtil.getMavenArtifactIdIfMavenModule(name), ModuleUtil.getMavenClassifierIfMavenModule(name), null, infos);
if (overrides != null)
ret = overrides.applyOverrides(name, version, ret);
return ret;
}
use of org.eclipse.ceylon.cmr.api.ModuleDependencyInfo in project ceylon by eclipse.
the class CeylonModuleLoader method addLoggingModules.
// Stef: enable back when we upgrade jboss modules
// @SuppressWarnings("unchecked")
// public List<ModuleIdentifier> findModuleForClass(String className){
// Object value = classNamesToModules.get(className);
// if(value == null)
// return Collections.emptyList();
// if(value instanceof ModuleIdentifier)
// return Arrays.asList((ModuleIdentifier)value);
// if(value instanceof List)
// return (List<ModuleIdentifier>) value;
// // WTF?
// return Collections.emptyList();
// }
//
// private void index(File artifact, ModuleIdentifier moduleIdentifier) {
// if(artifact != null && artifact.exists() && artifact.canRead()){
// // only index jars since we can't have CNFE with Ceylon modules
// if(artifact.getName().toLowerCase().endsWith(".jar")){
// System.err.println("Indexing "+artifact);
// try (ZipFile zipFile = new ZipFile(artifact)) {
// Enumeration<? extends ZipEntry> entries = zipFile.entries();
// while(entries.hasMoreElements()){
// ZipEntry entry = entries.nextElement();
// if(entry.isDirectory())
// continue;
// String name = entry.getName();
// if(!name.toLowerCase().endsWith(".class"))
// continue;
// String className = name.replace('/', '.').substring(0, name.length()-6);
// Object value = classNamesToModules.get(className);
// if(value == null)
// classNamesToModules.put(className, moduleIdentifier);
// else if(value instanceof ModuleIdentifier){
// List<ModuleIdentifier> list = new ArrayList<ModuleIdentifier>(2);
// list.add((ModuleIdentifier) value);
// list.add(moduleIdentifier);
// classNamesToModules.put(className, list);
// }else if(value instanceof List){
// @SuppressWarnings("unchecked")
// List<ModuleIdentifier> list = (List<ModuleIdentifier>) value;
// list.add(moduleIdentifier);
// }
// }
// } catch (IOException e) {
// // TODO Auto-generated catch block
// e.printStackTrace();
// }
// }
// }
// }
private void addLoggingModules(Builder builder, List<DependencySpec> deps, List<ModuleDependencyInfo> replacements) {
for (ModuleDependencyInfo mi : replacements) {
ModuleIdentifier identifier = ModuleIdentifier.create(mi.getName(), mi.getVersion());
final DependencySpec dependency = DependencySpec.createModuleDependencySpec(PathFilters.acceptAll(), mi.isExport() ? PathFilters.acceptAll() : PathFilters.rejectAll(), this, identifier, mi.isOptional());
builder.addDependency(dependency);
deps.add(dependency);
}
}
use of org.eclipse.ceylon.cmr.api.ModuleDependencyInfo in project ceylon by eclipse.
the class BytecodeUtils method readModuleInformation.
/**
* Read module info from bytecode.
*
* @param moduleName the module name
* @param jarFile the module jar file
* @return module info list
*/
private static ModuleInfo readModuleInformation(final String moduleName, final File jarFile, Overrides overrides) {
ClassFile moduleInfo = readModuleInfo(moduleName, jarFile);
if (moduleInfo == null)
return null;
Annotation ai = ClassFileUtil.findAnnotation(moduleInfo, MODULE_ANNOTATION);
if (ai == null)
return null;
final String version = (String) ClassFileUtil.getAnnotationValue(moduleInfo, ai, "version");
if (version == null)
return null;
String groupId, artifactId;
groupId = (String) ClassFileUtil.getAnnotationValue(moduleInfo, ai, "group");
if (groupId == null || groupId.isEmpty()) {
String[] coordinates = ModuleUtil.getMavenCoordinates(moduleName);
groupId = coordinates[0];
artifactId = coordinates[1];
} else {
artifactId = (String) ClassFileUtil.getAnnotationValue(moduleInfo, ai, "artifact");
if (artifactId == null || artifactId.isEmpty())
artifactId = moduleName;
}
final Object[] dependencies = (Object[]) ClassFileUtil.getAnnotationValue(moduleInfo, ai, "dependencies");
final Set<ModuleDependencyInfo> infos = getDependencies(moduleInfo, dependencies, moduleName, version, groupId, artifactId, overrides);
ModuleInfo ret = new ModuleInfo(null, moduleName, version, groupId, artifactId, null, null, infos);
if (overrides != null)
ret = overrides.applyOverrides(moduleName, version, ret);
return ret;
}
use of org.eclipse.ceylon.cmr.api.ModuleDependencyInfo in project ceylon by eclipse.
the class LegacyImporter method checkDependencies.
private void checkDependencies(TreeSet<ModuleDependencyInfo> sortedDeps, Set<String> visited, boolean exported) throws Exception {
for (ModuleDependencyInfo dep : sortedDeps) {
// only do exported, or non-exported
if (exported != dep.isExport())
continue;
// skip test scope
if (dep.getModuleScope() == ModuleScope.TEST)
continue;
// skip already-visited dependencies based on name/version key
if (!visited.add(dep.getModuleName()))
continue;
feedback.beforeDependency(dep);
String name = dep.getName();
String version = dep.getVersion();
// missing dep is OK, it can be fixed later, but invalid module/dependency is not OK
if (name == null || name.isEmpty())
feedback.dependencyError(DependencyErrors.DEPERR_INVALID_MODULE_NAME, dep);
if (ModuleUtil.isDefaultModule(name))
feedback.dependencyError(DependencyErrors.DEPERR_INVALID_MODULE_DEFAULT, dep);
if (version == null || version.isEmpty())
feedback.dependencyError(DependencyErrors.DEPERR_INVALID_MODULE_VERSION, dep);
Usage usage = null;
if (jdkProvider.isJDKModule(name)) {
usage = scanner.removeMatchingJdkClasses(name);
} else {
ArtifactContext context = new ArtifactContext(dep.getNamespace(), name, version, ArtifactContext.CAR, ArtifactContext.JAR);
ArtifactResult result = lookupRepoman.getArtifactResult(context);
File artifact = result != null ? result.artifact() : null;
if (artifact != null && artifact.exists()) {
try {
Set<String> importedClasses = JarUtils.gatherClassnamesFromJar(artifact);
addTransitiveDependenciesClasses(result, importedClasses, visited, dep);
usage = scanner.removeMatchingClasses(importedClasses);
} catch (IOException e) {
feedback.dependency(DependencyResults.DEP_CHECK_FAILED, dep);
hasErrors = true;
}
} else {
if (dep.isOptional()) {
String key = ModuleUtil.makeModuleName(dep.getName(), dep.getVersion());
if (missingDependenciesPackages != null && missingDependenciesPackages.containsKey(key)) {
List<Pattern> packages = missingDependenciesPackages.get(key);
usage = scanner.removeMatchingPackages(packages);
}
}
if (usage == null) {
feedback.dependency(DependencyResults.DEP_NOT_FOUND, dep);
hasErrors = true;
}
}
}
if (usage != null) {
switch(usage) {
case Used:
if (!dep.isExport()) {
feedback.dependency(DependencyResults.DEP_OK, dep);
} else {
dep = new ModuleDependencyInfo(null, dep.getName(), dep.getVersion(), dep.isOptional(), false, dep.getNativeBackends(), dep.getModuleScope());
feedback.dependency(DependencyResults.DEP_MARK_UNSHARED, dep);
}
break;
case UsedInPublicApi:
if (dep.isExport()) {
feedback.dependency(DependencyResults.DEP_OK, dep);
} else {
dep = new ModuleDependencyInfo(null, dep.getName(), dep.getVersion(), dep.isOptional(), true, dep.getNativeBackends(), dep.getModuleScope());
feedback.dependency(DependencyResults.DEP_MARK_SHARED, dep);
hasProblems = true;
}
break;
default:
// not used at all
dep = new ModuleDependencyInfo(null, dep.getName(), dep.getVersion(), dep.isOptional(), false, dep.getNativeBackends(), dep.getModuleScope());
feedback.dependency(DependencyResults.DEP_OK_UNUSED, dep);
}
}
feedback.afterDependency(dep);
expectedDependencies.add(dep);
}
}
Aggregations