Skip to content

Commit

Permalink
Allow multiple exported files at same level (#717)
Browse files Browse the repository at this point in the history
  • Loading branch information
kageiit authored Sep 11, 2018
1 parent 62b5d85 commit 0fa32de
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 35 deletions.
Binary file added app/debug.keystore
Binary file not shown.
8 changes: 7 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,13 @@ def addCommonConfigurationForAndroidModules(Project project) {
project.android {
signingConfigs {
debug {
storeFile project.rootProject.file("config/signing/debug.keystore")
if (project.path.equals(":kotlin-app")) {
storeFile project.rootProject.file("config/signing/debug_2.keystore")
} else if (project.path.equals(":app")) {
storeFile project.file("debug.keystore")
} else {
storeFile project.rootProject.file("config/signing/debug.keystore")
}
}
}
buildTypes {
Expand Down
72 changes: 42 additions & 30 deletions buildSrc/src/main/java/com/uber/okbuck/OkBuckGradlePlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,14 @@
import com.uber.okbuck.extension.WrapperExtension;
import com.uber.okbuck.generator.BuckFileGenerator;
import com.uber.okbuck.template.common.ExportFile;
import com.uber.okbuck.template.core.Rule;
import com.uber.okbuck.wrapper.BuckWrapperTask;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
Expand Down Expand Up @@ -76,7 +79,7 @@ public class OkBuckGradlePlugin implements Plugin<Project> {

public static final String OKBUCK_STATE = OKBUCK_STATE_DIR + "/STATE";
public final Map<Project, Map<String, Scope>> scopes = new ConcurrentHashMap<>();
public final Set<String> keystores = Sets.newConcurrentHashSet();
public final Set<String> exportedPaths = Sets.newConcurrentHashSet();

public DependencyCache depCache;
public DependencyCache lintDepCache;
Expand Down Expand Up @@ -169,6 +172,7 @@ public void apply(Project rootProject) {
transformManager.finalizeDependencies();
buckManager.finalizeDependencies();
manifestMergerManager.finalizeDependencies();
writeExportedFileRules(rootBuckProject, okbuckExt);
});

WrapperExtension wrapper = okbuckExt.getWrapperExtension();
Expand All @@ -195,20 +199,6 @@ public void apply(Project rootProject) {
.getConfigurations()
.maybeCreate(cacheName + "ExtraDepCache")));

Set<String> currentProjectPaths =
okbuckExt
.buckProjects
.stream()
.filter(project -> ProjectUtil.getType(project) != ProjectType.UNKNOWN)
.map(
project ->
rootBuckProject
.getProjectDir()
.toPath()
.relativize(project.getProjectDir().toPath())
.toString())
.collect(MoreCollectors.toImmutableSet());

setupOkbuck.doFirst(
task -> {
if (System.getProperty("okbuck.wrapper", "false").equals("false")) {
Expand Down Expand Up @@ -255,27 +245,13 @@ public void apply(Project rootProject) {
buckManager.setupBuckBinary();

manifestMergerManager.fetchManifestMergerDeps();

// Write out keystore rules
for (String keystore : keystores) {
File keystoreFile = rootBuckProject.file(keystore);
File containingDir = keystoreFile.getParentFile();
File buckFile = new File(containingDir, BUCK);
try (OutputStream os =
new FileOutputStream(
buckFile, currentProjectPaths.contains(containingDir.toString()))) {
new ExportFile().name(keystoreFile.getName()).render(os);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
});

// Create clean task
Task okBuckClean =
rootBuckProject
.getTasks()
.create(OKBUCK_CLEAN, OkBuckCleanTask.class, currentProjectPaths);
.create(OKBUCK_CLEAN, OkBuckCleanTask.class, okbuckExt.buckProjects);
rootOkBuckTask.dependsOn(okBuckClean);

// Create okbuck task on each project to generate their buck file
Expand All @@ -294,4 +270,40 @@ public void apply(Project rootProject) {
});
});
}

private void writeExportedFileRules(Project rootBuckProject, OkBuckExtension okBuckExtension) {
Set<String> currentProjectPaths =
okBuckExtension
.buckProjects
.stream()
.filter(project -> ProjectUtil.getType(project) != ProjectType.UNKNOWN)
.map(
project ->
rootBuckProject
.getProjectDir()
.toPath()
.relativize(project.getProjectDir().toPath())
.toString())
.collect(MoreCollectors.toImmutableSet());
Map<String, Set<Rule>> pathToRules = new HashMap<>();
for (String exportedPath : exportedPaths) {
File exportedFile = rootBuckProject.file(exportedPath);
String containingPath =
FileUtil.getRelativePath(rootBuckProject.getProjectDir(), exportedFile.getParentFile());
Set<Rule> rules = pathToRules.getOrDefault(containingPath, new HashSet<>());
rules.add(new ExportFile().name(exportedFile.getName()));
pathToRules.put(containingPath, rules);
}
for (Map.Entry<String, Set<Rule>> entry : pathToRules.entrySet()) {
File buckFile = new File(entry.getKey(), BUCK);
try (OutputStream os =
new FileOutputStream(buckFile, currentProjectPaths.contains(entry.getKey()))) {
for (Rule rule : entry.getValue()) {
rule.render(os);
}
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ private Keystore extractKeystore() {
if (config != null) {
String keystoreFilePath =
FileUtil.getRelativePath(getRootProject().getProjectDir(), config.getStoreFile());
ProjectUtil.getPlugin(getProject()).keystores.add(keystoreFilePath);
ProjectUtil.getPlugin(getProject()).exportedPaths.add(keystoreFilePath);
return Keystore.create(
keystoreFilePath,
config.getKeyAlias(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets;
import com.uber.okbuck.OkBuckGradlePlugin;
import com.uber.okbuck.core.model.base.ProjectType;
import com.uber.okbuck.core.util.FileUtil;
import com.uber.okbuck.core.util.MoreCollectors;
import com.uber.okbuck.core.util.ProjectUtil;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
Expand All @@ -22,11 +24,11 @@
@SuppressWarnings({"WeakerAccess", "CanBeFinal", "unused", "ResultOfMethodCallIgnored", "NewApi"})
public class OkBuckCleanTask extends DefaultTask {

@Input public Set<String> currentProjectPaths;
@Input public Set<Project> projects;

@Inject
public OkBuckCleanTask(Set<String> currentProjectPaths) {
this.currentProjectPaths = currentProjectPaths;
public OkBuckCleanTask(Set<Project> projects) {
this.projects = projects;
}

@TaskAction
Expand All @@ -52,6 +54,20 @@ void clean() throws IOException {
okbuckState.createNewFile();
}

Set<String> currentProjectPaths =
projects
.stream()
.filter(project -> ProjectUtil.getType(project) != ProjectType.UNKNOWN)
.map(
project ->
project
.getRootProject()
.getProjectDir()
.toPath()
.relativize(project.getProjectDir().toPath())
.toString())
.collect(MoreCollectors.toImmutableSet());

Sets.SetView<String> difference = Sets.difference(lastProjectPaths, currentProjectPaths);

// Delete stale project's BUCK file
Expand Down
Binary file added config/signing/debug_2.keystore
Binary file not shown.

0 comments on commit 0fa32de

Please sign in to comment.