| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
|
| 18 | |
|
| 19 | |
package org.apache.maven.plugin.eclipse.writers; |
| 20 | |
|
| 21 | |
import java.io.File; |
| 22 | |
import java.io.FileInputStream; |
| 23 | |
import java.io.FileNotFoundException; |
| 24 | |
import java.io.FileOutputStream; |
| 25 | |
import java.io.IOException; |
| 26 | |
import java.util.Properties; |
| 27 | |
|
| 28 | |
import org.apache.maven.plugin.MojoExecutionException; |
| 29 | |
import org.apache.maven.plugin.eclipse.Messages; |
| 30 | |
import org.apache.maven.plugin.ide.IdeUtils; |
| 31 | |
|
| 32 | |
|
| 33 | |
|
| 34 | |
|
| 35 | |
|
| 36 | |
|
| 37 | |
|
| 38 | 0 | public class EclipseSettingsWriter |
| 39 | |
extends AbstractEclipseWriter |
| 40 | |
{ |
| 41 | |
|
| 42 | |
private static final String JDK_1_2_SOURCES = "1.2"; |
| 43 | |
|
| 44 | |
private static final String FILE_ECLIPSE_JDT_CORE_PREFS = "org.eclipse.jdt.core.prefs"; |
| 45 | |
|
| 46 | |
private static final String PROP_ECLIPSE_PREFERENCES_VERSION = "eclipse.preferences.version"; |
| 47 | |
|
| 48 | |
private static final String DIR_DOT_SETTINGS = ".settings"; |
| 49 | |
|
| 50 | |
private static final String PROP_JDT_CORE_COMPILER_COMPLIANCE = "org.eclipse.jdt.core.compiler.compliance"; |
| 51 | |
|
| 52 | |
private static final String PROP_JDT_CORE_COMPILER_SOURCE = "org.eclipse.jdt.core.compiler.source"; |
| 53 | |
|
| 54 | |
|
| 55 | |
|
| 56 | |
|
| 57 | |
public void write() |
| 58 | |
throws MojoExecutionException |
| 59 | |
{ |
| 60 | |
|
| 61 | |
|
| 62 | 0 | Properties coreSettings = new Properties(); |
| 63 | |
|
| 64 | 0 | String source = IdeUtils.getCompilerSourceVersion( config.getProject() ); |
| 65 | 0 | String target = IdeUtils.getCompilerTargetVersion( config.getProject() ); |
| 66 | |
|
| 67 | 0 | if ( source != null ) |
| 68 | |
{ |
| 69 | 0 | coreSettings.put( PROP_JDT_CORE_COMPILER_SOURCE, source ); |
| 70 | 0 | coreSettings.put( PROP_JDT_CORE_COMPILER_COMPLIANCE, source ); |
| 71 | |
} |
| 72 | |
|
| 73 | 0 | if ( target != null && !JDK_1_2_SOURCES.equals( target ) ) |
| 74 | |
{ |
| 75 | 0 | coreSettings.put( "org.eclipse.jdt.core.compiler.codegen.targetPlatform", target ); |
| 76 | |
} |
| 77 | |
|
| 78 | |
|
| 79 | 0 | if ( !coreSettings.isEmpty() ) |
| 80 | |
{ |
| 81 | 0 | File settingsDir = new File( config.getEclipseProjectDirectory(), DIR_DOT_SETTINGS ); |
| 82 | |
|
| 83 | 0 | settingsDir.mkdirs(); |
| 84 | |
|
| 85 | 0 | coreSettings.put( PROP_ECLIPSE_PREFERENCES_VERSION, "1" ); |
| 86 | |
|
| 87 | |
try |
| 88 | |
{ |
| 89 | |
File oldCoreSettingsFile; |
| 90 | |
|
| 91 | 0 | File coreSettingsFile = new File( settingsDir, FILE_ECLIPSE_JDT_CORE_PREFS ); |
| 92 | |
|
| 93 | 0 | if ( coreSettingsFile.exists() ) |
| 94 | |
{ |
| 95 | 0 | oldCoreSettingsFile = coreSettingsFile; |
| 96 | |
|
| 97 | 0 | Properties oldsettings = new Properties(); |
| 98 | 0 | oldsettings.load( new FileInputStream( oldCoreSettingsFile ) ); |
| 99 | |
|
| 100 | 0 | Properties newsettings = (Properties) oldsettings.clone(); |
| 101 | 0 | newsettings.putAll( coreSettings ); |
| 102 | |
|
| 103 | 0 | if ( !oldsettings.equals( newsettings ) ) |
| 104 | |
{ |
| 105 | 0 | newsettings.store( new FileOutputStream( coreSettingsFile ), null ); |
| 106 | |
} |
| 107 | |
} |
| 108 | |
else |
| 109 | |
{ |
| 110 | 0 | coreSettings.store( new FileOutputStream( coreSettingsFile ), null ); |
| 111 | |
|
| 112 | 0 | log.info( Messages.getString( "EclipseSettingsWriter.wrotesettings", |
| 113 | |
coreSettingsFile.getCanonicalPath() ) ); |
| 114 | |
} |
| 115 | |
} |
| 116 | 0 | catch ( FileNotFoundException e ) |
| 117 | |
{ |
| 118 | 0 | throw new MojoExecutionException( Messages.getString( "EclipseSettingsWriter.cannotcreatesettings" ), e ); |
| 119 | |
} |
| 120 | 0 | catch ( IOException e ) |
| 121 | |
{ |
| 122 | 0 | throw new MojoExecutionException( Messages.getString( "EclipseSettingsWriter.errorwritingsettings" ), e ); |
| 123 | 0 | } |
| 124 | |
} |
| 125 | |
else |
| 126 | |
{ |
| 127 | 0 | log.info( Messages.getString( "EclipseSettingsWriter.usingdefaults" ) ); |
| 128 | |
} |
| 129 | 0 | } |
| 130 | |
} |