Example usage for com.google.gwt.eclipse.core.sdk GWTSdkRegistrant registerSdk

List of usage examples for com.google.gwt.eclipse.core.sdk GWTSdkRegistrant registerSdk

Introduction

In this page you can find the example usage for com.google.gwt.eclipse.core.sdk GWTSdkRegistrant registerSdk.

Prototype

public static void registerSdk(URL sdkUrl) throws CoreException 

Source Link

Document

Registers a GWT SDK for use by GPE.

Usage

From source file:com.google.gdt.eclipse.suite.preferences.GdtPreferences.java

License:Open Source License

/**
 * Attempts to register the SDK from a bundle.
 *//*  ww w .  j a va 2s .c om*/
private static void registerBundleSdk(Bundle bundle) throws CoreException {
    try {
        IPath propPath = new Path(SDK_REGISTRANT_PROPERTY_FILE);
        URL propUrl = FileLocator.find(bundle, propPath, (Map<?, ?>) null);
        if (propUrl != null) {
            InputStream instream = propUrl.openStream();
            Properties props = new Properties();
            props.load(instream);
            String sdkType = props.getProperty(SDK_BUNDLE_MARKER_PROPERTY);
            String sdkPrefix = props.getProperty(SDK_PATH_PREFIX_PROPERTY);
            if (sdkType != null && sdkPrefix != null) {
                IPath sdkPrefixPath = new Path(sdkPrefix);
                URL sdkPathUrl = FileLocator.find(bundle, sdkPrefixPath, (Map<?, ?>) null);
                if (sdkPathUrl == null) {
                    // Automatic SDK registration failed. This is expected in dev mode.
                    CorePluginLog.logWarning("Failed to register SDK: " + sdkPrefix);
                    return;
                }
                // resolve needed to switch from bundleentry to file url
                sdkPathUrl = FileLocator.resolve(sdkPathUrl);
                if (sdkPathUrl != null) {
                    if ("file".equals(sdkPathUrl.getProtocol())) {
                        if ("GAE".equals(sdkType)) {
                            GAESdkRegistrant.registerSdk(sdkPathUrl);
                        } else if ("GWT".equals(sdkType)) {
                            GWTSdkRegistrant.registerSdk(sdkPathUrl);
                        }
                    }
                }
            }
        }
    } catch (IOException e) {
        throw new CoreException(new Status(IStatus.WARNING, GdtPlugin.PLUGIN_ID, e.getLocalizedMessage(), e));
    }
}