org.apache.maven.plugin.ide
Class IdeUtils

java.lang.Object
  extended by org.apache.maven.plugin.ide.IdeUtils

public class IdeUtils
extends Object

Version:
$Id: IdeUtils.java 1517906 2013-08-27 18:25:03Z krosenvold $
Author:
Trygve Laugstøl, Fabrizio Giustina

Field Summary
static String JAVA_1_1
           
static String JAVA_1_2
           
static String JAVA_1_3
           
static String JAVA_1_4
           
static String JAVA_5_0
           
static String JAVA_6_0
           
static String NOT_AVAILABLE_MARKER_FILE_SUFFIX
          The suffix used to mark a file as not available.
static String PROJECT_NAME_DEFAULT_TEMPLATE
           
static String PROJECT_NAME_WITH_GROUP_AND_VERSION_TEMPLATE
           
static String PROJECT_NAME_WITH_GROUP_TEMPLATE
           
static String PROJECT_NAME_WITH_VERSION_TEMPLATE
           
 
Method Summary
static String calculateProjectNameTemplate(String projectNameTemplate, boolean addVersionToProjectName, boolean addGroupIdToProjectName, Log log)
          Calculate the project name template from the specified value projectNameTemplate, addVersionToProjectName and addGroupIdToProjectName Note: if projectNameTemplate is not null then that value will be used regardless of the values for addVersionToProjectName or addGroupIdToProjectName and a warning will be issued.
static Artifact createArtifactWithClassifier(String groupId, String artifactId, String version, String depClassifier, String inClassifier, ArtifactFactory artifactFactory)
          Wrap ArtifactFactory.createArtifactWithClassifier(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String) so that the type and classifier are set correctly for "sources" and "javadoc".
static void delete(File f, Log log)
          Delete a file, handling log messages and exceptions
static String fixSeparator(String filename)
          Convert the provided filename from a Windows separator \\ to a unix/java separator /
static String fixWindowsDriveURI(String input)
          NOTE: This is to account for the unfortunate fact that "file:" URIs differ between Windows and Unix.
static ArtifactVersion getArtifactVersion(String[] artifactIds, List dependencies)
           
static String getArtifactVersion(String[] artifactIds, List dependencies, int len)
          Extracts the version of the first matching artifact in the given list.
static String getCanonicalPath(File file)
           
static String getCompilerPluginSetting(MavenProject project, String optionName)
          Returns a compiler plugin settings, considering also settings altered in plugin executions .
static String getCompilerSourceEncoding(MavenProject project)
          Returns the source encoding configured for the compiler plugin.
static String getCompilerSourceVersion(MavenProject project)
          Returns the source version configured for the compiler plugin.
static String getCompilerTargetVersion(MavenProject project)
          Returns the target version configured for the compiler plugin.
static File getNotAvailableMarkerFile(ArtifactRepository localRepository, Artifact artifact)
           
static Xpp3Dom getPluginConfigurationDom(MavenProject project, String pluginId)
          Search for the configuration Xpp3 dom of an other plugin.
static Xpp3Dom[] getPluginConfigurationDom(MavenProject project, String artifactId, String[] subConfiguration)
          Search for the configuration Xpp3 dom of an other plugin.
static String getPluginSetting(MavenProject project, String pluginId, String optionName, String defaultValue)
          Search for a configuration setting of an other plugin for a configuration setting.
static String getProjectName(MavenProject project, boolean addVersionToProjectName)
           
static String getProjectName(String template, Artifact artifact)
          Use the project name template to create an eclipse project.
protected static String getProjectName(String template, IdeDependency dep)
          Use IdeDependency.getEclipseProjectName() instead.
static String getProjectName(String template, MavenProject project)
           
static Artifact resolveArtifact(ArtifactResolver artifactResolver, Artifact artifact, List remoteRepos, ArtifactRepository localRepository, Log log)
          Wrapper around ArtifactResolver.resolve(Artifact, List, ArtifactRepository)
static String resolveJavaVersion(MavenProject project)
           
static String toRelativeAndFixSeparator(File basedir, File fileToAdd, boolean replaceSlashesWithDashes)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

JAVA_1_1

public static final String JAVA_1_1
See Also:
Constant Field Values

JAVA_1_2

public static final String JAVA_1_2
See Also:
Constant Field Values

JAVA_1_3

public static final String JAVA_1_3
See Also:
Constant Field Values

JAVA_1_4

