Skip to content

Commit

Permalink
Create CONTRIBUTING.md
Browse files Browse the repository at this point in the history
Moved from the wiki

Update link to 'contributing' help

This is not in the standard place (CONTRIBUTING.md) not the wiki.

Fix Scala version to 2.10.1 to avoid confusing Gradle when it reads scalagen

Bump to 0.5.0 in next release

Add fork of scalagen that suffer artifact resolution problems

See timowest/scalagen#87
  • Loading branch information
SpaceBison committed Sep 12, 2017
1 parent 0ba4b45 commit 6a18c3d
Show file tree
Hide file tree
Showing 151 changed files with 10,291 additions and 59 deletions.
19 changes: 19 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
## 1. Use a feature branch

Feature branches make pull requests easier as GitHub will keep your pull request up-to-date when the feature branch changes. If you need to rebase to fix some things after creating your pull request, or if you end up having multiple pull requests open at the same time, **having a pull request associated with a branch instead of `master` will make your job easier**.

## 2. Run the test suite

*jsonschema2pojo* includes both unit and integration tests. The unit test coverage is not high, instead we rely on an exhaustive set of integration tests that cover all the code generation features using example schema documents.

To compile, unit test, package, and run the integration test suite (the typical full build), use:

`mvn clean verify`

## 3. Add integration tests

When contributing, you may often find unit tests (and TDD) helpful and you're free to add unit tests. **If you're adding/amending code generation features then integration tests (*end-to-end* tests that use an example schema to generate and compile Java code) are essential**. We can't merge pull requests unless they have integration tests, since without tests your feature could be lost in a future release.

## 4. Rebase and keep a clean log

Rebase against master often, if your pull request is stale it can't be merged. Rebase your commits into logical chunks, without errors (multiple commits are okay, but **squash minor commits that fix errors in earlier commits**). Force-push to your feature branch after you have rebased.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ A very simple Maven example:

