Author: nicolas Date: Thu Oct 15 08:25:55 2009 New Revision: 825432 URL: http://svn.apache.org/viewvc?rev=825432&view=rev Log: [MECLIPSE-156] Plugin should support setting file encoding
o read maven-compiler-plugin configuration for encoding and generate related .settings configuration for project sources, testSources, resources & testResources Modified: 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 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?rev=825432&r1=825431&r2=825432&view=diff ============================================================================== --- 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 Thu Oct 15 08:25:55 2009 @@ -24,7 +24,10 @@ import java.io.FileOutputStream; import java.io.IOException; import java.util.Properties; +import java.util.Iterator; +import java.util.List; +import org.apache.maven.model.Resource; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.eclipse.Messages; import org.apache.maven.plugin.ide.IdeUtils; @@ -51,6 +54,8 @@ private static final String PROP_JDT_CORE_COMPILER_SOURCE = "org.eclipse.jdt.core.compiler.source"; //$NON-NLS-1$ + private static final String PROP_JDT_CORE_COMPILER_ENCODING = "encoding/"; //$NON-NLS-1$ + /** * @see org.apache.maven.plugin.eclipse.writers.EclipseWriter#write() */ @@ -62,6 +67,7 @@ Properties coreSettings = new Properties(); String source = IdeUtils.getCompilerSourceVersion( config.getProject() ); + String encoding = IdeUtils.getCompilerSourceEncoding( config.getProject() ); String target = IdeUtils.getCompilerTargetVersion( config.getProject() ); if ( source != null ) @@ -69,6 +75,55 @@ coreSettings.put( PROP_JDT_CORE_COMPILER_SOURCE, source ); coreSettings.put( PROP_JDT_CORE_COMPILER_COMPLIANCE, source ); } + + if ( encoding != null ) + { + String basedir = config.getProject().getBasedir().getAbsolutePath(); + List compileSourceRoots = config.getProject().getCompileSourceRoots(); + if ( compileSourceRoots != null ) + { + Iterator it = compileSourceRoots.iterator(); + while ( it.hasNext() ) + { + String sourcePath = (String) it.next(); + String relativePath = sourcePath.substring( basedir.length() ).replace( '\\', '/' ); + coreSettings.put( PROP_JDT_CORE_COMPILER_ENCODING + relativePath, encoding ); + } + } + List testCompileSourceRoots = config.getProject().getTestCompileSourceRoots(); + if ( testCompileSourceRoots != null ) + { + Iterator it = testCompileSourceRoots.iterator(); + while ( it.hasNext() ) + { + String sourcePath = (String) it.next(); + String relativePath = sourcePath.substring( basedir.length() ).replace( '\\', '/' ); + coreSettings.put( PROP_JDT_CORE_COMPILER_ENCODING + relativePath, encoding ); + } + } + List resources = config.getProject().getResources(); + if ( resources != null ) + { + Iterator it = resources.iterator(); + while ( it.hasNext() ) + { + Resource resource = (Resource) it.next(); + String relativePath = resource.getDirectory().substring( basedir.length() ).replace( '\\', '/' ); + coreSettings.put( PROP_JDT_CORE_COMPILER_ENCODING + relativePath, encoding ); + } + } + List testResources = config.getProject().getTestResources(); + if ( testResources != null ) + { + Iterator it = testResources.iterator(); + while ( it.hasNext() ) + { + Resource resource = (Resource) it.next(); + String relativePath = resource.getDirectory().substring( basedir.length() ).replace( '\\', '/' ); + coreSettings.put( PROP_JDT_CORE_COMPILER_ENCODING + relativePath, encoding ); + } + } + } if ( target != null && !JDK_1_2_SOURCES.equals( target ) ) { 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?rev=825432&r1=825431&r2=825432&view=diff ============================================================================== --- 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 Thu Oct 15 08:25:55 2009 @@ -79,6 +79,11 @@ private static final String PROPERTY_SOURCE = "source"; //$NON-NLS-1$ /** + * 'encoding' property for maven-compiler-plugin. + */ + private static final String PROPERTY_ENCODING = "encoding"; //$NON-NLS-1$ + + /** * 'target' property for maven-compiler-plugin. */ private static final String PROPERTY_TARGET = "target"; //$NON-NLS-1$ @@ -173,6 +178,18 @@ } /** + * Returns the source encoding 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 getCompilerSourceEncoding( MavenProject project ) + { + return IdeUtils.getCompilerPluginSetting( project, PROPERTY_ENCODING ); + } + + /** * 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. *