add history

This commit is contained in:
Ivan Zinchenko 2025-06-20 23:41:01 +03:00
parent d7e50e36f2
commit 2287bd9e8f
6 changed files with 68 additions and 118 deletions

11
build.properties Normal file
View File

@ -0,0 +1,11 @@
src.dir=src/main/java
res.dir=src/main/resources
web.dir=src/main/webapp
test.dir=src/test/java
build.dir=build
dist.dir=dist
lib.dir=lib
war.name=jsf.war
history.diff.file=history.sh
history.script=history.diff

129
build.xml
View File

@ -1,33 +1,21 @@
<project name="jsf" default="build" basedir=".">
<!-- Конфигурация -->
<property name="src.dir" value="src/main/java"/>
<property name="res.dir" value="src/main/resources"/>
<property name="web.dir" value="src/main/webapp"/>
<property name="test.dir" value="src/test/java"/>
<property name="build.dir" value="build"/>
<property name="dist.dir" value="dist"/>
<property name="lib.dir" value="lib"/>
<property name="war.name" value="jsf.war"/>
<property file="build.properties"/>
<taskdef resource="net/sf/antcontrib/antlib.xml">
<classpath>
<pathelement location="lib/ant-contrib-1.0b3.jar"/>
</classpath>
</taskdef>
<path id="graal.classpath">
<pathelement location="lib/js-scriptengine-23.1.2.jar" />
<pathelement location="lib/js-22.3.1.jar" />
</path>
<!-- Подготовка -->
<target name="prepare">
<mkdir dir="${build.dir}"/>
<mkdir dir="${dist.dir}"/>
</target>
<!-- Очистка -->
<target name="clean">
<delete dir="${build.dir}"/>
<delete dir="${dist.dir}"/>
</target>
<!-- Компиляция -->
<target name="compile" depends="prepare">
<javac srcdir="${src.dir}" destdir="${build.dir}" includeantruntime="false" source="17" target="17">
<classpath>
@ -39,9 +27,8 @@
</copy>
</target>
<!-- Упаковка в WAR -->
<target name="build" depends="compile">
<war destfile="${dist.dir}/${war.name}" webxml="${web.dir}/WEB-INF/web.xml">
<war destfile="${dist.dir}/${war.name}" webxml="${web.dir}/WEB-INF/web.xml" manifest="src/main/resources/META-INF/MANIFEST.MF">
<fileset dir="${web.dir}">
<exclude name="WEB-INF/web.xml"/>
</fileset>
@ -60,7 +47,6 @@
</javac>
</target>
<!-- Тесты -->
<target name="test" depends="compile-tests">
<mkdir dir="test-reports"/>
<junit printsummary="yes" haltonfailure="yes" fork="true">
@ -77,110 +63,17 @@
</junit>
</target>
<!-- Валидация XML -->
<target name="xml">
<xmlvalidate lenient="no" failonerror="yes">
<fileset dir="." includes="**/*.xml"/>
<xmlvalidate lenient="true" failonerror="yes">
<fileset dir="." includes="**/*.xml" />
</xmlvalidate>
</target>
<!-- История -->
<target name="history">
<condition property="git.present">
<available file=".git" type="dir"/>
</condition>
<fail message="Git is required." unless="git.present"/>
<echo message="🔁 Attempting history recovery..."/>
<exec executable="git" output="revs.txt" failonerror="true">
<arg value="rev-list"/>
<arg value="HEAD"/>
<exec executable="bash">
<env key="DIFF_FILE" value="${history.diff.file}"/>
<arg value="${history.script}"/>
</exec>
<loadfile property="rev.lines" srcFile="revs.txt"/>
<property name="last.good" value=""/>
<property name="next.bad" value=""/>
<foreach list="${rev.lines}" target="try-revision" param="rev"/>
<fail message="🛑 No working revision found!" unless="last.good"/>
<echo message="✅ Working revision: ${last.good}"/>
<echo message="📄 Diffing from ${next.bad} to ${last.good}"/>
<exec executable="git" failonerror="false">
<arg value="diff"/>
<arg value="${next.bad}"/>
<arg value="${last.good}"/>
<redirector output="diff.patch"/>
</exec>
<echo message="📝 Diff saved to diff.patch"/>
</target>
<target name="try-revision" unless="last.good">
<echo message="⏪ Trying revision: ${rev}"/>
<exec executable="git" failonerror="false">
<arg value="checkout"/>
<arg value="${rev}"/>
</exec>
<property name="compile.successful" value="false"/>
<trycatch>
<try>
<antcall target="clean"/>
<antcall target="compile"/>
<property name="compile.successful" value="true"/>
</try>
<catch>
<echo message="❌ Failed to compile at ${rev}"/>
</catch>
</trycatch>
<if>
<equals arg1="${compile.successful}" arg2="true"/>
<then>
<echo message="✅ Successfully compiled ${rev}"/>
<property name="last.good" value="${rev}"/>
<echo message="🛑 Breaking loop"/>
<property name="break.loop" value="true"/>
</then>
<else>
<property name="next.bad" value="${rev}"/>
</else>
</if>
</target>
<target name="try-compile" unless="found.good">
<property name="current.rev" value="@{rev}"/>
<exec executable="git" failonerror="true">
<arg value="checkout"/>
<arg value="${current.rev}"/>
</exec>
<trycatch property="compile.success">
<try>
<antcall target="clean"/>
<antcall target="compile"/>
</try>
<catch>
<echo message="❌ Failed to compile at ${current.rev}"/>
</catch>
</trycatch>
<condition property="compile.success">
<available file="${build.dir}"/>
</condition>
<if>
<isset property="compile.success"/>
<then>
<property name="last.good" value="${current.rev}"/>
<property name="found.good" value="true"/>
</then>
<else>
<property name="next.bad" value="${current.rev}"/>
</else>
</if>
</target>
</project>

46
history.sh Normal file
View File

@ -0,0 +1,46 @@
#!/usr/bin/env bash
set -euo pipefail
# You can override with env vars when invoking from Ant
DIFF_FILE="${DIFF_FILE:-history.diff}"
# Remember where we started, so we can optionally restore later
ORIG_HEAD="$(git rev-parse HEAD)"
BROKEN_COMMIT=""
# Compile target to test (defaults to 'compile', change if necessary)
ANT_TARGET="${ANT_TARGET:-compile}"
while true; do
echo "[history.sh] Trying to build commit $(git rev-parse --short HEAD)"
if ant -q "${ANT_TARGET}"; then
echo "[history.sh] Build succeeded on commit $(git rev-parse --short HEAD)"
break
fi
if [[ -z "${BROKEN_COMMIT}" ]]; then
BROKEN_COMMIT="$(git rev-parse HEAD)"
fi
# If this is the first commit, stop the search
if [[ "$(git rev-list --count HEAD)" -eq 1 ]]; then
echo "[history.sh] Reached the first commit without a successful build. Aborting."
exit 1
fi
# Step back one commit
git reset --hard HEAD^
done
# If we discovered a broken commit, emit the diff
if [[ -n "${BROKEN_COMMIT}" ]]; then
echo "[history.sh] Saving diff between working HEAD and first broken commit ${BROKEN_COMMIT:0:7}${DIFF_FILE}"
git diff HEAD "${BROKEN_COMMIT}" > "${DIFF_FILE}"
fi
# Restore original state (comment this line if you prefer to stay on the good commit)
# git checkout -q "${ORIG_HEAD}"
exit 0

BIN
lib/ant-contrib-1.0b2.jar Normal file

Binary file not shown.

BIN
lib/js-22.3.1.jar Normal file

Binary file not shown.

Binary file not shown.