Search in sources :

Example 21 with ModuleDependencyInfo

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;
}
Also used : ModuleVersionDetails(org.eclipse.ceylon.cmr.api.ModuleVersionDetails) ModuleDependencyInfo(org.eclipse.ceylon.cmr.api.ModuleDependencyInfo) ModuleVersionArtifact(org.eclipse.ceylon.cmr.api.ModuleVersionArtifact) Map(java.util.Map)

Example 22 with ModuleDependencyInfo

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;
}
Also used : ModuleInfo(org.eclipse.ceylon.cmr.api.ModuleInfo) ModuleDependencyInfo(org.eclipse.ceylon.cmr.api.ModuleDependencyInfo) HashSet(java.util.HashSet)

Example 23 with ModuleDependencyInfo

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);
    }
}
Also used : ModuleDependencyInfo(org.eclipse.ceylon.cmr.api.ModuleDependencyInfo) DependencySpec(org.jboss.modules.DependencySpec) ModuleIdentifier(org.jboss.modules.ModuleIdentifier)

Example 24 with ModuleDependencyInfo

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;
}
Also used : ClassFile(org.eclipse.ceylon.langtools.classfile.ClassFile) ModuleInfo(org.eclipse.ceylon.cmr.api.ModuleInfo) ModuleDependencyInfo(org.eclipse.ceylon.cmr.api.ModuleDependencyInfo) Annotation(org.eclipse.ceylon.langtools.classfile.Annotation)

Example 25 with ModuleDependencyInfo

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);
    }
}
Also used : Pattern(java.util.regex.Pattern) Usage(org.eclipse.ceylon.cmr.ceylon.ClassFileScanner.Usage) ModuleDependencyInfo(org.eclipse.ceylon.cmr.api.ModuleDependencyInfo) ArtifactContext(org.eclipse.ceylon.cmr.api.ArtifactContext) IOException(java.io.IOException) File(java.io.File) ArtifactResult(org.eclipse.ceylon.model.cmr.ArtifactResult)

Aggregations

ModuleDependencyInfo (org.eclipse.ceylon.cmr.api.ModuleDependencyInfo)29 ModuleInfo (org.eclipse.ceylon.cmr.api.ModuleInfo)12 ModuleVersionDetails (org.eclipse.ceylon.cmr.api.ModuleVersionDetails)10 HashSet (java.util.HashSet)9 ArrayList (java.util.ArrayList)5 Map (java.util.Map)5 ModuleVersionArtifact (org.eclipse.ceylon.cmr.api.ModuleVersionArtifact)5 IOException (java.io.IOException)3 ArtifactContext (org.eclipse.ceylon.cmr.api.ArtifactContext)3 Backends (org.eclipse.ceylon.common.Backends)3 Annotation (org.eclipse.ceylon.langtools.classfile.Annotation)3 ArtifactResult (org.eclipse.ceylon.model.cmr.ArtifactResult)3 File (java.io.File)2 LinkedHashSet (java.util.LinkedHashSet)2 LinkedList (java.util.LinkedList)2 Properties (java.util.Properties)2 TreeSet (java.util.TreeSet)2 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)2 DependencyDescriptor (org.eclipse.ceylon.cmr.resolver.aether.DependencyDescriptor)2 ClassFile (org.eclipse.ceylon.langtools.classfile.ClassFile)2