Skip to content

Commit 90ba345

Browse files
Merge pull request #6 from mbwhite/azure-pipeline-corrections
Fix Azure Pipelines (master)
2 parents 13fbec8 + 11a26ce commit 90ba345

File tree

27 files changed

+868
-1767
lines changed

27 files changed

+868
-1767
lines changed

build.gradle

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,28 @@
66

77
apply plugin: 'idea'
88
apply plugin: 'eclipse-wtp'
9-
9+
apply plugin: 'com.dorongold.task-tree'
1010
version = '2.0.0-SNAPSHOT'
1111

12+
buildscript {
13+
repositories {
14+
maven {
15+
url "https://plugins.gradle.org/m2/"
16+
}
17+
}
18+
dependencies {
19+
classpath "gradle.plugin.com.dorongold.plugins:task-tree:1.4"
20+
}
21+
}
22+
23+
1224
allprojects {
1325
repositories {
26+
mavenCentral()
1427
mavenLocal()
1528
jcenter()
1629
maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
1730
maven { url "https://www.jitpack.io" }
18-
mavenCentral()
1931
}
2032
}
2133

@@ -41,7 +53,7 @@ subprojects {
4153

4254
if (!it.name.equals('fabric-chaincode-protos')) {
4355
tasks.withType(JavaCompile) {
44-
options.compilerArgs << "-Xlint:all,-try" << "-Werror"
56+
options.compilerArgs << "-Xlint:all,-try"
4557
}
4658
}
4759

ci/azure-pipelines.yml

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,20 @@
44
#
55
# fabric-chaincode-java azure pipeline configuration.
66
#
7+
name: RELEASE-$(Date:yyyyMMdd)$(Rev:.rrr)
8+
9+
# Daily build for final quality
10+
# cf https://crontab.guru/#0_23_*_*_*
11+
schedules:
12+
- cron: "0 23 * * *"
13+
displayName: 'Chaincode Java Nightly Driver'
14+
branches:
15+
include:
16+
- master
17+
- release-1.4
18+
always: true
19+
20+
721
trigger:
822
branches:
923
include:
@@ -17,9 +31,17 @@ trigger:
1731
# to know to produce tests results in XML format for Azure to consume, for developers
1832
# this isn't set so command line output is given
1933
#
34+
# These are custom defined variables, the pipeline one is currently used for the build scripts
35+
# to know to produce tests results in XML format for Azure to consume, for developers
36+
# this isn't set so command line output is given
37+
#
38+
# Chaincode_Java_Creds is the protected group of keys for publishing
2039
variables:
21-
component: fabric-chaincode-node
22-
pipeline: ci
40+
- group: Chaincode_Java_Creds
41+
- name: component
42+
value: fabric-chaincode-java
43+
- name: pipeline
44+
value: ci
2345

2446
pool:
2547
vmImage: 'ubuntu-latest'

fabric-chaincode-integration-test/bin/.gitignore

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,27 @@
11
dependencies {
2-
testCompile 'org.testcontainers:testcontainers:1.10.3'
2+
compile project(':fabric-chaincode-docker')
33
testCompile 'org.hyperledger.fabric-sdk-java:fabric-sdk-java:1.4.4'
4+
compile project(':fabric-chaincode-shim')
5+
implementation group: 'org.json', name: 'json', version: '20180813'
46
}
57

8+
9+
test {
10+
// Always run tests, even when nothing changed.
11+
dependsOn 'cleanTest'
12+
13+
// Show test results.
14+
testLogging {
15+
events "passed", "skipped", "failed"
16+
showExceptions true
17+
showCauses true
18+
showStandardStreams true
19+
exceptionFormat "full"
20+
21+
}
22+
}
23+
24+
625
task getLatestDockerImages{
726
doLast {
827
exec {
@@ -11,7 +30,11 @@ task getLatestDockerImages{
1130
}
1231
}
1332
}
14-
compileJava.dependsOn project(':fabric-chaincode-docker').buildImage
15-
compileJava.dependsOn project(':fabric-chaincode-example-sacc-jars').jar
33+
34+
build.dependsOn project(':fabric-chaincode-docker').buildImage
35+
36+
37+
// compileJava.dependsOn project(':fabric-chaincode-docker').buildImage
38+
// compileJava.dependsOn project(':fabric-chaincode-example-sacc-jars').jar
1639
test.dependsOn project.getLatestDockerImages
1740

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
/*
2+
Copyright IBM Corp. All Rights Reserved.
3+
4+
SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
package org.hyperleder.fabric.shim.integration;
8+
9+
import java.io.BufferedReader;
10+
import java.io.IOException;
11+
import java.io.InputStream;
12+
import java.io.InputStreamReader;
13+
import java.io.PrintStream;
14+
import java.util.ArrayList;
15+
import java.util.HashMap;
16+
import java.util.List;
17+
import java.util.Map;
18+
import java.util.concurrent.CompletableFuture;
19+
import java.util.concurrent.ExecutionException;
20+
21+
public class Command {
22+
23+
protected List<String> cmd;
24+
protected Map<String, String> env;
25+
26+
Command(List<String> cmd) {
27+
this.cmd = cmd;
28+
this.env = new HashMap<>();
29+
30+
}
31+
32+
class Result {
33+
ArrayList<String> stdout;
34+
ArrayList<String> stderr;
35+
int exitcode;
36+
}
37+
38+
/**
39+
* Run but don't suppress the output being printed directly
40+
*/
41+
public Result run() {
42+
return this.run(false);
43+
}
44+
45+
/**
46+
* Run the command, and process the output to arrays for later parsing and checking
47+
*
48+
* @param quiet true if the output should NOT be printed directly to System.out/System.err
49+
*/
50+
public Result run(boolean quiet) {
51+
52+
ProcessBuilder processBuilder = new ProcessBuilder(cmd);
53+
processBuilder.environment().putAll(env);
54+
final Result result = new Result();
55+
56+
System.out.println("Running:" + this.toString());
57+
try {
58+
Process process = processBuilder.start();
59+
60+
CompletableFuture<ArrayList<String>> soutFut = readOutStream(process.getInputStream(),quiet?null:System.out);
61+
CompletableFuture<ArrayList<String>> serrFut = readOutStream(process.getErrorStream(),quiet?null:System.err);
62+
63+
CompletableFuture<Result> resultFut = soutFut.thenCombine(serrFut, (stdout, stderr) -> {
64+
// print to current stderr the stderr of process and return the stdout
65+
result.stderr = stderr;
66+
result.stdout = stdout;
67+
return result;
68+
});
69+
70+
result.exitcode = process.waitFor();
71+
// get stdout once ready, blocking
72+
resultFut.get();
73+
74+
} catch (IOException | InterruptedException | ExecutionException e) {
75+
e.printStackTrace();
76+
result.exitcode = -1;
77+
}
78+
79+
return result;
80+
}
81+
82+
/**
83+
* Collect the information from the executed process and add them to a result object
84+
*
85+
* @param is
86+
* @param stream
87+
* @return Completable Future with the array list of the stdout/sstderr
88+
*/
89+
CompletableFuture<ArrayList<String>> readOutStream(InputStream is, PrintStream stream) {
90+
return CompletableFuture.supplyAsync(() -> {
91+
try (InputStreamReader isr = new InputStreamReader(is); BufferedReader br = new BufferedReader(isr);) {
92+
ArrayList<String> res = new ArrayList<String>();
93+
String inputLine;
94+
while ((inputLine = br.readLine()) != null) {
95+
if (stream!=null) stream.println(inputLine);
96+
res.add(inputLine);
97+
}
98+
return res;
99+
} catch (Throwable e) {
100+
throw new RuntimeException("problem with executing program", e);
101+
}
102+
});
103+
}
104+
105+
public String toString() {
106+
return "[" + String.join(" ", cmd) + "]";
107+
}
108+
109+
static public class Builder<T extends Command> implements Cloneable {
110+
public Builder<T> duplicate() {
111+
try {
112+
return (Builder<T>) this.clone();
113+
} catch (CloneNotSupportedException e) {
114+
e.printStackTrace();
115+
return null;
116+
}
117+
}
118+
}
119+
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/*
2+
Copyright IBM Corp. All Rights Reserved.
3+
4+
SPDX-License-Identifier: Apache-2.0
5+
*/
6+
package org.hyperleder.fabric.shim.integration;
7+
import java.util.ArrayList;
8+
import java.util.List;
9+
10+
/** Represents the 'docker' cli command
11+
*
12+
*
13+
*
14+
*/
15+
public class Docker extends Command {
16+
17+
public static DockerBuilder newBuilder(){
18+
return new DockerBuilder();
19+
}
20+
21+
static public class DockerBuilder implements Cloneable {
22+
boolean exec;
23+
String container;
24+
String script;
25+
26+
public DockerBuilder duplicate() {
27+
try {
28+
return (DockerBuilder) this.clone();
29+
} catch (CloneNotSupportedException e) {
30+
e.printStackTrace();
31+
return null;
32+
}
33+
}
34+
35+
public DockerBuilder script(String script){
36+
this.script = script;
37+
return this;
38+
}
39+
40+
public DockerBuilder container(String container){
41+
this.container = container;
42+
return this;
43+
}
44+
45+
public DockerBuilder exec(){
46+
this.exec = true;
47+
return this;
48+
}
49+
public Docker build(){
50+
51+
ArrayList<String> list = new ArrayList<>();
52+
list.add("docker");
53+
if(exec){
54+
list.add("exec");
55+
56+
}
57+
58+
if (container == null || container.isEmpty()){
59+
throw new RuntimeException("container should be set");
60+
}
61+
list.add(container);
62+
63+
if (script == null || script.isEmpty()){
64+
throw new RuntimeException("script should be set");
65+
}
66+
list.add(script);
67+
68+
69+
return new Docker(list);
70+
}
71+
}
72+
73+
Docker(List<String> cmd) {
74+
super(cmd);
75+
}
76+
77+
}

0 commit comments

Comments
 (0)