-
Notifications
You must be signed in to change notification settings - Fork 154
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,8 @@ | |
*/ | ||
package playRepository; | ||
|
||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.fasterxml.jackson.databind.node.ObjectNode; | ||
import controllers.UserApp; | ||
import controllers.routes; | ||
import models.Project; | ||
|
@@ -33,19 +35,20 @@ | |
import org.apache.commons.lang3.StringUtils; | ||
import org.apache.tika.Tika; | ||
import org.apache.tika.metadata.Metadata; | ||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.fasterxml.jackson.databind.node.ObjectNode; | ||
import org.eclipse.jgit.api.ArchiveCommand; | ||
import org.eclipse.jgit.api.Git; | ||
import org.eclipse.jgit.api.LogCommand; | ||
import org.eclipse.jgit.api.errors.GitAPIException; | ||
import org.eclipse.jgit.archive.ZipFormat; | ||
import org.eclipse.jgit.attributes.AttributesNode; | ||
import org.eclipse.jgit.attributes.AttributesNodeProvider; | ||
import org.eclipse.jgit.attributes.AttributesRule; | ||
import org.eclipse.jgit.blame.BlameResult; | ||
import org.eclipse.jgit.diff.*; | ||
import org.eclipse.jgit.diff.Edit.Type; | ||
import org.eclipse.jgit.errors.AmbiguousObjectException; | ||
import org.eclipse.jgit.errors.IncorrectObjectTypeException; | ||
import org.eclipse.jgit.errors.MissingObjectException; | ||
import org.eclipse.jgit.internal.storage.dfs.DfsRepository; | ||
import org.eclipse.jgit.lib.*; | ||
import org.eclipse.jgit.lib.RefUpdate.Result; | ||
import org.eclipse.jgit.revwalk.RevCommit; | ||
|
@@ -63,8 +66,9 @@ | |
import org.eclipse.jgit.util.io.NullOutputStream; | ||
import org.tmatesoft.svn.core.SVNException; | ||
import play.Logger; | ||
import play.api.Play; | ||
import play.libs.Json; | ||
import play.mvc.Results.Chunks; | ||
import utils.ChunkedOutputStream; | ||
import utils.FileUtil; | ||
import utils.GravatarUtil; | ||
|
||
|
@@ -1940,4 +1944,23 @@ public File getDirectory() { | |
public Repository getRepository() { | ||
return repository; | ||
} | ||
|
||
public void getArchive(Chunks.Out<byte[]> out, String branchName){ | ||
Git git = new Git(getRepository()); | ||
ArchiveCommand.registerFormat("zip", new ZipFormat()); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
doortts
Author
Collaborator
|
||
try { | ||
ChunkedOutputStream cos = new ChunkedOutputStream(out, 16384); | ||
git.archive() | ||
.setTree(getRepository().resolve(branchName)) | ||
.setFormat("zip") | ||
.setOutputStream(cos) | ||
.call(); | ||
} catch (IncorrectObjectTypeException | AmbiguousObjectException | GitAPIException e) { | ||
play.Logger.error(e.getMessage()); | ||
} catch (IOException e){ | ||
play.Logger.error(e.getMessage()); | ||
} finally{ | ||
ArchiveCommand.unregisterFormat("zip"); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
/** | ||
* Yona, 21st Century Project Hosting SW | ||
* <p> | ||
* Copyright Yona & Yobi Authors & NAVER Corp. | ||
* https://yona.io | ||
**/ | ||
|
||
package utils; | ||
|
||
import play.mvc.Results.Chunks; | ||
|
||
import java.io.IOException; | ||
import java.io.OutputStream; | ||
|
||
// | ||
// ChunkedOutputStream is made by referring to BufferedOutputStream.java | ||
// | ||
public class ChunkedOutputStream extends OutputStream { | ||
|
||
Chunks.Out<byte[]> out; | ||
/** | ||
* The internal buffer where data is stored. | ||
*/ | ||
protected byte buf[]; | ||
|
||
/** | ||
* The number of valid bytes in the buffer. This value is always | ||
* in the range <tt>0</tt> through <tt>buf.length</tt>; elements | ||
* <tt>buf[0]</tt> through <tt>buf[count-1]</tt> contain valid | ||
* byte data. | ||
*/ | ||
protected int count; | ||
|
||
public ChunkedOutputStream(Chunks.Out<byte[]> out, int size) { | ||
if (size <= 0) { | ||
buf = new byte[16384]; | ||
} else { | ||
buf = new byte[size]; | ||
} | ||
this.out = out; | ||
} | ||
|
||
/** | ||
* Writes the specified byte to this buffered output stream. | ||
* | ||
* @param b the byte to be written. | ||
* @exception IOException if an I/O error occurs. | ||
*/ | ||
@Override | ||
public synchronized void write(int b) throws IOException { | ||
if (count >= buf.length) { | ||
flushBuffer(); | ||
} | ||
buf[count++] = (byte)b; | ||
} | ||
|
||
public void write(byte b[]) throws IOException { | ||
throw new UnsupportedOperationException("write(byte b[])"); | ||
} | ||
|
||
/** | ||
* Writes <code>len</code> bytes from the specified byte array | ||
* starting at offset <code>off</code> to this buffered output stream. | ||
* | ||
* <p> Ordinarily this method stores bytes from the given array into this | ||
* stream's buffer, flushing the buffer to the underlying output stream as | ||
* needed. If the requested length is at least as large as this stream's | ||
* buffer, however, then this method will flush the buffer and write the | ||
* bytes directly to the underlying output stream. Thus redundant | ||
* <code>BufferedOutputStream</code>s will not copy data unnecessarily. | ||
* | ||
* @param b the data. | ||
* @param off the start offset in the data. | ||
* @param len the number of bytes to write. | ||
* @exception IOException if an I/O error occurs. | ||
*/ | ||
@Override | ||
public synchronized void write(byte b[], int off, int len) throws IOException { | ||
if (len >= buf.length) { | ||
/* If the request length exceeds the size of the output buffer, | ||
flush the output buffer and then write the data directly. | ||
In this way buffered streams will cascade harmlessly. */ | ||
flushBuffer(); | ||
write(b, off, len); | ||
return; | ||
} | ||
if (len > buf.length - count) { | ||
flushBuffer(); | ||
} | ||
System.arraycopy(b, off, buf, count, len); | ||
count += len; | ||
} | ||
|
||
private void flushBuffer() throws IOException { | ||
if (count > 0) { | ||
chunkOut(); | ||
} | ||
} | ||
|
||
@Override | ||
public void close() throws IOException { | ||
if (count > 0) { | ||
chunkOut(); | ||
} | ||
out.close(); | ||
} | ||
|
||
private void chunkOut() { | ||
byte remainBuf[] = new byte[count]; | ||
System.arraycopy(buf, 0, remainBuf,0, count); | ||
out.write(remainBuf); | ||
count = 0; | ||
} | ||
} |
제가 JGit을 잘 몰라서 드리는 질문인데, Multi thread 문제는 없을까요? 즉 아래와 같은순서로 실행되어도 상관이 없는지 궁금합니다.