plugins/org.symbian.tools.tmw.core/src/org/symbian/tools/tmw/core/utilities/CoreUtil.java
author Eugene Ostroukhov <eugeneo@symbian.org>
Wed, 01 Sep 2010 16:27:43 -0700
changeset 481 e908ec135fa1
parent 477 b616697678bf
child 484 f5df819c1852
permissions -rw-r--r--
Application import wizard was refactored into extensible code
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
468
a05c6e5cc7d9 Previewer now is TMWed (can support projects with different natures). Note: this commit does not compile. This previewer still only supports WRT libraries
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
     1
/**
a05c6e5cc7d9 Previewer now is TMWed (can support projects with different natures). Note: this commit does not compile. This previewer still only supports WRT libraries
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
     2
 * Copyright (c) 2010 Symbian Foundation and/or its subsidiary(-ies).
a05c6e5cc7d9 Previewer now is TMWed (can support projects with different natures). Note: this commit does not compile. This previewer still only supports WRT libraries
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
     3
 * All rights reserved.
a05c6e5cc7d9 Previewer now is TMWed (can support projects with different natures). Note: this commit does not compile. This previewer still only supports WRT libraries
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
     4
 * This component and the accompanying materials are made available
a05c6e5cc7d9 Previewer now is TMWed (can support projects with different natures). Note: this commit does not compile. This previewer still only supports WRT libraries
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
     5
 * under the terms of the License "Eclipse Public License v1.0"
a05c6e5cc7d9 Previewer now is TMWed (can support projects with different natures). Note: this commit does not compile. This previewer still only supports WRT libraries
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
     6
 * which accompanies this distribution, and is available
a05c6e5cc7d9 Previewer now is TMWed (can support projects with different natures). Note: this commit does not compile. This previewer still only supports WRT libraries
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
     7
 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
a05c6e5cc7d9 Previewer now is TMWed (can support projects with different natures). Note: this commit does not compile. This previewer still only supports WRT libraries
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
     8
 *
a05c6e5cc7d9 Previewer now is TMWed (can support projects with different natures). Note: this commit does not compile. This previewer still only supports WRT libraries
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
     9
 * Initial Contributors:
a05c6e5cc7d9 Previewer now is TMWed (can support projects with different natures). Note: this commit does not compile. This previewer still only supports WRT libraries
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    10
 * Symbian Foundation - initial contribution.
a05c6e5cc7d9 Previewer now is TMWed (can support projects with different natures). Note: this commit does not compile. This previewer still only supports WRT libraries
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    11
 * Contributors:
a05c6e5cc7d9 Previewer now is TMWed (can support projects with different natures). Note: this commit does not compile. This previewer still only supports WRT libraries
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    12
 * Description:
a05c6e5cc7d9 Previewer now is TMWed (can support projects with different natures). Note: this commit does not compile. This previewer still only supports WRT libraries
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    13
 * Overview:
a05c6e5cc7d9 Previewer now is TMWed (can support projects with different natures). Note: this commit does not compile. This previewer still only supports WRT libraries
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    14
 * Details:
a05c6e5cc7d9 Previewer now is TMWed (can support projects with different natures). Note: this commit does not compile. This previewer still only supports WRT libraries
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    15
 * Platforms/Drives/Compatibility:
a05c6e5cc7d9 Previewer now is TMWed (can support projects with different natures). Note: this commit does not compile. This previewer still only supports WRT libraries
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    16
 * Assumptions/Requirement/Pre-requisites:
a05c6e5cc7d9 Previewer now is TMWed (can support projects with different natures). Note: this commit does not compile. This previewer still only supports WRT libraries
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    17
 * Failures and causes:
a05c6e5cc7d9 Previewer now is TMWed (can support projects with different natures). Note: this commit does not compile. This previewer still only supports WRT libraries
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    18
 */
a05c6e5cc7d9 Previewer now is TMWed (can support projects with different natures). Note: this commit does not compile. This previewer still only supports WRT libraries
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    19
package org.symbian.tools.tmw.core.utilities;
a05c6e5cc7d9 Previewer now is TMWed (can support projects with different natures). Note: this commit does not compile. This previewer still only supports WRT libraries
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    20
481
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 477
diff changeset
    21
import org.eclipse.core.resources.IProject;
468
a05c6e5cc7d9 Previewer now is TMWed (can support projects with different natures). Note: this commit does not compile. This previewer still only supports WRT libraries
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    22
import org.eclipse.core.runtime.Platform;
481
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 477
diff changeset
    23
import org.eclipse.wst.jsdt.core.IJavaScriptProject;
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 477
diff changeset
    24
import org.eclipse.wst.jsdt.core.IType;
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 477
diff changeset
    25
import org.eclipse.wst.jsdt.core.JavaScriptCore;
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 477
diff changeset
    26
