Java Code Examples for org.apache.maven.shared.mapping.MappingUtils

The following examples show how to use org.apache.maven.shared.mapping.MappingUtils. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: appassembler   Source File: DependencyFactory.java    License: MIT License 5 votes vote down vote up
/**
 * Used by GenericDaemonGenerator.
 * @param artifact {@link Artifact}
 * @param layout {@link ArtifactRepositoryLayout}
 * @param outputFileNameMapping The name mapping.
 * @return the dependency.
 */
public static Dependency create( Artifact artifact, ArtifactRepositoryLayout layout, String outputFileNameMapping )
{
    Dependency dependency = new Dependency();
    dependency.setGroupId( artifact.getGroupId() );
    dependency.setArtifactId( artifact.getArtifactId() );
    dependency.setVersion( artifact.getVersion() );
    dependency.setClassifier( artifact.getClassifier() );

    String path = layout.pathOf( artifact );
    if ( StringUtils.isNotEmpty( outputFileNameMapping ) )
    {
        // Replace the file name part of the path with one that has been mapped
        File directory = new File( path ).getParentFile();

        try
        {
            String fileName = MappingUtils.evaluateFileNameMapping( outputFileNameMapping, artifact );
            File file = new File( directory, fileName );
            // Always use forward slash as path separator, because that's what layout.pathOf( artifact ) uses
            path = file.getPath().replace( '\\', '/' );
        }
        catch ( InterpolationException e )
        {
            // TODO Handle exceptions!
            // throw new MojoExecutionException("Unable to map file name.", e);
        }
    }
    dependency.setRelativePath( path );

    return dependency;
}
 
Example 2
Source Project: ci.maven   Source File: LooseEarApplication.java    License: Apache License 2.0 5 votes vote down vote up
public String getEarOutputFileNameMapping(Artifact artifact) throws Exception {
    String outputFileNameMapping = MavenProjectUtil.getPluginConfiguration(project, "org.apache.maven.plugins",
        "maven-ear-plugin", "outputFileNameMapping");
    String fileNameMapping = MappingUtils.evaluateFileNameMapping( outputFileNameMapping, artifact );
    if (fileNameMapping == null || fileNameMapping.isEmpty()) {
        // default format if none is specified
        String defaultFormat = "@{groupId}@[email protected]{artifactId}@[email protected]{version}@@{dashClassifier?}@[email protected]{extension}@";
        fileNameMapping = MappingUtils.evaluateFileNameMapping( defaultFormat, artifact );
    }
    return fileNameMapping;
}