/*
 * Copyright (C) 2016 Satomichi Nishihara
 *
 * This file is distributed under the terms of the
 * GNU General Public License. See the file `LICENSE'
 * in the root directory of the present distribution,
 * or http://www.gnu.org/copyleft/gpl.txt .
 */

package burai.com.env;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class MacCPUInfo extends CPUInfo {

    private static final String CHK_MAC_CPUCOM = "system_profiler SPHardwareDataType";

    private static final String CPU_WORD = "Cores";

    public MacCPUInfo() {
        super();
    }

    @Override
    protected int countNumCPUs() {

        /*
         *  TODO: get #cpus for MacOS.
         */

        int numCPUs = 1;

        try {
            Process process = Runtime.getRuntime().exec(CHK_MAC_CPUCOM);
            BufferedReader in = new BufferedReader(new InputStreamReader(process
                .getInputStream()));

            String line = null;
            while ((line = in.readLine()) != null) {
                line = line.trim();
                if (line.contains(CPU_WORD)){
                    String[] nCPULine = line.split(" ", 0);
                    if (nCPULine.length == 0){
                        numCPUs = 1;
                        break;
                    }
                    else {
                        numCPUs = Integer.parseInt(nCPULine[nCPULine.length -1]);
                    }
                }
            }

        } catch (IOException e) {
            // TODO
            numCPUs = 1;
            e.printStackTrace();
        }

        return numCPUs;
    }
}

@@ -1213,24 +1213,127 @@
 t(%22 %22, 0);%0D%0A
+                    if (nCPULine == null) %7B%0D%0A                        continue;%0D%0A                    %7D%0D%0A
             
@@ -1568,24 +1568,173 @@
 ngth -1%5D);%0D%0A
+                        if (numCPUs %3C= 0)%7B%0D%0A                            numCPUs = 1;%0D%0A                            break;%0D%0A                        %7D%0D%0A
             

check the number of CPU in Mac OS (R2)