Java Code Examples for com.android.utils.ILogger#error()

The following examples show how to use com.android.utils.ILogger#error() . 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: SdkManager.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Creates an {@link SdkManager} for a given sdk location.
 *
 * @param osSdkPath the location of the SDK.
 * @param log       the ILogger object receiving warning/error from the parsing.
 * @return the created {@link SdkManager} or null if the location is not valid.
 */
@Nullable
public static SdkManager createManager(
        @NonNull String osSdkPath,
        @NonNull ILogger log) {
    try {
        SdkManager manager = new SdkManager(osSdkPath);
        manager.reloadSdk(log);

        return manager;
    } catch (Throwable throwable) {
        log.error(throwable, "Error parsing the sdk.");
    }

    return null;
}
 
Example 2
Source File: MergingReport.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
/**
 * dumps all logging records to a logger.
 */
public void log(ILogger logger) {
    for (Record record : mRecords) {
        switch(record.mSeverity) {
            case WARNING:
                logger.warning(record.toString());
                break;
            case ERROR:
                logger.error(null /* throwable */, record.toString());
                break;
            case INFO:
                logger.verbose(record.toString());
                break;
            default:
                logger.error(null /* throwable */, "Unhandled record type " + record.mSeverity);
        }
    }
    mActions.log(logger);

    if (!mResult.isSuccess()) {
        logger.warning("\nSee http://g.co/androidstudio/manifest-merger for more information"
                + " about the manifest merger.\n");
    }
}
 
Example 3
Source File: MergingReport.java    From java-n-IDE-for-Android with Apache License 2.0 6 votes vote down vote up
/**
 * dumps all logging records to a logger.
 */
public void log(ILogger logger) {
    for (Record record : mRecords) {
        switch(record.mSeverity) {
            case WARNING:
                logger.warning(record.toString());
                break;
            case ERROR:
                logger.error(null /* throwable */, record.toString());
                break;
            case INFO:
                logger.verbose(record.toString());
                break;
            default:
                logger.error(null /* throwable */, "Unhandled record type " + record.mSeverity);
        }
    }
    mActions.log(logger);
}
 
Example 4
Source File: AvdManager.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
/**
 * Updates an AVD with new path to the system image folders.
 * @param avd the AVD to update.
 * @param log the log object to receive action logs. Cannot be null.
 * @throws IOException
 */
public AvdInfo updateAvd(AvdInfo avd, ILogger log) throws IOException {
    // get the properties. This is a unmodifiable Map.
    Map<String, String> oldProperties = avd.getProperties();

    // create a new map
    Map<String, String> properties = new HashMap<String, String>();
    if (oldProperties != null) {
        properties.putAll(oldProperties);
    }

    AvdStatus status;

    // create the path to the new system images.
    if (setImagePathProperties(avd.getTarget(),
                               avd.getTag(),
                               avd.getAbiType(),
                               properties,
                               log)) {
        if (properties.containsKey(AVD_INI_IMAGES_1)) {
            log.info("Updated '%1$s' with value '%2$s'\n", AVD_INI_IMAGES_1,
                    properties.get(AVD_INI_IMAGES_1));
        }

        if (properties.containsKey(AVD_INI_IMAGES_2)) {
            log.info("Updated '%1$s' with value '%2$s'\n", AVD_INI_IMAGES_2,
                    properties.get(AVD_INI_IMAGES_2));
        }

        status = AvdStatus.OK;
    } else {
        log.error(null, "Unable to find non empty system images folders for %1$s",
                avd.getName());
        //FIXME: display paths to empty image folders?
        status = AvdStatus.ERROR_IMAGE_DIR;
    }

    return updateAvd(avd, properties, status, log);
}
 
Example 5
Source File: ResourceSet.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
private static ResourceFile createResourceFile(File file, FolderData folderData, ILogger logger)
        throws MergingException {
    if (folderData.type != null) {
        int pos;// get the resource name based on the filename
        String name = file.getName();
        pos = name.indexOf('.');
        if (pos >= 0) {
            name = name.substring(0, pos);
        }

        return new ResourceFile(
                file,
                new ResourceItem(name, folderData.type, null),
                folderData.qualifiers);
    } else {
        try {
            ValueResourceParser2 parser = new ValueResourceParser2(file);
            List<ResourceItem> items = parser.parseFile();

            return new ResourceFile(file, items, folderData.qualifiers);
        } catch (MergingException e) {
            e.setFile(file);
            logger.error(e, "Failed to parse %s", file.getAbsolutePath());
            throw e;
        }
    }
}
 
