diff options
author | Igor Fedorenko | 2011-07-14 15:30:53 +0000 |
---|---|---|
committer | Igor Fedorenko | 2011-07-14 15:30:53 +0000 |
commit | c0e3be615997a389f62a64909b5ad3b252a393ca (patch) | |
tree | 0ada5edfb178bd2e02f6a055f7f4a8a21f6b5584 | |
parent | d9cec9237a770db8494045c1ebca4f0c684b67ce (diff) | |
download | m2e-core-c0e3be615997a389f62a64909b5ad3b252a393ca.tar.gz m2e-core-c0e3be615997a389f62a64909b5ad3b252a393ca.tar.xz m2e-core-c0e3be615997a389f62a64909b5ad3b252a393ca.zip |
350939 make JavaProjectConfigurator more extensible
Some projects (no names mentioned!) create forked versions of
maven-compiler-plugin and need to way to customize compiler plugin
groupdId, artifactId and goal names to match their forked version.
Signed-off-by: Igor Fedorenko <igor@ifedorenko.com>
-rw-r--r-- | org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/AbstractJavaProjectConfigurator.java | 79 |
1 files changed, 47 insertions, 32 deletions
diff --git a/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/AbstractJavaProjectConfigurator.java b/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/AbstractJavaProjectConfigurator.java index 00147116..e0a69e4d 100644 --- a/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/AbstractJavaProjectConfigurator.java +++ b/org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/internal/AbstractJavaProjectConfigurator.java @@ -253,37 +253,41 @@ public abstract class AbstractJavaProjectConfigurator extends AbstractProjectCon MavenSession mavenSession = request.getMavenSession(); - for(MojoExecution compile : projectFacade.getMojoExecutions(COMPILER_PLUGIN_GROUP_ID, - COMPILER_PLUGIN_ARTIFACT_ID, mon.newChild(1), GOAL_COMPILE)) { - mainSourceEncoding = maven.getMojoParameterValue(mavenSession, compile, "encoding", String.class); //$NON-NLS-1$ - try { - inclusion = toPaths(maven.getMojoParameterValue(request.getMavenSession(), compile, - "includes", String[].class)); //$NON-NLS-1$ - } catch(CoreException ex) { - log.error("Failed to determine compiler inclusions, assuming defaults", ex); - } - try { - exclusion = toPaths(maven.getMojoParameterValue(request.getMavenSession(), compile, - "excludes", String[].class)); //$NON-NLS-1$ - } catch(CoreException ex) { - log.error("Failed to determine compiler exclusions, assuming defaults", ex); + List<MojoExecution> executions = getCompilerMojoExecutions(request, mon.newChild(1)); + + for(MojoExecution compile : executions) { + if(isCompileExecution(compile)) { + mainSourceEncoding = maven.getMojoParameterValue(mavenSession, compile, "encoding", String.class); //$NON-NLS-1$ + try { + inclusion = toPaths(maven.getMojoParameterValue(request.getMavenSession(), compile, + "includes", String[].class)); //$NON-NLS-1$ + } catch(CoreException ex) { + log.error("Failed to determine compiler inclusions, assuming defaults", ex); + } + try { + exclusion = toPaths(maven.getMojoParameterValue(request.getMavenSession(), compile, + "excludes", String[].class)); //$NON-NLS-1$ + } catch(CoreException ex) { + log.error("Failed to determine compiler exclusions, assuming defaults", ex); + } } } - for(MojoExecution compile : projectFacade.getMojoExecutions(COMPILER_PLUGIN_GROUP_ID, - COMPILER_PLUGIN_ARTIFACT_ID, mon.newChild(1), GOAL_TESTCOMPILE)) { - testSourceEncoding = maven.getMojoParameterValue(mavenSession, compile, "encoding", String.class); //$NON-NLS-1$ - try { - inclusionTest = toPaths(maven.getMojoParameterValue(request.getMavenSession(), compile, - "testIncludes", String[].class)); //$NON-NLS-1$ - } catch(CoreException ex) { - log.error("Failed to determine compiler test inclusions, assuming defaults", ex); - } - try { - exclusionTest = toPaths(maven.getMojoParameterValue(request.getMavenSession(), compile, - "testExcludes", String[].class)); //$NON-NLS-1$ - } catch(CoreException ex) { - log.error("Failed to determine compiler test exclusions, assuming defaults", ex); + for(MojoExecution compile : executions) { + if(isTestCompileExecution(compile)) { + testSourceEncoding = maven.getMojoParameterValue(mavenSession, compile, "encoding", String.class); //$NON-NLS-1$ + try { + inclusionTest = toPaths(maven.getMojoParameterValue(request.getMavenSession(), compile, + "testIncludes", String[].class)); //$NON-NLS-1$ + } catch(CoreException ex) { + log.error("Failed to determine compiler test inclusions, assuming defaults", ex); + } + try { + exclusionTest = toPaths(maven.getMojoParameterValue(request.getMavenSession(), compile, + "testExcludes", String[].class)); //$NON-NLS-1$ + } catch(CoreException ex) { + log.error("Failed to determine compiler test exclusions, assuming defaults", ex); + } } } @@ -311,6 +315,14 @@ public abstract class AbstractJavaProjectConfigurator extends AbstractProjectCon } } + protected boolean isTestCompileExecution(MojoExecution execution) { + return GOAL_TESTCOMPILE.equals(execution.getGoal()); + } + + protected boolean isCompileExecution(MojoExecution execution) { + return GOAL_COMPILE.equals(execution.getGoal()); + } + private IPath[] toPaths(String[] values) { if(values == null) { return new IPath[0]; @@ -410,12 +422,9 @@ public abstract class AbstractJavaProjectConfigurator extends AbstractProjectCon String source = null, target = null; - for(MojoExecution execution : request.getMavenProjectFacade().getMojoExecutions(COMPILER_PLUGIN_GROUP_ID, - COMPILER_PLUGIN_ARTIFACT_ID, monitor, GOAL_COMPILE, GOAL_TESTCOMPILE)) { - + for(MojoExecution execution : getCompilerMojoExecutions(request, monitor)) { source = getCompilerLevel(mavenSession, execution, "source", source, SOURCES); //$NON-NLS-1$ target = getCompilerLevel(mavenSession, execution, "target", target, TARGETS); //$NON-NLS-1$ - } if(source == null) { @@ -434,6 +443,12 @@ public abstract class AbstractJavaProjectConfigurator extends AbstractProjectCon options.put(JavaCore.COMPILER_PB_FORBIDDEN_REFERENCE, "warning"); //$NON-NLS-1$ } + protected List<MojoExecution> getCompilerMojoExecutions(ProjectConfigurationRequest request, IProgressMonitor monitor) + throws CoreException { + return request.getMavenProjectFacade().getMojoExecutions(COMPILER_PLUGIN_GROUP_ID, + COMPILER_PLUGIN_ARTIFACT_ID, monitor, GOAL_COMPILE, GOAL_TESTCOMPILE); + } + private String getCompilerLevel(MavenSession session, MojoExecution execution, String parameter, String source, List<String> levels) { int levelIdx = getLevelIndex(source, levels); |