Java Code Examples for com.android.sdklib.IAndroidTarget#isPlatform()

The following examples show how to use com.android.sdklib.IAndroidTarget#isPlatform() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PlatformTarget.java    From java-n-IDE-for-Android with Apache License 2.0 6 votes vote down vote up
@Override
public int compareTo(IAndroidTarget target) {
    // quick check.
    if (this == target) {
        return 0;
    }

    int versionDiff = mVersion.compareTo(target.getVersion());

    // only if the version are the same do we care about add-ons.
    if (versionDiff == 0) {
        // platforms go before add-ons.
        if (target.isPlatform() == false) {
            return -1;
        }
    }

    return versionDiff;
}
 
Example 2
Source File: PlatformPackage.java    From java-n-IDE-for-Android with Apache License 2.0 6 votes vote down vote up
/**
 * Computes a potential installation folder if an archive of this package were
 * to be installed right away in the given SDK root.
 * <p/>
 * A platform package is typically installed in SDK/platforms/android-"version".
 * However if we can find a different directory under SDK/platform that already
 * has this platform version installed, we'll use that one.
 *
 * @param osSdkRoot The OS path of the SDK root folder.
 * @param sdkManager An existing SDK manager to list current platforms and addons.
 * @return A new {@link File} corresponding to the directory to use to install this package.
 */
@Override
public File getInstallFolder(String osSdkRoot, SdkManager sdkManager) {

    // First find if this platform is already installed. If so, reuse the same directory.
    for (IAndroidTarget target : sdkManager.getTargets()) {
        if (target.isPlatform() && target.getVersion().equals(mVersion)) {
            return new File(target.getLocation());
        }
    }

    File platforms = new File(osSdkRoot, SdkConstants.FD_PLATFORMS);
    File folder = new File(platforms,
            String.format("android-%s", getAndroidVersion().getApiString())); //$NON-NLS-1$

    return folder;
}
 
Example 3
Source File: PlatformTarget.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
@Override
public int compareTo(IAndroidTarget target) {
    // quick check.
    if (this == target) {
        return 0;
    }

    int versionDiff = mVersion.compareTo(target.getVersion());

    // only if the version are the same do we care about add-ons.
    if (versionDiff == 0) {
        // platforms go before add-ons.
        if (target.isPlatform() == false) {
            return -1;
        }
    }

    return versionDiff;
}
 
Example 4
Source File: PlatformPackage.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Computes a potential installation folder if an archive of this package were
 * to be installed right away in the given SDK root.
 * <p/>
 * A platform package is typically installed in SDK/platforms/android-"version".
 * However if we can find a different directory under SDK/platform that already
 * has this platform version installed, we'll use that one.
 *
 * @param osSdkRoot The OS path of the SDK root folder.
 * @param sdkManager An existing SDK manager to list current platforms and addons.
 * @return A new {@link File} corresponding to the directory to use to install this package.
 */
@Override
public File getInstallFolder(String osSdkRoot, SdkManager sdkManager) {

    // First find if this platform is already installed. If so, reuse the same directory.
    for (IAndroidTarget target : sdkManager.getTargets()) {
        if (target.isPlatform() && target.getVersion().equals(mVersion)) {
            return new File(target.getLocation());
        }
    }

    File platforms = new File(osSdkRoot, SdkConstants.FD_PLATFORMS);
    File folder = new File(platforms,
            String.format("android-%s", getAndroidVersion().getApiString())); //$NON-NLS-1$

    return folder;
}
 
Example 5
Source File: LintDetectorTest.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
@Nullable
@Override
public IAndroidTarget getCompileTarget(@NonNull Project project) {
    IAndroidTarget compileTarget = super.getCompileTarget(project);
    if (compileTarget == null) {
        IAndroidTarget[] targets = getTargets();
        for (int i = targets.length - 1; i >= 0; i--) {
            IAndroidTarget target = targets[i];
            if (target.isPlatform()) {
                return target;
            }
        }
    }

    return compileTarget;
}
 
Example 6
Source File: AddOnTarget.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
@Override
public int compareTo(IAndroidTarget target) {
    // quick check.
    if (this == target) {
        return 0;
    }

    int versionDiff = getVersion().compareTo(target.getVersion());

    // only if the version are the same do we care about platform/add-ons.
    if (versionDiff == 0) {
        // platforms go before add-ons.
        if (target.isPlatform()) {
            return +1;
        } else {
            AddOnTarget targetAddOn = (AddOnTarget)target;

            // both are add-ons of the same version. Compare per vendor then by name
            int vendorDiff = mVendor.compareTo(targetAddOn.mVendor);
            if (vendorDiff == 0) {
                return mName.compareTo(targetAddOn.mName);
            } else {
                return vendorDiff;
            }
        }

    }

    return versionDiff;
}
 
Example 7
Source File: AddonPackage.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
/**
 * Computes a potential installation folder if an archive of this package were
 * to be installed right away in the given SDK root.
 * <p/>
 * An add-on package is typically installed in SDK/add-ons/"addon-name"-"api-level".
 * The name needs to be sanitized to be acceptable as a directory name.
 * However if we can find a different directory under SDK/add-ons that already
 * has this add-ons installed, we'll use that one.
 *
 * @param osSdkRoot The OS path of the SDK root folder.
 * @param sdkManager An existing SDK manager to list current platforms and addons.
 * @return A new {@link File} corresponding to the directory to use to install this package.
 */
