<commit_before>package com.github.radium.oracle.tn;

import com.github.radium.htmlunit.HtmlUnit;
import com.google.common.base.Predicate;
import com.google.common.collect.Iterables;
import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import com.github.radium.maven.Coordinates;
import com.google.common.base.Charsets;
import com.google.common.hash.HashFunction;
import com.google.common.hash.Hashing;
import com.google.common.io.Files;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.apache.maven.wagon.AbstractWagon;
import org.apache.maven.wagon.ConnectionException;
import org.apache.maven.wagon.ResourceDoesNotExistException;
import org.apache.maven.wagon.TransferFailedException;
import org.apache.maven.wagon.Wagon;
import org.apache.maven.wagon.authentication.AuthenticationException;
import org.apache.maven.wagon.authorization.AuthorizationException;
import org.codehaus.plexus.component.annotations.Component;
import org.w3c.dom.Document;
import org.w3c.dom.Node;

@Component(role = Wagon.class, hint = "otn")
public class ResourceWagon extends AbstractWagon {

    public ResourceWagon() {
        super();

    }

    @Override
    protected void openConnectionInternal() throws ConnectionException, AuthenticationException {
        System.out.println(this.getRepository());
    }

    @Override
    protected void closeConnection() throws ConnectionException {
        System.out.println("closeConnection");
    }

    private Resource findResourceByCoordinates(final Coordinates coordinates) {
        return Iterables.get(Iterables.filter(Arrays.asList(Resource.values()), new Predicate<Resource>() {

            @Override
            public boolean apply(Resource resource) {
                System.out.println(resource);
                return coordinates.equals(Coordinates.fromText(resource.getCoordinates()));
            }

        }), 0);
    }

    public void getJAR(Coordinates coordinates, File localResourceFile) throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException {
        Resource resource = findResourceByCoordinates(coordinates);
        System.out.println(" ===> " + resource);
        if (resource == null) {
            throw new ResourceDoesNotExistException("The resource does not exists");
        }

        try {
            String url = "http" + getRepository().getUrl().substring("otn".length());
            System.out.println(" ----> url = " + url);
            
            String userName = getAuthenticationInfo().getUserName();
            String password = getAuthenticationInfo().getPassword();

            System.out.println("user = " + userName);
            System.out.println("password = " + password);
            HtmlUnit.disableLogging();
            ResourceDownloader.signIn(userName, password).browse(url).downloadResource(resource, localResourceFile);
        } catch (IOException e) {
            e.printStackTrace(System.err);
            throw new TransferFailedException("The transfert failed", e);
        }
    }

    public void getPOM(Coordinates coordinates, File localResourceFile) throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException {
        if(findResourceByCoordinates(coordinates) == null) {
            hrow new ResourceDoesNotExistException("Sorry !");
        }
        
        String pom = getPOM(coordinates);
        try {
            Files.write(pom, localResourceFile, Charsets.UTF_8);
        } catch (IOException e) {
            throw new TransferFailedException("Unable to write POM", e);<commit_msg>Update ResourceWagon.java<commit_after>package com.github.radium.oracle.tn;

import com.github.radium.htmlunit.HtmlUnit;
import com.google.common.base.Predicate;
import com.google.common.collect.Iterables;
import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import com.github.radium.maven.Coordinates;
import com.google.common.base.Charsets;
import com.google.common.hash.HashFunction;
import com.google.common.hash.Hashing;
import com.google.common.io.Files;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.apache.maven.wagon.AbstractWagon;
import org.apache.maven.wagon.ConnectionException;
import org.apache.maven.wagon.ResourceDoesNotExistException;
import org.apache.maven.wagon.TransferFailedException;
import org.apache.maven.wagon.Wagon;
import org.apache.maven.wagon.authentication.AuthenticationException;
import org.apache.maven.wagon.authorization.AuthorizationException;
import org.codehaus.plexus.component.annotations.Component;
import org.w3c.dom.Document;
import org.w3c.dom.Node;

@Component(role = Wagon.class, hint = "otn")
public class ResourceWagon extends AbstractWagon {

    public ResourceWagon() {
        super();

    }

    @Override
    protected void openConnectionInternal() throws ConnectionException, AuthenticationException {
        System.out.println(this.getRepository());
    }

    @Override
    protected void closeConnection() throws ConnectionException {
        System.out.println("closeConnection");
    }

    private Resource findResourceByCoordinates(final Coordinates coordinates) {
        return Iterables.get(Iterables.filter(Arrays.asList(Resource.values()), new Predicate<Resource>() {

            @Override
            public boolean apply(Resource resource) {
                System.out.println(resource);
                return coordinates.equals(Coordinates.fromText(resource.getCoordinates()));
            }

        }), 0);
    }

    public void getJAR(Coordinates coordinates, File localResourceFile) throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException {
        Resource resource = findResourceByCoordinates(coordinates);
        System.out.println(" ===> " + resource);
        if (resource == null) {
            throw new ResourceDoesNotExistException("The resource does not exists");
        }

        try {
            String url = "http" + getRepository().getUrl().substring("otn".length());
            System.out.println(" ----> url = " + url);
            
            String userName = getAuthenticationInfo().getUserName();
            String password = getAuthenticationInfo().getPassword();

            System.out.println("user = " + userName);
            System.out.println("password = " + password);
            HtmlUnit.disableLogging();
            ResourceDownloader.signIn(userName, password).browse(url).downloadResource(resource, localResourceFile);
        } catch (IOException e) {
            e.printStackTrace(System.err);
            throw new TransferFailedException("The transfert failed", e);
        }
    }

    public void getPOM(Coordinates coordinates, File localResourceFile) throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException {
        if(findResourceByCoordinates(coordinates) == null) {
            throw new ResourceDoesNotExistException("Sorry !");
        }
        
        String pom = getPOM(coordinates);
        try {
            Files.write(pom, localResourceFile, Charsets.UTF_8);
        } catch (IOException e) {
            throw new TransferFailedException("Unable to write POM", e);
{'fraction_non_alphanumeric': 0.1036851142517501, 'fraction_numerical': 0.0010566635847312112, 'mean_word_length': 3.5044616299821536, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 6}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4155654', 'n_tokens_mistral': 2001, 'n_tokens_neox': 1956, 'n_words': 380}