Skip to content
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
14d2bba
Add functional tests #16
ChiuchiuSorin Nov 7, 2023
d07aae7
Add functional tests #16
ChiuchiuSorin Nov 8, 2023
d629057
Add functional tests #16 - draft
ChiuchiuSorin Nov 10, 2023
1430526
Add functional tests #16
ChiuchiuSorin Nov 14, 2023
9089388
Merge licensing into functional-tests
ChiuchiuSorin Nov 14, 2023
441fb84
Add functional tests #16
ChiuchiuSorin Nov 17, 2023
c2116d0
Merge remote-tracking branch 'origin/main' into functional-tests
ChiuchiuSorin Nov 21, 2023
214479e
Add functional tests #16
ChiuchiuSorin Dec 13, 2023
38d87f8
Add functional tests #16
ChiuchiuSorin Dec 14, 2023
d7a45e8
Merge remote-tracking branch 'origin/main' into functional-tests
ChiuchiuSorin Dec 20, 2023
1736eb5
Add functional tests #16
ChiuchiuSorin Dec 20, 2023
c8c295f
Merge remote-tracking branch 'origin/main' into functional-tests
ChiuchiuSorin Jan 16, 2024
27d5f75
Add functional tests #16
ChiuchiuSorin Jan 17, 2024
e0f69bd
Merge remote-tracking branch 'origin/main' into functional-tests
ChiuchiuSorin Jan 18, 2024
d94abf8
Merge remote-tracking branch 'origin/main' into functional-tests
ChiuchiuSorin Jan 30, 2024
0dd9234
Add functional tests #16
ChiuchiuSorin Jan 30, 2024
70cffc6
Merge remote-tracking branch 'origin/main' into functional-tests
ChiuchiuSorin Feb 14, 2024
80c2439
Merge branch 'main' into functional-tests
ChiuchiuSorin Feb 19, 2024
9d198d8
Merge branch 'main' into functional-tests
ChiuchiuSorin Feb 27, 2024
5a6f418
Add functional tests #16
ChiuchiuSorin Feb 27, 2024
292a560
Merge branch 'main' into functional-tests
ChiuchiuSorin Mar 28, 2024
eec7de8
Add functional tests #16
ChiuchiuSorin Mar 28, 2024
035d5f5
Merge branch 'main' into functional-tests
ChiuchiuSorin Apr 1, 2024
98de17c
Add functional tests #16
ChiuchiuSorin Apr 1, 2024
2a58e5b
Merge branch 'main' into functional-tests
ChiuchiuSorin Apr 2, 2024
ffa9b92
Merge branch 'main' into functional-tests
ChiuchiuSorin Nov 25, 2024
71ebc08
[MISC] Add functional tests #16
ChiuchiuSorin Nov 25, 2024
14b883d
Add functional tests #16
ChiuchiuSorin Dec 4, 2024
05f446d
[MISC] Add functional tests #16
ChiuchiuSorin Dec 4, 2024
2c66f85
[MISC] Add functional tests #16
ChiuchiuSorin Jan 17, 2025
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 @@ -19,15 +19,14 @@
*/
package com.xwiki.admintools;

import java.util.Map;
import java.util.regex.Pattern;

import org.xwiki.component.annotation.Role;

import java.util.regex.Pattern;

/**
* Exposes methods for accessing server specific information, like configurations, logs or other XWiki and server
* files.
*
* @version $Id$
*/
@Role
Expand All @@ -40,7 +39,7 @@ public interface ServerIdentifier
*
* @return {@code true} if the server is used, {@code false} otherwise.
*/
boolean isUsed();
boolean foundServerPath();

/**
* Extract the hint of a component.
Expand Down Expand Up @@ -68,13 +67,6 @@ public interface ServerIdentifier
*/
void updatePossiblePaths();

/**
* Access a JSON containing the server metadata.
*
* @return the server metadata.
*/
Map<String, String> getServerMetadata();

