Skip to content

Commit

Permalink
Add plugin service descriptor paths to minion classpath
Browse files Browse the repository at this point in the history
  • Loading branch information
Vampire committed Sep 27, 2019
1 parent 013a9e7 commit 33c4d20
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ public class PluginFilter implements Predicate<String> {
public PluginFilter(final PluginServices plugin) {
FCollection.mapTo(plugin.findClientClasspathPlugins(), classToLocation(),
this.includedClassPathElement);
FCollection.mapTo(plugin.findClientClasspathPluginDescriptors(), fileToLocation(),
this.includedClassPathElement);
}

private static Function<ClientClasspathPlugin, String> classToLocation() {
Expand All @@ -43,6 +45,24 @@ private PitError createPitErrorForExceptionOnClass(final Exception ex,
};
}

private static Function<File, String> fileToLocation() {
return new Function<File, String>() {
@Override
public String apply(final File a) {
try {
return a.getCanonicalPath();
} catch (final IOException ex) {
throw createPitErrorForExceptionOnClass(ex, a);
}
}

private PitError createPitErrorForExceptionOnClass(final Exception ex,
final File file) {
return new PitError("Error getting location of file " + file, ex);
}
};
}

@Override
public boolean test(final String a) {
return this.includedClassPathElement.contains(a);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
package org.pitest.mutationtest.config;

import java.io.File;
import java.io.IOException;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Enumeration;
import java.util.List;

import org.pitest.mutationtest.MutationEngineFactory;
Expand All @@ -13,6 +19,7 @@
import org.pitest.plugin.ToolClasspathPlugin;
import org.pitest.testapi.TestPluginFactory;
import org.pitest.util.IsolationUtils;
import org.pitest.util.PitError;
import org.pitest.util.ServiceLoader;

public class PluginServices {
Expand Down Expand Up @@ -53,10 +60,23 @@ public Iterable<? extends ClientClasspathPlugin> findClientClasspathPlugins() {
l.addAll(nullPlugins());
return l;
}

public Iterable<? extends File> findClientClasspathPluginDescriptors() {
final List<File> l = new ArrayList<>();
l.addAll(findMutationEngineDescriptors());
l.addAll(findTestFrameworkPluginDescriptors());
l.addAll(nullPluginDescriptors());
return l;
}

Collection<? extends TestPluginFactory> findTestFrameworkPlugins() {
return ServiceLoader.load(TestPluginFactory.class, this.loader);
}

Collection<File> findTestFrameworkPluginDescriptors() {
return findPluginDescriptors(TestPluginFactory.class);
}

Collection<? extends MutationGrouperFactory> findGroupers() {
return ServiceLoader.load(MutationGrouperFactory.class, this.loader);
}
Expand All @@ -69,6 +89,10 @@ Collection<? extends MutationEngineFactory> findMutationEngines() {
return ServiceLoader.load(MutationEngineFactory.class, this.loader);
}

Collection<File> findMutationEngineDescriptors() {
return findPluginDescriptors(MutationEngineFactory.class);
}

Collection<? extends TestPrioritiserFactory> findTestPrioritisers() {
return ServiceLoader.load(TestPrioritiserFactory.class, this.loader);
}
Expand All @@ -77,8 +101,28 @@ private Collection<ClientClasspathPlugin> nullPlugins() {
return ServiceLoader.load(ClientClasspathPlugin.class, this.loader);
}

private Collection<File> nullPluginDescriptors() {
return findPluginDescriptors(ClientClasspathPlugin.class);
}

public Collection<? extends MutationInterceptorFactory> findInterceptors() {
return ServiceLoader.load(MutationInterceptorFactory.class, this.loader);
}

private Collection<File> findPluginDescriptors(Class<?> ifc) {
try {
final Collection<File> pluginDescriptors = new ArrayList<>();
Enumeration<URL> e = this.loader.getResources("META-INF/services/" + ifc.getName());
while (e.hasMoreElements()) {
URL url = e.nextElement();
if (url.getProtocol() == "file") {
pluginDescriptors.add(Paths.get(url.toURI()).getParent().getParent().getParent().toFile());
}
}
return pluginDescriptors;
} catch (final IOException | URISyntaxException ex) {
throw new PitError("Error finding plugin descriptor for " + ifc.getName(), ex);
}
}

}

0 comments on commit 33c4d20

Please sign in to comment.