aboutsummaryrefslogtreecommitdiffstats
blob: fcfc97043b68a7db1dfc01248d24a1e3ba1cbf87 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/*******************************************************************************
 * Copyright (c) 2008 Sonatype, Inc.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *******************************************************************************/

package org.eclipse.m2e.jdt;

import java.io.File;

import org.apache.maven.plugin.MojoExecution;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.m2e.core.project.IMavenProjectFacade;
import org.eclipse.m2e.core.project.MavenProjectUtils;
import org.eclipse.m2e.core.project.configurator.AbstractProjectConfigurator;
import org.eclipse.m2e.core.project.configurator.ProjectConfigurationRequest;

public abstract class AbstractJavaProjectConfigurator
    extends AbstractProjectConfigurator
    implements IJavaProjectConfigurator
{
    @Override
    public void configure( ProjectConfigurationRequest request, IProgressMonitor monitor )
        throws CoreException
    {
        // TODO Auto-generated method stub

    }

    public void configureClasspath( IMavenProjectFacade facade, IClasspathDescriptor classpath, IProgressMonitor monitor )
        throws CoreException
    {
        // TODO Auto-generated method stub

    }

    public void configureRawClasspath( ProjectConfigurationRequest request, IClasspathDescriptor classpath,
                                       IProgressMonitor monitor )
        throws CoreException
    {
        IMavenProjectFacade facade = request.getMavenProjectFacade();

        assertHasNature( request.getProject(), JavaCore.NATURE_ID );

        for ( MojoExecution mojoExecution : getMojoExecutions( request, monitor ) )
        {
            File[] sources = getSourceFolders( request, mojoExecution );

            for ( File source : sources )
            {
                IPath sourcePath = getFullPath( facade, source );

                if ( sourcePath != null && !classpath.containsPath( sourcePath ) )
                {
                    classpath.addSourceEntry( sourcePath, facade.getOutputLocation(), true );
                }
            }
        }
    }

    protected IPath getFullPath( IMavenProjectFacade facade, File file )
    {
        IProject project = facade.getProject();
        IPath path = MavenProjectUtils.getProjectRelativePath( project, file.getAbsolutePath() );
        return project.getFullPath().append( path );
    }

    protected File[] getSourceFolders( ProjectConfigurationRequest request, MojoExecution mojoExecution )
        throws CoreException
    {
        return new File[] { getParameterValue( getOutputFolderParameterName(), File.class, request.getMavenSession(),
                                               mojoExecution ) };
    }

    protected String getOutputFolderParameterName()
    {
        return "outputDirectory";
    }

}