org.apache.maven.plugin.ide
Class AbstractIdeSupportMojo

java.lang.Object
  extended by org.apache.maven.plugin.AbstractMojo
      extended by org.apache.maven.plugin.ide.AbstractIdeSupportMojo
All Implemented Interfaces:
ContextEnabled, Mojo, org.codehaus.plexus.logging.LogEnabled
Direct Known Subclasses:
EclipsePlugin

public abstract class AbstractIdeSupportMojo
extends AbstractMojo
implements org.codehaus.plexus.logging.LogEnabled

Abstract base plugin which takes care of the common stuff usually needed by maven IDE plugins. A plugin extending AbstractIdeSupportMojo should implement the setup() and writeConfiguration() methods, plus the getters needed to get the various configuration flags and required components. The lifecycle:

       *** calls setup() where you can configure your specific stuff and stop the mojo from execute if appropriate ***
       - manually resolve project dependencies, NOT failing if a dependency is missing
       - compute project references (reactor projects) if the getUseProjectReferences() flag is set
       - download sources/javadocs if the getDownloadSources() flag is set
       *** calls writeConfiguration(), passing the list of resolved referenced dependencies ***
       - report the list of missing sources or just tell how to turn this feature on if the flag was disabled
 

Version:
$Id: AbstractIdeSupportMojo.java 1173952 2011-09-22 05:53:22Z baerrach $
Author:
Fabrizio Giustina

Field Summary
protected  ArtifactCollector artifactCollector
          Artifact collector, needed to resolve dependencies.
protected  ArtifactFactory artifactFactory
          Artifact factory, needed to download source jars for inclusion in classpath.
protected  ArtifactMetadataSource artifactMetadataSource
           
protected  ArtifactResolver artifactResolver
          Artifact resolver, needed to download source jars for inclusion in classpath.
protected  boolean downloadJavadocs
          Enables/disables the downloading of javadoc attachments.
protected  boolean downloadSources
          Enables/disables the downloading of source attachments.
protected  MavenProject executedProject
          The currently executed project (can be a reactor project).
protected  boolean forceRecheck
          Enables/disables the rechecking of the remote repository for downloading source/javadoc attachments.
protected  ArtifactRepository localRepository
          Local maven repository.
protected  org.codehaus.plexus.logging.Logger logger
          Plexus logger needed for debugging manual artifact resolution.
protected  String packaging
          The project packaging.
protected  MavenProject project
          The project whose project files to create.
protected  List reactorProjects
          If the executed project is a reactor project, this will contains the full list of projects in the reactor.
protected  List remoteArtifactRepositories
          Remote repositories which will be searched for source attachments.
 
Fields inherited from interface org.apache.maven.plugin.Mojo
ROLE
 
Constructor Summary
AbstractIdeSupportMojo()
           
 
Method Summary
protected  IdeDependency[] doDependencyResolution()
          Resolve project dependencies.
 void enableLogging(org.codehaus.plexus.logging.Logger logger)
           
 void execute()
           
 ArtifactFactory getArtifactFactory()
          Getter for artifactFactory.
 ArtifactMetadataSource getArtifactMetadataSource()
          Getter for artifactMetadataSource.
 ArtifactResolver getArtifactResolver()
          Getter for artifactResolver.
 boolean getDownloadJavadocs()
          Getter for downloadJavadocs.
 boolean getDownloadSources()
          Getter for downloadSources.
abstract  List getExcludes()
           
 MavenProject getExecutedProject()
          Getter for executedProject.
 ArtifactRepository getLocalRepository()
          Getter for localRepository.
 MavenProject getProject()
          Getter for project.
abstract  String getProjectNameForArifact(Artifact artifact)
          Find the name of the project as used in eclipse.
protected  MavenProject getReactorProject(Artifact artifact)
          Checks the list of reactor projects to see if the artifact is included.
 List getReactorProjects()
          Getter for reactorProjects.
 List getRemoteArtifactRepositories()
          Getter for remoteArtifactRepositories.
protected abstract  boolean getUseProjectReferences()
          return false if projects available in a reactor build should be considered normal dependencies, true if referenced project will be linked and not need artifact resolution.
