Apache Maven 映射

这些类源自 Maven WAR 插件中的文件名映射代码。

目标是为所有需要映射的插件提供一个共享组件。

映射工具

这个类有一个方法evaluateFileNameMapping,它接受一个表达式和一个Artifact作为参数。它返回一个字符串,该字符串是将Artifact对象中的值插入到表达式中的结果。

以下是 WAR 插件中的一些代码,展示了如何使用它:

    protected String getFileName( Artifact artifact )
    {
        if ( getOutputFileNameMapping() != null )
        {
            // The user has specified a custom file name mapping expression
            return MappingUtils.evaluateFileNameMapping( getOutputFileNameMapping(), artifact );
        }

        String classifier = artifact.getClassifier();
        if ( ( classifier != null ) && !( "".equals( classifier.trim() ) ) )
        {
            // The artifact has a classifier - use the default expression for artifacts with classifier
            return MappingUtils.evaluateFileNameMapping( MappingUtils.DEFAULT_FILE_NAME_MAPPING_CLASSIFIER,
                                                         artifact );
        }
        else
        {
            // The artifact does not have a classifier - use the default expression for artifacts
            return MappingUtils.evaluateFileNameMapping( MappingUtils.DEFAULT_FILE_NAME_MAPPING, artifact );
        }
    }

查看Maven WAR 插件的文档,了解一些可以使用的表达式示例。

DashClassifierValueSource

这是ValueSource接口的实现,可用于插值。MappingUtils在内部使用它。它将这两个标记添加到Interpolator

  • 破折号分类器
  • 破折号分类器?

你可以像这样调用它:

        Interpolator interpolator = StringSearchInterpolator());
        interpolator.addValueSource( new DashClassifierValueSource( artifact.getClassifier() ) );