public static final String JAVA_1_4
See Also:
Constant Field Values

JAVA_5_0

public static final String JAVA_5_0
See Also:
Constant Field Values

JAVA_6_0

public static final String JAVA_6_0
See Also:
Constant Field Values

PROJECT_NAME_DEFAULT_TEMPLATE

public static final String PROJECT_NAME_DEFAULT_TEMPLATE
See Also:
Constant Field Values

PROJECT_NAME_WITH_VERSION_TEMPLATE

public static final String PROJECT_NAME_WITH_VERSION_TEMPLATE
See Also:
Constant Field Values

PROJECT_NAME_WITH_GROUP_TEMPLATE

public static final String PROJECT_NAME_WITH_GROUP_TEMPLATE
See Also:
Constant Field Values

PROJECT_NAME_WITH_GROUP_AND_VERSION_TEMPLATE

public static final String PROJECT_NAME_WITH_GROUP_AND_VERSION_TEMPLATE
See Also:
Constant Field Values

NOT_AVAILABLE_MARKER_FILE_SUFFIX

public static final String NOT_AVAILABLE_MARKER_FILE_SUFFIX
The suffix used to mark a file as not available.

See Also:
Constant Field Values
Method Detail

delete

public static void delete(File f,
                          Log log)
                   throws MojoExecutionException
Delete a file, handling log messages and exceptions

Parameters:
f - File to be deleted
Throws:
MojoExecutionException - only if a file exists and can't be deleted

getCanonicalPath

public static String getCanonicalPath(File file)
                               throws MojoExecutionException
Throws:
MojoExecutionException

getCompilerPluginSetting

public static String getCompilerPluginSetting(MavenProject project,
                                              String optionName)
Returns a compiler plugin settings, considering also settings altered in plugin executions .

Parameters:
project - maven project
Returns:
option value (may be null)

getCompilerSourceVersion

public static String getCompilerSourceVersion(MavenProject project)
Returns the source version configured for the compiler plugin. Returns the minimum version required to compile both standard and test sources, if settings are different.

Parameters:
project - maven project
Returns:
java source version

getCompilerSourceEncoding

public static String getCompilerSourceEncoding(MavenProject project)
Returns the source encoding configured for the compiler plugin. Returns the minimum version required to compile both standard and test sources, if settings are different.

Parameters:
project - maven project
Returns:
java source version

getCompilerTargetVersion

public static String getCompilerTargetVersion(MavenProject project)
Returns the target version configured for the compiler plugin. Returns the minimum version required to compile both standard and test sources, if settings are different.

Parameters:
project - maven project
Returns:
java target version

getArtifactVersion

public static String getArtifactVersion(String[] artifactIds,
                                        List dependencies,
                                        int len)
Extracts the version of the first matching artifact in the given list.

The len parameter indicated what to to return:

Parameters:
artifactIds - artifact names to compare against for extracting version
artifacts - Set of artifacts for our project
len - expected length of the version sub-string
Returns:

getArtifactVersion

public static ArtifactVersion getArtifactVersion(String[] artifactIds,
                                                 List dependencies)
Parameters:
artifactIds - an array of artifactIds, should not be null
dependencies - a list of Dependency-objects, should not be null
Returns:
the resolved ArtifactVersion, otherwise null

getPluginSetting

public static String getPluginSetting(MavenProject project,
                                      String pluginId,
                                      String optionName,
                                      String defaultValue)
Search for a configuration setting of an other plugin for a configuration setting.

Parameters:
project - the current maven project to get the configuration from.
pluginId - the group id and artifact id of the plugin to search for
optionName - the option to get from the configuration
defaultValue - the default value if the configuration was not found
Returns:
the value of the option configured in the plugin configuration

getPluginConfigurationDom

public static Xpp3Dom getPluginConfigurationDom(MavenProject project,
                                                String pluginId)
Search for the configuration Xpp3 dom of an other plugin.

Parameters:
project - the current maven project to get the configuration from.
pluginId - the group id and artifact id of the plugin to search for
Returns:
the value of the option configured in the plugin configuration

getPluginConfigurationDom

public static Xpp3Dom[] getPluginConfigurationDom(MavenProject project,
                                                  String artifactId,
                                                  String[] subConfiguration)
Search for the configuration Xpp3 dom of an other plugin.

Parameters:
project - the current maven project to get the configuration from.
artifactId - the artifact id of the plugin to search for
Returns:
the value of the option configured in the plugin configuration

calculateProjectNameTemplate

