Search in sources :

Example 21 with ModuleVersionDetails

use of org.eclipse.ceylon.cmr.api.ModuleVersionDetails 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 ModuleVersionDetails

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

the class NpmUtils method getBinaryVersions.

@Override
public int[] getBinaryVersions(String moduleName, String version, File moduleArchive) {
    int major = 0;
    int minor = 0;
    ModuleVersionDetails mvd = readModuleInfo(moduleName, version, moduleArchive, false, null);
    ModuleVersionArtifact mva = mvd.getArtifactTypes().first();
    if (mva.getMajorBinaryVersion() != null) {
        major = mva.getMajorBinaryVersion();
    }
    if (mva.getMinorBinaryVersion() != null) {
        minor = mva.getMinorBinaryVersion();
    }
    return new int[] { major, minor };
}
Also used : ModuleVersionDetails(org.eclipse.ceylon.cmr.api.ModuleVersionDetails) ModuleVersionArtifact(org.eclipse.ceylon.cmr.api.ModuleVersionArtifact)

Example 23 with ModuleVersionDetails

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

the class CeylonCompileTool method initialize.

@Override
public void initialize(CeylonTool mainTool) throws Exception {
    super.initialize(mainTool);
    compiler = new Main("ceylon compile");
    helper.options.clear();
    Options.instance(new Context());
    includeDependencies = processCompileFlags(includeDependencies, DefaultToolOptions.getCompilerIncludeDependencies());
    if (modulesOrFiles.isEmpty() && !javac.contains("-help") && !javac.contains("-X") && !javac.contains("-version")) {
        throw new IllegalStateException("Argument moduleOrFile should appear at least 1 time(s)");
    }
    arguments = new ArrayList<>();
    if (cwd != null) {
        arguments.add("-cwd");
        arguments.add(cwd.getPath());
        validateWithJavac(org.eclipse.ceylon.langtools.tools.javac.main.Option.CEYLONCWD, "-cwd", cwd.getPath());
    }
    if (jdkProvider != null) {
        arguments.add("-jdk-provider");
        arguments.add(jdkProvider.toString());
    }
    if (aptModules != null) {
        for (ModuleSpec mod : aptModules) {
            arguments.add("-apt");
            arguments.add(mod.toString());
        }
    }
    for (File source : applyCwd(this.sources)) {
        arguments.add("-src");
        arguments.add(source.getPath());
        validateWithJavac(org.eclipse.ceylon.langtools.tools.javac.main.Option.CEYLONSOURCEPATH, "-sourcepath", source.getPath());
    }
    for (File resource : applyCwd(this.resources)) {
        arguments.add("-res");
        arguments.add(resource.getPath());
    }
    if (resourceRoot != null) {
        arguments.add("-resroot");
        arguments.add(resourceRoot);
    }
    if (continueOnErrors) {
        arguments.add("-continue");
    }
    if (progress) {
        arguments.add("-progress");
    }
    if (offline) {
        arguments.add("-offline");
    }
    if (timeout != -1) {
        arguments.add("-timeout");
        arguments.add(String.valueOf(timeout));
    }
    if (flatClasspath) {
        arguments.add("-flat-classpath");
    }
    if (autoExportMavenDependencies) {
        arguments.add("-auto-export-maven-dependencies");
    }
    if (fullyExportMavenDependencies) {
        arguments.add("-fully-export-maven-dependencies");
    }
    if (overrides != null) {
        arguments.add("-overrides");
        if (overrides.startsWith("classpath:")) {
            arguments.add(overrides);
        } else {
            arguments.add(applyCwd(new File(overrides)).getPath());
        }
    }
    if (jigsaw) {
        arguments.add("-module-info");
    }
    if (noOsgi) {
        arguments.add("-noosgi");
    }
    if (osgiProvidedBundles != null && !osgiProvidedBundles.isEmpty()) {
        arguments.add("-osgi-provided-bundles");
        arguments.add(osgiProvidedBundles);
    }
    if (noPom) {
        arguments.add("-nopom");
    }
    if (pack200) {
        arguments.add("-pack200");
    }
    if (verbose != null) {
        if (verbose.isEmpty()) {
            arguments.add("-verbose");
        } else {
            arguments.add("-verbose:" + verbose);
        }
    }
    if (out != null) {
        arguments.add("-out");
        arguments.add(out);
    }
    if (user != null) {
        arguments.add("-user");
        arguments.add(user);
    }
    if (pass != null) {
        arguments.add("-pass");
        arguments.add(pass);
    }
    String fileEncoding = encoding;
    if (fileEncoding == null) {
        fileEncoding = DefaultToolOptions.getDefaultEncoding();
    }
    if (fileEncoding != null) {
        try {
            Charset.forName(fileEncoding);
        } catch (IllegalCharsetNameException | UnsupportedCharsetException e) {
            throw new IllegalArgumentException("Unsupported encoding: " + fileEncoding);
        }
        arguments.add(org.eclipse.ceylon.langtools.tools.javac.main.Option.ENCODING.text);
        arguments.add(fileEncoding);
    }
    if (systemRepo != null) {
        arguments.add("-sysrep");
        arguments.add(systemRepo);
    }
    if (cacheRepo != null) {
        arguments.add("-cacherep");
        arguments.add(cacheRepo);
    }
    if (noDefRepos) {
        arguments.add("-nodefreps");
    }
    if (repos != null) {
        for (URI uri : this.repos) {
            arguments.add("-rep");
            arguments.add(uri.toString());
        }
    }
    if (suppressWarnings != null) {
        arguments.add("-suppress-warnings");
        arguments.add(EnumUtil.enumsToString(suppressWarnings));
    }
    if (targetVersion != null) {
        arguments.add("-source");
        arguments.add(targetVersion.toString());
        arguments.add("-target");
        arguments.add(targetVersion.toString());
    }
    if (ee) {
        arguments.add("-ee");
    }
    if (eeImport != null) {
        for (String eeImport : this.eeImport) {
            arguments.add("-ee-import");
            arguments.add(eeImport);
        }
    }
    if (eeAnnotation != null) {
        for (String eeAnnotation : this.eeAnnotation) {
            arguments.add("-ee-annotation");
            arguments.add(eeAnnotation);
        }
    }
    addJavacArguments(arguments, javac);
    List<File> srcs = applyCwd(this.sources);
    Collection<String> expandedModulesOrFiles = ModuleWildcardsHelper.expandWildcards(srcs, this.modulesOrFiles, Backend.Java);
    expandedModulesOrFiles = normalizeFileNames(expandedModulesOrFiles);
    if (expandedModulesOrFiles.isEmpty()) {
        String msg = CeylonCompileMessages.msg("error.no.sources");
        if (ModuleWildcardsHelper.onlyGlobArgs(this.modulesOrFiles)) {
            throw new NonFatalToolMessage(msg);
        } else {
            throw new ToolUsageError(msg);
        }
    }
    for (String moduleOrFile : expandedModulesOrFiles) {
        if (!org.eclipse.ceylon.langtools.tools.javac.main.Option.SOURCEFILE.matches(moduleOrFile)) {
            throw new IllegalArgumentException(CeylonCompileMessages.msg("argument.error", moduleOrFile));
        }
        validateWithJavac(org.eclipse.ceylon.langtools.tools.javac.main.Option.SOURCEFILE, moduleOrFile, moduleOrFile);
    }
    // We validate that all source arguments are correct
    SourceArgumentsResolver sar = new SourceArgumentsResolver(this.sources, this.resources, Constants.CEYLON_SUFFIX, Constants.JAVA_SUFFIX);
    sar.cwd(cwd).parse(expandedModulesOrFiles);
    if (includeDependencies != null && !COMPILE_NEVER.equals(includeDependencies)) {
        // Determine any dependencies that might need compiling as well
        SourceDependencyResolver sdr = new SourceDependencyResolver(getModuleVersionReader(), this.sources, Backends.JAVA);
        if (sdr.traverseDependencies(sar.getSourceFiles())) {
            for (ModuleVersionDetails mvd : sdr.getAdditionalModules()) {
                if (COMPILE_FORCE.equals(includeDependencies) || (COMPILE_CHECK.equals(includeDependencies) && shouldRecompile(getOfflineRepositoryManager(), mvd.getModule(), mvd.getVersion(), ModuleQuery.Type.JVM, true)) || (COMPILE_ONCE.equals(includeDependencies) && shouldRecompile(getOfflineRepositoryManager(), mvd.getModule(), mvd.getVersion(), ModuleQuery.Type.JVM, false))) {
                    expandedModulesOrFiles.add(mvd.getModule());
                    if (incremental) {
                        sar.parse(expandedModulesOrFiles);
                    }
                }
            }
        }
    }
    if (incremental) {
        next_module: for (String module : sar.getModules()) {
            // Determine module version from source
            ModuleVersionDetails mvd = getModuleVersionReader().fromSource(module);
            if (mvd != null) {
                // Find the module's CAR file
                ArtifactResult artifact = getModuleArtifact(getOfflineRepositoryManager(), mvd.getModule(), mvd.getVersion(), ModuleQuery.Type.JVM);
                if (artifact != null) {
                    // Check the language module version
                    for (ArtifactResult dep : artifact.dependencies()) {
                        if ("ceylon.language".equals(dep.name())) {
                            if (!Versions.CEYLON_VERSION_NUMBER.equals(dep.version())) {
                                // Skip handling of --incremental on this module
                                continue next_module;
                            }
                            break;
                        }
                    }
                    File carFile = artifact.artifact();
                    // Check if it has META-INF/errors.txt
                    Properties errors = getMetaInfErrors(carFile);
                    if (errors != null && !errors.isEmpty()) {
                        // TODO handle this incrementally
                        continue;
                    }
                    // Check if it has META-INF/hashes.txt
                    Properties oldHashes = getMetaInfHashes(carFile);
                    if (oldHashes != null) {
                        // Get the hashes for the new files
                        List<File> files = sar.getFilesByModule().get(module);
                        Properties newHashes = getFileHashes(module, files);
                        // Compare the two and make list of changed files
                        Collection<String> changedFiles = determineChangedFiles(module, oldHashes, newHashes, carFile);
                        if (changedFiles == null) {
                        // This shouldn't happen, but if it does we just skip any
                        // special treatment and compile this module normally
                        } else if (changedFiles.isEmpty()) {
                            // No files were changed, we shouldn't compile the module
                            expandedModulesOrFiles.remove(module);
                            // And we remove its files too if any were mentioned
                            Collection<String> remove = filesToStrings(module, files);
                            expandedModulesOrFiles.removeAll(remove);
                        } else {
                            if (expandedModulesOrFiles.contains(module)) {
                                // The module itself was mentioned on the command line
                                if (changedFiles.size() < files.size()) {
                                    // There were fewer changed files than the total number
                                    // So we remove the module
                                    expandedModulesOrFiles.remove(module);
                                    // And we remove its files too if any were mentioned
                                    Collection<String> remove = filesToStrings(module, files);
                                    expandedModulesOrFiles.removeAll(remove);
                                    // And then we add only those files that were changed
                                    expandedModulesOrFiles.addAll(changedFiles);
                                }
                            } else {
                                // Separate source files were mentioned on the command line
                                // So we remove the unchanged files
                                Collection<String> unchanged = filesToStrings(module, files);
                                unchanged.removeAll(changedFiles);
                                expandedModulesOrFiles.removeAll(unchanged);
                            }
                        }
                    }
                }
            }
        }
        if (expandedModulesOrFiles.isEmpty()) {
            String msg = CeylonCompileMessages.msg("error.no.need");
            throw new NonFatalToolMessage(msg);
        }
    }
    arguments.addAll(expandedModulesOrFiles);
    if (verbose != null) {
        System.out.println(arguments);
        System.out.flush();
    }
}
Also used : Context(org.eclipse.ceylon.langtools.tools.javac.util.Context) SourceArgumentsResolver(org.eclipse.ceylon.common.tools.SourceArgumentsResolver) ModuleVersionDetails(org.eclipse.ceylon.cmr.api.ModuleVersionDetails) SourceDependencyResolver(org.eclipse.ceylon.common.tools.SourceDependencyResolver) Properties(java.util.Properties) URI(java.net.URI) NonFatalToolMessage(org.eclipse.ceylon.common.tool.NonFatalToolMessage) ArtifactResult(org.eclipse.ceylon.model.cmr.ArtifactResult) IllegalCharsetNameException(java.nio.charset.IllegalCharsetNameException) ModuleSpec(org.eclipse.ceylon.common.ModuleSpec) UnsupportedCharsetException(java.nio.charset.UnsupportedCharsetException) ToolUsageError(org.eclipse.ceylon.common.tool.ToolUsageError) Collection(java.util.Collection) List(java.util.List) ArrayList(java.util.ArrayList) Main(org.eclipse.ceylon.compiler.java.launcher.Main) File(java.io.File)

