public ClassPathByteArraySource() { this(new ClassPath()); }
public Collection<String> findClasses(final Predicate<String> nameFilter) { return FCollection.filter(classNames(), nameFilter); }
public Collection<ClassName> code() { return FCollection.filter( this.classPath.getComponent(this.pathFilter.getCodeFilter()) .findClasses(this.classFilter.getCode()), this.classFilter.getCode()).stream() .map(ClassName.stringToClassName()) .collect(Collectors.toList()); }
private ClassPath classPathWithoutJUnit() { final List<File> cpWithoutJUnit = ClassPath.getClassPathElementsAsFiles().stream() .filter(file -> !file.getName().contains("junit")) .collect(Collectors.toList()); return new ClassPath(cpWithoutJUnit); }
@Override public Optional<byte[]> getBytes(final String classname) { final ClassPath cp = new ClassPath(new ResourceFolderClassPathroot()); try { return Optional.ofNullable(cp.getClassData(classname)); } catch (final IOException ex) { throw Unchecked.translateCheckedException(ex); } }
@Test public void waitToDieShouldReturnProcessExitCode() throws IOException, InterruptedException { final LaunchOptions launchOptions = new LaunchOptions(NullJavaAgent.instance(), new DefaultJavaExecutableLocator(), Collections.<String> emptyList(), new HashMap<String, String>()); final ProcessArgs processArgs = ProcessArgs .withClassPath(new ClassPath().getLocalClassPath()) .andBaseDir(new File(System.getProperty("user.dir"))) .andLaunchOptions(launchOptions).andStdout(nullHandler()) .andStderr(nullHandler()); final WrappingProcess wrappingProcess = new WrappingProcess(-1, processArgs, getClass()); wrappingProcess.start(); final JavaProcess process = wrappingProcess.getProcess(); assertTrue(process.isAlive()); assertEquals(EXIT_CODE, process.waitToDie()); }
@Override public Optional<byte[]> getBytes(final String classname) { try { return Optional.ofNullable(this.classPath.getClassData(classname)); } catch (final IOException e) { LOG.fine("Could not read class " + classname + ":" + e.getMessage()); return Optional.empty(); } } }
@Test public void shouldAllowSubComponentsToBeSelected() { assertEquals(Collections.singletonList("FooClass"), this.testee .getComponent(rootIsEqualTo("foo")).classNames()); }
public ClassPath() { this(ClassPath.getClassPathElementsAsFiles()); }
public static ProcessArgs withClassPath(final ClassPath cp) { return new ProcessArgs(cp.getLocalClassPath()); }
private void setClassPath(final OptionSet userArgs, final ReportOptions data) { final List<String> elements = new ArrayList<>(); if (data.isIncludeLaunchClasspath()) { elements.addAll(ClassPath.getClassPathElementsAsPaths()); } else { elements.addAll(FCollection.filter( ClassPath.getClassPathElementsAsPaths(), this.dependencyFilter)); } if (userArgs.has(this.classPathFile)) { try (BufferedReader classPathFileBR = new BufferedReader(new FileReader(userArgs.valueOf(this.classPathFile).getAbsoluteFile()))) { String element; while ((element = classPathFileBR.readLine()) != null) { elements.add(element); } } catch (final IOException ioe) { LOG.warning("Unable to read class path file:" + userArgs.valueOf(this.classPathFile).getAbsolutePath() + " - " + ioe.getMessage()); } } elements.addAll(userArgs.valuesOf(this.additionalClassPathSpec)); data.setClassPathElements(elements); }
@Test public void shouldFindMatchingClasses() { assertEquals(Arrays.asList("FooClass"), this.testee.findClasses(Prelude.isEqualTo("FooClass"))); }
@Override public Optional<byte[]> getBytes(final String classname) { try { return Optional.ofNullable(this.cp.getClassData(classname)); } catch (final IOException ex) { throw Unchecked.translateCheckedException(ex); } }
public static Collection<String> getClassPathElementsAsPaths() { final Set<String> filesAsString = new LinkedHashSet<>(); FCollection.mapTo(getClassPathElementsAsFiles(), file -> file.getPath(), filesAsString); return filesAsString; }
private List<MutationAnalysisUnit> buildMutationTests( final CoverageDatabase coverageData, final MutationEngine engine, EngineArguments args) { final MutationConfig mutationConfig = new MutationConfig(engine, coverage() .getLaunchOptions()); final ClassByteArraySource bas = fallbackToClassLoader(new ClassPathByteArraySource( this.data.getClassPath())); final TestPrioritiser testPrioritiser = this.settings.getTestPrioritiser() .makeTestPrioritiser(this.data.getFreeFormProperties(), this.code, coverageData); final MutationInterceptor interceptor = this.settings.getInterceptor() .createInterceptor(this.data, bas); final MutationSource source = new MutationSource(mutationConfig, testPrioritiser, bas, interceptor); final MutationAnalyser analyser = new IncrementalAnalyser( new DefaultCodeHistory(this.code, history()), coverageData); final WorkerFactory wf = new WorkerFactory(this.baseDir, coverage() .getConfiguration(), mutationConfig, args, new PercentAndConstantTimeoutStrategy(this.data.getTimeoutFactor(), this.data.getTimeoutConstant()), this.data.isVerbose(), this.data.isFullMutationMatrix(), this.data.getClassPath().getLocalClassPath()); final MutationGrouper grouper = this.settings.getMutationGrouper().makeFactory( this.data.getFreeFormProperties(), this.code, this.data.getNumberOfThreads(), this.data.getMutationUnitSize()); final MutationTestBuilder builder = new MutationTestBuilder(wf, analyser, source, grouper); return builder.createMutationTestUnits(this.code.getCodeUnderTestNames()); }
@Test public void shouldMutateClassesSuppliedToAlternateClassPath() throws IOException { // yes, this is horrid final String location = FileUtil.randomFilename() + ".jar"; try { try (FileOutputStream fos = new FileOutputStream(location)) { final InputStream stream = IsolationUtils.getContextClassLoader() .getResourceAsStream("outofcp.jar"); copy(stream, fos); } this.data.setTargetClasses(asList("com.outofclasspath.*Mutee*")); this.data.setTargetTests(predicateFor("com.outofclasspath.*")); final List<String> cp = new ArrayList<>(); cp.addAll(ClassPath.getClassPathElementsAsPaths()); cp.add(location); this.data.setClassPathElements(cp); this.data.setDependencyAnalysisMaxDistance(-1); this.data.setExcludedClasses(asList("*Power*", "*JMockit*")); createAndRun(); verifyResults(KILLED); } finally { new File(location).delete(); } }
public ClassPath getComponent(final Predicate<ClassPathRoot> predicate) { return new ClassPath(FCollection.filter(this.root, predicate).toArray( new ClassPathRoot[0])); }
public Collection<ClassName> test() { return FCollection.filter( this.classPath.getComponent(this.pathFilter.getTestFilter()) .findClasses(this.classFilter.getTest()), this.classFilter.getTest()).stream() .map(ClassName.stringToClassName()) .collect(Collectors.toList()); }
@Override protected Class<?> findClass(final String name) throws ClassNotFoundException { try { final byte[] b = this.classPath.getClassData(name); if (b == null) { throw new ClassNotFoundException(name); } definePackage(name); return defineClass(name, b); } catch (final IOException exception) { throw new ClassNotFoundException(name, exception); } }
public ClassPath() { this(ClassPath.getClassPathElementsAsFiles()); }