use of org.eclipse.che.api.git.shared.Tag in project che by eclipse.
the class TagListWriter method writeTo.
/**
* @see MessageBodyWriter#writeTo(Object, Class, java.lang.reflect.Type, java.lang.annotation.Annotation[], javax.ws.rs.core.MediaType,
* javax.ws.rs.core.MultivaluedMap, java.io.OutputStream)
*/
@Override
public void writeTo(Iterable<Tag> tags, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws IOException, WebApplicationException {
Writer writer = new OutputStreamWriter(entityStream);
for (Tag tag : tags) {
writer.write(tag.getName());
writer.write('\n');
}
writer.flush();
}
use of org.eclipse.che.api.git.shared.Tag in project che by eclipse.
the class JGitConnection method branchList.
@Override
public List<Branch> branchList(BranchListMode listMode) throws GitException {
ListBranchCommand listBranchCommand = getGit().branchList();
if (LIST_ALL == listMode || listMode == null) {
listBranchCommand.setListMode(ListMode.ALL);
} else if (LIST_REMOTE == listMode) {
listBranchCommand.setListMode(ListMode.REMOTE);
}
List<Ref> refs;
String currentRef;
try {
refs = listBranchCommand.call();
String headBranch = getRepository().getBranch();
Optional<Ref> currentTag = getGit().tagList().call().stream().filter(tag -> tag.getObjectId().getName().equals(headBranch)).findFirst();
if (currentTag.isPresent()) {
currentRef = currentTag.get().getName();
} else {
currentRef = "refs/heads/" + headBranch;
}
} catch (GitAPIException | IOException exception) {
throw new GitException(exception.getMessage(), exception);
}
List<Branch> branches = new ArrayList<>();
for (Ref ref : refs) {
String refName = ref.getName();
boolean isCommitOrTag = Constants.HEAD.equals(refName);
String branchName = isCommitOrTag ? currentRef : refName;
String branchDisplayName;
if (isCommitOrTag) {
branchDisplayName = "(detached from " + Repository.shortenRefName(currentRef) + ")";
} else {
branchDisplayName = Repository.shortenRefName(refName);
}
Branch branch = newDto(Branch.class).withName(branchName).withActive(isCommitOrTag || refName.equals(currentRef)).withDisplayName(branchDisplayName).withRemote(refName.startsWith("refs/remotes"));
branches.add(branch);
}
return branches;
}
use of org.eclipse.che.api.git.shared.Tag in project che by eclipse.
the class JGitConnection method tagList.
@Override
public List<Tag> tagList(String patternStr) throws GitException {
Pattern pattern = null;
if (patternStr != null) {
StringBuilder sb = new StringBuilder();
for (int i = 0; i < patternStr.length(); i++) {
char c = patternStr.charAt(i);
if (c == '*' || c == '?') {
sb.append('.');
} else if (c == '.' || c == '(' || c == ')' || c == '[' || c == ']' || c == '^' || c == '$' || c == '|') {
sb.append('\\');
}
sb.append(c);
}
pattern = Pattern.compile(sb.toString());
}
Set<String> tagNames = repository.getTags().keySet();
List<Tag> tags = new ArrayList<>(tagNames.size());
for (String tagName : tagNames) {
if (pattern == null || pattern.matcher(tagName).matches()) {
tags.add(newDto(Tag.class).withName(tagName));
}
}
return tags;
}
use of org.eclipse.che.api.git.shared.Tag in project che by eclipse.
the class JGitConnection method tagCreate.
@Override
public Tag tagCreate(TagCreateParams params) throws GitException {
String commit = params.getCommit();
if (commit == null) {
commit = Constants.HEAD;
}
try {
RevWalk revWalk = new RevWalk(repository);
RevObject revObject;
try {
revObject = revWalk.parseAny(repository.resolve(commit));
} finally {
revWalk.close();
}
TagCommand tagCommand = getGit().tag().setName(params.getName()).setObjectId(revObject).setMessage(params.getMessage()).setForceUpdate(params.isForce());
GitUser tagger = getUser();
if (tagger != null) {
tagCommand.setTagger(new PersonIdent(tagger.getName(), tagger.getEmail()));
}
Ref revTagRef = tagCommand.call();
RevTag revTag = revWalk.parseTag(revTagRef.getLeaf().getObjectId());
return newDto(Tag.class).withName(revTag.getTagName());
} catch (IOException | GitAPIException exception) {
throw new GitException(exception.getMessage(), exception);
}
}
Aggregations