Skip to content

Commit

Permalink
Javassist plugin integration and class processor for adding OvalBuild…
Browse files Browse the repository at this point in the history
…er validation.
  • Loading branch information
Ville Koskela committed Sep 23, 2016
1 parent 1b16334 commit a4f1924
Show file tree
Hide file tree
Showing 9 changed files with 2,379 additions and 2 deletions.
61 changes: 60 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -70,17 +70,24 @@
<!--Dependency versions-->
<akka.version>2.4.2</akka.version>
<cglib.version>3.2.1</cglib.version>
<findbugs.annotations.version>3.0.1</findbugs.annotations.version>
<guava.version>19.0</guava.version>
<guice.version>4.0</guice.version>
<hamcrest.version>2.0.0.0</hamcrest.version>
<jackson.version>2.7.4</jackson.version>
<javassist.version>3.20.0-GA</javassist.version>
<javassist.maven.core.version>0.1.2</javassist.maven.core.version>
<jsr305.version>3.0.0</jsr305.version>
<junit.version>4.12</junit.version>
<logback.steno.version>1.15.0</logback.steno.version>
<mockito.version>1.10.19</mockito.version>
<oval.version>1.82</oval.version>
<oval.version>1.85</oval.version>
<scala.version>2.11</scala.version>
<scala.library.version>2.11.7</scala.library.version>

<!-- Plugin versions -->
<javassist.maven.plugin.version>0.1.2</javassist.maven.plugin.version>

<!-- Code Coverage -->
<jacoco.check.line.coverage>1.0</jacoco.check.line.coverage>
<jacoco.check.branch.coverage>1.0</jacoco.check.branch.coverage>
Expand Down Expand Up @@ -113,6 +120,36 @@
<artifactId>wrapper-maven-plugin</artifactId>
<inherited>false</inherited>
</plugin>
<!-- Project Specific Plugins -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven.compiler.plugin.version}</version>
<configuration>
<showDeprecation>true</showDeprecation>
<showWarnings>true</showWarnings>
<compilerArgs combine.self="override">
<!--<arg>-Xlint:all</arg>
<arg>-Werror</arg>-->
</compilerArgs>
</configuration>
</plugin>
<plugin>
<groupId>com.arpnetworking.commons</groupId>
<artifactId>javassist-maven-plugin</artifactId>
<version>${javassist.maven.plugin.version}</version>
<executions>
<execution>
<id>javassist-test-process</id>
<goals>
<goal>test-process</goal>
</goals>
<configuration>
<processor>com.arpnetworking.commons.builder.ValidationProcessor</processor>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
Expand All @@ -122,6 +159,16 @@
<artifactId>logback-steno</artifactId>
<version>${logback.steno.version}</version>
</dependency>
<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>jsr305</artifactId>
<version>${jsr305.version}</version>
</dependency>
<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>findbugs-annotations</artifactId>
<version>${findbugs.annotations.version}</version>
</dependency>
<!-- Provided -->
<dependency>
<groupId>com.typesafe.akka</groupId>
Expand Down Expand Up @@ -189,6 +236,18 @@
<version>${oval.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.javassist</groupId>
<artifactId>javassist</artifactId>
<version>${javassist.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.arpnetworking.commons</groupId>
<artifactId>javassist-maven-core</artifactId>
<version>${javassist.maven.core.version}</version>
<scope>provided</scope>
</dependency>
<!-- Test - General -->
<dependency>
<groupId>org.hamcrest</groupId>
Expand Down
14 changes: 13 additions & 1 deletion src/main/java/com/arpnetworking/commons/builder/OvalBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.arpnetworking.steno.LogValueMapFactory;
import com.arpnetworking.steno.Logger;
import com.arpnetworking.steno.LoggerFactory;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import net.sf.oval.ConstraintViolation;
import net.sf.oval.Validator;
Expand Down Expand Up @@ -160,13 +161,24 @@ public String toString() {
*/
@Override
public T build() {
final List<ConstraintViolation> violations = VALIDATOR.validate(this);
final List<ConstraintViolation> violations = Lists.newArrayList();
validate(violations);
if (!violations.isEmpty()) {
throw new ConstraintsViolatedException(violations);
}
return construct();
}

/**
* Validate this <code>Builder</code> instance.
*
* @param violations <code>List</code> of <code>ConstraintViolation</code>
* instances to populate.
*/
protected void validate(final List<ConstraintViolation> violations) {
violations.addAll(VALIDATOR.validate(this));
}

/**
* Protected method to construct the target class reflectively from the
* specified type by passing its constructor an instance of this builder.
Expand Down
Loading

0 comments on commit a4f1924

Please sign in to comment.