Skip to content

Commit 4513b29

Browse files
authored
Set up CI with Azure Pipelines (#2)
* Set up CI with Azure Pipelines [skip ci] * adding more stages and jobs * Trying again * One more time * Lets see if this works * oops * Facepalm * Testing * Implementing checkstyleMain * peeking * Simple commit CI for now
1 parent 7a67944 commit 4513b29

16 files changed

+418
-76
lines changed

azure-pipelines.yml

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
jobs:
2+
- job: BuildLintUnitTest
3+
displayName: Build, Lint and Unit Test
4+
pool:
5+
vmImage: 'Ubuntu-16.04'
6+
steps:
7+
- bash: ./gradlew clean build --refresh-dependencies -x sign -x checkstyleTest

build.gradle

+8
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ plugins {
22
id 'java'
33
id 'maven'
44
id 'signing'
5+
id 'checkstyle'
56
}
67

78
group = "ai.evolv"
@@ -28,6 +29,13 @@ dependencies {
2829
testImplementation 'junit:junit:4.12'
2930
}
3031

32+
checkstyleMain {
33+
source ='src/main/java'
34+
}
35+
checkstyleTest {
36+
source ='src/test/java'
37+
}
38+
3139
task sourcesJar(type: Jar, dependsOn: classes) {
3240
classifier = 'sources'
3341
from sourceSets.main.allSource

config/checkstyle/checkstyle.xml

+258
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,258 @@
1+
<?xml version="1.0"?>
2+
<!DOCTYPE module PUBLIC
3+
"-//Puppy Crawl//DTD Check Configuration 1.3//EN"
4+
"http://www.puppycrawl.com/dtds/configuration_1_3.dtd">
5+
6+
<!--
7+
Checkstyle configuration that checks the Google coding conventions from Google Java Style
8+
that can be found at https://google.github.io/styleguide/javaguide.html.
9+
Checkstyle is very configurable. Be sure to read the documentation at
10+
http://checkstyle.sf.net (or in your downloaded distribution).
11+
To completely disable a check, just comment it out or delete it from the file.
12+
Authors: Max Vetrenko, Ruslan Diachenko, Roman Ivanov.
13+
-->
14+
15+
<module name = "Checker">
16+
<property name="charset" value="UTF-8"/>
17+
18+
<property name="severity" value="error"/>
19+
20+
<property name="fileExtensions" value="java, properties, xml"/>
21+
<!-- Excludes all 'module-info.java' files -->
22+
<!-- See https://checkstyle.org/config_filefilters.html -->
23+
<!--<module name="BeforeExecutionExclusionFileFilter">-->
24+
<!--<property name="fileNamePattern" value="module\-info\.java$"/>-->
25+
<!--</module>-->
26+
<!-- Checks for whitespace -->
27+
<!-- See http://checkstyle.sf.net/config_whitespace.html -->
28+
<module name="FileTabCharacter">
29+
<property name="eachLine" value="true"/>
30+
</module>
31+
32+
<module name="TreeWalker">
33+
<module name="OuterTypeFilename"/>
34+
<module name="IllegalTokenText">
35+
<property name="tokens" value="STRING_LITERAL, CHAR_LITERAL"/>
36+
<property name="format"
37+
value="\\u00(09|0(a|A)|0(c|C)|0(d|D)|22|27|5(C|c))|\\(0(10|11|12|14|15|42|47)|134)"/>
38+
<property name="message"
39+
value="Consider using special escape sequence instead of octal value or Unicode escaped value."/>
40+
</module>
41+
<module name="AvoidEscapedUnicodeCharacters">
42+
<property name="allowEscapesForControlCharacters" value="true"/>
43+
<property name="allowByTailComment" value="true"/>
44+
<property name="allowNonPrintableEscapes" value="true"/>
45+
</module>
46+
<module name="LineLength">
47+
<property name="max" value="100"/>
48+
<property name="ignorePattern" value="^package.*|^import.*|a href|href|http://|https://|ftp://"/>
49+
</module>
50+
<module name="AvoidStarImport"/>
51+
<module name="OneTopLevelClass"/>
52+
<module name="NoLineWrap"/>
53+
<module name="EmptyBlock">
54+
<property name="option" value="TEXT"/>
55+
<property name="tokens"
56+
value="LITERAL_TRY, LITERAL_FINALLY, LITERAL_IF, LITERAL_ELSE, LITERAL_SWITCH"/>
57+
</module>
58+
<module name="NeedBraces"/>
59+
<module name="LeftCurly"/>
60+
<module name="RightCurly">
61+
<property name="id" value="RightCurlySame"/>
62+
<property name="tokens"
63+
value="LITERAL_TRY, LITERAL_CATCH, LITERAL_FINALLY, LITERAL_IF, LITERAL_ELSE,
64+
LITERAL_DO"/>
65+
</module>
66+
<module name="RightCurly">
67+
<property name="id" value="RightCurlyAlone"/>
68+
<property name="option" value="alone"/>
69+
<property name="tokens"
70+
value="CLASS_DEF, METHOD_DEF, CTOR_DEF, LITERAL_FOR, LITERAL_WHILE, STATIC_INIT,
71+
INSTANCE_INIT"/>
72+
</module>
73+
<module name="WhitespaceAround">
74+
<property name="allowEmptyConstructors" value="true"/>
75+
<property name="allowEmptyLambdas" value="true"/>
76+
<property name="allowEmptyMethods" value="true"/>
77+
<property name="allowEmptyTypes" value="true"/>
78+
<property name="allowEmptyLoops" value="true"/>
79+
<message key="ws.notFollowed"
80+
value="WhitespaceAround: ''{0}'' is not followed by whitespace. Empty blocks may only be represented as '{}' when not part of a multi-block statement (4.1.3)"/>
81+
<message key="ws.notPreceded"
82+
value="WhitespaceAround: ''{0}'' is not preceded with whitespace."/>
83+
</module>
84+
<module name="OneStatementPerLine"/>
85+
<module name="MultipleVariableDeclarations"/>
86+
<module name="ArrayTypeStyle"/>
87+
<module name="MissingSwitchDefault"/>
88+
<module name="FallThrough"/>
89+
<module name="UpperEll"/>
90+
<module name="ModifierOrder"/>
91+
<module name="EmptyLineSeparator">
92+
<property name="allowNoEmptyLineBetweenFields" value="true"/>
93+
</module>
94+
<module name="SeparatorWrap">
95+
<property name="id" value="SeparatorWrapDot"/>
96+
<property name="tokens" value="DOT"/>
97+
<property name="option" value="nl"/>
98+
</module>
99+
<module name="SeparatorWrap">
100+
<property name="id" value="SeparatorWrapComma"/>
101+
<property name="tokens" value="COMMA"/>
102+
<property name="option" value="EOL"/>
103+
</module>
104+
<module name="SeparatorWrap">
105+
<!-- ELLIPSIS is EOL until https://github.com/google/styleguide/issues/258 -->
106+
<property name="id" value="SeparatorWrapEllipsis"/>
107+
<property name="tokens" value="ELLIPSIS"/>
108+
<property name="option" value="EOL"/>
109+
</module>
110+
<module name="SeparatorWrap">
111+
<!-- ARRAY_DECLARATOR is EOL until https://github.com/google/styleguide/issues/259 -->
112+
<property name="id" value="SeparatorWrapArrayDeclarator"/>
113+
<property name="tokens" value="ARRAY_DECLARATOR"/>
114+
<property name="option" value="EOL"/>
115+
</module>
116+
<!--<module name="SeparatorWrap">-->
117+
<!--<property name="id" value="SeparatorWrapMethodRef"/>-->
118+
<!--<property name="tokens" value="METHOD_REF"/>-->
119+
<!--<property name="option" value="nl"/>-->
120+
<!--</module>-->
121+
<module name="PackageName">
122+
<property name="format" value="^[a-z]+(\.[a-z][a-z0-9]*)*$"/>
123+
<message key="name.invalidPattern"
124+
value="Package name ''{0}'' must match pattern ''{1}''."/>
125+
</module>
126+
<module name="TypeName">
127+
<message key="name.invalidPattern"
128+
value="Type name ''{0}'' must match pattern ''{1}''."/>
129+
</module>
130+
<module name="MemberName">
131+
<property name="format" value="^[a-z][a-z0-9][a-zA-Z0-9]*$"/>
132+
<message key="name.invalidPattern"
133+
value="Member name ''{0}'' must match pattern ''{1}''."/>
134+
</module>
135+
<module name="ParameterName">
136+
<property name="format" value="^[a-z]([a-z0-9][a-zA-Z0-9]*)?$"/>
137+
<message key="name.invalidPattern"
138+
value="Parameter name ''{0}'' must match pattern ''{1}''."/>
139+
</module>
140+
<!--<module name="LambdaParameterName">-->
141+
<!--<property name="format" value="^[a-z]([a-z0-9][a-zA-Z0-9]*)?$"/>-->
142+
<!--<message key="name.invalidPattern"-->
143+
<!--value="Lambda parameter name ''{0}'' must match pattern ''{1}''."/>-->
144+
<!--</module>-->
145+
<module name="CatchParameterName">
146+
<property name="format" value="^[a-z]([a-z0-9][a-zA-Z0-9]*)?$"/>
147+
<message key="name.invalidPattern"
148+
value="Catch parameter name ''{0}'' must match pattern ''{1}''."/>
149+
</module>
150+
<module name="LocalVariableName">
151+
<property name="tokens" value="VARIABLE_DEF"/>
152+
<property name="format" value="^[a-z]([a-z0-9][a-zA-Z0-9]*)?$"/>
153+
<message key="name.invalidPattern"
154+
value="Local variable name ''{0}'' must match pattern ''{1}''."/>
155+
</module>
156+
<module name="ClassTypeParameterName">
157+
<property name="format" value="(^[A-Z][0-9]?)$|([A-Z][a-zA-Z0-9]*[T]$)"/>
158+
<message key="name.invalidPattern"
159+
value="Class type name ''{0}'' must match pattern ''{1}''."/>
160+
</module>
161+
<module name="MethodTypeParameterName">
162+
<property name="format" value="(^[A-Z][0-9]?)$|([A-Z][a-zA-Z0-9]*[T]$)"/>
163+
<message key="name.invalidPattern"
164+
value="Method type name ''{0}'' must match pattern ''{1}''."/>
165+
</module>
166+
<module name="InterfaceTypeParameterName">
167+
<property name="format" value="(^[A-Z][0-9]?)$|([A-Z][a-zA-Z0-9]*[T]$)"/>
168+
<message key="name.invalidPattern"
169+
value="Interface type name ''{0}'' must match pattern ''{1}''."/>
170+
</module>
171+
<module name="NoFinalizer"/>
172+
<module name="GenericWhitespace">
173+
<message key="ws.followed"
174+
value="GenericWhitespace ''{0}'' is followed by whitespace."/>
175+
<message key="ws.preceded"
176+
value="GenericWhitespace ''{0}'' is preceded with whitespace."/>
177+
<message key="ws.illegalFollow"
178+
value="GenericWhitespace ''{0}'' should followed by whitespace."/>
179+
<message key="ws.notPreceded"
180+
value="GenericWhitespace ''{0}'' is not preceded with whitespace."/>
181+
</module>
182+
<module name="Indentation">
183+
<property name="basicOffset" value="4"/>
184+
<property name="braceAdjustment" value="0"/>
185+
<property name="caseIndent" value="2"/>
186+
<property name="throwsIndent" value="4"/>
187+
<property name="lineWrappingIndentation" value="4"/>
188+
<property name="arrayInitIndent" value="2"/>
189+
</module>
190+
<module name="AbbreviationAsWordInName">
191+
<property name="ignoreFinal" value="false"/>
192+
<property name="allowedAbbreviationLength" value="1"/>
193+
</module>
194+
<module name="OverloadMethodsDeclarationOrder"/>
195+
<module name="VariableDeclarationUsageDistance"/>
196+
<module name="CustomImportOrder">
197+
<property name="sortImportsInGroupAlphabetically" value="true"/>
198+
<property name="separateLineBetweenGroups" value="true"/>
199+
<property name="customImportOrderRules" value="STATIC###THIRD_PARTY_PACKAGE"/>
200+
</module>
201+
<module name="MethodParamPad"/>
202+
<!--<module name="NoWhitespaceBefore">-->
203+
<!--<property name="tokens"-->
204+
<!--value="COMMA, SEMI, POST_INC, POST_DEC, DOT, ELLIPSIS, METHOD_REF"/>-->
205+
<!--<property name="allowLineBreaks" value="true"/>-->
206+
<!--</module>-->
207+
<module name="ParenPad"/>
208+
<!--<module name="OperatorWrap">-->
209+
<!--<property name="option" value="NL"/>-->
210+
<!--<property name="tokens"-->
211+
<!--value="BAND, BOR, BSR, BXOR, DIV, EQUAL, GE, GT, LAND, LE, LITERAL_INSTANCEOF, LOR,-->
212+
<!--LT, MINUS, MOD, NOT_EQUAL, PLUS, QUESTION, SL, SR, STAR, METHOD_REF "/>-->
213+
<!--</module>-->
214+
<module name="AnnotationLocation">
215+
<property name="id" value="AnnotationLocationMostCases"/>
216+
<property name="tokens"
217+
value="CLASS_DEF, INTERFACE_DEF, ENUM_DEF, METHOD_DEF, CTOR_DEF"/>
218+
</module>
219+
<module name="AnnotationLocation">
220+
<property name="id" value="AnnotationLocationVariables"/>
221+
<property name="tokens" value="VARIABLE_DEF"/>
222+
<property name="allowSamelineMultipleAnnotations" value="true"/>
223+
</module>
224+
<module name="NonEmptyAtclauseDescription"/>
225+
<module name="JavadocTagContinuationIndentation"/>
226+
<module name="SummaryJavadoc">
227+
<property name="forbiddenSummaryFragments"
228+
value="^@return the *|^This method returns |^A [{]@code [a-zA-Z0-9]+[}]( is a )"/>
229+
</module>
230+
<module name="JavadocParagraph"/>
231+
<module name="AtclauseOrder">
232+
<property name="tagOrder" value="@param, @return, @throws, @deprecated"/>
233+
<property name="target"
234+
value="CLASS_DEF, INTERFACE_DEF, ENUM_DEF, METHOD_DEF, CTOR_DEF, VARIABLE_DEF"/>
235+
</module>
236+
<module name="JavadocMethod">
237+
<property name="scope" value="public"/>
238+
<property name="allowMissingParamTags" value="true"/>
239+
<property name="allowMissingThrowsTags" value="true"/>
240+
<property name="allowMissingReturnTag" value="true"/>
241+
<property name="minLineCount" value="2"/>
242+
<property name="allowedAnnotations" value="Override, Test"/>
243+
<property name="allowThrowsTagsForSubclasses" value="true"/>
244+
</module>
245+
<module name="MethodName">
246+
<property name="format" value="^[a-z][a-z0-9][a-zA-Z0-9_]*$"/>
247+
<message key="name.invalidPattern"
248+
value="Method name ''{0}'' must match pattern ''{1}''."/>
249+
</module>
250+
<module name="SingleLineJavadoc">
251+
<property name="ignoreInlineTags" value="false"/>
252+
</module>
253+
<module name="EmptyCatchBlock">
254+
<property name="exceptionVariableName" value="expected"/>
255+
</module>
256+
<module name="CommentsIndentation"/>
257+
</module>
258+
</module>

src/main/java/ai/evolv/Allocations.java

+9-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package ai.evolv;
22

3+
import ai.evolv.exceptions.AscendKeyError;
4+
35
import com.google.gson.Gson;
46
import com.google.gson.JsonArray;
57
import com.google.gson.JsonElement;
@@ -11,8 +13,6 @@
1113
import java.util.Map;
1214
import java.util.Set;
1315

14-
import ai.evolv.exceptions.AscendKeyError;
15-
1616
class Allocations {
1717

1818
private final JsonArray allocations;
@@ -42,7 +42,7 @@ JsonObject getGenomeFromAllocations() {
4242
for (JsonElement allocation : allocations) {
4343
JsonObject originalGenome = allocation.getAsJsonObject().getAsJsonObject("genome");
4444
Set<Map.Entry<String, JsonElement>> entrySet = originalGenome.entrySet();
45-
for(Map.Entry<String, JsonElement> entry : entrySet){
45+
for (Map.Entry<String, JsonElement> entry : entrySet) {
4646
genome.add(entry.getKey(), originalGenome.get(entry.getKey()));
4747
}
4848
}
@@ -55,16 +55,18 @@ JsonObject getGenomeFromAllocations() {
5555
* Reconciles the previous allocations with any new allocations.
5656
*
5757
* <p>
58-
* Check the current allocations for any allocations that belong to experiments in the previous
59-
* allocations. If there are, keep the previous allocations. If there are any live experiments
60-
* that are not in the previous allocations add the new allocation to the allocations list.
58+
* Check the current allocations for any allocations that belong to experiments
59+
* in the previous allocations. If there are, keep the previous allocations.
60+
* If there are any live experiments that are not in the previous allocations
61+
* add the new allocation to the allocations list.
6162
* </p>
6263
*
6364
* @param previousAllocations the stored allocations
6465
* @param currentAllocations the allocations recently fetched
6566
* @return the reconcile allocations
6667
*/
67-
static JsonArray reconcileAllocations(JsonArray previousAllocations, JsonArray currentAllocations) {
68+
static JsonArray reconcileAllocations(JsonArray previousAllocations,
69+
JsonArray currentAllocations) {
6870
JsonArray allocations = new JsonArray();
6971

7072
for (JsonElement ca : currentAllocations) {

src/main/java/ai/evolv/Allocator.java

+8-6
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@
55
import com.google.gson.JsonArray;
66
import com.google.gson.JsonParser;
77

8+
import java.net.URI;
9+
import java.net.URL;
10+
import java.util.concurrent.CompletableFuture;
11+
812
import org.slf4j.Logger;
913
import org.slf4j.LoggerFactory;
1014

11-
import java.net.*;
12-
import java.util.concurrent.CompletableFuture;
13-
1415

1516
class Allocator {
1617

@@ -57,7 +58,8 @@ void sandBagContamination() {
5758

5859
String createAllocationsUrl() {
5960
try {
60-
String path = String.format("//%s/%s/%s/allocations", config.getDomain(), config.getVersion(),
61+
String path = String.format("//%s/%s/%s/allocations", config.getDomain(),
62+
config.getVersion(),
6163
config.getEnvironmentId());
6264
String queryString = String.format("uid=%s&sid=%s", ascendParticipant.getUserId(),
6365
ascendParticipant.getSessionId());
@@ -97,7 +99,7 @@ CompletableFuture<JsonArray> fetchAllocations() {
9799
// could throw an exception due to customer's action logic
98100
try {
99101
executionQueue.executeAllWithValuesFromAllocations(allocations);
100-
} catch(Exception e) {
102+
} catch (Exception e) {
101103
throw new AscendRuntimeException(e);
102104
}
103105

@@ -107,7 +109,7 @@ CompletableFuture<JsonArray> fetchAllocations() {
107109
// surface any customer implementation errors
108110
logger.error(ex.getCause().getCause().toString());
109111
return result;
110-
} else if (ex != null && result == null ){
112+
} else if (ex != null && result == null) {
111113
return resolveAllocationFailure();
112114
} else {
113115
return result;

src/main/java/ai/evolv/AscendAllocationStore.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ public interface AscendAllocationStore {
77
/**
88
* Retrieves a JsonArray.
99
* <p>
10-
* Retrieves a JsonArray that represents the participant's allocations. If there are no stored allocations,
11-
* should return an empty JsonArray.
10+
* Retrieves a JsonArray that represents the participant's allocations.
11+
* If there are no stored allocations, should return an empty JsonArray.
1212
* </p>
1313
* @return a participant's allocations
1414
*/

0 commit comments

Comments
 (0)