<commit_before>import org.gradle.api.JavaVersion;
import org.gradle.api.Plugin;
import org.gradle.api.Project;
import org.gradle.api.Task;
import org.gradle.api.publish.PublishingExtension;
import org.gradle.api.publish.maven.MavenPublication;
import org.gradle.api.tasks.TaskProvider;
import org.gradle.authentication.http.BasicAuthentication;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.UncheckedIOException;
import java.nio.file.Files;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.EnumSet;
import java.util.Locale;
import java.util.Properties;
import java.util.Set;
import java.util.stream.Collectors;

/**
 * Takes care of adding tasks and configurations to build developer distributions and releases.
 */
public class ReleasePlugin implements Plugin<Project> {
    private static final Logger LOGGER = LoggerFactory.getLogger(ReleasePlugin.class);

    public static final String SNAPSHOT_REPOSITORY_URL = "https://repo.gradle.org/gradle/ext-snapshots-local";
    private static final String RELEASES_REPOSITORY_URL = "https://dl.bintray.com/adammurdoch/maven";

    private static final DateTimeFormatter SNAPSHOT_TIMESTAMP_FORMATTER = DateTimeFormatter.ofPattern("yyyyMMddHHmmssZ", Locale.US).withZone(ZoneOffset.UTC);
    private static final String BUILD_RECEIPT_NAME = "build-receipt.properties";
    private static final String BUILD_TIMESTAMP_PROPERTY = "buildTimestamp";
    private static final String UPLOAD_MAIN_TASK_NAME = "uploadMain";
    private static final String UPLOAD_JNI_TASK_NAME = "uploadJni";

    @Override
    public void apply(Project project) {
        VersionDetails.BuildType buildType = determineBuildType(project);
        VersionDetails versions = project.getExtensions().create("versions", VersionDetails.class, buildType);

        if (buildType != VersionDetails.BuildType.Dev && JavaVersion.current() != JavaVersion.VERSION_1_8) {
            throw new RuntimeException("Java 8 is required to build a release of native-platform. Later versions are not supported.");
        }

        String buildTimestamp = determineBuildTimestamp(project);
        writeBuildTimestamp(buildTimestamp, project);

        VersionCalculator versionCalculator = new VersionCalculator(versions, buildType, buildTimestamp);

        project.getGradle().getTaskGraph().whenReady(graph -> {
            if (graph.hasTask(":" + UPLOAD_MAIN_TASK_NAME) || graph.hasTask(":" + UPLOAD_JNI_TASK_NAME)) {
                project.getLogger().lifecycle("##teamcity[buildStatus text='{build.status.text}, Published version {}']", versionCalculator);
            }
        });

        project.allprojects(subproject -> {
            subproject.getPlugins().apply(UploadPlugin.class);
            subproject.getPlugins().apply(PublishSnapshotPlugin.class);
            subproject.setVersion(versionCalculator);

            // Use authenticated snapshot/bintray repo while building a test distribution during snapshot/release
            final BintrayCredentials credentials = subproject.getExtensions().getByType(BintrayCredentials.class);

            if (versions.isUseRepo()) {
                credentials.assertPresent();
                String repositoryUrl = buildType == VersionDetails.BuildType.Snapshot
                        ? SNAPSHOT_REPOSITORY_URL
                        : RELEASES_REPOSITORY_URL;
                subproject.getRepositories().maven(repo -> {
                    repo.setUrl(repositoryUrl);
                    repo.getCredentials().setUsername(credentials.getUserName());
                    repo.getCredentials().setPassword(<PASSWORD>.<PASSWORD>());
                    repo.getAuthentication().create("basic", BasicAuthentication.class);
                });
            }

            addUploadLifecycleTasks(subproject, buildType);
        });
    }

