Java Code Examples for org.eclipse.jgit.internal.JGitText#get()

The following examples show how to use org.eclipse.jgit.internal.JGitText#get() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GitSkipSslValidationCredentialsProviderTest.java    From spring-cloud-config with Apache License 2.0 6 votes vote down vote up
@Test
public void testSupportsSslValidationYesNoTypes() {
	CredentialItem yesNoType = new CredentialItem.YesNoType(
			JGitText.get().sslTrustNow);
	assertThat(this.skipSslValidationCredentialsProvider.supports(yesNoType)).as(
			"GitSkipSslValidationCredentialsProvider should always support the trust now YesNoType item")
			.isTrue();

	yesNoType = new CredentialItem.YesNoType(
			MessageFormat.format(JGitText.get().sslTrustForRepo, "/a/path.git"));
	assertThat(this.skipSslValidationCredentialsProvider.supports(yesNoType)).as(
			"GitSkipSslValidationCredentialsProvider should always support the trust repo YesNoType item")
			.isTrue();

	yesNoType = new CredentialItem.YesNoType(JGitText.get().sslTrustAlways);
	assertThat(this.skipSslValidationCredentialsProvider.supports(yesNoType)).as(
			"GitSkipSslValidationCredentialsProvider should always support the trust always YesNoType item")
			.isTrue();

	yesNoType = new CredentialItem.YesNoType("unrelated");
	assertThat(this.skipSslValidationCredentialsProvider.supports(yesNoType)).as(
			"GitSkipSslValidationCredentialsProvider should not support unrelated YesNoType items")
			.isFalse();
}
 
Example 2
Source File: RevWalk.java    From onedev with MIT License 6 votes vote down vote up
/**
 * Reads the "shallow" file and applies it by setting the parents of shallow
 * commits to an empty array.
 * <p>
 * There is a sequencing problem if the first commit being parsed is a
 * shallow commit, since {@link RevCommit#parseCanonical(RevWalk, byte[])}
 * calls this method before its callers add the new commit to the
 * {@link RevWalk#objects} map. That means a call from this method to
 * {@link #lookupCommit(AnyObjectId)} fails to find that commit and creates
 * a new one, which is promptly discarded.
 * <p>
 * To avoid that, {@link RevCommit#parseCanonical(RevWalk, byte[])} passes
 * its commit to this method, so that this method can apply the shallow
 * state to it directly and avoid creating the duplicate commit object.
 *
 * @param rc
 *            the initial commit being parsed
 * @throws IOException
 *             if the shallow commits file can't be read
 */
void initializeShallowCommits(RevCommit rc) throws IOException {
	if (shallowCommitsInitialized) {
		throw new IllegalStateException(
				JGitText.get().shallowCommitsAlreadyInitialized);
	}

	shallowCommitsInitialized = true;

	if (reader == null) {
		return;
	}

	for (ObjectId id : reader.getShallowCommits()) {
		if (id.equals(rc.getId())) {
			rc.parents = RevCommit.NO_PARENTS;
		} else {
			lookupCommit(id).parents = RevCommit.NO_PARENTS;
		}
	}
}
 
Example 3
Source File: GitSkipSslValidationCredentialsProviderTest.java    From spring-cloud-config with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetSslTrustItems() throws URISyntaxException {
	URIish uri = new URIish("https://example.com/repo.git");
	CredentialItem message = new CredentialItem.InformationalMessage(
			JGitText.get().sslFailureTrustExplanation);
	CredentialItem.YesNoType trustNow = new CredentialItem.YesNoType(
			JGitText.get().sslTrustNow);
	CredentialItem.YesNoType trustAlways = new CredentialItem.YesNoType(
			JGitText.get().sslTrustAlways);

	boolean getSuccessful = this.skipSslValidationCredentialsProvider.get(uri,
			message, trustNow, trustAlways);

	assertThat(getSuccessful).as(
			"SkipSSlValidationCredentialsProvider must successfully get the types required for SSL validation skipping")
			.isTrue();
	assertThat(trustNow.getValue()).as(
			"SkipSSlValidationCredentialsProvider should trust the current repo operation")
			.isTrue();
	assertThat(trustAlways.getValue())
			.as("We should not globally skip all SSL validation").isFalse();
}
 
