Kaynağa Gözat

Avoid calls to System.exit() and throw an exception instead

The exception is caught in Main and System.exit() is called.

Bug: 413522
Change-Id: Ibe68f7104d4fd55b832000a7840c07a169e7dd58
Signed-off-by: Guillaume Nodet <gnodet@gmail.com>
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
tags/v3.4.0.201405051725-m7
Guillaume Nodet 10 yıl önce
ebeveyn
işleme
977596b209

+ 23
- 0
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Die.java Dosyayı Görüntüle

public class Die extends RuntimeException { public class Die extends RuntimeException {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;


private boolean aborted;

/** /**
* Construct a new message explaining what has gone wrong. * Construct a new message explaining what has gone wrong.
* *
public Die(final String why, final Throwable cause) { public Die(final String why, final Throwable cause) {
super(why, cause); super(why, cause);
} }

/**
* Construct a new exception reflecting the fact that the
* command execution has been aborted before running.
*
* @param aborted boolean indicating the fact the execution has been aborted
* @since 3.4
*/
public Die(boolean aborted) {
this.aborted = aborted;
}

/**
* Check if this exception should cause the execution to be aborted.
*
* @return boolean indicating that the execution should be aborted
* @since 3.4
*/
public boolean isAborted() {
return aborted;
}
} }

+ 2
- 0
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Main.java Dosyayı Görüntüle

configureHttpProxy(); configureHttpProxy();
execute(argv); execute(argv);
} catch (Die err) { } catch (Die err) {
if (err.isAborted())
System.exit(1);
System.err.println(MessageFormat.format(CLIText.get().fatalError, err.getMessage())); System.err.println(MessageFormat.format(CLIText.get().fatalError, err.getMessage()));
if (showStackTrace) if (showStackTrace)
err.printStackTrace(); err.printStackTrace();

+ 12
- 2
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/TextBuiltin.java Dosyayı Görüntüle

} catch (CmdLineException err) { } catch (CmdLineException err) {
if (!help) { if (!help) {
this.errw.println(MessageFormat.format(CLIText.get().fatalError, err.getMessage())); this.errw.println(MessageFormat.format(CLIText.get().fatalError, err.getMessage()));
System.exit(1);
throw die(true);
} }
} }


errw.println(); errw.println();


errw.flush(); errw.flush();
System.exit(1);
throw die(true);
} }


/** /**
return new Die(why, cause); return new Die(why, cause);
} }


/**
* @param aborted
* boolean indicating that the execution has been aborted before running
* @return a runtime exception the caller is expected to throw
* @since 3.4
*/
protected static Die die(boolean aborted) {
return new Die(aborted);
}

String abbreviateRef(String dst, boolean abbreviateRemote) { String abbreviateRef(String dst, boolean abbreviateRemote) {
if (dst.startsWith(R_HEADS)) if (dst.startsWith(R_HEADS))
dst = dst.substring(R_HEADS.length()); dst = dst.substring(R_HEADS.length());

Loading…
İptal
Kaydet