Skip to content

Commit

Permalink
Merge pull request #318 from hcoles/split_parent_child
Browse files Browse the repository at this point in the history
Separate main process code from code that share client classpath
  • Loading branch information
hcoles authored Dec 8, 2016
2 parents dd88086 + 73d78e0 commit 8cb135d
Show file tree
Hide file tree
Showing 251 changed files with 1,022 additions and 175 deletions.
27 changes: 24 additions & 3 deletions hackers_guide.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,37 @@ As long as the resulting binaries support Java 6 technically the build itself co

It is reccomended to use Java 8 while developing, but be aware that it is not possible to use any Java 8 (or 7) features.

# Eclipse users
## Structure

Pitest is split into several modules

* pitest - Main mutation engine and other code that must share a JVM with the system under test
* pitest-entry - The main entry point for build tools. Contains code that runs in main controller process.
* pitest-html-report - Generates the html report
* pitest-command-line - Command line tool for running pitet
* pitest-maven - Maven mojo for running pitest
* pitest-ant - Ant task for running pitest
* pitest-maven-verification - Integration tests that execute pitest via maven module
* pitest-java8-verification - Integration tests that validate pitest against java 8 features
* pitest-groovy-verification - Integration tests that validate pitets behaviour with groovy
* pitest-build-config - A minimal checkstyle configuration used in other modules.

Care must be taken not to load the code under test into the JVM within the pitest-entry module (e.g by the use of reflection).

Third party dependencies must not be introduced into the pitest module as they may conflict with those of the code under test. Where dependencies are unavoidable (e.g ASM) they must be shaded to avoid conflict.

Dependencies may be introduced into the other modules, but are discouraged so start a discussion before doing so. Any dependencies introduced must be added to the classpath by users of the command-line tool and Ant.

## Eclipse users

Import everything as an existing maven project. If you do not have groovy plugins installed the `pitest-groovy-verification` module will show errors. Unless you are working on something Groovy related it is easiest just to close the module rather than installing the Groovy dependencies into eclipse.

## Code format
### Code format

The files `code_format_profile.xml` and `code_cleanup_profile.xml` in the root of the repository.

Will create formatting and cleanup profiles named henry. Some aspects of these will be changed in the future (e.g. the use of columns to layout fields) but they should be used while editing pitest to maintain consistency.

# InteliJ
## InteliJ

?
2 changes: 0 additions & 2 deletions pitest-build-config/pom.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.pitest</groupId>
<artifactId>pitest-build-config</artifactId>
<version>1.1.12-SNAPSHOT</version>
<name>Build Config</name>
<parent>
<artifactId>pitest-parent</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion pitest-command-line/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
<dependencies>
<dependency>
<groupId>org.pitest</groupId>
<artifactId>pitest</artifactId>
<artifactId>pitest-entry</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
Expand Down
139 changes: 139 additions & 0 deletions pitest-entry/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>pitest-parent</artifactId>
<groupId>org.pitest</groupId>
<version>1.1.12-SNAPSHOT</version>
</parent>
<artifactId>pitest-entry</artifactId>
<name>pitest-entry</name>
<url>http://pitest.org</url>
<description>Pitest entry point</description>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
</manifest>
<index>true</index>
</archive>
</configuration>
<executions>
<execution>
<goals>
<goal>test-jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<testNGArtifactName>none:none</testNGArtifactName>

<includes>
<include>org/**/Test*.java</include>
<include>org/**/*Test.java</include>
</includes>
<excludes>
<exclude>**/*$*</exclude>
<exclude>com/*/**.java</exclude>
<exclude>**/FullyCoveredByTestNGTesteeTest.java</exclude>
</excludes>
<excludedGroups>org.pitest.SystemTest</excludedGroups>
</configuration>
<dependencies>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>${testng.version}</version>
</dependency>
</dependencies>
</plugin>

<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<configuration>

<!-- for PowerMockAgentTest -javaagent:"${settings.localRepository}"/org/powermock/powermock-module-javaagent/${powermock.version}/powermock-module-javaagent-${powermock.version}.jar -->
<argLine>-Dfoo=foo</argLine>

