Skip to content

Commit 558c18b

Browse files
authored
Merge pull request #118 from intergral/114-failed-plugins-can-prevent-startup
fix(plugins): ensure that failed plugins do not block start up
2 parents d420fa2 + a3a8c04 commit 558c18b

File tree

7 files changed

+139
-1
lines changed

7 files changed

+139
-1
lines changed

.github/workflows/on_release.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ jobs:
6464
distribution: 'temurin'
6565
cache: 'maven'
6666

67+
- name: Update java version
68+
run: mvn versions:set -DnewVersion=${VERSION} -B -U
69+
6770
- name: Package project
6871
run: mvn clean package -DskipTests -U -B -P cf-it-tests,examples
6972

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# 1.2.1 - (12/03/2024)
22
- **[BUGFIX]**: plugin: fix ColdFusion detection on Windows [#116](https://github.com/intergral/deep/pull/116) [@LMarkie](https://github.com/LMarkie)
3+
- **[BUGFIX]**: plugin: ensure that failed plugins do not block start up [#118](https://github.com/intergral/deep/pull/118) [@Umaaz](https://github.com/Umaaz)
34

45
# 1.2.0 - (06/02/2024)
56
- **[CHANGE]**: change log config to allow better control of logging [#103](https://github.com/intergral/deep/pull/103) [@Umaaz](https://github.com/Umaaz)

agent/src/main/java/com/intergral/deep/agent/plugins/PluginSpiLoader.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,16 @@
2727
import java.util.List;
2828
import java.util.Set;
2929
import java.util.stream.Collectors;
30+
import org.slf4j.Logger;
31+
import org.slf4j.LoggerFactory;
3032

3133
/**
3234
* This acts as the main loader for plugins using the SPI loader system.
3335
*/
3436
public final class PluginSpiLoader {
3537

38+
private static final Logger LOGGER = LoggerFactory.getLogger(PluginSpiLoader.class);
39+
3640
private PluginSpiLoader() {
3741
}
3842

@@ -59,7 +63,12 @@ public static List<IDeepPlugin> loadPlugins(final ISettings settings, final IRef
5963
.filter(plugin -> !ResourceDetector.isDisabled(plugin.getClass(), enabledProviders, disabledProviders))
6064
.filter(plugin -> {
6165
if (plugin instanceof IConditional) {
62-
return ((IConditional) plugin).isActive();
66+
try {
67+
return ((IConditional) plugin).isActive();
68+
} catch (Exception e) {
69+
LOGGER.error("Failed to load plugin {}", plugin.getClass().getName(), e);
70+
return false;
71+
}
6372
}
6473
return true;
6574
})
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Copyright (C) 2024 Intergral GmbH
3+
*
4+
* This program is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU Affero General Public License as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU Affero General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU Affero General Public License
15+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
16+
*/
17+
18+
package com.intergral.deep.agent.plugins;
19+
20+
import com.intergral.deep.agent.api.spi.IConditional;
21+
import com.intergral.deep.agent.api.spi.IDeepPlugin;
22+
23+
/**
24+
* This is used to test the SPI loder and just throws an exception on activate.
25+
*/
26+
public class MockBadPlugin implements IDeepPlugin, IConditional {
27+
28+
29+
@Override
30+
public boolean isActive() {
31+
throw new RuntimeException("test exception");
32+
}
33+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* Copyright (C) 2024 Intergral GmbH
3+
*
4+
* This program is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU Affero General Public License as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU Affero General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU Affero General Public License
15+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
16+
*/
17+
18+
package com.intergral.deep.agent.plugins;
19+
20+
import com.intergral.deep.agent.api.spi.IDeepPlugin;
21+
22+
/**
23+
* This is used to test the SPI loder and doesn't need to actually do anything.
24+
*/
25+
public class MockPlugin implements IDeepPlugin {
26+
27+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* Copyright (C) 2024 Intergral GmbH
3+
*
4+
* This program is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU Affero General Public License as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU Affero General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU Affero General Public License
15+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
16+
*/
17+
18+
package com.intergral.deep.agent.plugins;
19+
20+
import static org.junit.jupiter.api.Assertions.assertFalse;
21+
import static org.junit.jupiter.api.Assertions.assertNotNull;
22+
import static org.junit.jupiter.api.Assertions.assertTrue;
23+
24+
import com.intergral.deep.agent.api.settings.ISettings;
25+
import com.intergral.deep.agent.api.spi.IDeepPlugin;
26+
import java.util.List;
27+
import java.util.Set;
28+
import java.util.stream.Collectors;
29+
import org.junit.jupiter.api.Test;
30+
import org.mockito.Mockito;
31+
32+
class PluginSpiLoaderTest {
33+
34+
@Test
35+
void loadPlugins() {
36+
final ISettings settings = Mockito.mock(ISettings.class);
37+
final List<IDeepPlugin> iDeepPlugins = PluginSpiLoader.loadPlugins(settings, null, null);
38+
assertNotNull(iDeepPlugins);
39+
40+
assertTrue(iDeepPlugins.size() > 1);
41+
42+
final Set<String> classNames = iDeepPlugins.stream().map(Object::getClass).map(Class::getName).collect(Collectors.toSet());
43+
44+
assertTrue(classNames.contains(MockPlugin.class.getName()));
45+
assertFalse(classNames.contains(MockBadPlugin.class.getName()));
46+
}
47+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#
2+
# Copyright (C) 2024 Intergral GmbH
3+
#
4+
# This program is free software: you can redistribute it and/or modify
5+
# it under the terms of the GNU Affero General Public License as published by
6+
# the Free Software Foundation, either version 3 of the License, or
7+
# (at your option) any later version.
8+
#
9+
# This program is distributed in the hope that it will be useful,
10+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
# GNU Affero General Public License for more details.
13+
#
14+
# You should have received a copy of the GNU Affero General Public License
15+
# along with this program. If not, see <https://www.gnu.org/licenses/>.
16+
#
17+
com.intergral.deep.agent.plugins.MockPlugin
18+
com.intergral.deep.agent.plugins.MockBadPlugin

0 commit comments

Comments
 (0)