Useful pages:
* **[Getting started](https://github.com/joelittlejohn/jsonschema2pojo/wiki/Getting-Started)**
* **[How to contribute](https://github.com/joelittlejohn/jsonschema2pojo/wiki/Contribute)**
* **[How to contribute](https://github.com/joelittlejohn/jsonschema2pojo/blob/master/CONTRIBUTING.md)**
* [Reference](https://github.com/joelittlejohn/jsonschema2pojo/wiki/Reference)
* [Latest Javadocs](https://joelittlejohn.github.io/jsonschema2pojo/javadocs/0.4.37/)
* [Documentation for the Maven plugin](https://joelittlejohn.github.io/jsonschema2pojo/site/0.4.37/generate-mojo.html)
Expand Down
2 changes: 1 addition & 1 deletion jsonschema2pojo-ant/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>jsonschema2pojo</artifactId>
<groupId>org.jsonschema2pojo</groupId>
<version>0.4.38-SNAPSHOT</version>
<version>0.5.0-SNAPSHOT</version>
</parent>

<artifactId>jsonschema2pojo-ant</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion jsonschema2pojo-cli/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>jsonschema2pojo</artifactId>
<groupId>org.jsonschema2pojo</groupId>
<version>0.4.38-SNAPSHOT</version>
<version>0.5.0-SNAPSHOT</version>
</parent>

<artifactId>jsonschema2pojo-cli</artifactId>
Expand Down
11 changes: 6 additions & 5 deletions jsonschema2pojo-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>jsonschema2pojo</artifactId>
<groupId>org.jsonschema2pojo</groupId>
<version>0.4.38-SNAPSHOT</version>
<version>0.5.0-SNAPSHOT</version>
</parent>

<artifactId>jsonschema2pojo-core</artifactId>
Expand All @@ -14,12 +14,13 @@

<dependencies>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<groupId>org.jsonschema2pojo</groupId>
<artifactId>jsonschema2pojo-scalagen</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.mysema.scalagen</groupId>
<artifactId>scalagen_2.10.1</artifactId>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
<dependency>
<groupId>org.scala-lang</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,7 @@

package org.jsonschema2pojo.rules;

import static org.apache.commons.lang3.StringUtils.*;
import static org.jsonschema2pojo.rules.PrimitiveTypes.*;
import static org.jsonschema2pojo.util.TypeUtil.*;

import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.jsonschema2pojo.AnnotationStyle;
import org.jsonschema2pojo.Schema;
import org.jsonschema2pojo.exception.ClassAlreadyExistsException;
import org.jsonschema2pojo.util.NameHelper;
import org.jsonschema2pojo.util.ParcelableHelper;
import org.jsonschema2pojo.util.SerializableHelper;
import android.os.Parcelable;

import com.fasterxml.jackson.annotation.JsonTypeInfo;
import com.fasterxml.jackson.databind.JsonNode;
Expand All @@ -55,7 +35,30 @@
import com.sun.codemodel.JType;
import com.sun.codemodel.JVar;

import android.os.Parcelable;
import org.jsonschema2pojo.AnnotationStyle;
import org.jsonschema2pojo.Schema;
import org.jsonschema2pojo.exception.ClassAlreadyExistsException;
import org.jsonschema2pojo.util.NameHelper;
import org.jsonschema2pojo.util.ParcelableHelper;
import org.jsonschema2pojo.util.SerializableHelper;

import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import static org.apache.commons.lang3.StringUtils.capitalize;
import static org.apache.commons.lang3.StringUtils.substringAfter;
import static org.apache.commons.lang3.StringUtils.substringBefore;
import static org.jsonschema2pojo.rules.PrimitiveTypes.isPrimitive;
import static org.jsonschema2pojo.rules.PrimitiveTypes.primitiveType;
import static org.jsonschema2pojo.util.TypeUtil.resolveType;

/**
* Applies the generation steps required for schemas of type "object".
Expand Down Expand Up @@ -132,8 +135,8 @@ public JType apply(String nodeName, JsonNode node, JPackage _package, Schema sch
}

if (ruleFactory.getGenerationConfig().isIncludeHashcodeAndEquals()) {
addHashCode(jclass);
addEquals(jclass);
addHashCode(jclass, node);
addEquals(jclass, node);
}

if (ruleFactory.getGenerationConfig().isParcelable()) {
Expand Down Expand Up @@ -403,8 +406,8 @@ private void addToString(JDefinedClass jclass) {
toString.annotate(Override.class);
}

private void addHashCode(JDefinedClass jclass) {
Map<String, JFieldVar> fields = jclass.fields();
private void addHashCode(JDefinedClass jclass, JsonNode node) {
Map<String, JFieldVar> fields = removeFieldsExcludedFromEqualsAndHashCode(jclass.fields(), node);

JMethod hashCode = jclass.method(JMod.PUBLIC, int.class, "hashCode");

Expand All @@ -430,6 +433,37 @@ private void addHashCode(JDefinedClass jclass) {
hashCode.annotate(Override.class);
}

private Map<String, JFieldVar> removeFieldsExcludedFromEqualsAndHashCode(Map<String, JFieldVar> fields, JsonNode node) {
Map<String, JFieldVar> filteredFields = new HashMap<String, JFieldVar>(fields);

JsonNode properties = node.get("properties");

if (properties != null) {
if (node.has("excludedFromEqualsAndHashCode")) {
JsonNode excludedArray = node.get("excludedFromEqualsAndHashCode");

for (Iterator<JsonNode> iterator = excludedArray.elements(); iterator.hasNext(); ) {
String excludedPropertyName = iterator.next().asText();
JsonNode excludedPropertyNode = properties.get(excludedPropertyName);
filteredFields.remove(ruleFactory.getNameHelper().getPropertyName(excludedPropertyName, excludedPropertyNode));
}
}

for (Iterator<Map.Entry<String, JsonNode>> iterator = properties.fields(); iterator.hasNext(); ) {
Map.Entry<String, JsonNode> entry = iterator.next();
String propertyName = entry.getKey();
JsonNode propertyNode = entry.getValue();

if (propertyNode.has("excludedFromEqualsAndHashCode") &&
propertyNode.get("excludedFromEqualsAndHashCode").asBoolean()) {
filteredFields.remove(ruleFactory.getNameHelper().getPropertyName(propertyName, propertyNode));
}
}
}

return filteredFields;
}

private void addConstructors(JDefinedClass jclass, JsonNode node, Schema schema, boolean onlyRequired) {

LinkedHashSet<String> classProperties = getConstructorProperties(node, onlyRequired);
Expand Down Expand Up @@ -522,8 +556,8 @@ private JFieldVar searchClassAndSuperClassesForField(String property, JDefinedCl
return field;
}

private void addEquals(JDefinedClass jclass) {
Map<String, JFieldVar> fields = jclass.fields();
private void addEquals(JDefinedClass jclass, JsonNode node) {
Map<String, JFieldVar> fields = removeFieldsExcludedFromEqualsAndHashCode(jclass.fields(), node);

JMethod equals = jclass.method(JMod.PUBLIC, boolean.class, "equals");
JVar otherObject = equals.param(Object.class, "other");
Expand Down
2 changes: 1 addition & 1 deletion jsonschema2pojo-gradle-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>jsonschema2pojo</artifactId>
<groupId>org.jsonschema2pojo</groupId>
<version>0.4.38-SNAPSHOT</version>
<version>0.5.0-SNAPSHOT</version>
</parent>

<artifactId>jsonschema2pojo-gradle-plugin</artifactId>
Expand Down
7 changes: 1 addition & 6 deletions jsonschema2pojo-integration-tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>jsonschema2pojo</artifactId>
<groupId>org.jsonschema2pojo</groupId>
<version>0.4.38-SNAPSHOT</version>
<version>0.5.0-SNAPSHOT</version>
</parent>

<artifactId>jsonschema2pojo-integration-tests</artifactId>
Expand Down Expand Up @@ -155,11 +155,6 @@
<groupId>org.skyscreamer</groupId>
<artifactId>jsonassert</artifactId>
</dependency>
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-compiler</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

</project>
Loading

0 comments on commit 6a18c3d

Please sign in to comment.