Search in sources :

Example 1 with KeystoreProperties

use of com.facebook.buck.android.KeystoreProperties in project buck by facebook.

the class ReDexStepTest method constructorArgsAreUsedToCreateShellCommand.

@Test
public void constructorArgsAreUsedToCreateShellCommand() {
    Path workingDirectory = Paths.get("/where/the/code/is");
    List<String> redexBinaryArgs = ImmutableList.of("/usr/bin/redex");
    Map<String, String> redexEnvironmentVariables = ImmutableMap.of("REDEX_DEBUG", "1");
    Path inputApkPath = Paths.get("buck-out/gen/app.apk.zipalign");
    Path outputApkPath = Paths.get("buck-out/gen/app.apk");
    Path keystorePath = Paths.get("keystores/debug.keystore");
    KeystoreProperties keystoreProperties = new KeystoreProperties(keystorePath, "storepass", "keypass", "alias");
    Supplier<KeystoreProperties> keystorePropertiesSupplier = Suppliers.ofInstance(keystoreProperties);
    Path redexConfigPath = Paths.get("redex/redex-config.json");
    Optional<Path> redexConfig = Optional.of(redexConfigPath);
    ImmutableList<Arg> redexExtraArgs = ImmutableList.of(StringArg.of("foo"), StringArg.of("bar"));
    Path proguardMap = Paths.get("buck-out/gen/app/__proguard__/mapping.txt");
    Path proguardConfig = Paths.get("app.proguard.config");
    Path seeds = Paths.get("buck-out/gen/app/__proguard__/seeds.txt");
    SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer())));
    ReDexStep redex = new ReDexStep(workingDirectory, redexBinaryArgs, redexEnvironmentVariables, inputApkPath, outputApkPath, keystorePropertiesSupplier, redexConfig, redexExtraArgs, proguardMap, proguardConfig, seeds, pathResolver);
    assertEquals("redex", redex.getShortName());
    AndroidPlatformTarget androidPlatform = EasyMock.createMock(AndroidPlatformTarget.class);
    Path sdkDirectory = Paths.get("/Users/user/android-sdk-macosx");
    EasyMock.expect(androidPlatform.getSdkDirectory()).andReturn(Optional.of(sdkDirectory));
    EasyMock.replay(androidPlatform);
    ExecutionContext context = TestExecutionContext.newBuilder().setAndroidPlatformTargetSupplier(Suppliers.ofInstance(androidPlatform)).build();
    assertEquals(ImmutableMap.of("ANDROID_SDK", sdkDirectory.toString(), "REDEX_DEBUG", "1"), redex.getEnvironmentVariables(context));
    EasyMock.verify(androidPlatform);
    assertEquals(ImmutableList.of("/usr/bin/redex", "--config", redexConfigPath.toString(), "--sign", "--keystore", keystorePath.toString(), "--keyalias", "alias", "--keypass", "keypass", "--proguard-map", proguardMap.toString(), "-P", proguardConfig.toString(), "--keep", seeds.toString(), "--out", outputApkPath.toString(), "foo", "bar", inputApkPath.toString()), redex.getShellCommandInternal(context));
}
Also used : Path(java.nio.file.Path) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) AndroidPlatformTarget(com.facebook.buck.android.AndroidPlatformTarget) ExecutionContext(com.facebook.buck.step.ExecutionContext) TestExecutionContext(com.facebook.buck.step.TestExecutionContext) Arg(com.facebook.buck.rules.args.Arg) StringArg(com.facebook.buck.rules.args.StringArg) KeystoreProperties(com.facebook.buck.android.KeystoreProperties) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) Test(org.junit.Test)

Example 2 with KeystoreProperties

use of com.facebook.buck.android.KeystoreProperties in project buck by facebook.

the class Project method createModuleForProjectConfig.

