You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by fg...@apache.org on 2005/10/30 16:06:12 UTC
svn commit: r329579 - in
/maven/components/trunk/maven-plugins/maven-eclipse-plugin/src/main:
java/org/apache/maven/plugin/eclipse/AddMavenRepoMojo.java
resources/org/apache/maven/plugin/eclipse/messages.properties
Author: fgiust
Date: Sun Oct 30 07:06:04 2005
New Revision: 329579
URL: http://svn.apache.org/viewcvs?rev=329579&view=rev
Log:
add-maven-repo was overwriting all the existing eclipse settins.
Fixed to preserve existing properties and only add/update the M2_REPO var
Modified:
maven/components/trunk/maven-plugins/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/AddMavenRepoMojo.java
maven/components/trunk/maven-plugins/maven-eclipse-plugin/src/main/resources/org/apache/maven/plugin/eclipse/messages.properties
Modified: maven/components/trunk/maven-plugins/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/AddMavenRepoMojo.java
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-plugins/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/AddMavenRepoMojo.java?rev=329579&r1=329578&r2=329579&view=diff
==============================================================================
--- maven/components/trunk/maven-plugins/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/AddMavenRepoMojo.java (original)
+++ maven/components/trunk/maven-plugins/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/AddMavenRepoMojo.java Sun Oct 30 07:06:04 2005
@@ -16,10 +16,14 @@
* limitations under the License.
*/
-
import java.io.File;
-import java.io.FileWriter;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
import java.io.IOException;
+import java.io.OutputStream;
+import java.util.Properties;
+
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
@@ -29,7 +33,8 @@
*
* @goal add-maven-repo
*/
-public class AddMavenRepoMojo extends AbstractMojo
+public class AddMavenRepoMojo
+ extends AbstractMojo
{
/**
* Location of the <code>Eclipse</code> workspace that holds your configuration and source.
@@ -42,7 +47,7 @@
* @required
*/
private String workspace;
-
+
/**
* @parameter expression="${localRepository}"
* @required
@@ -50,28 +55,48 @@
*/
private ArtifactRepository localRepository;
- public void execute() throws MojoExecutionException
+ public void execute()
+ throws MojoExecutionException
{
-
- File workDir = new File( workspace, ".metadata/.plugins/org.eclipse.core.runtime/.settings" );
-
+
+ File workDir = new File( workspace, ".metadata/.plugins/org.eclipse.core.runtime/.settings" ); //$NON-NLS-1$
workDir.mkdirs();
-
- File f = new File( workDir.getAbsolutePath(), "org.eclipse.jdt.core.prefs" );
-
- try
+
+ Properties props = new Properties();
+
+ File f = new File( workDir.getAbsolutePath(), "org.eclipse.jdt.core.prefs" ); //$NON-NLS-1$
+
+ // preserve old settings
+ if ( f.exists() )
{
- FileWriter fWriter = new FileWriter( f );
-
- fWriter.write( "\norg.eclipse.jdt.core.classpathVariable.M2_REPO=" + localRepository.getBasedir() );
+ try
+ {
+ props.load( new FileInputStream( f ) );
+ }
+ catch ( FileNotFoundException e )
+ {
+ throw new MojoExecutionException( Messages
+ .getString( "EclipsePlugin.cantreadfile", f.getAbsolutePath() ), e ); //$NON-NLS-1$
+ }
+ catch ( IOException e )
+ {
+ throw new MojoExecutionException( Messages
+ .getString( "EclipsePlugin.cantreadfile", f.getAbsolutePath() ), e ); //$NON-NLS-1$
+ }
+ }
- fWriter.flush();
+ props.put( "\norg.eclipse.jdt.core.classpathVariable.M2_REPO", localRepository.getBasedir() ); //$NON-NLS-1$
- fWriter.close();
+ try
+ {
+ OutputStream os = new FileOutputStream( f );
+ props.store( os, null );
+ os.close();
}
- catch( IOException ioe )
+ catch ( IOException ioe )
{
- throw new MojoExecutionException( "Unable to write to file: " + f.getAbsolutePath() );
+ throw new MojoExecutionException( Messages.getString( "EclipsePlugin.cantwritetofile", //$NON-NLS-1$
+ f.getAbsolutePath() ) );
}
}
}
Modified: maven/components/trunk/maven-plugins/maven-eclipse-plugin/src/main/resources/org/apache/maven/plugin/eclipse/messages.properties
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-plugins/maven-eclipse-plugin/src/main/resources/org/apache/maven/plugin/eclipse/messages.properties?rev=329579&r1=329578&r2=329579&view=diff
==============================================================================
--- maven/components/trunk/maven-plugins/maven-eclipse-plugin/src/main/resources/org/apache/maven/plugin/eclipse/messages.properties (original)
+++ maven/components/trunk/maven-plugins/maven-eclipse-plugin/src/main/resources/org/apache/maven/plugin/eclipse/messages.properties Sun Oct 30 07:06:04 2005
@@ -4,6 +4,8 @@
EclipsePlugin.cantcreatedir=Can''t create directory "{0}"
EclipsePlugin.erroropeningfile=Exception while opening file.
EclipsePlugin.cantcanonicalize=Can''t canonicalize system path: {0}
+EclipsePlugin.cantwritetofile=Unable to write to file: {0}
+EclipsePlugin.cantreadfile=Unable to read file: {0}
EclipsePlugin.cantresolvesources=Cannot resolve source artifact. Artifact id: {0} (Message: {1})
EclipsePlugin.errorresolvingsources=Error resolving source artifact. Artifact id: {0} (Message: {1})
EclipsePlugin.wrote=Wrote Eclipse project for "{0}" to {1}.