<commit_before>/*
 * Copyright (C) 2015 Red Bull Media House GmbH <http://www.redbullmediahouse.com> - all rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.rbmhtechnology.apidocserver.service.mavenrepo;

import static java.lang.String.format;

import com.rbmhtechnology.apidocserver.exception.AccessNotAllowedException;
import com.rbmhtechnology.apidocserver.exception.DownloadException;
import com.rbmhtechnology.apidocserver.exception.NotFoundException;
import com.rbmhtechnology.apidocserver.exception.RepositoryException;
import com.rbmhtechnology.apidocserver.service.ArtifactIdentifier;
import io.vavr.collection.List;
import io.vavr.collection.Map;
import io.vavr.control.Try;
import java.io.File;
import org.apache.maven.wagon.ConnectionException;
import org.apache.maven.wagon.ResourceDoesNotExistException;
import org.apache.maven.wagon.TransferFailedException;
import org.apache.maven.wagon.authentication.AuthenticationException;
import org.apache.maven.wagon.authentication.AuthenticationInfo;
import org.apache.maven.wagon.authorization.AuthorizationException;
import org.apache.maven.wagon.providers.http.HttpWagon;
import org.apache.maven.wagon.repository.Repository;
import org.apache.maven.wagon.shared.http.BasicAuthScope;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

@Component
public class MavenRepoClient {

  private static final Logger LOG = LoggerFactory.getLogger(MavenRepoClient.class);

  private final HttpWagon httpWagon;
  private final Repository repository;
  private final AuthenticationInfo authenticationInfo;

  public MavenRepoClient(MavenRepositoryConfig config) {
    this.httpWagon = new HttpWagon();
    this.authenticationInfo = config.getCredentials().map(c -> {
      final AuthenticationInfo authInfo = new AuthenticationInfo();
      authInfo.setUserName(c.username());
      authInfo.setPassword(<PASSWORD>());
      BasicAuthScope scope = new BasicAuthScope();
      scope.setHost(config.repositoryHost());
      scope.setPort(String.valueOf(config.repositoryPort()));
      httpWagon.setBasicAuthScope(scope);<commit_msg>Extract configuration of BasicAuthScope from AuthenticationInfo mapping in MavenRepoClient instantiation<commit_after>/*
 * Copyright (C) 2015 Red Bull Media House GmbH <http://www.redbullmediahouse.com> - all rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.rbmhtechnology.apidocserver.service.mavenrepo;

import static java.lang.String.format;

import com.rbmhtechnology.apidocserver.exception.AccessNotAllowedException;
import com.rbmhtechnology.apidocserver.exception.DownloadException;
import com.rbmhtechnology.apidocserver.exception.NotFoundException;
import com.rbmhtechnology.apidocserver.exception.RepositoryException;
import com.rbmhtechnology.apidocserver.service.ArtifactIdentifier;
import io.vavr.collection.List;
import io.vavr.collection.Map;
import io.vavr.control.Try;
import java.io.File;
import org.apache.maven.wagon.ConnectionException;
import org.apache.maven.wagon.ResourceDoesNotExistException;
import org.apache.maven.wagon.TransferFailedException;
import org.apache.maven.wagon.authentication.AuthenticationException;
import org.apache.maven.wagon.authentication.AuthenticationInfo;
import org.apache.maven.wagon.authorization.AuthorizationException;
import org.apache.maven.wagon.providers.http.HttpWagon;
import org.apache.maven.wagon.repository.Repository;
import org.apache.maven.wagon.shared.http.BasicAuthScope;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

@Component
public class MavenRepoClient {

  private static final Logger LOG = LoggerFactory.getLogger(MavenRepoClient.class);

  private final HttpWagon httpWagon;
  private final Repository repository;
  private final AuthenticationInfo authenticationInfo;

  public MavenRepoClient(MavenRepositoryConfig config) {
    this.httpWagon = new HttpWagon();
    final BasicAuthScope scope = new BasicAuthScope();
    scope.setHost(config.repositoryHost());
    scope.setPort(String.valueOf(config.repositoryPort()));
    this.httpWagon.setBasicAuthScope(scope);

    this.authenticationInfo = config.getCredentials().map(c -> {
      final AuthenticationInfo authInfo = new AuthenticationInfo();
      authInfo.setUserName(c.username());
      authInfo.setPassword(<PASSWORD>());
{'fraction_non_alphanumeric': 0.08846790509472136, 'fraction_numerical': 0.0036784991723376862, 'mean_word_length': 5.591515151515152, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4631215', 'n_tokens_mistral': 1552, 'n_tokens_neox': 1484, 'n_words': 373}