<commit_before>package org.springframework.roo.project;

import static org.springframework.roo.support.util.FileUtils.CURRENT_DIRECTORY;

import java.io.File;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.Service;
import org.osgi.service.component.ComponentContext;
import org.springframework.roo.file.monitor.FileMonitorService;
import org.springframework.roo.metadata.MetadataDependencyRegistry;
import org.springframework.roo.metadata.MetadataService;
import org.springframework.roo.process.manager.FileManager;
import org.springframework.roo.project.maven.Pom;
import org.springframework.roo.project.maven.PomFactory;
import org.springframework.roo.shell.Shell;
import org.springframework.roo.support.osgi.OSGiUtils;
import org.springframework.roo.support.util.Assert;
import org.springframework.roo.support.util.FileUtils;
import org.springframework.roo.support.util.StringUtils;
import org.springframework.roo.support.util.XmlUtils;
import org.w3c.dom.Document;
import org.w3c.dom.Element;

@Component
@Service
public class PomManagementServiceImpl implements PomManagementService {

    // Constants
    private static final String DEFAULT_POM_NAME = "pom.xml";
    private static final String DEFAULT_RELATIVE_PATH = ".." + File.separator
            + DEFAULT_POM_NAME;

    // Fields
    @Reference FileManager fileManager;
    @Reference FileMonitorService fileMonitorService;
    @Reference MetadataDependencyRegistry metadataDependencyRegistry;
    @Reference MetadataService metadataService;
    @Reference PomFactory pomFactory;
    @Reference Shell shell;

    private final Set<String> toBeParsed = new HashSet<String>();
    private final Map<String, Pom> pomMap = new LinkedHashMap<String, Pom>(); // linked
                                                                              // to
                                                                              // preserve
                                                                              // sort
                                                                              // order
    private String focusedModulePath;
    private String projectRootDirectory;

    // ------------------------ OSGi lifecycle callbacks -----------------------

    protected void activate(final ComponentContext context) {
        final File projectDirectory = new File(StringUtils.defaultIfEmpty(
                OSGiUtils.getRooWorkingDirectory(context), CURRENT_DIRECTORY));
        projectRootDirectory = FileUtils.getCanonicalPath(projectDirectory);
    }

    // --------------------- PomManagementService methods ----------------------

    public Pom getModuleForFileIdentifier(final String fileIdentifier) {
        updatePomCache();
        String startingPoint = FileUtils.getFirstDirectory(fileIdentifier);
        String pomPath = FileUtils.ensureTrailingSeparator(startingPoint)
                + DEFAULT_POM_NAME;
        File pom = new File(pomPath);
        while (!pom.exists()) {
            if (startingPoint.equals(File.separator)) {
                break;
            }
            startingPoint = FileUtils.backOneDirectory(startingPoint);
            pomPath = FileUtils.ensureTrailingSeparator(startingPoint)
                    + DEFAULT_POM_NAME;
            pom = new File(pomPath);
        }
        return getPomFromPath(pomPath);
    }
<commit_msg>ROO-2986: Post 1.2.0.RELEASE code refactor and clean up - more formatting<commit_after>package org.springframework.roo.project;

import static org.springframework.roo.support.util.FileUtils.CURRENT_DIRECTORY;

import java.io.File;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.Service;
import org.osgi.service.component.ComponentContext;
import org.springframework.roo.file.monitor.FileMonitorService;
import org.springframework.roo.metadata.MetadataDependencyRegistry;
import org.springframework.roo.metadata.MetadataService;
import org.springframework.roo.process.manager.FileManager;
import org.springframework.roo.project.maven.Pom;
import org.springframework.roo.project.maven.PomFactory;
import org.springframework.roo.shell.Shell;
import org.springframework.roo.support.osgi.OSGiUtils;
import org.springframework.roo.support.util.Assert;
import org.springframework.roo.support.util.FileUtils;
import org.springframework.roo.support.util.StringUtils;
import org.springframework.roo.support.util.XmlUtils;
import org.w3c.dom.Document;
import org.w3c.dom.Element;

@Component
@Service
public class PomManagementServiceImpl implements PomManagementService {

    // Constants
    private static final String DEFAULT_POM_NAME = "pom.xml";
    private static final String DEFAULT_RELATIVE_PATH = ".." + File.separator
            + DEFAULT_POM_NAME;

    // Fields
    @Reference FileManager fileManager;
    @Reference FileMonitorService fileMonitorService;
    @Reference MetadataDependencyRegistry metadataDependencyRegistry;
    @Reference MetadataService metadataService;
    @Reference PomFactory pomFactory;
    @Reference Shell shell;

    private final Set<String> toBeParsed = new HashSet<String>();
    private final Map<String, Pom> pomMap = new LinkedHashMap<String, Pom>();
    private String focusedModulePath;
    private String projectRootDirectory;

    // ------------------------ OSGi lifecycle callbacks -----------------------

    protected void activate(final ComponentContext context) {
        final File projectDirectory = new File(StringUtils.defaultIfEmpty(
                OSGiUtils.getRooWorkingDirectory(context), CURRENT_DIRECTORY));
        projectRootDirectory = FileUtils.getCanonicalPath(projectDirectory);
    }

    // --------------------- PomManagementService methods ----------------------

    public Pom getModuleForFileIdentifier(final String fileIdentifier) {
        updatePomCache();
        String startingPoint = FileUtils.getFirstDirectory(fileIdentifier);
        String pomPath = FileUtils.ensureTrailingSeparator(startingPoint)
                + DEFAULT_POM_NAME;
        File pom = new File(pomPath);
        while (!pom.exists()) {
            if (startingPoint.equals(File.separator)) {
                break;
            }
            startingPoint = FileUtils.backOneDirectory(startingPoint);
            pomPath = FileUtils.ensureTrailingSeparator(startingPoint)
                    + DEFAULT_POM_NAME;
            pom = new File(pomPath);
        }
        return getPomFromPath(pomPath);
    }

{'fraction_non_alphanumeric': 0.10621437508689004, 'fraction_numerical': 0.0015292645627693591, 'mean_word_length': 2.9354485776805253, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4157808', 'n_tokens_mistral': 1842, 'n_tokens_neox': 1800, 'n_words': 366}