From 3e34f7c596462c00bee503703d0856d4a3d46a5c Mon Sep 17 00:00:00 2001 From: reger24 Date: Tue, 18 Jan 2022 20:00:55 +0100 Subject: [PATCH] Import Ant build.xml into Gradle and use old compile of servlets in Gradle to be able to use/reuse Ant targets where task has not been implemented in Gradle build. - use the import to include the compile of htroot as first important task ! it is possible that first build fails an compile of GitRevTask.jar ! ! solution/workaround -> use "ant all" once to compile GitRevTask.jar ! - adjusted build.xml a little - split compile-core into compile-core and compile-htroot to have a target for htroot comp. only - set build-path to reuse Gradles build directory - (fix javadoc failure) - changed the filtered-copy of yacyBuildProperties.java to ! the build path :-( as current (copy,delete,exclude) is complicated and not migration worthy, used simple/straigt forward approach (using a yacyBuildProperties.java.template file as copy source) --- .gitignore | 1 + build.gradle | 26 +++++++ build.xml | 27 +++---- .../yacyBuildProperties.java.template | 72 +++++++++++++++++++ 4 files changed, 113 insertions(+), 13 deletions(-) create mode 100644 source/net/yacy/peers/operation/yacyBuildProperties.java.template diff --git a/.gitignore b/.gitignore index 1e2bb8ca6..e4c8e7eb3 100644 --- a/.gitignore +++ b/.gitignore @@ -21,3 +21,4 @@ yacy.log /javadoc/ /build/ .gradle +source/net/yacy/peers/operation/yacyBuildProperties.java diff --git a/build.gradle b/build.gradle index 0735eee9c..a5b74a058 100644 --- a/build.gradle +++ b/build.gradle @@ -109,3 +109,29 @@ task copyDependenciesToLib(type: Copy) { } build.dependsOn(copyDependenciesToLib) } + +/** ----------------------------------------------------------- + * Settings during the migration from Ant to Gradle build + * importing Ant targets and to use them within this Gradle build + * until/where functionality has not been migrated yet + * ------------------------------------------------------------ + */ +// Import Ant build and prefix all task names with 'ant_' to prevent naming conflict with Gradle tasks. +ant.importBuild('build.xml') { antTaskName -> "ant_${antTaskName}".toString() } + +// Set group property for all Ant tasks. +tasks.matching { task -> task.name.startsWith('ant_') }*.group = 'Ant' + +// include compile of htroot servlets in Gradle lifecycle somewhere after compileJava +startScripts.dependsOn("ant_compile-htroot") + +tasks.named('ant_buildGitRevTask') { + doFirst { + println '=====================================' + println 'In case this imported Ant task fails' + println '(stop ant jvm which on failure keeps a lock on libbuild/GitRevTask.jar (making supsequent builds fail too)' + println '- run the normal ant build "ant all" ONCE (to complile the libbuild/GitRevTask.jar)' + println '- after this Gradle build should work' + println '=====================================' + } +} \ No newline at end of file diff --git a/build.xml b/build.xml index 1f482df63..560bbb828 100644 --- a/build.xml +++ b/build.xml @@ -43,7 +43,7 @@ - + @@ -81,7 +81,7 @@ - + @@ -146,11 +146,10 @@ - - + - + @@ -159,7 +158,8 @@ windowtitle="YaCy API: javadoc documentation" encoding="UTF-8" charset="UTF-8" - access="private"> + access="private" + useexternalfile="true"> @@ -280,6 +280,7 @@ + @@ -319,7 +319,7 @@ - + + + @@ -538,18 +540,17 @@ - - - + + - + diff --git a/source/net/yacy/peers/operation/yacyBuildProperties.java.template b/source/net/yacy/peers/operation/yacyBuildProperties.java.template new file mode 100644 index 000000000..9149ae567 --- /dev/null +++ b/source/net/yacy/peers/operation/yacyBuildProperties.java.template @@ -0,0 +1,72 @@ +package net.yacy.peers.operation; + +import java.util.Locale; +import java.util.regex.Pattern; + + +/** + * Properties set when compiling this release/version + */ +public final class yacyBuildProperties { + private yacyBuildProperties() { + } + + /** + * returns the SVN-Revision Number as a String + */ + public static String getSVNRevision() { + final String revision = "@REPL_REVISION_NR@"; + if (revision.contains("@") || revision.contains("$")) { + return "0"; + } + return revision; + } + + /** + * returns the version String (e. g. 0.9) + */ + public static String getVersion() { + if ("@REPL_VERSION@".contains("@") ) { + return "0.1"; + } + return "@REPL_VERSION@"; + } + + public static final Pattern versionMatcher = Pattern.compile("\\A(\\d+\\.\\d{1,3})(\\d{0,5})\\z"); + + /** + * returns the long version String (e. g. 0.9106712) + */ + public static String getLongVersion() { + return String.format(Locale.US, "%.3f%05d", Float.valueOf(getVersion()), Integer.valueOf(getSVNRevision())); + } + + /** + * returns the date, when this release was build + */ + public static String getBuildDate() { + if ("@REPL_DATE@".contains("@")) { + return "19700101"; + } + return "@REPL_DATE@"; + } + + /** + * determines, if this release was compiled and installed + * by a package manager + */ + public static boolean isPkgManager() { + return "@REPL_PKGMANAGER@".equals("true"); + } + + /** + * returns command to use to restart the YaCy daemon, + * when YaCy was installed with a packagemanger + */ + public static String getRestartCmd() { + if ("@REPL_RESTARTCMD@".contains("@")) { + return "echo 'error'"; + } + return "@REPL_RESTARTCMD@"; + } +}