Java Code Examples for com.android.SdkConstants#FD_ADDONS

The following examples show how to use com.android.SdkConstants#FD_ADDONS . 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: 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 2
Source File: LocalSdkParser.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
/**
 * The sdk manager only lists valid addons. However here we also want to find "broken"
 * addons, i.e. addons that failed to load for some reason.
 * <p/>
 * Find any other sub-directories under the /add-ons root that hasn't been visited yet
 * and assume they contain broken addons.
 */
private void scanMissingAddons(SdkManager sdkManager,
        HashSet<File> visited,
        ArrayList<Package> packages,
        ILogger log) {
    File addons = new File(new File(sdkManager.getLocation()), SdkConstants.FD_ADDONS);

    for (File dir : listFilesNonNull(addons)) {
        if (dir.isDirectory() && !visited.contains(dir)) {
            Pair<Map<String, String>, String> infos =
                parseAddonProperties(dir, sdkManager.getTargets(), log);
            Properties sourceProps =
                parseProperties(new File(dir, SdkConstants.FN_SOURCE_PROP));

            Map<String, String> addonProps = infos.getFirst();
            String error = infos.getSecond();
            try {
                Package pkg = AddonPackage.createBroken(dir.getAbsolutePath(),
                                                        sourceProps,
                                                        addonProps,
                                                        error);
                packages.add(pkg);
                visited.add(dir);
            } catch (Exception e) {
                log.error(e, null);
            }
        }
    }
}
 
Example 3
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 4
Source File: LocalSdkParser.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
/**
 * The sdk manager only lists valid addons. However here we also want to find "broken"
 * addons, i.e. addons that failed to load for some reason.
 * <p/>
 * Find any other sub-directories under the /add-ons root that hasn't been visited yet
 * and assume they contain broken addons.
 */
private void scanMissingAddons(SdkManager sdkManager,
        HashSet<File> visited,
        ArrayList<Package> packages,
        ILogger log) {
    File addons = new File(new File(sdkManager.getLocation()), SdkConstants.FD_ADDONS);

    for (File dir : listFilesNonNull(addons)) {
        if (dir.isDirectory() && !visited.contains(dir)) {
            Pair<Map<String, String>, String> infos =
                parseAddonProperties(dir, sdkManager.getTargets(), log);
            Properties sourceProps =
                parseProperties(new File(dir, SdkConstants.FN_SOURCE_PROP));

            Map<String, String> addonProps = infos.getFirst();
            String error = infos.getSecond();
            try {
                Package pkg = AddonPackage.createBroken(dir.getAbsolutePath(),
                                                        sourceProps,
                                                        addonProps,
                                                        error);
                packages.add(pkg);
                visited.add(dir);
            } catch (Exception e) {
                log.error(e, null);
            }
        }
    }
}