Search in sources :

Example 1 with RepositoryException

use of org.eclipse.ceylon.model.cmr.RepositoryException in project ceylon by eclipse.

the class CeylonMavenExportTool method makeMavenModule.

protected void makeMavenModule(Module module, File outputFolder, Set<String> directImports) {
    String groupId = module.artifact.groupId();
    String artifactId = module.artifact.artifactId();
    String path = groupId.replace('.', '/') + "/" + artifactId + "/" + module.version;
    File folder = new File(outputFolder, path);
    FileUtil.mkdirs(folder);
    String mavenFileName = artifactId + "-" + module.version;
    try {
        File jarFile = new File(folder, mavenFileName + ".jar");
        File pomFile = new File(folder, mavenFileName + ".pom");
        Files.copy(module.artifact.artifact().toPath(), jarFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
        // extract its pom.xml too
        try (ZipFile zf = new ZipFile(module.artifact.artifact())) {
            ZipEntry pomEntry = zf.getEntry("META-INF/maven/" + groupId + "/" + artifactId + "/pom.xml");
            if (pomEntry != null) {
                try (InputStream is = zf.getInputStream(pomEntry)) {
                    Files.copy(is, pomFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
                }
            } else {
                generatePomFromModule(pomFile, module.artifact, directImports);
            }
        }
        // now sha1 them
        ShaSigner.sign(jarFile, null, false);
        ShaSigner.sign(pomFile, null, false);
    } catch (RepositoryException | IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
Also used : ZipFile(java.util.zip.ZipFile) InputStream(java.io.InputStream) ZipEntry(java.util.zip.ZipEntry) RepositoryException(org.eclipse.ceylon.model.cmr.RepositoryException) IOException(java.io.IOException) ZipFile(java.util.zip.ZipFile) File(java.io.File)

Example 2 with RepositoryException

use of org.eclipse.ceylon.model.cmr.RepositoryException in project ceylon by eclipse.

the class AbstractNodeRepositoryManager method putArtifact.

public void putArtifact(ArtifactContext context, InputStream content) throws RepositoryException {
    try {
        final Node parent = getOrCreateParent(context);
        log.debug("Adding artifact " + context + " to cache " + cache.getDisplayString());
        log.debug(" -> " + NodeUtils.getFullPath(parent));
        final String[] names = cache.getArtifactNames(context);
        if (names.length != 1) {
            throw new RepositoryException("ArtifactContext should have a single suffix");
        }
        final String label = names[0];
        try {
            if (parent instanceof OpenNode) {
                final OpenNode on = (OpenNode) parent;
                if (on.addContent(label, content, context) == null)
                    addContent(context, parent, label, content);
            } else {
                addContent(context, parent, label, content);
            }
        } catch (IOException e) {
            throw new RepositoryException(e);
        }
        log.debug(" -> [done]");
    } finally {
        IOUtils.safeClose(content);
    }
}
Also used : OpenNode(org.eclipse.ceylon.cmr.spi.OpenNode) Node(org.eclipse.ceylon.cmr.spi.Node) RepositoryException(org.eclipse.ceylon.model.cmr.RepositoryException) IOException(java.io.IOException) OpenNode(org.eclipse.ceylon.cmr.spi.OpenNode)

Example 3 with RepositoryException

use of org.eclipse.ceylon.model.cmr.RepositoryException in project ceylon by eclipse.

the class AbstractNodeRepositoryManager method downloadZipped.

private ArtifactResult downloadZipped(Node node, ArtifactContext context) {
    ArtifactContext zippedContext = context.getZipContext();
    ArtifactResult zipResult = getArtifactResult(zippedContext);
    if (zipResult != null) {
        String zipName = zipResult.artifact().getName();
        File unzippedFolder = new File(zipResult.artifact().getParentFile(), zipName.substring(0, zipName.length() - 4));
        try {
            IOUtils.extractArchive(zipResult.artifact(), unzippedFolder);
        } catch (IOException e) {
            throw new RepositoryException("Failed to unzip folder downloaded from Herd: " + zipResult.artifact(), e);
        }
        return new FileArtifactResult(zipResult.repository(), this, zipResult.name(), zipResult.version(), unzippedFolder, zipResult.repositoryDisplayString());
    } else {
        return null;
    }
}
Also used : ArtifactContext(org.eclipse.ceylon.cmr.api.ArtifactContext) RepositoryException(org.eclipse.ceylon.model.cmr.RepositoryException) IOException(java.io.IOException) File(java.io.File) ArtifactResult(org.eclipse.ceylon.model.cmr.ArtifactResult)

Example 4 with RepositoryException

use of org.eclipse.ceylon.model.cmr.RepositoryException in project ceylon by eclipse.

the class AbstractNodeRepositoryManager method isSameFile.

// Check if the source file and destination node point to the same file
@Override
public boolean isSameFile(ArtifactContext context, File srcFile) throws RepositoryException {
    boolean same = false;
    if (!cache.getRoot().isRemote()) {
        Node dstParent = getOrCreateParent(context);
        Node newChild = dstParent.getChild(srcFile.getName());
        if (newChild != null) {
            try {
                File existing = newChild.getContent(File.class);
                same = FileUtil.sameFile(srcFile, existing);
            } catch (IOException e) {
                throw new RepositoryException(e);
            }
        }
    }
    return same;
}
Also used : OpenNode(org.eclipse.ceylon.cmr.spi.OpenNode) Node(org.eclipse.ceylon.cmr.spi.Node) RepositoryException(org.eclipse.ceylon.model.cmr.RepositoryException) IOException(java.io.IOException) File(java.io.File)

Example 5 with RepositoryException

use of org.eclipse.ceylon.model.cmr.RepositoryException in project ceylon by eclipse.

the class AbstractNodeRepositoryManager method removeArtifact.

public void removeArtifact(ArtifactContext context) throws RepositoryException {
    Node parent = getFromCacheNode(context, false);
    log.debug("Remove artifact " + context + " to repository " + cache.getDisplayString());
    if (parent != null) {
        final String[] labels = cache.getArtifactNames(context);
        for (String label : labels) {
            try {
                removeNode(parent, label);
            } catch (IOException e) {
                throw new RepositoryException(e);
            }
        }
        log.debug(" -> [done]");
    } else {
        log.debug(" -> No such artifact: " + context);
    }
}
Also used : OpenNode(org.eclipse.ceylon.cmr.spi.OpenNode) Node(org.eclipse.ceylon.cmr.spi.Node) RepositoryException(org.eclipse.ceylon.model.cmr.RepositoryException) IOException(java.io.IOException)

Aggregations

RepositoryException (org.eclipse.ceylon.model.cmr.RepositoryException)16 IOException (java.io.IOException)15 File (java.io.File)11 Node (org.eclipse.ceylon.cmr.spi.Node)5 OpenNode (org.eclipse.ceylon.cmr.spi.OpenNode)5 ArtifactContext (org.eclipse.ceylon.cmr.api.ArtifactContext)3 ArtifactResult (org.eclipse.ceylon.model.cmr.ArtifactResult)3 ZipFile (java.util.zip.ZipFile)2 BufferedReader (java.io.BufferedReader)1 FileInputStream (java.io.FileInputStream)1 FileWriter (java.io.FileWriter)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 PrintWriter (java.io.PrintWriter)1 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 TreeSet (java.util.TreeSet)1 ZipEntry (java.util.zip.ZipEntry)1 DefaultRepositorySystemSession (org.eclipse.aether.DefaultRepositorySystemSession)1