Merge branch 'stable-3.3'

* stable-3.3:
  Prepare 3.3.2-SNAPSHOT builds
  JGit v3.3.1.201403241930-r
  Retry to call credentials provider if http authentication failed
  Ensure that ssh authentication is retried only in JGit
  [findBugs] Ensure streams are closed in a finally block
  Update com.jcraft.jsch to 0.1.50 also in pom dependencies

Change-Id: I45b48a3f2dc8c7708e9518645d72bc5645002836
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
This commit is contained in:
Matthias Sohn 2014-03-25 11:03:56 +01:00
commit 5c1736a8d8
4 changed files with 25 additions and 14 deletions

View File

@ -714,26 +714,27 @@ public int compare(PackExt o1, PackExt o2) {
JGitText.get().cannotCreateIndexfile, tmpIdx.getPath())); JGitText.get().cannotCreateIndexfile, tmpIdx.getPath()));
// write the packfile // write the packfile
@SuppressWarnings("resource" /* java 7 */) FileOutputStream fos = new FileOutputStream(tmpPack);
FileChannel channel = new FileOutputStream(tmpPack).getChannel(); FileChannel channel = fos.getChannel();
OutputStream channelStream = Channels.newOutputStream(channel); OutputStream channelStream = Channels.newOutputStream(channel);
try { try {
pw.writePack(pm, pm, channelStream); pw.writePack(pm, pm, channelStream);
} finally { } finally {
channel.force(true); channel.force(true);
channelStream.close(); channelStream.close();
channel.close(); fos.close();
} }
// write the packindex // write the packindex
FileChannel idxChannel = new FileOutputStream(tmpIdx).getChannel(); fos = new FileOutputStream(tmpIdx);
FileChannel idxChannel = fos.getChannel();
OutputStream idxStream = Channels.newOutputStream(idxChannel); OutputStream idxStream = Channels.newOutputStream(idxChannel);
try { try {
pw.writeIndex(idxStream); pw.writeIndex(idxStream);
} finally { } finally {
idxChannel.force(true); idxChannel.force(true);
idxStream.close(); idxStream.close();
idxChannel.close(); fos.close();
} }
if (pw.prepareBitmapIndex(pm)) { if (pw.prepareBitmapIndex(pm)) {
@ -745,14 +746,15 @@ public int compare(PackExt o1, PackExt o2) {
JGitText.get().cannotCreateIndexfile, JGitText.get().cannotCreateIndexfile,
tmpBitmapIdx.getPath())); tmpBitmapIdx.getPath()));
idxChannel = new FileOutputStream(tmpBitmapIdx).getChannel(); fos = new FileOutputStream(tmpBitmapIdx);
idxChannel = fos.getChannel();
idxStream = Channels.newOutputStream(idxChannel); idxStream = Channels.newOutputStream(idxChannel);
try { try {
pw.writeBitmapIndex(idxStream); pw.writeBitmapIndex(idxStream);
} finally { } finally {
idxChannel.force(true); idxChannel.force(true);
idxStream.close(); idxStream.close();
idxChannel.close(); fos.close();
} }
} }

View File

@ -82,8 +82,12 @@ public Note merge(Note base, Note ours, Note theirs, ObjectReader reader,
ObjectLoader lt = reader.open(theirs.getData()); ObjectLoader lt = reader.open(theirs.getData());
UnionInputStream union = new UnionInputStream(lo.openStream(), UnionInputStream union = new UnionInputStream(lo.openStream(),
lt.openStream()); lt.openStream());
ObjectId noteData = inserter.insert(Constants.OBJ_BLOB, try {
lo.getSize() + lt.getSize(), union); ObjectId noteData = inserter.insert(Constants.OBJ_BLOB,
return new Note(ours, noteData); lo.getSize() + lt.getSize(), union);
return new Note(ours, noteData);
} finally {
union.close();
}
} }
} }

View File

@ -148,6 +148,9 @@ private Session createSession(CredentialsProvider credentialsProvider,
FS fs, String user, final String pass, String host, int port, FS fs, String user, final String pass, String host, int port,
final OpenSshConfig.Host hc) throws JSchException { final OpenSshConfig.Host hc) throws JSchException {
final Session session = createSession(hc, user, host, port, fs); final Session session = createSession(hc, user, host, port, fs);
// We retry already in getSession() method. JSch must not retry
// on its own.
session.setConfig("MaxAuthTries", "1"); //$NON-NLS-1$ //$NON-NLS-2$
if (pass != null) if (pass != null)
session.setPassword(pass); session.setPassword(pass);
final String strictHostKeyCheckingPolicy = hc final String strictHostKeyCheckingPolicy = hc

View File

@ -471,12 +471,14 @@ private HttpConnection connect(final String service)
if (authMethod == HttpAuthMethod.NONE) if (authMethod == HttpAuthMethod.NONE)
throw new TransportException(uri, MessageFormat.format( throw new TransportException(uri, MessageFormat.format(
JGitText.get().authenticationNotSupported, uri)); JGitText.get().authenticationNotSupported, uri));
if (1 < authAttempts CredentialsProvider credentialsProvider = getCredentialsProvider();
|| !authMethod.authorize(uri, if (3 < authAttempts
getCredentialsProvider())) { || !authMethod.authorize(uri, credentialsProvider)) {
credentialsProvider.reset(uri);
throw new TransportException(uri, throw new TransportException(uri,
JGitText.get().notAuthorized); JGitText.get().notAuthorized);
} }
credentialsProvider.reset(uri);
authAttempts++; authAttempts++;
continue; continue;
@ -504,7 +506,7 @@ final HttpConnection httpOpen(URL u) throws IOException {
/** /**
* Open an HTTP connection. * Open an HTTP connection.
* *
* @param method * @param method
* @param u * @param u
* @return the connection * @return the connection