<groups>org.pitest.SystemTest</groups>
</configuration>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
<configuration>
<includes>
<include>**/*.class</include>
</includes>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>

<dependencies>
<dependency>
<groupId>org.pitest</groupId>
<artifactId>pitest</artifactId>
<version>${project.version}</version>
</dependency>
<!-- for the xstream history store. cannot used shaded version -->
<dependency>
<groupId>com.thoughtworks.xstream</groupId>
<artifactId>xstream</artifactId>
<version>1.4.8</version>
</dependency>
<dependency>
<groupId>org.pitest</groupId>
<artifactId>pitest</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>nl.jqno.equalsverifier</groupId>
<artifactId>equalsverifier</artifactId>
<version>1.7.5</version>
<scope>test</scope>
</dependency>

<!-- to verify compatibility -->
<dependency>
<groupId>org.easymock</groupId>
<artifactId>easymock</artifactId>
<version>3.3.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>${testng.version}</version>
<scope>test</scope>
</dependency>
</dependencies>

</project>
14 changes: 14 additions & 0 deletions pitest-entry/src/main/java/org/pitest/classinfo/AddlerHash.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package org.pitest.classinfo;

import java.util.zip.Adler32;

public class AddlerHash implements HashFunction {

@Override
public long hash(final byte[] value) {
final Adler32 adler = new Adler32();
adler.update(value);
return adler.getValue();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package org.pitest.classinfo;

import org.pitest.functional.Option;

public interface ClassInfoSource {
Option<ClassInfo> fetchClass(ClassName name);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package org.pitest.classinfo;

import org.pitest.functional.F;
import org.pitest.functional.Option;

public class NameToClassInfo implements F<ClassName, Option<ClassInfo>> {

private final ClassInfoSource repository;

public NameToClassInfo(final ClassInfoSource repository) {
this.repository = repository;
}

@Override
public Option<ClassInfo> apply(final ClassName a) {
return this.repository.fetchClass(a);
}

}
110 changes: 110 additions & 0 deletions pitest-entry/src/main/java/org/pitest/classinfo/Repository.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
/*
* Copyright 2011 Henry Coles
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and limitations under the License.
*/
package org.pitest.classinfo;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import org.pitest.functional.Option;

public class Repository implements ClassInfoSource {

private final HashFunction hashFunction;
private final Map<ClassName, ClassInfo> knownClasses = new HashMap<ClassName, ClassInfo>();
private final Set<ClassName> unknownClasses = new HashSet<ClassName>();
private final ClassByteArraySource source;

public Repository(final ClassByteArraySource source) {
this(source, new AddlerHash());
}

Repository(final ClassByteArraySource source, final HashFunction hashFunction) {
this.source = source;
this.hashFunction = hashFunction;
}

public boolean hasClass(final ClassName name) {
return this.knownClasses.containsKey(name) || querySource(name).hasSome();
}

public Option<ClassInfo> fetchClass(final Class<?> clazz) { // NO_UCD (test
// only)
return fetchClass(clazz.getName());
}

private Option<ClassInfo> fetchClass(final String name) {
return fetchClass(new ClassName(name));
}

@Override
public Option<ClassInfo> fetchClass(final ClassName name) {
final ClassInfo info = this.knownClasses.get(name);
if (info != null) {
return Option.some(info);
}

final Option<ClassInfo> maybeInfo = nameToClassInfo(name);
if (maybeInfo.hasSome()) {
this.knownClasses.put(name, maybeInfo.value());
}
return maybeInfo;
}

private Option<ClassInfo> nameToClassInfo(final ClassName name) {
final Option<byte[]> bytes = querySource(name);
if (bytes.hasSome()) {
final ClassInfoBuilder classData = ClassInfoVisitor.getClassInfo(name,
bytes.value(), this.hashFunction.hash(bytes.value()));
return contructClassInfo(classData);
} else {
return Option.none();
}
}

public Option<byte[]> querySource(final ClassName name) {
if (this.unknownClasses.contains(name)) {
return Option.none();
}
final Option<byte[]> option = this.source.getBytes(name.asJavaName());
if (option.hasSome()) {
return option;
}

this.unknownClasses.add(name);
return option;
}

private Option<ClassInfo> contructClassInfo(final ClassInfoBuilder classData) {
return Option.some(new ClassInfo(resolveClass(classData.superClass),
resolveClass(classData.outerClass), classData));
}

private ClassPointer resolveClass(final String clazz) {
if (clazz == null) {
return new DefaultClassPointer(null);
} else {
final ClassInfo alreadyResolved = this.knownClasses.get(ClassName
.fromString(clazz));
if (alreadyResolved != null) {
return new DefaultClassPointer(alreadyResolved);
} else {
return new DeferredClassPointer(this, ClassName.fromString(clazz));
}
}
}

}
Loading

0 comments on commit 8cb135d

Please sign in to comment.