Example 6
Source File: AvdManager.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
/**
 * Sets the paths to the system images in a properties map.
 *
 * @param target the target in which to find the system images.
 * @param abiType the abi type of the avd to find
 *        the architecture-dependent system images.
 * @param properties the properties in which to set the paths.
 * @param log the log object to receive action logs. Cannot be null.
 * @return true if success, false if some path are missing.
 */
private boolean setImagePathProperties(IAndroidTarget target,
        IdDisplay tag,
        String abiType,
        Map<String, String> properties,
        ILogger log) {
    properties.remove(AVD_INI_IMAGES_1);
    properties.remove(AVD_INI_IMAGES_2);

    try {
        String property = AVD_INI_IMAGES_1;

        // First the image folders of the target itself
        String imagePath = getImageRelativePath(target, tag, abiType);
        if (imagePath != null) {
            properties.put(property, imagePath);
            property = AVD_INI_IMAGES_2;
        }

        // If the target is an add-on we need to add the Platform image as a backup.
        IAndroidTarget parent = target.getParent();
        if (parent != null) {
            imagePath = getImageRelativePath(parent, tag, abiType);
            if (imagePath != null) {
                properties.put(property, imagePath);
            }
        }

        // we need at least one path!
        return properties.containsKey(AVD_INI_IMAGES_1);
    } catch (InvalidTargetPathException e) {
        log.error(e, e.getMessage());
    }

    return false;
}
 
Example 7
Source File: AvdManager.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
/**
 * Updates the device-specific part of an AVD ini.
 * @param avd the AVD to update.
 * @param log the log object to receive action logs. Cannot be null.
 * @return The new AVD on success.
 * @throws IOException
 */
public AvdInfo updateDeviceChanged(AvdInfo avd, ILogger log) throws IOException {

    // Overwrite the properties derived from the device and nothing else
    Map<String, String> properties = new HashMap<String, String>(avd.getProperties());

    DeviceManager devMan = DeviceManager.createInstance(myLocalSdk.getLocation(), log);
    Collection<Device> devices = devMan.getDevices(DeviceManager.ALL_DEVICES);
    String name = properties.get(AvdManager.AVD_INI_DEVICE_NAME);
    String manufacturer = properties.get(AvdManager.AVD_INI_DEVICE_MANUFACTURER);

    if (properties != null && devices != null && name != null && manufacturer != null) {
        for (Device d : devices) {
            if (d.getId().equals(name) && d.getManufacturer().equals(manufacturer)) {
                properties.putAll(DeviceManager.getHardwareProperties(d));
                try {
                    return updateAvd(avd, properties, AvdStatus.OK, log);
                } catch (IOException e) {
                    log.error(e, null);
                }
            }
        }
    } else {
        log.error(null, "Base device information incomplete or missing.");
    }
    return null;
}
 
Example 8
Source File: LocalSdkParser.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Scan the sources/folders and register valid as well as broken source packages.
 */
private void scanSources(SdkManager sdkManager,
        HashSet<File> visited,
        ArrayList<Package> packages,
        ILogger log) {
    File srcRoot = new File(sdkManager.getLocation(), SdkConstants.FD_PKG_SOURCES);

    // The sources folder contains a list of platform folders.
    for (File platformDir : listFilesNonNull(srcRoot)) {
        if (platformDir.isDirectory() && !visited.contains(platformDir)) {
            visited.add(platformDir);

            // Ignore empty directories
            File[] srcFiles = platformDir.listFiles();
            if (srcFiles != null && srcFiles.length > 0) {
                Properties props =
                    parseProperties(new File(platformDir, SdkConstants.FN_SOURCE_PROP));

                try {
                    Package pkg = SourcePackage.create(platformDir, props);
                    packages.add(pkg);
                } catch (Exception e) {
                    log.error(e, null);
                }
            }
        }
    }
}
 
Example 9
Source File: LocalSdkParser.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Try to find a platform-tools package at the given location.
 * Returns null if not found.
 */
