Java Code Examples for org.apache.maven.project.MavenProject#getParentFile()

The following examples show how to use org.apache.maven.project.MavenProject#getParentFile() . 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: MavenEmbedder.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * normalize all File references in the object tree.
 * @param project 
 * @since 2.36
 */
public static void normalizePaths(MavenProject project) {
    if (project == null) {
        return;
    }
    File f = project.getFile();
    if (f != null) {
        project.setFile(FileUtil.normalizeFile(f));
    }
    normalizePath(project.getArtifact());
    normalizePaths(project.getAttachedArtifacts());
    f = project.getParentFile();
    if (f != null) {
        project.setParentFile(FileUtil.normalizeFile(f));
    }
    normalizePath(project.getParentArtifact());
    
    normalizePaths(project.getArtifacts());
    normalizePaths(project.getDependencyArtifacts());
    normalizePaths(project.getExtensionArtifacts());
    normalizePaths(project.getPluginArtifacts());
    
    normalizePath(project.getModel());
    normalizePath(project.getOriginalModel());
}
 
Example 2
Source File: NbMavenProjectImpl.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * replacement for MavenProject.getParent() which has bad long term memory behaviour. We offset it by recalculating/reparsing everything
 * therefore should not be used lightly!
 * pass a MavenProject instance and current configuration and other settings will be applied when loading the parent.
 * @param project
 * @return null or the parent mavenproject
 */

public MavenProject loadParentOf(MavenEmbedder embedder, MavenProject project) throws ProjectBuildingException {

    MavenProject parent = null;
    ProjectBuilder builder = embedder.lookupComponent(ProjectBuilder.class);
    MavenExecutionRequest req = embedder.createMavenExecutionRequest();
    M2Configuration active = configProvider.getActiveConfiguration();
    req.addActiveProfiles(active.getActivatedProfiles());
    req.setNoSnapshotUpdates(true);
    req.setUpdateSnapshots(false);
    req.setInteractiveMode(false);
    req.setRecursive(false);
    req.setOffline(true);
    //#238800 important to merge, not replace
    Properties uprops = req.getUserProperties();
    uprops.putAll(MavenProjectCache.createUserPropsForProjectLoading(active.getProperties()));
    req.setUserProperties(uprops);
    
    ProjectBuildingRequest request = req.getProjectBuildingRequest();
    request.setRemoteRepositories(project.getRemoteArtifactRepositories());
    DefaultMaven maven = (DefaultMaven) embedder.lookupComponent(Maven.class);
    
    request.setRepositorySession(maven.newRepositorySession(req));

    if (project.getParentFile() != null) {
        parent = builder.build(project.getParentFile(), request).getProject();
    } else if (project.getModel().getParent() != null) {
        parent = builder.build(project.getParentArtifact(), request).getProject();
    }
    //clear the project building request, it references multiple Maven Models via the RepositorySession cache
    //is not used in maven itself, most likely used by m2e only..
    if (parent != null) {
        parent.setProjectBuildingRequest(null);
    }
    MavenEmbedder.normalizePaths(parent);
    return parent;
}
 
Example 3
Source File: AbstractSetQualifierMojo.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
private void checkNonRelativeParent ( final MavenProject project )
{
    if ( project.getModel ().getParent () == null )
    {
        // no parent
        return;
    }

    if ( project.getParentFile () != null )
    {
        // is a local parent
        return;
    }

    final Parent parent = project.getModel ().getParent ();

    final String prefix = String.format ( "%s:%s:", parent.getGroupId (), parent.getArtifactId () );
    for ( final String entry : this.forceUpdateParentQualifiers )
    {
        if ( entry.startsWith ( prefix ) )
        {
            final String qualifier = entry.substring ( prefix.length () );
            final String newVersion = makeVersion ( parent.getVersion (), qualifier );

            getLog ().info ( String.format ( "Force update parent of %s to %s -> %s", project.getId (), parent.getId (), newVersion ) );

            addChange ( project.getFile (), new ModelModifier () {

                @Override
                public boolean apply ( final Model model )
                {
                    model.getParent ().setVersion ( newVersion );
                    return true;
                }
            } );
        }
    }
}
 
Example 4
Source File: DefaultPomHelper.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
private boolean hasLocalParent ( final MavenProject project )
{
    if ( project.getParentFile () != null )
    {
        return true;
    }
    return false;
}
 
Example 5
Source File: DefaultPomHelper.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void visitModulesWithParent ( final Collection<MavenProject> projects, final MavenProject parentProject, final ProjectVisitor visitor ) throws Exception
{
    for ( final MavenProject project : projects )
    {
        if ( project.getParentFile () == null )
        {
            continue;
        }
        if ( project.getParentFile ().equals ( parentProject.getFile () ) )
        {
            visitor.visit ( project );
        }
    }
}
 
Example 6
Source File: ApigccMojo.java    From apigcc-maven-plugin with MIT License 4 votes vote down vote up
private MavenProject findParent(MavenProject mp){
    if(mp.getParentFile()!=null && mp.getParentFile().exists()){
        return findParent(mp.getParent());
    }
    return mp;
}