import org.apache.commons.dbcp.BasicDataSource;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.core.io.ClassPathResource;
import org.springframework.jdbc.core.JdbcTemplate;

import javax.sql.DataSource;
import java.io.BufferedReader;
import java.io.File;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.URL;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * Created by IntelliJ IDEA.
 * User: Andrey
 * Date: Apr 26, 2010
 * Time: 1:12:20 PM
 * To change this template use File | Settings | File Templates.
 */
public class AtlasInstaller {
    public DataSource getDataSource() {
        return dataSource;
    }

    public void setDataSource(DataSource dataSource) {
        this.dataSource = dataSource;
    }

    public JdbcTemplate getJdbcTemplate() {
        if((null==jdbcTemplate)&&(null!=dataSource)){
            this.jdbcTemplate = new JdbcTemplate(dataSource);
        }
        return jdbcTemplate;
    }

    public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
        this.jdbcTemplate = jdbcTemplate;
    }

    private DataSource dataSource = null;
    private JdbcTemplate jdbcTemplate = null;

    private void runProcess(String workingFolder, String ... args) throws Exception{

        ProcessBuilder pb = new ProcessBuilder(args); //,pathToInstall,connectionString);

        if(null!=workingFolder){
            pb.directory(new File(workingFolder));
        }

        Process child = pb.start();

        BufferedReader stdInput = new BufferedReader(new
                InputStreamReader(child.getInputStream()));

        BufferedReader stdError = new BufferedReader(new
                InputStreamReader(child.getInputStream()));

        String s;
        while ((s = stdInput.readLine()) != null) {
                 System.out.println(s);
        }

        while ((s = stdError.readLine()) != null) {
            System.out.println(s);
        }

        int retCode = child.waitFor();

        if(0!=retCode)
            throw new Exception(String.format("process executed returned %1$s",retCode));
    }

    public void install() throws Exception{
        Runtime rtime = Runtime.getRuntime();

        ClassPathResource r = new ClassPathResource("install.sh");

        //(new ClassPathResource("install.sh"))?
        String pathToInstall = getClass().getResource("install.sh").getPath();
        String workingFolder = getClass().getResource("").getPath();
        String connectionUrl = ((BasicDataSource) dataSource).getUrl();
        String connectionUsername =  ((BasicDataSource) dataSource).getUsername();
        String connectionPassword =  ((BasicDataSource) dataSource).getPassword();

        String connectionString =  String.format("%1$s/%2$s@%3$s"
                                                  ,connectionUsername
                                                  ,connectionPassword
                                                  ,connectionUrl);

        Pattern pattern = Pattern.compile("^jdbc:oracle:thin:@([\\w|.]+):(\\d+):(\\w+)$");
        Matcher matcher = pattern.matcher(connectionUrl);
        if(matcher.find()){
            String serverUrl = matcher.group(1);
            String serverPort = matcher.group(2);
            String serverServiceName = matcher.group(3);

            connectionString =  String.format("%1$s/%2$s@%3$s:%4$s/%5$s"
                                              ,connectionUsername
                                              ,connectionPassword
                                              ,serverUrl
                                              ,serverPort
                                              ,serverServiceName);
        }

        /*
        String command = String.format("sh %1$s %2$s"
                                       , pathToInstall
                                       , connectionString);
        */

        System.out.println(pathToInstall);

        String command = String.format("sh %1$s %2$s\n",pathToInstall,connectionString);
        command = String.format("chmod +x %1$s",pathToInstall);

        int retCode = 0;

        runProcess(null,"chmod","+x",pathToInstall);

        runProcess(workingFolder,pathToInstall,connectionString);
    }
}

@@ -45,192 +45,8 @@
 ce;%0A
-import org.springframework.context.ApplicationContext;%0Aimport org.springframework.context.support.ClassPathXmlApplicationContext;%0Aimport org.springframework.core.io.ClassPathResource;%0A
 impo
@@ -212,64 +212,8 @@
 er;%0A
-import java.io.OutputStreamWriter;%0Aimport java.net.URL;%0A
 impo
@@ -695,16 +695,19 @@
   if
+ 
 ((null
+ 
 ==
+ 
 jdbc
@@ -719,17 +719,21 @@
 ate)
+ 
 &&
+ 
 (null
+ 
 !=
+ 
 data
@@ -740,16 +740,17 @@
 Source))
+ 
 %7B%0A      
@@ -1106,17 +1106,16 @@
 , String
- 
 ... args
@@ -1132,16 +1132,17 @@
 xception
+ 
 %7B%0A%0A     
@@ -1241,15 +1241,18 @@
   if
+ 
 (null
+ 
 !=
+ 
 work
@@ -1261,16 +1261,17 @@
 gFolder)
+ 
 %7B%0A      
@@ -1677,29 +1677,24 @@
             
-     
 System.out.p
@@ -1867,12 +1867,15 @@
   if
+ 
 (0
+ 
 !=
+ 
 retC
@@ -1958,16 +1958,17 @@
 d %251$s%22,
+ 
 retCode)
@@ -2023,173 +2023,10 @@
 tion
+ 
 %7B
-%0A        Runtime rtime = Runtime.getRuntime();%0A%0A        ClassPathResource r = new ClassPathResource(%22install.sh%22);%0A%0A        //(new ClassPathResource(%22install.sh%22))?
 %0A   
@@ -2277,17 +2277,16 @@
 ername =
- 
  ((Basic
@@ -2359,17 +2359,16 @@
 ssword =
- 
  ((Basic
@@ -2432,33 +2432,32 @@
 nnectionString =
- 
  String.format(%22
@@ -2475,200 +2475,50 @@
 3$s%22
-%0A                                                  ,connectionUsername%0A                                                  ,connectionPassword%0A                                                  ,
+, connectionUsername, connectionPassword, 
 conn
@@ -2689,16 +2689,17 @@
       if
+ 
 (matcher
@@ -2706,16 +2706,17 @@
 .find())
+ 
 %7B%0A      
@@ -2896,17 +2896,16 @@
 String =
- 
  String.
@@ -2941,56 +2941,10 @@
 5$s%22
-%0A                                              
 ,
+ 
 conn
@@ -2957,16 +2957,17 @@
 Username
+,
 %0A       
@@ -2983,660 +2983,123 @@
     
-                          ,connectionPassword%0A                                              ,serverUrl%0A                                              ,serverPort%0A                                              ,serverServiceName);%0A        %7D%0A%0A        /*%0A        String command = String.format(%22sh %251$s %252$s%22%0A                                       , pathToInstall%0A                                       , connectionString);%0A        */%0A%0A        System.out.println(pathToInstall);%0A%0A        String command = String.format(%22sh %251$s %252$s%5Cn%22,pathToInstall,connectionString);%0A        command = String.format(%22chmod +x %251$s%22,pathToInstall);%0A%0A        int retCode = 0
+connectionPassword, serverUrl, serverPort, serverServiceName);%0A        %7D%0A%0A        System.out.println(pathToInstall)
 ;%0A%0A 
@@ -3125,16 +3125,17 @@
 ull,
+ 
 %22chmod%22,
 %22+x%22
@@ -3134,13 +3134,15 @@
 od%22,
+ 
 %22+x%22,
+ 
 path
@@ -3187,16 +3187,17 @@
 gFolder,
+ 
 pathToIn
@@ -3194,32 +3194,33 @@
 , pathToInstall,
+ 
 connectionString

Dead store to local variable This instruction assigns a value to a local variable, but the value is not read or used in any subsequent instruction. Often, this indicates an error, because the value computed is never used.