Fixing a couple of issues actually reported against the m1/m2 plugin:

MPECLIPSE-102 Running 'maven:eclipse' turns CheckStyle off for the project.
MPECLIPSE-106 Eclipse loses Sysdeo "Is Tomcat Project" setting after mvn eclipse:eclipse

existing .project files are parsed and additional natures/builders are preserved. Running eclipse:clean will remove existing settings and start from scratch

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@332376 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Fabrizio Giustina 2005-11-10 21:27:12 +00:00
parent b91ab29a07
commit e6aedd7d5d
3 changed files with 89 additions and 13 deletions

View File

@ -197,9 +197,11 @@ public class EclipseClasspathWriter
throw new MojoExecutionException( message, e ); throw new MojoExecutionException( message, e );
} }
log.info( Messages.getString( "EclipsePlugin.artifactissystemscoped", //$NON-NLS-1$ if ( log.isDebugEnabled() )
new Object[] { artifact.getArtifactId(), path } ) ); {
log.debug( Messages.getString( "EclipsePlugin.artifactissystemscoped", //$NON-NLS-1$
new Object[] { artifact.getArtifactId(), path } ) );
}
log.info( Messages.getString( "EclipseClasspathWriter.sourcesnotavailable", //$NON-NLS-1$ log.info( Messages.getString( "EclipseClasspathWriter.sourcesnotavailable", //$NON-NLS-1$
artifact.getArtifactId() ) ); artifact.getArtifactId() ) );

View File

@ -16,6 +16,15 @@ package org.apache.maven.plugin.eclipse;
* limitations under the License. * limitations under the License.
*/ */
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
import org.apache.maven.artifact.Artifact; import org.apache.maven.artifact.Artifact;
import org.apache.maven.model.Resource; import org.apache.maven.model.Resource;
import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoExecutionException;
@ -24,12 +33,9 @@ import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.util.IOUtil; import org.codehaus.plexus.util.IOUtil;
import org.codehaus.plexus.util.xml.PrettyPrintXMLWriter; import org.codehaus.plexus.util.xml.PrettyPrintXMLWriter;
import org.codehaus.plexus.util.xml.XMLWriter; import org.codehaus.plexus.util.xml.XMLWriter;
import org.codehaus.plexus.util.xml.Xpp3Dom;
import java.io.File; import org.codehaus.plexus.util.xml.Xpp3DomBuilder;
import java.io.FileWriter; import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
import java.io.IOException;
import java.util.Iterator;
import java.util.List;
/** /**
* Writes eclipse .project file. * Writes eclipse .project file.
@ -50,19 +56,85 @@ public class EclipseProjectWriter
} }
protected void write( File projectBaseDir, File basedir, MavenProject project, MavenProject executedProject, protected void write( File projectBaseDir, File basedir, MavenProject project, MavenProject executedProject,
List reactorArtifacts, List projectnatures, List buildCommands ) List reactorArtifacts, List addedProjectnatures, List addedBuildCommands )
throws MojoExecutionException throws MojoExecutionException
{ {
Set projectnatures = new LinkedHashSet();
Set buildCommands = new LinkedHashSet();
File dotProject = new File( basedir, ".project" );
if ( dotProject.exists() )
{
log.info( Messages.getString( "EclipsePlugin.keepexisting", dotProject.getAbsolutePath() ) ); //$NON-NLS-1$
// parse existing file in order to keep manually-added entries
FileReader reader = null;
try
{
reader = new FileReader( dotProject );
Xpp3Dom dom = Xpp3DomBuilder.build( reader );
Xpp3Dom naturesElement = dom.getChild( "natures" );
if ( naturesElement != null )
{
Xpp3Dom[] existingNatures = naturesElement.getChildren( "nature" );
for ( int j = 0; j < existingNatures.length; j++ )
{
// adds all the existing natures
projectnatures.add( existingNatures[j].getValue() );
}
}
Xpp3Dom buildSpec = dom.getChild( "buildSpec" );
if ( buildSpec != null )
{
Xpp3Dom[] existingBuildCommands = buildSpec.getChildren( "buildCommand" );
for ( int j = 0; j < existingBuildCommands.length; j++ )
{
Xpp3Dom buildCommandName = existingBuildCommands[j].getChild( "name" );
if ( buildCommandName != null )
{
buildCommands.add( buildCommandName.getValue() );
}
}
}
}
catch ( XmlPullParserException e )
{
log.warn( Messages.getString( "EclipsePlugin.cantparseexisting", dotProject.getAbsolutePath() ) ); //$NON-NLS-1$
}
catch ( IOException e )
{
log.warn( Messages.getString( "EclipsePlugin.cantparseexisting", dotProject.getAbsolutePath() ) ); //$NON-NLS-1$
}
finally
{
IOUtil.close( reader );
}
}
// adds new entries after the existing ones
for ( Iterator iter = addedProjectnatures.iterator(); iter.hasNext(); )
{
projectnatures.add( iter.next() );
}
for ( Iterator iter = addedBuildCommands.iterator(); iter.hasNext(); )
{
buildCommands.add( iter.next() );
}
FileWriter w; FileWriter w;
try try
{ {
w = new FileWriter( new File( basedir, ".project" ) ); //$NON-NLS-1$ w = new FileWriter( dotProject ); //$NON-NLS-1$
} }
catch ( IOException ex ) catch ( IOException ex )
{ {
throw new MojoExecutionException( Messages.getString( "EclipsePlugin.erroropeningfile" ), throw new MojoExecutionException( Messages.getString( "EclipsePlugin.erroropeningfile" ), ex ); //$NON-NLS-1$
ex ); //$NON-NLS-1$
} }
XMLWriter writer = new PrettyPrintXMLWriter( w ); XMLWriter writer = new PrettyPrintXMLWriter( w );

View File

@ -6,6 +6,8 @@ EclipsePlugin.erroropeningfile=Exception while opening file.
EclipsePlugin.cantcanonicalize=Can''t canonicalize system path: {0} EclipsePlugin.cantcanonicalize=Can''t canonicalize system path: {0}
EclipsePlugin.cantwritetofile=Unable to write to file: {0} EclipsePlugin.cantwritetofile=Unable to write to file: {0}
EclipsePlugin.cantreadfile=Unable to read file: {0} EclipsePlugin.cantreadfile=Unable to read file: {0}
EclipsePlugin.keepexisting=File {0} already exists.\n Additional settings will be preserved, run mvn eclipse:clean if you want old settings to be removed.
EclipsePlugin.cantparseexisting=Unable to parse existing file: {0}. Settings will not be preserved.
EclipsePlugin.cantresolvesources=Cannot resolve source artifact. Artifact id: {0} (Message: {1}) EclipsePlugin.cantresolvesources=Cannot resolve source artifact. Artifact id: {0} (Message: {1})
EclipsePlugin.errorresolvingsources=Error resolving 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}. EclipsePlugin.wrote=Wrote Eclipse project for "{0}" to {1}.