protected  IdeDependency[] getWorkspaceArtefacts()
           
protected  boolean hasToResolveJar(Artifact art)
          Checks if jar has to be resolved for the given artifact
protected  boolean isAvailableAsAReactorProject(Artifact artifact)
          Utility method that locates a project producing the given artifact.
protected  boolean isMavenVersion(String version)
          Checks whether the currently running Maven satisfies the specified version (range).
protected  boolean isResolveDependencies()
           
 void setArtifactFactory(ArtifactFactory artifactFactory)
          Setter for artifactFactory.
 void setArtifactMetadataSource(ArtifactMetadataSource artifactMetadataSource)
          Setter for artifactMetadataSource.
 void setArtifactResolver(ArtifactResolver artifactResolver)
          Setter for artifactResolver.
 void setDownloadJavadocs(boolean downloadJavadoc)
          Setter for downloadJavadocs.
 void setDownloadSources(boolean downloadSources)
          Setter for downloadSources.
 void setExecutedProject(MavenProject executedProject)
          Setter for executedProject.
 void setLocalRepository(ArtifactRepository localRepository)
          Setter for localRepository.
 void setProject(MavenProject project)
          Setter for project.
 void setReactorProjects(List reactorProjects)
          Setter for reactorProjects.
 void setRemoteArtifactRepositories(List remoteArtifactRepositories)
          Setter for remoteArtifactRepositories.
protected  void setResolveDependencies(boolean resolveDependencies)
           
protected abstract  boolean setup()
          Hook for preparation steps before the actual plugin execution.
protected  boolean useProjectReference(Artifact art)
          Checks if a projects reference has to be used for the given artifact
protected abstract  void writeConfiguration(IdeDependency[] deps)
          Main plugin method where dependencies should be processed in order to generate IDE configuration files.
 
Methods inherited from class org.apache.maven.plugin.AbstractMojo
getLog, getPluginContext, setLog, setPluginContext
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

project

protected MavenProject project
The project whose project files to create.

Is defined by:
expression:
${project}
Is readonly.
Is required.

executedProject

protected MavenProject executedProject
The currently executed project (can be a reactor project).

Is defined by:
expression:
${executedProject}
Is readonly.

packaging

protected String packaging
The project packaging.

Is defined by:
expression:
${project.packaging}

artifactFactory

protected ArtifactFactory artifactFactory
Artifact factory, needed to download source jars for inclusion in classpath.

Is a Plexus component defined by:
role:
org.apache.maven.artifact.factory.ArtifactFactory
Is readonly.
Is required.

artifactResolver

protected ArtifactResolver artifactResolver
Artifact resolver, needed to download source jars for inclusion in classpath.

Is a Plexus component defined by:
role:
org.apache.maven.artifact.resolver.ArtifactResolver
Is readonly.
Is required.

artifactCollector

protected ArtifactCollector artifactCollector
Artifact collector, needed to resolve dependencies.

Is a Plexus component defined by:
role:
org.apache.maven.artifact.resolver.ArtifactCollector
Is readonly.
Is required.

artifactMetadataSource

protected ArtifactMetadataSource artifactMetadataSource
Is a Plexus component defined by:
role:
org.apache.maven.artifact.metadata.ArtifactMetadataSource
hint:
maven

remoteArtifactRepositories

protected List remoteArtifactRepositories
Remote repositories which will be searched for source attachments.

Is defined by:
expression:
${project.remoteArtifactRepositories}
Is readonly.
Is required.

localRepository

protected ArtifactRepository localRepository
Local maven repository.

Is defined by:
expression:
${localRepository}
Is readonly.
Is required.

reactorProjects

protected List reactorProjects
If the executed project is a reactor project, this will contains the full list of projects in the reactor.

Is defined by:
expression:
${reactorProjects}
Is readonly.
Is required.

downloadSources

