diff --git a/build.gradle b/build.gradle index cde6233a2..5e95ba5c5 100644 --- a/build.gradle +++ b/build.gradle @@ -13,7 +13,7 @@ buildscript { classpath 'com.netflix.nebula:nebula-publishing-plugin:14.1.1' classpath 'com.netflix.nebula:gradle-info-plugin:5.2.0' classpath 'com.palantir.gradle.consistentversions:gradle-consistent-versions:1.12.4' - classpath 'com.palantir.baseline:gradle-baseline-java:2.39.0' + classpath 'com.palantir.baseline:gradle-baseline-java:2.40.0' classpath 'com.palantir.gradle.gitversion:gradle-git-version:0.12.2' classpath 'gradle.plugin.org.inferred:gradle-processors:3.1.0' classpath "com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.4" diff --git a/src/main/java/com/palantir/gradle/versions/ConflictSafeLockFile.java b/src/main/java/com/palantir/gradle/versions/ConflictSafeLockFile.java index 014b030e5..fa69a4eeb 100644 --- a/src/main/java/com/palantir/gradle/versions/ConflictSafeLockFile.java +++ b/src/main/java/com/palantir/gradle/versions/ConflictSafeLockFile.java @@ -82,12 +82,13 @@ public Stream parseLines(Stream stringStream) { line); return matcher; }) - .map(matcher -> ImmutableLine.of( - matcher.group("group"), - matcher.group("artifact"), - matcher.group("version"), - Integer.parseInt(matcher.group("num")), - matcher.group("hash"))); + .map(matcher -> + ImmutableLine.of( + matcher.group("group"), + matcher.group("artifact"), + matcher.group("version"), + Integer.parseInt(matcher.group("num")), + matcher.group("hash"))); } public void writeLocks(FullLockState fullLockState) { diff --git a/src/main/java/com/palantir/gradle/versions/FixLegacyJavaConfigurationsPlugin.java b/src/main/java/com/palantir/gradle/versions/FixLegacyJavaConfigurationsPlugin.java index d1372a1d1..9a0357596 100644 --- a/src/main/java/com/palantir/gradle/versions/FixLegacyJavaConfigurationsPlugin.java +++ b/src/main/java/com/palantir/gradle/versions/FixLegacyJavaConfigurationsPlugin.java @@ -85,9 +85,10 @@ private void injectVersions(Configuration conf, GetVersion getVersion) { // don't interfere with the way forces trump everything for (ModuleVersionSelector force : conf.getResolutionStrategy().getForcedModules()) { if (requested.getGroup().equals(force.getGroup()) && requested.getName().equals(force.getName())) { - details.because(String.format( - "Would have recommended a version for %s:%s, but a force is in place", - requested.getGroup(), requested.getName())); + details.because( + String.format( + "Would have recommended a version for %s:%s, but a force is in place", + requested.getGroup(), requested.getName())); return; } } diff --git a/src/main/java/com/palantir/gradle/versions/GetVersionPlugin.java b/src/main/java/com/palantir/gradle/versions/GetVersionPlugin.java index a05d8a77a..1dd50959f 100644 --- a/src/main/java/com/palantir/gradle/versions/GetVersionPlugin.java +++ b/src/main/java/com/palantir/gradle/versions/GetVersionPlugin.java @@ -83,11 +83,12 @@ private static String getVersion(Project project, String group, String name, Con static Optional getOptionalVersion( 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\", " - + "configurations.%s) " - + "at configuration time", - group, name, configuration.getName())); + throw new GradleException( + String.format( + "Not allowed to call gradle-consistent-versions's getVersion(\"%s\", \"%s\", " + + "configurations.%s) " + + "at configuration time", + group, name, configuration.getName())); } List list = @@ -113,9 +114,11 @@ private static GradleException notFound(String group, String name, Configuration .map(ResolvedComponentResult::getModuleVersion) .map(mvi -> String.format("\t- %s:%s:%s", mvi.getGroup(), mvi.getName(), mvi.getVersion())) .collect(Collectors.joining("\n")); - 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)); + 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)); } } diff --git a/src/main/java/com/palantir/gradle/versions/GradleComparators.java b/src/main/java/com/palantir/gradle/versions/GradleComparators.java index 8e3b52e2d..7e6008746 100644 --- a/src/main/java/com/palantir/gradle/versions/GradleComparators.java +++ b/src/main/java/com/palantir/gradle/versions/GradleComparators.java @@ -36,8 +36,9 @@ private GradleComparators() {} */ public static final Comparator COMPONENT_IDENTIFIER_COMPARATOR = Comparator.comparing( (ComponentIdentifier id) -> tryCast(ModuleComponentIdentifier.class, id), - Comparators.emptiesFirst(Ordering.from(MODULE_IDENTIFIER_COMPARATOR) - .onResultOf(ModuleComponentIdentifier::getModuleIdentifier))) + Comparators.emptiesFirst( + Ordering.from(MODULE_IDENTIFIER_COMPARATOR) + .onResultOf(ModuleComponentIdentifier::getModuleIdentifier))) .thenComparing(ComponentIdentifier::getDisplayName); static Optional tryCast(Class to, A value) { diff --git a/src/main/java/com/palantir/gradle/versions/GradleWorkarounds.java b/src/main/java/com/palantir/gradle/versions/GradleWorkarounds.java index c488080d4..01101df35 100644 --- a/src/main/java/com/palantir/gradle/versions/GradleWorkarounds.java +++ b/src/main/java/com/palantir/gradle/versions/GradleWorkarounds.java @@ -77,28 +77,31 @@ static boolean isConfiguring(ProjectState state) { @SuppressWarnings("unchecked") static ListProperty fixListProperty(ListProperty property) { Class propertyInternalClass = org.gradle.api.internal.provider.CollectionPropertyInternal.class; - return (ListProperty) Proxy.newProxyInstance( - GradleWorkarounds.class.getClassLoader(), - 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.getName().equals("getElementType")) { - // Proxy to `propertyInternalClass` which we know DefaultListProperty implements. - return propertyInternalClass - .getMethod(method.getName(), method.getParameterTypes()) - .invoke(property, args); - } else if (method.getName().equals("size")) { - return property.get().size(); - } - throw new GradleException( - String.format("Could not proxy method '%s' to object %s", method, property)); - } else { - return method.invoke(property, args); - } - }); + return (ListProperty) + Proxy.newProxyInstance( + GradleWorkarounds.class.getClassLoader(), + 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.getName().equals("getElementType")) { + // Proxy to `propertyInternalClass` which we know DefaultListProperty implements. + return propertyInternalClass + .getMethod(method.getName(), method.getParameterTypes()) + .invoke(property, args); + } else if (method.getName().equals("size")) { + return property.get().size(); + } + throw new GradleException( + String.format("Could not proxy method '%s' to object %s", method, property)); + } else { + return method.invoke(property, args); + } + }); } /** diff --git a/src/main/java/com/palantir/gradle/versions/VerifyLocksTask.java b/src/main/java/com/palantir/gradle/versions/VerifyLocksTask.java index bbe47deb9..0dd76fb2a 100644 --- a/src/main/java/com/palantir/gradle/versions/VerifyLocksTask.java +++ b/src/main/java/com/palantir/gradle/versions/VerifyLocksTask.java @@ -103,12 +103,13 @@ private void verifyLocksForScope(Function> differing) { return differing.entrySet().stream() - .map(diff -> String.format( - "" // to align strings - + "-%s\n" - + "+%s", - diff.getValue().leftValue().stringRepresentation(), - diff.getValue().rightValue().stringRepresentation())) + .map(diff -> + String.format( + "" // to align strings + + "-%s\n" + + "+%s", + diff.getValue().leftValue().stringRepresentation(), + diff.getValue().rightValue().stringRepresentation())) .collect(Collectors.joining("\n")); } } diff --git a/src/main/java/com/palantir/gradle/versions/VersionsLockPlugin.java b/src/main/java/com/palantir/gradle/versions/VersionsLockPlugin.java index 1efefcf95..5e0d5c08e 100644 --- a/src/main/java/com/palantir/gradle/versions/VersionsLockPlugin.java +++ b/src/main/java/com/palantir/gradle/versions/VersionsLockPlugin.java @@ -280,10 +280,11 @@ public final void apply(Project project) { } if (Files.notExists(rootLockfile)) { - throw new GradleException(String.format( - "Root lock file '%s' doesn't exist, please run " - + "`./gradlew --write-locks` to initialise locks", - rootLockfile)); + throw new GradleException( + String.format( + "Root lock file '%s' doesn't exist, please run " + + "`./gradlew --write-locks` to initialise locks", + rootLockfile)); } configureAllProjectsUsingConstraints(project, rootLockfile, lockedConfigurations); @@ -391,8 +392,10 @@ private static void addConfigurationDependencies( /** Create a dependency to {@code toConfiguration}, where the latter should exist in the given {@code project}. */ private static ProjectDependency createConfigurationDependency(Project project, Configuration toConfiguration) { - return (ProjectDependency) project.getDependencies().project(ImmutableMap.of( - "path", project.getPath(), "configuration", toConfiguration.getName())); + return (ProjectDependency) + project.getDependencies() + .project( + ImmutableMap.of("path", project.getPath(), "configuration", toConfiguration.getName())); } /** Create a dependency to {@code toConfiguration}, where the latter should exist in the given {@code project}. */ @@ -424,11 +427,12 @@ private static void checkPreconditions(Project project) { project.subprojects(subproject -> { subproject.afterEvaluate(sub -> { if (haveSameGroupAndName(project, sub)) { - throw new GradleException(String.format( - "This plugin doesn't work if the root project shares both group and name with a" - + " subproject. Consider adding the following to settings.gradle:\n" - + "rootProject.name = '%s-root'", - project.getName())); + throw new GradleException( + String.format( + "This plugin doesn't work if the root project shares both group and name with a" + + " subproject. Consider adding the following to settings.gradle:\n" + + "rootProject.name = '%s-root'", + project.getName())); } String coordinate = String.format("%s:%s", subproject.getGroup(), subproject.getName()); coordinateDuplicates.put(coordinate, subproject); @@ -462,13 +466,16 @@ private static void checkForDuplicatesInSubprojects(Multimap co ImmutableMap.copyOf(Maps.filterValues(coordinateDuplicates.asMap(), projects -> projects.size() > 1)); if (!duplicates.isEmpty()) { - throw new GradleException(String.format( - "All subprojects must have unique $group:$name coordinates, but found duplicates:\n%s", - duplicates.entrySet().stream() - .map(entry -> String.format( - "- '%s' -> %s", - entry.getKey(), Collections2.transform(entry.getValue(), Project::getPath))) - .collect(Collectors.joining("\n")))); + throw new GradleException( + String.format( + "All subprojects must have unique $group:$name coordinates, but found duplicates:\n%s", + duplicates.entrySet().stream() + .map(entry -> + String.format( + "- '%s' -> %s", + entry.getKey(), + Collections2.transform(entry.getValue(), Project::getPath))) + .collect(Collectors.joining("\n")))); } } @@ -565,10 +572,11 @@ private void recursivelyCopyProjectDependenciesWithScope( causeWithDependenciesActionsToRun(targetConf); Configuration copiedConf = targetConf.copyRecursive(); - copiedConf.setDescription(String.format( - "Copy of the '%s' configuration that can be resolved by " - + "com.palantir.consistent-versions without resolving the '%s' configuration itself.", - targetConf.getName(), targetConf.getName())); + copiedConf.setDescription( + String.format( + "Copy of the '%s' configuration that can be resolved by com.palantir.consistent-versions" + + " without resolving the '%s' configuration itself.", + targetConf.getName(), targetConf.getName())); // Update state about what we've seen copiedConfigurationsCache.put(targetConf, copiedConf.getName()); @@ -656,10 +664,13 @@ private void failIfAnyDependenciesUnresolved(ResolutionResult resolutionResult) .map(a -> (UnresolvedDependencyResult) a) .collect(Collectors.toList()); if (!unresolved.isEmpty()) { - throw new GradleException(String.format( - "Could not compute lock state from configuration '%s' due to unresolved dependencies:\n%s", - UNIFIED_CLASSPATH_CONFIGURATION_NAME, - unresolved.stream().map(this::formatUnresolvedDependencyResult).collect(Collectors.joining("\n")))); + throw new GradleException( + String.format( + "Could not compute lock state from configuration '%s' due to unresolved dependencies:\n%s", + UNIFIED_CLASSPATH_CONFIGURATION_NAME, + unresolved.stream() + .map(this::formatUnresolvedDependencyResult) + .collect(Collectors.joining("\n")))); } } @@ -687,8 +698,9 @@ private static FullLockState computeLockState(ResolutionResult resolutionResult) extractDependents(component)); return; } - throw new RuntimeException(String.format( - "Unexpected scope for component %s: %s", component.getModuleVersion(), scope)); + throw new RuntimeException( + String.format( + "Unexpected scope for component %s: %s", component.getModuleVersion(), scope)); }); return builder.build(); } @@ -719,19 +731,25 @@ private static GcvScope getScopeRecursively( } private static Dependents extractDependents(ResolvedComponentResult component) { - return Dependents.of(component.getDependents().stream().collect(Collectors.groupingBy( - dep -> dep.getFrom().getId(), - () -> new TreeMap<>(GradleComparators.COMPONENT_IDENTIFIER_COMPARATOR), - Collectors.mapping(dep -> getRequestedVersionConstraint(dep.getRequested()), Collectors.toCollection( - () -> new TreeSet<>(Comparator.comparing(VersionConstraint::toString))))))); + return Dependents.of( + component.getDependents().stream() + .collect( + Collectors.groupingBy( + dep -> dep.getFrom().getId(), + () -> new TreeMap<>(GradleComparators.COMPONENT_IDENTIFIER_COMPARATOR), + Collectors.mapping( + dep -> getRequestedVersionConstraint(dep.getRequested()), + Collectors.toCollection(() -> new TreeSet<>( + Comparator.comparing(VersionConstraint::toString))))))); } private static VersionConstraint getRequestedVersionConstraint(ComponentSelector requested) { if (requested instanceof ModuleComponentSelector) { return ((ModuleComponentSelector) requested).getVersionConstraint(); } - throw new RuntimeException(String.format( - "Expecting a ModuleComponentSelector but found a %s: %s", requested.getClass(), requested)); + throw new RuntimeException( + String.format( + "Expecting a ModuleComponentSelector but found a %s: %s", requested.getClass(), requested)); } /** diff --git a/src/main/java/com/palantir/gradle/versions/VersionsPropsPlugin.java b/src/main/java/com/palantir/gradle/versions/VersionsPropsPlugin.java index b713d3e30..83eb5faf6 100644 --- a/src/main/java/com/palantir/gradle/versions/VersionsPropsPlugin.java +++ b/src/main/java/com/palantir/gradle/versions/VersionsPropsPlugin.java @@ -159,12 +159,13 @@ private static void setupConfiguration( // Add fail-safe error reporting conf.getIncoming().beforeResolve(resolvableDependencies -> { if (GradleWorkarounds.isConfiguring(subproject.getState())) { - throw new GradleException(String.format( - "Not allowed to resolve %s at " - + "configuration time (https://guides.gradle.org/performance/" - + "#don_t_resolve_dependencies_at_configuration_time). Please upgrade your " - + "plugins and double-check your gradle scripts (see stacktrace)", - conf)); + throw new GradleException( + String.format( + "Not allowed to resolve %s at " + + "configuration time (https://guides.gradle.org/performance/" + + "#don_t_resolve_dependencies_at_configuration_time). Please upgrade your " + + "plugins and double-check your gradle scripts (see stacktrace)", + conf)); } }); }); @@ -189,8 +190,8 @@ private static boolean isSameOrSuperconfigurationOf( private static Provider> extractPlatformDependencies( Project project, Configuration rootConfiguration) { ListProperty proxiedDependencies = project.getObjects().listProperty(Dependency.class); - proxiedDependencies.addAll(project.provider( - () -> rootConfiguration.getDependencies().withType(ModuleDependency.class).matching(dep -> + proxiedDependencies.addAll(project.provider(() -> + rootConfiguration.getDependencies().withType(ModuleDependency.class).matching(dep -> GradleWorkarounds.isPlatform(dep.getAttributes())))); return GradleWorkarounds.fixListProperty(proxiedDependencies); } diff --git a/src/main/java/com/palantir/gradle/versions/WhyDependencyTask.java b/src/main/java/com/palantir/gradle/versions/WhyDependencyTask.java index aa89c44c9..d2d470333 100644 --- a/src/main/java/com/palantir/gradle/versions/WhyDependencyTask.java +++ b/src/main/java/com/palantir/gradle/versions/WhyDependencyTask.java @@ -66,8 +66,9 @@ public final void fullLockState(Provider provider) { @TaskAction public final void taskAction() { // read the lockfile from disk so that we can fail fast without resolving anything if the hash isn't found - Multimap lineByHash = new ConflictSafeLockFile(lockfile).readLocks().allLines().stream() - .collect(Multimaps.toMultimap(Line::dependentsHash, Function.identity(), HashMultimap::create)); + Multimap lineByHash = new ConflictSafeLockFile(lockfile) + .readLocks().allLines().stream() + .collect(Multimaps.toMultimap(Line::dependentsHash, Function.identity(), HashMultimap::create)); if (!hashOption.isPresent()) { Optional example = lineByHash.keySet().stream() diff --git a/src/main/java/com/palantir/gradle/versions/lockstate/LockState.java b/src/main/java/com/palantir/gradle/versions/lockstate/LockState.java index 37d166a46..dcd6abcfc 100644 --- a/src/main/java/com/palantir/gradle/versions/lockstate/LockState.java +++ b/src/main/java/com/palantir/gradle/versions/lockstate/LockState.java @@ -50,15 +50,19 @@ default List allLines() { /** Mapping from {@code group:artifact} to the full line. */ @Value.Lazy default SortedMap productionLinesByModuleIdentifier() { - return productionLines().stream().collect(ImmutableSortedMap.toImmutableSortedMap( - GradleComparators.MODULE_IDENTIFIER_COMPARATOR, Line::identifier, Function.identity())); + return productionLines().stream() + .collect( + ImmutableSortedMap.toImmutableSortedMap( + GradleComparators.MODULE_IDENTIFIER_COMPARATOR, Line::identifier, Function.identity())); } /** Mapping from {@code group:artifact} to the full line. */ @Value.Lazy default SortedMap testLinesByModuleIdentifier() { - return testLines().stream().collect(ImmutableSortedMap.toImmutableSortedMap( - GradleComparators.MODULE_IDENTIFIER_COMPARATOR, Line::identifier, Function.identity())); + return testLines().stream() + .collect( + ImmutableSortedMap.toImmutableSortedMap( + GradleComparators.MODULE_IDENTIFIER_COMPARATOR, Line::identifier, Function.identity())); } static LockState from(Stream productionLines, Stream testLines) {