private Package scanPlatformTools(File platformToolsFolder, ILogger log) {
    // Can we find some properties?
    Properties props = parseProperties(new File(platformToolsFolder,
            SdkConstants.FN_SOURCE_PROP));

    // We're not going to check that all tools are present. At the very least
    // we should expect to find adb, aidl, aapt and dx (adapted to the current OS).

    if (platformToolsFolder.listFiles() == null) {
        // ListFiles is null if the directory doesn't even exist.
        // Not going to find anything in there...
        return null;
    }

    // Create our package. use the properties if we found any.
    try {
        Package pkg = PlatformToolPackage.create(
                null,                           //source
                props,                          //properties
                0,                              //revision
                null,                           //license
                "Platform Tools",               //description
                null,                           //descUrl
                platformToolsFolder.getPath()   //archiveOsPath
                );

        return pkg;
    } catch (Exception e) {
        log.error(e, null);
    }
    return null;
}
 
Example 10
Source File: LocalSdkParser.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
/**
 * Scan the build-tool/folders and register valid as well as broken build tool packages.
 */
private void scanBuildTools(
        SdkManager sdkManager,
        HashSet<File> visited,
        ArrayList<Package> packages,
        ILogger log) {
    File buildToolRoot = new File(sdkManager.getLocation(), SdkConstants.FD_BUILD_TOOLS);

    // The build-tool root folder contains a list of revisioned folders.
    for (File buildToolDir : listFilesNonNull(buildToolRoot)) {
        if (buildToolDir.isDirectory() && !visited.contains(buildToolDir)) {
            visited.add(buildToolDir);

            // Ignore empty directories
            File[] srcFiles = buildToolDir.listFiles();
            if (srcFiles != null && srcFiles.length > 0) {
                Properties props =
                    parseProperties(new File(buildToolDir, SdkConstants.FN_SOURCE_PROP));

                try {
                    Package pkg = BuildToolPackage.create(buildToolDir, props);
                    packages.add(pkg);
                } catch (Exception e) {
                    log.error(e, null);
                }
            }
        }
    }
}
 
Example 11
Source File: LocalSdkParser.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
/**
 * Try to find a platform-tools package at the given location.
 * Returns null if not found.
 */
private Package scanPlatformTools(File platformToolsFolder, ILogger log) {
    // Can we find some properties?
    Properties props = parseProperties(new File(platformToolsFolder,
            SdkConstants.FN_SOURCE_PROP));

    // We're not going to check that all tools are present. At the very least
    // we should expect to find adb, aidl, aapt and dx (adapted to the current OS).

    if (platformToolsFolder.listFiles() == null) {
        // ListFiles is null if the directory doesn't even exist.
        // Not going to find anything in there...
        return null;
    }

    // Create our package. use the properties if we found any.
    try {
        Package pkg = PlatformToolPackage.create(
                null,                           //source
                props,                          //properties
                0,                              //revision
                null,                           //license
                "Platform Tools",               //description
                null,                           //descUrl
                platformToolsFolder.getPath()   //archiveOsPath
                );

        return pkg;
    } catch (Exception e) {
        log.error(e, null);
    }
    return null;
}
 
Example 12
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);
            }
        }
    }
}
 
Example 13
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 14
Source File: LocalSdkParser.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Scan the build-tool/folders and register valid as well as broken build tool packages.
 */
private void scanBuildTools(
        SdkManager sdkManager,
        HashSet<File> visited,
        ArrayList<Package> packages,
        ILogger log) {
    File buildToolRoot = new File(sdkManager.getLocation(), SdkConstants.FD_BUILD_TOOLS);

    // The build-tool root folder contains a list of revisioned folders.
    for (File buildToolDir : listFilesNonNull(buildToolRoot)) {
        if (buildToolDir.isDirectory() && !visited.contains(buildToolDir)) {
            visited.add(buildToolDir);

            // Ignore empty directories
            File[] srcFiles = buildToolDir.listFiles();
            if (srcFiles != null && srcFiles.length > 0) {
                Properties props =
                    parseProperties(new File(buildToolDir, SdkConstants.FN_SOURCE_PROP));

                try {
                    Package pkg = BuildToolPackage.create(buildToolDir, props);
                    packages.add(pkg);
                } catch (Exception e) {
                    log.error(e, null);
                }
            }
        }
    }
}
 
Example 15
Source File: LocalSdkParser.java    From javaide with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Try to find a tools package at the given location.
 * Returns null if not found.
 */
