Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Excavator: Upgrades Baseline to the latest version #345

Merged
merged 1 commit into from
Dec 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,13 @@ public Stream<Line> parseLines(Stream<String> 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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
21 changes: 12 additions & 9 deletions src/main/java/com/palantir/gradle/versions/GetVersionPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,12 @@ private static String getVersion(Project project, String group, String name, Con
static Optional<String> 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<ModuleVersionIdentifier> list =
Expand All @@ -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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ private GradleComparators() {}
*/
public static final Comparator<ComponentIdentifier> 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 <A, T> Optional<T> tryCast(Class<T> to, A value) {
Expand Down
47 changes: 25 additions & 22 deletions src/main/java/com/palantir/gradle/versions/GradleWorkarounds.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,28 +77,31 @@ static boolean isConfiguring(ProjectState state) {
@SuppressWarnings("unchecked")
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<?>[] {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<T>)
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);
}
});
}

/**
Expand Down
13 changes: 7 additions & 6 deletions src/main/java/com/palantir/gradle/versions/VerifyLocksTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,13 @@ private void verifyLocksForScope(Function<LockState, SortedMap<MyModuleIdentifie

private static String formatDependencyDifferences(Map<MyModuleIdentifier, ValueDifference<Line>> 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"));
}
}
100 changes: 62 additions & 38 deletions src/main/java/com/palantir/gradle/versions/VersionsLockPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -279,10 +279,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);
Expand Down Expand Up @@ -387,8 +388,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 requiring capabilities for the listed scope. */
Expand Down Expand Up @@ -420,11 +423,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);
Expand Down Expand Up @@ -458,13 +462,16 @@ private static void checkForDuplicatesInSubprojects(Multimap<String, Project> 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"))));
}
}

Expand Down Expand Up @@ -561,10 +568,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());
Expand Down Expand Up @@ -595,9 +603,15 @@ private void recursivelyCopyProjectDependenciesWithScope(
});
// To avoid capability based conflict detection between all these copied configurations (where they
// conflict as each has no capabilities), we give each of them a capability
copiedConf.getOutgoing().capability(String.format(
"gcv:%s-%s-%s-%s:extra",
projectDep.getGroup(), projectDep.getName(), projectDep.getVersion(), copiedConf.getName()));
copiedConf
.getOutgoing()
.capability(
String.format(
"gcv:%s-%s-%s-%s:extra",
projectDep.getGroup(),
projectDep.getName(),
projectDep.getVersion(),
copiedConf.getName()));

projectDep.getConfigurations().add(copiedConf);

Expand Down Expand Up @@ -672,10 +686,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"))));
}
}

Expand Down Expand Up @@ -703,8 +720,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();
}
Expand Down Expand Up @@ -735,19 +753,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));
}

/**
Expand Down
Loading