Monday, September 1, 2014

Amp Archetype for Share build corrupts *.ico image files

When using the amp archetype from alfresco maven sdk for alfresco share, all image files that had an extension of *.ico were corrupted after going through the amp build process.

PROBLEM:
Research of the parent alfresco-sdk-parent shows that the maven-resources-plugin configures binary extensions that are filtered during the build process. Since *.ico files were not included, these file extensions are corrupted during the build process.
/Users/cherryshoe/.m2/repository/org/alfresco/maven/alfresco-sdk-parent/1.1.1/alfresco-sdk-parent-1.1.1.pom
<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-resources-plugin</artifactId>
  <version>${maven.resources.version}</version>
  <configuration>
    <encoding>UTF-8</encoding>
    <nonFilteredFileExtensions>
      <nonFilteredFileExtension>ftl</nonFilteredFileExtension>
      <nonFilteredFileExtension>acp</nonFilteredFileExtension>
      <nonFilteredFileExtension>jpg</nonFilteredFileExtension>
      <nonFilteredFileExtension>png</nonFilteredFileExtension>
      <nonFilteredFileExtension>gif</nonFilteredFileExtension>
      <nonFilteredFileExtension>pdf</nonFilteredFileExtension>
      <nonFilteredFileExtension>doc</nonFilteredFileExtension>
      <nonFilteredFileExtension>xls</nonFilteredFileExtension>
      <nonFilteredFileExtension>ppt</nonFilteredFileExtension>
      <nonFilteredFileExtension>bin</nonFilteredFileExtension>
      <nonFilteredFileExtension>lic</nonFilteredFileExtension>
      <nonFilteredFileExtension>swf</nonFilteredFileExtension>
    </nonFilteredFileExtensions>
  </configuration>
</plugin>

SOLUTION:
Instead of putting in a trouble ticket on the google maven-alfresco-archetypes project, the workaround solution was to to append additional filtered extensions that the alfresco-sdk-parent doesn't have to the child share maven module's pom.  Note the combine.children="append" attribute on the nonFilteredFileExtensions tag, this way you don't have to completely override by repeating the parent's nonFilteredExtensions config, just append to it.

NOTE: This was tested on Alfresco Community 4.2.e and would also apply to any other file extensions that get corrupted during the build, mainly binary files.

<!-- Append additional filtered extensions that the alfresco-sdk-parent doesn't have -->
<build>
  <pluginManagement>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-resources-plugin</artifactId>
        <version>${maven.resources.version}</version>
        <configuration>
          <encoding>UTF-8</encoding>
          <nonFilteredFileExtensions combine.children="append">
            <nonFilteredFileExtension>ico</nonFilteredFileExtension>
          </nonFilteredFileExtensions>
        </configuration>
      </plugin>
    </plugins>
  </pluginManagement>
</build>

What questions do you have about this post? Let me know in the comments section below, and I will answer each one.

