1// Copyright (C) 2017 The Android Open Source Project 2// 3// Licensed under the Apache License, Version 2.0 (the "License"); 4// you may not use this file except in compliance with the License. 5// You may obtain a copy of the License at 6// 7// http://www.apache.org/licenses/LICENSE-2.0 8// 9// Unless required by applicable law or agreed to in writing, software 10// distributed under the License is distributed on an "AS IS" BASIS, 11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12// See the License for the specific language governing permissions and 13// limitations under the License. 14if (project.ext.has("exoplayerPublishEnabled") 15 && project.ext.exoplayerPublishEnabled) { 16 apply plugin: 'bintray-release' 17 publish { 18 artifactId = releaseArtifact 19 desc = releaseDescription 20 publishVersion = releaseVersion 21 repoName = getBintrayRepo() 22 userOrg = 'google' 23 groupId = 'com.google.android.exoplayer' 24 website = 'https://github.com/google/ExoPlayer' 25 } 26 27 gradle.taskGraph.whenReady { taskGraph -> 28 project.tasks 29 .findAll { task -> task.name.contains("generatePomFileFor") } 30 .forEach { task -> 31 task.doLast { 32 task.outputs.files 33 .filter { File file -> 34 file.path.contains("publications") \ 35 && file.name.matches("^pom-.+\\.xml\$") 36 } 37 .forEach { File file -> addLicense(file) } 38 } 39 } 40 } 41} 42 43def getBintrayRepo() { 44 boolean publicRepo = hasProperty('publicRepo') && 45 property('publicRepo').toBoolean() 46 return publicRepo ? 'exoplayer' : 'exoplayer-test' 47} 48 49static void addLicense(File pom) { 50 def licenseNode = new Node(null, "license") 51 licenseNode.append( 52 new Node(null, "name", "The Apache Software License, Version 2.0")) 53 licenseNode.append( 54 new Node(null, "url", "http://www.apache.org/licenses/LICENSE-2.0.txt")) 55 licenseNode.append(new Node(null, "distribution", "repo")) 56 def licensesNode = new Node(null, "licenses") 57 licensesNode.append(licenseNode) 58 59 def xml = new XmlParser().parse(pom) 60 xml.append(licensesNode) 61 62 def writer = new PrintWriter(new FileWriter(pom)) 63 writer.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n") 64 def printer = new XmlNodePrinter(writer) 65 printer.preserveWhitespace = true 66 printer.print(xml) 67 writer.close() 68} 69