aboutsummaryrefslogtreecommitdiff
path: root/nixpkgs/pkgs/development/mobile/androidenv/convertaddons.xsl
blob: 20f007eca048725efc17e83ea24de0adf96af405 (plain)
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
<?xml version="1.0"?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:addon="http://schemas.android.com/sdk/android/repo/addon2/01"
  xmlns:sdk="http://schemas.android.com/repository/android/common/01"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

  <xsl:output omit-xml-declaration="yes" indent="no" />

  <!-- Template that puts a google HTTP prefix in front of relative URLs -->
  <xsl:template name="repository-url">
    <xsl:variable name="raw-url" select="complete/url"/>
    <xsl:choose>
      <xsl:when test="starts-with($raw-url, 'http')">
        <xsl:value-of select="$raw-url"/>
      </xsl:when>
      <xsl:otherwise>
        <xsl:text>https://dl.google.com/android/repository/</xsl:text>
        <xsl:value-of select="$raw-url"/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

  <xsl:template match="/addon:sdk-addon">
{fetchurl}:

{
  addons = {
    <!-- Convert all addons, but skip the entry for google APIs version 25 because it is inconsistent with the spec -->
    <xsl:for-each select="remotePackage[type-details/@xsi:type='addon:addonDetailsType' and archives/archive/complete/url != 'google_apis-25_r1.zip' ]"><xsl:sort select="@path" />
    "<xsl:value-of select="type-details/api-level" />"."<xsl:value-of select="type-details/tag/id" />" = {
      name = "<xsl:value-of select="type-details/tag/id" />";
      path = "<xsl:value-of select="translate(@path, ';', '/')" />";
      revision = "<xsl:value-of select="type-details/api-level" />";
      displayName = "<xsl:value-of select="display-name" />";
      archives = {
      <xsl:for-each select="archives/archive[not(host-os)]">
        all = fetchurl {
          url = "<xsl:call-template name="repository-url"/>";
          sha1 = "<xsl:value-of select="complete/checksum" />";
        };
      </xsl:for-each>
      <xsl:for-each select="archives/archive[host-os and not(host-os = 'windows')]">
        <xsl:value-of select="host-os" /> = fetchurl {
          url = "<xsl:call-template name="repository-url"/>";
          sha1 = "<xsl:value-of select="complete/checksum" />";
        };
      </xsl:for-each>
      };
    };
    </xsl:for-each>

    <!-- Workaround to make google APIs version 25 work. Hopefully, we can get rid of this at some point -->
    <xsl:for-each select="remotePackage[type-details/@xsi:type='addon:addonDetailsType' and archives/archive/complete/url = 'google_apis-25_r1.zip' ]">
    "<xsl:value-of select="25" />"."<xsl:value-of select="type-details/tag/id" />" = {
      name = "<xsl:value-of select="type-details/tag/id" />";
      path = "add-ons/addon-google_apis-google-25";
      revision = "<xsl:value-of select="25" />";
      displayName = "<xsl:value-of select="display-name" />";
      archives = {
      <xsl:for-each select="archives/archive[not(host-os)]">
        all = fetchurl {
          url = "<xsl:call-template name="repository-url"/>";
          sha1 = "<xsl:value-of select="complete/checksum" />";
        };
      </xsl:for-each>
      <xsl:for-each select="archives/archive[host-os and not(host-os = 'windows')]">
        <xsl:value-of select="host-os" /> = fetchurl {
          url = "<xsl:call-template name="repository-url"/>";
          sha1 = "<xsl:value-of select="complete/checksum" />";
        };
      </xsl:for-each>
      };
    };
    </xsl:for-each>
  };

  extras = {
    <!-- Convert all extras and maven artefacts -->
    <xsl:for-each select="remotePackage[type-details/@xsi:type='addon:extraDetailsType' or type-details/@xsi:type='addon:mavenType']"><xsl:sort select="@path" />
    
    <!-- Compose revision string from revision attributes -->
    <xsl:variable name="revision">
      <xsl:choose>
        <xsl:when test="revision/major">
          <xsl:value-of select="revision/major" />
        </xsl:when>
      </xsl:choose>
      <xsl:choose>
        <xsl:when test="revision/minor">.<xsl:value-of select="revision/minor" />
        </xsl:when>
      </xsl:choose>
      <xsl:choose>
        <xsl:when test="revision/micro">.<xsl:value-of select="revision/micro" />
        </xsl:when>
      </xsl:choose>
      <xsl:choose>
        <xsl:when test="revision/preview">-rc<xsl:value-of select="revision/preview" />
        </xsl:when>
      </xsl:choose>
    </xsl:variable>

    "<xsl:value-of select="@path" />" = {
      name = "<xsl:value-of select="translate(@path, ';', '-')" />";
      path = "<xsl:value-of select="translate(@path, ';', '/')" />";
      revision = "<xsl:value-of select="$revision" />";
      displayName = "<xsl:value-of select="display-name" />";
      archives = {
      <xsl:for-each select="archives/archive[not(host-os)]">
        all = fetchurl {
          url = "<xsl:call-template name="repository-url"/>";
          sha1 = "<xsl:value-of select="complete/checksum" />";
        };
      </xsl:for-each>
      <xsl:for-each select="archives/archive[host-os and not(host-os = 'windows')]">
        <xsl:value-of select="host-os" /> = fetchurl {
          url = "<xsl:call-template name="repository-url"/>";
          sha1 = "<xsl:value-of select="complete/checksum" />";
        };
      </xsl:for-each>
      };
    };
    </xsl:for-each>
  };
}
  </xsl:template>

</xsl:stylesheet>