Skip to content

Commit a123a8f

Browse files
authored
Merge pull request #238 from paxtonhare/okhttp
Okhttp
2 parents 1017340 + fbca0ff commit a123a8f

File tree

9 files changed

+254
-20
lines changed

9 files changed

+254
-20
lines changed

.travis.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
language: java
2+
jdk:
3+
- oraclejdk8
4+
sudo: true
5+
before_install:
6+
- echo 'America/Los_Angeles' | sudo tee /etc/timezone
7+
- sudo dpkg-reconfigure --frontend noninteractive tzdata
8+
- chmod 755 ./shared/dev-tasks/*.sh
9+
- chmod 755 ./gradlew
10+
install:
11+
- ./shared/dev-tasks/install-dependencies.sh
12+
script:
13+
- ./shared/dev-tasks/run-tests.sh
14+
15+
#whitelist
16+
branches:
17+
only:
18+
- master
19+
- dev

build.gradle

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@ plugins {
66
id "com.jfrog.bintray" version "1.6"
77
id "com.github.jk1.dependency-license-report" version "0.3.11"
88
id "com.gradle.plugin-publish" version "0.9.7"
9+
id "java-gradle-plugin"
910
}
1011

11-
sourceCompatibility = "1.7"
12-
targetCompatibility = "1.7"
12+
sourceCompatibility = "1.8"
13+
targetCompatibility = "1.8"
1314

1415
repositories {
1516
mavenLocal() // Used for local development only
@@ -22,6 +23,13 @@ dependencies {
2223
compile mlAppDeployerDependency
2324
compile mlcpUtilDependency
2425
compile group: 'commons-io', name: 'commons-io', version: '2.5'
26+
27+
testCompile localGroovy()
28+
testCompile gradleTestKit()
29+
testCompile 'xmlunit:xmlunit:1.3'
30+
testCompile('org.spockframework:spock-core:1.1-groovy-2.4') {
31+
exclude module: 'groovy-all'
32+
}
2533
}
2634

2735
task sourcesJar(type: Jar, dependsOn: classes) {
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/bash
2+
3+
if [ "${TRAVIS_SECURE_ENV_VARS}" = "true" ] ; then
4+
./shared/dev-tasks/travis-install-ml.sh release
5+
./shared/dev-tasks/setup-marklogic.sh
6+
fi

shared/dev-tasks/run-tests.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/bash
2+
3+
if [ "${TRAVIS_SECURE_ENV_VARS}" = "true" ] ; then
4+
cd ${TRAVIS_BUILD_DIR}
5+
./gradlew test -i
6+
fi
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/bash
2+
3+
sudo /etc/init.d/MarkLogic start
4+
sleep 10
5+
curl -X POST -d "" http://localhost:8001/admin/v1/init
6+
sleep 10
7+
curl -X POST -H "Content-type: application/x-www-form-urlencoded" \
8+
--data "admin-username=admin" \
9+
--data "admin-password=admin" \
10+
--data "realm=public" \
11+
"http://localhost:8001/admin/v1/instance-admin"
12+
sleep 10
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
#!/bin/bash
2+
3+
# runs command from parameters and exits with the eoror code of the command
4+
# if it fails
5+
function successOrExit {
6+
"$@"
7+
local status=$?
8+
if [ $status -ne 0 ]; then
9+
echo "$1 exited with error: $status"
10+
exit $status
11+
fi
12+
}
13+
14+
set | grep TRAVIS
15+
16+
test $1 && arg1=$1
17+
if [[ $arg1 = 'release' ]]; then
18+
ver=${ML_VERSION}
19+
fname=MarkLogic-${ver}.x86_64.rpm
20+
fnamedeb="marklogic_"
21+
fnamedeb=$fnamedeb$ver
22+
suff="_amd64.deb"
23+
fnamedeb=$fnamedeb$suff
24+
25+
curl -c cookies.txt --data "email=${MLBUILD_USER}&password=${MLBUILD_PASSWORD}" https://developer.marklogic.com/login
26+
dl_link=$(curl -b cookies.txt --data "download=/download/binaries/9.0/${fname}" https://developer.marklogic.com/get-download-url | perl -pe 's/.*"path":"([^"]+).*/\1/')
27+
url="https://developer.marklogic.com${dl_link}"
28+
29+
echo "********* Downloading MarkLogic $ver"
30+
31+
successOrExit curl -k -o ./$fname $url
32+
33+
fname=$(pwd)/$fname
34+
35+
sudo apt-get update
36+
sudo apt-get install wajig alien rpm lsb-base dpkg-dev debhelper build-essential
37+
(cd /etc && sudo ln -s default sysconfig)
38+
sudo wajig rpminstall $fname
39+
40+
echo "********* MarkLogic $ver installed"
41+
else
42+
# find today
43+
day=$(date +"%Y%m%d")
44+
45+
# if the user passed a day string as a param then use it instead
46+
test $1 && day=$1
47+
# make a version number out of the date
48+
ver="9.0-$day"
49+
50+
echo "********* Downloading MarkLogic nightly $ver"
51+
52+
# fetch/install ML nightly
53+
fname="MarkLogic-$ver.x86_64.rpm"
54+
fnamedeb="marklogic_"
55+
fnamedeb=$fnamedeb$ver
56+
suff="_amd64.deb"
57+
fnamedeb=$fnamedeb$suff
58+
59+
url="https://root.marklogic.com/nightly/builds/linux64-rh7/rh7v-intel64-90-test-build.marklogic.com/b9_0/pkgs.$day/$fname"
60+
61+
status=$(curl -k --anyauth -u $MLBUILD_USER:$MLBUILD_PASSWORD --head --write-out %{http_code} --silent --output /dev/null $url)
62+
if [[ $status = 200 ]]; then
63+
successOrExit curl -k --anyauth -u $MLBUILD_USER:$MLBUILD_PASSWORD -o ./$fname $url
64+
65+
fname=$(pwd)/$fname
66+
67+
sudo apt-get update
68+
sudo apt-get install alien dpkg-dev debhelper build-essential
69+
sudo alien -d -k $fname
70+
sudo dpkg -i $fnamedeb
71+
72+
echo "********* MarkLogic nightly $ver installed"
73+
else
74+
echo "CANNOT DOWNLOAD: status = $status for date $day (URL=\"$url\")"
75+
exit 1
76+
fi
77+
fi

