1*30877f79SAndroid Build Coastguard Worker// Copyright (C) 2018 The Android Open Source Project
2*30877f79SAndroid Build Coastguard Worker//
3*30877f79SAndroid Build Coastguard Worker// Licensed under the Apache License, Version 2.0 (the "License");
4*30877f79SAndroid Build Coastguard Worker// you may not use this file except in compliance with the License.
5*30877f79SAndroid Build Coastguard Worker// You may obtain a copy of the License at
6*30877f79SAndroid Build Coastguard Worker//
7*30877f79SAndroid Build Coastguard Worker//      http://www.apache.org/licenses/LICENSE-2.0
8*30877f79SAndroid Build Coastguard Worker//
9*30877f79SAndroid Build Coastguard Worker// Unless required by applicable law or agreed to in writing, software
10*30877f79SAndroid Build Coastguard Worker// distributed under the License is distributed on an "AS IS" BASIS,
11*30877f79SAndroid Build Coastguard Worker// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12*30877f79SAndroid Build Coastguard Worker// See the License for the specific language governing permissions and
13*30877f79SAndroid Build Coastguard Worker// limitations under the License.
14*30877f79SAndroid Build Coastguard Workerext.fixJavadoc = {
15*30877f79SAndroid Build Coastguard Worker  def javadocPath = "${project.buildDir}/docs/javadoc"
16*30877f79SAndroid Build Coastguard Worker  // Fix external Android links to target the top frame.
17*30877f79SAndroid Build Coastguard Worker  def androidRoot = "https://developer.android.com/reference/"
18*30877f79SAndroid Build Coastguard Worker  def androidLink = "<a href=\"(${androidRoot}.*?)\\?is-external=true(.*)\""
19*30877f79SAndroid Build Coastguard Worker  def androidFixed = "<a href=\"\\1\\2\" target=\"_top\""
20*30877f79SAndroid Build Coastguard Worker  ant.replaceregexp(match:androidLink, replace:androidFixed, flags:'g') {
21*30877f79SAndroid Build Coastguard Worker    fileset(dir: "${javadocPath}", includes: "**/*.html")
22*30877f79SAndroid Build Coastguard Worker  }
23*30877f79SAndroid Build Coastguard Worker  // Add favicon to each page
24*30877f79SAndroid Build Coastguard Worker  def headTag = "<head>"
25*30877f79SAndroid Build Coastguard Worker  def headTagWithFavicon = "<head>" +
26*30877f79SAndroid Build Coastguard Worker    "<!-- start favicons snippet, use https://realfavicongenerator.net/ -->" +
27*30877f79SAndroid Build Coastguard Worker    "<link rel=\"apple-touch-icon\" sizes=\"180x180\" href=\"/assets/apple-touch-icon.png\">" +
28*30877f79SAndroid Build Coastguard Worker    "<link rel=\"icon\" type=\"image/png\" sizes=\"32x32\" href=\"/assets/favicon-32x32.png\">" +
29*30877f79SAndroid Build Coastguard Worker    "<link rel=\"icon\" type=\"image/png\" sizes=\"16x16\" href=\"/assets/favicon-16x16.png\">" +
30*30877f79SAndroid Build Coastguard Worker    "<link rel=\"manifest\" href=\"/assets/site.webmanifest\">" +
31*30877f79SAndroid Build Coastguard Worker    "<link rel=\"mask-icon\" href=\"/assets/safari-pinned-tab.svg\" color=\"#fc4d50\">" +
32*30877f79SAndroid Build Coastguard Worker    "<link rel=\"shortcut icon\" href=\"/assets/favicon.ico\">" +
33*30877f79SAndroid Build Coastguard Worker    "<meta name=\"msapplication-TileColor\" content=\"#ffc40d\">" +
34*30877f79SAndroid Build Coastguard Worker    "<meta name=\"msapplication-config\" content=\"/assets/browserconfig.xml\">" +
35*30877f79SAndroid Build Coastguard Worker    "<meta name=\"theme-color\" content=\"#ffffff\">" +
36*30877f79SAndroid Build Coastguard Worker    "<!-- end favicons snippet -->"
37*30877f79SAndroid Build Coastguard Worker  ant.replaceregexp(match:headTag, replace:headTagWithFavicon, flags:'g') {
38*30877f79SAndroid Build Coastguard Worker    fileset(dir: "${javadocPath}", includes: "**/*.html")
39*30877f79SAndroid Build Coastguard Worker  }
40*30877f79SAndroid Build Coastguard Worker  // Remove date metadata that changes every time Javadoc is generated.
41*30877f79SAndroid Build Coastguard Worker  def javadocGeneratedBy = "<!-- Generated by javadoc.*?-->\n"
42*30877f79SAndroid Build Coastguard Worker  ant.replaceregexp(match:javadocGeneratedBy, replace:"") {
43*30877f79SAndroid Build Coastguard Worker    fileset(dir: "${javadocPath}", includes: "**/*.html")
44*30877f79SAndroid Build Coastguard Worker  }
45*30877f79SAndroid Build Coastguard Worker  def dateMeta = "<meta name=\"date\".*?>\n"
46*30877f79SAndroid Build Coastguard Worker  ant.replaceregexp(match:dateMeta, replace:"") {
47*30877f79SAndroid Build Coastguard Worker    fileset(dir: "${javadocPath}", includes: "**/*.html")
48*30877f79SAndroid Build Coastguard Worker  }
49*30877f79SAndroid Build Coastguard Worker}
50