Example 24 with ModuleVersionDetails

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

the class AbstractRepository method collectArtifacts.

private void collectArtifacts(Node node, ModuleQuery lookup, ModuleSearchResult result) {
    // Winner of the less aptly-named method
    boolean isFolder = !node.hasBinaries();
    if (isFolder) {
        if (ArtifactContext.isDirectoryName(node.getLabel()))
            return;
        Ret ret = new Ret();
        if (hasChildrenContainingArtifact(node, lookup, ret)) {
            // we have artifact children, are they of the right type?
            if (ret.foundRightType) {
                // collect them
                String moduleName = toModuleName(node);
                ModuleVersionDetails mvd = getSearchResult(moduleName, node, lookup);
                if (mvd != null) {
                    result.addResult(moduleName, mvd);
                }
            }
        } else {
            // collect in the children
            List<Node> sortedChildren = new ArrayList<Node>();
            for (Node child : node.getChildren()) sortedChildren.add(child);
            Collections.sort(sortedChildren, AlphabeticalNodeComparator);
            for (Node child : sortedChildren) {
                collectArtifacts(child, lookup, result);
            }
        }
    }
}
Also used : ModuleVersionDetails(org.eclipse.ceylon.cmr.api.ModuleVersionDetails) OpenNode(org.eclipse.ceylon.cmr.spi.OpenNode) Node(org.eclipse.ceylon.cmr.spi.Node) ArrayList(java.util.ArrayList)

