clean up eclipse plugin exception handling

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@314944 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Brett Leslie Porter 2005-10-12 15:21:42 +00:00
parent 1c6a04a831
commit 14db4338c1
6 changed files with 62 additions and 83 deletions

View File

@ -22,6 +22,7 @@ import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
import org.apache.maven.artifact.resolver.ArtifactResolver;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.logging.Log;
import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.util.IOUtil;
@ -61,7 +62,7 @@ public class EclipseClasspathWriter
EclipseSourceDir[] sourceDirs, List classpathContainers, ArtifactRepository localRepository,
ArtifactResolver artifactResolver, ArtifactFactory artifactFactory,
List remoteArtifactRepositories, boolean downloadSources, String outputDirectory )
throws EclipsePluginException
throws MojoExecutionException
{
FileWriter w;
@ -72,7 +73,7 @@ public class EclipseClasspathWriter
}
catch ( IOException ex )
{
throw new EclipsePluginException( Messages.getString( "EclipsePlugin.erroropeningfile" ),
throw new MojoExecutionException( Messages.getString( "EclipsePlugin.erroropeningfile" ),
ex ); //$NON-NLS-1$
}
@ -156,7 +157,7 @@ public class EclipseClasspathWriter
ArtifactRepository localRepository, ArtifactResolver artifactResolver,
ArtifactFactory artifactFactory, List remoteArtifactRepositories,
boolean downloadSources )
throws EclipsePluginException
throws MojoExecutionException
{
String path;
@ -228,7 +229,7 @@ public class EclipseClasspathWriter
private Artifact retrieveSourceArtifact( Artifact artifact, List remoteArtifactRepositories,
ArtifactRepository localRepository, ArtifactResolver artifactResolver,
ArtifactFactory artifactFactory )
throws EclipsePluginException
throws MojoExecutionException
{
// source artifact: use the "sources" classifier added by the source plugin
Artifact sourceArtifact = artifactFactory.createArtifactWithClassifier( artifact.getGroupId(),
@ -253,7 +254,7 @@ public class EclipseClasspathWriter
}
catch ( ArtifactResolutionException e )
{
throw new EclipsePluginException( "Error getting soruce artifact", e );
throw new MojoExecutionException( "Error getting source artifact", e );
}
return sourceArtifact;

View File

@ -21,6 +21,7 @@ import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.resolver.ArtifactResolver;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.project.MavenProject;
import java.io.File;
@ -262,9 +263,8 @@ public class EclipsePlugin
* @see org.apache.maven.plugin.Mojo#execute()
*/
public void execute()
throws MojoExecutionException
throws MojoExecutionException, MojoFailureException
{
if ( executedProject == null )
{
// backwards compat with alpha-2 only
@ -332,7 +332,7 @@ public class EclipsePlugin
}
public void write()
throws EclipsePluginException
throws MojoExecutionException
{
File projectBaseDir = executedProject.getFile().getParentFile();
@ -340,12 +340,14 @@ public class EclipsePlugin
List reactorArtifacts = EclipseUtils.resolveReactorArtifacts( project, reactorProjects );
// build a list of UNIQUE source dirs (both src and resources) to be used in classpath and wtpmodules
EclipseSourceDir[] sourceDirs = EclipseUtils.buildDirectoryList( executedProject, outputDir, getLog(), outputDirectory );
EclipseSourceDir[] sourceDirs =
EclipseUtils.buildDirectoryList( executedProject, outputDir, getLog(), outputDirectory );
// use project since that one has all artifacts resolved.
new EclipseClasspathWriter( getLog() ).write( projectBaseDir, outputDir, project, reactorArtifacts, sourceDirs,
classpathContainers, localRepository, artifactResolver,
artifactFactory, remoteArtifactRepositories, downloadSources, outputDirectory );
artifactFactory, remoteArtifactRepositories, downloadSources,
outputDirectory );
new EclipseProjectWriter( getLog() ).write( projectBaseDir, outputDir, project, executedProject,
reactorArtifacts, projectnatures, buildcommands );
@ -360,11 +362,11 @@ public class EclipsePlugin
}
private void assertNotEmpty( String string, String elementName )
throws EclipsePluginException
throws MojoFailureException
{
if ( string == null )
{
throw new EclipsePluginException(
throw new MojoFailureException(
Messages.getString( "EclipsePlugin.missingelement", elementName ) ); //$NON-NLS-1$
}
}
@ -374,7 +376,8 @@ public class EclipsePlugin
this.downloadSources = downloadSources;
}
public void setOutputDirectory(String outputDirectory) {
public void setOutputDirectory( String outputDirectory )
{
this.outputDirectory = outputDirectory;
}
}

View File

@ -1,37 +0,0 @@
package org.apache.maven.plugin.eclipse;
/*
* Copyright 2001-2005 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import org.apache.maven.plugin.MojoExecutionException;
/**
* @author <a href="mailto:trygvis@inamo.no">Trygve Laugst&oslash;l</a>
* @version $Id$
*/
public class EclipsePluginException
extends MojoExecutionException
{
public EclipsePluginException( String msg )
{
super( msg );
}
public EclipsePluginException( String msg, Throwable cause )
{
super( msg, cause );
}
}

View File

@ -16,22 +16,24 @@ package org.apache.maven.plugin.eclipse;
* limitations under the License.
*/
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Iterator;
import java.util.List;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.model.Resource;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.logging.Log;
import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.util.IOUtil;
import org.codehaus.plexus.util.xml.PrettyPrintXMLWriter;
import org.codehaus.plexus.util.xml.XMLWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Iterator;
import java.util.List;
/**
* Writes eclipse .project file.
*
* @author <a href="mailto:trygvis@inamo.no">Trygve Laugst&oslash;l</a>
* @author <a href="mailto:kenney@neonics.com">Kenney Westerhof</a>
* @author <a href="mailto:fgiust@users.sourceforge.net">Fabrizio Giustina</a>
@ -48,8 +50,8 @@ public class EclipseProjectWriter
}
protected void write( File projectBaseDir, File basedir, MavenProject project, MavenProject executedProject,
List reactorArtifacts, List projectnatures, List buildCommands )
throws EclipsePluginException
List reactorArtifacts, List projectnatures, List buildCommands )
throws MojoExecutionException
{
FileWriter w;
@ -59,7 +61,8 @@ public class EclipseProjectWriter
}
catch ( IOException ex )
{
throw new EclipsePluginException( Messages.getString( "EclipsePlugin.erroropeningfile" ), ex ); //$NON-NLS-1$
throw new MojoExecutionException( Messages.getString( "EclipsePlugin.erroropeningfile" ),
ex ); //$NON-NLS-1$
}
XMLWriter writer = new PrettyPrintXMLWriter( w );

View File

@ -16,15 +16,16 @@ package org.apache.maven.plugin.eclipse;
* limitations under the License.
*/
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.logging.Log;
import org.apache.maven.project.MavenProject;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Properties;
import org.apache.maven.plugin.logging.Log;
import org.apache.maven.project.MavenProject;
/**
* @author <a href="mailto:trygvis@inamo.no">Trygve Laugst&oslash;l</a>
* @author <a href="mailto:kenney@neonics.com">Kenney Westerhof</a>
@ -42,22 +43,24 @@ public class EclipseSettingsWriter
}
protected void write( File projectBaseDir, File outputDir, MavenProject project )
throws EclipsePluginException
throws MojoExecutionException
{
// check if it's necessary to create project specific settings
Properties coreSettings = new Properties();
String source = EclipseUtils.getPluginSetting( project, "maven-compiler-plugin", "source", null ); //$NON-NLS-1$ //$NON-NLS-2$
String target = EclipseUtils.getPluginSetting( project, "maven-compiler-plugin", "target", null ); //$NON-NLS-1$ //$NON-NLS-2$
String source = EclipseUtils.getPluginSetting( project, "maven-compiler-plugin", "source",
null ); //$NON-NLS-1$ //$NON-NLS-2$
String target = EclipseUtils.getPluginSetting( project, "maven-compiler-plugin", "target",
null ); //$NON-NLS-1$ //$NON-NLS-2$
if ( source != null && !source.equals( "1.3" ) ) //$NON-NLS-1$
if ( source != null && !"1.3".equals( source ) ) //$NON-NLS-1$
{
coreSettings.put( "org.eclipse.jdt.core.compiler.source", source ); //$NON-NLS-1$
coreSettings.put( "org.eclipse.jdt.core.compiler.compliance", source ); //$NON-NLS-1$
}
if ( target != null && !target.equals( "1.2" ) ) //$NON-NLS-1$
if ( target != null && !"1.2".equals( target ) ) //$NON-NLS-1$
{
coreSettings.put( "org.eclipse.jdt.core.compiler.codegen.targetPlatform", target ); //$NON-NLS-1$
}
@ -81,11 +84,13 @@ public class EclipseSettingsWriter
}
catch ( FileNotFoundException e )
{
throw new EclipsePluginException( Messages.getString( "EclipseSettingsWriter.cannotcreatesettings" ), e ); //$NON-NLS-1$
throw new MojoExecutionException( Messages.getString( "EclipseSettingsWriter.cannotcreatesettings" ),
e ); //$NON-NLS-1$
}
catch ( IOException e )
{
throw new EclipsePluginException( Messages.getString( "EclipseSettingsWriter.errorwritingsettings" ), e ); //$NON-NLS-1$
throw new MojoExecutionException( Messages.getString( "EclipseSettingsWriter.errorwritingsettings" ),
e ); //$NON-NLS-1$
}
}
else

View File

@ -16,14 +16,9 @@ package org.apache.maven.plugin.eclipse;
* limitations under the License.
*/
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Iterator;
import java.util.List;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.logging.Log;
import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.util.IOUtil;
@ -31,8 +26,15 @@ import org.codehaus.plexus.util.StringUtils;
import org.codehaus.plexus.util.xml.PrettyPrintXMLWriter;
import org.codehaus.plexus.util.xml.XMLWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Iterator;
import java.util.List;
/**
* Writes eclipse .wtpmodules file.
*
* @author <a href="mailto:fgiust@users.sourceforge.net">Fabrizio Giustina</a>
* @version $Id$
*/
@ -47,8 +49,8 @@ public class EclipseWtpmodulesWriter
}
protected void write( File basedir, MavenProject project, List referencedReactorArtifacts,
EclipseSourceDir[] sourceDirs, ArtifactRepository localRepository )
throws EclipsePluginException
EclipseSourceDir[] sourceDirs, ArtifactRepository localRepository )
throws MojoExecutionException
{
FileWriter w;
@ -58,7 +60,8 @@ public class EclipseWtpmodulesWriter
}
catch ( IOException ex )
{
throw new EclipsePluginException( Messages.getString( "EclipsePlugin.erroropeningfile" ), ex ); //$NON-NLS-1$
throw new MojoExecutionException( Messages.getString( "EclipsePlugin.erroropeningfile" ),
ex ); //$NON-NLS-1$
}
XMLWriter writer = new PrettyPrintXMLWriter( w );
@ -173,7 +176,7 @@ public class EclipseWtpmodulesWriter
}
private void writeWarSpecificResources( XMLWriter writer, File basedir, MavenProject project,
List referencedReactorArtifacts, ArtifactRepository localRepository )
List referencedReactorArtifacts, ArtifactRepository localRepository )
{
String warSourceDirectory = EclipseUtils.getPluginSetting( project, "maven-war-plugin", //$NON-NLS-1$
@ -195,7 +198,7 @@ public class EclipseWtpmodulesWriter
}
private void addDependency( XMLWriter writer, Artifact artifact, List referencedReactorProjects,
ArtifactRepository localRepository )
ArtifactRepository localRepository )
{
String handle;
@ -205,7 +208,8 @@ public class EclipseWtpmodulesWriter
// <dependency-type>uses</dependency-type>
// </dependent-module>
handle = "module:/resource/" + artifact.getArtifactId() + "/" + artifact.getArtifactId(); //$NON-NLS-1$ //$NON-NLS-2$
handle = "module:/resource/" + artifact.getArtifactId() + "/" +
artifact.getArtifactId(); //$NON-NLS-1$ //$NON-NLS-2$
}
else
{