// Path: src/main/java/com/google/jenkins/plugins/storage/UploadException.java
// public class UploadException extends Exception {
//   // Generated serial version ID.
//   private static final long serialVersionUID = 3255684370490910421L;
// 
//   public UploadException(String message) {
//     super(message);
//   }
// 
//   public UploadException(String message, Throwable cause) {
//     super(message, cause);
//   }
// }


import com.google.common.base.Strings;
import com.google.jenkins.plugins.credentials.oauth.GoogleRobotCredentials;
import com.google.jenkins.plugins.storage.UploadException;
import hudson.AbortException;
import hudson.FilePath;
import hudson.Util;
import hudson.model.AbstractBuild;
import hudson.model.Run;
import hudson.model.TaskListener;
import java.io.IOException;
import java.util.LinkedList;
/*
 * Copyright 2017 Google LLC
 *
 * 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
 *
 *     https://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.util;


/** A class to contain common utility operations */
public class StorageUtil {

  /**
   * Compute the relative path of the given file inclusion, relative to the given workspace. If the
   * path is absolute, it returns the root-relative path instead.
   *
   * @param include The file whose relative path we are computing.
   * @param workspace The workspace containing the included file.
   * @return The unix-style relative path of file.
   * @throws UploadException when the input is malformed
   */
  public static String getRelative(FilePath include, FilePath workspace) throws UploadException {
    LinkedList<String> segments = new LinkedList<String>();
    while (!include.equals(workspace)) {
      segments.push(include.getName());
      include = include.getParent();
// Path: src/main/java/com/google/jenkins/plugins/storage/UploadException.java
// public class UploadException extends Exception {
//   // Generated serial version ID.
//   private static final long serialVersionUID = 3255684370490910421L;
// 
//   public UploadException(String message) {
//     super(message);
//   }
// 
//   public UploadException(String message, Throwable cause) {
//     super(message, cause);
//   }
// }


// Path: src/main/java/com/google/jenkins/plugins/storage/util/StorageUtil.java
import com.google.common.base.Strings;
import com.google.jenkins.plugins.credentials.oauth.GoogleRobotCredentials;
import com.google.jenkins.plugins.storage.UploadException;
import hudson.AbortException;
import hudson.FilePath;
import hudson.Util;
import hudson.model.AbstractBuild;
import hudson.model.Run;
import hudson.model.TaskListener;
import java.io.IOException;
import java.util.LinkedList;

/*
 * Copyright 2017 Google LLC
 *
 * 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
 *
 *     https://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.util;


/** A class to contain common utility operations */
public class StorageUtil {

  /**
   * Compute the relative path of the given file inclusion, relative to the given workspace. If the
   * path is absolute, it returns the root-relative path instead.
   *
   * @param include The file whose relative path we are computing.
   * @param workspace The workspace containing the included file.
   * @return The unix-style relative path of file.
   * @throws UploadException when the input is malformed
   */
  public static String getRelative(FilePath include, FilePath workspace) throws UploadException {
    LinkedList<String> segments = new LinkedList<String>();
    while (!include.equals(workspace)) {
      segments.push(include.getName());
      include = include.getParent();
      if (Strings.isNullOrEmpty(include.getName())) {