Example 4
Source File: GitSkipSslValidationCredentialsProviderTest.java    From spring-cloud-config with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetSslTrustItemsWithLocalRepo() throws URISyntaxException {
	URIish uri = new URIish("https://example.com/repo.git");
	CredentialItem message = new CredentialItem.InformationalMessage(
			JGitText.get().sslFailureTrustExplanation);
	CredentialItem.YesNoType trustNow = new CredentialItem.YesNoType(
			JGitText.get().sslTrustNow);
	CredentialItem.YesNoType trustForRepo = new CredentialItem.YesNoType(
			JGitText.get().sslTrustForRepo);
	CredentialItem.YesNoType trustAlways = new CredentialItem.YesNoType(
			JGitText.get().sslTrustAlways);

	boolean getSuccessful = this.skipSslValidationCredentialsProvider.get(uri,
			message, trustNow, trustForRepo, trustAlways);

	assertThat(getSuccessful).as(
			"SkipSSlValidationCredentialsProvider must successfully get the types required for SSL validation skipping")
			.isTrue();
	assertThat(trustNow.getValue()).as(
			"SkipSSlValidationCredentialsProvider should trust the current repo operation")
			.isTrue();
	assertThat(trustForRepo.getValue())
			.as("Future operations on this repository should also be trusted")
			.isTrue();
	assertThat(trustAlways.getValue())
			.as("We should not globally skip all SSL validation").isFalse();
}
 
Example 5
Source File: TransportAmazonLambdaS3.java    From github-bucket with ISC License 5 votes vote down vote up
private void readLooseRefs(final TreeMap<String, Ref> avail) throws TransportException {
    try {
        // S3 limits the size of the response to 1000 entries. Batch the requests.
        String prefix = resolveKey(ROOT_DIR + "refs");
        List<S3ObjectSummary> refs = getS3ObjectSummaries(prefix);
        for (final S3ObjectSummary ref : refs) {
            readRef(avail, "refs/" + ref.getKey().substring(prefix.length() + 1));
        }
    }
    catch (IOException e) {
        throw new TransportException(getURI(), JGitText.get().cannotListRefs, e);
    }
}
 
Example 6
Source File: Merger.java    From onedev with MIT License 5 votes vote down vote up
/**
 * Create a new merge instance for a repository.
 *
 * @param local
 *            the repository this merger will read and write data on.
 */
protected Merger(Repository local) {
	if (local == null) {
		throw new NullPointerException(JGitText.get().repositoryIsRequired);
	}
	db = local;
	inserter = local.newObjectInserter();
	reader = inserter.newReader();
	walk = new RevWalk(reader);
}
 
Example 7
Source File: GitSkipSslValidationCredentialsProviderTest.java    From spring-cloud-config with Apache License 2.0 5 votes vote down vote up
@Test
public void testSupportsSslFailureInformationalMessage() {
	CredentialItem informationalMessage = new CredentialItem.InformationalMessage(
			"text " + JGitText.get().sslFailureTrustExplanation + " more text");
	assertThat(this.skipSslValidationCredentialsProvider
			.supports(informationalMessage)).as(
					"GitSkipSslValidationCredentialsProvider should always support SSL failure InformationalMessage")
					.isTrue();

	informationalMessage = new CredentialItem.InformationalMessage("unrelated");
	assertThat(this.skipSslValidationCredentialsProvider
			.supports(informationalMessage)).as(
					"GitSkipSslValidationCredentialsProvider should not support unrelated InformationalMessage items")
					.isFalse();
}
 
Example 8
Source File: AndRevFilter.java    From onedev with MIT License 5 votes vote down vote up
/**
 * Create a filter around many filters, all of which must match.
 *
 * @param list
 *            list of filters to match against. Must contain at least 2
 *            filters.
 * @return a filter that must match all input filters.
 */