@Override
public File getInstallFolder(String osSdkRoot, SdkManager sdkManager) {
    File addons = new File(osSdkRoot, SdkConstants.FD_ADDONS);

    // First find if this add-on is already installed. If so, reuse the same directory.
    for (IAndroidTarget target : sdkManager.getTargets()) {
        if (!target.isPlatform() && target.getVersion().equals(mVersion)) {
            // Starting with addon-4.xsd, the addon source.properties differentiate
            // between ids and display strings. However the addon target which relies
            // on the manifest.ini does not so we need to cover both cases.
            // TODO fix when we get rid of manifest.ini for addons
            if ((target.getName().equals(getNameId()) &&
                 target.getVendor().equals(getVendorId())) ||
                (target.getName().equals(getDisplayName()) &&
                 target.getVendor().equals(getDisplayVendor()))) {
                return new File(target.getLocation());
            }
        }
    }

    // Compute a folder directory using the addon declared name and vendor strings.
    String name = encodeAddonName();

    for (int i = 0; i < 100; i++) {
        String name2 = i == 0 ? name : String.format("%s-%d", name, i); //$NON-NLS-1$
        File folder = new File(addons, name2);
        if (!folder.exists()) {
            return folder;
        }
    }

    // We shouldn't really get here. I mean, seriously, we tried hard enough.
    return null;
}
 
Example 8
Source File: LintClient.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Returns the compile target to use for the given project
 *
 * @param project the project in question
 *
 * @return the compile target to use to build the given project
 */
@Nullable
public IAndroidTarget getCompileTarget(@NonNull Project project) {
    int buildSdk = project.getBuildSdk();
    IAndroidTarget[] targets = getTargets();
    for (int i = targets.length - 1; i >= 0; i--) {
        IAndroidTarget target = targets[i];
        if (target.isPlatform() && target.getVersion().getApiLevel() == buildSdk) {
            return target;
        }
    }

    return null;
}
 
Example 9
Source File: LintClient.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Returns the highest known API level.
 *
 * @return the highest known API level
 */
public int getHighestKnownApiLevel() {
    int max = SdkVersionInfo.HIGHEST_KNOWN_STABLE_API;

    for (IAndroidTarget target : getTargets()) {
        if (target.isPlatform()) {
            int api = target.getVersion().getApiLevel();
            if (api > max && !target.getVersion().isPreview()) {
                max = api;
            }
        }
    }

    return max;
}
 
Example 10
Source File: AddOnTarget.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
@Override
public int compareTo(@NonNull IAndroidTarget target) {
    // quick check.
    if (this == target) {
        return 0;
    }

    int versionDiff = getVersion().compareTo(target.getVersion());

    // only if the version are the same do we care about platform/add-ons.
    if (versionDiff == 0) {
        // platforms go before add-ons.
        if (target.isPlatform()) {
            return +1;
        } else {
            AddOnTarget targetAddOn = (AddOnTarget)target;

            // both are add-ons of the same version. Compare per vendor then by name
            int vendorDiff = mVendor.compareTo(targetAddOn.mVendor);
            if (vendorDiff == 0) {
                return mName.compareTo(targetAddOn.mName);
            } else {
                return vendorDiff;
            }
        }

    }

    return versionDiff;
}
 
Example 11
Source File: AddonPackage.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Computes a potential installation folder if an archive of this package were
 * to be installed right away in the given SDK root.
 * <p/>
 * An add-on package is typically installed in SDK/add-ons/"addon-name"-"api-level".
 * The name needs to be sanitized to be acceptable as a directory name.
 * However if we can find a different directory under SDK/add-ons that already
 * has this add-ons installed, we'll use that one.
 *
 * @param osSdkRoot The OS path of the SDK root folder.
 * @param sdkManager An existing SDK manager to list current platforms and addons.
 * @return A new {@link File} corresponding to the directory to use to install this package.
 */
@Override
public File getInstallFolder(String osSdkRoot, SdkManager sdkManager) {
    File addons = new File(osSdkRoot, SdkConstants.FD_ADDONS);

    // First find if this add-on is already installed. If so, reuse the same directory.
    for (IAndroidTarget target : sdkManager.getTargets()) {
        if (!target.isPlatform() && target.getVersion().equals(mVersion)) {
            // Starting with addon-4.xsd, the addon source.properties differentiate
            // between ids and display strings. However the addon target which relies
            // on the manifest.ini does not so we need to cover both cases.
            // TODO fix when we get rid of manifest.ini for addons
            if ((target.getName().equals(getNameId()) &&
                 target.getVendor().equals(getVendorId())) ||
                (target.getName().equals(getDisplayName()) &&
                 target.getVendor().equals(getDisplayVendor()))) {
                return new File(target.getLocation());
            }
        }
    }

    // Compute a folder directory using the addon declared name and vendor strings.
    String name = encodeAddonName();

    for (int i = 0; i < 100; i++) {
        String name2 = i == 0 ? name : String.format("%s-%d", name, i); //$NON-NLS-1$
        File folder = new File(addons, name2);
        if (!folder.exists()) {
            return folder;
        }
    }

    // We shouldn't really get here. I mean, seriously, we tried hard enough.
    return null;
}
 
Example 12
Source File: AndroidPlatformInfo.java    From NBANDROID-V2 with Apache License 2.0 5 votes vote down vote up
public FileObject getSDKFolderFo() {
    IAndroidTarget platformTarget = target;
    while (platformTarget != null && !platformTarget.isPlatform()) {
        platformTarget = platformTarget.getParent();
    }
    FileObject platformDir = platformTarget == null
            ? null
            : FileUtil.toFileObject(FileUtil.normalizeFile(new File(platformTarget.getLocation())));
    return platformDir;
}