<commit_before>package net.minecraftforge.gradle.tasks;

import static net.minecraftforge.gradle.common.Constants.resolveString;
import groovy.lang.Closure;
import groovy.util.MapEntry;

import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Collections;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.jar.JarOutputStream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;

import net.minecraftforge.gradle.util.ZipFileTree;

import org.gradle.api.DefaultTask;
import org.gradle.api.file.FileTreeElement;
import org.gradle.api.file.FileVisitDetails;
import org.gradle.api.file.FileVisitor;
import org.gradle.api.specs.Spec;
import org.gradle.api.tasks.Input;
import org.gradle.api.tasks.InputFile;
import org.gradle.api.tasks.OutputFile;
import org.gradle.api.tasks.ParallelizableTask;
import org.gradle.api.tasks.TaskAction;
import org.gradle.api.tasks.util.PatternFilterable;
import org.gradle.api.tasks.util.PatternSet;

import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Maps;
import com.google.common.io.ByteStreams;

@ParallelizableTask
public class SignJar extends DefaultTask implements PatternFilterable
{
    //@formatter:off
    @Input      private PatternSet patternSet = new PatternSet();
    @Input      private Object     alias;
    @Input      private Object     storePass;
    @Input      private Object     keyPass;
    @Input      private Object     keyStore;
    @InputFile  private Object     inputFile;
    @OutputFile private Object     outputFile;
    //@formatter:on

    @TaskAction
    public void doTask() throws IOException
    {
        final Map<String, Entry<byte[], Long>> ignoredStuff = Maps.newHashMap();
        File input = getInputFile();
        File toSign = new File(getTemporaryDir(), input.getName() + ".unsigned.tmp");
        File signed = new File(getTemporaryDir(), input.getName() + ".signed.tmp");
        File output = getOutputFile();

        // load in input jar, and create temp jar
        processInputJar(input, toSign, ignoredStuff);

        // SIGN!
        getProject().getAnt().invokeMethod("signjar", ImmutableMap.builder()
                .put("alias", getAlias())
                .put("storepass", getStorePass())
                .put("keypass", getKeyPass())
                .put("keystore", getKeyStore())
                .put("jar", toSign.getAbsolutePath())
                .put("signedjar", signed.getAbsolutePath())
                .build()
                );

        // write out
        writeOutputJar(signed, output, ignoredStuff);
    }

    private void processInputJar(File inputJar, File toSign, final Map<String, Entry<byte[], Long>> unsigned) throws IOException
    {
        final Spec<FileTreeElement> spec = patternSet.getAsSpec();

        toSign.getParentFile().mkdirs();
        final JarOutputStream outs = new JarOutputStream(new BufferedOutputStream(new FileOutputStream(toSign)));

        (new ZipFileTree(inputJar)).visit(new FileVisitor() {

            @Override
            public void visitDir(FileVisitDetails details)
            {
                details.stopVisiting();
                // nothing
            }

            @Override
            @SuppressWarnings("unchecked")
            public void visitFile(FileVisitDetails details)
            {
                try
                {
                    if (!spec.isSatisfiedBy(details))
                    {
                        ZipEntry entry = new ZipEntry(details.getPath());
                        entry.setTime(details.getLastModified());
                        outs.putNextEntry(entry);
                        details.copyTo(outs);
                        outs.closeEntry();
                    }
                    else
                    {
                        InputStream stream = details.open();
                        unsigned.put(details.getPath(), new MapEntry(ByteStreams.toByteArray(stream), details.getLastModified()));
                        stream.close();<commit_msg>We want to keep processing...<commit_after>package net.minecraftforge.gradle.tasks;

import static net.minecraftforge.gradle.common.Constants.resolveString;
import groovy.lang.Closure;
import groovy.util.MapEntry;

import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Collections;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.jar.JarOutputStream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;

import net.minecraftforge.gradle.util.ZipFileTree;

import org.gradle.api.DefaultTask;
import org.gradle.api.file.FileTreeElement;
import org.gradle.api.file.FileVisitDetails;
import org.gradle.api.file.FileVisitor;
import org.gradle.api.specs.Spec;
import org.gradle.api.tasks.Input;
import org.gradle.api.tasks.InputFile;
import org.gradle.api.tasks.OutputFile;
import org.gradle.api.tasks.ParallelizableTask;
import org.gradle.api.tasks.TaskAction;
import org.gradle.api.tasks.util.PatternFilterable;
import org.gradle.api.tasks.util.PatternSet;

import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Maps;
import com.google.common.io.ByteStreams;

@ParallelizableTask
public class SignJar extends DefaultTask implements PatternFilterable
{
    //@formatter:off
    @Input      private PatternSet patternSet = new PatternSet();
    @Input      private Object     alias;
    @Input      private Object     storePass;
    @Input      private Object     keyPass;
    @Input      private Object     keyStore;
    @InputFile  private Object     inputFile;
    @OutputFile private Object     outputFile;
    //@formatter:on

    @TaskAction
    public void doTask() throws IOException
    {
        final Map<String, Entry<byte[], Long>> ignoredStuff = Maps.newHashMap();
        File input = getInputFile();
        File toSign = new File(getTemporaryDir(), input.getName() + ".unsigned.tmp");
        File signed = new File(getTemporaryDir(), input.getName() + ".signed.tmp");
        File output = getOutputFile();

        // load in input jar, and create temp jar
        processInputJar(input, toSign, ignoredStuff);

        // SIGN!
        getProject().getAnt().invokeMethod("signjar", ImmutableMap.builder()
                .put("alias", getAlias())
                .put("storepass", getStorePass())
                .put("keypass", getKeyPass())
                .put("keystore", getKeyStore())
                .put("jar", toSign.getAbsolutePath())
                .put("signedjar", signed.getAbsolutePath())
                .build()
                );

        // write out
        writeOutputJar(signed, output, ignoredStuff);
    }

    private void processInputJar(File inputJar, File toSign, final Map<String, Entry<byte[], Long>> unsigned) throws IOException
    {
        final Spec<FileTreeElement> spec = patternSet.getAsSpec();

        toSign.getParentFile().mkdirs();
        final JarOutputStream outs = new JarOutputStream(new BufferedOutputStream(new FileOutputStream(toSign)));

        (new ZipFileTree(inputJar)).visit(new FileVisitor() {

            @Override
            public void visitDir(FileVisitDetails details)
            {
                // nothing
            }

            @Override
            @SuppressWarnings("unchecked")
            public void visitFile(FileVisitDetails details)
            {
                try
                {
                    if (!spec.isSatisfiedBy(details))
                    {
                        ZipEntry entry = new ZipEntry(details.getPath());
                        entry.setTime(details.getLastModified());
                        outs.putNextEntry(entry);
                        details.copyTo(outs);
                        outs.closeEntry();
                    }
                    else
                    {
                        InputStream stream = details.open();
                        unsigned.put(details.getPath(), new MapEntry(ByteStreams.toByteArray(stream), details.getLastModified()));
                        stream.close();
{'fraction_non_alphanumeric': 0.10507859733978235, 'fraction_numerical': 0.0, 'mean_word_length': 2.3621951219512196, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, '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': '3519893', 'n_tokens_mistral': 2277, 'n_tokens_neox': 2153, 'n_words': 458}