Skip to content

Commit

Permalink
Various updates (#879)
Browse files Browse the repository at this point in the history
* Various updates

* Remove comments

* Fix build

* Fix build

* Fix dex
  • Loading branch information
kageiit authored Jul 17, 2020
1 parent 2bc46b6 commit ca8a17f
Show file tree
Hide file tree
Showing 51 changed files with 189 additions and 199 deletions.
3 changes: 3 additions & 0 deletions .buckconfig
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,7 @@
polyglot_parsing_enabled = true
default_build_file_syntax = SKYLARK

[scala]
target_level = jvm-1.8

<file:.okbuck/config/okbuck.buckconfig>
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ private static String getLibraryArguments(String filename) throws IOException {
File file = new File(filename);

if (!file.isAbsolute()) {
throw new RuntimeException(String.format("%s should be absolute", file));
throw new IllegalStateException(String.format("%s should be absolute", file));
}

String librariesString = read(file.toPath()).trim();
Expand Down
65 changes: 43 additions & 22 deletions buildSrc/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ dependencies {
annotationProcessor deps.build.nullaway

errorprone deps.build.erroproneCompiler
errorproneJavac deps.build.errorproneJavac

compileOnly deps.external.inferAnnotations
compileOnly deps.apt.autoValueAnnotations

Expand All @@ -49,13 +51,15 @@ dependencies {
implementation deps.build.androidPlugin
implementation deps.build.commonsIo
implementation deps.build.commonsLang3
implementation deps.build.kotlinPlugin
implementation deps.build.kotlinAllOpen
implementation deps.build.rockerRuntime
implementation deps.build.jna
implementation deps.build.jnaPlatform
implementation deps.build.kotlinAllOpen
implementation deps.build.kotlinPlugin
implementation deps.build.mavenArtifact
implementation deps.build.rockerRuntime
implementation deps.external.gson
implementation deps.external.guava
implementation deps.lint.lintGradle

testImplementation deps.test.junit
}
Expand All @@ -65,29 +69,37 @@ rocker {
optimize true
extendsClass "com.uber.okbuck.template.core.RuleTemplate"
extendsModelClass "com.uber.okbuck.template.core.Rule"
markAsGenerated true
}

tasks.withType(JavaCompile) {
options.errorprone {
allDisabledChecksAsWarnings = true
disableWarningsInGeneratedCode = true

option("NullAway:AnnotatedPackages", "com.uber")
option("NullAway:TreatGeneratedAsUnannotated", "true")

error("NullAway")

disable("MissingSummary")
disable("BooleanParameter")
disable("FieldCanBeFinal")
disable("RemoveUnusedImports")
disable("AndroidJdkLibsChecker")
disable("Java7ApiChecker")

warn("ConstantField")
warn("MixedArrayDimensions")
warn("MultipleTopLevelClasses")
warn("MultiVariableDeclaration")
warn("PackageLocation")
warn("ThrowsUncheckedException")
warn("UnnecessaryStaticImport")
warn("WildcardImport")
}
options.compilerArgs += [
"-Werror",
"-XepAllDisabledChecksAsWarnings",
"-XepDisableWarningsInGeneratedCode",
"-Xep:NullAway:ERROR",
"-XepOpt:NullAway:AnnotatedPackages=com.uber",
"-XepOpt:NullAway:TreatGeneratedAsUnannotated=true",
"-Xep:BooleanParameter:OFF",
"-Xep:ReturnMissingNullable:OFF",
"-Xep:ConstructorInvokesOverridable:OFF",
"-Xep:FieldCanBeFinal:OFF",
"-Xep:ConstantField:WARN",
"-Xep:MixedArrayDimensions:WARN",
"-Xep:MultipleTopLevelClasses:WARN",
"-Xep:MultiVariableDeclaration:WARN",
"-Xep:PackageLocation:WARN",
"-Xep:RemoveUnusedImports:OFF",
"-Xep:ThrowsUncheckedException:WARN",
"-Xep:UnnecessaryStaticImport:WARN",
"-Xep:WildcardImport:WARN",
"-Werror"
]
}

Expand Down Expand Up @@ -145,3 +157,12 @@ bintray {
}
}
}

tasks.withType(com.fizzed.rocker.gradle.RockerTask).each { task ->
task.doLast {
def tree = fileTree(dir: task.outputDir, include: '**/*.java')
tree.each { file ->
file.text = file.text.replace("@com.fizzed.rocker.Generated", '@javax.annotation.Generated("Rocker")')
}
}
}
10 changes: 1 addition & 9 deletions buildSrc/src/main/java/com/uber/okbuck/OkBuckGradlePlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -230,14 +230,6 @@ public void apply(Project rootProject) {
wrapper.sourceRoots,
wrapper.ignoredDirs);

// Add elements from extraDepCaches to extraDepCachesMap for backwards compatibility
okbuckExt.extraDepCaches.forEach(
depCache -> {
if (!okbuckExt.extraDepCachesMap.containsKey(depCache)) {
okbuckExt.extraDepCachesMap.put(depCache, false);
}
});

Map<String, Configuration> extraConfigurations =
okbuckExt
.extraDepCachesMap
Expand Down Expand Up @@ -375,7 +367,7 @@ private void writeExportedFileRules(Project rootBuckProject, OkBuckExtension okB
.sorted((rule1, rule2) -> rule1.name().compareToIgnoreCase(rule2.name()))
.forEach(rule -> rule.render(os));
} catch (IOException e) {
throw new RuntimeException(e);
throw new IllegalStateException(e);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

public abstract class BuckRuleComposer {

public BuckRuleComposer() {}
protected BuckRuleComposer() {}

public static Set<String> external(Set<OExternalDependency> deps) {
return deps.stream().map(BuckRuleComposer::external).collect(Collectors.toSet());
Expand All @@ -21,7 +21,7 @@ public static String external(OExternalDependency dep) {
try {
return String.format("//%s:%s", dep.getTargetPath(), dep.getTargetName());
} catch (NullPointerException e) {
throw new RuntimeException(e);
throw new IllegalStateException(e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public List<Scope> getAnnotationProcessorScopes(Project project, Configuration c
Map<Set<Dependency>, Scope> autoValueScopeMap = getAutoValueDependencyToScopeMap();

if (!autoValueScopeMap.containsKey(autoValueDependencies)) {
throw new RuntimeException(
throw new IllegalStateException(
"autoValueConfigurations should be present if adding autoValue dependencies. missing: "
+ autoValueDependencies);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public Set<String> getAnnotationProcessors(OExternalDependency externalDependenc
return ImmutableSet.copyOf(processors.split(","));

} catch (IOException e) {
throw new RuntimeException(e);
throw new IllegalStateException(e);
}
}

Expand All @@ -125,7 +125,7 @@ public boolean hasAutoValueExtension(OExternalDependency externalDependency) {
"META-INF/services/com.google.auto.value.extension.AutoValueExtension");
return !extensions.isEmpty();
} catch (IOException e) {
throw new RuntimeException(e);
throw new IllegalStateException(e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.jar.JarFile;
import java.util.stream.Collectors;
import javax.annotation.Nullable;
import org.apache.commons.io.FilenameUtils;
Expand Down Expand Up @@ -84,7 +83,8 @@ public static String shaSum256(File file) {
try {
return Files.asByteSource(file).hash(Hashing.sha256()).toString();
} catch (IOException e) {
throw new RuntimeException(String.format("Failed to calculate shaSum256 of %s", file));
throw new IllegalStateException(
String.format("Failed to calculate shaSum256 of %s", file), e);
}
}

Expand Down Expand Up @@ -116,14 +116,6 @@ static String getModuleClassifier(String fileNameString, @Nullable String versio
}
}

private static long jarComparisonKeyFunction(File file) {
try {
return new JarFile(file).entries().nextElement().getTime();
} catch (IOException e) {
throw new RuntimeException(e);
}
}

public static Set<OExternalDependency> resolveExternal(
Project project,
Configuration configuration,
Expand Down Expand Up @@ -206,7 +198,7 @@ public static void enforceChangingDeps(Project project, Configuration configurat
if (useVersion != null) {
details.useVersion(useVersion);
} else {
throw new RuntimeException(
throw new IllegalStateException(
"Please do not use changing dependencies. They can cause hard to reproduce builds.\n"
+ "Found changing dependency "
+ details.getRequested()
Expand Down Expand Up @@ -244,7 +236,7 @@ static OExternalDependency lowest(Collection<OExternalDependency> dependencyList
.map(OExternalDependency::getVersionless)
.collect(Collectors.toSet());
if (versionless.size() != 1) {
throw new RuntimeException(
throw new IllegalStateException(
String.format(
"Lowest could only be found for the same group:artifactID, found -> %s",
dependencyList));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
if (!(o instanceof OExternalDependency)) {
return false;
}
OExternalDependency that = (OExternalDependency) o;
Expand Down Expand Up @@ -207,7 +207,7 @@ String getSourceFileNameFrom(String prebuiltName) {
if (ImmutableList.of(JAR, AAR).contains(getPackaging())) {
return prebuiltName.replaceFirst("\\.(jar|aar)$", SOURCE_FILE);
}
throw new RuntimeException("Couldn't get sources file name for " + prebuiltName);
throw new IllegalStateException("Couldn't get sources file name for " + prebuiltName);
}

private boolean shouldInclude(OExternalDependency dependency) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public abstract static class Builder {
}

@Override
public String toString() {
public final String toString() {
return this.getMavenCoords() + " -> " + realDependencyFile().toString();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.uber.okbuck.core.dependency;

import com.google.auto.value.AutoValue;
import com.google.common.collect.ImmutableSet;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand All @@ -14,7 +15,7 @@ public abstract class OUnresolvedDependency {

public abstract String version();

public abstract Set<ExcludeRule> excludeRules();
public abstract ImmutableSet<ExcludeRule> excludeRules();

public static Builder builder() {
return new AutoValue_OUnresolvedDependency.Builder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public static VersionlessDependency fromMavenCoords(String s) {
.build();
break;
default:
throw new RuntimeException("Invalid dependency specified: " + s);
throw new IllegalStateException("Invalid dependency specified: " + s);
}
return versionless;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public void resolveCurrentRawDeps() {
Map<String, List<ExternalDependency>> rawDepsMap =
rawDependencies
.stream()
.collect(Collectors.groupingBy(i -> i.getGroup() + ":" + i.getVersion()));
.collect(Collectors.groupingBy(i -> i.getGroup() + "--" + i.getVersion()));

List<Project> allProjects = new ArrayList<>(project.getAllprojects());
int numberOfChunks = allProjects.size();
Expand Down Expand Up @@ -235,7 +235,7 @@ private void validateDependencies(
Collectors.mapping(OExternalDependency::getVersion, Collectors.toSet())));

if (extraDependencies.size() > 0) {
throw new RuntimeException(
throw new IllegalStateException(
"Multiple versions found for external dependencies: \n"
+ mapJoiner.join(extraDependencies));
}
Expand All @@ -255,7 +255,7 @@ private void validateDependencies(
Collectors.mapping(OExternalDependency::getVersion, Collectors.toSet())));

if (singleDependencies.size() > 0) {
throw new RuntimeException(
throw new IllegalStateException(
"Single version found for external dependencies, please remove them from external dependency extension: \n"
+ mapJoiner.join(singleDependencies));
}
Expand Down Expand Up @@ -368,7 +368,7 @@ private static Set<OExternalDependency> childDependencies(
}

private static void dependencyException(ResolvedDependency dependency) {
throw new RuntimeException(
throw new IllegalStateException(
"Couldn't find "
+ dependency
+ " child of parents -> "
Expand All @@ -384,7 +384,7 @@ private void processDependencies(
try {
FileUtils.deleteDirectory(cacheDir);
} catch (IOException e) {
throw new RuntimeException("Could not delete dependency directory: " + cacheDir);
throw new IllegalStateException("Could not delete dependency directory: " + cacheDir, e);
}
}

Expand Down Expand Up @@ -457,7 +457,8 @@ private boolean isPrebuiltDependency(OExternalDependency dependency) {

private static void createSymlinks(Path path, Collection<OExternalDependency> dependencies) {
if (!path.toFile().exists() && !path.toFile().mkdirs()) {
throw new RuntimeException(String.format("Couldn't create %s when creating symlinks", path));
throw new IllegalStateException(
String.format("Couldn't create %s when creating symlinks", path));
}

SetMultimap<VersionlessDependency, OExternalDependency> nameToDependencyMap =
Expand Down Expand Up @@ -510,7 +511,7 @@ private static void persistSha256Cache(Project rootProject, HashMap<String, Stri
try {
FileUtil.persistMapToJsonFile(sha256Map, projectMappingFile);
} catch (IOException e) {
throw new RuntimeException(e);
throw new IllegalStateException(e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@ public final class JetifierManager {
private static final Logger LOG = LoggerFactory.getLogger(JetifierManager.class);

private static final String JETIFIER_LOCATION = OkBuckGradlePlugin.WORKSPACE_PATH + "/jetifier";
private static final String JETIFIER_CONFIG_FILE = "custom_mapping.config";
private static final String JETIFIER_CONFIG_LOCATION =
JETIFIER_LOCATION + "/" + JETIFIER_CONFIG_FILE;
private static final String JETIFIER_BUCK_FILE = JETIFIER_LOCATION + "/BUCK";
private static final String JETIFIER_DEPS_CONFIG = "okbuck_jetifier_deps";
private static final String JETIFIER_GROUP = "com.android.tools.build.jetifier";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ public final class ManifestMergerManager {
private static final String MANIFEST_MERGER_MODULE = "manifest-merger";
private static final String MANIFEST_MERGER_CACHE =
OkBuckGradlePlugin.WORKSPACE_PATH + "/manifest-merger";
private static final String CONFIGURATION_MANIFEST_MERGER = "manifest-merger";
private static final ImmutableSet<String> MANIFEST_MERGER_EXCLUDES =
ImmutableSet.of("META-INF/.*\\\\.SF", "META-INF/.*\\\\.DSA", "META-INF/.*\\\\.RSA");
private static final String MANIFEST_MERGER_CLI_CLASS =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.uber.okbuck.core.dependency.DependencyCache;
import com.uber.okbuck.core.dependency.OExternalDependency;
import com.uber.okbuck.core.util.FileUtil;
import com.uber.okbuck.core.util.MoreCollectors;
import com.uber.okbuck.core.util.ProjectUtil;
import com.uber.okbuck.template.config.SymlinkBuckFile;
import com.uber.okbuck.template.core.Rule;
Expand Down Expand Up @@ -65,7 +66,7 @@ public void download() {
.stream()
.map(dependencyCache::build)
.flatMap(Set::stream)
.collect(com.uber.okbuck.core.util.MoreCollectors.toImmutableSet());
.collect(MoreCollectors.toImmutableSet());
}

public void finalizeDependencies() {
Expand Down Expand Up @@ -106,7 +107,8 @@ enum API {
API_26("8.0.0_r4", "r1"),
API_27("8.1.0", "4611349"),
API_P("P", "4651975"),
API_28("9", "4913185-2");
API_28("9", "4913185-2"),
API_29("10", "5803371");

private final String androidVersion;
private final String frameworkSdkBuildVersion;
Expand Down
Loading

0 comments on commit ca8a17f

Please sign in to comment.