Search in sources :

Example 31 with ModuleSpec

use of org.eclipse.ceylon.common.ModuleSpec in project ceylon by eclipse.

the class CeylonJigsawTool method run.

@Override
public void run() throws Exception {
    for (ModuleSpec module : modules) {
        String moduleName = module.getName();
        String version = checkModuleVersionsOrShowSuggestions(moduleName, module.isVersioned() ? module.getVersion() : null, ModuleQuery.Type.JVM, Versions.JVM_BINARY_MAJOR_VERSION, Versions.JVM_BINARY_MINOR_VERSION, // JS binary but don't care since JVM
        null, // JS binary but don't care since JVM
        null, null);
        if (version == null)
            return;
        loadModule(null, moduleName, version);
        if (!force)
            errorOnConflictingModule(moduleName, version);
    }
    // force loading the module which contains the main
    loadModule(null, "org.eclipse.ceylon.java.main", Versions.CEYLON_VERSION_NUMBER);
    loader.resolve();
    if (!out.exists()) {
        if (!out.mkdirs()) {
            throw new ToolUsageError(Messages.msg(bundle, "jigsaw.folder.error", out));
        }
    }
    final List<ArtifactResult> staticMetamodelEntries = new ArrayList<>();
    loader.visitModules(new ModuleGraph.Visitor() {

        @Override
        public void visit(Module module) {
            if (module.artifact != null) {
                File file = module.artifact.artifact();
                try {
                    if (file != null) {
                        append(file.getAbsolutePath());
                        newline();
                        staticMetamodelEntries.add(module.artifact);
                        String name = file.getName();
                        if (name.endsWith(".car"))
                            name = name.substring(0, name.length() - 4) + ".jar";
                        Files.copy(file.toPath(), new File(out, name).toPath(), StandardCopyOption.REPLACE_EXISTING);
                    }
                } catch (IOException x) {
                    // lame
                    throw new RuntimeException(x);
                }
            }
        }
    });
    if (staticMetamodel) {
        JvmBackendUtil.writeStaticMetamodel(out, staticMetamodelEntries, jdkProvider);
    }
    flush();
}
Also used : ArrayList(java.util.ArrayList) IOException(java.io.IOException) ArtifactResult(org.eclipse.ceylon.model.cmr.ArtifactResult) ModuleSpec(org.eclipse.ceylon.common.ModuleSpec) ToolUsageError(org.eclipse.ceylon.common.tool.ToolUsageError) ModuleGraph(org.eclipse.ceylon.cmr.ceylon.loader.ModuleGraph) Module(org.eclipse.ceylon.cmr.ceylon.loader.ModuleGraph.Module) File(java.io.File)

Example 32 with ModuleSpec

use of org.eclipse.ceylon.common.ModuleSpec in project ceylon by eclipse.

the class CeylonMavenExportTool method run.

@Override
public void run() throws Exception {
    String firstModuleName = null;
    for (ModuleSpec module : modules) {
        String moduleName = module.getName();
        String version = checkModuleVersionsOrShowSuggestions(moduleName, module.isVersioned() ? module.getVersion() : null, ModuleQuery.Type.JVM, Versions.JVM_BINARY_MAJOR_VERSION, Versions.JVM_BINARY_MINOR_VERSION, // JS binary but don't care since JVM
        null, // JS binary but don't care since JVM
        null, null);
        if (version == null)
            return;
        if (firstModuleName == null) {
            firstModuleName = moduleName;
        }
        System.err.println("Doing " + module);
        loadModule(null, moduleName, version);
    }
    // FIXME: we probably want to allow exporting of multiple versions
    loader.resolve();
    final File outputFolder = applyCwd(out != null ? out : new File("maven-repository"));
    if (!outputFolder.exists()) {
        FileUtil.mkdirs(outputFolder);
    } else {
        // FIXME: error if regular file?
        // FIXME: or add, don't delete?
        FileUtil.delete(outputFolder);
    }
    final List<ArtifactResult> writtenModules = new LinkedList<>();
    final List<ArtifactResult> externalDependencies = new LinkedList<>();
    final Set<String> directImports = new HashSet<>();
    loader.visitModules(new ModuleGraph.Visitor() {

        @Override
        public void visit(ModuleGraph.Module module) {
            if (module.artifact == null || module.artifact.artifact() == null)
                return;
            // FIXME: skip Maven modules?
            if (forImport || forSdkImport) {
                if (forImport && !module.artifact.groupId().equals("org.ceylon-lang")) {
                    externalDependencies.add(module.artifact);
                    return;
                }
                if (forSdkImport && !directlyListed(module.artifact.name())) {
                    if (!module.artifact.groupId().equals("org.ceylon-lang")) {
                        externalDependencies.add(module.artifact);
                    }
                    return;
                }
                makeMavenImportFolder(module, outputFolder, directImports);
                writtenModules.add(module.artifact);
            } else
                makeMavenModule(module, outputFolder, directImports);
        }
    });
    if (forImport || forSdkImport) {
        makeMavenImportSpecialFolders(writtenModules, externalDependencies, outputFolder, directImports);
    }
    flush();
}
Also used : ModuleSpec(org.eclipse.ceylon.common.ModuleSpec) ModuleGraph(org.eclipse.ceylon.cmr.ceylon.loader.ModuleGraph) ZipFile(java.util.zip.ZipFile) File(java.io.File) LinkedList(java.util.LinkedList) ArtifactResult(org.eclipse.ceylon.model.cmr.ArtifactResult) HashSet(java.util.HashSet) Module(org.eclipse.ceylon.cmr.ceylon.loader.ModuleGraph.Module)