public static RevFilter create(Collection<RevFilter> list) {
	if (list.size() < 2)
		throw new IllegalArgumentException(JGitText.get().atLeastTwoFiltersNeeded);
	final RevFilter[] subfilters = new RevFilter[list.size()];
	list.toArray(subfilters);
	if (subfilters.length == 2)
		return create(subfilters[0], subfilters[1]);
	return new List(subfilters);
}
 
Example 9
Source File: AndRevFilter.java    From onedev with MIT License 5 votes vote down vote up
/**
 * Create a filter around many filters, all of which must match.
 *
 * @param list
 *            list of filters to match against. Must contain at least 2
 *            filters.
 * @return a filter that must match all input filters.
 */
public static RevFilter create(RevFilter[] list) {
	if (list.length == 2)
		return create(list[0], list[1]);
	if (list.length < 2)
		throw new IllegalArgumentException(JGitText.get().atLeastTwoFiltersNeeded);
	final RevFilter[] subfilters = new RevFilter[list.length];
	System.arraycopy(list, 0, subfilters, 0, list.length);
	return new List(subfilters);
}
 
Example 10
Source File: OrRevFilter.java    From onedev with MIT License 5 votes vote down vote up
/**
 * Create a filter around many filters, one of which must match.
 *
 * @param list
 *            list of filters to match against. Must contain at least 2
 *            filters.
 * @return a filter that must match at least one input filter.
 */
public static RevFilter create(Collection<RevFilter> list) {
	if (list.size() < 2)
		throw new IllegalArgumentException(JGitText.get().atLeastTwoFiltersNeeded);
	final RevFilter[] subfilters = new RevFilter[list.size()];
	list.toArray(subfilters);
	if (subfilters.length == 2)
		return create(subfilters[0], subfilters[1]);
	return new List(subfilters);
}
 
Example 11
Source File: OrRevFilter.java    From onedev with MIT License 5 votes vote down vote up
/**
 * Create a filter around many filters, one of which must match.
 *
 * @param list
 *            list of filters to match against. Must contain at least 2
 *            filters.
 * @return a filter that must match at least one input filter.
 */
public static RevFilter create(RevFilter[] list) {
	if (list.length == 2)
		return create(list[0], list[1]);
	if (list.length < 2)
		throw new IllegalArgumentException(JGitText.get().atLeastTwoFiltersNeeded);
	final RevFilter[] subfilters = new RevFilter[list.length];
	System.arraycopy(list, 0, subfilters, 0, list.length);
	return new List(subfilters);
}
 
Example 12
Source File: PatternMatchRevFilter.java    From onedev with MIT License 4 votes vote down vote up
/**
 * Construct a new pattern matching filter.
 *
 * @param pattern
 *            text of the pattern. Callers may want to surround their
 *            pattern with ".*" on either end to allow matching in the
 *            middle of the string.
 * @param innerString
 *            should .* be wrapped around the pattern of ^ and $ are
 *            missing? Most users will want this set.
 * @param rawEncoding
 *            should {@link #forceToRaw(String)} be applied to the pattern
 *            before compiling it?
 * @param flags
 *            flags from {@link java.util.regex.Pattern} to control how
 *            matching performs.
 */
protected PatternMatchRevFilter(String pattern, final boolean innerString,
		final boolean rawEncoding, final int flags) {
	if (pattern.length() == 0)
		throw new IllegalArgumentException(JGitText.get().cannotMatchOnEmptyString);
	patternText = pattern;

	if (innerString) {
		if (!pattern.startsWith("^") && !pattern.startsWith(".*")) //$NON-NLS-1$ //$NON-NLS-2$
			pattern = ".*" + pattern; //$NON-NLS-1$
		if (!pattern.endsWith("$") && !pattern.endsWith(".*")) //$NON-NLS-1$ //$NON-NLS-2$
			pattern = pattern + ".*"; //$NON-NLS-1$
	}
	final String p = rawEncoding ? forceToRaw(pattern) : pattern;
	compiledPattern = Pattern.compile(p, flags).matcher(""); //$NON-NLS-1$
}
 
