Skip to content

Commit b9ff720

Browse files
committed
Fix compatibility issue with Openfire 4.9.0
Replaced Openfire API usage that was deprecated in Openfire 4.8.0 and removed in 4.9.0. This plugin is now compatible with Openfire 4.9.0 and requires 4.8.0 or later. No longer compatible with versions older than 4.8.0. fixes #387
1 parent a9247d7 commit b9ff720

13 files changed

Lines changed: 146 additions & 85 deletions

File tree

changelog.html

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,11 @@ <h1>
4444
Monitoring Plugin Changelog
4545
</h1>
4646

47-
<p><b>2.5.1</b> -- (tbd)</p>
47+
<p><b>2.6.0</b> -- (tbd)</p>
4848
<ul>
49-
<li>[<a href='https://github.com/igniterealtime/openfire-monitoring-plugin/issues/377'>Issue #383</a>] - Fixes: Database query fails on Oracle</li>
49+
<li>Requires Openfire 4.8.0</li>
50+
<li>[<a href='https://github.com/igniterealtime/openfire-monitoring-plugin/issues/387'>Issue #387</a>] - Fixes: Compatibility issue with Openfire 4.9.0</li>
51+
<li>[<a href='https://github.com/igniterealtime/openfire-monitoring-plugin/issues/383'>Issue #383</a>] - Fixes: Database query fails on Oracle</li>
5052
<li>[<a href='https://github.com/igniterealtime/openfire-monitoring-plugin/issues/377'>Issue #377</a>] - Fixes: Erroneous index confirmation message</li>
5153
<li>[<a href='https://github.com/igniterealtime/openfire-monitoring-plugin/issues/367'>Issue #367</a>] - Fixes: JRobin's repository uses invalid certificate</li>
5254
<li>[<a href='https://github.com/igniterealtime/openfire-monitoring-plugin/issues/249'>Issue #249</a>] - Fixes: Erroneous index rebuild progress indicator</li>

plugin.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
<description>Monitors conversations and statistics of the server.</description>
77
<author>Ignite Realtime</author>
88
<version>${project.version}</version>
9-
<date>2024-04-17</date>
10-
<minServerVersion>4.7.0</minServerVersion>
9+
<date>2024-08-23</date>
10+
<minServerVersion>4.8.0</minServerVersion>
1111
<minJavaVersion>1.8</minJavaVersion>
1212
<databaseKey>monitoring</databaseKey>
1313
<databaseVersion>8</databaseVersion>

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
<parent>
55
<artifactId>plugins</artifactId>
66
<groupId>org.igniterealtime.openfire</groupId>
7-
<version>4.7.0</version>
7+
<version>4.8.0</version>
88
</parent>
99
<groupId>org.igniterealtime.openfire.plugins</groupId>
1010
<artifactId>monitoring</artifactId>
11-
<version>2.5.1-SNAPSHOT</version>
11+
<version>2.6.0-SNAPSHOT</version>
1212
<name>Monitoring Plugin</name>
1313
<description>Monitors conversations and statistics of the server.</description>
1414

src/java/com/reucon/openfire/plugin/archive/impl/MessageIndexer.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
/*
2+
* Copyright (C) 2008 Jive Software, 2024 Ignite Realtime Foundation. All rights reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
116
package com.reucon.openfire.plugin.archive.impl;
217

318
import org.apache.lucene.document.*;
@@ -17,6 +32,7 @@
1732
import javax.print.Doc;
1833
import java.io.File;
1934
import java.io.IOException;
35+
import java.nio.file.Path;
2036
import java.sql.Connection;
2137
import java.sql.PreparedStatement;
2238
import java.sql.ResultSet;
@@ -53,7 +69,7 @@ public class MessageIndexer extends LuceneIndexer
5369

5470
public MessageIndexer( final TaskEngine taskEngine, final ConversationManager conversationManager )
5571
{
56-
super(taskEngine, new File(JiveGlobals.getHomeDirectory() + File.separator + MonitoringConstants.NAME + File.separator + "msgsearch"), "MESSAGE", SCHEMA_VERSION);
72+
super(taskEngine, JiveGlobals.getHomePath().resolve(Path.of(MonitoringConstants.NAME, "msgsearch")), "MESSAGE", SCHEMA_VERSION);
5773
this.conversationManager = conversationManager;
5874
}
5975

src/java/com/reucon/openfire/plugin/archive/impl/MucIndexer.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
/*
2+
* Copyright (C) 2008 Jive Software, 2024 Ignite Realtime Foundation. All rights reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
116
package com.reucon.openfire.plugin.archive.impl;
217

318
import org.apache.lucene.document.*;
@@ -13,6 +28,7 @@
1328

1429
import java.io.File;
1530
import java.io.IOException;
31+
import java.nio.file.Path;
1632
import java.sql.Connection;
1733
import java.sql.PreparedStatement;
1834
import java.sql.ResultSet;
@@ -41,7 +57,7 @@ public class MucIndexer extends LuceneIndexer
4157

4258
public MucIndexer( final TaskEngine taskEngine, final ConversationManager conversationManager )
4359
{
44-
super(taskEngine, new File(JiveGlobals.getHomeDirectory() + File.separator + MonitoringConstants.NAME + File.separator + "mucsearch"), "MUCSEARCH", SCHEMA_VERSION);
60+
super(taskEngine, JiveGlobals.getHomePath().resolve(Path.of(MonitoringConstants.NAME, "mucsearch")), "MUCSEARCH", SCHEMA_VERSION);
4561
this.conversationManager = conversationManager;
4662
}
4763

src/java/org/jivesoftware/openfire/archive/ArchiveIndexer.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2008 Jive Software. All rights reserved.
2+
* Copyright (C) 2008 Jive Software, Ignite Realtime Foundation 2024. All rights reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -27,6 +27,7 @@
2727

2828
import java.io.File;
2929
import java.io.IOException;
30+
import java.nio.file.Path;
3031
import java.sql.Connection;
3132
import java.sql.PreparedStatement;
3233
import java.sql.ResultSet;
@@ -67,7 +68,7 @@ public class ArchiveIndexer extends org.jivesoftware.openfire.index.LuceneIndexe
6768
* @param taskEngine a task engine instance.
6869
*/
6970
public ArchiveIndexer(ConversationManager conversationManager, TaskEngine taskEngine) {
70-
super(taskEngine, new File(JiveGlobals.getHomeDirectory() + File.separator + MonitoringConstants.NAME + File.separator + "search"), "CONVERSATION", SCHEMA_VERSION);
71+
super(taskEngine, JiveGlobals.getHomePath().resolve(Path.of(MonitoringConstants.NAME, "search")), "CONVERSATION", SCHEMA_VERSION);
7172
this.conversationManager = conversationManager;
7273
}
7374

src/java/org/jivesoftware/openfire/archive/ConversationEventsQueue.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2008 Jive Software. All rights reserved.
2+
* Copyright (C) 2008 Jive Software, Ignite Realtime Foundation 2024. All rights reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,6 +16,7 @@
1616

1717
package org.jivesoftware.openfire.archive;
1818

19+
import java.time.Duration;
1920
import java.util.ArrayList;
2021
import java.util.HashMap;
2122
import java.util.List;
@@ -96,7 +97,7 @@ public void run() {
9697
}
9798
}
9899
};
99-
taskEngine.scheduleAtFixedRate(sendTask, JiveConstants.SECOND * 3, JiveConstants.SECOND * 3);
100+
taskEngine.scheduleAtFixedRate(sendTask, Duration.ofSeconds(3), Duration.ofSeconds(3));
100101
}
101102

102103
/**

src/java/org/jivesoftware/openfire/archive/ConversationManager.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2008 Jive Software. All rights reserved.
2+
* Copyright (C) 2008 Jive Software, Ignite Realtime Foundation 2024. All rights reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -255,7 +255,7 @@ public void run() {
255255
}
256256
}
257257
};
258-
taskEngine.scheduleAtFixedRate(cleanupTask, JiveConstants.MINUTE * 5, JiveConstants.MINUTE * 5);
258+
taskEngine.scheduleAtFixedRate(cleanupTask, Duration.ofMinutes(5), Duration.ofMinutes(5));
259259

260260
// Schedule a task to do conversation purging.
261261
maxAgeTask = new TimerTask() {
@@ -304,7 +304,7 @@ public void run() {
304304
}
305305
}
306306
};
307-
taskEngine.scheduleAtFixedRate(maxAgeTask, JiveConstants.MINUTE, JiveConstants.MINUTE);
307+
taskEngine.scheduleAtFixedRate(maxAgeTask, Duration.ofMinutes(1), Duration.ofMinutes(1));
308308

309309
// Register a statistic.
310310
Statistic conversationStat = new Statistic() {

src/java/org/jivesoftware/openfire/index/LuceneIndexer.java

Lines changed: 40 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
/*
2+
* Copyright (C) 2008 Jive Software, 2024 Ignite Realtime Foundation. All rights reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
116
package org.jivesoftware.openfire.index;
217

318
import org.apache.commons.io.FileUtils;
@@ -39,7 +54,7 @@ public abstract class LuceneIndexer
3954
private final int schemaVersion;
4055
protected TaskEngine taskEngine;
4156
protected RebuildFuture rebuildFuture;
42-
private File searchDir;
57+
private Path searchDir;
4358
private XMLProperties indexProperties;
4459
private Directory directory;
4560
private IndexSearcher searcher;
@@ -55,7 +70,7 @@ public abstract class LuceneIndexer
5570
.setPlugin(MonitoringConstants.PLUGIN_NAME)
5671
.build();
5772

58-
public LuceneIndexer(TaskEngine taskEngine, File searchDir, String logName, int schemaVersion)
73+
public LuceneIndexer(TaskEngine taskEngine, Path searchDir, String logName, int schemaVersion)
5974
{
6075
this.taskEngine = taskEngine;
6176
this.searchDir = searchDir;
@@ -66,19 +81,20 @@ public LuceneIndexer(TaskEngine taskEngine, File searchDir, String logName, int
6681
public void start()
6782
{
6883
Log.debug("Starting...");
69-
if ( !searchDir.exists() )
84+
if (!Files.exists(searchDir))
7085
{
71-
if ( !searchDir.mkdirs() )
72-
{
73-
Log.warn("Lucene index directory '{}' does not exist, but cannot be created!", searchDir);
86+
try {
87+
Files.createDirectories(searchDir);
88+
} catch (IOException e) {
89+
Log.warn("Lucene index directory '{}' does not exist, but cannot be created!", searchDir, e);
7490
}
7591
}
7692

7793
boolean indexCreated = false;
7894
try
7995
{
8096
indexProperties = loadPropertiesFile(searchDir);
81-
directory = FSDirectory.open(searchDir.toPath());
97+
directory = FSDirectory.open(searchDir);
8298
if ( !DirectoryReader.indexExists(directory) )
8399
{
84100
Log.info("Unable to find a Lucene index in {}. rebuilding.", directory);
@@ -94,7 +110,7 @@ public void start()
94110
{
95111
// See if the data on disk is of the schema version that we expect to be able to use.
96112
// TODO make this optional through configuration.
97-
final Path schemaVersionFile = searchDir.toPath().resolve("openfire-schema.version");
113+
final Path schemaVersionFile = searchDir.resolve("openfire-schema.version");
98114
final Scanner scanner = new Scanner(schemaVersionFile);
99115
int detectedSchemaVersion = -1;
100116
if (scanner.hasNextInt())
@@ -169,17 +185,22 @@ public void run()
169185
}
170186
};
171187
final Duration updateInterval = UPDATE_INTERVAL.getValue();
172-
taskEngine.schedule(indexUpdater, Duration.ofMinutes(1).toMillis(), updateInterval.toMillis());
188+
taskEngine.schedule(indexUpdater, Duration.ofMinutes(1), updateInterval);
173189
}
174190

175191
private void removeAndRebuildSearchDir() throws IOException {
176192
directory.close();
177-
FileUtils.deleteDirectory(searchDir);
178-
if ( !searchDir.mkdirs() )
193+
FileUtils.deleteDirectory(searchDir.toFile());
194+
if (!Files.exists(searchDir))
179195
{
180-
Log.warn("Lucene index directory '{}' cannot be recreated!", searchDir);
196+
try {
197+
Files.createDirectories(searchDir);
198+
} catch (IOException e) {
199+
Log.warn("Lucene index directory '{}' cannot be recreated!", searchDir, e);
200+
}
181201
}
182-
directory = FSDirectory.open(searchDir.toPath());
202+
203+
directory = FSDirectory.open(searchDir);
183204
}
184205

185206
protected synchronized Instant getLastModified()
@@ -244,7 +265,7 @@ public void stop()
244265
*/
245266
public long getIndexSize()
246267
{
247-
File[] files = searchDir.listFiles(( dir, name ) -> {
268+
File[] files = searchDir.toFile().listFiles(( dir, name ) -> {
248269
// Ignore the index properties file since it's not part of the index.
249270
return !name.equals("indexprops.xml");
250271
});
@@ -331,11 +352,11 @@ public synchronized Future<Integer> rebuildIndex() {
331352

332353
Log.debug("Removing old data from directory: {}", searchDir);
333354
try {
334-
FileUtils.cleanDirectory(searchDir);
335-
Files.write(searchDir.toPath().resolve("openfire-schema.version"), String.valueOf(this.schemaVersion).getBytes());
355+
FileUtils.cleanDirectory(searchDir.toFile());
356+
Files.write(searchDir.resolve("openfire-schema.version"), String.valueOf(this.schemaVersion).getBytes());
336357
indexProperties = loadPropertiesFile(searchDir);
337358
} catch ( IOException e ) {
338-
Log.warn("An exception occurred while trying to clean directory '{}' as part of a rebuild of the Lucene index that's in it.", searchDir);
359+
Log.warn("An exception occurred while trying to clean directory '{}' as part of a rebuild of the Lucene index that's in it.", searchDir, e);
339360
}
340361

341362
final Analyzer analyzer = new StandardAnalyzer();
@@ -431,9 +452,9 @@ public synchronized IndexSearcher getSearcher() throws IOException
431452
* loaded. If an XML file for the search properties isn't already
432453
* created, it will attempt to make a file with default values.
433454
*/
434-
private XMLProperties loadPropertiesFile( File searchDir ) throws IOException
455+
private XMLProperties loadPropertiesFile( Path searchDir ) throws IOException
435456
{
436-
File indexPropertiesFile = new File(searchDir, "indexprops.xml");
457+
File indexPropertiesFile = new File(searchDir.toFile(), "indexprops.xml");
437458

438459
// Make sure the file actually exists. If it doesn't, a new file
439460
// will be created.

src/java/org/jivesoftware/openfire/plugin/MonitoringPlugin.java

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2008 Jive Software, 2022-2023 Ignite Realtime Foundation. All rights reserved.
2+
* Copyright (C) 2008 Jive Software, 2022-2024 Ignite Realtime Foundation. All rights reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -18,6 +18,9 @@
1818

1919
import java.io.File;
2020
import java.io.FileFilter;
21+
import java.io.IOException;
22+
import java.nio.file.Files;
23+
import java.nio.file.Path;
2124
import java.util.ArrayList;
2225
import java.util.List;
2326

@@ -170,28 +173,22 @@ public void initializePlugin(PluginManager manager, File pluginDirectory) {
170173
xep0313Support2 = new Xep0313Support2(XMPPServer.getInstance());
171174
xep0313Support2.start();
172175

173-
// Check if we Enterprise is installed and stop loading this plugin if
174-
// found
175-
File pluginDir = new File(JiveGlobals.getHomeDirectory(), "plugins");
176-
File[] jars = pluginDir.listFiles(new FileFilter() {
177-
public boolean accept(File pathname) {
178-
String fileName = pathname.getName().toLowerCase();
179-
return (fileName.equalsIgnoreCase("enterprise.jar"));
180-
}
181-
});
182-
if (jars.length > 0) {
176+
// Check if we Enterprise is installed and stop loading this plugin if found
177+
if (manager.getPluginByName("enterprise").isPresent()) {
183178
// Do not load this plugin since Enterprise is still installed
184-
System.out
185-
.println("Enterprise plugin found. Stopping Monitoring Plugin");
186-
throw new IllegalStateException(
187-
"This plugin cannot run next to the Enterprise plugin");
179+
System.out.println("Enterprise plugin found. Stopping Monitoring Plugin");
180+
throw new IllegalStateException("This plugin cannot run next to the Enterprise plugin");
188181
}
189182

190183
// Make sure that the monitoring folder exists under the home directory
191-
File dir = new File(JiveGlobals.getHomeDirectory() + File.separator
192-
+ MonitoringConstants.NAME);
193-
if (!dir.exists()) {
194-
dir.mkdirs();
184+
final Path monitoringFolder = JiveGlobals.getHomePath().resolve(MonitoringConstants.NAME);
185+
if (!Files.exists(monitoringFolder))
186+
{
187+
try {
188+
Files.createDirectories(monitoringFolder);
189+
} catch (IOException e) {
190+
Log.warn("Monitoring directory '{}' does not exist, but cannot be created!", monitoringFolder, e);
191+
}
195192
}
196193

197194
loadPublicWeb(pluginDirectory);

0 commit comments

Comments
 (0)