Example 25 with ModuleVersionDetails

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

the class AbstractRepository method completeVersions.

@Override
public void completeVersions(ModuleVersionQuery lookup, ModuleVersionResult result) {
    // check for delegate
    ContentFinderDelegate delegate = root.getService(ContentFinderDelegate.class);
    if (delegate != null) {
        delegate.completeVersions(lookup, result, getOverrides());
        return;
    }
    // this is only for non-Maven modules
    if (ModuleUtil.isMavenModule(lookup.getName()))
        return;
    // FIXME: handle default module
    // FIXME: we should really get this splitting done somewhere in common
    String name = lookup.getName();
    Node namePart = NodeUtils.getNode(root, Arrays.asList(name.split("\\.")));
    if (namePart == null)
        return;
    String memberName = lookup.getMemberName();
    // now each child is supposed to be a version part, let's verify that
    for (Node child : namePart.getChildren()) {
        // Winner of the less aptly-named method
        boolean isFolder = !child.hasBinaries();
        // ignore non-folders
        if (!isFolder)
            continue;
        // now make sure we can find the artifact we're looking for in there
        String version = child.getLabel();
        // optional filter on version
        if (lookup.getVersion() != null) {
            if (lookup.isExactVersionMatch()) {
                if (!version.equals(lookup.getVersion()))
                    continue;
            } else {
                if (!version.startsWith(lookup.getVersion()))
                    continue;
            }
        }
        // avoid duplicates
        if (result.hasVersion(version))
            continue;
        // try every known suffix
        boolean found = false;
        boolean foundInfo = false;
        boolean binaryShouldMatch = false;
        boolean binaryMatch = false;
        // null here and read the info later
        ModuleVersionDetails mvd = new ModuleVersionDetails(getNamespace(), name, version, null, null);
        String[] suffixes = lookup.getType().getSuffixes();
        // When we need to find ALL requested suffixes we maintain a set of those not found yet
        HashSet<String> suffixesToFind = null;
        if (lookup.getRetrieval() == Retrieval.ALL) {
            suffixesToFind = new HashSet<String>(Arrays.asList(suffixes));
        }
        // Now try to retrieve information for each of the suffixes
        for (String suffix : suffixes) {
            String artifactName = getArtifactName(name, version, suffix);
            Node artifact = child.getChild(artifactName);
            if (artifact == null) {
                if (lookup.getRetrieval() == Retrieval.ALL) {
                    break;
                } else {
                    continue;
                }
            }
            if (shouldCheckBinaryVersion(suffix)) {
                binaryShouldMatch = true;
                if (!checkBinaryVersion(name, version, artifact, lookup, suffix)) {
                    if (lookup.getRetrieval() == Retrieval.ALL) {
                        break;
                    } else {
                        continue;
                    }
                }
                binaryMatch = true;
            }
            // we found the artifact: let's notify
            found = true;
            if (lookup.getRetrieval() == Retrieval.ALL) {
                suffixesToFind.remove(suffix);
            }
            // let's see if we can extract some information
            switch(addArtifactInfo(artifact, name, version, suffix, memberName, mvd, lookup)) {
                case INFO_FOUND:
                    foundInfo = true;
                    break;
                case NO_MATCH:
                    continue;
                case OTHER:
                    // nothing;
                    break;
            }
        }
        // read the artifact's information
        if (((found && memberName == null) || foundInfo) && (lookup.getRetrieval() == Retrieval.ANY || suffixesToFind.isEmpty()) && (!binaryShouldMatch || binaryMatch)) {
            mvd.setRemote(root.isRemote());
            mvd.setOrigin(getDisplayString());
            result.addVersion(mvd);
        }
    }
}
Also used : ModuleVersionDetails(org.eclipse.ceylon.cmr.api.ModuleVersionDetails) ContentFinderDelegate(org.eclipse.ceylon.cmr.api.ContentFinderDelegate) OpenNode(org.eclipse.ceylon.cmr.spi.OpenNode) Node(org.eclipse.ceylon.cmr.spi.Node)

