git-agent/src/main/java/jetbrains/buildServer/buildTriggers/vcs/git/agent/URIishHelperImpl.java [24:83]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
public class URIishHelperImpl implements URIishHelper {

  @Override
  @Nullable
  public String getUserNameFromUrl(final String url) {
    try {
      URIish u = new URIish(url);
      return u.getUser();
    } catch (URISyntaxException e) {
      //ignore
    }
    return null;
  }

  @Override
  public CommonURIish createAuthURI(@NotNull final AuthSettings authSettings, @Nullable final String uri) throws VcsException {
    return createAuthURI(authSettings, uri, true);
  }

  @Override
  public CommonURIish createAuthURI(@NotNull final AuthSettings authSettings, @Nullable final String uri, final boolean fixErrors) throws VcsException {
    return createAuthURI(authSettings, createURI(uri), fixErrors);
  }

  @NotNull
  public CommonURIish createURI(@Nullable String uri) throws VcsException {
    try {
      return new CommonURIishImpl(new URIish(uri));
    } catch (Exception e) {
      if (uri != null && ReferencesResolverUtil.containsReference(uri))
        throw new VcsException("Unresolved parameter in url: " + uri, e);
      throw new VcsException("Invalid URI: " + uri, e);
    }
  }

  @Override
  public CommonURIish createAuthURI(@NotNull final AuthSettings authSettings, @NotNull final CommonURIish uri) {
    return createAuthURI(authSettings, uri, true);
  }

  @Override
  public CommonURIish createAuthURI(@NotNull final AuthSettings authSettings, @NotNull final CommonURIish uri, final boolean fixErrors) {
    URIish result = uri.get();
    if (requiresCredentials(result)) {
      if (!StringUtil.isEmptyOrSpaces(authSettings.getUserName())) {
        result = result.setUser(authSettings.getUserName());
      }
      if (!StringUtil.isEmpty(authSettings.getPassword())) {
        result = result.setPass(authSettings.getPassword());
      }
    }
    if (fixErrors && isAnonymousProtocol(result)) {
      result = result.setUser(null);
      result = result.setPass(null);
    }
    return new CommonURIishImpl(result);
  }

  private static boolean isAnonymousProtocol(@NotNull URIish uriish) {
    return "git".equals(uriish.getScheme());
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



git-server/src/main/java/jetbrains/buildServer/buildTriggers/vcs/git/URIishHelperImpl.java [21:80]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
public class URIishHelperImpl implements URIishHelper {

  @Override
  @Nullable
  public String getUserNameFromUrl(final String url) {
    try {
      URIish u = new URIish(url);
      return u.getUser();
    } catch (URISyntaxException e) {
      //ignore
    }
    return null;
  }

  @Override
  public CommonURIish createAuthURI(@NotNull final AuthSettings authSettings, @Nullable final String uri) throws VcsException {
    return createAuthURI(authSettings, uri, true);
  }

  @Override
  public CommonURIish createAuthURI(@NotNull final AuthSettings authSettings, @Nullable final String uri, final boolean fixErrors) throws VcsException {
    return createAuthURI(authSettings, createURI(uri), fixErrors);
  }

  @NotNull
  public CommonURIish createURI(@Nullable String uri) throws VcsException {
    try {
      return new CommonURIishImpl(new URIish(uri));
    } catch (Exception e) {
      if (uri != null && ReferencesResolverUtil.containsReference(uri))
        throw new VcsException("Unresolved parameter in url: " + uri, e);
      throw new VcsException("Invalid URI: " + uri, e);
    }
  }

  @Override
  public CommonURIish createAuthURI(@NotNull final AuthSettings authSettings, @NotNull final CommonURIish uri) {
    return createAuthURI(authSettings, uri, true);
  }

  @Override
  public CommonURIish createAuthURI(@NotNull final AuthSettings authSettings, @NotNull final CommonURIish uri, final boolean fixErrors) {
    URIish result = uri.get();
    if (requiresCredentials(result)) {
      if (!StringUtil.isEmptyOrSpaces(authSettings.getUserName())) {
        result = result.setUser(authSettings.getUserName());
      }
      if (!StringUtil.isEmpty(authSettings.getPassword())) {
        result = result.setPass(authSettings.getPassword());
      }
    }
    if (fixErrors && isAnonymousProtocol(result)) {
      result = result.setUser(null);
      result = result.setPass(null);
    }
    return new CommonURIishImpl(result);
  }

  private static boolean isAnonymousProtocol(@NotNull URIish uriish) {
    return "git".equals(uriish.getScheme());
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