private Package scanTools(File toolFolder, ILogger log) {
    // Can we find some properties?
    Properties props = parseProperties(new File(toolFolder, SdkConstants.FN_SOURCE_PROP));

    // We're not going to check that all tools are present. At the very least
    // we should expect to find android and an emulator adapted to the current OS.
    boolean hasEmulator = false;
    boolean hasAndroid = false;
    String android1 = SdkConstants.androidCmdName().replace(".bat", ".exe");
    String android2 = android1.indexOf('.') == -1 ? null : android1.replace(".exe", ".bat");
    for (File file : listFilesNonNull(toolFolder)) {
        String name = file.getName();
        if (SdkConstants.FN_EMULATOR.equals(name)) {
            hasEmulator = true;
        }
        if (android1.equals(name) || (android2 != null && android2.equals(name))) {
            hasAndroid = true;
        }
    }

    if (!hasAndroid || !hasEmulator) {
        return null;
    }

    // Create our package. use the properties if we found any.
    try {
        Package pkg = ToolPackage.create(
                null,                       //source
                props,                      //properties
                0,                          //revision
                null,                       //license
                "Tools",                    //description
                null,                       //descUrl
                toolFolder.getPath()        //archiveOsPath
                );

        return pkg;
    } catch (Exception e) {
        log.error(e, null);
    }
    return null;
}
 
Example 16
Source File: LocalSdkParser.java    From java-n-IDE-for-Android with Apache License 2.0 4 votes vote down vote up
/**
 * Try to find a tools package at the given location.
 * Returns null if not found.
 */
private Package scanTools(File toolFolder, ILogger log) {
    // Can we find some properties?
    Properties props = parseProperties(new File(toolFolder, SdkConstants.FN_SOURCE_PROP));

    // We're not going to check that all tools are present. At the very least
    // we should expect to find android and an emulator adapted to the current OS.
    boolean hasEmulator = false;
    boolean hasAndroid = false;
    String android1 = SdkConstants.androidCmdName().replace(".bat", ".exe");
    String android2 = android1.indexOf('.') == -1 ? null : android1.replace(".exe", ".bat");
    for (File file : listFilesNonNull(toolFolder)) {
        String name = file.getName();
        if (SdkConstants.FN_EMULATOR.equals(name)) {
            hasEmulator = true;
        }
        if (android1.equals(name) || (android2 != null && android2.equals(name))) {
            hasAndroid = true;
        }
    }

    if (!hasAndroid || !hasEmulator) {
        return null;
    }

    // Create our package. use the properties if we found any.
    try {
        Package pkg = ToolPackage.create(
                null,                       //source
                props,                      //properties
                0,                          //revision
                null,                       //license
                "Tools",                    //description
                null,                       //descUrl
                toolFolder.getPath()        //archiveOsPath
                );

        return pkg;
    } catch (Exception e) {
        log.error(e, null);
    }
    return null;
}
 
