Skip to content

Commit dada5bf

Browse files
Issue 52684: Update Log4j plugin registration
1 parent 9c5da74 commit dada5bf

File tree

11 files changed

+55
-223
lines changed

11 files changed

+55
-223
lines changed

server/bootstrap/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ dependencies
2121
strictly "${apacheTomcatVersion}"
2222
}
2323
}
24+
implementation "org.apache.logging.log4j:log4j-core:${log4j2Version}"
2425
}
2526

2627
def JAR_BASE_NAME = "labkeyBootstrap"

server/bootstrap/src/org/labkey/bootstrap/CommonsLogger.java

Lines changed: 0 additions & 105 deletions
This file was deleted.

server/bootstrap/src/org/labkey/bootstrap/LabKeyBootstrapClassLoader.java

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
import org.apache.catalina.WebResourceRoot;
2020
import org.apache.catalina.loader.WebappClassLoader;
21+
import org.apache.logging.log4j.LogManager;
22+
import org.apache.logging.log4j.Logger;
2123

2224
import java.io.File;
2325
import java.io.FileNotFoundException;
@@ -41,7 +43,7 @@
4143
*/
4244
public class LabKeyBootstrapClassLoader extends WebappClassLoader implements ExplodedModuleService
4345
{
44-
private final SimpleLogger _log = new CommonsLogger(LabKeyBootstrapClassLoader.class);
46+
private final static Logger _log = LogManager.getLogger(LabKeyBootstrapClassLoader.class);
4547

4648
/** Modules which have been previously logged as having changed, which would trigger a webapp redeployment in development scenarios */
4749
private final Set<String> _previouslyLoggedModules = new HashSet<>();
@@ -87,7 +89,7 @@ private void extract(File webappDir)
8789
{
8890
try
8991
{
90-
_moduleExtractor = new ModuleExtractor(webappDir, new CommonsLogger(ModuleExtractor.class));
92+
_moduleExtractor = new ModuleExtractor(webappDir);
9193
var explodedModules = _moduleExtractor.extractModules();
9294
for(var exploded : explodedModules)
9395
{
@@ -176,10 +178,6 @@ public List<Map.Entry<File,File>> getExplodedModules()
176178
*
177179
* NOTE: this doesn't guarantee that the webapp won't reload. The caller has to inspect the archive
178180
* to ensure that.
179-
*
180-
* @param updatedArchive
181-
* @param existingArchive
182-
* @return
183181
*/
184182
public void validateReplaceArchive(File explodedModuleDirectory, File updatedArchive, File existingArchive) throws IOException
185183
{
@@ -193,8 +191,8 @@ public void validateReplaceArchive(File explodedModuleDirectory, File updatedArc
193191
if (!_moduleExtractor.hasExplodedArchive(existingArchive))
194192
throw new IllegalStateException(existingArchive.getAbsolutePath() + " it not an existing archive");
195193

196-
ModuleArchive existingModuleArchive = new ModuleArchive(existingArchive, _log);
197-
ModuleArchive updatedModuleArchive = new ModuleArchive(updatedArchive, _log);
194+
ModuleArchive existingModuleArchive = new ModuleArchive(existingArchive);
195+
ModuleArchive updatedModuleArchive = new ModuleArchive(updatedArchive);
198196
if (!existingModuleArchive.getModuleName().equalsIgnoreCase(updatedModuleArchive.getModuleName()))
199197
throw new IllegalArgumentException("Module name doesn't match, expected " + existingModuleArchive.getModuleName());
200198

@@ -286,7 +284,7 @@ public void validateCreateArchive(File newArchive, File target) throws IOExcepti
286284
if (target.exists())
287285
throw new IllegalArgumentException("File already exists: " + target.getPath());
288286

289-
ModuleArchive newModuleArchive = new ModuleArchive(newArchive, _log);
287+
ModuleArchive newModuleArchive = new ModuleArchive(newArchive);
290288
String moduleName = newModuleArchive.getModuleName();
291289
if (null==moduleName || moduleName.isBlank())
292290
throw new IllegalArgumentException("Module name not found in archive");

server/bootstrap/src/org/labkey/bootstrap/ModuleArchive.java

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
*/
1616
package org.labkey.bootstrap;
1717

18+
import org.apache.logging.log4j.LogManager;
19+
import org.apache.logging.log4j.Logger;
1820
import org.xml.sax.Attributes;
1921
import org.xml.sax.SAXException;
2022
import org.xml.sax.helpers.DefaultHandler;
@@ -53,10 +55,8 @@ public class ModuleArchive
5355
protected static final FileComparator _fileComparator = new FileComparator();
5456

5557
private final File _file;
56-
private final long _modified;
5758
private final String _moduleName;
58-
private final SimpleLogger _log;
59-
private final boolean _hasJavaCode;
59+
private final static Logger LOG = LogManager.getLogger(ModuleArchive.class);
6060

6161

6262
private String stripToNull(String s)
@@ -118,12 +118,10 @@ private String nameFromModuleProperties(InputStream is) throws IOException
118118
}
119119

120120

121-
public ModuleArchive(File file, SimpleLogger log) throws IOException
121+
public ModuleArchive(File file) throws IOException
122122
{
123123
_file = file;
124124
assert _file.exists() && _file.isFile();
125-
_modified = _file.lastModified();
126-
_log = log;
127125

128126
String moduleName = null;
129127
boolean hasJavaCode = false;
@@ -163,7 +161,6 @@ public ModuleArchive(File file, SimpleLogger log) throws IOException
163161
}
164162

165163
_moduleName = moduleName;
166-
_hasJavaCode = hasJavaCode;
167164
}
168165

169166
public File getFile()
@@ -181,8 +178,7 @@ public String getModuleName()
181178
if (null == _moduleName)
182179
{
183180
String fileName = getFile().getName();
184-
String baseName = fileName.substring(0, fileName.length() - FILE_EXTENSION.length());
185-
return baseName;
181+
return fileName.substring(0, fileName.length() - FILE_EXTENSION.length());
186182
}
187183
return _moduleName;
188184
}
@@ -234,7 +230,7 @@ public void extractAll(File targetDirectory) throws IOException
234230

235231
File archiveFile = getFile();
236232
long archiveFileLastModified = archiveFile.lastModified();
237-
_log.info("Extracting module " + archiveFile.getName() + ".");
233+
LOG.info("Extracting module " + archiveFile.getName() + ".");
238234

239235
// delete existing directory so that files that are
240236
// no longer in the archive are removed
@@ -259,7 +255,7 @@ public void extractAll(File targetDirectory) throws IOException
259255

260256
//set last mod on target directory to match module file
261257
targetDirectory.setLastModified(archiveFileLastModified);
262-
_log.info("Done extracting module " + archiveFile.getName() + ". Processed " + fileCount + " file(s) in " + (System.currentTimeMillis() - startTime) + "ms.");
258+
LOG.info("Done extracting module " + archiveFile.getName() + ". Processed " + fileCount + " file(s) in " + (System.currentTimeMillis() - startTime) + "ms.");
263259
}
264260

265261
public File extractEntry(JarFile jar, JarEntry entry, File targetDirectory) throws IOException
@@ -271,7 +267,7 @@ public File extractEntry(JarFile jar, JarEntry entry, File targetDirectory) thro
271267
entryParent.mkdirs();
272268
if (!entryParent.isDirectory())
273269
{
274-
_log.error("Unable to create directory " + entryParent.getPath() + ", there may be a problem with file permissions");
270+
LOG.error("Unable to create directory " + entryParent.getPath() + ", there may be a problem with file permissions");
275271
}
276272

277273
// if entry is a directory, just mkdirs, set last mod and return

server/bootstrap/src/org/labkey/bootstrap/ModuleExtractor.java

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616

1717
package org.labkey.bootstrap;
1818

19+
import org.apache.logging.log4j.LogManager;
20+
import org.apache.logging.log4j.Logger;
21+
1922
import java.io.*;
2023
import java.util.*;
2124
import java.util.concurrent.ConcurrentHashMap;
@@ -37,13 +40,12 @@ public class ModuleExtractor
3740
private Set<File> _ignoredExplodedDirs;
3841
private Set<ExplodedModule> _explodedModules;
3942

40-
private final SimpleLogger _log;
43+
private static final Logger _log = LogManager.getLogger(ModuleExtractor.class);
4144

42-
public ModuleExtractor(File webAppDirectory, SimpleLogger log)
45+
public ModuleExtractor(File webAppDirectory)
4346
{
4447
_webAppDirectory = webAppDirectory;
4548
_moduleDirectories = new ModuleDirectories(_webAppDirectory);
46-
_log = log;
4749
}
4850

4951
public Collection<ExplodedModule> extractModules()
@@ -71,11 +73,11 @@ public Collection<ExplodedModule> extractModules()
7173
.map(moduleArchiveFile -> {
7274
try
7375
{
74-
return new ModuleArchive(moduleArchiveFile, _log);
76+
return new ModuleArchive(moduleArchiveFile);
7577
}
7678
catch (IOException e)
7779
{
78-
_log.error("Unable to open module archive " + moduleArchiveFile.getPath() + "!", e);
80+
_log.error("Unable to open module archive {}!", moduleArchiveFile.getPath(), e);
7981
_errorArchives.put(moduleArchiveFile, moduleArchiveFile.lastModified());
8082
return null;
8183
}
@@ -89,8 +91,8 @@ public Collection<ExplodedModule> extractModules()
8991
if (null != found)
9092
{
9193
var re = new IllegalStateException("LabKey found two modules with the name \"" + moduleArchive.getModuleName() + "\". Please resolve this problem and restart the server");
92-
_log.error("Unable to extract module archive " + found.getFile().getPath() + "!");
93-
_log.error("Unable to extract module archive " + moduleArchive.getFile().getPath(), re);
94+
_log.error("Unable to extract module archive {}!", found.getFile().getPath());
95+
_log.error("Unable to extract module archive {}", moduleArchive.getFile().getPath(), re);
9496
throw re;
9597
}
9698
}
@@ -107,7 +109,7 @@ public Collection<ExplodedModule> extractModules()
107109
}
108110
catch (IOException e)
109111
{
110-
_log.error("Unable to extract module archive " + moduleArchiveFile.getPath() + "!", e);
112+
_log.error("Unable to extract module archive {}!", moduleArchiveFile.getPath(), e);
111113
_errorArchives.put(moduleArchiveFile, moduleArchiveFile.lastModified());
112114
}
113115
});
@@ -120,7 +122,7 @@ public Collection<ExplodedModule> extractModules()
120122
// from a .module archive.
121123
_moduleDirectories.streamAllModuleDirectories()
122124
.flatMap(dir-> {File[] files=dir.listFiles(File::isDirectory); return null==files ? null : Stream.of(files);})
123-
.collect(Collectors.toList()) // This intermediate list is critical. See comment above.
125+
.toList() // This intermediate list is critical. See comment above.
124126
.parallelStream()
125127
.forEach(dir->{
126128
if (dir.isHidden() || dir.getName().startsWith("."))
@@ -133,16 +135,16 @@ public Collection<ExplodedModule> extractModules()
133135
{
134136
ModuleArchive archive = mapModuleDirToArchive.get(dir.getAbsoluteFile());
135137
ExplodedModule explodedModule = new ExplodedModule(dir, null==archive?null:archive.getFile());
136-
_log.info("Deploying resources from " + explodedModule.getRootDirectory() + ".");
138+
_log.info("Deploying resources from {}.", explodedModule.getRootDirectory());
137139
long startTime = System.currentTimeMillis();
138140
Set<File> moduleWebAppFiles = explodedModule.deployToWebApp(_webAppDirectory);
139141

140142
_explodedModules.add(explodedModule);
141-
_log.info("Done deploying resources from " + explodedModule.getRootDirectory() + ". Extracted " + moduleWebAppFiles.size() + " file(s) in " + (System.currentTimeMillis() - startTime) + "ms.");
143+
_log.info("Done deploying resources from {}. Extracted {} file(s) in {}ms.", explodedModule.getRootDirectory(), moduleWebAppFiles.size(), System.currentTimeMillis() - startTime);
142144
}
143145
catch(IOException e)
144146
{
145-
_log.error("Unable to deploy resources from exploded module " + dir.getPath() + " to web app directory!", e);
147+
_log.error("Unable to deploy resources from exploded module {} to web app directory!", dir.getPath(), e);
146148
}
147149
});
148150