import org.eclipse.wst.jsdt.core.JavaScriptModelException;
468
a05c6e5cc7d9 Previewer now is TMWed (can support projects with different natures). Note: this commit does not compile. This previewer still only supports WRT libraries
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    27
a05c6e5cc7d9 Previewer now is TMWed (can support projects with different natures). Note: this commit does not compile. This previewer still only supports WRT libraries
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    28
/**
a05c6e5cc7d9 Previewer now is TMWed (can support projects with different natures). Note: this commit does not compile. This previewer still only supports WRT libraries
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    29
 * Utilities used all over the TMW code base. Users can rely on this methods 
a05c6e5cc7d9 Previewer now is TMWed (can support projects with different natures). Note: this commit does not compile. This previewer still only supports WRT libraries
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    30
 * even though they are not specific to mobile development.
a05c6e5cc7d9 Previewer now is TMWed (can support projects with different natures). Note: this commit does not compile. This previewer still only supports WRT libraries
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    31
 * 
a05c6e5cc7d9 Previewer now is TMWed (can support projects with different natures). Note: this commit does not compile. This previewer still only supports WRT libraries
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    32
 * @author Eugene Ostroukhov (eugeneo@symbian.org)
a05c6e5cc7d9 Previewer now is TMWed (can support projects with different natures). Note: this commit does not compile. This previewer still only supports WRT libraries
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    33
 */
a05c6e5cc7d9 Previewer now is TMWed (can support projects with different natures). Note: this commit does not compile. This previewer still only supports WRT libraries
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    34
public final class CoreUtil {
a05c6e5cc7d9 Previewer now is TMWed (can support projects with different natures). Note: this commit does not compile. This previewer still only supports WRT libraries
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    35
a05c6e5cc7d9 Previewer now is TMWed (can support projects with different natures). Note: this commit does not compile. This previewer still only supports WRT libraries
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    36
    private CoreUtil() {
a05c6e5cc7d9 Previewer now is TMWed (can support projects with different natures). Note: this commit does not compile. This previewer still only supports WRT libraries
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    37
        // Class with only static methods
a05c6e5cc7d9 Previewer now is TMWed (can support projects with different natures). Note: this commit does not compile. This previewer still only supports WRT libraries
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    38
    }
a05c6e5cc7d9 Previewer now is TMWed (can support projects with different natures). Note: this commit does not compile. This previewer still only supports WRT libraries
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    39
a05c6e5cc7d9 Previewer now is TMWed (can support projects with different natures). Note: this commit does not compile. This previewer still only supports WRT libraries
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    40
    public static boolean isMac() {
a05c6e5cc7d9 Previewer now is TMWed (can support projects with different natures). Note: this commit does not compile. This previewer still only supports WRT libraries
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    41
        return "macosx".equals(Platform.getOS());
a05c6e5cc7d9 Previewer now is TMWed (can support projects with different natures). Note: this commit does not compile. This previewer still only supports WRT libraries
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    42
    }
472
bd9f2d7c64a6 Debugger is now Symbian-independant
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 470
diff changeset
    43
bd9f2d7c64a6 Debugger is now Symbian-independant
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 470
diff changeset
    44
    public static boolean isLinux() {
bd9f2d7c64a6 Debugger is now Symbian-independant
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 470
diff changeset
    45
        return "linux".equals(Platform.getOS());
bd9f2d7c64a6 Debugger is now Symbian-independant
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 470
diff changeset
    46
    }
477
b616697678bf Providers can now specify fixed facets on per-runtime basis. Those facets will not be shown to users in the project creation wizard
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 472
diff changeset
    47
b616697678bf Providers can now specify fixed facets on per-runtime basis. Those facets will not be shown to users in the project creation wizard
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 472
diff changeset
    48
    public static String notNull(final String string) {
b616697678bf Providers can now specify fixed facets on per-runtime basis. Those facets will not be shown to users in the project creation wizard
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 472
diff changeset
    49
        return string == null ? "" : string.trim();
b616697678bf Providers can now specify fixed facets on per-runtime basis. Those facets will not be shown to users in the project creation wizard
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 472
diff changeset
    50
    }
481
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 477
diff changeset
    51
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 477
diff changeset
    52
    public final static boolean hasTypes(IProject p, String... typeNames) throws JavaScriptModelException {
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 477
diff changeset
    53
        final IJavaScriptProject project = JavaScriptCore.create(p);
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 477
diff changeset
    54
        if (project != null && project.exists()) {
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 477
diff changeset
    55
            for (String typeName : typeNames) {
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 477
diff changeset
    56
                if (!hasType(project, typeName)) {
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 477
diff changeset
    57
                    return false;
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 477
diff changeset
    58
                }
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 477
diff changeset
    59
            }
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 477
diff changeset
    60
        }
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 477
diff changeset
    61
        return true;
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 477
diff changeset
    62
    }
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 477
diff changeset
    63
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 477
diff changeset
    64
    // See https://bugs.eclipse.org/bugs/show_bug.cgi?id=318656
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 477
diff changeset
    65
    private static boolean hasType(IJavaScriptProject project, String name) throws JavaScriptModelException {
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 477
diff changeset
    66
        final IType[] types = project.findTypes(name);
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 477
diff changeset
    67
        if (types != null) {
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 477
diff changeset
    68
            for (IType type : types) {
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 477
diff changeset
    69
                if (type.getJavaScriptProject().equals(project)) {
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 477
diff changeset
    70
                    return true;
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 477
diff changeset
    71
                }
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 477
diff changeset
    72
            }
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 477
diff changeset
    73
        }
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 477
diff changeset
    74
        return false;
e908ec135fa1 Application import wizard was refactored into extensible code
Eugene Ostroukhov <eugeneo@symbian.org>
parents: 477
diff changeset
    75
    }
468
a05c6e5cc7d9 Previewer now is TMWed (can support projects with different natures). Note: this commit does not compile. This previewer still only supports WRT libraries
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff changeset
    76
}