Java Root Directory Get getRoot(final File workingDirectory)

Here you can find the source of getRoot(final File workingDirectory)

Description

Gets the root (or project) directory of a project.

License

Apache License

Parameter

Parameter Description
workingDirectory the working-directory.

Return

the root-directory.

Declaration

public static File getRoot(final File workingDirectory) 

Method Source Code


//package com.java2s;
/*//from   w  w w . ja v a 2 s  .com
 * #%L
 * restdoc-plugin
 * %%
 * Copyright (C) 2012 IG Group
 * %%
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * #L%
 */

import java.io.File;

public class Main {
    /**
     * The name of POM file.
     */
    public static final String POM_FILE = "pom.xml";

    /**
     * Gets the root (or project) directory of a project. The working-directory
     * can be any of the modules.
     * 
     * @param workingDirectory the working-directory.
     * @return the root-directory.
     */
    public static File getRoot(final File workingDirectory) {
        File ref = workingDirectory;
        while (ref.getParentFile() != null && new File(ref.getParentFile(), POM_FILE).exists()) {
            ref = ref.getParentFile();
        }
        return ref;
    }
}

Related

  1. getRoot()
  2. getRoot(File child)
  3. getRoot(File file)
  4. getRoot(File file)
  5. getRoot(File file, ArrayList lst)
  6. getRoot(final String path)
  7. getRoot(String path)
  8. getRootDir()
  9. getRootDir()