Skip to content

Commit 9d35aaf

Browse files
committed
LUCENE-6938: Add WC checks back, now based on JGit
1 parent 74e5f1c commit 9d35aaf

File tree

1 file changed

+70
-5
lines changed

1 file changed

+70
-5
lines changed

build.xml

+70-5
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
<project name="lucene-solr" default="-projecthelp" basedir=".">
2121
<import file="lucene/common-build.xml"/>
2222

23+
<property name="jgit-version" value="4.2.0.201601211800-r"/>
24+
2325
<property name="tests.heap-dump-dir" location="heapdumps"/>
2426

2527
<property name="maven-build-dir" value="maven-build"/>
@@ -551,8 +553,71 @@ File | Project Structure | Platform Settings | SDKs):
551553
<delete dir="${smokeTestRelease.tmp}"/>
552554
</target>
553555

554-
<target name="check-working-copy">
555-
<echo>This task is currently disabled due to migration to GIT</echo>
556+
<macrodef xmlns:ivy="antlib:org.apache.ivy.ant" name="wc-checker">
557+
<attribute name="failonmodifications"/><!-- fail if modifications were found, otherwise it only fails on unversioned files -->
558+
<sequential>
559+
<local name="wc.unversioned.files"/>
560+
<local name="wc.modified.files"/>
561+
<ivy:cachepath xmlns:ivy="antlib:org.apache.ivy.ant"
562+
organisation="org.eclipse.jgit" module="org.eclipse.jgit" revision="${jgit-version}"
563+
inline="true" conf="default" transitive="true" pathid="jgit.classpath"/>
564+
<groovy taskname="wc-checker" classpathref="jgit.classpath"><![CDATA[
565+
import org.apache.tools.ant.BuildException;
566+
import org.apache.tools.ant.Project;
567+
import org.eclipse.jgit.api.Git;
568+
import org.eclipse.jgit.api.Status;
569+
import org.eclipse.jgit.lib.Repository;
570+
import org.eclipse.jgit.storage.file.FileRepositoryBuilder;
571+
import org.eclipse.jgit.errors.*;
572+
573+
def setProjectPropertyFromSet(prop, set) {
574+
if (set) {
575+
properties[prop] = '* ' + set.join(properties['line.separator'] + '* ');
576+
}
577+
};
578+
579+
try {
580+
task.log('Initializing working copy...', Project.MSG_INFO);
581+
final Repository repository = new FileRepositoryBuilder()
582+
.setWorkTree(project.getBaseDir())
583+
.setMustExist(true)
584+
.build();
585+
586+
task.log('Checking working copy status...', Project.MSG_INFO);
587+
final Status status = new Git(repository).status().call();
588+
if (!status.isClean()) {
589+
final SortedSet unversioned = new TreeSet(), modified = new TreeSet();
590+
status.properties.each{ prop, val ->
591+
if (val instanceof Set) {
592+
if (prop in ['untracked', 'untrackedFolders', 'missing']) {
593+
unversioned.addAll(val);
594+
} else if (prop != 'ignoredNotInIndex') {
595+
modified.addAll(val);
596+
}
597+
}
598+
};
599+
setProjectPropertyFromSet('wc.unversioned.files', unversioned);
600+
setProjectPropertyFromSet('wc.modified.files', modified);
601+
}
602+
} catch (RepositoryNotFoundException | NoWorkTreeException | NotSupportedException e) {
603+
task.log('WARNING: Development directory is not a valid GIT checkout! Disabling checks...', Project.MSG_WARN);
604+
}
605+
]]></groovy>
606+
<fail if="wc.unversioned.files"
607+
message="Source checkout is dirty (unversioned/missing files) after running tests!!! Offending files:${line.separator}${wc.unversioned.files}"/>
608+
<fail message="Source checkout is modified!!! Offending files:${line.separator}${wc.modified.files}">
609+
<condition>
610+
<and>
611+
<istrue value="@{failonmodifications}"/>
612+
<isset property="wc.modified.files"/>
613+
</and>
614+
</condition>
615+
</fail>
616+
</sequential>
617+
</macrodef>
618+
619+
<target name="check-working-copy" description="Checks working copy for unversioned changes" depends="resolve-groovy">
620+
<wc-checker failonmodifications="${is.jenkins.build}"/>
556621
</target>
557622

558623
<target name="run-clover" description="Runs all tests to measure coverage and generates report (pass &quot;ANT_OPTS=-Xmx1536M&quot; as environment)" depends="clean">
@@ -645,13 +710,13 @@ File | Project Structure | Platform Settings | SDKs):
645710
</target>
646711

647712
<!-- should only be called by jenkins, not precommit! -->
648-
<target name="-check-after-regeneration">
649-
<!-- TODO -->
713+
<target name="-check-after-regeneration" depends="resolve-groovy">
714+
<wc-checker failonmodifications="true"/>
650715
</target>
651716

652717
<!-- TODO: remove me when jenkins works -->
653718
<target name="regenerateAndCheck" depends="regenerate,-check-after-regeneration"/>
654-
719+
655720
<target name="-append-all-modules-dependencies-properties">
656721
<delete file="lucene/build/module.dependencies.properties"/>
657722
<subant target="-append-module-dependencies-properties" inheritall="false" failonerror="true">

0 commit comments

Comments
 (0)