protected boolean downloadSources
Enables/disables the downloading of source attachments. Defaults to false. When this flag is true remote repositories are checked for sources: in order to avoid repeated check for unavailable source archives, a status cache is mantained. With versions 2.6+ of the plugin to reset this cache run mvn eclipse:remove-cache, or use the forceRecheck option with versions. With older versions delete the file mvn-eclipse-cache.properties in the target directory.

Is defined by:
expression:
${downloadSources}

downloadJavadocs

protected boolean downloadJavadocs
Enables/disables the downloading of javadoc attachments. Defaults to false. When this flag is true remote repositories are checked for javadocs: in order to avoid repeated check for unavailable javadoc archives, a status cache is mantained. With versions 2.6+ of the plugin to reset this cache run mvn eclipse:remove-cache, or use the forceRecheck option with versions. With older versions delete the file mvn-eclipse-cache.properties in the target directory.

Is defined by:
expression:
${downloadJavadocs}

forceRecheck

protected boolean forceRecheck
Enables/disables the rechecking of the remote repository for downloading source/javadoc attachments. Defaults to false. When this flag is true and the source or javadoc attachment has a status cache to indicate that it is not available, then the remote repository will be rechecked for a source or javadoc attachment and the status cache updated to reflect the new state.

Is defined by:
expression:
${forceRecheck}

logger

protected org.codehaus.plexus.logging.Logger logger
Plexus logger needed for debugging manual artifact resolution.

Constructor Detail

AbstractIdeSupportMojo

public AbstractIdeSupportMojo()
Method Detail

getArtifactMetadataSource

public ArtifactMetadataSource getArtifactMetadataSource()
Getter for artifactMetadataSource.

Returns:
Returns the artifactMetadataSource.

setArtifactMetadataSource

public void setArtifactMetadataSource(ArtifactMetadataSource artifactMetadataSource)
Setter for artifactMetadataSource.

Parameters:
artifactMetadataSource - The artifactMetadataSource to set.

getProject

public MavenProject getProject()
Getter for project.

Returns:
Returns the project.

setProject

public void setProject(MavenProject project)
Setter for project.

Parameters:
project - The project to set.

getReactorProjects

public List getReactorProjects()
Getter for reactorProjects.

Returns:
Returns the reactorProjects.

setReactorProjects

public void setReactorProjects(List reactorProjects)
Setter for reactorProjects.

Parameters:
reactorProjects - The reactorProjects to set.

getRemoteArtifactRepositories

public List getRemoteArtifactRepositories()
Getter for remoteArtifactRepositories.

Returns:
Returns the remoteArtifactRepositories.

setRemoteArtifactRepositories

public void setRemoteArtifactRepositories(List remoteArtifactRepositories)
Setter for remoteArtifactRepositories.

Parameters:
remoteArtifactRepositories - The remoteArtifactRepositories to set.

getArtifactFactory

public ArtifactFactory getArtifactFactory()
Getter for artifactFactory.

Returns:
Returns the artifactFactory.

setArtifactFactory

public void setArtifactFactory(ArtifactFactory artifactFactory)
Setter for artifactFactory.

Parameters:
artifactFactory - The artifactFactory to set.

getArtifactResolver

public ArtifactResolver getArtifactResolver()
Getter for artifactResolver.

Returns:
Returns the artifactResolver.

setArtifactResolver

public void setArtifactResolver(ArtifactResolver artifactResolver)
Setter for artifactResolver.

Parameters:
artifactResolver - The artifactResolver to set.

getExecutedProject

public MavenProject getExecutedProject()
Getter for executedProject.

Returns:
Returns the executedProject.

setExecutedProject

public void setExecutedProject(MavenProject executedProject)
Setter for executedProject.

Parameters:
executedProject - The executedProject to set.

getLocalRepository

public ArtifactRepository getLocalRepository()
Getter for localRepository.

Returns:
Returns the localRepository.

setLocalRepository

public void setLocalRepository(ArtifactRepository localRepository)
Setter for localRepository.

Parameters:
localRepository - The localRepository to set.

getDownloadJavadocs

public boolean getDownloadJavadocs()
Getter for downloadJavadocs.

Returns:
Returns the downloadJavadocs.

setDownloadJavadocs

