<commit_before>package com.demandware.studio.webdav;

import com.demandware.studio.toolWindow.DWConsoleService;
import com.intellij.execution.ui.ConsoleView;
import com.intellij.execution.ui.ConsoleViewContentType;
import com.intellij.notification.Notification;
import com.intellij.notification.NotificationType;
import com.intellij.notification.Notifications;
import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.progress.PerformInBackgroundOption;
import com.intellij.openapi.progress.ProgressIndicator;
import com.intellij.openapi.progress.Task;
import com.intellij.openapi.project.Project;
import org.apache.http.client.CredentialsProvider;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.client.methods.RequestBuilder;
import org.apache.http.client.protocol.HttpClientContext;
import org.apache.http.entity.FileEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.jetbrains.annotations.NotNull;

import java.io.File;
import java.io.IOException;
import java.net.UnknownHostException;
import java.util.ArrayList;

public class DWUpdateFileTask extends Task.Backgroundable {
    private final Logger LOG = Logger.getInstance(DWUpdateFileTask.class);

    private final CloseableHttpClient httpClient;
    private final HttpClientContext context;
    private final ArrayList<String> remoteDirPaths;
    private final String remoteFilePath;
    private final String localFilePath;
    private final Project project;

    public DWUpdateFileTask(Project project,
                            final String title,
                            final boolean canBeCancelled,
                            final PerformInBackgroundOption backgroundOption,
                            CloseableHttpClient httpClient,
                            CredentialsProvider credentialsProvider,
                            ArrayList<String> remoteDirPaths,
                            String remoteFilePath,
                            String localFilePath) {
        super(project, title, canBeCancelled, backgroundOption);
        this.project = project;
        this.httpClient = httpClient;
        this.context = new HttpClientContext();
        this.context.setCredentialsProvider(credentialsProvider);
        this.remoteDirPaths = remoteDirPaths;
        this.remoteFilePath = remoteFilePath;
        this.localFilePath = localFilePath;
    }