Example 17
Source File: ToolsInstructionsCleaner.java    From java-n-IDE-for-Android with Apache License 2.0 4 votes vote down vote up
private static MergingReport.Result cleanToolsReferences(
        Element element,
        ILogger logger) {

    NamedNodeMap namedNodeMap = element.getAttributes();
    if (namedNodeMap != null) {
        // make a copy of the original list of attributes as we will remove some during this
        // process.
        List<Node> attributes = new ArrayList<Node>();
        for (int i = 0; i < namedNodeMap.getLength(); i++) {
            attributes.add(namedNodeMap.item(i));
        }
        for (Node attribute : attributes) {
            if (SdkConstants.TOOLS_URI.equals(attribute.getNamespaceURI())) {
                // we need to special case when the element contained tools:node="remove"
                // since it also needs to be deleted unless it had a selector.
                // if this is ools:node="removeAll", we always delete the element whether or
                // not there is a tools:selector.
                boolean hasSelector = namedNodeMap.getNamedItemNS(
                        SdkConstants.TOOLS_URI, "selector") != null;
                if (attribute.getLocalName().equals(NodeOperationType.NODE_LOCAL_NAME)
                        && (attribute.getNodeValue().equals(REMOVE_ALL_OPERATION_XML_MAME)
                            || (attribute.getNodeValue().equals(REMOVE_OPERATION_XML_MAME))
                                && !hasSelector)) {

                    if (element.getParentNode().getNodeType() == Node.DOCUMENT_NODE) {
                        logger.error(null /* Throwable */,
                                String.format(
                                    "tools:node=\"%1$s\" not allowed on top level %2$s element",
                                    attribute.getNodeValue(),
                                    XmlNode.unwrapName(element)));
                        return ERROR;
                    } else {
                        element.getParentNode().removeChild(element);
                    }
                } else {
                    // anything else, we just clean the attribute.
                    element.removeAttributeNS(
                            attribute.getNamespaceURI(), attribute.getLocalName());
                }
            }
            // this could also be the xmlns:tools declaration.
            if (attribute.getNodeName().startsWith(SdkConstants.XMLNS_PREFIX)
                && SdkConstants.TOOLS_URI.equals(attribute.getNodeValue())) {
                element.removeAttribute(attribute.getNodeName());
            }
        }
    }
    // make a copy of the element children since we will be removing some during
    // this process, we don't want side effects.
    NodeList childNodes = element.getChildNodes();
    ImmutableList.Builder<Element> childElements = ImmutableList.builder();
    for (int i = 0; i < childNodes.getLength(); i++) {
        Node node = childNodes.item(i);
        if (node.getNodeType() == Node.ELEMENT_NODE) {
            childElements.add((Element) node);
        }
    }
    for (Element childElement : childElements.build()) {
        if (cleanToolsReferences(childElement, logger) == ERROR) {
            return ERROR;
        }
    }
    return MergingReport.Result.SUCCESS;
}
 
Example 18
Source File: LocalSdkParser.java    From java-n-IDE-for-Android with Apache License 2.0 4 votes vote down vote up
/**
 * The sdk manager only lists valid system image via its addons or platform targets.
 * However here we also want to find "broken" system images, that is system images
 * that are located in the sdk/system-images folder but somehow not loaded properly.
 */
private void scanMissingSystemImages(SdkManager sdkManager,
        HashSet<File> visited,
        ArrayList<Package> packages,
        ILogger log) {
    File siRoot = new File(sdkManager.getLocation(), SdkConstants.FD_SYSTEM_IMAGES);

    // The system-images folder contains a list of platform folders.
    for (File platformDir : listFilesNonNull(siRoot)) {
        if (platformDir.isDirectory() && !visited.contains(platformDir)) {
            visited.add(platformDir);

            // In the platform directory, we expect a list of abi folders
            // or a list of tag/abi folders. Basically parse any folder that has
            // a source.prop file within 2 levels.
            List<File> propFiles = Lists.newArrayList();

            for (File dir1 : listFilesNonNull(platformDir)) {
                if (dir1.isDirectory() && !visited.contains(dir1)) {
                    visited.add(dir1);
                    File prop1 = new File(dir1, SdkConstants.FN_SOURCE_PROP);
                    if (prop1.isFile()) {
                        propFiles.add(prop1);
                    } else {
                        for (File dir2 : listFilesNonNull(dir1)) {
                            if (dir2.isDirectory() && !visited.contains(dir2)) {
                                visited.add(dir2);
                                File prop2 = new File(dir2, SdkConstants.FN_SOURCE_PROP);
                                if (prop2.isFile()) {
                                    propFiles.add(prop2);
                                }
                            }
                        }
                    }
                }
            }

            for (File propFile : propFiles) {
                Properties props = parseProperties(propFile);
                try {
                    Package pkg = SystemImagePackage.createBroken(propFile.getParentFile(),
                                                                  props);
                    packages.add(pkg);
                } catch (Exception e) {
                    log.error(e, null);
                }
            }
        }
    }
}
 
Example 19
Source File: LocalSdkParser.java    From javaide with GNU General Public License v3.0 4 votes vote down vote up
/**
 * The sdk manager only lists valid system image via its addons or platform targets.
 * However here we also want to find "broken" system images, that is system images
 * that are located in the sdk/system-images folder but somehow not loaded properly.
 */