    private void addUploadLifecycleTasks(Project project, VersionDetails.BuildType buildType) {
        Task uploadMainLifecycle = project.getTasks().maybeCreate(UPLOAD_MAIN_TASK_NAME);
        uploadMainLifecycle.setGroup("Upload");
        uploadMainLifecycle.setDescription("Upload Main publication");

        Task uploadJniLifecycle = project.getTasks().maybeCreate(UPLOAD_JNI_TASK_NAME);
        uploadJniLifecycle.setGroup("Upload");
        uploadJniLifecycle.setDescription("Upload all JNI publications");

        project.getExtensions().configure(
                PublishingExtension.class,
                extension -> extension.getPublications().withType(MavenPublication.class, publication -> {
                    String uploadTaskName = buildType == VersionDetails.BuildType.Snapshot
                            ? PublishSnapshotPlugin.uploadTaskName(publication)
                            : UploadPlugin.uploadTaskName(publication);
                    TaskProvider<Task> uploadTask = project.getTasks().named(uploadTaskName);
                    if (BasePublishPlugin.isMainPublication(publication)) {
                        uploadMainLifecycle.dependsOn(uploadTask);
                    } else {
                        uploadJniLifecycle.dependsOn(uploadTask);
                    }
                }));
    }

    private void writeBuildTimestamp(String buildTimestamp, Project project) {
        File buildReceiptFile = project.getRootProject().file(BUILD_RECEIPT_NAME);
        try (OutputStream outputStream = Files.newOutputStream(buildReceiptFile.toPath())) {
            Properties properties = new Properties();
            properties.setProperty(BUILD_TIMESTAMP_PROPERTY, buildTimestamp);
            properties.store(outputStream, null);
        } catch (IOException e) {
            throw new UncheckedIOException(e);
        }<commit_msg>Add a task to only upload the ncurses JNI jars<commit_after>import org.gradle.api.JavaVersion;
import org.gradle.api.Plugin;
import org.gradle.api.Project;
import org.gradle.api.Task;
import org.gradle.api.publish.PublishingExtension;
import org.gradle.api.publish.maven.MavenPublication;
import org.gradle.api.tasks.TaskProvider;
import org.gradle.authentication.http.BasicAuthentication;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.UncheckedIOException;
import java.nio.file.Files;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.EnumSet;
import java.util.Locale;
import java.util.Properties;
import java.util.Set;
import java.util.stream.Collectors;

/**
 * Takes care of adding tasks and configurations to build developer distributions and releases.
 */
public class ReleasePlugin implements Plugin<Project> {
    private static final Logger LOGGER = LoggerFactory.getLogger(ReleasePlugin.class);

    public static final String SNAPSHOT_REPOSITORY_URL = "https://repo.gradle.org/gradle/ext-snapshots-local";
    private static final String RELEASES_REPOSITORY_URL = "https://dl.bintray.com/adammurdoch/maven";

    private static final DateTimeFormatter SNAPSHOT_TIMESTAMP_FORMATTER = DateTimeFormatter.ofPattern("yyyyMMddHHmmssZ", Locale.US).withZone(ZoneOffset.UTC);
    private static final String BUILD_RECEIPT_NAME = "build-receipt.properties";
    private static final String BUILD_TIMESTAMP_PROPERTY = "buildTimestamp";
    private static final String UPLOAD_MAIN_TASK_NAME = "uploadMain";
    private static final String UPLOAD_JNI_TASK_NAME = "uploadJni";
    private static final String UPLOAD_NCURSES_JNI_TASK_NAME = "uploadNcursesJni";

    @Override
    public void apply(Project project) {
        VersionDetails.BuildType buildType = determineBuildType(project);
        VersionDetails versions = project.getExtensions().create("versions", VersionDetails.class, buildType);

        if (buildType != VersionDetails.BuildType.Dev && JavaVersion.current() != JavaVersion.VERSION_1_8) {
            throw new RuntimeException("Java 8 is required to build a release of native-platform. Later versions are not supported.");
        }

        String buildTimestamp = determineBuildTimestamp(project);
        writeBuildTimestamp(buildTimestamp, project);

        VersionCalculator versionCalculator = new VersionCalculator(versions, buildType, buildTimestamp);

        project.getGradle().getTaskGraph().whenReady(graph -> {
            if (graph.hasTask(":" + UPLOAD_MAIN_TASK_NAME) || graph.hasTask(":" + UPLOAD_JNI_TASK_NAME)) {
                project.getLogger().lifecycle("##teamcity[buildStatus text='{build.status.text}, Published version {}']", versionCalculator);
            }
        });

        project.allprojects(subproject -> {
            subproject.getPlugins().apply(UploadPlugin.class);
            subproject.getPlugins().apply(PublishSnapshotPlugin.class);
            subproject.setVersion(versionCalculator);

            // Use authenticated snapshot/bintray repo while building a test distribution during snapshot/release
            final BintrayCredentials credentials = subproject.getExtensions().getByType(BintrayCredentials.class);

            if (versions.isUseRepo()) {
                credentials.assertPresent();
                String repositoryUrl = buildType == VersionDetails.BuildType.Snapshot
                        ? SNAPSHOT_REPOSITORY_URL
                        : RELEASES_REPOSITORY_URL;
                subproject.getRepositories().maven(repo -> {
                    repo.setUrl(repositoryUrl);
                    repo.getCredentials().setUsername(credentials.getUserName());
                    repo.getCredentials().setPassword(<PASSWORD>.<PASSWORD>ApiKey());
                    repo.getAuthentication().create("basic", BasicAuthentication.class);
                });
            }

            addUploadLifecycleTasks(subproject, buildType);
        });
    }

    private void addUploadLifecycleTasks(Project project, VersionDetails.BuildType buildType) {
        Task uploadMainLifecycle = project.getTasks().maybeCreate(UPLOAD_MAIN_TASK_NAME);
        uploadMainLifecycle.setGroup("Upload");
        uploadMainLifecycle.setDescription("Upload Main publication");

        Task uploadJniLifecycle = project.getTasks().maybeCreate(UPLOAD_JNI_TASK_NAME);
        uploadJniLifecycle.setGroup("Upload");
        uploadJniLifecycle.setDescription("Upload all JNI publications");

        Task uploadNcursesJniLifecycle = project.getTasks().maybeCreate(UPLOAD_NCURSES_JNI_TASK_NAME);
        uploadNcursesJniLifecycle.setGroup("Upload");
        uploadNcursesJniLifecycle.setDescription("Upload only ncurses5/6 JNI publications");

        project.getExtensions().configure(
                PublishingExtension.class,
                extension -> extension.getPublications().withType(MavenPublication.class, publication -> {
                    String uploadTaskName = buildType == VersionDetails.BuildType.Snapshot
                            ? PublishSnapshotPlugin.uploadTaskName(publication)
                            : UploadPlugin.uploadTaskName(publication);
                    TaskProvider<Task> uploadTask = project.getTasks().named(uploadTaskName);
                    if (BasePublishPlugin.isMainPublication(publication)) {
                        uploadMainLifecycle.dependsOn(uploadTask);
                    } else {
                        uploadJniLifecycle.dependsOn(uploadTask);
                        if (uploadTaskName.contains("ncurses")) {
                            uploadNcursesJniLifecycle.dependsOn(uploadTask);
                        }
                    }
                }));
    }

    private void writeBuildTimestamp(String buildTimestamp, Project project) {
        File buildReceiptFile = project.getRootProject().file(BUILD_RECEIPT_NAME);
        try (OutputStream outputStream = Files.newOutputStream(buildReceiptFile.toPath())) {
            Properties properties = new Properties();
            properties.setProperty(BUILD_TIMESTAMP_PROPERTY, buildTimestamp);
            properties.store(outputStream, null);
        } catch (IOException e) {
            throw new UncheckedIOException(e);
        }
{'fraction_non_alphanumeric': 0.09232769830949285, 'fraction_numerical': 0.0009752925877763329, 'mean_word_length': 3.1486850977747807, 'pattern_counts': {'":': 4, '<': 11, '<?xml version=': 0, '>': 21, 'https://': 4, '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': '2966330', 'n_tokens_mistral': 3208, 'n_tokens_neox': 3132, 'n_words': 577}