Aggregations

ModuleVersionDetails (org.eclipse.ceylon.cmr.api.ModuleVersionDetails)32 ModuleDependencyInfo (org.eclipse.ceylon.cmr.api.ModuleDependencyInfo)10 ModuleVersionArtifact (org.eclipse.ceylon.cmr.api.ModuleVersionArtifact)10 File (java.io.File)7 ArrayList (java.util.ArrayList)6 ModuleVersionQuery (org.eclipse.ceylon.cmr.api.ModuleVersionQuery)5 ModuleVersionResult (org.eclipse.ceylon.cmr.api.ModuleVersionResult)5 OpenNode (org.eclipse.ceylon.cmr.spi.OpenNode)5 ArtifactContext (org.eclipse.ceylon.cmr.api.ArtifactContext)4 Node (org.eclipse.ceylon.cmr.spi.Node)4 ModuleSpec (org.eclipse.ceylon.common.ModuleSpec)4 HashSet (java.util.HashSet)3 TreeSet (java.util.TreeSet)3 RepositoryManager (org.eclipse.ceylon.cmr.api.RepositoryManager)3 ToolUsageError (org.eclipse.ceylon.common.tool.ToolUsageError)3 ArtifactResult (org.eclipse.ceylon.model.cmr.ArtifactResult)3 List (java.util.List)2 Map (java.util.Map)2 CmrRepository (org.eclipse.ceylon.cmr.api.CmrRepository)2 ModuleInfo (org.eclipse.ceylon.cmr.api.ModuleInfo)2