<commit_before>/*
 * Copyright 2013 Google Inc. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.google.jenkins.plugins.storage;

import static java.util.logging.Level.SEVERE;

import java.io.IOException;
import java.io.Serializable;
import java.math.BigInteger;
import java.net.URLConnection;
import java.security.GeneralSecurityException;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Queue;
import java.util.logging.Logger;

import javax.annotation.Nullable;

import org.apache.commons.io.FilenameUtils;
import org.jenkinsci.remoting.RoleChecker;

import static com.google.api.client.http.HttpStatusCodes.STATUS_CODE_UNAUTHORIZED;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.jenkins.plugins.storage.AbstractUploadDescriptor.GCS_SCHEME;

import com.google.api.client.googleapis.media.MediaHttpUploader;
import com.google.api.client.http.HttpResponseException;
import com.google.api.client.http.InputStreamContent;
import com.google.api.services.storage.Storage;
import com.google.api.services.storage.model.Bucket;
import com.google.api.services.storage.model.ObjectAccessControl;
import com.google.api.services.storage.model.StorageObject;
import com.google.common.base.Joiner;
import com.google.common.base.Objects;
import com.google.common.base.Predicate;
import com.google.common.base.Strings;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import com.google.common.io.Files;
import com.google.jenkins.plugins.credentials.oauth.GoogleRobotCredentials;
import com.google.jenkins.plugins.metadata.MetadataContainer;
import com.google.jenkins.plugins.storage.reports.BuildGcsUploadReport;
import com.google.jenkins.plugins.util.ConflictException;
import com.google.jenkins.plugins.util.Executor;
import com.google.jenkins.plugins.util.ExecutorException;
import com.google.jenkins.plugins.util.ForbiddenException;
import com.google.jenkins.plugins.util.NotFoundException;

import hudson.DescriptorExtensionList;
import hudson.ExtensionPoint;
import hudson.FilePath;
import hudson.Util;
import hudson.model.AbstractBuild;
import hudson.model.Describable;
import hudson.model.Hudson;
import hudson.model.Result;
import hudson.model.TaskListener;
import hudson.remoting.Callable;

/**
 * This new extension point is used for surfacing different kinds of
 * Google Cloud Storage (GCS) uploads.  The most obvious implementations
 * are provided as:
 * @see ClassicUpload
 * @see StdoutUpload
 *
 * We provide the following hooks for implementations to inject additional
 * functionality:
 * <ul>
 *   <li> Required {@link #getDetails}: provides detail information for the
 * GCS upload report.
 *   <li> Required {@link #getInclusions}: surfaces the set of
 * {@link UploadSpec} for the base class to upload to GCS.
 *
 *   <li> Optional {@link #forResult}: determines the build states for which
 * uploading should be performed.
 *   <li> Optional {@link #getMetadata}: allows the implementation to surface
 * additional metadata on the storage object
 *   <li> Optional {@link #annotateObject}: allows the implementation to
 * ~arbitrarily rewrite parts of the object prior to insertion.
 * </ul>
 */
