Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 362252 - no well-defined resource filtering mechanism (for resources included via bin.includes)
Summary: no well-defined resource filtering mechanism (for resources included via bin....
Status: VERIFIED FIXED
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: Tycho (show other bugs)
Version: unspecified   Edit
Hardware: All All
: P3 enhancement with 3 votes (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 360457 (view as bug list)
Depends on: 419849
Blocks:
  Show dependency tree
 
Reported: 2011-10-27 21:05 EDT by Greg Amerson CLA
Modified: 2021-04-28 16:54 EDT (History)
13 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Greg Amerson CLA 2011-10-27 21:05:21 EDT
The user story is a developer who wants to display the most recent build-id in an about dialog text of an Eclipse RCP product.  In order to display the current version this string value would need to be added during build time to properties file from the bundle source.  Currently there is no way to modify those property files as they are being copied into the jar.  To make this work with version 0.13.0 something like the following approach much be used with ant:

<build>
	<plugins>
		<plugin>
			<groupId>org.apache.maven.plugins</groupId>
			<artifactId>maven-antrun-plugin</artifactId>
			<version>1.6</version>
			<executions>
				<execution>
					<id>prepare-package</id>
					<phase>prepare-package</phase>
					<configuration>
						<target>
							<replace file="plugin.properties">
								<replacefilter token="_VERSION_" value="${unqualifiedVersion}.${buildQualifier}" />
							</replace>
						</target>
					</configuration>
					<goals>
						<goal>run</goal>
					</goals>
				</execution>
				<execution>
					<id>package</id>
					<phase>package</phase>
					<configuration>
						<target>
							<replace file="plugin.properties">
								<replacefilter token="${unqualifiedVersion}.${buildQualifier}" value="_VERSION_" />
							</replace>
						</target>
					</configuration>
					<goals>
						<goal>run</goal>
					</goals>
				</execution>
			</executions>
		</plugin>
	</plugins>
</build>
Comment 1 Tonny Madsen CLA 2012-05-03 05:21:00 EDT
Also see http://stackoverflow.com/q/10410717/796559 for an additional example.
Comment 2 Tobias Oberlies CLA 2012-06-29 07:09:36 EDT
In recent Tycho versions, we even have a problem with resources located in src/main/resources, because both the resources-plugin and the tycho-compiler-plugin may copy the resources. This is to be addressed in bug 383872.

This is different to the problem described in this bug, which is (as far as I understand) about supporting resource filtering for resources included via the build.properties.
Comment 3 Tobias Oberlies CLA 2012-06-29 07:12:27 EDT
*** Bug 360457 has been marked as a duplicate of this bug. ***
Comment 4 Jan Sievers CLA 2012-11-15 07:47:02 EST
also see bug 390119 for a workaround

proper solution should be provided with this bug
Comment 5 Tobias Oberlies CLA 2013-03-08 08:43:12 EST
Yet another non-general solution to the resource filtering problem: bug 369758.
Comment 6 Tonny Madsen CLA 2013-10-23 05:05:45 EDT
Notice that the files that are not "used" directly by Tycho during the build, can all be handled via the usual Maven resource filters:

E.g. I have the following in my product plug-in:

  <build>
    <resources>
      <resource>
        <directory>.</directory>
        <includes>
          <include>about.mappings</include>
          <include>plugin_customization.ini</include>
        </includes>
        <filtering>true</filtering>
      </resource>
    </resources>
  </build>
Comment 7 Greg Amerson CLA 2013-10-23 05:56:42 EDT
Hey Tonny,

Is there any more that has to be done in order to get your example to work?  I add that to the pom.xml in my branding plugin and re-ran the build, but the output file, the about.ini is not changed.  Is there any other configuration required?
Comment 8 Tonny Madsen CLA 2013-10-23 06:19:39 EDT
(In reply to Greg Amerson from comment #7)
> Hey Tonny,
> 
> Is there any more that has to be done in order to get your example to work? 
> I add that to the pom.xml in my branding plugin and re-ran the build, but
> the output file, the about.ini is not changed.  Is there any other
> configuration required?

Ohh, I forgot to add a sample about.mappings. You can of cause add the about.ini file as well. But only files NOT USED DIRECTLY by Tycho - so no feature.xml, *.target or *.product!

The referenced variables below are the properties from Maven. ${buildQualifier} you get for free - the rest I set in my top-level POM or get from the CI (in my case TeamCity).

You still have to added the file(s) to build.properties as well.

about.mappings:
------------------
0=${product.version}
1=${build.number} (${buildQualifier})
2=${build.type}
Comment 9 Greg Amerson CLA 2013-10-23 21:59:40 EDT
In my about.ini I have this:
aboutText=Liferay IDE ${unqualifiedVersion}.${buildQualifier}
featureImage=icons/liferay32.png
aboutImage=icons/liferay32.png

And in my build.properties I have this:
bin.includes = META-INF/,\
               about.ini,\
               icons/,\
               OSGI-INF/

And in my pom.xml I have this:
    <artifactId>com.liferay.ide.tools.branding</artifactId>
    <packaging>eclipse-plugin</packaging>

    <name>Liferay IDE Branding</name>

    <build>
        <resources>
            <resource>
                <directory>.</directory>
                <includes>
                    <include>about.ini</include>
                </includes>
                <filtering>true</filtering>
            </resource>
        </resources>
    </build>
    
    
However, after I run the tycho build, the compiled jar, if I open the about.ini none of the variables have been filtered.  It still is the same:
aboutText=Liferay IDE ${unqualifiedVersion}.${buildQualifier}

Am I missing something else?
Comment 10 Thanh Ha CLA 2013-10-25 14:54:05 EDT
In Platform we recently resolved this using a combination of maven-resources-plugin and tycho-packaging-plugin's additionalFileSets [1].


We used a filtering profile for about.mappings [2] (Snippet below). Basically the idea is to use maven-resources-plugin to filter the about.mappings, in our case 0=${buildId} and copy that to ${project.build.directory}.

Next we used tycho-packaging-plugins additionalFileSets [1] parameter to include about.mappings from ${project.build.directory} into the final jar. Note that you will need to use Tycho 0.19.0 for this to work due to bug 419849.

Hope this helps.


[1] http://eclipse.org/tycho/sitedocs/tycho-packaging-plugin/package-plugin-mojo.html#additionalFileSets
[2] http://git.eclipse.org/c/platform/eclipse.platform.releng.aggregator.git/tree/eclipse-platform-parent/pom.xml#n735



--- snippet ---

          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-resources-plugin</artifactId>
            <version>2.6</version>
            <executions>
              <execution>
                <id>process-about.mappings</id>
                <phase>prepare-package</phase>
                <configuration>
                  <outputDirectory>${project.build.directory}</outputDirectory>
                  <overwrite>true</overwrite>
                  <resources>
                    <resource>
                      <directory>${basedir}</directory>
                      <includes>
                        <include>about.mappings</include>
                      </includes>
                      <filtering>true</filtering>
                    </resource>
                  </resources>
                </configuration>
                <goals>
                  <goal>copy-resources</goal>
                </goals>
              </execution>
            </executions>
          </plugin>
          <plugin>
            <groupId>org.eclipse.tycho</groupId>
            <artifactId>tycho-packaging-plugin</artifactId>
            <version>${tycho.version}</version>
            <configuration>
              <additionalFileSets>
                <fileSet>
                  <directory>${project.build.directory}</directory>
                  <includes>
                    <include>about.mappings</include>
                  </includes>
                </fileSet>
              </additionalFileSets>
            </configuration>
          </plugin>

--- end snippet ---
Comment 11 Thanh Ha CLA 2013-10-25 15:01:12 EDT
(In reply to Greg Amerson from comment #9)
> However, after I run the tycho build, the compiled jar, if I open the
> about.ini none of the variables have been filtered.  It still is the same:
> aboutText=Liferay IDE ${unqualifiedVersion}.${buildQualifier}
> 
> Am I missing something else?

I think the problem here is that when your bin.includes includes a file to be included. Tycho searches the project directory and includes that.

Correct me if I'm wrong but I believe maven-resources-plugin by default filters files and copies them to the target/ directory leaving the version of that file untouched in original location (where Tycho looks for the bin.includes). So what's copied to your final jar is the original version and not your filtered version.

With bug 419849 now resolved in 0.19.0 you should be able to use the tycho-packaging-plugin's additionalFileSets parameter to tell Tycho to include the filtered version of your about.ini. See comment 10 for an explanation of how we did this in Platform.

Hope this helps.
Comment 12 Greg Amerson CLA 2013-10-28 02:20:46 EDT
Thanks Thanh Ha,

That helps a lot and I was able to get it working locally using 0.19.0 and your snippets.
Comment 13 Thanh Ha CLA 2013-11-03 01:00:25 EST
(In reply to Greg Amerson from comment #12)
> Thanks Thanh Ha,
> 
> That helps a lot and I was able to get it working locally using 0.19.0 and
> your snippets.

Great! I think this bug is resolved?

Feel free to reopen if you think otherwise.
Comment 14 Greg Amerson CLA 2013-11-05 02:43:58 EST
Verified with my adopter build.