FileDocCategorySizeDatePackage
VersionCheck.javaAPI DocAndroid 1.5 API4563Wed May 06 22:41:10 BST 2009com.android.ide.eclipse.adt

VersionCheck

public final class VersionCheck extends Object
Class handling the version check for the plugin vs. the SDK.
The plugin must be able to support all version of the SDK.

An SDK can require a new version of the plugin.

The SDK contains a file with the minimum version for the plugin. This file is inside the tools/lib directory, and is called plugin.prop.
Inside that text file, there is a line in the format "plugin.version=#.#.#". This is checked against the current plugin version.

Fields Summary
private static final Pattern
sPluginVersionPattern
Pattern to get the minimum plugin version supported by the SDK. This is read from the file $SDK/tools/lib/plugin.prop.
Constructors Summary
Methods Summary
public static booleancheckVersion(java.lang.String osSdkPath, com.android.ide.eclipse.adt.AdtPlugin.CheckSdkErrorHandler errorHandler)
Checks the plugin and the SDK have compatible versions.

param
osSdkPath The path to the SDK
return
true if compatible.

 //$NON-NLS-1$

                             
           
        AdtPlugin plugin = AdtPlugin.getDefault();
        String osLibs = osSdkPath + SdkConstants.OS_SDK_TOOLS_LIB_FOLDER;

        // get the plugin property file, and grab the minimum plugin version required
        // to work with the sdk
        int minMajorVersion = -1;
        int minMinorVersion = -1;
        int minMicroVersion = -1;
        try {
            FileReader reader = new FileReader(osLibs + SdkConstants.FN_PLUGIN_PROP);
            BufferedReader bReader = new BufferedReader(reader);
            String line;
            while ((line = bReader.readLine()) != null) {
                Matcher m = sPluginVersionPattern.matcher(line);
                if (m.matches()) {
                    minMajorVersion = Integer.parseInt(m.group(1));
                    minMinorVersion = Integer.parseInt(m.group(2));
                    minMicroVersion = Integer.parseInt(m.group(3));
                    break;
                }
            }
        } catch (FileNotFoundException e) {
            // the build id will be null, and this is handled by the builders.
        } catch (IOException e) {
            // the build id will be null, and this is handled by the builders.
        }

        // Failed to get the min plugin version number?
        if (minMajorVersion == -1 || minMinorVersion == -1 || minMicroVersion ==-1) {
            return errorHandler.handleWarning(Messages.VersionCheck_Plugin_Version_Failed);
        }

        // test the plugin number
        String versionString = (String) plugin.getBundle().getHeaders().get(
                Constants.BUNDLE_VERSION);
        Version version = new Version(versionString);

        boolean valid = true;
        if (version.getMajor() < minMajorVersion) {
            valid = false;
        } else if (version.getMajor() == minMajorVersion) {
            if (version.getMinor() < minMinorVersion) {
                valid = false;
            } else if (version.getMinor() == minMinorVersion) {
                if (version.getMicro() < minMicroVersion) {
                    valid = false;
                }
            }
        }

        if (valid == false) {
            return errorHandler.handleWarning(
                    String.format(Messages.VersionCheck_Plugin_Too_Old,
                            minMajorVersion, minMinorVersion, minMicroVersion, versionString));
        }

        return true; // no error!