Sfoglia il codice sorgente

Merge branch 'run-tests-against-examples-in-ci' (closes #50)

John S. Ryan 11 anni fa
parent
commit
15808d141d
43 ha cambiato i file con 317 aggiunte e 6 eliminazioni
  1. 7
    3
      .travis.yml
  2. 224
    3
      README.md
  3. 0
    0
      _template/src/example/java/.keep
  4. 0
    0
      accumulate/src/example/java/Accumulate.java
  5. 1
    0
      allergies/src/example/java/Allergen.java
  6. 0
    0
      allergies/src/example/java/Allergies.java
  7. 0
    0
      anagram/src/example/java/Anagram.java
  8. 0
    0
      atbash-cipher/src/example/java/Atbash.java
  9. 12
    0
      bin/build.sh
  10. 0
    0
      binary/src/example/java/Binary.java
  11. 0
    0
      bob/src/example/java/Bob.java
  12. 22
    0
      build.gradle
  13. 0
    0
      crypto-square/src/example/java/Crypto.java
  14. 0
    0
      etl/src/example/java/Etl.java
  15. 3
    0
      gigasecond/src/example/java/Gigasecond.java
  16. 0
    0
      grade-school/src/example/java/School.java
  17. 3
    0
      hamming/src/example/java/Hamming.java
  18. 0
    0
      luhn/src/example/java/Luhn.java
  19. 0
    0
      meetup/src/example/java/Meetup.java
  20. 1
    0
      meetup/src/example/java/MeetupSchedule.java
  21. 0
    0
      nucleotide-count/src/example/java/DNA.java
  22. 0
    0
      octal/src/example/java/Octal.java
  23. 0
    0
      pascals-triangle/src/example/java/PascalsTriangle.java
  24. 0
    0
      phone-number/src/example/java/PhoneNumber.java
  25. 0
    0
      pig-latin/src/example/java/PigLatin.java
  26. 1
    0
      prime-factors/build.gradle
  27. 0
    0
      prime-factors/src/example/java/PrimeFactors.java
  28. 0
    0
      raindrops/src/example/java/Raindrops.java
  29. 0
    0
      rna-transcription/src/example/java/RnaTranscription.java
  30. 1
    0
      robot-name/build.gradle
  31. 0
    0
      robot-name/src/example/java/Robot.java
  32. 3
    0
      roman-numerals/src/example/java/RomanNumeral.java
  33. 3
    0
      scrabble-score/src/example/java/Scrabble.java
  34. 31
    0
      settings.gradle
  35. 0
    0
      sieve/src/example/java/Sieve.java
  36. 0
    0
      simple-cipher/src/example/java/Cipher.java
  37. 0
    0
      space-age/src/example/java/SpaceAge.java
  38. 0
    0
      strain/src/example/java/Strain.java
  39. 3
    0
      triangle/src/example/java/Triangle.java
  40. 1
    0
      triangle/src/example/java/TriangleException.java
  41. 1
    0
      triangle/src/example/java/TriangleKind.java
  42. 0
    0
      trinary/src/example/java/Trinary.java
  43. 0
    0
      word-count/src/example/java/WordCount.java

+ 7
- 3
.travis.yml Vedi File

@@ -1,5 +1,9 @@
1
-language: bash
1
+language: java
2
+jdk:
3
+  - oraclejdk8
4
+
5
+# http://docs.travis-ci.com/user/migrating-from-legacy
6
+sudo: false
2 7
 
3 8
 script:
4
-  - bin/fetch-configlet
5
-  - bin/configlet .
9
+  - bin/build.sh

+ 224
- 3
README.md Vedi File

@@ -1,12 +1,233 @@
1 1
 # xJava [![Build Status](https://travis-ci.org/exercism/xjava.svg?branch=master)](https://travis-ci.org/exercism/xjava)
2 2
 
3
-Exercism Exercises in Java
3
+Exercism Exercises in Java.
4 4
 
5 5
 ## Contributing Guide
6 6
 
7
-Please see the [contributing guide](https://github.com/exercism/x-api/blob/master/CONTRIBUTING.md#the-exercise-data)
7
+For general information about how to contribute to Exercism, please refer to the [Contributing Guide](https://github.com/exercism/x-api/blob/master/CONTRIBUTING.md#the-exercise-data).
8 8
 
9
-## License
9
+## Table of Contents
10
+
11
+* [Overview](#overview)
12
+* [Getting Setup](#getting-setup)
13
+* [Getting Familiar With the Codebase](#getting-familiar-with-the-codebase)
14
+  * [The Rootproject](#the-rootproject)
15
+  * [The Problem Subprojects](#the-problem-subprojects)
16
+  * [Running The Build](#running-the-build)
17
+* [Submitting Your Contribution](#submitting-your-contribution)
18
+  * [Doing the Commit Dance](#doing-the-commit-dance)
19
+  * [Making the Pull Request](#making-the-pull-request)
20
+* [Reverting Your CLI Config](#reverting-your-cli-config)
21
+
22
+
23
+## Overview
24
+----
25
+
26
+This guide walks you through how to contribute to the Java language track.  It is opinionated and specific to allow those who are relatively new to Free Open Source Software to have a fighting chance of being successful.  However, if you know what you're doing, we intent these instructions to be guidelines.
27
+
28
+The steps described herein were composed on OS X.  They will presumably work with no change on any *nix distro.  Almost all of them will work on Windows; though you might want to use cygwin or some other Unix support for creating soft-links.  Otherwise, you'll need to improvise on some steps.  If you *do* find a nice workflow for Windows, please feel free to submit a PR for changes to this doc.  Thanks!
29
+
30
+This guide flows chronologically, from setting-up your environment, taking a quick tour of the build process to finally what it takes to successfully submit.
31
+
32
+If, at any point, you're having any trouble, pop in the [Gitter exercism/dev room](https://gitter.im/exercism/dev) for help.
33
+
34
+
35
+## Getting Setup
36
+----
37
+
38
+You'll *need* the following:
39
+
40
+* Java 1.8+
41
+* Gradle 2.x
42
+* Git 1.x
43
+
44
+If you haven't already, please read our advice on [Git Workflow](http://help.exercism.io/git-workflow.html).
45
+
46
+
47
+Here's one way to get setup:
48
+
49
+1. **Stand-up the x-api, locally.**  You should ultimate verify your work by delivering your problem through the exercism CLI and solving it from that `exercism fetch`'ed copy.  The CLI fetches problems from the x-api.  You'll need your own instance of the x-api running locally.
50
+
51
+	```
52
+	cd ~
53
+	mkdir -p workspace/exercism && cd workspace/exercism
54
+	git clone https://github.com/exercism/x-api
55
+	cd x-api
56
+	bundle install
57
+	git submodule init
58
+	git submodule update
59
+	rackup
60
+	```
61
+
62
+If you want more details, check out the [x-api README](https://github.com/exercism/x-api).
63
+
64
+2. **Configure your exercism CLI to point to that x-api.** Out of the box, the CLI is configured to point to the production instances of the API (for account-specific data) and X-API (for problem data).  You need to configure your CLI to point to the X-API instance you stood up in the prior step.
65
+	
66
+	If you haven't already, you'll need need to [install the CLI](http://help.exercism.io/installing-the-cli.html).
67
+
68
+	```
69
+	cd ~
70
+	mkdir -p workspace/exercism/exercises
71
+	cd ~/workspace/exercism/exercises
72
+	exercism configure --dir=~/workspace/exercism/exercises
73
+	exercism configure --api http://localhost:9292
74
+	exercism debug
75
+	exercism fetch java bob
76
+	tree java
77
+	```
78
+
79
+	If things are properly setup:
80
+	* `exercism debug` output will include "`XAPI: http://localhost:9292 [connected]`"
81
+	* `tree java` will look something like this:
82
+	
83
+		```
84
+		java
85
+		└── bob
86
+		    ├── README.md
87
+		    ├── build.gradle
88
+		    └── src
89
+		        └── test
90
+		            └── java
91
+		                └── BobTest.java
92
+		```
93
+
94
+3. **Point your local x-api to your xjava fork.**  Most people contribute by submitting pull request from their fork of the track repo (covered below).  To make it easy to develop, replace the java problem set in your local x-api with your fork:
95
+
96
+	If you haven't already, fork the track repo: [exercism/xjava](https://github.com/exercism/xjava).
97
+
98
+	```
99
+	cd ~/workspace/exercism/
100
+	git clone git@github.com:jtigger/xjava.git
101
+	git remote add upstream https://github.com/exercism/xjava.git
102
+	git pull --rebase upstream/master
103
+	cd ~/workspace/exercism/x-api/problems
104
+	rm -rf java
105
+	ln -s ../../xjava java
106
+	```
107
+
108
+You are now ready to go!
109
+
110
+## Getting Familiar With the Codebase
111
+----
112
+
113
+There are two objectives to the design of this build:
114
+
115
+1. when a problem is built from within the xjava repo, the tests run against the "example" code.
116
+2. when a problem is built outside the xjava repo (namely, when it has been served through the CLI on a user's computer), the tests run against the "main" code.
117
+
118
+This repo is a mulit-project gradle build.
119
+
120
+### The Rootproject
121
+
122
+The rootproject is a container for the problem subprojects.
123
+
124
+  * it's `build.gradle` points the "main" sourceset to the example code.
125
+  * it's `settings.gradle` names each of the subprojects, one for each problem in the set.
126
+
127
+
128
+### The Problem Subprojects
129
+
130
+Each problem/subproject is a subdirectory of the same name as its slug.
131
+
132
+  * it's `build.gradle` names dependencies required to work that problem.
133
+
134
+Each problem/subproject has three source sets:
135
+
136
+* `src/test/java/` — a test suite defining the edges of the problem
137
+* `src/example/java/` — an example solution that passes all the tests
138
+* `src/main/java/` — starter source files, if required/desired *(this directory usually only has a `.keep` file in it)*.
139
+
140
+### Running The Build
141
+
142
+To run all the tests against example code:
143
+
144
+```
145
+cd ~/workspace/exercism/xjava
146
+gradle assemble check
147
+```
148
+
149
+To run the test against just one problem, run gradle from within that directory:
150
+
151
+```
152
+cd ~/workspace/exercism/xjava/bob
153
+gradle assemble check
154
+```
155
+
156
+To run the complete build as done on CI (which includes compiling any "starter" code and running the configlet tool):
157
+
158
+```
159
+cd ~/workspace/exercism/xjava
160
+./bin/build.sh
161
+```
162
+
163
+## Submitting Your Contribution
164
+----
165
+
166
+First of all... Exercism is meant help programmers, world-wide, to develop their skills and in doing so help raise the bar on our industry as a whole.  Your contribution is making that experience even better.  Thank you!
167
+
168
+Before you submit a pull request, please ensure:
169
+
170
+- the test suite covers the essential parts of the problem and interesting corner cases.
171
+- your example solution represents your best attempt at exemplary code. 
172
+- the build script (`./bin/build.sh`) compiles and tests your code successfully.
173
+
174
+
175
+### Doing the Commit Dance
176
+*(These instructions assume you setup your development environment using the instructions above.)*
177
+
178
+1. **Run the build script, locally.**
179
+ 
180
+   ```
181
+   cd ~/workspace/exercism/xjava
182
+   ./bin/build.sh
183
+   ```
184
+
185
+   verify that the script runs successfully.
186
+   
187
+2. **Fetch the problem from your local x-api, using the CLI.**
188
+
189
+   ```
190
+   cd ~/workspace/exercism/exercises
191
+   exercism fetch java <problem-slug>
192
+   ```
193
+   
194
+   verify that the fetched problem does *not* contain any files not needed for the problem.
195
+   
196
+3. **Run the tests against the example source.**
197
+
198
+   ```
199
+   cd ~/workspace/exercism/exercises/java/<problem-slug>
200
+   cp ../../../xjava/<problem-slug>/src/example/java/* src/main/java
201
+   gradle check
202
+   ```
203
+
204
+   verify that all tests pass.
205
+   
206
+If you've successfully navigated to this point, you're ready to make that pull request!
207
+
208
+### Making the Pull Request
209
+
210
+Hopefully you've read our [Git Workflow](http://help.exercism.io/git-workflow.html) and done your work on a clone of a fork of the exercism xjava repo.
211
+
212
+After you've pushed your changes to your fork (best done on a branch, remember), it's a matter of going to GitHub and submitting a pull request.
213
+
214
+When you do so, notice that it automatically kicks off a CI build on Travis.  This is an important step: **be sure to wait for the CI results to come back before you leave!**  Pull Requests that do no pass CI will not be merged in.
215
+
216
+One of the track maintainers will review your PR as soon as we can.
217
+
218
+If you need help, drop in on the [Gitter exercism/dev room](https://gitter.im/exercism/dev).
219
+
220
+
221
+## Reverting Your CLI Config
222
+
223
+In the setup, above, we configured the CLI client to point to your local x-api instance.  Presumably, you like to submit solutions, yourself.  To revert your CLI back to the the production x-api:
224
+
225
+```
226
+exercism configure --api http://x.exercism.io
227
+```
228
+
229
+
230
+# License
10 231
 
11 232
 The MIT License (MIT)
12 233
 

+ 0
- 0
_template/src/example/java/.keep Vedi File


accumulate/example.java → accumulate/src/example/java/Accumulate.java Vedi File


+ 1
- 0
allergies/src/example/java/Allergen.java Vedi File

@@ -0,0 +1 @@
1
+../../main/java/Allergen.java

allergies/example.java → allergies/src/example/java/Allergies.java Vedi File


anagram/example.java → anagram/src/example/java/Anagram.java Vedi File


atbash-cipher/example.java → atbash-cipher/src/example/java/Atbash.java Vedi File


+ 12
- 0
bin/build.sh Vedi File

@@ -0,0 +1,12 @@
1
+#!/bin/bash
2
+set -e
3
+gradle --version
4
+echo ""
5
+echo ">>> Running tests..."
6
+TERM=dumb gradle check compileStarterSourceJava --continue
7
+
8
+
9
+echo ""
10
+echo ">>> Running configlet..."
11
+bin/fetch-configlet
12
+bin/configlet .

binary/example.java → binary/src/example/java/Binary.java Vedi File


bob/example.java → bob/src/example/java/Bob.java Vedi File


+ 22
- 0
build.gradle Vedi File

@@ -0,0 +1,22 @@
1
+subprojects { project ->
2
+  apply plugin: "java"
3
+
4
+  sourceSets {
5
+    // Verify that the tests are working by running them against the example code.
6
+    // By replacing the "main" sourceSet with the example code we avoid any collisions
7
+    //   with solution code that may have been included as a "starter" (e.g. etl).
8
+    main {
9
+      java.srcDirs = ["src/example/java"]
10
+    }
11
+    project["compileJava"].doFirst { compileTask ->
12
+      println "  (source = " + compileTask.source.asPath + ")"
13
+    }
14
+
15
+    starterSource {
16
+      java.srcDirs = ["src/main/java"]
17
+    }
18
+    project["compileStarterSourceJava"].doFirst { compileTask ->
19
+      println "  (source = " + compileTask.source.asPath + ")"
20
+    }
21
+  }
22
+}

crypto-square/example.java → crypto-square/src/example/java/Crypto.java Vedi File


etl/example.java → etl/src/example/java/Etl.java Vedi File


gigasecond/example.java → gigasecond/src/example/java/Gigasecond.java Vedi File

@@ -1,3 +1,6 @@
1
+import java.time.LocalDateTime;
2
+import java.time.LocalDate;
3
+
1 4
 public class Gigasecond {
2 5
 
3 6
     private LocalDateTime birthDateTime;

grade-school/example.java → grade-school/src/example/java/School.java Vedi File


hamming/example.java → hamming/src/example/java/Hamming.java Vedi File

@@ -1,6 +1,9 @@
1 1
 public class Hamming {
2 2
 
3 3
     public static int compute(String leftStrand, String rightStrand) {
4
+        if(leftStrand.length() != rightStrand.length()) {
5
+            throw new IllegalArgumentException("leftStrand and rightStrand must be of equal length.");
6
+        }
4 7
         final int length = Math.min(leftStrand.length(), rightStrand.length());
5 8
         int distance = 0;
6 9
         for (int i = 0; i < length; i++) {

luhn/example.java → luhn/src/example/java/Luhn.java Vedi File


meetup/example.java → meetup/src/example/java/Meetup.java Vedi File


+ 1
- 0
meetup/src/example/java/MeetupSchedule.java Vedi File

@@ -0,0 +1 @@
1
+../../main/java/MeetupSchedule.java

nucleotide-count/example.java → nucleotide-count/src/example/java/DNA.java Vedi File


octal/example.java → octal/src/example/java/Octal.java Vedi File


pascals-triangle/example.java → pascals-triangle/src/example/java/PascalsTriangle.java Vedi File


phone-number/example.java → phone-number/src/example/java/PhoneNumber.java Vedi File


pig-latin/example.java → pig-latin/src/example/java/PigLatin.java Vedi File


+ 1
- 0
prime-factors/build.gradle Vedi File

@@ -9,3 +9,4 @@ repositories {
9 9
 dependencies {
10 10
   testCompile "junit:junit:4.12"
11 11
 }
12
+

prime-factors/example.java → prime-factors/src/example/java/PrimeFactors.java Vedi File


raindrops/example.java → raindrops/src/example/java/Raindrops.java Vedi File


rna-transcription/example.java → rna-transcription/src/example/java/RnaTranscription.java Vedi File


+ 1
- 0
robot-name/build.gradle Vedi File

@@ -9,3 +9,4 @@ repositories {
9 9
 dependencies {
10 10
   testCompile "junit:junit:4.10"
11 11
 }
12
+

robot-name/example.java → robot-name/src/example/java/Robot.java Vedi File


roman-numerals/example.java → roman-numerals/src/example/java/RomanNumeral.java Vedi File

@@ -1,3 +1,6 @@
1
+import java.util.Map;
2
+import java.util.LinkedHashMap;
3
+
1 4
 public class RomanNumeral {
2 5
 
3 6
     private int arabicNumeral;

scrabble-score/example.java → scrabble-score/src/example/java/Scrabble.java Vedi File

@@ -1,3 +1,6 @@
1
+import java.util.Map;
2
+import java.util.HashMap;
3
+
1 4
 public class Scrabble {
2 5
 
3 6
     private String word;

+ 31
- 0
settings.gradle Vedi File

@@ -0,0 +1,31 @@
1
+include 'accumulate'
2
+include 'allergies'
3
+include 'anagram'
4
+include 'atbash-cipher'
5
+include 'binary'
6
+include 'bob'
7
+include 'crypto-square'
8
+include 'etl'
9
+include 'gigasecond'
10
+include 'grade-school'
11
+include 'hamming'
12
+include 'luhn'
13
+include 'meetup'
14
+include 'nucleotide-count'
15
+include 'octal'
16
+include 'pascals-triangle'
17
+include 'phone-number'
18
+include 'pig-latin'
19
+include 'raindrops'
20
+include 'rna-transcription'
21
+include 'robot-name'
22
+include 'roman-numerals'
23
+include 'prime-factors'
24
+include 'scrabble-score'
25
+include 'sieve'
26
+include 'simple-cipher'
27
+include 'space-age'
28
+include 'strain'
29
+include 'triangle'
30
+include 'trinary'
31
+include 'word-count'

sieve/example.java → sieve/src/example/java/Sieve.java Vedi File


simple-cipher/example.java → simple-cipher/src/example/java/Cipher.java Vedi File


space-age/example.java → space-age/src/example/java/SpaceAge.java Vedi File


strain/example.java → strain/src/example/java/Strain.java Vedi File


triangle/example.java → triangle/src/example/java/Triangle.java Vedi File

@@ -1,3 +1,6 @@
1
+import java.util.HashSet;
2
+import java.util.Set;
3
+
1 4
 public class Triangle {
2 5
 
3 6
     private double side1;

+ 1
- 0
triangle/src/example/java/TriangleException.java Vedi File

@@ -0,0 +1 @@
1
+../../main/java/TriangleException.java

+ 1
- 0
triangle/src/example/java/TriangleKind.java Vedi File

@@ -0,0 +1 @@
1
+../../main/java/TriangleKind.java

trinary/example.java → trinary/src/example/java/Trinary.java Vedi File


word-count/example.java → word-count/src/example/java/WordCount.java Vedi File