11package org .pitest .mutationtest .config ;
22
3+ import java .io .File ;
4+ import java .io .IOException ;
5+ import java .net .URISyntaxException ;
6+ import java .net .URL ;
7+ import java .nio .file .Paths ;
38import java .util .ArrayList ;
49import java .util .Collection ;
10+ import java .util .Enumeration ;
511import java .util .List ;
612
713import org .pitest .mutationtest .MutationEngineFactory ;
1319import org .pitest .plugin .ToolClasspathPlugin ;
1420import org .pitest .testapi .TestPluginFactory ;
1521import org .pitest .util .IsolationUtils ;
22+ import org .pitest .util .PitError ;
1623import org .pitest .util .ServiceLoader ;
1724
1825public class PluginServices {
@@ -53,10 +60,23 @@ public Iterable<? extends ClientClasspathPlugin> findClientClasspathPlugins() {
5360 l .addAll (nullPlugins ());
5461 return l ;
5562 }
63+
64+ public Iterable <? extends File > findClientClasspathPluginDescriptors () {
65+ final List <File > l = new ArrayList <>();
66+ l .addAll (findMutationEngineDescriptors ());
67+ l .addAll (findTestFrameworkPluginDescriptors ());
68+ l .addAll (nullPluginDescriptors ());
69+ return l ;
70+ }
71+
5672 Collection <? extends TestPluginFactory > findTestFrameworkPlugins () {
5773 return ServiceLoader .load (TestPluginFactory .class , this .loader );
5874 }
5975
76+ Collection <File > findTestFrameworkPluginDescriptors () {
77+ return findPluginDescriptors (TestPluginFactory .class );
78+ }
79+
6080 Collection <? extends MutationGrouperFactory > findGroupers () {
6181 return ServiceLoader .load (MutationGrouperFactory .class , this .loader );
6282 }
@@ -69,6 +89,10 @@ Collection<? extends MutationEngineFactory> findMutationEngines() {
6989 return ServiceLoader .load (MutationEngineFactory .class , this .loader );
7090 }
7191
92+ Collection <File > findMutationEngineDescriptors () {
93+ return findPluginDescriptors (MutationEngineFactory .class );
94+ }
95+
7296 Collection <? extends TestPrioritiserFactory > findTestPrioritisers () {
7397 return ServiceLoader .load (TestPrioritiserFactory .class , this .loader );
7498 }
@@ -77,8 +101,28 @@ private Collection<ClientClasspathPlugin> nullPlugins() {
77101 return ServiceLoader .load (ClientClasspathPlugin .class , this .loader );
78102 }
79103
104+ private Collection <File > nullPluginDescriptors () {
105+ return findPluginDescriptors (ClientClasspathPlugin .class );
106+ }
107+
80108 public Collection <? extends MutationInterceptorFactory > findInterceptors () {
81109 return ServiceLoader .load (MutationInterceptorFactory .class , this .loader );
82110 }
83111
112+ private Collection <File > findPluginDescriptors (Class <?> ifc ) {
113+ try {
114+ final Collection <File > pluginDescriptors = new ArrayList <>();
115+ Enumeration <URL > e = this .loader .getResources ("META-INF/services/" + ifc .getName ());
116+ while (e .hasMoreElements ()) {
117+ URL url = e .nextElement ();
118+ if (url .getProtocol () == "file" ) {
119+ pluginDescriptors .add (Paths .get (url .toURI ()).getParent ().getParent ().getParent ().toFile ());
120+ }
121+ }
122+ return pluginDescriptors ;
123+ } catch (final IOException | URISyntaxException ex ) {
124+ throw new PitError ("Error finding plugin descriptor for " + ifc .getName (), ex );
125+ }
126+ }
127+
84128}
0 commit comments