5 comments:

  1. Hi Judy,

    thanks for the explanation and solution.

    I would be very grateful if you help me with this problem:

    I have many "favicon.ico" files. With some of them there is an excception:

    Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:2.7:resources

    But, with some of them there isn't exception.

    I put "favicon.ico" in the following directory:

    /share-amp/src/main/amp/web

    When additional filtered extension, that you mentioned, is added to the pom.xml everything is OK.

    ReplyDelete
  2. Hi Judy,

    I think that I've just found explanation for my problem:

    Link: https://maven.apache.org/plugins/maven-resources-plugin/examples/filter.html

    Gist:
    Warning: Do not filter files with binary content like images! This will most likely result in corrupt output.
    ...

    So, if you don't exclude image file from filtering you will most likely have a corrupted output.

    I apologize if I took your time.

    Kind regards,
    Uros Vukasinovic

    ReplyDelete
  3. Hi Uros,

    I don't think I fully understand what your issue in your first comment was. Are you saying that some *.ico fies get corrupted and some don't? Or that if you include some *.ico files in the build, some will cause the error "Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:2.7:resources"?

    I noticed for any files that are in src\main\amp\web, and under subdirectories this has worked.

    Which version of the alfresco-maven-sdk are you using?

    Also, this maven article shows that you should and can filter binary files or they will get corrupted - https://maven.apache.org/plugins/maven-resources-plugin/examples/binaries-filtering.html.

    I wrote another similar article to this issue here as well for your reference - http://www.codified.com/warning-failed-to-scan-jar-java-util-zip-zipexception-error-in-opening-zip-file/.

    Happy coding!
    Judy

    ReplyDelete
  4. Hi Judy,

    Thanks for the quick response.

    I will try to explain better.

    I created few *.ico files for different share-amp projects(Alfresco SDK 2.0).

    For the first project, there is a file: "favicon.ico". I put that file
    in the directory "web", so its path is:
    first-project/.../share-amp/src/main/amp/web.

    When I ran the command "mvn install", build is successful.
    ...
    For the second project, there is another file: "favicon.ico". I put that file
    in the directory "web", so its path is:
    second-project/.../share-amp/src/main/amp/web.

    When I ran command "mvn install", there is a build error:

    Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:2.7:resources
    ...

    If I put "favicon.ico" from the first project to the second project, build is successful.

    If I edit "favicon.ico" from the second project(resize, edit...) some of them go through build without error and
    some of them failed.

    Build status depends on the binary file(favicon.ico).

    I spent some time to investigate this problem, and I found your solution. And, when I use your "additional filtered extensions" everything is OK.

    But, different build status for different favicon.ico files bothered me.
    So, finally I found an explanation for my problem:

    *******************************************************************************************************************
    Link: https://maven.apache.org/plugins/maven-resources-plugin/examples/filter.html

    Key sentence:
    Warning: Do not filter files with binary content like images! This will most likely result in corrupt output.
    *******************************************************************************************************************

    "Most likely" is the key. It means that isn't true for everyone, but for the most of them :).

    If you don't exclude image file from filtering you will most likely have a corrupted output.

    Also, it may happen that build passed without error(It depends on *.ico file)

    I hope that you now understand my story.

    Thanks and good luck with Alfresco :),
    Uros

    ReplyDelete
  5. Hi Judy,

    Thanks for the quick response.

    I will try to explain better.

    I created few *.ico files for different share-amp projects(Alfresco SDK 2.0).

    For the first project, there is a file: "favicon.ico". I put that file
    in the directory "web", so its path is:
    first-project/.../share-amp/src/main/amp/web.

    When I ran the command "mvn install", build is successful.
    ...
    For the second project, there is another file: "favicon.ico". I put that file
    in the directory "web", so its path is:
    second-project/.../share-amp/src/main/amp/web.

    When I ran command "mvn install", there is a build error:

    Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:2.7:resources
    ...

    If I put "favicon.ico" from the first project to the second project, build is successful.

    If I edit "favicon.ico" from the second project(resize, edit...) some of them go through build without error and
    some of them failed.

    Build status depends on the binary file(favicon.ico).

    I spent some time to investigate this problem, and I found your solution. And, when I use your "additional filtered extensions" everything is OK.

    But, different build status for different favicon.ico files bothered me.
    So, finally I found an explanation for my problem:

    *****************************************************************
    Link: https://maven.apache.org/plugins/maven-resources-plugin/examples/filter.html

    Key sentence:
    Warning: Do not filter files with binary content like images! This will most likely result in corrupt output.
    ******************************************************************

    "Most likely" is the key. It means that isn't true for everyone, but for the most of them :).

    If you don't exclude image file from filtering you will most likely have a corrupted output.

    Also, it may happen that build passed without error(It depends on *.ico file)

    I hope that you now understand my story.

    Thanks and good luck with Alfresco :),
    Uros

    ReplyDelete

I appreciate your time in leaving a comment!