private UpdateInfo findUpdateInfoToRemoveDependency()

in org.apache.ivyde.eclipse/src/java/org/apache/ivyde/common/ivyfile/IvyFileUpdater.java [143:191]


    private UpdateInfo findUpdateInfoToRemoveDependency(String content, ModuleId depId) {
        UpdateInfo info = new UpdateInfo();

        Matcher depsMatcher = Pattern.compile("<\\s*dependencies").matcher(content);
        if (!depsMatcher.find()) {
            // no dependencies at all, nothing to do
            return null;
        }
        Matcher depMatcher = Pattern.compile("<\\s*dependency\\s+.*name=[\"']([^\"']+)[\"']")
                .matcher(content);
        int start = depsMatcher.start();
        while (depMatcher.find(start)) {
            if (depId.getName().equals(depMatcher.group(1))) {
                // we have found the dependency to remove: let's remove it
                info.insertFromIndex = depMatcher.start();
                Matcher m = Pattern.compile("</\\s*dependency\\s*>").matcher(content);
                if (m.find(info.insertFromIndex)) {
                    info.insertToIndex = m.end();
                }
                m = Pattern.compile("<\\s*dependency[^<]*?\\/\\>").matcher(content);
                if (m.find(info.insertFromIndex)) {
                    info.insertToIndex = info.insertToIndex > 0 ? Math.min(info.insertToIndex, m
                            .end()) : m.end();
                }
                info.insertFromIndex = findStartOfBlock(content, info.insertFromIndex);
                info.insertToIndex = findEndOfBlock(content, info.insertToIndex);
                return info;
            }
            start = depMatcher.end();
        }

        // we haven't found the dependency in the list of declared dependencies

        if (start == depsMatcher.start()) {
            // no dependencies at all, nothing to do
            return null;
        }
        // there is at least one direct dependency, but not the one to remove, so we must exclude it
        Matcher depsCloseMatcher = Pattern.compile("<\\s*/dependencies").matcher(content);
        if (!depsCloseMatcher.find()) {
            // no closing tag for dependencies, probably malformed xml, nothing to do
            return null;
        }
        info.insertFromIndex = findLastDependencyEnd(content, depsCloseMatcher.start());
        info.insertToIndex = info.insertFromIndex;
        info.prefix = NL;
        info.insert = getDependencyToExclude(depId);
        return info;
    }