Building an XPI using Maven

For FireCurl, I wanted to use maven to do the packaging of the resulting XPI file.

Following below suggestions, you’ll be able to use the following for your Mozilla Extension project:

# to build a new XPI
mvn package
 
# to cycle versions in the POM, tag and build
mvn release:prepare

Automatic submission to AMO is missing so far.

The directory structure is pretty simple and what you’d expect:

.
└── src
    └── main
        ├── assembly
        └── resources
            ├── chrome
            │   ├── content
            │   │   └── firecurl
            │   ├── locale
            │   │   └── en-US
            │   └── skin
            │       └── classic
            └── defaults
                └── preferences

In your pom, you need to configure the maven assembly plugin to create a .xpi file from the contents in resources/. (lines 29-47 below).
The descriptor (src/main/assembly/xpi.xml) defines how the file is packaged (more below).
Unfortunately, the finalName configuration parameter is appending “-xpi.zip” and I couldn’t find how to prevent that. This is why starting at line 49, I use an antrun target to move the file.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?xml version="1.0" encoding="UTF-8" ?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
 
    <groupId>cx.bp.moz</groupId>
    <artifactId>firecurl</artifactId>
    <packaging>pom</packaging>
    <version>0.0.3-SNAPSHOT</version>
 
    <name>FireCurl</name>
 
    <scm>
        <connection>scm:svn:http://ben-peter.jira.com/svn/FIRECURL/trunk</connection>
        <developerConnection>scm:svn:https://ben-peter.jira.com/svn/FIRECURL/trunk</developerConnection>
        <url>https://ben-peter.jira.com/source/browse/FIRECURL/trunk</url>
    </scm>
 
    <build>
        <plugins>
            <plugin>
                <artifactId>maven-release-plugin</artifactId>
                <version>2.2.1</version>
                <configuration>
                    <releaseProfiles>release</releaseProfiles>
                    <goals>package</goals>
                    <tagBase>https://ben-peter.jira.com/svn/FIRECURL/tags</tagBase>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>2.2-beta-5</version>
                <configuration>
                    <descriptors>
                        <descriptor>src/main/assembly/xpi.xml</descriptor>
                    </descriptors>
                    <finalName>${project.name}-${project.version}.xpi</finalName>
                </configuration>
                <executions>
                    <execution>
                        <id>make-assembly</id>
                        <phase>prepare-package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <artifactId>maven-antrun-plugin</artifactId>
                <version>1.6</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <configuration>
                            <target>
                                <move file="${project.build.directory}/${project.name}-${project.version}.xpi-xpi.zip" tofile="${project.build.directory}/${project.name}-${project.version}.xpi" />
                            </target>
                        </configuration>
                        <goals>
                            <goal>run</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

The assembly descriptor just packs all the stuff in resources/ into the XPI.
The one exception is that it filters the install.rdf file, so that the version number can be substituted in that file

<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
    <id>xpi</id>
    <includeBaseDirectory>false</includeBaseDirectory>
    <formats>
        <format>zip</format>
    </formats>
    <fileSets>
        <fileSet>
            <outputDirectory>/</outputDirectory>
            <directory>src/main/resources</directory>
            <excludes>
                <exclude>install.rdf</exclude>
            </excludes>
        </fileSet>
        <fileSet>
            <outputDirectory>/</outputDirectory>
            <directory>src/main/resources</directory>
            <includes>
                <include>install.rdf</include>
            </includes>
            <filtered>true</filtered>
        </fileSet>
    </fileSets>
</assembly>

Substitution in the install.rdf looks like this:

<?xml version="1.0"?>
<RDF xmlns="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
     xmlns:em="http://www.mozilla.org/2004/em-rdf#">
 
    <Description about="urn:mozilla:install-manifest">
        <em:id>firecurl@bp.cx</em:id>
        <em:version>${project.version}</em:version>
        <em:iconURL>chrome://firecurl/skin/firecurl32.png</em:iconURL>
 
        <em:targetApplication>
            <Description>
                <em:id>{ec8030f7-c20a-464f-9b0e-13a3a9e97384}</em:id>
                <em:minVersion>1.5</em:minVersion>
                <em:maxVersion>7.*</em:maxVersion>
                <em:type>2</em:type>
            </Description>
        </em:targetApplication>
 
        <em:name>FireCurl</em:name>
        <em:description>Copy and paste a curl command line for any request in the Firebug Net Panel.</em:description>
        <em:creator>Ben Peter, bp@ben-peter.com</em:creator>
        <em:homepageURL>http://ben-peter.com/</em:homepageURL>
    </Description>
</RDF>
This entry was posted in Uncategorized and tagged , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">