From 5f5abc363046b82f2a8bee2947625bdc1bd9fb6d Mon Sep 17 00:00:00 2001 From: Andrey Loskutov Date: Sun, 14 Apr 2024 11:57:44 +0200 Subject: [PATCH] Moved TouchBundles from releng tests to releng tools See https://github.com/eclipse-platform/eclipse.platform.releng.aggregator/pull/1931 See https://github.com/eclipse-platform/eclipse.platform.releng.aggregator/issues/1923 See https://github.com/eclipse-platform/eclipse.platform.releng.buildtools/pull/61 --- .../eclipse/releng/tests/TouchBundles.java | 154 ------------------ 1 file changed, 154 deletions(-) delete mode 100644 eclipse.platform.releng/bundles/org.eclipse.releng.tests/src/org/eclipse/releng/tests/TouchBundles.java diff --git a/eclipse.platform.releng/bundles/org.eclipse.releng.tests/src/org/eclipse/releng/tests/TouchBundles.java b/eclipse.platform.releng/bundles/org.eclipse.releng.tests/src/org/eclipse/releng/tests/TouchBundles.java deleted file mode 100644 index 53bc6fc2a26..00000000000 --- a/eclipse.platform.releng/bundles/org.eclipse.releng.tests/src/org/eclipse/releng/tests/TouchBundles.java +++ /dev/null @@ -1,154 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2023 Andrey Loskutov and others. - * - * This program and the accompanying materials - * are made available under the terms of the Eclipse Public License 2.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Andrey Loskutov - initial API and implementation - *******************************************************************************/ -package org.eclipse.releng.tests; - -import java.io.File; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.nio.file.StandardOpenOption; -import java.util.Arrays; -import java.util.Map; -import java.util.Map.Entry; -import java.util.stream.Collectors; - -public class TouchBundles { - - final static String FQU_FILE = "forceQualifierUpdate.txt"; - static String ticketMessage; - - /** - * Tries to map & touch all bundles that are mentioned in artifactcomparisons. - * - * @param args first is path to the extracted artifactcomparisons.zip, second - * path to the root directory with all repositories, third one is - * the ticket message - * @throws Exception - */ - public static void main(String[] args) throws Exception { - if (args.length != 3) { - System.out.println("Arguments: first is path to the artifactcomparisons.zip, \n" - + "second is the path to the root directory with all repositories, \n" - + "third is the ticket message"); - System.exit(1); - } - Path artifactsPath = Paths.get(args[0]); - File[] badDirs = artifactsPath.toFile().listFiles(); - if (badDirs == null) { - System.out.println("No files found in " + artifactsPath); - System.exit(1); - } - - Path rootReposDir = Paths.get(args[1]); - File[] gitDirs = rootReposDir.toFile().listFiles(); - if (gitDirs == null) { - System.out.println("No files found in " + rootReposDir); - System.exit(1); - } - ticketMessage = args[2].strip(); - if (ticketMessage.isBlank()) { - ticketMessage = "Touching " + FQU_FILE + " to force bundle rebuild\n"; - } - - Map badDirMap = Arrays.asList(badDirs).stream().filter(File::isDirectory) - .collect(Collectors.toMap(File::getName, f -> f)); - - Map gitDirMap = Arrays.asList(gitDirs).stream().filter(File::isDirectory) - .collect(Collectors.toMap(File::getName, f -> f)); - - if (gitDirMap.containsKey("eclipse.pde.ui")) { - gitDirMap.put("eclipse.pde", gitDirMap.get("eclipse.pde.ui")); - } - if (gitDirMap.containsKey("eclipse.platform.releng.aggregator")) { - gitDirMap.put("eclipse.platform.releng", - new File(gitDirMap.get("eclipse.platform.releng.aggregator"), "eclipse.platform.releng")); - } - - for (Entry entry : badDirMap.entrySet()) { - String dirName = entry.getKey(); - File badDir = entry.getValue(); - File repoDir = gitDirMap.get(dirName); - if (repoDir == null) { - System.err.println("Repo " + dirName + " not found in " + rootReposDir); - continue; - } - - if (repoDir.isDirectory()) { - updateRepo(badDir, repoDir); - } else { - System.err.println("Repo " + repoDir + " is not a directory in " + rootReposDir); - } - } - } - - private static void updateRepo(File badDir, File repoDir) { - System.out.println("Checking " + badDir + " -> " + repoDir); - File[] dirs = badDir.listFiles(); - if (dirs == null) { - System.err.println("No children at " + badDir); - return; - } - for (File dir : dirs) { - File gitDir = new File(repoDir, dir.getName()); - if (isBundleWithChanges(dir)) { - updateFQU(gitDir); - } else { - updateRepo(new File(badDir, dir.getName()), gitDir); - } - } - } - - private static void updateFQU(File dir) { - if (!dir.isDirectory()) { - System.err.println("\tCan't update non existing directory " + dir); - return; - } - System.out.println("\tUpdating " + dir); - File fquFile = new File(dir, FQU_FILE); - try { - boolean created; - if (!fquFile.exists()) { - created = true; - Files.createFile(fquFile.toPath()); - } else { - created = false; - } - Path path = fquFile.toPath(); - String content = Files.readString(path); - if (content.endsWith(ticketMessage)) { - // already updated - System.out.println("\t\tAlready updated: " + fquFile); - return; - } - if (created) { - System.out.println("\t\tWill create new file: " + fquFile); - } else { - System.out.println("\t\tWill update file: " + fquFile); - } - if (content.endsWith("\n")) { - Files.write(path, ticketMessage.getBytes(), StandardOpenOption.APPEND); - } else { - Files.write(path, ("\n" + ticketMessage).getBytes(), StandardOpenOption.APPEND); - } - } catch (Exception e) { - System.err.println("Failed to update file " + fquFile); - } - } - - private static boolean isBundleWithChanges(File dir) { - return dir.isDirectory() && new File(dir, "target").isDirectory(); - } - - -}