Java Code Examples for com.android.io.IAbstractFile#exists()

The following examples show how to use com.android.io.IAbstractFile#exists() . These examples are extracted from open source projects. 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
/**
 * Merges all properties from the given file into the current properties.
 * <p/>
 * This emulates the Ant behavior: existing properties are <em>not</em> overridden.
 * Only new undefined properties become defined.
 * <p/>
 * Typical usage:
 * <ul>
 * <li>Create a ProjectProperties with {@code PropertyType#ANT}
 * <li>Merge in values using {@code PropertyType#PROJECT}
 * <li>The result is that this contains all the properties from default plus those
 *     overridden by the build.properties file.
 * </ul>
 *
 * @param type One the possible {@link ProjectProperties.PropertyType}s.
 * @return this object, for chaining.
 */
public synchronized ProjectPropertiesWorkingCopy merge(PropertyType type) {
    if (mProjectFolder.exists() && mType != type) {
        IAbstractFile propFile = mProjectFolder.getFile(type.getFilename());
        if (propFile.exists()) {
            Map<String, String> map = parsePropertyFile(propFile, null /* log */);
            if (map != null) {
                for (Entry<String, String> entry : map.entrySet()) {
                    String key = entry.getKey();
                    String value = entry.getValue();
                    if (!mProperties.containsKey(key) && value != null) {
                        mProperties.put(key, value);
                    }
                }
            }
        }
    }
    return this;
}
 
Example 2
/**
 * Merges all properties from the given file into the current properties.
 * <p/>
 * This emulates the Ant behavior: existing properties are <em>not</em> overridden.
 * Only new undefined properties become defined.
 * <p/>
 * Typical usage:
 * <ul>
 * <li>Create a ProjectProperties with {@code PropertyType#ANT}
 * <li>Merge in values using {@code PropertyType#PROJECT}
 * <li>The result is that this contains all the properties from default plus those
 *     overridden by the build.properties file.
 * </ul>
 *
 * @param type One the possible {@link ProjectProperties.PropertyType}s.
 * @return this object, for chaining.
 */
public synchronized ProjectPropertiesWorkingCopy merge(PropertyType type) {
    if (mProjectFolder.exists() && mType != type) {
        IAbstractFile propFile = mProjectFolder.getFile(type.getFilename());
        if (propFile.exists()) {
            Map<String, String> map = parsePropertyFile(propFile, null /* log */);
            if (map != null) {
                for (Entry<String, String> entry : map.entrySet()) {
                    String key = entry.getKey();
                    String value = entry.getValue();
                    if (!mProperties.containsKey(key) && value != null) {
                        mProperties.put(key, value);
                    }
                }
            }
        }
    }
    return this;
}
 
Example 3
/**
 * Loads a project properties file and return a {@link ProjectProperties} object
 * containing the properties.
 *
 * @param projectFolder the project folder.
 * @param type One the possible {@link PropertyType}s.
 */
public static ProjectProperties load(IAbstractFolder projectFolder, PropertyType type) {
    if (projectFolder.exists()) {
        IAbstractFile propFile = projectFolder.getFile(type.mFilename);
        if (propFile.exists()) {
            Map<String, String> map = parsePropertyFile(propFile, null /* log */);
            if (map != null) {
                return new ProjectProperties(projectFolder, map, type);
            }
        }
    }
    return null;
}
 
Example 4
/**
 * Deletes a project properties file.
 *
 * @param projectFolder the project folder.
 * @param type One the possible {@link PropertyType}s.
 * @return true if success.
 */
public static boolean delete(IAbstractFolder projectFolder, PropertyType type) {
    if (projectFolder.exists()) {
        IAbstractFile propFile = projectFolder.getFile(type.mFilename);
        if (propFile.exists()) {
            return propFile.delete();
        }
    }

    return false;
}
 
Example 5
/**
 * Reloads the properties from the underlying file.
 */
public synchronized void reload() {
    if (mProjectFolder.exists()) {
        IAbstractFile propFile = mProjectFolder.getFile(mType.mFilename);
        if (propFile.exists()) {
            Map<String, String> map = parsePropertyFile(propFile, null /* log */);
            if (map != null) {
                mProperties.clear();
                mProperties.putAll(map);
            }
        }
    }
}
 
Example 6
/**
 * Returns an {@link IAbstractFile} object representing the manifest for the given project.
 *
 * @param projectFolder The project containing the manifest file.
 * @return An IAbstractFile object pointing to the manifest or null if the manifest
 *         is missing.
 */
public static IAbstractFile getManifest(IAbstractFolder projectFolder) {
    IAbstractFile file = projectFolder.getFile(SdkConstants.FN_ANDROID_MANIFEST_XML);
    if (file != null && file.exists()) {
        return file;
    }

    return null;
}
 
Example 7
/**
 * Loads a project properties file and return a {@link ProjectProperties} object
 * containing the properties.
 *
 * @param projectFolder the project folder.
 * @param type One the possible {@link PropertyType}s.
 */
public static ProjectProperties load(IAbstractFolder projectFolder, PropertyType type) {
    if (projectFolder.exists()) {
        IAbstractFile propFile = projectFolder.getFile(type.mFilename);
        if (propFile.exists()) {
            Map<String, String> map = parsePropertyFile(propFile, null /* log */);
            if (map != null) {
                return new ProjectProperties(projectFolder, map, type);
            }
        }
    }
    return null;
}
 
Example 8
/**
 * Deletes a project properties file.
 *
 * @param projectFolder the project folder.
 * @param type One the possible {@link PropertyType}s.
 * @return true if success.
 */
public static boolean delete(IAbstractFolder projectFolder, PropertyType type) {
    if (projectFolder.exists()) {
        IAbstractFile propFile = projectFolder.getFile(type.mFilename);
        if (propFile.exists()) {
            return propFile.delete();
        }
    }

    return false;
}
 
Example 9
/**
 * Reloads the properties from the underlying file.
 */
public synchronized void reload() {
    if (mProjectFolder.exists()) {
        IAbstractFile propFile = mProjectFolder.getFile(mType.mFilename);
        if (propFile.exists()) {
            Map<String, String> map = parsePropertyFile(propFile, null /* log */);
            if (map != null) {
                mProperties.clear();
                mProperties.putAll(map);
            }
        }
    }
}
 
Example 10
/**
 * Returns an {@link IAbstractFile} object representing the manifest for the given project.
 *
 * @param projectFolder The project containing the manifest file.
 * @return An IAbstractFile object pointing to the manifest or null if the manifest
 *         is missing.
 */
public static IAbstractFile getManifest(IAbstractFolder projectFolder) {
    IAbstractFile file = projectFolder.getFile(SdkConstants.FN_ANDROID_MANIFEST_XML);
    if (file != null && file.exists()) {
        return file;
    }

    return null;
}