private void scanMissingSystemImages(SdkManager sdkManager,
        HashSet<File> visited,
        ArrayList<Package> packages,
        ILogger log) {
    File siRoot = new File(sdkManager.getLocation(), SdkConstants.FD_SYSTEM_IMAGES);

    // The system-images folder contains a list of platform folders.
    for (File platformDir : listFilesNonNull(siRoot)) {
        if (platformDir.isDirectory() && !visited.contains(platformDir)) {
            visited.add(platformDir);

            // In the platform directory, we expect a list of abi folders
            // or a list of tag/abi folders. Basically parse any folder that has
            // a source.prop file within 2 levels.
            List<File> propFiles = Lists.newArrayList();

            for (File dir1 : listFilesNonNull(platformDir)) {
                if (dir1.isDirectory() && !visited.contains(dir1)) {
                    visited.add(dir1);
                    File prop1 = new File(dir1, SdkConstants.FN_SOURCE_PROP);
                    if (prop1.isFile()) {
                        propFiles.add(prop1);
                    } else {
                        for (File dir2 : listFilesNonNull(dir1)) {
                            if (dir2.isDirectory() && !visited.contains(dir2)) {
                                visited.add(dir2);
                                File prop2 = new File(dir2, SdkConstants.FN_SOURCE_PROP);
                                if (prop2.isFile()) {
                                    propFiles.add(prop2);
                                }
                            }
                        }
                    }
                }
            }

            for (File propFile : propFiles) {
                Properties props = parseProperties(propFile);
                try {
                    Package pkg = SystemImagePackage.createBroken(propFile.getParentFile(),
                                                                  props);
                    packages.add(pkg);
                } catch (Exception e) {
                    log.error(e, null);
                }
            }
        }
    }
}
 
Example 20
Source File: ToolsInstructionsCleaner.java    From javaide with GNU General Public License v3.0 4 votes vote down vote up
private static MergingReport.Result cleanToolsReferences(
        Element element,
        ILogger logger) {

    NamedNodeMap namedNodeMap = element.getAttributes();
    if (namedNodeMap != null) {
        // make a copy of the original list of attributes as we will remove some during this
        // process.
        List<Node> attributes = new ArrayList<Node>();
        for (int i = 0; i < namedNodeMap.getLength(); i++) {
            attributes.add(namedNodeMap.item(i));
        }
        for (Node attribute : attributes) {
            if (SdkConstants.TOOLS_URI.equals(attribute.getNamespaceURI())) {
                // we need to special case when the element contained tools:node="remove"
                // since it also needs to be deleted unless it had a selector.
                // if this is ools:node="removeAll", we always delete the element whether or
                // not there is a tools:selector.
                boolean hasSelector = namedNodeMap.getNamedItemNS(
                        SdkConstants.TOOLS_URI, "selector") != null;
                if (attribute.getLocalName().equals(NodeOperationType.NODE_LOCAL_NAME)
                        && (attribute.getNodeValue().equals(REMOVE_ALL_OPERATION_XML_MAME)
                            || (attribute.getNodeValue().equals(REMOVE_OPERATION_XML_MAME))
                                && !hasSelector)) {

                    if (element.getParentNode().getNodeType() == Node.DOCUMENT_NODE) {
                        logger.error(null /* Throwable */,
                                String.format(
                                    "tools:node=\"%1$s\" not allowed on top level %2$s element",
                                    attribute.getNodeValue(),
                                    XmlNode.unwrapName(element)));
                        return ERROR;
                    } else {
                        element.getParentNode().removeChild(element);
                    }
                } else {
                    // anything else, we just clean the attribute.
                    element.removeAttributeNS(
                            attribute.getNamespaceURI(), attribute.getLocalName());
                }
            }
            // this could also be the xmlns:tools declaration.
            if (attribute.getNodeName().startsWith(SdkConstants.XMLNS_PREFIX)
                && SdkConstants.TOOLS_URI.equals(attribute.getNodeValue())) {
                element.removeAttribute(attribute.getNodeName());
            }
        }
    }
    // make a copy of the element children since we will be removing some during
    // this process, we don't want side effects.
    NodeList childNodes = element.getChildNodes();
    ImmutableList.Builder<Element> childElements = ImmutableList.builder();
    for (int i = 0; i < childNodes.getLength(); i++) {
        Node node = childNodes.item(i);
        if (node.getNodeType() == Node.ELEMENT_NODE) {
            childElements.add((Element) node);
        }
    }
    for (Element childElement : childElements.build()) {
        if (cleanToolsReferences(childElement, logger) == ERROR) {
            return ERROR;
        }
    }
    return MergingReport.Result.SUCCESS;
}