Skip to content

Commit 5004021

Browse files
author
Vladimir Kotal
authored
fix Sonar issues in PluginFramework (#3845)
* synchronize setPluginDirectory(String directory) * limit visibility of PluginFramework constructor * no need for protected in final class * fix doc
1 parent 515292a commit 5004021

File tree

3 files changed

+18
-6
lines changed

3 files changed

+18
-6
lines changed

opengrok-indexer/src/main/java/org/opengrok/indexer/authorization/AuthorizationFramework.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ public void setStack(AuthorizationStack s) {
245245
* @param stack the stack
246246
* @param entity the authorization entity (stack or plugin)
247247
*/
248-
protected void addPlugin(AuthorizationStack stack, AuthorizationEntity entity) {
248+
void addPlugin(AuthorizationStack stack, AuthorizationEntity entity) {
249249
if (stack != null) {
250250
stack.add(entity);
251251
}
@@ -378,12 +378,12 @@ protected void afterReload() {
378378
loadAllPlugins(loadingStack);
379379

380380
AuthorizationStack oldStack;
381-
/**
382-
* Replace the stack in a write lock to avoid inconsistent state between
381+
/*
382+
* Replace the stack in write lock to avoid inconsistent state between
383383
* the stack change and currently executing requests performing some
384384
* authorization on the same stack.
385385
*
386-
* @see #performCheck is controlled with a read lock
386+
* performCheck() uses read lock.
387387
*/
388388
lock.writeLock().lock();
389389
try {

opengrok-indexer/src/main/java/org/opengrok/indexer/framework/PluginFramework.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public abstract class PluginFramework<PluginType> {
8080
* @param classType the class of the plugin type
8181
* @param path the plugin directory path
8282
*/
83-
public PluginFramework(Class<PluginType> classType, String path) {
83+
protected PluginFramework(Class<PluginType> classType, String path) {
8484
this.classType = classType;
8585
setPluginDirectory(path);
8686
}
@@ -108,7 +108,7 @@ public synchronized void setPluginDirectory(File pluginDirectory) {
108108
*
109109
* @param directory the directory path
110110
*/
111-
public void setPluginDirectory(String directory) {
111+
public synchronized void setPluginDirectory(String directory) {
112112
setPluginDirectory(directory != null ? new File(directory) : null);
113113
}
114114

opengrok-indexer/src/test/java/org/opengrok/indexer/authorization/AuthorizationFrameworkTest.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import java.util.stream.Collectors;
3333

3434
import jakarta.servlet.http.HttpServletRequest;
35+
import org.junit.jupiter.api.Test;
3536
import org.junit.jupiter.params.ParameterizedTest;
3637
import org.junit.jupiter.params.provider.MethodSource;
3738
import org.opengrok.indexer.condition.DeliberateRuntimeException;
@@ -929,4 +930,15 @@ private static TestCase NewTest(boolean expected, Nameable entity) {
929930
private static TestCase NewTest(boolean expected, HttpServletRequest request, Nameable entity) {
930931
return new TestCase(expected, request, entity);
931932
}
933+
934+
@Test
935+
void setPluginDirectoryTest() {
936+
String pluginDirectoryPath = "foo";
937+
AuthorizationFramework authorizationFramework = new AuthorizationFramework(pluginDirectoryPath, null);
938+
assertEquals(pluginDirectoryPath, authorizationFramework.getPluginDirectory().toString());
939+
940+
pluginDirectoryPath = "bar";
941+
authorizationFramework.setPluginDirectory(pluginDirectoryPath);
942+
assertEquals(pluginDirectoryPath, authorizationFramework.getPluginDirectory().toString());
943+
}
932944
}

0 commit comments

Comments
 (0)