<commit_before>package org.torquebox.mojo.jruby9;

import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.Set;

import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.resolver.ArtifactResolutionRequest;
import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.repository.RepositorySystem;
import org.codehaus.plexus.archiver.ArchiverException;
import org.codehaus.plexus.archiver.UnArchiver;
import org.codehaus.plexus.util.FileUtils;

public class ArtifactHelper {
    private final UnArchiver archiver;
    private final RepositorySystem system;
    private final ArtifactRepository localRepo;
    private final List<ArtifactRepository> remoteRepos;

    public ArtifactHelper(UnArchiver archiver, RepositorySystem system,
            ArtifactRepository localRepo, List<ArtifactRepository> remoteRepos) {
        this.system = system;
        this.localRepo = localRepo;
        this.remoteRepos = remoteRepos;
        this.archiver = archiver;
    }

    public Set<Artifact> resolve(String groupId, String artifactId, String version)
            throws MojoExecutionException {
        return resolve(groupId, artifactId, version, null);
    }

    public Set<Artifact> resolve(String groupId, String artifactId, String version, final String exclusion)
            throws MojoExecutionException {
        ArtifactResolutionRequest request = new ArtifactResolutionRequest()
            .setResolveTransitively(true)
            .setResolveRoot(true)
            .setArtifact(system.createArtifact(groupId, artifactId, version, "jar"))
            .setLocalRepository(this.localRepo)
            .setRemoteRepositories(remoteRepos).setCollectionFilter(new ArtifactFilter() {
                
                @Override
                public boolean include(Artifact artifact) {
                    if (exclusion != null && 
                            (artifact.getGroupId() + ":" + artifact.getArtifactId()).equals(exclusion)) {
                        return false;
                    }
                    return artifact.getScope() == null || artifact.getScope().equals("compile") || artifact.getScope().equals("runtime");
                }
            });

        ArtifactResolutionResult result = system.resolve(request);  
        // TODO error handling
        return result.getArtifacts();
    }

    public void copy(File output, String groupId, String artifactId, String version)
            throws MojoExecutionException {
        copy(output, groupId, artifactId, version, null);
    }

    public void copy(File output, String groupId, String artifactId, String version, String exclusion)
            throws MojoExecutionException {
        output.mkdirs();
        for(Artifact artifact: resolve(groupId, artifactId, version, exclusion)) {
            try {
                FileUtils.copyFile(artifact.getFile(), new File(output, artifact.getFile().getName()));
            } catch (IOException e) {
                throw new MojoExecutionException("could not copy: " + artifact, e);
            }
        }
    }

    public void unzip(File output, String groupId, String artifactId, String version)
            throws MojoExecutionException {
        output.mkdirs();
        archiver.setDestDirectory(output);
        for(Artifact artifact: resolve(groupId, artifactId, version)) {
            archiver.setSourceFile(artifact.getFile());
            try {
                archiver.extract();
            } catch (ArchiverException e) {
                throw new MojoExecutionException("could not unzip: " + artifact, e);
            }
        }
    }
}<commit_msg>fail if there is not a single artifact for the given version<commit_after>package org.torquebox.mojo.jruby9;

import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.Set;

import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.resolver.ArtifactResolutionRequest;
import org.apache.maven.artifact.resolver.ArtifactResolutionResult;
import org.apache.maven.artifact.resolver.filter.ArtifactFilter;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.repository.RepositorySystem;
import org.codehaus.plexus.archiver.ArchiverException;
import org.codehaus.plexus.archiver.UnArchiver;
import org.codehaus.plexus.util.FileUtils;

public class ArtifactHelper {
    private final UnArchiver archiver;
    private final RepositorySystem system;
    private final ArtifactRepository localRepo;
    private final List<ArtifactRepository> remoteRepos;

    public ArtifactHelper(UnArchiver archiver, RepositorySystem system,
            ArtifactRepository localRepo, List<ArtifactRepository> remoteRepos) {
        this.system = system;
        this.localRepo = localRepo;
        this.remoteRepos = remoteRepos;
        this.archiver = archiver;
    }

    public Set<Artifact> resolve(String groupId, String artifactId, String version)
            throws MojoExecutionException {
        return resolve(groupId, artifactId, version, null);
    }

    public Set<Artifact> resolve(String groupId, String artifactId, String version, final String exclusion)
            throws MojoExecutionException {
        ArtifactResolutionRequest request = new ArtifactResolutionRequest()
            .setResolveTransitively(true)
            .setResolveRoot(true)
            .setArtifact(system.createArtifact(groupId, artifactId, version, "jar"))
            .setLocalRepository(this.localRepo)
            .setRemoteRepositories(remoteRepos).setCollectionFilter(new ArtifactFilter() {
                
                @Override
                public boolean include(Artifact artifact) {
                    if (exclusion != null && 
                            (artifact.getGroupId() + ":" + artifact.getArtifactId()).equals(exclusion)) {
                        return false;
                    }
                    return artifact.getScope() == null || artifact.getScope().equals("compile") || artifact.getScope().equals("runtime");
                }
            });

        ArtifactResolutionResult result = system.resolve(request);  
        // TODO error handling
        return result.getArtifacts();
    }

    public void copy(File output, String groupId, String artifactId, String version)
            throws MojoExecutionException {
        copy(output, groupId, artifactId, version, null);
    }

    public void copy(File output, String groupId, String artifactId, String version, String exclusion)
            throws MojoExecutionException {
        output.mkdirs();
        boolean atLeastOne = false;
        for(Artifact artifact: resolve(groupId, artifactId, version, exclusion)) {
            try {
                FileUtils.copyFile(artifact.getFile(), new File(output, artifact.getFile().getName()));
                atLeastOne = true;
            } catch (IOException e) {
                throw new MojoExecutionException("could not copy: " + artifact, e);
            }
        }
        if (!atLeastOne) {
            throw new MojoExcutionException("could not resolve: " + groupId + ":" + artifactId + ":" + version);
        }
    }

    public void unzip(File output, String groupId, String artifactId, String version)
            throws MojoExecutionException {
        output.mkdirs();
        archiver.setDestDirectory(output);
        for(Artifact artifact: resolve(groupId, artifactId, version)) {
            archiver.setSourceFile(artifact.getFile());
            try {
                archiver.extract();
            } catch (ArchiverException e) {
                throw new MojoExecutionException("could not unzip: " + artifact, e);
            }
        }
    }
}
{'fraction_non_alphanumeric': 0.08938407611417126, 'fraction_numerical': 0.0002503755633450175, 'mean_word_length': 2.6832641770401104, 'pattern_counts': {'":': 4, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2145544', 'n_tokens_mistral': 2120, 'n_tokens_neox': 1999, 'n_words': 460}