@SuppressWarnings("PMD.LooseCoupling")
private SerializableModule createModuleForProjectConfig(ProjectConfig projectConfig, Optional<Path> rJava) throws IOException {
    BuildRule projectRule = Preconditions.checkNotNull(projectConfig.getProjectRule());
    Preconditions.checkState(projectRule instanceof AndroidBinary || projectRule instanceof AndroidLibrary || projectRule instanceof AndroidResource || projectRule instanceof JavaBinary || projectRule instanceof JavaLibrary || projectRule instanceof JavaTest || projectRule instanceof CxxLibrary || projectRule instanceof NdkLibrary, "project_config() does not know how to process a src_target of type %s (%s).", projectRule.getType(), projectRule.getBuildTarget());
    LinkedHashSet<SerializableDependentModule> dependencies = Sets.newLinkedHashSet();
    final BuildTarget target = projectConfig.getBuildTarget();
    SerializableModule module = new SerializableModule(projectRule, target);
    module.name = getIntellijNameForRule(projectRule);
    module.isIntelliJPlugin = projectConfig.getIsIntelliJPlugin();
    Path relativePath = projectConfig.getBuildTarget().getBasePath();
    module.pathToImlFile = relativePath.resolve(module.name + ".iml");
    // List the module source as the first dependency.
    boolean includeSourceFolder = true;
    // Do the tests before the sources so they appear earlier in the classpath. When tests are run,
    // their classpath entries may be deliberately shadowing production classpath entries.
    // tests folder
    boolean hasSourceFoldersForTestRule = addSourceFolders(module, projectConfig.getTestRule(), projectConfig.getTestsSourceRoots(), true);
    // test dependencies
    BuildRule testRule = projectConfig.getTestRule();
    if (testRule != null) {
        walkRuleAndAdd(testRule, true, /* isForTests */
        dependencies, projectConfig.getSrcRule());
    }
    // src folder
    boolean hasSourceFoldersForSrcRule = addSourceFolders(module, projectConfig.getSrcRule(), projectConfig.getSourceRoots(), false);
    addRootExcludes(module, projectConfig.getSrcRule(), projectFilesystem);
    // non-library Android project with no source roots specified.
    if (!hasSourceFoldersForTestRule && !hasSourceFoldersForSrcRule) {
        includeSourceFolder = false;
    }
    // IntelliJ expects all Android projects to have a gen/ folder, even if there is no src/
    // directory specified.
    boolean isAndroidRule = projectRule.getProperties().is(ANDROID);
    if (isAndroidRule) {
        boolean hasSourceFolders = !module.sourceFolders.isEmpty();
        module.sourceFolders.add(SerializableModule.SourceFolder.GEN);
        if (!hasSourceFolders) {
            includeSourceFolder = true;
        }
    }
    // src dependencies
    // Note that isForTests is false even if projectRule is the project_config's test_target.
    walkRuleAndAdd(projectRule, false, /* isForTests */
    dependencies, projectConfig.getSrcRule());
    Path basePath = projectConfig.getBuildTarget().getBasePath();
    // Specify another path for intellij to generate gen/ for each android module,
    // so that it will not disturb our glob() rules.
    // To specify the location of gen, Intellij requires the relative path from
    // the base path of current build target.
    module.moduleGenPath = generateRelativeGenPath(projectFilesystem, basePath);
    if (turnOffAutoSourceGeneration && rJava.isPresent()) {
        module.moduleRJavaPath = basePath.relativize(Paths.get("")).resolve(rJava.get());
    }
    SerializableDependentModule jdkDependency;
    if (isAndroidRule) {
        // android details
        if (projectRule instanceof NdkLibrary) {
            NdkLibrary ndkLibrary = (NdkLibrary) projectRule;
            module.isAndroidLibraryProject = true;
            module.keystorePath = null;
            module.nativeLibs = relativePath.relativize(ndkLibrary.getLibraryPath());
        } else if (projectRule instanceof AndroidLibrary) {
            module.isAndroidLibraryProject = true;
            module.keystorePath = null;
            module.resFolder = intellijConfig.getAndroidResources().orElse(null);
            module.assetFolder = intellijConfig.getAndroidAssets().orElse(null);
        } else if (projectRule instanceof AndroidResource) {
            AndroidResource androidResource = (AndroidResource) projectRule;
            module.resFolder = createRelativeResourcesPath(Optional.ofNullable(androidResource.getRes()).map(resolver::getAbsolutePath).map(projectFilesystem::relativize).orElse(null), target);
            module.isAndroidLibraryProject = true;
            module.keystorePath = null;
        } else if (projectRule instanceof AndroidBinary) {
            AndroidBinary androidBinary = (AndroidBinary) projectRule;
            module.resFolder = intellijConfig.getAndroidResources().orElse(null);
            module.assetFolder = intellijConfig.getAndroidAssets().orElse(null);
            module.isAndroidLibraryProject = false;
            module.binaryPath = generateRelativeAPKPath(projectFilesystem, projectRule.getBuildTarget().getShortName(), basePath);
            KeystoreProperties keystoreProperties = KeystoreProperties.createFromPropertiesFile(resolver.getAbsolutePath(androidBinary.getKeystore().getPathToStore()), resolver.getRelativePath(androidBinary.getKeystore().getPathToPropertiesFile()), projectFilesystem);
            // getKeystore() returns an absolute path, but an IntelliJ module
            // expects the path to the keystore to be relative to the module root.
            // First, grab the aboslute path to the project config.
            BuildTarget projectTarget = projectConfig.getBuildTarget();
            Path modulePath = projectTarget.getCellPath().resolve(projectTarget.getBasePath());
            // Now relativize to the keystore path, which is absolute too.
            module.keystorePath = modulePath.relativize(keystoreProperties.getKeystore());
        } else {
            module.isAndroidLibraryProject = true;
            module.keystorePath = null;
        }
        module.hasAndroidFacet = true;
        module.proguardConfigPath = null;
        module.androidManifest = resolveAndroidManifestRelativePath(basePath);
        // List this last so that classes from modules can shadow classes in the JDK.
        jdkDependency = SerializableDependentModule.newInheritedJdk();
    } else {
        module.hasAndroidFacet = false;
        if (module.isIntelliJPlugin()) {
            jdkDependency = SerializableDependentModule.newIntelliJPluginJdk();
        } else {
            jdkDependency = SerializableDependentModule.newStandardJdk(intellijConfig.getJdkName(), intellijConfig.getJdkType());
        }
    }
    // Assign the dependencies.
    module.setModuleDependencies(createDependenciesInOrder(includeSourceFolder, dependencies, jdkDependency));
    // Annotation processing generates sources for IntelliJ to consume, but does so outside
    // the module directory to avoid messing up globbing.
    JavaLibrary javaLibrary = null;
    if (projectRule instanceof JavaLibrary) {
        javaLibrary = (JavaLibrary) projectRule;
    }
    if (javaLibrary != null) {
        Optional<Path> processingParams = javaLibrary.getGeneratedSourcePath();
        if (processingParams.isPresent()) {
            module.annotationGenPath = basePath.relativize(processingParams.get());
            module.annotationGenIsForTest = !hasSourceFoldersForSrcRule;
        }
    }
    return module;
}
Also used : Path(java.nio.file.Path) PathSourcePath(com.facebook.buck.rules.PathSourcePath) SourcePath(com.facebook.buck.rules.SourcePath) CxxLibrary(com.facebook.buck.cxx.CxxLibrary) AndroidBinary(com.facebook.buck.android.AndroidBinary) JavaBinary(com.facebook.buck.jvm.java.JavaBinary) AndroidResource(com.facebook.buck.android.AndroidResource) JavaLibrary(com.facebook.buck.jvm.java.JavaLibrary) AndroidLibrary(com.facebook.buck.android.AndroidLibrary) BuildTarget(com.facebook.buck.model.BuildTarget) JavaTest(com.facebook.buck.jvm.java.JavaTest) BuildRule(com.facebook.buck.rules.BuildRule) NdkLibrary(com.facebook.buck.android.NdkLibrary) KeystoreProperties(com.facebook.buck.android.KeystoreProperties)