Example 33 with ModuleSpec

use of org.eclipse.ceylon.common.ModuleSpec in project ceylon by eclipse.

the class CeylonBrowseTool method run.

@Override
public void run() throws Exception {
    for (ModuleSpec module : modules) {
        List<ModuleVersionDetails> versions = new ArrayList<ModuleVersionDetails>(getModuleVersions(getRepositoryManager(), module.getNamespace(), module.getName(), module.getVersion(), false, ModuleQuery.Type.ALL, null, null, null, null));
        Collections.sort(versions);
        if (versions.isEmpty()) {
            String err = getModuleNotFoundErrorMessage(getRepositoryManager(), module.getName(), module.getVersion());
            errorAppend(err);
            errorNewline();
            continue;
        }
        ModuleVersionDetails mvd = versions.get(versions.size() - 1);
        browseDoc(mvd);
    }
}
Also used : ModuleSpec(org.eclipse.ceylon.common.ModuleSpec) ModuleVersionDetails(org.eclipse.ceylon.cmr.api.ModuleVersionDetails) ArrayList(java.util.ArrayList)

Example 34 with ModuleSpec

use of org.eclipse.ceylon.common.ModuleSpec in project ceylon by eclipse.

the class CeylonClasspathTool method run.

@Override
public void run() throws Exception {
    // we do depend on having a Main
    loadModule(null, "org.eclipse.ceylon.java.main", Versions.CEYLON_VERSION_NUMBER);
    for (ModuleSpec module : modules) {
        String moduleName = module.getName();
        String version = checkModuleVersionsOrShowSuggestions(moduleName, module.isVersioned() ? module.getVersion() : null, ModuleQuery.Type.JVM, Versions.JVM_BINARY_MAJOR_VERSION, Versions.JVM_BINARY_MINOR_VERSION, // JS binary but don't care since JVM
        null, // JS binary but don't care since JVM
        null, null);
        if (version == null)
            continue;
        loadModule(null, moduleName, version);
        if (!force)
            errorOnConflictingModule(moduleName, version);
    }
    loader.resolve();
    loader.visitModules(new ModuleGraph.Visitor() {

        boolean once = true;

        @Override
        public void visit(Module module) {
            if (module.artifact != null) {
                File file = module.artifact.artifact();
                try {
                    if (file != null) {
                        if (once)
                            once = false;
                        else
                            append(File.pathSeparator);
                        append(file.getAbsolutePath());
                    }
                } catch (IOException x) {
                    // lame
                    throw new RuntimeException(x);
                }
            }
        }
    });
    flush();
}
Also used : ModuleSpec(org.eclipse.ceylon.common.ModuleSpec) IOException(java.io.IOException) ModuleGraph(org.eclipse.ceylon.cmr.ceylon.loader.ModuleGraph) Module(org.eclipse.ceylon.cmr.ceylon.loader.ModuleGraph.Module) File(java.io.File)

Example 35 with ModuleSpec

use of org.eclipse.ceylon.common.ModuleSpec in project ceylon by eclipse.

the class CeylonFatJarTool method run.

