// Path: src/main/java/org/jenkinsci/plugins/credentialsbinding/BindingDescriptor.java
// public abstract class BindingDescriptor<C extends StandardCredentials> extends Descriptor<MultiBinding<C>> {
// 
//     protected abstract Class<C> type();
// 
//     /**
//      * Determines whether this {@link MultiBinding} needs a workspace to evaluate.
//      */
//     public boolean requiresWorkspace() {
//         return true;
//     }
// 
//     public ListBoxModel doFillCredentialsIdItems(@AncestorInPath Item owner) {
//         if (owner == null || !owner.hasPermission(Item.CONFIGURE)) {
//             return new ListBoxModel();
//         }
//         // when configuring the job, you only want those credentials that are available to ACL.SYSTEM selectable
//         // as we cannot select from a user's credentials unless they are the only user submitting the build
//         // (which we cannot assume) thus ACL.SYSTEM is correct here.
//         return new Model().withAll(CredentialsProvider.lookupCredentials(type(), owner, ACL.SYSTEM, Collections.emptyList()));
//     }
// 
//     private final class Model extends AbstractIdCredentialsListBoxModel<Model,C> {
// 
//         @NonNull
//         @Override
//         protected String describe(@NonNull C c) {
//             return CredentialsNameProvider.name(c);
//         }
// 
//     }
// 
// }


import hudson.model.TaskListener;
import java.io.IOException;
import org.jenkinsci.Symbol;
import org.jenkinsci.plugins.credentialsbinding.BindingDescriptor;
import org.jenkinsci.plugins.plaincredentials.FileCredentials;
import org.kohsuke.stapler.DataBoundConstructor;
import edu.umd.cs.findbugs.annotations.NonNull;
import edu.umd.cs.findbugs.annotations.Nullable;
import hudson.Extension;
import hudson.FilePath;
import hudson.Launcher;
import hudson.model.Run;
/*
 * The MIT License
 *
 * Copyright 2013 jglick.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */

package org.jenkinsci.plugins.credentialsbinding.impl;




public class FileBinding extends AbstractOnDiskBinding<FileCredentials> {

    @DataBoundConstructor public FileBinding(String variable, String credentialsId) {
        super(variable, credentialsId);
    }

    @Override protected Class<FileCredentials> type() {
        return FileCredentials.class;
    }

    @Override protected final FilePath write(FileCredentials credentials, FilePath dir) throws IOException, InterruptedException {
        FilePath secret = dir.child(credentials.getFileName());
        secret.copyFrom(credentials.getContent());
        secret.chmod(0400);
        return secret;
    }

    @SuppressWarnings("unused")
    @Deprecated
    private static class UnbinderImpl implements Unbinder {
        private static final long serialVersionUID = 1;
        private final String dirName;

        private UnbinderImpl(String dirName) {
            this.dirName = dirName;
        }

// Path: src/main/java/org/jenkinsci/plugins/credentialsbinding/BindingDescriptor.java
// public abstract class BindingDescriptor<C extends StandardCredentials> extends Descriptor<MultiBinding<C>> {
// 
//     protected abstract Class<C> type();
// 
//     /**
//      * Determines whether this {@link MultiBinding} needs a workspace to evaluate.
//      */
//     public boolean requiresWorkspace() {
//         return true;
//     }
// 
//     public ListBoxModel doFillCredentialsIdItems(@AncestorInPath Item owner) {
//         if (owner == null || !owner.hasPermission(Item.CONFIGURE)) {
//             return new ListBoxModel();
//         }
//         // when configuring the job, you only want those credentials that are available to ACL.SYSTEM selectable
//         // as we cannot select from a user's credentials unless they are the only user submitting the build
//         // (which we cannot assume) thus ACL.SYSTEM is correct here.
//         return new Model().withAll(CredentialsProvider.lookupCredentials(type(), owner, ACL.SYSTEM, Collections.emptyList()));
//     }
// 
//     private final class Model extends AbstractIdCredentialsListBoxModel<Model,C> {
// 
//         @NonNull
//         @Override
//         protected String describe(@NonNull C c) {
//             return CredentialsNameProvider.name(c);
//         }
// 
//     }
// 
// }


// Path: src/main/java/org/jenkinsci/plugins/credentialsbinding/impl/FileBinding.java
import hudson.model.TaskListener;
import java.io.IOException;
import org.jenkinsci.Symbol;
import org.jenkinsci.plugins.credentialsbinding.BindingDescriptor;
import org.jenkinsci.plugins.plaincredentials.FileCredentials;
import org.kohsuke.stapler.DataBoundConstructor;
import edu.umd.cs.findbugs.annotations.NonNull;
import edu.umd.cs.findbugs.annotations.Nullable;
import hudson.Extension;
import hudson.FilePath;
import hudson.Launcher;
import hudson.model.Run;

/*
 * The MIT License
 *
 * Copyright 2013 jglick.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */

package org.jenkinsci.plugins.credentialsbinding.impl;




public class FileBinding extends AbstractOnDiskBinding<FileCredentials> {

    @DataBoundConstructor public FileBinding(String variable, String credentialsId) {
        super(variable, credentialsId);
    }

    @Override protected Class<FileCredentials> type() {
        return FileCredentials.class;
    }

    @Override protected final FilePath write(FileCredentials credentials, FilePath dir) throws IOException, InterruptedException {
        FilePath secret = dir.child(credentials.getFileName());
        secret.copyFrom(credentials.getContent());
        secret.chmod(0400);
        return secret;
    }

    @SuppressWarnings("unused")
    @Deprecated
    private static class UnbinderImpl implements Unbinder {
        private static final long serialVersionUID = 1;
        private final String dirName;

        private UnbinderImpl(String dirName) {
            this.dirName = dirName;
        }

        protected Object readResolve() {