    @Override
    public void run(@NotNull ProgressIndicator indicator) {
        boolean isNewRemoteFile = true;
        ConsoleView consoleView = ServiceManager.getService(project, DWConsoleService.class).getConsoleView();
        indicator.setFraction(.33);

        HttpUriRequest getRequest = RequestBuilder.create("GET").setUri(remoteFilePath).build();
        try {
            CloseableHttpResponse response = httpClient.execute(getRequest, context);
            if (response.getStatusLine().getStatusCode() == 200) {
                isNewRemoteFile = false;
            }
            if (response.getStatusLine().getStatusCode() == 401) {
                Notifications.Bus.notify(new Notification("Demandware", "Unauthorized Request",
                        "Please check your server configuration in the Demandware facet settings.", NotificationType.INFORMATION));
                return;
            }
            response.close();
        } catch (UnknownHostException e) {
            Notifications.Bus.notify(new Notification("Demandware", "Unknown Host",
                    "Please check your server configuration in the Demandware facet settings.", NotificationType.INFORMATION));
            return;
        } catch (IOException e) {
            e.printStackTrace();
        }

        indicator.setFraction(.5);

        // Create Remote Directories if file is a new local or remote file
        if (isNewRemoteFile) {
            for (String path : remoteDirPaths) {
                HttpUriRequest mkcolRequest = RequestBuilder.create("MKCOL").setUri(path + "/").build();
                try {
                    try (CloseableHttpResponse response = httpClient.execute(mkcolRequest, context)) {
                        if (response.getStatusLine().getStatusCode() == 201) {
                            consoleView.print("[Created] " + mkcolRequest.getURI().toString() + "\n", ConsoleViewContentType.NORMAL_OUTPUT);
                        }
                    }
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }

        indicator.setFraction(.80);

        // Put remote file
        HttpUriRequest request = RequestBuilder.create("PUT")
                .setUri(remoteFilePath)
                .setEntity(new FileEntity(new File(localFilePath)))
                .build();

        try {
            try (CloseableHttpResponse response = httpClient.execute(request, context)) {
                if (isNewRemoteFile) {
                    consoleView.print("[Created] " + request.getURI().toString() + "\n", ConsoleViewContentType.NORMAL_OUTPUT);
                } else {
                    consoleView.print("[Updated] " + request.getURI().toString() + "\n", ConsoleViewContentType.NORMAL_OUTPUT);
                }
            }
        } catch (IOException e) {
            LOG.error(e);
        }

        indicator.setFraction(1);
    }
}
<commit_msg>Added timestamps to upload events<commit_after>package com.demandware.studio.webdav;

import com.demandware.studio.toolWindow.DWConsoleService;
import com.intellij.execution.ui.ConsoleView;
import com.intellij.execution.ui.ConsoleViewContentType;
import com.intellij.notification.Notification;
import com.intellij.notification.NotificationType;
import com.intellij.notification.Notifications;
import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.progress.PerformInBackgroundOption;
import com.intellij.openapi.progress.ProgressIndicator;
import com.intellij.openapi.progress.Task;
import com.intellij.openapi.project.Project;
import org.apache.http.client.CredentialsProvider;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.client.methods.RequestBuilder;
import org.apache.http.client.protocol.HttpClientContext;
import org.apache.http.entity.FileEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.jetbrains.annotations.NotNull;

import java.io.File;
import java.io.IOException;
import java.net.UnknownHostException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;

public class DWUpdateFileTask extends Task.Backgroundable {
    private final Logger LOG = Logger.getInstance(DWUpdateFileTask.class);

    private final CloseableHttpClient httpClient;
    private final HttpClientContext context;
    private final ArrayList<String> remoteDirPaths;
    private final String remoteFilePath;
    private final String localFilePath;
    private final Project project;
    private final SimpleDateFormat timeFormat = new SimpleDateFormat("hh:mm:ss");

    public DWUpdateFileTask(Project project,
                            final String title,
                            final boolean canBeCancelled,
                            final PerformInBackgroundOption backgroundOption,
                            CloseableHttpClient httpClient,
                            CredentialsProvider credentialsProvider,
                            ArrayList<String> remoteDirPaths,
                            String remoteFilePath,
                            String localFilePath) {
        super(project, title, canBeCancelled, backgroundOption);
        this.project = project;
        this.httpClient = httpClient;
        this.context = new HttpClientContext();
        this.context.setCredentialsProvider(credentialsProvider);
        this.remoteDirPaths = remoteDirPaths;
        this.remoteFilePath = remoteFilePath;
        this.localFilePath = localFilePath;
    }

    @Override
    public void run(@NotNull ProgressIndicator indicator) {
        boolean isNewRemoteFile = true;
        ConsoleView consoleView = ServiceManager.getService(project, DWConsoleService.class).getConsoleView();
        indicator.setFraction(.33);

        HttpUriRequest getRequest = RequestBuilder.create("GET").setUri(remoteFilePath).build();
        try {
            CloseableHttpResponse response = httpClient.execute(getRequest, context);
            if (response.getStatusLine().getStatusCode() == 200) {
                isNewRemoteFile = false;
            }
            if (response.getStatusLine().getStatusCode() == 401) {
                Notifications.Bus.notify(new Notification("Demandware", "Unauthorized Request",
                        "Please check your server configuration in the Demandware facet settings.", NotificationType.INFORMATION));
                return;
            }
            response.close();
        } catch (UnknownHostException e) {
            Notifications.Bus.notify(new Notification("Demandware", "Unknown Host",
                    "Please check your server configuration in the Demandware facet settings.", NotificationType.INFORMATION));
            return;
        } catch (IOException e) {
            e.printStackTrace();
        }

        indicator.setFraction(.5);

        // Create Remote Directories if file is a new local or remote file
        if (isNewRemoteFile) {
            for (String path : remoteDirPaths) {
                HttpUriRequest mkcolRequest = RequestBuilder.create("MKCOL").setUri(path + "/").build();
                try {
                    try (CloseableHttpResponse response = httpClient.execute(mkcolRequest, context)) {
                        if (response.getStatusLine().getStatusCode() == 201) {
                            Date now = new Date();
                            consoleView.print("[" + timeFormat.format(now) + "] " + "Created " + mkcolRequest.getURI().toString() + "\n", ConsoleViewContentType.NORMAL_OUTPUT);
                        }
                    }
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }

        indicator.setFraction(.80);

        // Put remote file
        HttpUriRequest request = RequestBuilder.create("PUT")
                .setUri(remoteFilePath)
                .setEntity(new FileEntity(new File(localFilePath)))
                .build();

        try {
            try (CloseableHttpResponse response = httpClient.execute(request, context)) {
                if (isNewRemoteFile) {
                    Date now = new Date();
                    consoleView.print("[" + timeFormat.format(now) + "] " + "Created " + request.getURI().toString() + "\n", ConsoleViewContentType.NORMAL_OUTPUT);
                } else {
                    Date now = new Date();
                    consoleView.print("[" + timeFormat.format(now) + "] " + "Updated " + request.getURI().toString() + "\n", ConsoleViewContentType.NORMAL_OUTPUT);
                }
            }
        } catch (IOException e) {
            LOG.error(e);
        }

        indicator.setFraction(1);
    }
}

{'fraction_non_alphanumeric': 0.09106120651695289, 'fraction_numerical': 0.002642007926023778, 'mean_word_length': 2.4112346049864826, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '5708974', 'n_tokens_mistral': 2835, 'n_tokens_neox': 2729, 'n_words': 568}