@Override
public void run() throws Exception {
    String firstModuleName = null, firstModuleVersion = null;
    for (ModuleSpec module : modules) {
        String moduleName = module.getName();
        String version = checkModuleVersionsOrShowSuggestions(moduleName, module.isVersioned() ? module.getVersion() : null, ModuleQuery.Type.JVM, Versions.JVM_BINARY_MAJOR_VERSION, Versions.JVM_BINARY_MINOR_VERSION, // JS binary but don't care since JVM
        null, // JS binary but don't care since JVM
        null, null);
        if (version == null)
            return;
        if (firstModuleName == null) {
            firstModuleName = moduleName;
            firstModuleVersion = version;
        }
        loadModule(null, moduleName, version);
        if (!force)
            errorOnConflictingModule(moduleName, version);
    }
    loader.resolve();
    String versionSuffix = firstModuleVersion != null && !firstModuleVersion.isEmpty() ? "-" + firstModuleVersion : "";
    File outputJar = applyCwd(out != null ? out : new File(firstModuleName + versionSuffix + ".jar"));
    if (outputJar.getParentFile() != null && !outputJar.getParentFile().exists()) {
        FileUtil.mkdirs(outputJar.getParentFile());
    }
    if (outputJar.exists()) {
        FileUtil.delete(outputJar);
    }
    final Set<String> added = new HashSet<>();
    if (firstModuleName != null && run != null && !run.contains("::") && !run.contains(".")) {
        run = firstModuleName + "::" + run;
    }
    Manifest manifest = new Manifest();
    Attributes mainAttributes = manifest.getMainAttributes();
    final String className = javaClassNameFromCeylon(firstModuleName, run);
    mainAttributes.putValue("Main-Class", className);
    mainAttributes.putValue("Manifest-Version", "1.0");
    mainAttributes.putValue("Created-By", "Ceylon fat-jar for module " + firstModuleName + "/" + firstModuleVersion);
    writeManifestEntries(mainAttributes);
    added.add("META-INF/");
    added.add("META-INF/MANIFEST.MF");
    addResources();
    try (JarOutputStream zipFile = new JarOutputStream(new FileOutputStream(outputJar), manifest)) {
        writeResources(zipFile);
        final List<ArtifactResult> staticMetamodelEntries = new ArrayList<>();
        loader.visitModules(new ModuleGraph.Visitor() {

            String runClassPath = className.replace('.', '/') + ".class";

            @Override
            public void visit(ModuleGraph.Module module) {
                if (module.artifact != null) {
                    File file = module.artifact.artifact();
                    try {
                        if (file != null) {
                            if (isVerbose()) {
                                append(file.getAbsolutePath());
                                newline();
                            }
                            staticMetamodelEntries.add(module.artifact);
                            try (ZipFile src = new ZipFile(file)) {
                                Enumeration<? extends ZipEntry> entries = src.entries();
                                while (entries.hasMoreElements()) {
                                    ZipEntry srcEntry = entries.nextElement();
                                    if (srcEntry.getName().equals(runClassPath))
                                        foundRun = true;
                                    // skip manifests
                                    if (skipEntry(srcEntry.getName()))
                                        continue;
                                    if (!added.add(srcEntry.getName())) {
                                        // multiple folders is fine
                                        if (!srcEntry.isDirectory()) {
                                            append("Warning: skipping duplicate entry ").append(srcEntry.getName()).append(" from ").append(file).newline();
                                        }
                                        continue;
                                    }
                                    srcEntry.setCompressedSize(-1);
                                    zipFile.putNextEntry(srcEntry);
                                    if (!srcEntry.isDirectory())
                                        IOUtils.copyStream(src.getInputStream(srcEntry), zipFile, true, false);
                                }
                            }
                        }
                    } catch (IOException x) {
                        // lame
                        throw new RuntimeException(x);
                    }
                }
            }
        });
        JvmBackendUtil.writeStaticMetamodel(zipFile, added, staticMetamodelEntries, jdkProvider, Collections.<String>emptySet());
        zipFile.flush();
    }
    flush();
    if (!foundRun) {
        append("Warning: missing run class ").append(className).newline();
    }
}
Also used : Enumeration(java.util.Enumeration) ZipEntry(java.util.zip.ZipEntry) Attributes(java.util.jar.Attributes) ArrayList(java.util.ArrayList) JarOutputStream(java.util.jar.JarOutputStream) IOException(java.io.IOException) Manifest(java.util.jar.Manifest) ArtifactResult(org.eclipse.ceylon.model.cmr.ArtifactResult) ModuleSpec(org.eclipse.ceylon.common.ModuleSpec) ZipFile(java.util.zip.ZipFile) FileOutputStream(java.io.FileOutputStream) ModuleGraph(org.eclipse.ceylon.cmr.ceylon.loader.ModuleGraph) ZipFile(java.util.zip.ZipFile) File(java.io.File) HashSet(java.util.HashSet)

Aggregations

ModuleSpec (org.eclipse.ceylon.common.ModuleSpec)35 File (java.io.File)18 ArtifactResult (org.eclipse.ceylon.model.cmr.ArtifactResult)13 ArrayList (java.util.ArrayList)11 ArtifactContext (org.eclipse.ceylon.cmr.api.ArtifactContext)7 IOException (java.io.IOException)6 Test (org.junit.Test)6 ZipFile (java.util.zip.ZipFile)5 ModuleGraph (org.eclipse.ceylon.cmr.ceylon.loader.ModuleGraph)5 HashSet (java.util.HashSet)4 LinkedList (java.util.LinkedList)4 ModuleVersionDetails (org.eclipse.ceylon.cmr.api.ModuleVersionDetails)4 ToolUsageError (org.eclipse.ceylon.common.tool.ToolUsageError)4 List (java.util.List)3 ZipEntry (java.util.zip.ZipEntry)3 RepositoryManager (org.eclipse.ceylon.cmr.api.RepositoryManager)3 Module (org.eclipse.ceylon.cmr.ceylon.loader.ModuleGraph.Module)3 Ignore (org.junit.Ignore)3 BufferedReader (java.io.BufferedReader)2 FileOutputStream (java.io.FileOutputStream)2