Skip to content

Commit

Permalink
Excavator: Format Java files
Browse files Browse the repository at this point in the history
  • Loading branch information
svc-excavator-bot committed Sep 9, 2019
1 parent 8806a8b commit 7c68b83
Show file tree
Hide file tree
Showing 12 changed files with 193 additions and 102 deletions.
1 change: 1 addition & 0 deletions .baseline/copyright/999_palantir.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(c) Copyright ${today.year} Palantir Technologies Inc. All rights reserved.
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ public LockState readLocks() {
return LockState.from(parseLines(productionDeps), parseLines(testDeps));
} catch (IOException e) {
throw new GradleException(
String.format("Couldn't load versions from palantir dependency lock file: %s", lockfile), e);
String.format("Couldn't load versions from palantir dependency lock file: %s", lockfile),
e);
}
}

Expand All @@ -93,10 +94,11 @@ public Stream<Line> parseLines(Stream<String> stringStream) {

public void writeLocks(FullLockState fullLockState) {
LockState lockState = LockStates.toLockState(fullLockState);
try (BufferedWriter writer = Files.newBufferedWriter(
lockfile,
StandardOpenOption.CREATE,
StandardOpenOption.TRUNCATE_EXISTING)) {
try (
BufferedWriter writer = Files.newBufferedWriter(
lockfile,
StandardOpenOption.CREATE,
StandardOpenOption.TRUNCATE_EXISTING)) {
writer.append(HEADER_COMMENT);
writer.newLine();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,10 @@ private void fixLegacyResolvableJavaConfigurations(Project project, Configuratio
injectVersions(
conf,
(group, name) -> GetVersionPlugin.getOptionalVersion(
project, group, name, unifiedClasspath));
project,
group,
name,
unifiedClasspath));
}));
}

