首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用自己的插件进行资源过滤

使用自己的插件进行资源过滤
EN

Stack Overflow用户
提问于 2012-11-21 18:19:18
回答 1查看 429关注 0票数 0

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

我的plugin (execute)方法中有以下代码:

代码语言:javascript
复制
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()等的输出。

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

代码语言:javascript
复制
[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()方法。

所以问题是:有人知道我做错了什么吗?(完整的源代码可以在here上找到。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-11-22 20:31:49

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

代码语言:javascript
复制
mavenResourcesExecution.addFilerWrapperWithEscaping(valueSource, "@", "@", "@", false);
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13491042

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档