Author: fgiust Date: Sat Dec 16 11:29:12 2006 New Revision: 487861 URL: http://svn.apache.org/viewvc?view=rev&rev=487861 Log: small enhancement to the detecting of compiler settings when a different java version is used for test sources
Added: maven/plugins/trunk/maven-eclipse-plugin/src/test/resources/projects/project-26/ maven/plugins/trunk/maven-eclipse-plugin/src/test/resources/projects/project-26/expected/ maven/plugins/trunk/maven-eclipse-plugin/src/test/resources/projects/project-26/pom.xml (with props) maven/plugins/trunk/maven-eclipse-plugin/src/test/resources/projects/project-26/src/ maven/plugins/trunk/maven-eclipse-plugin/src/test/resources/projects/project-26/src/main/ maven/plugins/trunk/maven-eclipse-plugin/src/test/resources/projects/project-26/src/main/java/ maven/plugins/trunk/maven-eclipse-plugin/src/test/resources/projects/project-26/src/main/java/PlaceHolder.java (with props) Modified: maven/plugins/trunk/maven-eclipse-plugin/ (props changed) maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/writers/AbstractWtpResourceWriter.java maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/writers/EclipseSettingsWriter.java maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/ide/IdeUtils.java maven/plugins/trunk/maven-eclipse-plugin/src/test/java/org/apache/maven/plugin/eclipse/EclipsePluginTest.java Propchange: maven/plugins/trunk/maven-eclipse-plugin/ ------------------------------------------------------------------------------ --- svn:ignore (original) +++ svn:ignore Sat Dec 16 11:29:12 2006 @@ -1,8 +1,9 @@ -target -*.iml -.wtpmodules -.project -.classpath -.settings -.deployables -*.ser +target +*.iml +.wtpmodules +.project +.classpath +.settings +.deployables +*.ser +pom-test.xml Modified: maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/writers/AbstractWtpResourceWriter.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/writers/AbstractWtpResourceWriter.java?view=diff&rev=487861&r1=487860&r2=487861 ============================================================================== --- maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/writers/AbstractWtpResourceWriter.java (original) +++ maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/writers/AbstractWtpResourceWriter.java Sat Dec 16 11:29:12 2006 @@ -277,10 +277,10 @@ protected String resolveJavaVersion() { - String version = IdeUtils.getPluginSetting( config.getProject(), "maven-compiler-plugin", "target", null ); //$NON-NLS-1$ //$NON-NLS-2$ + String version = IdeUtils.getCompilerTargetVersion( config.getProject() ); if ( version == null ) { - IdeUtils.getPluginSetting( config.getProject(), "maven-compiler-plugin", "source", null ); //$NON-NLS-1$ //$NON-NLS-2$ + IdeUtils.getCompilerSourceVersion( config.getProject() ); } if ( "1.5".equals( version ) || "5".equals( version ) ) //$NON-NLS-1$ //$NON-NLS-2$ Modified: maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/writers/EclipseSettingsWriter.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/writers/EclipseSettingsWriter.java?view=diff&rev=487861&r1=487860&r2=487861 ============================================================================== --- maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/writers/EclipseSettingsWriter.java (original) +++ maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/writers/EclipseSettingsWriter.java Sat Dec 16 11:29:12 2006 @@ -39,16 +39,6 @@ extends AbstractEclipseWriter { - /** - * 'target' property for maven-compiler-plugin. - */ - private static final String PROPERTY_TARGET = "target"; //$NON-NLS-1$ - - /** - * 'source' property for maven-compiler-plugin. - */ - private static final String PROPERTY_SOURCE = "source"; //$NON-NLS-1$ - private static final String JDK_1_2_SOURCES = "1.2"; //$NON-NLS-1$ private static final String FILE_ECLIPSE_JDT_CORE_PREFS = "org.eclipse.jdt.core.prefs"; //$NON-NLS-1$ @@ -61,8 +51,6 @@ private static final String PROP_JDT_CORE_COMPILER_SOURCE = "org.eclipse.jdt.core.compiler.source"; //$NON-NLS-1$ - private static final String ARTIFACT_MAVEN_COMPILER_PLUGIN = "maven-compiler-plugin"; //$NON-NLS-1$ - /** * @see org.apache.maven.plugin.eclipse.writers.EclipseWriter#write() */ @@ -73,10 +61,8 @@ // check if it's necessary to create project specific settings Properties coreSettings = new Properties(); - String source = IdeUtils.getPluginSetting( config.getProject(), ARTIFACT_MAVEN_COMPILER_PLUGIN, - PROPERTY_SOURCE, null ); - String target = IdeUtils.getPluginSetting( config.getProject(), ARTIFACT_MAVEN_COMPILER_PLUGIN, - PROPERTY_TARGET, null ); + String source = IdeUtils.getCompilerSourceVersion( config.getProject() ); + String target = IdeUtils.getCompilerTargetVersion( config.getProject() ); if ( source != null ) { Modified: maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/ide/IdeUtils.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/ide/IdeUtils.java?view=diff&rev=487861&r1=487860&r2=487861 ============================================================================== --- maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/ide/IdeUtils.java (original) +++ maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/ide/IdeUtils.java Sat Dec 16 11:29:12 2006 @@ -31,6 +31,7 @@ import org.apache.maven.artifact.resolver.ArtifactResolutionException; import org.apache.maven.artifact.resolver.ArtifactResolver; import org.apache.maven.model.Plugin; +import org.apache.maven.model.PluginExecution; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.logging.Log; import org.apache.maven.project.MavenProject; @@ -44,6 +45,20 @@ */ public class IdeUtils { + /** + * compiler plugin id. + */ + private static final String ARTIFACT_MAVEN_COMPILER_PLUGIN = "maven-compiler-plugin"; //$NON-NLS-1$ + + /** + * 'target' property for maven-compiler-plugin. + */ + private static final String PROPERTY_TARGET = "target"; //$NON-NLS-1$ + + /** + * 'source' property for maven-compiler-plugin. + */ + private static final String PROPERTY_SOURCE = "source"; //$NON-NLS-1$ private IdeUtils() { @@ -183,4 +198,69 @@ } return null; } + + /** + * Returns the target version configured for the compiler plugin. Returns the minimum version required to compile + * both standard and test sources, if settings are different. + * @param project maven project + * @return java target version + */ + public static String getCompilerTargetVersion( MavenProject project ) + { + return IdeUtils.getCompilerPluginSetting( project, PROPERTY_TARGET ); + } + + /** + * Returns the source version configured for the compiler plugin. Returns the minimum version required to compile + * both standard and test sources, if settings are different. + * @param project maven project + * @return java source version + */ + public static String getCompilerSourceVersion( MavenProject project ) + { + return IdeUtils.getCompilerPluginSetting( project, PROPERTY_SOURCE ); + } + + /** + * Returns a compiler plugin settings, considering also settings altered in plugin executions . + * @param project maven project + * @return option value (may be null) + */ + public static String getCompilerPluginSetting( MavenProject project, String optionName ) + { + String value = null; + + for ( Iterator it = project.getModel().getBuild().getPlugins().iterator(); it.hasNext(); ) + { + Plugin plugin = (Plugin) it.next(); + + if ( plugin.getArtifactId().equals( ARTIFACT_MAVEN_COMPILER_PLUGIN ) ) + { + Xpp3Dom o = (Xpp3Dom) plugin.getConfiguration(); + + // this is the default setting + if ( o != null && o.getChild( optionName ) != null ) + { + value = o.getChild( optionName ).getValue(); + } + + List executions = plugin.getExecutions(); + + // a different source/target version can be configured for test sources compilation + for ( Iterator iter = executions.iterator(); iter.hasNext(); ) + { + PluginExecution execution = (PluginExecution) iter.next(); + o = (Xpp3Dom) execution.getConfiguration(); + + if ( o != null && o.getChild( optionName ) != null ) + { + value = o.getChild( optionName ).getValue(); + } + } + } + } + + return value; + } + } Modified: maven/plugins/trunk/maven-eclipse-plugin/src/test/java/org/apache/maven/plugin/eclipse/EclipsePluginTest.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-eclipse-plugin/src/test/java/org/apache/maven/plugin/eclipse/EclipsePluginTest.java?view=diff&rev=487861&r1=487860&r2=487861 ============================================================================== --- maven/plugins/trunk/maven-eclipse-plugin/src/test/java/org/apache/maven/plugin/eclipse/EclipsePluginTest.java (original) +++ maven/plugins/trunk/maven-eclipse-plugin/src/test/java/org/apache/maven/plugin/eclipse/EclipsePluginTest.java Sat Dec 16 11:29:12 2006 @@ -245,4 +245,14 @@ testProject( "project-25" ); } + /** + * Test different compiler settings for test sources. + * @throws Exception any exception thrown during test + */ + public void testProject26() + throws Exception + { + testProject( "project-26" ); + } + } Added: maven/plugins/trunk/maven-eclipse-plugin/src/test/resources/projects/project-26/pom.xml URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-eclipse-plugin/src/test/resources/projects/project-26/pom.xml?view=auto&rev=487861 ============================================================================== --- maven/plugins/trunk/maven-eclipse-plugin/src/test/resources/projects/project-26/pom.xml (added) +++ maven/plugins/trunk/maven-eclipse-plugin/src/test/resources/projects/project-26/pom.xml Sat Dec 16 11:29:12 2006 @@ -0,0 +1,42 @@ +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <modelVersion>4.0.0</modelVersion> + <groupId>eclipse</groupId> + <artifactId>maven-eclipse-plugin-test-project-26</artifactId> + <version>26</version> + <name>maven-eclipse-plugin-test-project-26</name> + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-compiler-plugin</artifactId> + <version>2.0</version> + <configuration> + <source>1.4</source> + <target>1.4</target> + </configuration> + <executions> + <execution> + <id>compile-tests</id> + <phase>process-test-sources</phase> + <goals> + <goal>testCompile</goal> + </goals> + <configuration> + <source>1.5</source> + <target>1.5</target> + </configuration> + </execution> + </executions> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-eclipse-plugin</artifactId> + <version>test</version> + <configuration> + <wtpversion>1.5</wtpversion> + </configuration> + </plugin> + </plugins> + </build> +</project> Propchange: maven/plugins/trunk/maven-eclipse-plugin/src/test/resources/projects/project-26/pom.xml ------------------------------------------------------------------------------ svn:eol-style = native Propchange: maven/plugins/trunk/maven-eclipse-plugin/src/test/resources/projects/project-26/pom.xml ------------------------------------------------------------------------------ svn:mime-type = text/xml Added: maven/plugins/trunk/maven-eclipse-plugin/src/test/resources/projects/project-26/src/main/java/PlaceHolder.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-eclipse-plugin/src/test/resources/projects/project-26/src/main/java/PlaceHolder.java?view=auto&rev=487861 ============================================================================== (empty) Propchange: maven/plugins/trunk/maven-eclipse-plugin/src/test/resources/projects/project-26/src/main/java/PlaceHolder.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: maven/plugins/trunk/maven-eclipse-plugin/src/test/resources/projects/project-26/src/main/java/PlaceHolder.java ------------------------------------------------------------------------------ svn:keywords = Author Date Id Revision Propchange: maven/plugins/trunk/maven-eclipse-plugin/src/test/resources/projects/project-26/src/main/java/PlaceHolder.java ------------------------------------------------------------------------------ svn:mime-type = text/plain