/**
* Get path to server.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Provider;
import javax.inject.Singleton;

import org.xwiki.bridge.event.DocumentDeletedEvent;
Expand Down Expand Up @@ -63,7 +64,7 @@ public class AdminToolsEventListener extends AbstractEventListener
private WikiDescriptorManager wikiManager;

@Inject
private CurrentServer currentServer;
private Provider<CurrentServer> currentServerProvider;

/**
* Creates an event-listener filtering for DocumentUpdatedEvent and DocumentDeletedEvent.
Expand All @@ -79,7 +80,7 @@ public void onEvent(Event event, Object source, Object data)
if (event instanceof DocumentUpdatedEvent || event instanceof DocumentDeletedEvent) {
XWikiDocument document = (XWikiDocument) source;
if (document != null && isAdminToolsConfigObject(document)) {
this.currentServer.updateCurrentServer();
this.currentServerProvider.get().updateCurrentServer();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
*/
package com.xwiki.admintools.internal;

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

import javax.inject.Inject;
Expand Down Expand Up @@ -95,7 +94,7 @@ public String generateData(String hint)
*/
public List<String> getSupportedDBs()
{
return new ArrayList<>(this.currentServer.getSupportedDBs().values());
return this.currentServer.getSupportedDBs();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,10 @@ public Map<String, String> getDataAsJSON() throws Exception
systemInfo.put("databaseName", dbMetadata.get(METADATA_NAME));
systemInfo.put("databaseVersion", dbMetadata.get(METADATA_VERSION));
systemInfo.put("xwikiCfgPath", getCurrentServer().getXwikiCfgFolderPath());
systemInfo.put("serverPath", getCurrentServer().getServerPath());
systemInfo.put("tomcatConfPath", this.getCurrentServer().getServerCfgPath());
systemInfo.put("javaVersion", this.getJavaVersion());
Map<String, String> serverMetadata = this.getCurrentServer().getServerMetadata();
Map<String, String> serverMetadata = this.currentServer.getServerMetadata();
systemInfo.put("usedServerName", serverMetadata.get(METADATA_NAME));
systemInfo.put("usedServerVersion", serverMetadata.get(METADATA_VERSION));
systemInfo.put("xwikiVersion", getXWikiVersion());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,20 @@
package com.xwiki.admintools.internal.data.identifiers;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.inject.Inject;
import javax.inject.Provider;
import javax.inject.Singleton;

import org.xwiki.activeinstalls2.internal.data.ServletContainerPing;
import org.xwiki.component.annotation.Component;
import org.xwiki.component.phase.Initializable;
import org.xwiki.component.phase.InitializationException;

import com.xwiki.admintools.ServerIdentifier;
import com.xwiki.admintools.internal.PingProvider;

/**
* Manages the server identifiers and offers endpoints to retrieve info about their paths.
Expand All @@ -43,11 +44,18 @@
@Singleton
public class CurrentServer implements Initializable
{
private static final String SERVER_NAME_KEY = "name";

private static final String SERVER_VERSION_KEY = "version";

@Inject
private Provider<List<ServerIdentifier>> supportedServers;

private ServerIdentifier currentServerIdentifier;

@Inject
private PingProvider pingProvider;

@Override
public void initialize() throws InitializationException
{
Expand All @@ -65,19 +73,13 @@ public ServerIdentifier getCurrentServer()
}

/**
* Get a {@link Map} with the supported databases.
* Get a {@link List} with the supported databases.
*
* @return the supported databases.
*/
public Map<String, String> getSupportedDBs()
public List<String> getSupportedDBs()
{
Map<String, String> supportedDBs = new HashMap<>();
supportedDBs.put("mysql", "MySQL");
supportedDBs.put("hsqldb", "HSQLDB");
supportedDBs.put("mariadb", "MariaDB");
supportedDBs.put("postgresql", "PostgreSQL");
supportedDBs.put("oracle", "Oracle");
return supportedDBs;
return List.of("MySQL", "HSQL", "MariaDB", "PostgreSQL", "Oracle");
}

/**
Expand All @@ -94,14 +96,29 @@ public List<String> getSupportedServers()
return supportedServerList;
}

/**
* Access a JSON containing the server metadata.
*
* @return the server metadata.
*/
public Map<String, String> getServerMetadata()
{
ServletContainerPing servletPing = pingProvider.getServletPing();
String serverName = servletPing.getName();
String serverVersion = servletPing.getVersion();
return Map.of(SERVER_NAME_KEY, serverName, SERVER_VERSION_KEY, serverVersion);
}

/**
* Go through all supported servers and return the one that is used.
*/
public void updateCurrentServer()
{
this.currentServerIdentifier = null;
for (ServerIdentifier serverIdentifier : this.supportedServers.get()) {
if (serverIdentifier.isUsed()) {
boolean matchingHint =
getServerMetadata().get(SERVER_NAME_KEY).toLowerCase().contains(serverIdentifier.getComponentHint());
if (matchingHint && serverIdentifier.foundServerPath()) {
this.currentServerIdentifier = serverIdentifier;
this.currentServerIdentifier.updatePossiblePaths();
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,14 @@
package com.xwiki.admintools.internal.data.identifiers;

import java.io.File;
import java.util.Map;
import java.util.regex.Pattern;

import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;

import org.xwiki.activeinstalls2.internal.data.ServletContainerPing;
import org.xwiki.component.annotation.Component;

import com.xwiki.admintools.ServerIdentifier;
import com.xwiki.admintools.internal.PingProvider;

/**
* {@link ServerIdentifier} implementation used for identifying a Tomcat server and retrieving its info.
Expand All @@ -46,29 +42,7 @@ public class TomcatIdentifier extends AbstractServerIdentifier
/**
* Component identifier.
*/
public static final String HINT = "Tomcat";

@Inject
private PingProvider pingProvider;

@Override
public boolean isUsed()
{
this.serverPath = null;
String providedConfigServerPath = this.adminToolsConfig.getServerPath();
if (providedConfigServerPath != null && !providedConfigServerPath.isEmpty()) {
return checkAndSetServerPath(providedConfigServerPath);
} else {
String catalinaBase = System.getProperty("catalina.base");
String catalinaHome = System.getenv("CATALINA_HOME");
if (catalinaBase != null && !catalinaBase.isEmpty()) {
return checkAndSetServerPath(catalinaBase);
} else if (catalinaHome != null && !catalinaHome.isEmpty()) {
return checkAndSetServerPath(catalinaHome);
}
}
return false;
}
public static final String HINT = "tomcat";

@Override
public String getComponentHint()
Expand All @@ -89,15 +63,6 @@ public void updatePossiblePaths()
String.format("%s/webapps/xwiki/WEB-INF/", this.serverPath) };
}

@Override
public Map<String, String> getServerMetadata()
{
ServletContainerPing servletPing = pingProvider.getServletPing();
String serverName = servletPing.getName();
String serverVersion = servletPing.getVersion();
return Map.of("name", serverName, "version", serverVersion);
}

@Override
public String getLogsFolderPath()
{
Expand All @@ -116,6 +81,25 @@ public Pattern getLogsPattern()
return Pattern.compile("\\d{4}-\\d{2}-\\d{2}");
}

@Override
public boolean foundServerPath()
{
this.serverPath = null;
String providedConfigServerPath = this.adminToolsConfig.getServerPath();
if (providedConfigServerPath != null && !providedConfigServerPath.isEmpty()) {
return checkAndSetServerPath(providedConfigServerPath);
} else {
String catalinaBase = System.getProperty("catalina.base");
String catalinaHome = System.getenv("CATALINA_HOME");
if (catalinaBase != null && !catalinaBase.isEmpty()) {
return checkAndSetServerPath(catalinaBase);
} else if (catalinaHome != null && !catalinaHome.isEmpty()) {
return checkAndSetServerPath(catalinaHome);
}
}
return false;
}

private boolean checkAndSetServerPath(String path)
{
File file = new File(path + "/conf/catalina.properties");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@
#if ($services.licensing.licensor.hasLicensureForEntity($mainReference))
#set ($discard = $xwiki.jsx.use('AdminTools.Code.AdminToolsJS'))
#includeMacros("AdminTools.Code.Macros")
#viewLastNLinesMoldal("configuration")
#if ($configuration['serverFound'] == 'true')
<div class="adminToolsDashboardItem">
<div id="adminToolsBackendSection" class="adminToolsDashboardItem">
<h2>$services.icon.renderHTML('world')
$escapetool.xml($services.localization.render('adminTools.dashboard.section.backend.title'))</h2>
<p>$escapetool.xml($services.localization.render('adminTools.dashboard.section.backend.description'))</p>
Expand Down Expand Up @@ -56,21 +57,31 @@
$configuration['osArch']</li>
</ul>
</li>
#if ($configuration['databaseName'] != $null)
<li>$escapetool.xml($services.localization.render('adminTools.dashboard.section.backend.usedDB'))
$configuration['databaseName'] - $configuration['databaseVersion']</li>
#set($databaseName = $configuration['databaseName'])
#if ($databaseName != $null)
<li>$escapetool.xml($services.localization.render('adminTools.dashboard.section.backend.usedDB'))
$databaseName - $configuration['databaseVersion']</li>
#set ($supportedDatabases = $services.admintools.getSupportedDatabases())
#set ($isSupported = false)
#databaseIsSupported($databaseName $supportedDatabases $isSupported)
#if (!$isSupported)
#set($warningDatabaseMessage = $escapetool.xml(
$services.localization.render('adminTools.dashboard.section.backend.supportedDB.error')) + ':')
#set($warningDatabaseMessage = $warningDatabaseMessage +
$stringtool.join($supportedDatabases, ', '))
#warning($warningDatabaseMessage)
#end
#else
#set($warningDatabaseMessage = $escapetool.xml(
$services.localization.render('adminTools.dashboard.section.backend.supportedDB.error')) + ':')
#set($warningDatabaseMessage = $warningDatabaseMessage +
$stringtool.join($services.admintools.getSupportedDatabases(), ', '))
<li>$escapetool.xml(
$services.localization.render('adminTools.dashboard.section.backend.usedDB')) #warning($warningDatabaseMessage)
</li>
<li>$escapetool.xml(
$services.localization.render('adminTools.dashboard.section.backend.usedDB')) #warning($warningDatabaseMessage)
</li>
#end
</ul>
</div>
#viewLastNLinesMoldal("configuration")
#else
#set($warningMessage =
$escapetool.xml($services.localization.render('adminTools.dashboard.section.backend.configuration.error'))+ '<br>')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#includeMacros("AdminTools.Code.Macros")
#set($adminToolsFilesPath = "$request.getContextPath()/rest/admintools/files")
#if ($found)
<div class="adminToolsDashboardItem">
<div id="adminToolsFilesSection" class="adminToolsDashboardItem">
<h2>$services.icon.renderHTML('download')
$escapetool.xml($services.localization.render('adminTools.dashboard.section.download.title'))</h2>
<p>$escapetool.xml($services.localization.render('adminTools.dashboard.section.download.description'))</p>
Expand All @@ -37,13 +37,13 @@
$escapetool.xml($services.localization.render('adminTools.dashboard.section.download.view.description'))
<ul>
<li>
<a href="$adminToolsFilesPath/xwikiConfig"
<a id="filesConfig" href="$adminToolsFilesPath/xwikiConfig"
target="_blank">
$escapetool.xml($services.localization.render('adminTools.dashboard.section.download.view.configuration'))
</a>
</li>
<li>
<a href="$adminToolsFilesPath/xwikiProperties"
<a id="filesProperties" href="$adminToolsFilesPath/xwikiProperties"
target="_blank">
$escapetool.xml($services.localization.render('adminTools.dashboard.section.download.view.properties'))
</a>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#set ($mainReference = $services.model.createDocumentReference('', ['AdminTools', 'Code'], 'ConfigurationClass'))
#if ($services.licensing.licensor.hasLicensureForEntity($mainReference))
#if($security['serverFound'] == 'true')
<div class="adminToolsDashboardItem">
<div id="adminToolsSecuritySection" class="adminToolsDashboardItem">
<h2>$services.icon.renderHTML('lock')
$escapetool.xml($services.localization.render('adminTools.dashboard.section.security.title'))</h2>
<p>$escapetool.xml($services.localization.render('adminTools.dashboard.section.security.description'))</p>
Expand Down
Loading