Example 13
Source File: RevFilter.java    From onedev with MIT License 4 votes vote down vote up
@Override
public boolean include(RevWalk walker, RevCommit c) {
	throw new UnsupportedOperationException(JGitText.get().cannotBeCombined);
}
 
Example 14
Source File: LogCommand.java    From orion.server with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Executes the {@code Log} command with all the options and parameters collected by the setter methods (e.g. {@link #add(AnyObjectId)},
 * {@link #not(AnyObjectId)}, ..) of this class. Each instance of this class should only be used for one invocation of the command. Don't call this method
 * twice on an instance.
 *
 * @return an iteration over RevCommits
 * @throws NoHeadException
 *             of the references ref cannot be resolved
 */
@Override
public Iterable<RevCommit> call() throws GitAPIException, NoHeadException {
	checkCallable();
	ArrayList<RevFilter> filters = new ArrayList<RevFilter>();

	if (pathFilters.size() > 0)
		walk.setTreeFilter(AndTreeFilter.create(PathFilterGroup.create(pathFilters), TreeFilter.ANY_DIFF));

	if (msgFilter != null)
		filters.add(msgFilter);
	if (authorFilter != null)
		filters.add(authorFilter);
	if (committerFilter != null)
		filters.add(committerFilter);
	if (sha1Filter != null)
		filters.add(sha1Filter);
	if (dateFilter != null)
		filters.add(dateFilter);
	if (skip > -1)
		filters.add(SkipRevFilter.create(skip));
	if (maxCount > -1)
		filters.add(MaxCountRevFilter.create(maxCount));
	RevFilter filter = null;
	if (filters.size() > 1) {
		filter = AndRevFilter.create(filters);
	} else if (filters.size() == 1) {
		filter = filters.get(0);
	}

	if (filter != null)
		walk.setRevFilter(filter);

	if (!startSpecified) {
		try {
			ObjectId headId = repo.resolve(Constants.HEAD);
			if (headId == null)
				throw new NoHeadException(JGitText.get().noHEADExistsAndNoExplicitStartingRevisionWasSpecified);
			add(headId);
		} catch (IOException e) {
			// all exceptions thrown by add() shouldn't occur and represent
			// severe low-level exception which are therefore wrapped
			throw new JGitInternalException(JGitText.get().anExceptionOccurredWhileTryingToAddTheIdOfHEAD, e);
		}
	}
	setCallable(false);
	return walk;
}
 
Example 15
Source File: MultiUserSshSessionFactory.java    From WebIDE-Backend with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public synchronized RemoteSession getSession(URIish uri,
                                             CredentialsProvider credentialsProvider, FS fs, int tms)
        throws TransportException {

    String user = uri.getUser();
    final String pass = uri.getPass();
    String host = uri.getHost();
    int port = uri.getPort();

    try {
        if (config == null)
            config = OpenSshConfig.get(fs);

        final OpenSshConfig.Host hc = config.lookup(host);
        host = hc.getHostName();
        if (port <= 0)
            port = hc.getPort();
        if (user == null)
            user = hc.getUser();

        Session session = createSession(credentialsProvider, fs, user,
                pass, host, port, hc);

        int retries = 0;
        while (!session.isConnected()) {
            try {
                retries++;
                session.connect(tms);
            } catch (JSchException e) {
                session.disconnect();
                session = null;
                // Make sure our known_hosts is not outdated
                knownHosts(getJSch(credentialsProvider, hc, fs), fs);

                if (isAuthenticationCanceled(e)) {
                    throw e;
                } else if (isAuthenticationFailed(e)
                        && credentialsProvider != null) {
                    // if authentication failed maybe credentials changed at
                    // the remote end therefore reset credentials and retry
                    if (retries < 3) {
                        credentialsProvider.reset(uri);
                        session = createSession(credentialsProvider, fs,
                                user, pass, host, port, hc);
                    } else
                        throw e;
                } else if (retries >= hc.getConnectionAttempts()) {
                    throw e;
                } else {
                    try {
                        Thread.sleep(1000);
                        session = createSession(credentialsProvider, fs,
                                user, pass, host, port, hc);
                    } catch (InterruptedException e1) {
                        throw new TransportException(
                                JGitText.get().transportSSHRetryInterrupt,
                                e1);
                    }
                }
            }
        }

        return new JschSession(session, uri);

    } catch (JSchException je) {
        final Throwable c = je.getCause();
        if (c instanceof UnknownHostException)
            throw new TransportException(uri, JGitText.get().unknownHost);
        if (c instanceof ConnectException)
            throw new TransportException(uri, c.getMessage());
        throw new TransportException(uri, je.getMessage(), je);
    }

}
 
Example 16
Source File: MessageRevFilter.java    From onedev with MIT License 3 votes vote down vote up
/**
 * Create a message filter.
 * <p>
 * An optimized substring search may be automatically selected if the
 * pattern does not contain any regular expression meta-characters.
 * <p>
 * The search is performed using a case-insensitive comparison. The
 * character encoding of the commit message itself is not respected. The
 * filter matches on raw UTF-8 byte sequences.
 *
 * @param pattern
 *            regular expression pattern to match.
 * @return a new filter that matches the given expression against the
 *         message body of the commit.
 */
public static RevFilter create(String pattern) {
	if (pattern.length() == 0)
		throw new IllegalArgumentException(JGitText.get().cannotMatchOnEmptyString);
	if (SubStringRevFilter.safe(pattern))
		return new SubStringSearch(pattern);
	return new PatternSearch(pattern);
}
 
Example 17
Source File: MaxCountRevFilter.java    From onedev with MIT License 3 votes vote down vote up
/**
 * Create a new max count filter.
 *
 * @param maxCount
 *            the limit
 * @return a new filter
 */
public static RevFilter create(int maxCount) {
	if (maxCount < 0)
		throw new IllegalArgumentException(
				JGitText.get().maxCountMustBeNonNegative);
	return new MaxCountRevFilter(maxCount);
}
 
Example 18
Source File: AuthorRevFilter.java    From onedev with MIT License 3 votes vote down vote up
/**
 * Create a new author filter.
 * <p>
 * An optimized substring search may be automatically selected if the
 * pattern does not contain any regular expression meta-characters.
 * <p>
 * The search is performed using a case-insensitive comparison. The
 * character encoding of the commit message itself is not respected. The
 * filter matches on raw UTF-8 byte sequences.
 *
 * @param pattern
 *            regular expression pattern to match.
 * @return a new filter that matches the given expression against the author
 *         name and address of a commit.
 */
public static RevFilter create(String pattern) {
	if (pattern.length() == 0)
		throw new IllegalArgumentException(JGitText.get().cannotMatchOnEmptyString);
	if (SubStringRevFilter.safe(pattern))
		return new SubStringSearch(pattern);
	return new PatternSearch(pattern);
}
 
Example 19
Source File: SkipRevFilter.java    From onedev with MIT License 3 votes vote down vote up
/**
 * Create a new skip filter.
 *
 * @param skip
 *            the number of commits to skip
 * @return a new filter
 */
public static RevFilter create(int skip) {
	if (skip < 0)
		throw new IllegalArgumentException(
				JGitText.get().skipMustBeNonNegative);
	return new SkipRevFilter(skip);
}
 
Example 20
Source File: Merger.java    From onedev with MIT License 3 votes vote down vote up
/**
 * Get non-null repository instance
 *
 * @return non-null repository instance
 * @throws java.lang.NullPointerException
 *             if the merger was constructed without a repository.
 * @since 4.8
 */
protected Repository nonNullRepo() {
	if (db == null) {
		throw new NullPointerException(JGitText.get().repositoryIsRequired);
	}
	return db;
}