core/src/main/java/io/fabric8/jube/util/InstallHelper.java
public static void writeEnvironmentVariables(File envScriptFile, Map<String, String> environmentVariables) throws IOException {
        // make sure to create file
        if (!envScriptFile.exists()) {
            envScriptFile.createNewFile();

        }
        List<String> lines = FilesHelper.readLines(envScriptFile);
        // find position to insert variables, which is before first existing environment is set
        int pos = 0;
        for (int i = 0; i < lines.size(); i++) {
            String line = lines.get(i);
            if (Strings.isNullOrBlank(line)) {
                continue;
            }
            line = line.trim();
            if (line.startsWith("set ") || line.startsWith("export ")) {
                pos = i;
                break;
            } else {
                pos = i;
            }
        }

        // insert blank line
        lines.add(pos, "");

        Set<Map.Entry<String, String>> entries = environmentVariables.entrySet();
        for (Map.Entry<String, String> entry : entries) {
            String name = entry.getKey();
            String value = entry.getValue();

            String line;
            if (envScriptFile.getName().endsWith(".bat")) {
                // do not quote on windows
                line = "set " + name + "=" + value;
            } else {
                line = "export " + name + "=\"" + value + "\"";
            }
            lines.add(++pos, line);
        }

        // insert blank line
        lines.add(++pos, "");

        // write lines to file
        Files.writeLines(envScriptFile, lines);
    }
/**
     * Inserts the environment variables to the env.sh/env.bat script file in the top
     */
Inserts the environment variables to the env.sh/env.bat script file in the top
Inserts the environment variables to the env . sh / env . bat script file in the top
public static void writeEnvironmentVariables(File envScriptFile, Map<String, String> environmentVariables) throws IOException {
        if (!envScriptFile.exists()) {
            envScriptFile.createNewFile();
        }
        List<String> lines = FilesHelper.readLines(envScriptFile);
        int pos = 0;
        for (int i = 0; i < lines.size(); i++) {
            String line = lines.get(i);
            if (Strings.isNullOrBlank(line)) {
                continue;
            }
            line = line.trim();
            if (line.startsWith("set ") || line.startsWith("export ")) {
                pos = i;
                break;
            } else {
                pos = i;
            }
        }
        lines.add(pos, "");
        Set<Map.Entry<String, String>> entries = environmentVariables.entrySet();
        for (Map.Entry<String, String> entry : entries) {
            String name = entry.getKey();
            String value = entry.getValue();
            String line;
            if (envScriptFile.getName().endsWith(".bat")) {
                line = "set " + name + "=" + value;
            } else {
                line = "export " + name + "=\"" + value + "\"";
            }
            lines.add(++pos, line);
        }
        lines.add(++pos, "");
        Files.writeLines(envScriptFile, lines);
    }
public static void writeEnvironmentVariables ( File envScriptFile , Map < String , String > environmentVariables ) throws IOException { if ( ! envScriptFile . exists ( ) ) { envScriptFile . createNewFile ( ) ; } List < String > lines = FilesHelper . readLines ( envScriptFile ) ; int pos = 0 ; for ( int i = 0 ; i < lines . size ( ) ; i ++ ) { String line = lines . get ( i ) ; if ( Strings . isNullOrBlank ( line ) ) { continue ; } line = line . trim ( ) ; if ( line . startsWith ( "set " ) || line . startsWith ( "export " ) ) { pos = i ; break ; } else { pos = i ; } } lines . add ( pos , "" ) ; Set < Map . Entry < String , String > > entries = environmentVariables . entrySet ( ) ; for ( Map . Entry < String , String > entry : entries ) { String name = entry . getKey ( ) ; String value = entry . getValue ( ) ; String line ; if ( envScriptFile . getName ( ) . endsWith ( ".bat" ) ) { line = "set " + name + "=" + value ; } else { line = "export " + name + "=\"" + value + "\"" ; } lines . add ( ++ pos , line ) ; } lines . add ( ++ pos , "" ) ; Files . writeLines ( envScriptFile , lines ) ; }
Inserts the environment variables to the env.sh/env.bat script file in the top
Inserts the environment variables to the env . sh / env . bat script file in the top
// make sure to create file // find position to insert variables, which is before first existing environment is set // insert blank line // do not quote on windows // insert blank line // write lines to file