0

目前我开发了自己的插件,它将通过加载影响资源过滤的其他文件来进行资源过滤。

我的插件(执行)方法中有以下代码:

public void execute() throws MojoExecutionException {
    if (StringUtils.isEmpty(encoding) && isFilteringEnabled(getResources())) {
        getLog().warn(
                "File encoding has not been set, using platform encoding "
                        + ReaderFactory.FILE_ENCODING
                        + ", i.e. build is platform dependent!");
    }
    Scope scope = convertToScope(getScope());
    getLog().info("Hallo welt. (" + scope + ")");

    if (getResources() != null) {
        for (Resource item : getResources()) {
            getLog().info(" --| Resource: " + item.getFiltering() + "|" + item.getDirectory());
        }
    }

    try {

        MavenResourcesExecution mavenResourcesExecution = new MavenResourcesExecution(
                resources, outputDirectory, project, encoding, null,
                nonFilteredFileExtensions, mavenSession);

        ValueSource valueSource = new ValueSource() {

            @Override
            public Object getValue(String expression) {
                getLog().info("Expression: " + expression);

                return "XXX";
            }

            @Override
            public List getFeedback() {
                getLog().info("getFeedback()");
                return Collections.EMPTY_LIST;
            }

            @Override
            public void clearFeedback() {
                // TODO Auto-generated method stub
                getLog().info("clearFeedback()");

            }
        };
        mavenResourcesExecution.addFilerWrapperWithEscaping(valueSource,
                "\\@", "\\@", "@", false);

        mavenResourcesExecution.setUseDefaultFilterWrappers(false);

        mavenResourcesFiltering.filterResources(mavenResourcesExecution);

    } catch (MavenFilteringException e) {
        throw new MojoExecutionException(e.getMessage(), e);
    }

}

但是在我的集成测试期间,过滤不会完成。在我的输出中,我找不到 getValue()、getFeedback() 等的输出。

目前我的集成测试期间的输出如下所示:

[INFO] Hallo welt. ()
[INFO]  --| Resource: true|src/main/resource-files
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[DEBUG] resource with targetPath null
directory src/main/resource-files
excludes []
includes []
[DEBUG] ignoreDelta true
[INFO] Copying 1 resource
[DEBUG] file thisIsTheFirst.properties has a filtered file extension
[DEBUG] filtering ..it\configurationTest\src\main\resource-files\thisIsTheFirst.properties to ...\it\configurationTest\target\classes\thisIsTheFirst.properties

但不幸的是,在这种情况下不会调用 getValue() 方法。

所以问题是:有人知道我做错了什么吗?(完整源代码可在此处获得。

4

1 回答 1

0

解决方案是不使用正则表达式:

mavenResourcesExecution.addFilerWrapperWithEscaping(valueSource, "@", "@", "@", false);
于 2012-11-22T12:31:48.847 回答