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.

3 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

I appreciate your time in leaving a comment!