| /* |
| * Copyright 2012-present Facebook, Inc. |
| * |
| * Licensed under the Apache License, Version 2.0 (the "License"); you may |
| * not use this file except in compliance with the License. You may obtain |
| * a copy of the License at |
| * |
| * http://www.apache.org/licenses/LICENSE-2.0 |
| * |
| * Unless required by applicable law or agreed to in writing, software |
| * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| * License for the specific language governing permissions and limitations |
| * under the License. |
| */ |
| |
| package com.facebook.buck.android; |
| |
| import com.facebook.buck.step.ExecutionContext; |
| import com.facebook.buck.shell.ShellStep; |
| import com.facebook.buck.util.KeystoreProperties; |
| import com.facebook.buck.util.ProjectFilesystem; |
| import com.google.common.annotations.VisibleForTesting; |
| import com.google.common.base.Preconditions; |
| import com.google.common.collect.ImmutableList; |
| |
| import java.io.IOException; |
| |
| public class ReadKeystorePropertiesAndSignApkStep extends ShellStep { |
| |
| private final String pathToKeystorePropertiesFile; |
| private final String unsignedApk; |
| private final String outputPath; |
| private final ProjectFilesystem projectFilesystem; |
| |
| /** This will be initialized during {@link #setup(com.facebook.buck.step.ExecutionContext)}. */ |
| private SignApkStep signApkCommand; |
| |
| public ReadKeystorePropertiesAndSignApkStep( |
| String pathToKeystorePropertiesFile, |
| String unsignedApk, |
| String outputPath, |
| ProjectFilesystem projectFilesystem) { |
| super(String.format("sign %s using the values in %s", |
| unsignedApk, |
| pathToKeystorePropertiesFile)); |
| this.pathToKeystorePropertiesFile = Preconditions.checkNotNull(pathToKeystorePropertiesFile); |
| this.unsignedApk = Preconditions.checkNotNull(unsignedApk); |
| this.outputPath = Preconditions.checkNotNull(outputPath); |
| this.projectFilesystem = Preconditions.checkNotNull(projectFilesystem); |
| } |
| |
| @Override |
| public void setup(ExecutionContext context) throws IOException { |
| KeystoreProperties keystoreProperties = KeystoreProperties.createFromPropertiesFile( |
| pathToKeystorePropertiesFile, projectFilesystem); |
| this.signApkCommand = new SignApkStep(outputPath, |
| unsignedApk, |
| keystoreProperties.getKeystore(), |
| keystoreProperties.getStorepass(), |
| keystoreProperties.getKeypass(), |
| keystoreProperties.getAlias()); |
| } |
| |
| @Override |
| public String getShortName(ExecutionContext context) { |
| return "sign apk"; |
| } |
| |
| @Override |
| protected ImmutableList<String> getShellCommandInternal(ExecutionContext context) { |
| Preconditions.checkNotNull(signApkCommand, |
| "setup() must be invoked before shell command args are returned."); |
| return signApkCommand.getShellCommand(context); |
| } |
| |
| @VisibleForTesting |
| SignApkStep getSignApkCommand() { |
| return signApkCommand; |
| } |
| } |