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

The following examples show how to use org.apache.maven.shared.mapping.MappingUtils. 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 File: DependencyFactory.java    From appassembler with 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 File: LooseEarApplication.java    From ci.maven with 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}@-@{artifactId}@-@{version}@@{dashClassifier?}@.@{extension}@";
        fileNameMapping = MappingUtils.evaluateFileNameMapping( defaultFormat, artifact );
    }
    return fileNameMapping;
}