Skip to content

Commit 2499017

Browse files
committed
Remove old shaded Guava JARs during upgrade
1 parent a307c5f commit 2499017

File tree

3 files changed

+139
-29
lines changed

3 files changed

+139
-29
lines changed

opendj-server-legacy/src/main/java/org/opends/server/tools/upgrade/Upgrade.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,8 @@ public final class Upgrade
547547
register("4.0.0", moveSubordinateBaseDnToGlobalConfiguration());
548548
register("4.0.0", removeTools("ldif-diff", "make-ldif", "dsjavaproperties"));
549549

550+
register("5.0.4", removeMatchingJarFiles("forgerock-guava-*.jar"));
551+
550552
/* All upgrades will refresh the server configuration schema and generate a new upgrade folder. */
551553
registerLast(
552554
copySchemaFile("02-config.ldif"),

opendj-server-legacy/src/main/java/org/opends/server/tools/upgrade/UpgradeTasks.java

Lines changed: 84 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,82 @@
1212
* information: "Portions Copyright [year] [name of copyright owner]".
1313
*
1414
* Portions Copyright 2013-2016 ForgeRock AS.
15-
* Portions Copyright 2022 Wren Security
15+
* Portions Copyright 2022-2026 Wren Security
1616
*/
1717
package org.opends.server.tools.upgrade;
1818

19-
import static org.opends.server.util.SchemaUtils.addSchemaFileToElementDefinitionIfAbsent;
20-
21-
import static java.nio.charset.StandardCharsets.*;
22-
import static java.nio.file.StandardOpenOption.*;
19+
import static java.nio.charset.StandardCharsets.UTF_8;
20+
import static java.nio.file.StandardOpenOption.APPEND;
2321
import static javax.security.auth.callback.ConfirmationCallback.NO;
2422
import static javax.security.auth.callback.ConfirmationCallback.YES;
25-
import static javax.security.auth.callback.TextOutputCallback.*;
23+
import static javax.security.auth.callback.TextOutputCallback.INFORMATION;
2624
import static org.forgerock.util.Utils.joinAsString;
27-
import static org.opends.messages.ToolMessages.*;
25+
import static org.opends.messages.ToolMessages.ERR_UPGRADE_ADDATTRIBUTE_FAILS;
26+
import static org.opends.messages.ToolMessages.ERR_UPGRADE_ADDOBJECTCLASS_FAILS;
27+
import static org.opends.messages.ToolMessages.ERR_UPGRADE_ADD_CONFIG_FILE_FAILS;
28+
import static org.opends.messages.ToolMessages.ERR_UPGRADE_CONFIG_ERROR_UPGRADE_FOLDER;
29+
import static org.opends.messages.ToolMessages.ERR_UPGRADE_COPYSCHEMA_FAILS;
30+
import static org.opends.messages.ToolMessages.ERR_UPGRADE_CORRUPTED_TEMPLATE;
31+
import static org.opends.messages.ToolMessages.ERR_UPGRADE_PERFORMING_POST_TASKS_FAIL;
32+
import static org.opends.messages.ToolMessages.INFO_UPGRADE_ALL_REBUILD_INDEX_DECLINED;
33+
import static org.opends.messages.ToolMessages.INFO_UPGRADE_CHANGE_DONE_IN_SPECIFIC_FILE;
34+
import static org.opends.messages.ToolMessages.INFO_UPGRADE_NO_CHANGE_DONE_IN_SPECIFIC_FILE;
35+
import static org.opends.messages.ToolMessages.INFO_UPGRADE_NO_INDEX_TO_REBUILD_FOR_BACKEND;
36+
import static org.opends.messages.ToolMessages.INFO_UPGRADE_REBUILD_ALL;
37+
import static org.opends.messages.ToolMessages.INFO_UPGRADE_REBUILD_INDEXES_DECLINED;
38+
import static org.opends.messages.ToolMessages.INFO_UPGRADE_REBUILD_INDEX_ARGUMENTS;
39+
import static org.opends.messages.ToolMessages.INFO_UPGRADE_REBUILD_INDEX_ENDS;
40+
import static org.opends.messages.ToolMessages.INFO_UPGRADE_REBUILD_INDEX_STARTS;
41+
import static org.opends.messages.ToolMessages.INFO_UPGRADE_TASK_ADD_CONFIG_FILE;
42+
import static org.opends.messages.ToolMessages.INFO_UPGRADE_TASK_ADD_SUBORDINATE_BASE_DN_TO_GLOBAL_CONFIG;
43+
import static org.opends.messages.ToolMessages.INFO_UPGRADE_TASK_CANNOT_READ_SCHEMA_FILE;
44+
import static org.opends.messages.ToolMessages.INFO_UPGRADE_TASK_CANNOT_WRITE_TO_CONCATENATED_SCHEMA_FILE;
45+
import static org.opends.messages.ToolMessages.INFO_UPGRADE_TASK_DELETE_CHANGELOG_SUMMARY;
46+
import static org.opends.messages.ToolMessages.INFO_UPGRADE_TASK_DELETE_FILE;
47+
import static org.opends.messages.ToolMessages.INFO_UPGRADE_TASK_DELETE_SUBORDINATE_BASE_DN_FROM_ROOT_DSE;
48+
import static org.opends.messages.ToolMessages.INFO_UPGRADE_TASK_MIGRATE_CHANGELOG_DESCRIPTION;
49+
import static org.opends.messages.ToolMessages.INFO_UPGRADE_TASK_MIGRATE_CONFIG_READ_FAIL;
50+
import static org.opends.messages.ToolMessages.INFO_UPGRADE_TASK_MIGRATE_JE_CANCELLED;
51+
import static org.opends.messages.ToolMessages.INFO_UPGRADE_TASK_MIGRATE_JE_DESCRIPTION;
52+
import static org.opends.messages.ToolMessages.INFO_UPGRADE_TASK_MIGRATE_JE_ENV_UNREADABLE;
53+
import static org.opends.messages.ToolMessages.INFO_UPGRADE_TASK_MIGRATE_JE_NO_JE_LIB;
54+
import static org.opends.messages.ToolMessages.INFO_UPGRADE_TASK_MIGRATE_JE_SUMMARY_1;
55+
import static org.opends.messages.ToolMessages.INFO_UPGRADE_TASK_MIGRATE_JE_SUMMARY_5;
56+
import static org.opends.messages.ToolMessages.INFO_UPGRADE_TASK_MIGRATE_JE_UGLY_DN;
57+
import static org.opends.messages.ToolMessages.INFO_UPGRADE_TASK_NEEDS_USER_CONFIRM;
58+
import static org.opends.messages.ToolMessages.INFO_UPGRADE_TASK_REFRESH_UPGRADE_DIRECTORY;
59+
import static org.opends.messages.ToolMessages.INFO_UPGRADE_TASK_REMOVE_OLD_JARS;
60+
import static org.opends.messages.ToolMessages.INFO_UPGRADE_TASK_REPLACE_SCHEMA_FILE;
61+
import static org.opends.messages.ToolMessages.INFO_UPGRADE_TASK_SUMMARY_RESTORE_CSV_DELIMITER_CHAR;
62+
import static org.opends.messages.ToolMessages.INFO_UPGRADE_TASK_UNABLE_TO_REMOVE_OLD_JARS;
2863
import static org.opends.server.tools.upgrade.FileManager.copyRecursively;
29-
import static org.opends.server.tools.upgrade.UpgradeUtils.*;
30-
import static org.opends.server.util.StaticUtils.*;
64+
import static org.opends.server.tools.upgrade.UpgradeUtils.batDirectory;
65+
import static org.opends.server.tools.upgrade.UpgradeUtils.binDirectory;
66+
import static org.opends.server.tools.upgrade.UpgradeUtils.concatenatedSchemaFile;
67+
import static org.opends.server.tools.upgrade.UpgradeUtils.configDirectory;
68+
import static org.opends.server.tools.upgrade.UpgradeUtils.configFile;
69+
import static org.opends.server.tools.upgrade.UpgradeUtils.configSchemaDirectory;
70+
import static org.opends.server.tools.upgrade.UpgradeUtils.deleteFileIfExists;
71+
import static org.opends.server.tools.upgrade.UpgradeUtils.getInstancePath;
72+
import static org.opends.server.tools.upgrade.UpgradeUtils.libDirectory;
73+
import static org.opends.server.tools.upgrade.UpgradeUtils.searchConfigFile;
74+
import static org.opends.server.tools.upgrade.UpgradeUtils.templateConfigDirectory;
75+
import static org.opends.server.tools.upgrade.UpgradeUtils.templateConfigSchemaDirectory;
76+
import static org.opends.server.tools.upgrade.UpgradeUtils.updateConfigFile;
77+
import static org.opends.server.tools.upgrade.UpgradeUtils.updateConfigUpgradeSchemaFile;
78+
import static org.opends.server.tools.upgrade.UpgradeUtils.updateSchemaFile;
79+
import static org.opends.server.tools.upgrade.UpgradeUtils.deleteMatchingFiles;
80+
import static org.opends.server.util.SchemaUtils.addSchemaFileToElementDefinitionIfAbsent;
81+
import static org.opends.server.util.StaticUtils.isClassAvailable;
82+
import static org.opends.server.util.StaticUtils.stackTraceToSingleLineString;
3183

84+
import com.forgerock.opendj.cli.ClientException;
85+
import com.forgerock.opendj.cli.ReturnCode;
86+
import com.sleepycat.je.DatabaseException;
87+
import com.sleepycat.je.Environment;
88+
import com.sleepycat.je.EnvironmentConfig;
89+
import com.sleepycat.je.Transaction;
90+
import com.sleepycat.je.TransactionConfig;
3291
import java.io.BufferedWriter;
3392
import java.io.File;
3493
import java.io.FileReader;
@@ -45,9 +104,7 @@
45104
import java.util.Set;
46105
import java.util.TreeMap;
47106
import java.util.TreeSet;
48-
49107
import javax.security.auth.callback.TextOutputCallback;
50-
51108
import org.forgerock.i18n.LocalizableMessage;
52109
import org.forgerock.i18n.slf4j.LocalizedLogger;
53110
import org.forgerock.opendj.ldap.Attribute;
@@ -72,14 +129,6 @@
72129
import org.opends.server.util.ChangeOperationType;
73130
import org.opends.server.util.StaticUtils;
74131

75-
import com.forgerock.opendj.cli.ClientException;
76-
import com.forgerock.opendj.cli.ReturnCode;
77-
import com.sleepycat.je.DatabaseException;
78-
import com.sleepycat.je.Environment;
79-
import com.sleepycat.je.EnvironmentConfig;
80-
import com.sleepycat.je.Transaction;
81-
import com.sleepycat.je.TransactionConfig;
82-
83132
/** Factory methods for create new upgrade tasks. */
84133
final class UpgradeTasks
85134
{
@@ -1416,6 +1465,22 @@ public void perform(final UpgradeContext context) throws ClientException {
14161465
};
14171466
}
14181467

1468+
static UpgradeTask removeMatchingJarFiles(final String... patterns)
1469+
{
1470+
return new AbstractUpgradeTask() {
1471+
@Override
1472+
public void perform(UpgradeContext context) throws ClientException {
1473+
try {
1474+
for (String pattern : patterns) {
1475+
deleteMatchingFiles(libDirectory.toPath(), pattern);
1476+
}
1477+
} catch (IOException e) {
1478+
throw new ClientException(ReturnCode.ERROR_UNEXPECTED, LocalizableMessage.raw(e.getMessage()));
1479+
}
1480+
}
1481+
};
1482+
}
1483+
14191484
/** Prevent instantiation. */
14201485
private UpgradeTasks()
14211486
{

opendj-server-legacy/src/main/java/org/opends/server/tools/upgrade/UpgradeUtils.java

Lines changed: 53 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,38 @@
1212
* information: "Portions Copyright [year] [name of copyright owner]".
1313
*
1414
* Portions Copyright 2013-2016 ForgeRock AS.
15+
* Portions Copyright 2026 Wren Security
1516
*/
1617
package org.opends.server.tools.upgrade;
1718

19+
import static org.forgerock.opendj.ldap.schema.CoreSchema.getCaseExactMatchingRule;
20+
import static org.forgerock.opendj.ldap.schema.CoreSchema.getDirectoryStringSyntax;
21+
import static org.forgerock.opendj.ldap.schema.SchemaOptions.DEFAULT_MATCHING_RULE_OID;
22+
import static org.forgerock.opendj.ldap.schema.SchemaOptions.DEFAULT_SYNTAX_OID;
23+
import static org.opends.messages.ConfigMessages.INFO_CONFIG_FILE_HEADER;
24+
import static org.opends.messages.ToolMessages.ERR_UPGRADE_CORRUPTED_TEMPLATE;
25+
import static org.opends.messages.ToolMessages.ERR_UPGRADE_READING_CONF_FILE;
26+
import static org.opends.messages.ToolMessages.ERR_UPGRADE_UNKNOWN_OC_ATT;
27+
import static org.opends.server.tools.upgrade.FileManager.deleteRecursively;
28+
import static org.opends.server.tools.upgrade.FileManager.rename;
29+
import static org.opends.server.tools.upgrade.Installation.CONFIG_PATH_RELATIVE;
30+
import static org.opends.server.tools.upgrade.Installation.CURRENT_CONFIG_FILE_NAME;
31+
import static org.opends.server.tools.upgrade.Installation.INSTANCE_LOCATION_PATH;
32+
import static org.opends.server.tools.upgrade.Installation.INSTANCE_LOCATION_PATH_RELATIVE;
33+
import static org.opends.server.tools.upgrade.Installation.LIB_RELATIVE_PATH;
34+
import static org.opends.server.tools.upgrade.Installation.LOCKS_PATH_RELATIVE;
35+
import static org.opends.server.tools.upgrade.Installation.OPENDJ_BOOTSTRAP_JAR_RELATIVE_PATH;
36+
import static org.opends.server.tools.upgrade.Installation.SCHEMA_PATH_RELATIVE;
37+
import static org.opends.server.tools.upgrade.Installation.SVC_SCRIPT_FILE_NAME;
38+
import static org.opends.server.tools.upgrade.Installation.TEMPLATE_RELATIVE_PATH;
39+
import static org.opends.server.tools.upgrade.Installation.UNIX_BINARIES_PATH_RELATIVE;
40+
import static org.opends.server.tools.upgrade.Installation.UPGRADE_PATH;
41+
import static org.opends.server.tools.upgrade.Installation.WINDOWS_BINARIES_PATH_RELATIVE;
42+
import static org.opends.server.util.ChangeOperationType.ADD;
43+
import static org.opends.server.util.ChangeOperationType.DELETE;
44+
import static org.opends.server.util.ChangeOperationType.MODIFY;
45+
import static org.opends.server.util.ServerConstants.SCHEMA_CONCAT_FILE_NAME;
46+
1847
import java.io.BufferedReader;
1948
import java.io.File;
2049
import java.io.FileInputStream;
@@ -23,11 +52,17 @@
2352
import java.io.FileReader;
2453
import java.io.FilenameFilter;
2554
import java.io.IOException;
55+
import java.nio.file.FileSystems;
56+
import java.nio.file.FileVisitResult;
57+
import java.nio.file.Files;
58+
import java.nio.file.Path;
59+
import java.nio.file.PathMatcher;
60+
import java.nio.file.SimpleFileVisitor;
61+
import java.nio.file.attribute.BasicFileAttributes;
2662
import java.util.HashMap;
2763
import java.util.HashSet;
2864
import java.util.Map;
2965
import java.util.Set;
30-
3166
import org.forgerock.i18n.LocalizableMessage;
3267
import org.forgerock.i18n.slf4j.LocalizedLogger;
3368
import org.forgerock.opendj.ldap.Assertion;
@@ -58,15 +93,6 @@
5893
import org.opends.server.util.ChangeOperationType;
5994
import org.opends.server.util.SchemaUtils;
6095

61-
import static org.forgerock.opendj.ldap.schema.CoreSchema.*;
62-
import static org.forgerock.opendj.ldap.schema.SchemaOptions.*;
63-
import static org.opends.messages.ConfigMessages.*;
64-
import static org.opends.messages.ToolMessages.*;
65-
import static org.opends.server.tools.upgrade.FileManager.*;
66-
import static org.opends.server.tools.upgrade.Installation.*;
67-
import static org.opends.server.util.ChangeOperationType.*;
68-
import static org.opends.server.util.ServerConstants.*;
69-
7096
/** Common utility methods needed by the upgrade. */
7197
final class UpgradeUtils
7298
{
@@ -754,6 +780,23 @@ static void deleteFileIfExists(final File f)
754780
}
755781
}
756782

783+
static void deleteMatchingFiles(Path base, String pattern) throws IOException {
784+
PathMatcher matcher = FileSystems.getDefault().getPathMatcher("glob:" + pattern);
785+
Files.walkFileTree(base, new SimpleFileVisitor<Path>() {
786+
@Override
787+
public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {
788+
return dir.equals(base) ? FileVisitResult.CONTINUE : FileVisitResult.SKIP_SUBTREE;
789+
}
790+
@Override
791+
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
792+
if (matcher.matches(file.getFileName()) && attrs.isRegularFile()) {
793+
Files.delete(file);
794+
}
795+
return FileVisitResult.CONTINUE;
796+
}
797+
});
798+
}
799+
757800
/** Prevent instantiation. */
758801
private UpgradeUtils()
759802
{

0 commit comments

Comments
 (0)