@@ -239,7 +241,7 @@ public boolean areModulesModified(Set<String> previouslyLoggedModules)
239241
moduleArchive = null;
240242
if (null == moduleArchive)
241243
{
242-
moduleArchive = new ModuleArchive(moduleArchiveFile, _log);
244+
moduleArchive = new ModuleArchive(moduleArchiveFile);
243245
File explodedDir = moduleArchive.extractAll();
244246
new ExplodedModule(explodedDir).deployToWebApp(_webAppDirectory);
245247
_moduleArchiveFiles.put(moduleArchiveFile, moduleArchive);
@@ -320,7 +322,7 @@ public boolean hasExplodedArchive(File moduleArchive)
320322
*/
321323
public Map.Entry<File,File> extractUpdatedModuleArchive(File moduleArchiveFile, File previousArchiveFile) throws IOException
322324
{
323-
ModuleArchive moduleArchive = new ModuleArchive(moduleArchiveFile, _log);
325+
ModuleArchive moduleArchive = new ModuleArchive(moduleArchiveFile);
324326
File explodedDir = moduleArchive.extractAll();
325327

326328
ExplodedModule explodedModule = new ExplodedModule(explodedDir, moduleArchiveFile);
@@ -340,7 +342,7 @@ public Map.Entry<File,File> extractUpdatedModuleArchive(File moduleArchiveFile,
340342

341343
public Map.Entry<File,File> extractNewModuleArchive(File moduleArchiveFile) throws IOException
342344
{
343-
ModuleArchive moduleArchive = new ModuleArchive(moduleArchiveFile, _log);
345+
ModuleArchive moduleArchive = new ModuleArchive(moduleArchiveFile);
344346
File explodedDir = moduleArchive.extractAll();
345347

346348
ExplodedModule explodedModule = new ExplodedModule(explodedDir, moduleArchiveFile);
@@ -356,15 +358,14 @@ public Map.Entry<File,File> extractNewModuleArchive(File moduleArchiveFile) thro
356358
* Extract .module files
357359
* @param args see usages
358360
* @throws ConfigException thrown if there is a problem with the configuration
359-
* @throws IOException thrown if there is a problem extracting the module archives
360361
*/
361362
public static void main(String... args)
362363
{
363364
try
364365
{
365366
PipelineBootstrapConfig config = new PipelineBootstrapConfig(args, false);
366367

367-
ModuleExtractor extractor = new ModuleExtractor(config.getWebappDir(), new StdOutLogger());
368+
ModuleExtractor extractor = new ModuleExtractor(config.getWebappDir());
368369
extractor.extractModules();
369370
}
370371
catch (ConfigException e)

server/bootstrap/src/org/labkey/bootstrap/PipelineBootstrapConfig.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ private synchronized void init()
177177
{
178178
if (_classLoader == null)
179179
{
180-
ModuleExtractor extractor = new ModuleExtractor(getWebappDir(), new StdOutLogger());
180+
ModuleExtractor extractor = new ModuleExtractor(getWebappDir());
181181
Collection<ExplodedModule> explodedModules = extractor.extractModules();
182182
_moduleFiles = new ArrayList<>(extractor.getExplodedModuleDirectories());
183183
_moduleSpringContextFiles = new ArrayList<>();

0 commit comments

Comments
 (0)