/**
 * Copyright (C) 2016 Red Hat, Inc.
 *
 * 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 io.fabric8.jenkins.openshiftsync;

import hudson.Extension;
import hudson.model.Job;
import hudson.model.JobProperty;
import hudson.model.JobPropertyDescriptor;
import io.fabric8.openshift.api.model.BuildConfig;
import jenkins.model.ParameterizedJobMixIn;
import org.kohsuke.stapler.DataBoundConstructor;

import static io.fabric8.jenkins.openshiftsync.OpenShiftUtils.getOpenShiftClient;

/**
 * Stores the OpenShift Build Config related project properties.
 *
 * - Namespace
 * - Build config name
 * - Build config uid
 */
public class BuildConfigProjectProperty extends JobProperty<Job<?, ?>> {

  // The build config uid this job relates to.
  private String uid;

  private String namespace;

  private String name;

  private String resourceVersion;

  private String contextDir;

  @DataBoundConstructor
  public BuildConfigProjectProperty(String namespace, String name, String uid, String resourceVersion, String contextDir) {
    this.namespace = namespace;
    this.name = name;
    this.uid = uid;
    this.resourceVersion = resourceVersion;
    this.contextDir = contextDir;
  }

  public BuildConfigProjectProperty(BuildConfig bc) {
    this(
      bc.getMetadata().getNamespace(),
      bc.getMetadata().getName(),
      bc.getMetadata().getUid(),
      bc.getMetadata().getResourceVersion(),
      bc.getSpec().getSource().getContextDir()
    );
  }

  public String getUid() {
    return uid;
  }

  public BuildConfig getBuildConfig() {
    BuildConfig bc = getOpenShiftClient().buildConfigs().inNamespace(namespace).withName(name).get();
    if (bc != null && bc.getMetadata().getUid().equals(uid)) {
      return bc;
    }
    return null;
  }

  public String getName() {
    return name;
  }

  public String getNamespace() {
    return namespace;
  }

  public String getResourceVersion() {
    return resourceVersion;
  }

  public void setResourceVersion(String resourceVersion) {
    this.resourceVersion = resourceVersion;
  }

  public String getContextDir() {
    return contextDir;
  }

  @Extension
  public static final class DescriptorImpl extends JobPropertyDescriptor {
    public boolean isApplicable(Class<? extends Job> jobType) {
      return ParameterizedJobMixIn.ParameterizedJob.class.isAssignableFrom(jobType);
    }
  }
}

@@ -1368,37 +1368,8 @@
 n;%0A%0A
-  private String contextDir;%0A
 %0A  @
@@ -1494,27 +1494,8 @@
 sion
-, String contextDir
 ) %7B%0A
@@ -1616,42 +1616,8 @@
 on;%0A
-    this.contextDir = contextDir;%0A
   %7D%0A
@@ -1836,55 +1836,8 @@
 (),%0A
-      bc.getSpec().getSource().getContextDir()%0A
     

Remove unused contextDir from build property