public void setDownloadJavadocs(boolean downloadJavadoc)
Setter for downloadJavadocs.

Parameters:
downloadJavadoc - The downloadJavadocs to set.

getDownloadSources

public boolean getDownloadSources()
Getter for downloadSources.

Returns:
Returns the downloadSources.

setDownloadSources

public void setDownloadSources(boolean downloadSources)
Setter for downloadSources.

Parameters:
downloadSources - The downloadSources to set.

setResolveDependencies

protected void setResolveDependencies(boolean resolveDependencies)

isResolveDependencies

protected boolean isResolveDependencies()

getUseProjectReferences

protected abstract boolean getUseProjectReferences()
return false if projects available in a reactor build should be considered normal dependencies, true if referenced project will be linked and not need artifact resolution.

Returns:
true if referenced project will be linked and not need artifact resolution

setup

protected abstract boolean setup()
                          throws MojoExecutionException
Hook for preparation steps before the actual plugin execution.

Returns:
true if execution should continue or false if not.
Throws:
MojoExecutionException - generic mojo exception

writeConfiguration

protected abstract void writeConfiguration(IdeDependency[] deps)
                                    throws MojoExecutionException
Main plugin method where dependencies should be processed in order to generate IDE configuration files.

Parameters:
deps - list of IdeDependency objects, with artifacts, sources and javadocs already resolved
Throws:
MojoExecutionException - generic mojo exception

enableLogging

public void enableLogging(org.codehaus.plexus.logging.Logger logger)
Specified by:
enableLogging in interface org.codehaus.plexus.logging.LogEnabled
See Also:
LogEnabled.enableLogging(org.codehaus.plexus.logging.Logger)

execute

public final void execute()
                   throws MojoExecutionException,
                          MojoFailureException
Specified by:
execute in interface Mojo
Throws:
MojoExecutionException
MojoFailureException
See Also:
Mojo.execute()

doDependencyResolution

protected IdeDependency[] doDependencyResolution()
                                          throws MojoExecutionException
Resolve project dependencies. Manual resolution is needed in order to avoid resolution of multiproject artifacts (if projects will be linked each other an installed jar is not needed) and to avoid a failure when a jar is missing.

Returns:
resolved IDE dependencies, with attached jars for non-reactor dependencies
Throws:
MojoExecutionException - if dependencies can't be resolved

getProjectNameForArifact

public abstract String getProjectNameForArifact(Artifact artifact)
Find the name of the project as used in eclipse.

Parameters:
artifact - The artifact to find the eclipse name for.
Returns:
The name os the eclipse project.

isAvailableAsAReactorProject

protected boolean isAvailableAsAReactorProject(Artifact artifact)
Utility method that locates a project producing the given artifact.

Parameters:
artifact - the artifact a project should produce.
Returns:
true if the artifact is produced by a reactor projectart.

getReactorProject

protected MavenProject getReactorProject(Artifact artifact)
Checks the list of reactor projects to see if the artifact is included.

Parameters:
artifact - the artifact to check if it is in the reactor
Returns:
the reactor project or null if it is not in the reactor

getWorkspaceArtefacts

protected IdeDependency[] getWorkspaceArtefacts()
Returns:
an array with all dependencies available in the workspace, to be implemented by the subclasses.

getExcludes

public abstract List getExcludes()
Returns:
List of dependencies to exclude from eclipse classpath.
Since:
2.5

hasToResolveJar

protected boolean hasToResolveJar(Artifact art)
Checks if jar has to be resolved for the given artifact

Parameters:
art - the artifact to check
Returns:
true if resolution should happen

useProjectReference

protected boolean useProjectReference(Artifact art)
Checks if a projects reference has to be used for the given artifact

Parameters:
art - the artifact to check
Returns:
true if a project reference has to be used.

isMavenVersion

protected boolean isMavenVersion(String version)
Checks whether the currently running Maven satisfies the specified version (range).

Parameters:
version - The version range to test for, must not be null.
Returns:
true if the current Maven version matches the specified version range, false otherwise.


Copyright © 2002-2012 The Apache Software Foundation. All Rights Reserved.