public abstract class AbstractUpload
    implements Describable<AbstractUpload>, ExtensionPoint, Serializable {
  // Only attempt to refresh the remote credentials once per 401 received.
  protected static final int MAX_REMOTE_CREDENTIAL_EXPIRED_RETRIES = 1;
  private static final Logger logger =
      Logger.getLogger(AbstractUpload.class.getName());
  private static final ImmutableMap<String, String> CONTENT_TYPES =
      ImmutableMap.of(
        "css", "text/css",
        "js", "application/javascript",
        "svg", "image/svg+xml"
      );

  /**
   * Construct the base upload from a handful of universal properties.
   *
   * @param bucket The unresolved name of the storage bucket within
   * which to store the resulting objects.
   * @param sharedPublicly Whether to publicly share the objects being uploaded
   * @param forFailedJobs Whether to perform the upload regardless of the
   * build's outcome
   * @param showInline Whether to indicate in metadata that the file should be
   * viewable inline in web browsers, rather than requiring it to be downloaded
   * first.
   * @param pathPrefix Path prefix to strip from uploaded files when determining
   * the filename in GCS. Null indicates no stripping. Filenames that do not
   * start with this prefix will not be modified. Trailing slash is
   * automatically added if it is missing.
   */
  public AbstractUpload(String bucket, boolean sharedPublicly,
      boolean forFailedJobs, boolean showInline, @Nullable String pathPrefix,
      @Nullable UploadModule module) {
    if (module != null) {<commit_msg>Added 'woff2' mime type definition<commit_after>/*
 * Copyright 2013 Google Inc. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.google.jenkins.plugins.storage;

import static java.util.logging.Level.SEVERE;

import java.io.IOException;
import java.io.Serializable;
import java.math.BigInteger;
import java.net.URLConnection;
import java.security.GeneralSecurityException;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Queue;
import java.util.logging.Logger;

import javax.annotation.Nullable;

import org.apache.commons.io.FilenameUtils;
import org.jenkinsci.remoting.RoleChecker;

import static com.google.api.client.http.HttpStatusCodes.STATUS_CODE_UNAUTHORIZED;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.jenkins.plugins.storage.AbstractUploadDescriptor.GCS_SCHEME;

import com.google.api.client.googleapis.media.MediaHttpUploader;
import com.google.api.client.http.HttpResponseException;
import com.google.api.client.http.InputStreamContent;
import com.google.api.services.storage.Storage;
import com.google.api.services.storage.model.Bucket;
import com.google.api.services.storage.model.ObjectAccessControl;
import com.google.api.services.storage.model.StorageObject;
import com.google.common.base.Joiner;
import com.google.common.base.Objects;
import com.google.common.base.Predicate;
import com.google.common.base.Strings;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import com.google.common.io.Files;
import com.google.jenkins.plugins.credentials.oauth.GoogleRobotCredentials;
import com.google.jenkins.plugins.metadata.MetadataContainer;
import com.google.jenkins.plugins.storage.reports.BuildGcsUploadReport;
import com.google.jenkins.plugins.util.ConflictException;
import com.google.jenkins.plugins.util.Executor;
import com.google.jenkins.plugins.util.ExecutorException;
import com.google.jenkins.plugins.util.ForbiddenException;
import com.google.jenkins.plugins.util.NotFoundException;

import hudson.DescriptorExtensionList;
import hudson.ExtensionPoint;
import hudson.FilePath;
import hudson.Util;
import hudson.model.AbstractBuild;
import hudson.model.Describable;
import hudson.model.Hudson;
import hudson.model.Result;
import hudson.model.TaskListener;
import hudson.remoting.Callable;

/**
 * This new extension point is used for surfacing different kinds of
 * Google Cloud Storage (GCS) uploads.  The most obvious implementations
 * are provided as:
 * @see ClassicUpload
 * @see StdoutUpload
 *
 * We provide the following hooks for implementations to inject additional
 * functionality:
 * <ul>
 *   <li> Required {@link #getDetails}: provides detail information for the
 * GCS upload report.
 *   <li> Required {@link #getInclusions}: surfaces the set of
 * {@link UploadSpec} for the base class to upload to GCS.
 *
 *   <li> Optional {@link #forResult}: determines the build states for which
 * uploading should be performed.
 *   <li> Optional {@link #getMetadata}: allows the implementation to surface
 * additional metadata on the storage object
 *   <li> Optional {@link #annotateObject}: allows the implementation to
 * ~arbitrarily rewrite parts of the object prior to insertion.
 * </ul>
 */
public abstract class AbstractUpload
    implements Describable<AbstractUpload>, ExtensionPoint, Serializable {
  // Only attempt to refresh the remote credentials once per 401 received.
  protected static final int MAX_REMOTE_CREDENTIAL_EXPIRED_RETRIES = 1;
  private static final Logger logger =
      Logger.getLogger(AbstractUpload.class.getName());
  private static final ImmutableMap<String, String> CONTENT_TYPES =
      ImmutableMap.of(
        "css", "text/css",
        "js", "application/javascript",
        "svg", "image/svg+xml",
        "woff2", "font/woff2"
      );

  /**
   * Construct the base upload from a handful of universal properties.
   *
   * @param bucket The unresolved name of the storage bucket within
   * which to store the resulting objects.
   * @param sharedPublicly Whether to publicly share the objects being uploaded
   * @param forFailedJobs Whether to perform the upload regardless of the
   * build's outcome
   * @param showInline Whether to indicate in metadata that the file should be
   * viewable inline in web browsers, rather than requiring it to be downloaded
   * first.
   * @param pathPrefix Path prefix to strip from uploaded files when determining
   * the filename in GCS. Null indicates no stripping. Filenames that do not
   * start with this prefix will not be modified. Trailing slash is
   * automatically added if it is missing.
   */
  public AbstractUpload(String bucket, boolean sharedPublicly,
      boolean forFailedJobs, boolean showInline, @Nullable String pathPrefix,
      @Nullable UploadModule module) {
    if (module != null) {
{'fraction_non_alphanumeric': 0.0855001805706031, 'fraction_numerical': 0.002437703141928494, 'mean_word_length': 4.698045267489712, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2144131', 'n_tokens_mistral': 3056, 'n_tokens_neox': 2985, 'n_words': 984}