Example 3 with KeystoreProperties

use of com.facebook.buck.android.KeystoreProperties in project buck by facebook.

the class ReDexStep method getShellCommandInternal.

@Override
protected ImmutableList<String> getShellCommandInternal(ExecutionContext context) {
    ImmutableList.Builder<String> args = ImmutableList.<String>builder();
    // In practice, redexBinaryArgs is likely to be a single argument, which is the path to the
    // ReDex binary.
    args.addAll(redexBinaryArgs);
    // Config is optional.
    if (redexConfig.isPresent()) {
        args.add("--config", redexConfig.get().toString());
    }
    // Signing args.
    KeystoreProperties keystoreProperties = keystorePropertiesSupplier.get();
    args.add("--sign");
    args.add("--keystore", keystoreProperties.getKeystore().toString(), "--keyalias", keystoreProperties.getAlias(), "--keypass", keystoreProperties.getKeypass());
    // Proguard args.
    args.add("--proguard-map", proguardMap.toString());
    args.add("-P", proguardCommandLine.toString());
    args.add("--keep", seeds.toString());
    args.add("--out", outputApkPath.toString());
    args.addAll(Arg.stringify(redexExtraArgs, pathResolver));
    args.add(inputApkPath.toString());
    return args.build();
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) KeystoreProperties(com.facebook.buck.android.KeystoreProperties)

Aggregations

KeystoreProperties (com.facebook.buck.android.KeystoreProperties)3 Path (java.nio.file.Path)2 AndroidBinary (com.facebook.buck.android.AndroidBinary)1 AndroidLibrary (com.facebook.buck.android.AndroidLibrary)1 AndroidPlatformTarget (com.facebook.buck.android.AndroidPlatformTarget)1 AndroidResource (com.facebook.buck.android.AndroidResource)1 NdkLibrary (com.facebook.buck.android.NdkLibrary)1 CxxLibrary (com.facebook.buck.cxx.CxxLibrary)1 JavaBinary (com.facebook.buck.jvm.java.JavaBinary)1 JavaLibrary (com.facebook.buck.jvm.java.JavaLibrary)1 JavaTest (com.facebook.buck.jvm.java.JavaTest)1 BuildTarget (com.facebook.buck.model.BuildTarget)1 BuildRule (com.facebook.buck.rules.BuildRule)1 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)1 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)1 PathSourcePath (com.facebook.buck.rules.PathSourcePath)1 SourcePath (com.facebook.buck.rules.SourcePath)1 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)1 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)1 Arg (com.facebook.buck.rules.args.Arg)1