Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
/*
 * Copyright 2011 SOFTEC sa. All rights reserved.
 *
 * This source code is licensed under the Creative Commons
 * Attribution-NonCommercial-NoDerivs 3.0 Luxembourg
 * License.
 *
 * To view a copy of this license, visit
 * http://creativecommons.org/licenses/by-nc-nd/3.0/lu/
 * or send a letter to Creative Commons, 171 Second Street,
 * Suite 300, San Francisco, California, 94105, USA.
 */

import java.io.*;
import java.util.ArrayList;

import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main {
    public static String getLatestIosPlatformVersion() {
        List<String> platforms = listAvailableIosPlatformVersions();
        if (!platforms.isEmpty()) {
            return platforms.get(0);
        }
        return "4.3";
    }

    public static List<String> listAvailableIosPlatformVersions() {
        List<String> results = new ArrayList<String>();
        try {
            ProcessBuilder pb = new ProcessBuilder("xcodebuild", "-showsdks");
            pb.redirectErrorStream(true);
            Process p = pb.start();
            BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
            String line = null;
            Pattern pattern = Pattern.compile("-sdk iphoneos(([0-9]+.?)+)");
            while ((line = reader.readLine()) != null) {
                Matcher m = pattern.matcher(line);
                while (m.find()) {
                    results.add(m.group(1));
                }
            }
        } catch (Throwable t) {
        }
        return results;
    }
}