2012-11-21 22 views
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()方法不在這種情況下稱爲。

所以問題是:有人有一個想法我做錯了什麼? (全源可用here

回答

0

的解決方案是不使用正則表達式:

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