Expand Down
31 changes: 22 additions & 9 deletions src/main/java/com/palantir/gradle/versions/GetVersionPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,10 @@ public void apply(Project project) {
* This is the preferred signature because it's shortest.
*/
public String doCall(Object moduleVersion) {
return doCall(moduleVersion, project.getRootProject()
.getConfigurations()
.getByName(VersionsLockPlugin.UNIFIED_CLASSPATH_CONFIGURATION_NAME));
return doCall(moduleVersion,
project.getRootProject()
.getConfigurations()
.getByName(VersionsLockPlugin.UNIFIED_CLASSPATH_CONFIGURATION_NAME));
}

/** Find a version from another configuration, e.g. from the gradle-docker plugin. */
Expand All @@ -60,9 +61,12 @@ public String doCall(Object moduleVersion, Configuration configuration) {

/** This matches the signature of nebula's dependencyRecommendations.getRecommendedVersion. */
public String doCall(String group, String name) {
return getVersion(project, group, name, project.getRootProject()
.getConfigurations()
.getByName(VersionsLockPlugin.UNIFIED_CLASSPATH_CONFIGURATION_NAME));
return getVersion(project,
group,
name,
project.getRootProject()
.getConfigurations()
.getByName(VersionsLockPlugin.UNIFIED_CLASSPATH_CONFIGURATION_NAME));
}

public String doCall(String group, String name, Configuration configuration) {
Expand All @@ -77,7 +81,10 @@ private static String getVersion(Project project, String group, String name, Con
}

static Optional<String> getOptionalVersion(
Project project, String group, String name, Configuration configuration) {
Project project,
String group,
String name,
Configuration configuration) {
if (GradleWorkarounds.isConfiguring(project.getState())) {
throw new GradleException(
String.format("Not allowed to call gradle-consistent-versions's getVersion(\"%s\", \"%s\", "
Expand All @@ -99,7 +106,10 @@ static Optional<String> getOptionalVersion(

if (list.size() > 1) {
throw new GradleException(String.format("Multiple modules matching '%s:%s' in %s: %s",
group, name, configuration, list));
group,
name,
configuration,
list));
}

return Optional.of(Iterables.getOnlyElement(list).getVersion());
Expand All @@ -116,6 +126,9 @@ private static GradleException notFound(String group, String name, Configuration
return new GradleException(String.format(
"Unable to find '%s:%s' in %s. This may happen if you specify the version in versions.props but do not"
+ " have a dependency in the configuration. The configuration contained:\n%s",
group, name, configuration, actual));
group,
name,
configuration,
actual));
}
}
21 changes: 13 additions & 8 deletions src/main/java/com/palantir/gradle/versions/GradleWorkarounds.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,12 @@ static boolean isConfiguring(ProjectState state) {
Class<?> stateInternal = Class.forName("org.gradle.api.internal.project.ProjectStateInternal");
Object internal = stateInternal.cast(state);
return (boolean) stateInternal.getDeclaredMethod("isConfiguring").invoke(internal);
} catch (ClassNotFoundException | ClassCastException | NoSuchMethodException
| IllegalAccessException | InvocationTargetException e) {
} catch (
ClassNotFoundException
| ClassCastException
| NoSuchMethodException
| IllegalAccessException
| InvocationTargetException e) {
log.warn("Couldn't use ProjectStateInternal to determine whether project is configuring", e);
// This is an approximation the public API exposes.
// It will give us a false negative if we're in 'afterEvaluate'
Expand All @@ -75,14 +79,14 @@ static boolean isConfiguring(ProjectState state) {
static <T> ListProperty<T> fixListProperty(ListProperty<T> property) {
Class<?> propertyInternalClass = org.gradle.api.internal.provider.CollectionPropertyInternal.class;
return (ListProperty<T>) Proxy.newProxyInstance(GradleWorkarounds.class.getClassLoader(),
new Class<?>[]{
new Class<?>[] {
org.gradle.api.internal.provider.CollectionProviderInternal.class,
ListProperty.class},
(proxy, method, args) -> {
// Find matching method on CollectionPropertyInternal
//org.gradle.api.internal.provider.CollectionProviderInternal
if (method.getDeclaringClass()
== org.gradle.api.internal.provider.CollectionProviderInternal.class) {
if (method
.getDeclaringClass() == org.gradle.api.internal.provider.CollectionProviderInternal.class) {
if (method.getName().equals("getElementType")) {
// Proxy to `propertyInternalClass` which we know DefaultListProperty implements.
return propertyInternalClass.getMethod(method.getName(), method.getParameterTypes())
Expand Down Expand Up @@ -112,7 +116,8 @@ static <T> ListProperty<T> fixListProperty(ListProperty<T> property) {
* </ul>
*/
static <T extends ModuleDependency> T fixAttributesOfModuleDependency(
ObjectFactory objectFactory, T dependency) {
ObjectFactory objectFactory,
T dependency) {
if (GradleVersion.current().compareTo(GradleVersion.version("5.6")) >= 0
// Merged on 2019-06-12 so next nightly should be good
|| GradleVersion.current().compareTo(GradleVersion.version("5.6-20190613000000+0000")) >= 0) {
Expand Down Expand Up @@ -166,8 +171,8 @@ private static boolean isPlatformPre53(AttributeContainer attributes) {

static boolean isFailOnVersionConflict(Configuration conf) {
org.gradle.api.internal.artifacts.configurations.ConflictResolution conflictResolution =
((org.gradle.api.internal.artifacts.configurations.ResolutionStrategyInternal)
conf.getResolutionStrategy()).getConflictResolution();
((org.gradle.api.internal.artifacts.configurations.ResolutionStrategyInternal) conf
.getResolutionStrategy()).getConflictResolution();
return conflictResolution == org.gradle.api.internal.artifacts.configurations.ConflictResolution.strict;
}

Expand Down
18 changes: 12 additions & 6 deletions src/main/java/com/palantir/gradle/versions/VerifyLocksTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,31 +84,37 @@ private void verifyLocksForScope(
Set<MyModuleIdentifier> missing = difference.entriesOnlyOnLeft().keySet();
if (!missing.isEmpty()) {
throw new RuntimeException(
"Locked dependencies missing from the resolution result: " + missing + ". "
"Locked dependencies missing from the resolution result: " + missing
+ ". "
+ ". Please run './gradlew --write-locks'.");
}

Set<MyModuleIdentifier> unknown = difference.entriesOnlyOnRight().keySet();
if (!unknown.isEmpty()) {
throw new RuntimeException(
"Found dependencies that were not in the lock state: " + unknown + ". "
"Found dependencies that were not in the lock state: " + unknown
+ ". "
+ "Please run './gradlew --write-locks'.");
}

Map<MyModuleIdentifier, ValueDifference<Line>> differing = difference.entriesDiffering();
if (!differing.isEmpty()) {
throw new RuntimeException("Found dependencies whose dependents changed:\n"
+ formatDependencyDifferences(differing) + "\n\n"
+ formatDependencyDifferences(differing)
+ "\n\n"
+ "Please run './gradlew --write-locks'.");
}
}

private static String formatDependencyDifferences(
Map<MyModuleIdentifier, ValueDifference<Line>> differing) {
return differing.entrySet().stream().map(diff -> String.format("" // to align strings
return differing.entrySet()
.stream()
.map(diff -> String.format("" // to align strings
+ "-%s\n"
+ "+%s",
diff.getValue().leftValue().stringRepresentation(),
diff.getValue().rightValue().stringRepresentation())).collect(Collectors.joining("\n"));
diff.getValue().leftValue().stringRepresentation(),
diff.getValue().rightValue().stringRepresentation()))
.collect(Collectors.joining("\n"));
}
}
Loading

0 comments on commit 7c68b83

Please sign in to comment.