/*
 * Copyright 2012 the original author or authors.
 *
 * 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 org.gradle.internal.nativeplatform.jna;

import org.gradle.internal.nativeplatform.*;

import java.io.File;
import java.util.Map;

/**
 * Temporary environment for analyzing stability issues with IBM JDK.
 */
public class TemporaryIbmProcessEnvironment implements ProcessEnvironment {
    private final ProcessEnvironment delegate;

    public TemporaryIbmProcessEnvironment(ProcessEnvironment delegate) {
        this.delegate = delegate;
    }

    public Long getPid() throws NativeIntegrationException {
        return delegate.getPid();
    }

    public File getProcessDir() throws NativeIntegrationException {
        throw new NativeIntegrationException("TemporaryIbmProcessEnvironment doesn't implement getProcessDir()");
    }

    public void setProcessDir(File processDir) throws NativeIntegrationException {
        throw new NativeIntegrationException("TemporaryIbmProcessEnvironment doesn't implement setProcessDir()");
    }

    public void setEnvironmentVariable(String name, String value) throws NativeIntegrationException {
        throw new NativeIntegrationException("TemporaryIbmProcessEnvironment doesn't implement setEnvironmentVariable()");
    }

    public void removeEnvironmentVariable(String name) throws NativeIntegrationException {
        throw new NativeIntegrationException("TemporaryIbmProcessEnvironment doesn't implement removeEnvironmentVariable()");
    }

    public Long maybeGetPid() {
        return delegate.maybeGetPid();
    }

    public boolean maybeSetProcessDir(File processDir) {
        return false;
    }

    public boolean maybeSetEnvironment(Map<String, String> source) {
        return false;
    }

    public boolean maybeSetEnvironmentVariable(String name, String value) {
        return false;
    }

    public boolean maybeRemoveEnvironmentVariable(String name) {
        return false;
    }
}

@@ -1673,95 +1673,17 @@
     
-throw new NativeInt
+del
 eg
-r
 at
-ionException(%22TemporaryIbmProcessEnvironment doesn't implement 
+e.
 setE
@@ -1693,34 +1693,43 @@
 ronmentVariable(
-)%22
+name, value
 );%0A    %7D%0A%0A    pu
@@ -1825,95 +1825,17 @@
     
-throw new NativeInt
+del
 eg
-r
 at
-ionException(%22TemporaryIbmProcessEnvironment doesn't implement 
+e.
 remo
@@ -1856,18 +1856,20 @@
 ariable(
-)%22
+name
 );%0A    %7D
@@ -2110,37 +2110,68 @@
 %0A        return 
-false
+delegate.maybeSetEnvironment(source)
 ;%0A    %7D%0A%0A    pub
@@ -2246,37 +2246,81 @@
 %0A        return 
-false
+delegate.maybeSetEnvironmentVariable(name, value)
 ;%0A    %7D%0A%0A    pub
@@ -2384,31 +2384,62 @@
 %0A        return 
-false
+maybeRemoveEnvironmentVariable(name)
 ;%0A    %7D%0A%7D%0A

bring back native environment variable handling for IBM JDKs (experiment to find stability issues)