src/main/groovy/com/marklogic/gradle/MarkLogicPlugin.groovy

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -62,23 +62,17 @@ import com.marklogic.mgmt.ManageConfig
6262
import com.marklogic.mgmt.admin.AdminConfig
6363
import com.marklogic.mgmt.admin.AdminManager
6464
import com.marklogic.mgmt.admin.DefaultAdminConfigFactory
65-
import com.sun.jersey.core.spi.component.ProviderServices
6665
import org.gradle.api.Plugin
6766
import org.gradle.api.Project
6867
import org.slf4j.LoggerFactory
6968

70-
import java.util.logging.Level
71-
import java.util.logging.Logger
72-
7369
class MarkLogicPlugin implements Plugin<Project> {
7470

7571
org.slf4j.Logger logger = LoggerFactory.getLogger(getClass())
7672

7773
void apply(Project project) {
7874
logger.info("\nInitializing ml-gradle")
7975

80-
quietDownJerseyLogging()
81-
8276
initializeAppDeployerObjects(project)
8377

8478
project.getConfigurations().create("mlRestApi")
@@ -293,16 +287,4 @@ class MarkLogicPlugin implements Plugin<Project> {
293287
deployer.setCommands(commands)
294288
return deployer
295289
}
296-
297-
/**
298-
* When the MarkLogic DatabaseClient class is used in Gradle, the Jersey ProviderServices class spits out
299-
* a lot of not helpful logging at the INFO level. So we bump it down to WARNING to avoid that.
300-
*/
301-
void quietDownJerseyLogging() {
302-
try {
303-
Logger.getLogger(ProviderServices.class.getName()).setLevel(Level.WARNING)
304-
} catch (Exception e) {
305-
// Ignore, not important
306-
}
307-
}
308290
}
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
package com.marklogic.gradle
2+
3+
import com.marklogic.mgmt.ManageClient
4+
import com.marklogic.mgmt.ManageConfig
5+
import com.marklogic.mgmt.admin.AdminConfig
6+
import com.marklogic.mgmt.admin.AdminManager
7+
import com.marklogic.mgmt.resource.appservers.ServerManager
8+
import com.marklogic.mgmt.resource.databases.DatabaseManager
9+
import com.marklogic.rest.util.ResourcesFragment
10+
import org.custommonkey.xmlunit.XMLUnit
11+
import org.gradle.testkit.runner.BuildResult
12+
import org.gradle.testkit.runner.GradleRunner
13+
import org.junit.rules.TemporaryFolder
14+
import spock.lang.Specification
15+
16+
class BaseTest extends Specification {
17+
static final TemporaryFolder testProjectDir = new TemporaryFolder()
18+
static File buildFile
19+
static File propertiesFile
20+
21+
static BuildResult runTask(String... task) {
22+
return GradleRunner.create()
23+
.withProjectDir(testProjectDir.root)
24+
.withArguments(task)
25+
.withDebug(true)
26+
.withPluginClasspath()
27+
.build()
28+
}
29+
30+
BuildResult runFailTask(String... task) {
31+
return GradleRunner.create()
32+
.withProjectDir(testProjectDir.root)
33+
.withArguments(task)
34+
.withDebug(true)
35+
.withPluginClasspath().buildAndFail()
36+
}
37+
38+
static void createBuildFile() {
39+
buildFile = testProjectDir.newFile('build.gradle')
40+
buildFile << """
41+
plugins {
42+
id 'com.marklogic.ml-gradle'
43+
}
44+
"""
45+
}
46+
47+
static AdminConfig getAdminConfig() {
48+
return new AdminConfig("localhost", 8001, "admin", "admin")
49+
}
50+
51+
static AdminManager getAdminManager() {
52+
return new AdminManager(getAdminConfig())
53+
}
54+
55+
static ManageClient getManageClient() {
56+
ManageConfig manageConfig = new ManageConfig("localhost", 8002, "admin", "admin")
57+
ManageClient manageClient = new ManageClient(manageConfig)
58+
return manageClient
59+
}
60+
61+
static ServerManager getServerManager() {
62+
return new ServerManager(getManageClient());
63+
}
64+
65+
static DatabaseManager getDatabaseManager() {
66+
return new DatabaseManager(getManageClient());
67+
}
68+
69+
static ResourcesFragment getDbConfig() {
70+
return getDatabaseManager().getAsXml()
71+
}
72+
73+
static ResourcesFragment getServerConfig() {
74+
return getServerManager().getAsXml()
75+
}
76+
77+
static void createPropertiesFile(contents) {
78+
propertiesFile = testProjectDir.newFile('gradle.properties')
79+
propertiesFile << contents
80+
}
81+
82+
def setupSpec() {
83+
XMLUnit.setIgnoreWhitespace(true)
84+
testProjectDir.create()
85+
createBuildFile()
86+
}
87+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package com.marklogic.gradle
2+
3+
import org.gradle.testkit.runner.UnexpectedBuildFailure
4+
5+
import static org.gradle.testkit.runner.TaskOutcome.SUCCESS
6+
7+
class DeployAppTaskTest extends BaseTest {
8+
9+
def "deploy barebones app"() {
10+
setup:
11+
print(runTask('mlUnDeploy').output)
12+
13+
expect:
14+
def srf = getServerConfig()
15+
def drf = getDbConfig()
16+
!srf.resourceExists("my-app")
17+
!drf.resourceExists("my-app-content")
18+
!drf.resourceExists("my-app-modules")
19+
20+
when:
21+
def result = runTask('mlDeploy')
22+
print(result.output)
23+
24+
then:
25+
notThrown(UnexpectedBuildFailure)
26+
result.task(":mlDeploy").outcome == SUCCESS
27+
def srf2 = getServerConfig()
28+
def drf2 = getDbConfig()
29+
srf2.resourceExists("my-app")
30+
drf2.resourceExists("my-app-content")
31+
drf2.resourceExists("my-app-modules")
32+
33+
cleanup:
34+
runTask('mlUndeploy')
35+
}
36+
37+
}

0 commit comments

Comments
 (0)