Search in sources :

Example 11 with Branch

use of org.eclipse.che.api.git.shared.Branch in project che by eclipse.

the class BranchListWriter 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<Branch> branches, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws IOException, WebApplicationException {
    Writer writer = new OutputStreamWriter(entityStream);
    for (Branch branch : branches) {
        if (branch.isActive()) {
            writer.write('*');
        } else {
            writer.write(' ');
        }
        writer.write(' ');
        if (branch.getName().startsWith("refs/remotes")) {
            // trim leading 'refs/'
            writer.write(branch.getName().substring(5));
        } else {
            writer.write(branch.getDisplayName());
        }
        writer.write('\n');
    }
    writer.flush();
}
Also used : Branch(org.eclipse.che.api.git.shared.Branch) OutputStreamWriter(java.io.OutputStreamWriter) MessageBodyWriter(javax.ws.rs.ext.MessageBodyWriter) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter)

Aggregations

Branch (org.eclipse.che.api.git.shared.Branch)11 List (java.util.List)6 Operation (org.eclipse.che.api.promises.client.Operation)4 OperationException (org.eclipse.che.api.promises.client.OperationException)4 PromiseError (org.eclipse.che.api.promises.client.PromiseError)4 ArrayList (java.util.ArrayList)3 GitException (org.eclipse.che.api.git.exception.GitException)3 GitOutputConsole (org.eclipse.che.ide.ext.git.client.outputconsole.GitOutputConsole)3 File (java.io.File)2 IOException (java.io.IOException)2 Map (java.util.Map)2 Optional (java.util.Optional)2 GitConnection (org.eclipse.che.api.git.GitConnection)2 GitConflictException (org.eclipse.che.api.git.exception.GitConflictException)2 GitInvalidRefNameException (org.eclipse.che.api.git.exception.GitInvalidRefNameException)2 GitRefAlreadyExistsException (org.eclipse.che.api.git.exception.GitRefAlreadyExistsException)2 GitRefNotFoundException (org.eclipse.che.api.git.exception.GitRefNotFoundException)2 DiffCommitFile (org.eclipse.che.api.git.shared.DiffCommitFile)2 Revision (org.eclipse.che.api.git.shared.Revision)2 CheckoutCommand (org.eclipse.jgit.api.CheckoutCommand)2