public static String calculateProjectNameTemplate(String projectNameTemplate,
                                                  boolean addVersionToProjectName,
                                                  boolean addGroupIdToProjectName,
                                                  Log log)
Calculate the project name template from the specified value projectNameTemplate, addVersionToProjectName and addGroupIdToProjectName

Note: if projectNameTemplate is not null then that value will be used regardless of the values for addVersionToProjectName or addGroupIdToProjectName and a warning will be issued.

Parameters:
projectNameTemplate - the current projectNameTemplate, if available
addVersionToProjectName - whether to include Version in the project name
addGroupIdToProjectName - whether to include GroupId in the project name.
Returns:
the project name template.

getProjectName

protected static String getProjectName(String template,
                                       IdeDependency dep)
Use IdeDependency.getEclipseProjectName() instead.


getProjectName

public static String getProjectName(String template,
                                    Artifact artifact)
Use the project name template to create an eclipse project.

Parameters:
template - Template for the project name
artifact - the artifact to create the project name for
Returns:
the created ide project name

getProjectName

public static String getProjectName(String template,
                                    MavenProject project)

getProjectName

public static String getProjectName(MavenProject project,
                                    boolean addVersionToProjectName)

getNotAvailableMarkerFile

public static File getNotAvailableMarkerFile(ArtifactRepository localRepository,
                                             Artifact artifact)
Parameters:
artifact - the artifact
Returns:
the not-available marker file for the specified artifact

resolveArtifact

public static Artifact resolveArtifact(ArtifactResolver artifactResolver,
                                       Artifact artifact,
                                       List remoteRepos,
                                       ArtifactRepository localRepository,
                                       Log log)
Wrapper around ArtifactResolver.resolve(Artifact, List, ArtifactRepository)

Parameters:
artifactResolver - see ArtifactResolver.resolve(Artifact, List, ArtifactRepository)
artifact - see ArtifactResolver.resolve(Artifact, List, ArtifactRepository)
remoteRepos - see ArtifactResolver.resolve(Artifact, List, ArtifactRepository)
localRepository - see ArtifactResolver.resolve(Artifact, List, ArtifactRepository)
log - Logger
Returns:
the artifact, resolved if possible.

createArtifactWithClassifier

public static Artifact createArtifactWithClassifier(String groupId,
                                                    String artifactId,
                                                    String version,
                                                    String depClassifier,
                                                    String inClassifier,
                                                    ArtifactFactory artifactFactory)
Wrap ArtifactFactory.createArtifactWithClassifier(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String) so that the type and classifier are set correctly for "sources" and "javadoc".

Parameters:
groupId - see ArtifactFactory.createArtifactWithClassifier(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String)
artifactId - see ArtifactFactory.createArtifactWithClassifier(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String)
version - see ArtifactFactory.createArtifactWithClassifier(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String)
depClassifier - see ArtifactFactory.createArtifactWithClassifier(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String)
inClassifier - either "sources" of "javadoc"
artifactFactory - see ArtifactFactory.createArtifactWithClassifier(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String)
Returns:
see ArtifactFactory.createArtifactWithClassifier(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String)
See Also:
ArtifactFactory.createArtifactWithClassifier(java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.String)

resolveJavaVersion

public static String resolveJavaVersion(MavenProject project)

toRelativeAndFixSeparator

public static String toRelativeAndFixSeparator(File basedir,
                                               File fileToAdd,
                                               boolean replaceSlashesWithDashes)
                                        throws MojoExecutionException
Throws:
MojoExecutionException

fixSeparator

public static String fixSeparator(String filename)
Convert the provided filename from a Windows separator \\ to a unix/java separator /

Parameters:
filename - file name to fix separator
Returns:
filename with all \\ replaced with /

fixWindowsDriveURI

public static String fixWindowsDriveURI(String input)
NOTE: This is to account for the unfortunate fact that "file:" URIs differ between Windows and Unix. On a Windows box, the path "C:\dir" is mapped to "file:/C:/dir". On a Unix box, the path "/home/dir" is mapped to "file:/home/dir". So, in the first case the slash after "file:" is not part of the corresponding filesystem path while in the later case it is. This discrepancy makes verifying the javadoc attachments in ".classpath" a little tricky.

Parameters:
input - string input that may contain a windows URI
Returns:
all windows URI convert "file:C:/dir" to "file:/C:/dir"


Copyright © 2002–2015 The Apache Software Foundation. All rights reserved.