/*-
 * Copyright (c) 2015-2017 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 org.fedoraproject.xmvn.resolver.impl;

import java.io.IOException;

import org.fedoraproject.xmvn.artifact.Artifact;
import org.fedoraproject.xmvn.logging.impl.Logger;

/**
 * @author Mikolaj Izdebski
 */
class MockAgent
{
    private static final String REQUEST_CMD = System.getProperty( "xmvn.resolver.requestArtifactCmd" );

    private final Logger logger;

    public MockAgent( Logger logger )
    {
        this.logger = logger;
    }

    public boolean tryInstallArtifact( Artifact artifact )
    {
        if ( REQUEST_CMD == null )
            return false;

        try
        {
            String cmd = String.format( "%s maven '%s'", REQUEST_CMD, artifact.toString() );
            logger.debug( "Trying to install artifact with external command: {}", cmd );

            ProcessBuilder pb = new ProcessBuilder( "sh", "-c", cmd );
            pb.redirectInput();
            pb.redirectOutput();
            pb.redirectError();
            int exit = pb.start().waitFor();

            if ( exit == 0 )
            {
                logger.info( "Artifact installed with external command: {}", artifact );
                return true;
            }
            else
            {
                logger.info( "External command failed, exit code is {}", exit );
                return false;
            }
        }
        catch ( IOException e )
        {
            logger.debug( "Failed to launch subprocess", e );
            return false;
        }
        catch ( InterruptedException e )
        {
            throw new RuntimeException( "Interrupted when waiting for subprocess to complete", e );
        }
    }
}

@@ -847,15 +847,8 @@
 ate 
-static 
 fina
@@ -860,78 +860,22 @@
 ing 
-REQUEST_CMD = System.getProperty( %22xmvn.resolver.requestArtifactCmd%22 )
+requestCommand
 ;%0A%0A 
@@ -981,16 +981,104 @@
 logger;%0A
+        this.requestCommand = System.getProperty( %22xmvn.resolver.requestArtifactCmd%22 );%0A
     %7D%0A%0A 
@@ -1154,27 +1154,30 @@
    if ( 
-REQUEST_CMD
+requestCommand
  == null
@@ -1289,19 +1289,22 @@
 '%22, 
-REQUEST_CMD
+requestCommand
 , ar

Move MockAgent command initialization to constructor