本文整理汇总了Java中org.eclipse.jgit.api.ArchiveCommand类的典型用法代码示例。如果您正苦于以下问题:Java ArchiveCommand类的具体用法?Java ArchiveCommand怎么用?Java ArchiveCommand使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ArchiveCommand类属于org.eclipse.jgit.api包,在下文中一共展示了ArchiveCommand类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getRepositoryZip
import org.eclipse.jgit.api.ArchiveCommand; //导入依赖的package包/类
/** 커밋을 입력받으면 당시 파일들을 압축하여 사용자에게 보내줌.
* @param commitName
* @param format
* @param response
*/
public void getRepositoryZip(String commitName,String format, HttpServletResponse response) {
try {
ArchiveCommand.registerFormat("zip", new ZipFormat());
ArchiveCommand.registerFormat("tar", new TarFormat());
ObjectId revId = this.localRepo.resolve(commitName);
git.archive().setOutputStream(response.getOutputStream())
.setFormat(format)
.setTree(revId)
.call();
ArchiveCommand.unregisterFormat("zip");
ArchiveCommand.unregisterFormat("tar");
response.flushBuffer();
} catch (Exception e) {
System.err.println(e.getMessage());
}
}
示例2: getProjectZip
import org.eclipse.jgit.api.ArchiveCommand; //导入依赖的package包/类
/** 커밋을 입력받으면 당시 파일들을 압축하여 사용자에게 보내줌.
* @param commitName
* @param format
* @param response
*/
public void getProjectZip(String commitName,String format, HttpServletResponse response) {
try {
ArchiveCommand.registerFormat("zip", new ZipFormat());
ArchiveCommand.registerFormat("tar", new TarFormat());
ObjectId revId = this.localRepo.resolve(commitName);
git.archive().setOutputStream(response.getOutputStream())
.setFormat(format)
.setTree(revId)
.call();
ArchiveCommand.unregisterFormat("zip");
ArchiveCommand.unregisterFormat("tar");
response.flushBuffer();
} catch (Exception e) {
System.err.println(e.getMessage());
}
}
示例3: getConfiguration
import org.eclipse.jgit.api.ArchiveCommand; //导入依赖的package包/类
/**
* Export the git tag identified by the entry id
*
* @param config
* @param e
* @param exportDirectory
* @throws Exception
*/
public void getConfiguration(Configuration config, Entry e, File exportDirectory) throws Exception {
Preconditions.checkNotNull(config, "Configuration must be supplied.");
Preconditions.checkNotNull(e, "Entry must be supplied.");
Preconditions.checkNotNull(exportDirectory, "Directory must be supplied.");
File zip = new File(exportDirectory, e.getUUID().toString()+".zip");
ArchiveCommand.registerFormat("zip", new ZipFormat());
try (FileOutputStream out = new FileOutputStream(zip);){
LOG.debug("Exporting tag {} to {}", e.getUUID(), zip);
git.archive().setTree(git.getRepository().resolve(e.getUUID().toString()))
.setFormat("zip")
.setOutputStream(out)
.call();
unzip(zip);
} catch (IOException | RevisionSyntaxException | GitAPIException ioe) {
zip.delete();
LOG.error("Error creating archive from tag: " + e.getUUID().toString(), ioe);
throw ioe;
} finally {
ArchiveCommand.unregisterFormat("zip");
}
}
示例4: main
import org.eclipse.jgit.api.ArchiveCommand; //导入依赖的package包/类
public static void main(String[] args) throws IOException, GitAPIException {
try (Repository repository = CookbookHelper.openJGitCookbookRepository()) {
File file = File.createTempFile("test", ".mzip");
// make the archive format known
ArchiveCommand.registerFormat("myzip", new ZipArchiveFormat());
try {
// this is the file that we write the archive to
try (OutputStream out = new FileOutputStream(file)) {
// finally call the ArchiveCommand to write out using the given format
try (Git git = new Git(repository)) {
git.archive()
.setTree(repository.resolve("master"))
.setFormat("myzip")
.setOutputStream(out)
.call();
}
}
} finally {
ArchiveCommand.unregisterFormat("myzip");
}
System.out.println("Wrote " + file.length() + " bytes to " + file);
}
}
示例5: apply
import org.eclipse.jgit.api.ArchiveCommand; //导入依赖的package包/类
@Override
public BinaryResult apply(RevisionResource rsrc)
throws BadRequestException, IOException, MethodNotAllowedException {
if (Strings.isNullOrEmpty(format)) {
throw new BadRequestException("format is not specified");
}
final ArchiveFormat f = allowedFormats.extensions.get("." + format);
if (f == null) {
throw new BadRequestException("unknown archive format");
}
if (f == ArchiveFormat.ZIP) {
throw new MethodNotAllowedException("zip format is disabled");
}
boolean close = true;
final Repository repo = repoManager.openRepository(rsrc.getProject());
try {
final RevCommit commit;
String name;
try (RevWalk rw = new RevWalk(repo)) {
commit = rw.parseCommit(ObjectId.fromString(rsrc.getPatchSet().getRevision().get()));
name = name(f, rw, commit);
}
BinaryResult bin =
new BinaryResult() {
@Override
public void writeTo(OutputStream out) throws IOException {
try {
new ArchiveCommand(repo)
.setFormat(f.name())
.setTree(commit.getTree())
.setOutputStream(out)
.call();
} catch (GitAPIException e) {
throw new IOException(e);
}
}
@Override
public void close() throws IOException {
repo.close();
}
};
bin.disableGzip().setContentType(f.getMimeType()).setAttachmentName(name);
close = false;
return bin;
} finally {
if (close) {
repo.close();
}
}
}