Skip to content

Commit

Permalink
Merge pull request #21843 Report deprecations for deprecated members …
Browse files Browse the repository at this point in the history
…from the org.gradle.util package

* #21839

For some members of `org.gradle.util.*` deprecation logging could not be added because smoke tested plugins and other third parties don't offer a version that is free of their use:

* **Kotlin Gradle Plugin**
  * `WrapUtil.toDomainObjectSet()`
  * [KT-53882 - Kotlin Gradle Plugin should not use the deprecated WrapUtil.toDomainObjectSet() function](https://youtrack.jetbrains.com/issue/KT-53882/Kotlin-Gradle-Plugin-should-not-use-the-deprecated-WrapUtiltoDomainObjectSet-function)
  * #21882
* **Android Gradle Plugin**
  * `GUtil.toWords(string)`
  * [ANDROID-245405989 - Android Gradle Plugin should not use the deprecated GUtil.toWords(string) function](https://issuetracker.google.com/issues/245405989)
  * #21899
  * `ConfigureUtil.configure(closure, target)`
  * [ANDROID-245405989 - Android Gradle Plugin should not use the deprecated ConfigureUtil.configure(closure, target) function](https://issuetracker.google.com/issues/245405994)
  * #21901
* **Spring Dependency Management Plugin**
  * `GradleVersion.getNextMajor()`
  * spring-gradle-plugins/dependency-management-plugin#338
  * #21898
* **Google Protobuf Gradle Plugin**
  * `GUtil.toCamelCase(string)`
  * google/protobuf-gradle-plugin#604
  * #21900
  * `ConfigureUtil.configure(closure, target)`
  * google/protobuf-gradle-plugin#577
  * #21901
* **OSDetector Gradle Plugin (via the Protobuf plugin)**
  * `VersionNumber.*`
  * google/osdetector-gradle-plugin#24
  * #21902
* **Asciidoctor Gradle Plugin / Grolifant**
  * `CollectionUtils.stringize(collection)`
  * [GROLIFANT-85 - Grolifant should not use the deprecated CollectionUtils](https://gitlab.com/ysb33rOrg/grolifant/-/issues/85)
  * #21903
* **Nebula Lint Plugin**
  * `GUtil.loadProperties(inputStream)`
  * nebula-plugins/gradle-lint-plugin#378
  * #21912
* **Nebula Dependency Lock Plugin**
  * `NameMatcher`
  * nebula-plugins/gradle-dependency-lock-plugin#243
  * #21913
* **IntelliJ IDEA**
  * `GUtil.toCamelCase(string)`
  * `GUtil.toLowerCamelCase(string)`
  * `GUtil.loadProperties(inputStream)`
  * `ConfigureUtil.configureByMap(properties, delegate)`
  * [IDEA-301430 - IntelliJ IDEA should not use deprecated types from the org.gradle.util package](https://youtrack.jetbrains.com/issue/IDEA-301430/IntelliJ-IDEA-should-not-use-deprecated-types-from-the-orggradleutil-package)
  * #21912
  * #21900
  * #21914

Co-authored-by: Bo Zhang <bo@gradle.com>
  • Loading branch information
bot-gradle and blindpirate committed Sep 10, 2022
2 parents bd51a00 + ba11ca4 commit c789e0e
Show file tree
Hide file tree
Showing 39 changed files with 575 additions and 62 deletions.
1 change: 1 addition & 0 deletions subprojects/build-init/build.gradle.kts
Expand Up @@ -47,6 +47,7 @@ dependencies {
testFixturesImplementation(project(":base-services"))
testFixturesImplementation(project(":platform-base"))
testFixturesImplementation(project(":core-api"))
testFixturesImplementation(project(":logging"))
testFixturesImplementation(project(":plugins"))
testFixturesImplementation(project(":testing-base"))

Expand Down
1 change: 1 addition & 0 deletions subprojects/build-scan-performance/build.gradle.kts
Expand Up @@ -13,6 +13,7 @@ dependencies {
testFixturesApi(project(":base-services"))
testFixturesImplementation(project(":internal-testing"))
testFixturesImplementation(project(":internal-integ-testing"))
testFixturesImplementation(project(":logging"))
testFixturesImplementation(libs.groovyJson)

performanceTestDistributionRuntimeOnly(project(":distributions-full")) {
Expand Down
Expand Up @@ -16,7 +16,7 @@

package org.gradle.api.tasks

import org.gradle.util.TextUtil
import org.gradle.util.internal.TextUtil


class CachedLineEndingSensitivityIntegrationSpec extends AbstractLineEndingSensitivityIntegrationSpec {
Expand Down
Expand Up @@ -16,20 +16,33 @@
package org.gradle.util;

import org.gradle.internal.UncheckedException;
import org.gradle.internal.deprecation.DeprecationLogger;

import java.net.URI;
import java.net.URISyntaxException;

/**
* This class is only here to maintain binary compatibility with existing plugins.
*
* @deprecated Will be removed in Gradle 8.0.
* @deprecated Will be removed in Gradle 9.0.
*/
@Deprecated
public class DistributionLocator {

private static void logDeprecation() {
DeprecationLogger.deprecateType(DistributionLocator.class)
.willBeRemovedInGradle9()
.withUpgradeGuideSection(7, "org_gradle_util_reports_deprecations")
.nagUser();
}

private static final String RELEASE_REPOSITORY = "https://services.gradle.org/distributions";
private static final String SNAPSHOT_REPOSITORY = "https://services.gradle.org/distributions-snapshots";

public DistributionLocator() {
logDeprecation();
}

public URI getDistributionFor(GradleVersion version) {
return getDistributionFor(version, "bin");
}
Expand Down
19 changes: 18 additions & 1 deletion subprojects/core/src/main/java/org/gradle/util/NameMatcher.java
Expand Up @@ -20,25 +20,39 @@
import java.util.regex.Pattern;

import org.apache.commons.lang.StringUtils;
import org.gradle.internal.deprecation.DeprecationLogger;

/**
* This class is only here to maintain binary compatibility with existing plugins.
*
* @deprecated Will be removed in Gradle 8.0.
* @deprecated Will be removed in Gradle 9.0.
*/
@Deprecated
public class NameMatcher {

private static void logDeprecation() {
DeprecationLogger.deprecateType(NameMatcher.class)
.willBeRemovedInGradle9()
.withUpgradeGuideSection(7, "org_gradle_util_reports_deprecations")
.nagUser();
}

private final SortedSet<String> matches = new TreeSet<>();
private final Set<String> candidates = new TreeSet<>();
private String pattern;

public NameMatcher() {
// TODO log deprecation once nebula.dependency-lock plugin is fixed
}

/**
* Locates the best match for a camel case pattern in a key set of a map and returns the corresponding value.
*
* @return The matching item if exactly 1 match found, null if no matches or multiple matches.
* @see #find(String, Collection)
*/
public <T> T find(String pattern, Map<String, ? extends T> items) {
logDeprecation();
String name = find(pattern, items.keySet());
if (name != null) {
return items.get(name);
Expand All @@ -59,6 +73,7 @@ public <T> T find(String pattern, Map<String, ? extends T> items) {
* @return The match if exactly 1 match found, null if no matches or multiple matches.
*/
public String find(String pattern, Collection<String> items) {
// TODO log deprecation once nebula.dependency-lock plugin is fixed
this.pattern = pattern;
matches.clear();
candidates.clear();
Expand Down Expand Up @@ -178,6 +193,7 @@ private static Pattern getKebabCasePatternForName(String name) {
* @return The matches. Returns an empty set when there are no matches.
*/
public Set<String> getMatches() {
logDeprecation();
return matches;
}

Expand All @@ -187,6 +203,7 @@ public Set<String> getMatches() {
* @return The matches. Returns an empty set when there are no potential matches.
*/
public Set<String> getCandidates() {
logDeprecation();
return candidates;
}

Expand Down
Expand Up @@ -18,17 +18,25 @@

import org.apache.commons.lang.StringUtils;
import org.gradle.api.InvalidUserDataException;
import org.gradle.internal.deprecation.DeprecationLogger;

import java.util.Arrays;

/**
* This class is only here to maintain binary compatibility with existing plugins.
*
* @deprecated Will be removed in Gradle 8.0.
* @deprecated Will be removed in Gradle 9.0.
*/
@Deprecated
public final class NameValidator {

private static void logDeprecation() {
DeprecationLogger.deprecateType(NameValidator.class)
.willBeRemovedInGradle9()
.withUpgradeGuideSection(7, "org_gradle_util_reports_deprecations")
.nagUser();
}

private static final char[] FORBIDDEN_CHARACTERS = new char[] {'/', '\\', ':', '<', '>', '"', '?', '*', '|'};
private static final char FORBIDDEN_LEADING_AND_TRAILING_CHARACTER = '.';

Expand All @@ -38,6 +46,7 @@ private NameValidator() { }
* Validates that a given name string does not contain any forbidden characters.
*/
public static void validate(String name, String nameDescription, String fixSuggestion) throws InvalidUserDataException {
logDeprecation();
if (StringUtils.isEmpty(name)) {
throw newInvalidUserDataException("The " + nameDescription + " must not be empty.", fixSuggestion);
} else if (StringUtils.containsAny(name, FORBIDDEN_CHARACTERS)) {
Expand Down
Expand Up @@ -17,16 +17,30 @@
package org.gradle.util;

import org.gradle.internal.UncheckedException;
import org.gradle.internal.deprecation.DeprecationLogger;
import org.gradle.util.internal.TextUtil;

import java.io.File;

/**
* This class is only here to maintain binary compatibility with existing plugins.
*
* @deprecated Will be removed in Gradle 8.0.
* @deprecated Will be removed in Gradle 9.0.
*/
@Deprecated
public class RelativePathUtil {

private static void logDeprecation() {
DeprecationLogger.deprecateType(RelativePathUtil.class)
.willBeRemovedInGradle9()
.withUpgradeGuideSection(7, "org_gradle_util_reports_deprecations")
.nagUser();
}

public RelativePathUtil() {
logDeprecation();
}

/**
* Returns a relative path from 'from' to 'to'
*
Expand All @@ -35,6 +49,7 @@ public class RelativePathUtil {
* @return The relative path
*/
public static String relativePath(File from, File to) {
logDeprecation();
try {
return TextUtil.normaliseFileSeparators(from.toPath().relativize(to.toPath()).toString());
} catch (Exception e) {
Expand Down
48 changes: 40 additions & 8 deletions subprojects/core/src/main/java/org/gradle/util/VersionNumber.java
Expand Up @@ -18,16 +18,25 @@

import com.google.common.base.Objects;
import com.google.common.collect.Ordering;
import org.gradle.internal.deprecation.DeprecationLogger;

import javax.annotation.Nullable;

/**
* This class is only here to maintain binary compatibility with existing plugins.
*
* @deprecated Will be removed in Gradle 8.0.
* @deprecated Will be removed in Gradle 9.0.
*/
@Deprecated
public class VersionNumber implements Comparable<VersionNumber> {

private static void logDeprecation() {
DeprecationLogger.deprecateType(VersionNumber.class)
.willBeRemovedInGradle9()
.withUpgradeGuideSection(7, "org_gradle_util_reports_deprecations")
.nagUser();
}

private static final DefaultScheme DEFAULT_SCHEME = new DefaultScheme();
private static final SchemeWithPatchVersion PATCH_SCHEME = new SchemeWithPatchVersion();
public static final VersionNumber UNKNOWN = version(0);
Expand All @@ -38,51 +47,70 @@ public class VersionNumber implements Comparable<VersionNumber> {
private final int patch;
private final String qualifier;
private final AbstractScheme scheme;
private boolean deprecationLogged;

public VersionNumber(int major, int minor, int micro, @Nullable String qualifier) {
this(major, minor, micro, 0, qualifier, DEFAULT_SCHEME);
this(major, minor, micro, 0, qualifier, DEFAULT_SCHEME, true);
}

public VersionNumber(int major, int minor, int micro, int patch, @Nullable String qualifier) {
this(major, minor, micro, patch, qualifier, PATCH_SCHEME);
this(major, minor, micro, patch, qualifier, PATCH_SCHEME, true);
}

private VersionNumber(int major, int minor, int micro, int patch, @Nullable String qualifier, AbstractScheme scheme) {
private VersionNumber(int major, int minor, int micro, int patch, @Nullable String qualifier, AbstractScheme scheme, boolean logDeprecation) {
this.major = major;
this.minor = minor;
this.micro = micro;
this.patch = patch;
this.qualifier = qualifier;
this.scheme = scheme;
// TODO log deprecation once protobuf/osdetector plugin is fixed
if (logDeprecation) {
logDeprecation();
deprecationLogged = true;
}
}

private void maybeLogDeprecation() {
if(!deprecationLogged) {
logDeprecation();
}
}

public int getMajor() {
maybeLogDeprecation();
return major;
}

public int getMinor() {
maybeLogDeprecation();
return minor;
}

public int getMicro() {
maybeLogDeprecation();
return micro;
}

public int getPatch() {
maybeLogDeprecation();
return patch;
}

@Nullable
public String getQualifier() {
maybeLogDeprecation();
return qualifier;
}

public VersionNumber getBaseVersion() {
return new VersionNumber(major, minor, micro, patch, null, scheme);
maybeLogDeprecation();
return new VersionNumber(major, minor, micro, patch, null, scheme, false);
}

@Override
public int compareTo(VersionNumber other) {
// TODO log deprecation once protobuf/osdetector plugin is fixed
if (major != other.major) {
return major - other.major;
}
Expand Down Expand Up @@ -115,6 +143,7 @@ public int hashCode() {

@Override
public String toString() {
maybeLogDeprecation();
return scheme.format(this);
}

Expand All @@ -123,24 +152,27 @@ public static VersionNumber version(int major) {
}

public static VersionNumber version(int major, int minor) {
return new VersionNumber(major, minor, 0, 0, null, DEFAULT_SCHEME);
return new VersionNumber(major, minor, 0, 0, null, DEFAULT_SCHEME, false);
}

/**
* Returns the default MAJOR.MINOR.MICRO-QUALIFIER scheme.
*/
public static Scheme scheme() {
logDeprecation();
return DEFAULT_SCHEME;
}

/**
* Returns the MAJOR.MINOR.MICRO.PATCH-QUALIFIER scheme.
*/
public static Scheme withPatchNumber() {
logDeprecation();
return PATCH_SCHEME;
}

public static VersionNumber parse(String versionString) {
// TODO log deprecation once protobuf/osdetector plugin is fixed
return DEFAULT_SCHEME.parse(versionString);
}

Expand Down Expand Up @@ -196,12 +228,12 @@ public VersionNumber parse(@Nullable String versionString) {
}

if (scanner.isEnd()) {
return new VersionNumber(major, minor, micro, patch, null, this);
return new VersionNumber(major, minor, micro, patch, null, this, false);
}

if (scanner.isQualifier()) {
scanner.skipSeparator();
return new VersionNumber(major, minor, micro, patch, scanner.remainder(), this);
return new VersionNumber(major, minor, micro, patch, scanner.remainder(), this, false);
}

return UNKNOWN;
Expand Down

0 comments on commit c789e0e

Please sign in to comment.