diff --git a/.gitignore b/.gitignore index 0cca571..03190ae 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,5 @@ build/** .gradle/** out/** .idea/** -.composite-enable \ No newline at end of file +.composite-enable +gradle.properties \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index 2c38b37..d7dcb9a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,19 +12,16 @@ cache: stages: - name: test - name: build -- name: snapshot - if: branch = master - name: release if: branch = release +before_script: + git checkout ${TRAVIS_BRANCH} # to fix issue with Grgit if travis checks out HEAD jobs: include: - stage: test - script: "./gradlew test" + script: "./gradlew test -PcheckoutIfCloned=true" - stage: build - script: "./gradlew build -x test" - - stage: snapshot - script: "./gradlew publish -x test -Dnexus.user=$NEXUS_USER -Dnexus.key=$NEXUS_KEY - -Dbuild.number=$TRAVIS_BUILD_NUMBER" + script: "./gradlew build -x test -PcheckoutIfCloned=true" - stage: release script: "./gradlew publish -x test -Ddisablesnapshot=true -Dnexus.user=$NEXUS_USER -Dnexus.key=$NEXUS_KEY -Dbuild.number=$TRAVIS_BUILD_NUMBER" diff --git a/GRADLE_BUILD.md b/GRADLE_BUILD.md new file mode 100644 index 0000000..e853715 --- /dev/null +++ b/GRADLE_BUILD.md @@ -0,0 +1,32 @@ +# Composite Build +The **upb.crypto** libraries, except for **math** all depend on at least one of the other libraries. +Often times, when developing for example **craco**, you might also be doing some changes to **math**. +To include these changes faster, we make extensive use of Gradle`s [composite build](https://docs.gradle.org/current/userguide/composite_builds.html) feature. +To make this easier to use, we have a composite build script contained in ``settings.gradle`` that decides when to enable composite builds and when not. +It also serves to enable composite builds on the Travis CI. + +## Default Script Behaviour +By default, the script will automatically clone **upb.crypto** dependencies that are not stored in the local file system yet. +It clones them to the same folder that the top-level folder of the library being built is contained in. +Furthermore, it checks that the branch names match. +If the library is on branch ``branch1`` and a dependency is on ``branch2``, the script will complain and tell you to checkout out branch ``branch1`` in the dependency's git. +If no such branch exists, the library will instead want to use the ``master`` branch. + +You can customize this behaviour via the properties detailed in the following section. + +## Customizing the Script via Properties +The composite build script can be customized via the following properties. +The parameters can be set via the ``gradle.properties`` file or set via command line as detailed [here](https://docs.gradle.org/current/userguide/build_environment.html). + +- ``useCurrentBranch``: If defined (any value), will cause the composite build to use the currently + checked out branch of the dependencies. +- ``checkoutIfCloned``: If defined (any value), will automatically check out the corresponding + dependency branch (branch with same name) given that the dependency was freshly cloned. + Used by the Travis CI to automatically switch to the right dependency branch for the build. + +An example ``gradle.properties`` file: +``` +useCurrentBranch="" +``` +Here, ``useCurrentBranch`` is enabled by giving it an empty String value. + diff --git a/build.gradle b/build.gradle index 996fce5..f3ae6c2 100644 --- a/build.gradle +++ b/build.gradle @@ -1,7 +1,6 @@ plugins { // Apply the java-library plugin to add support for Java Library id 'java-library' - id 'maven' id 'maven-publish' } @@ -62,8 +61,7 @@ test { //packaging tests task packageTests(type: Jar) { - classifier = 'tests' - baseName = project.name + '-test' + archiveClassifier = 'tests' from sourceSets.test.output+sourceSets.test.allSource } diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 0d4a951..62d4c05 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 2d9c86b..4c5803d 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,5 @@ -#Mon Oct 29 17:01:07 CET 2018 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-6.4-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-4.9-all.zip diff --git a/gradlew b/gradlew index cccdd3d..fbd7c51 100755 --- a/gradlew +++ b/gradlew @@ -1,5 +1,21 @@ #!/usr/bin/env sh +# +# Copyright 2015 the original author or authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + ############################################################################## ## ## Gradle start up script for UN*X @@ -28,7 +44,7 @@ APP_NAME="Gradle" APP_BASE_NAME=`basename "$0"` # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS="" +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD="maximum" @@ -66,6 +82,7 @@ esac CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + # Determine the Java command to use to start the JVM. if [ -n "$JAVA_HOME" ] ; then if [ -x "$JAVA_HOME/jre/sh/java" ] ; then @@ -109,10 +126,11 @@ if $darwin; then GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" fi -# For Cygwin, switch paths to Windows format before running java -if $cygwin ; then +# For Cygwin or MSYS, switch paths to Windows format before running java +if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then APP_HOME=`cygpath --path --mixed "$APP_HOME"` CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + JAVACMD=`cygpath --unix "$JAVACMD"` # We build the pattern for arguments to be converted via cygpath @@ -138,19 +156,19 @@ if $cygwin ; then else eval `echo args$i`="\"$arg\"" fi - i=$((i+1)) + i=`expr $i + 1` done case $i in - (0) set -- ;; - (1) set -- "$args0" ;; - (2) set -- "$args0" "$args1" ;; - (3) set -- "$args0" "$args1" "$args2" ;; - (4) set -- "$args0" "$args1" "$args2" "$args3" ;; - (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; - (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; - (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; - (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; - (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + 0) set -- ;; + 1) set -- "$args0" ;; + 2) set -- "$args0" "$args1" ;; + 3) set -- "$args0" "$args1" "$args2" ;; + 4) set -- "$args0" "$args1" "$args2" "$args3" ;; + 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; esac fi @@ -159,14 +177,9 @@ save () { for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done echo " " } -APP_ARGS=$(save "$@") +APP_ARGS=`save "$@"` # Collect all arguments for the java command, following the shell quoting and substitution rules eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" -# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong -if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then - cd "$(dirname "$0")" -fi - exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat index f955316..a9f778a 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -1,84 +1,104 @@ -@if "%DEBUG%" == "" @echo off -@rem ########################################################################## -@rem -@rem Gradle startup script for Windows -@rem -@rem ########################################################################## - -@rem Set local scope for the variables with windows NT shell -if "%OS%"=="Windows_NT" setlocal - -set DIRNAME=%~dp0 -if "%DIRNAME%" == "" set DIRNAME=. -set APP_BASE_NAME=%~n0 -set APP_HOME=%DIRNAME% - -@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -set DEFAULT_JVM_OPTS= - -@rem Find java.exe -if defined JAVA_HOME goto findJavaFromJavaHome - -set JAVA_EXE=java.exe -%JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto init - -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:findJavaFromJavaHome -set JAVA_HOME=%JAVA_HOME:"=% -set JAVA_EXE=%JAVA_HOME%/bin/java.exe - -if exist "%JAVA_EXE%" goto init - -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. - -goto fail - -:init -@rem Get command-line arguments, handling Windows variants - -if not "%OS%" == "Windows_NT" goto win9xME_args - -:win9xME_args -@rem Slurp the command line arguments. -set CMD_LINE_ARGS= -set _SKIP=2 - -:win9xME_args_slurp -if "x%~1" == "x" goto execute - -set CMD_LINE_ARGS=%* - -:execute -@rem Setup the command line - -set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar - -@rem Execute Gradle -"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% - -:end -@rem End local scope for the variables with windows NT shell -if "%ERRORLEVEL%"=="0" goto mainEnd - -:fail -rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of -rem the _cmd.exe /c_ return code! -if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 -exit /b 1 - -:mainEnd -if "%OS%"=="Windows_NT" endlocal - -:omega +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto init + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto init + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:init +@rem Get command-line arguments, handling Windows variants + +if not "%OS%" == "Windows_NT" goto win9xME_args + +:win9xME_args +@rem Slurp the command line arguments. +set CMD_LINE_ARGS= +set _SKIP=2 + +:win9xME_args_slurp +if "x%~1" == "x" goto execute + +set CMD_LINE_ARGS=%* + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/settings.gradle b/settings.gradle index 92db598..db2f49c 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1 +1,78 @@ -rootProject.name = 'protocols' \ No newline at end of file +plugins { + id 'org.ajoberstar.grgit' version '4.0.2' apply false +} +import org.ajoberstar.grgit.Grgit + +rootProject.name = 'protocols' +def msgPrefix = rootProject.name + " settings: " + +// do specific snapshot dependency resolution for snapshot builds +if (!Boolean.valueOf(System.getProperty("disablesnapshot"))) { + def compositeLibraries = ["upb.crypto.math", "upb.crypto.craco"] + for (String lib : compositeLibraries) { + def libPrefix = "dependency " + lib + def libPath = file("../" + lib).getPath() + def grgitLib + def cloned + if (file(libPath).exists()) { + println(msgPrefix + libPrefix + ": Local repository exists.") + grgitLib = Grgit.open(dir: libPath) + cloned = false + } else { + println(msgPrefix + libPrefix + ": Local repository does not exist. Cloning to " + libPath + ".") + grgitLib = Grgit.clone(dir: libPath, uri: "https://github.com/upbcuk/" + lib + ".git") + cloned = true + } + def grgitThis = Grgit.open(dir: rootProject.projectDir) + def branchThis = grgitThis.branch.current() + if (hasProperty("useCurrentBranch")) { + println(msgPrefix + libPrefix + ": Parameter 'useCurrentBranch' is set. Using branch '" + grgitLib.branch.current().getName() + "'.") + } else { + if (file(libPath + "/.git/refs/heads/" + branchThis.getName()).exists()) { + if (grgitLib.branch.current().getName() == branchThis.getName()) { + println(msgPrefix + libPrefix + ": Branch '" + branchThis.getName() + "' exists and is checked out already.") + } else { + throw new GradleException(msgPrefix + libPrefix + ": Branch '" + branchThis.getName() + "' exists but is not checked out. " + + "Please check it out yourself before building.") + } + } else { + println(msgPrefix + libPrefix + ": Branch '" + branchThis.getName() + "' does not exist locally.") + if (grgitLib.branch.list { mode = "REMOTE" }.collect { it.getName() }.contains("origin/" + branchThis.getName())) { + if (hasProperty("checkoutIfCloned") && cloned) { + println(msgPrefix + libPrefix + ": Branch '" + branchThis.getName() + "' exists but is not checked out. " + + "'checkoutIfCloned' is set. Automatically checking it out.") + grgitLib.checkout { + branch = branchThis.getName() + startPoint = "origin/" + branchThis.getName() + createBranch = true + } + } else { + throw new GradleException(msgPrefix + libPrefix + ": Branch '" + branchThis.getName() + + "' exists remotely but not locally. Please check it out yourself before building.") + } + } else { + println(msgPrefix + libPrefix + ": Branch '" + branchThis.getName() + "' does not exist remotely. Using master.") + if (grgitLib.branch.current().getName() == "master") { + println(msgPrefix + libPrefix + ": Branch master is checked out already. Using it.") + } else { + if (hasProperty("checkoutIfCloned") && cloned) { + println(msgPrefix + libPrefix + ": Branch master is not checked out. " + + "'checkoutIfCloned' is set. Automatically checking it out.") + grgitLib.checkout { + branch = branchThis.getName() + startPoint = "origin/" + branchThis.getName() + createBranch = true + } + } else { + throw new GradleException(msgPrefix + libPrefix + ": Branch master exists but is not checked out. " + + "Please check it out yourself before building.") + } + } + } + } + } + + println(msgPrefix + libPrefix + ": Enabling composite build.") + includeBuild(libPath) + } +}