* stable-3.5: Prepare 3.5.1-SNAPSHOT builds JGit v3.5.0.201409260305-r Fix PackWriterBitmapWalker handling non-existing uninteresting objects Enable maven site generation for jgit Generate javadocs as part of Maven site project reports Compare API changes with clirr against 3.4.1 [cli] Use chaining credentials provider to enable .netrc Add chaining credentials provider [Java 8] Configure doclint to accept missing descriptions Do not use .netrc implicitly if no CredentialsProvider was set Prepare post 3.5.0-rc1 builds JGit 3.5.0.201409071800-rc1 Fix the ls-remote command when there is no local repo Change-Id: Iaa4485cac6ff9c7917380e89e12e416e0f52a557 Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>tags/v3.6.0.201411121045-m1
import java.io.Console; | import java.io.Console; | ||||
import org.eclipse.jgit.errors.UnsupportedCredentialItem; | import org.eclipse.jgit.errors.UnsupportedCredentialItem; | ||||
import org.eclipse.jgit.transport.ChainingCredentialsProvider; | |||||
import org.eclipse.jgit.transport.CredentialItem; | import org.eclipse.jgit.transport.CredentialItem; | ||||
import org.eclipse.jgit.transport.CredentialsProvider; | import org.eclipse.jgit.transport.CredentialsProvider; | ||||
import org.eclipse.jgit.transport.NetRCCredentialsProvider; | |||||
import org.eclipse.jgit.transport.URIish; | import org.eclipse.jgit.transport.URIish; | ||||
/** Interacts with the user during authentication by using the text console. */ | /** Interacts with the user during authentication by using the text console. */ | ||||
if (c.cons == null) | if (c.cons == null) | ||||
throw new NoClassDefFoundError( | throw new NoClassDefFoundError( | ||||
ConsoleText.get().noSystemConsoleAvailable); | ConsoleText.get().noSystemConsoleAvailable); | ||||
CredentialsProvider.setDefault(c); | |||||
CredentialsProvider cp = new ChainingCredentialsProvider( | |||||
new NetRCCredentialsProvider(), c); | |||||
CredentialsProvider.setDefault(cp); | |||||
} | } | ||||
private final Console cons = System.console(); | private final Console cons = System.console(); |
} | } | ||||
} | } | ||||
@Override | |||||
protected boolean requiresRepository() { | |||||
return false; | |||||
} | |||||
private void show(final AnyObjectId id, final String name) | private void show(final AnyObjectId id, final String name) | ||||
throws IOException { | throws IOException { | ||||
outw.print(id.name()); | outw.print(id.name()); |
import java.io.File; | import java.io.File; | ||||
import java.io.FileOutputStream; | import java.io.FileOutputStream; | ||||
import java.io.IOException; | import java.io.IOException; | ||||
import java.text.ParseException; | |||||
import java.util.ArrayList; | import java.util.ArrayList; | ||||
import java.util.Arrays; | import java.util.Arrays; | ||||
import java.util.Collections; | import java.util.Collections; | ||||
// shouldn't throw anything | // shouldn't throw anything | ||||
} | } | ||||
/** | |||||
* Try to pass non-existing object as uninteresting, with ignoring setting. | |||||
* Use a repo with bitmap indexes because then PackWriter will use | |||||
* PackWriterBitmapWalker which had problems with this situation. | |||||
* | |||||
* @throws IOException | |||||
* @throws ParseException | |||||
*/ | |||||
@Test | |||||
public void testIgnoreNonExistingObjectsWithBitmaps() throws IOException, | |||||
ParseException { | |||||
final ObjectId nonExisting = ObjectId | |||||
.fromString("0000000000000000000000000000000000000001"); | |||||
new GC(db).gc(); | |||||
createVerifyOpenPack(EMPTY_SET_OBJECT, | |||||
Collections.singleton(nonExisting), false, true, true); | |||||
// shouldn't throw anything | |||||
} | |||||
/** | /** | ||||
* Create pack basing on only interesting objects, then precisely verify | * Create pack basing on only interesting objects, then precisely verify | ||||
* content. No delta reuse here. | * content. No delta reuse here. | ||||
final Set<ObjectId> uninterestings, final boolean thin, | final Set<ObjectId> uninterestings, final boolean thin, | ||||
final boolean ignoreMissingUninteresting) | final boolean ignoreMissingUninteresting) | ||||
throws MissingObjectException, IOException { | throws MissingObjectException, IOException { | ||||
createVerifyOpenPack(interestings, uninterestings, thin, | |||||
ignoreMissingUninteresting, false); | |||||
} | |||||
private void createVerifyOpenPack(final Set<ObjectId> interestings, | |||||
final Set<ObjectId> uninterestings, final boolean thin, | |||||
final boolean ignoreMissingUninteresting, boolean useBitmaps) | |||||
throws MissingObjectException, IOException { | |||||
NullProgressMonitor m = NullProgressMonitor.INSTANCE; | NullProgressMonitor m = NullProgressMonitor.INSTANCE; | ||||
writer = new PackWriter(config, db.newObjectReader()); | writer = new PackWriter(config, db.newObjectReader()); | ||||
writer.setUseBitmaps(useBitmaps); | |||||
writer.setThin(thin); | writer.setThin(thin); | ||||
writer.setIgnoreMissingUninteresting(ignoreMissingUninteresting); | writer.setIgnoreMissingUninteresting(ignoreMissingUninteresting); | ||||
writer.preparePack(m, interestings, uninterestings); | writer.preparePack(m, interestings, uninterestings); |
Set<? extends ObjectId> have) | Set<? extends ObjectId> have) | ||||
throws MissingObjectException, IncorrectObjectTypeException, | throws MissingObjectException, IncorrectObjectTypeException, | ||||
IOException { | IOException { | ||||
BitmapBuilder haveBitmap = bitmapWalker.findObjects(have, null); | |||||
BitmapBuilder haveBitmap = bitmapWalker.findObjects(have, null, true); | |||||
bitmapWalker.reset(); | bitmapWalker.reset(); | ||||
BitmapBuilder wantBitmap = bitmapWalker.findObjects(want, haveBitmap); | |||||
BitmapBuilder wantBitmap = bitmapWalker.findObjects(want, haveBitmap, | |||||
false); | |||||
BitmapBuilder needBitmap = wantBitmap.andNot(haveBitmap); | BitmapBuilder needBitmap = wantBitmap.andNot(haveBitmap); | ||||
if (useCachedPacks && reuseSupport != null | if (useCachedPacks && reuseSupport != null | ||||
walker = bitmapPreparer.newBitmapWalker(); | walker = bitmapPreparer.newBitmapWalker(); | ||||
BitmapBuilder bitmap = walker.findObjects( | BitmapBuilder bitmap = walker.findObjects( | ||||
Collections.singleton(cmit), null); | |||||
Collections.singleton(cmit), null, false); | |||||
if (last != null && cmit.isReuseWalker() && !bitmap.contains(last)) | if (last != null && cmit.isReuseWalker() && !bitmap.contains(last)) | ||||
throw new IllegalStateException(MessageFormat.format( | throw new IllegalStateException(MessageFormat.format( |
this.pm = (pm == null) ? NullProgressMonitor.INSTANCE : pm; | this.pm = (pm == null) ? NullProgressMonitor.INSTANCE : pm; | ||||
} | } | ||||
BitmapBuilder findObjects(Set<? extends ObjectId> start, BitmapBuilder seen) | |||||
BitmapBuilder findObjects(Set<? extends ObjectId> start, BitmapBuilder seen, boolean ignoreMissingStart) | |||||
throws MissingObjectException, IncorrectObjectTypeException, | throws MissingObjectException, IncorrectObjectTypeException, | ||||
IOException { | IOException { | ||||
final BitmapBuilder bitmapResult = bitmapIndex.newBitmapBuilder(); | final BitmapBuilder bitmapResult = bitmapIndex.newBitmapBuilder(); | ||||
boolean marked = false; | boolean marked = false; | ||||
for (ObjectId obj : start) { | for (ObjectId obj : start) { | ||||
if (!bitmapResult.contains(obj)) { | |||||
walker.markStart(walker.parseAny(obj)); | |||||
marked = true; | |||||
try { | |||||
if (!bitmapResult.contains(obj)) { | |||||
walker.markStart(walker.parseAny(obj)); | |||||
marked = true; | |||||
} | |||||
} catch (MissingObjectException e) { | |||||
if (ignoreMissingStart) | |||||
continue; | |||||
throw e; | |||||
} | } | ||||
} | } | ||||
/* | |||||
* Copyright (C) 2014, Matthias Sohn <matthias.sohn@sap.com> | |||||
* and other copyright owners as documented in the project's IP log. | |||||
* | |||||
* This program and the accompanying materials are made available | |||||
* under the terms of the Eclipse Distribution License v1.0 which | |||||
* accompanies this distribution, is reproduced below, and is | |||||
* available at http://www.eclipse.org/org/documents/edl-v10.php | |||||
* | |||||
* All rights reserved. | |||||
* | |||||
* Redistribution and use in source and binary forms, with or | |||||
* without modification, are permitted provided that the following | |||||
* conditions are met: | |||||
* | |||||
* - Redistributions of source code must retain the above copyright | |||||
* notice, this list of conditions and the following disclaimer. | |||||
* | |||||
* - Redistributions in binary form must reproduce the above | |||||
* copyright notice, this list of conditions and the following | |||||
* disclaimer in the documentation and/or other materials provided | |||||
* with the distribution. | |||||
* | |||||
* - Neither the name of the Eclipse Foundation, Inc. nor the | |||||
* names of its contributors may be used to endorse or promote | |||||
* products derived from this software without specific prior | |||||
* written permission. | |||||
* | |||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND | |||||
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, | |||||
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR | |||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |||||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | |||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | |||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | |||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | |||||
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF | |||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |||||
*/ | |||||
package org.eclipse.jgit.transport; | |||||
import java.util.ArrayList; | |||||
import java.util.Arrays; | |||||
import java.util.List; | |||||
import org.eclipse.jgit.errors.UnsupportedCredentialItem; | |||||
/** | |||||
* A credentials provider chaining multiple credentials providers | |||||
* | |||||
* @since 3.5 | |||||
*/ | |||||
public class ChainingCredentialsProvider extends CredentialsProvider { | |||||
private List<CredentialsProvider> credentialProviders; | |||||
/** | |||||
* Create a new chaining credential provider. This provider tries to | |||||
* retrieve credentials from the chained credential providers in the order | |||||
* they are given here. If multiple providers support the requested items | |||||
* and have non-null credentials the first of them will be used. | |||||
* | |||||
* @param providers | |||||
* credential providers asked for credentials in the order given | |||||
* here | |||||
*/ | |||||
public ChainingCredentialsProvider(CredentialsProvider... providers) { | |||||
this.credentialProviders = new ArrayList<CredentialsProvider>( | |||||
Arrays.asList(providers)); | |||||
for (CredentialsProvider p : providers) | |||||
credentialProviders.add(p); | |||||
} | |||||
/** | |||||
* @return {@code true} if any of the credential providers in the list is | |||||
* interactive, otherwise {@code false} | |||||
* @see org.eclipse.jgit.transport.CredentialsProvider#isInteractive() | |||||
*/ | |||||
@Override | |||||
public boolean isInteractive() { | |||||
for (CredentialsProvider p : credentialProviders) | |||||
if (p.isInteractive()) | |||||
return true; | |||||
return false; | |||||
} | |||||
/** | |||||
* @return {@code true} if any of the credential providers in the list | |||||
* supports the requested items, otherwise {@code false} | |||||
* @see org.eclipse.jgit.transport.CredentialsProvider#supports(org.eclipse.jgit.transport.CredentialItem[]) | |||||
*/ | |||||
@Override | |||||
public boolean supports(CredentialItem... items) { | |||||
for (CredentialsProvider p : credentialProviders) | |||||
if (p.supports(items)) | |||||
return true; | |||||
return false; | |||||
} | |||||
/** | |||||
* Populates the credential items with the credentials provided by the first | |||||
* credential provider in the list which populates them with non-null values | |||||
* | |||||
* @return {@code true} if any of the credential providers in the list | |||||
* supports the requested items, otherwise {@code false} | |||||
* @see org.eclipse.jgit.transport.CredentialsProvider#supports(org.eclipse.jgit.transport.CredentialItem[]) | |||||
*/ | |||||
@Override | |||||
public boolean get(URIish uri, CredentialItem... items) | |||||
throws UnsupportedCredentialItem { | |||||
for (CredentialsProvider p : credentialProviders) { | |||||
if (p.supports(items)) { | |||||
p.get(uri, items); | |||||
if (isAnyNull(items)) | |||||
continue; | |||||
return true; | |||||
} | |||||
} | |||||
return false; | |||||
} | |||||
private boolean isAnyNull(CredentialItem... items) { | |||||
for (CredentialItem i : items) | |||||
if (i == null) | |||||
return true; | |||||
return false; | |||||
} | |||||
} |
public static Transport open(final Repository local, final String remote, | public static Transport open(final Repository local, final String remote, | ||||
final Operation op) throws NotSupportedException, | final Operation op) throws NotSupportedException, | ||||
URISyntaxException, TransportException { | URISyntaxException, TransportException { | ||||
final RemoteConfig cfg = new RemoteConfig(local.getConfig(), remote); | |||||
if (doesNotExist(cfg)) | |||||
return open(local, new URIish(remote), null); | |||||
return open(local, cfg, op); | |||||
if (local != null) { | |||||
final RemoteConfig cfg = new RemoteConfig(local.getConfig(), remote); | |||||
if (doesNotExist(cfg)) | |||||
return open(local, new URIish(remote), null); | |||||
return open(local, cfg, op); | |||||
} else | |||||
return open(new URIish(remote)); | |||||
} | } | ||||
/** | /** |
} | } | ||||
http = local.getConfig().get(HTTP_KEY); | http = local.getConfig().get(HTTP_KEY); | ||||
proxySelector = ProxySelector.getDefault(); | proxySelector = ProxySelector.getDefault(); | ||||
if (getCredentialsProvider() == null) | |||||
setCredentialsProvider(new NetRCCredentialsProvider()); | |||||
} | } | ||||
/** | /** |