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

Remove DependencyUpdatesTask withType instances #453

Merged
merged 2 commits into from
Feb 5, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@ private void writeGmeReposMarkerFile() throws IOException {
StandardCopyOption.REPLACE_EXISTING);
}

private void updateAllExtraGradleFilesWithGmeRepos() throws IOException, ManipulationException {
private void updateAllExtraGradleFilesWithGmeRepos() throws IOException {
final File rootDir = getProject().getRootDir();
final File gradleScriptsDirectory = rootDir.toPath().resolve(GRADLE).toFile();
if (!gradleScriptsDirectory.exists()) {
Expand All @@ -582,7 +582,6 @@ private void updateAllExtraGradleFilesWithGmeRepos() throws IOException, Manipul
DirectoryFileFilter.DIRECTORY);
for (File extraGradleScript : extraGradleScripts) {
final List<String> lines = FileUtils.readLines(extraGradleScript, Charset.defaultCharset());

if (!APPLY_GME_REPOS.equals(org.jboss.gm.common.utils.FileUtils.getFirstLine(lines))) {
final List<String> result = new ArrayList<>(lines.size() + 2);
result.add(APPLY_GME_REPOS);
Expand Down
8 changes: 3 additions & 5 deletions common/src/main/java/org/jboss/gm/common/utils/FileUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

import org.apache.commons.io.input.ReversedLinesFileReader;
import org.apache.commons.lang.StringUtils;
import org.commonjava.maven.ext.common.ManipulationException;
import org.slf4j.helpers.MessageFormatter;

import static org.apache.commons.lang.StringUtils.isBlank;
Expand Down Expand Up @@ -39,16 +38,15 @@ public static String getLastLine(File target) throws IOException {
* Take a collection of lines and returns the first non blank entry.
*
* @param lines the collection of string lines
* @return the first non blank entry.
* @throws ManipulationException if it cannot find a non-blank entry.
* @return the first non blank entry or empty string if it can't find one.
*/
public static String getFirstLine(List<String> lines) throws ManipulationException {
public static String getFirstLine(List<String> lines) {
for (String line : lines) {
if (StringUtils.isNotBlank(line)) {
return line;
}
}
throw new ManipulationException("Unable to find a non blank line in the collection");
return "";
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class PluginUtils {

static {
PLUGINS.put("com.github.ben-manes.versions", new PluginReference(Collections.singleton("dependencyUpdates"),
"", Stream.of("dependencyUpdates", "DependencyUpdatesTask").collect(
"DependencyUpdatesTask", Stream.of("dependencyUpdates", "DependencyUpdatesTask").collect(
Collectors.toSet()),
"", Collections.singleton("com.github.benmanes.gradle.versions.updates.DependencyUpdatesTask")));
PLUGINS.put("com.github.burrunan.s3-build-cache", new PluginReference("buildCache"));
Expand Down Expand Up @@ -245,6 +245,8 @@ public static void pluginRemoval(Logger logger, File target, Set<String> plugins
contentBuilder = new StringBuilder(content);
removed |= removeBlock(logger, buildFile, eol, contentBuilder,
"plugins.withType<" + pluginType + ">");
removed |= removeBlock(logger, buildFile, eol, contentBuilder,
"tasks.withType<" + pluginType + ">");
content = contentBuilder.toString();
}

Expand Down
27 changes: 27 additions & 0 deletions common/src/test/java/org/jboss/gm/common/utils/FileUtilsTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package org.jboss.gm.common.utils;

import java.util.ArrayList;
import java.util.List;

import org.junit.Test;

import static org.junit.Assert.assertEquals;

public class FileUtilsTest {
@Test
public void testReadLines() {
List<String> lines = new ArrayList<>();
lines.add("");
lines.add("FOO");

assertEquals("FOO", FileUtils.getFirstLine(lines));
}

@Test
public void testReadLinesFail() {
List<String> lines = new ArrayList<>();
lines.add("");

assertEquals("", FileUtils.getFirstLine(lines));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -913,11 +913,62 @@ public void testRemoval16()

String result = FileUtils.readFileToString(target, Charset.defaultCharset());

System.out.println(result);
assertFalse(result.contains("dependencyUpdates"));
assertFalse(result.contains("benmanes"));
}

@Test
public void testRemoval17()
throws IOException, ManipulationException {

File target = folder.newFile("build.gradle");
org.apache.commons.io.FileUtils.writeStringToFile(target,
"import com.github.benmanes.gradle.versions.updates.DependencyUpdatesTask\n"
+ "\n" + "plugins {\n" + " `kotlin-dsl`\n"
+ " alias(libs.plugins.versions)\n" + "}\n" + "\n"
+ "java.toolchain.languageVersion = JavaLanguageVersion.of(11)\n"
+ "\n" + "dependencies {\n"
+ " implementation(libs.bnd)\n"
+ " implementation(libs.guava)\n"
+ " implementation(libs.coveralls)\n"
+ " implementation(libs.sonarqube)\n"
+ " implementation(libs.bundles.jmh)\n"
+ " implementation(libs.bundles.pmd)\n"
+ " implementation(libs.forbiddenApis)\n"
+ " implementation(libs.nexus.publish)\n"
+ " implementation(libs.nullaway.plugin)\n"
+ " implementation(libs.spotbugs.plugin)\n"
+ " implementation(libs.dependency.check)\n"
+ " implementation(libs.errorprone.plugin)\n"
+ " implementation(libs.dependency.versions)\n"
+ " implementation(platform(libs.asm.bom))\n"
+ " implementation(platform(libs.junit5.bom))\n"
+ " implementation(platform(libs.kotlin.bom))\n"
+ " implementation(platform(libs.jackson.bom))\n"
+ " implementation(files(libs.javaClass.superclass.protectionDomain.codeSource.location))\n"
+ "\n"
+ " libs.bundles.constraints.get().forEach { library ->\n"
+ " constraints.add(\"implementation\", library.module.toString())\n"
+ " .version { require(library.version!!) }\n"
+ " }\n" + "}\n" + "\n"
+ "tasks.withType<DependencyUpdatesTask> {\n"
+ " val ignoredGroups = listOf(\"org.jetbrains.kotlin\", \"org.gradle.kotlin.kotlin-dsl\")\n"
+ " rejectVersionIf {\n"
+ " (candidate.group in ignoredGroups) && (candidate.version != currentVersion)\n"
+ " }\n" + "}\n",
Charset.defaultCharset());

HashSet<String> plugins = new LinkedHashSet<>();
plugins.add("ALL");
PluginUtils.pluginRemoval(logger, target.getParentFile(), plugins);

String result = FileUtils.readFileToString(target, Charset.defaultCharset());

System.out.println(result);
assertFalse(result.contains("update.DependencyUpdatesTask"));
assertFalse(result.contains("<DependencyUpdatesTask>"));
}

@Test
public void testCheckForSemanticPlugin1()
throws IOException, ManipulationException {
Expand Down
Loading