Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 /*
  * Copyright 2012 Red Hat, Inc. and/or its affiliates.
  *
  * Licensed under the Eclipse Public License version 1.0, available at
  * http://www.eclipse.org/legal/epl-v10.html
  */
 package org.jboss.forge.maven.locators;
 
 import java.io.File;
Locate a Maven project starting in the current directory, and progressing up the chain of parent directories until a project is found, or the root directory is found. If a project is found, return the java.io.File referring to the directory containing that project, or return null if no projects were found.

Author(s):
Lincoln Baxter, III
public class MavenProjectLocator implements ProjectLocator
    private final ProjectFactory factory;
    private final Instance<MavenCoreFacetcoreFacetInstance;
    @Inject
    public MavenProjectLocator(final ProjectFactory factory, @Any final Instance<MavenCoreFacetcoreFacet)
    {
        this. = factory;
        this. = coreFacet;
    }
    @Override
    public Project createProject(final DirectoryResource dir)
    {
        Project result = new ProjectImpl(dir);
        MavenCoreFacet maven = .get();
        maven.setProject(result);
        if (!maven.isInstalled())
        {
            result.installFacet(maven);
        }
        else
            result.registerFacet(maven);
        
        if(!result.hasFacet(MavenCoreFacet.class))
        {
            throw new IllegalStateException("Could not create Maven project [MavenCoreFacet could not be installed.]");
        }
        return result;
    }
    @Override
    public boolean containsProject(final DirectoryResource dir)
    {
        Resource<?> pom = dir.getChild("pom.xml");
        return pom.exists();
    }
New to GrepCode? Check out our FAQ X