سؤال

After reading through a lot of SO questions as well as other sites I still haven't been able to exactly address this problem.

We have a long build cycle (10-20 mins) because there are a lot of dependencies. It sometimes happens that you start a build with everything up do date, but while it's being done, someone pushes new changes to the remote svn.

I would like Maven to check on the validate and verify phases if svn is still up to date basically, on all dependent projects.

I've tried using the Enforcer plugin, and the Build number plugin with no success yet. The enforcer seems like it could do the trick, but I haven't figured out which rules to set. The build number plugin on the other hand checks if there are no local modifications, but I don't think it checks the remote changes.

I don't think the POM is very relevant to the question, but if anyone needs it, or some parts please let me know and I'll update with it.

هل كانت مفيدة؟

المحلول

I would try a combination of the maven-scm-plugin's diff goal and Enforcer.

scm:diff may be configured to write output to a file. Run that when there are no changes and see how big the file is, or, if it generates the file at all if there are no changes. Then, use the Enforcer plugin's requireFilesDontExist and/or requireFileSize rules to make sure the scm:diff output file is the "no changes" size you determined. If it's larger than that, changes were committed during this build.

نصائح أخرى

After a lot of testing I found another solution. This solution is for people that work with SVN and only want to commit changes once the build succeeds, and need to use the latest revision for a build.

What this will do is retrieve the latest revision number from SVN and update the working copy. At the end of the build process it will check the revision number again, to ensure that no one has pushed any changes.

<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>buildnumber-maven-plugin</artifactId>
<version>1.2</version>
<executions>
    <execution>
        <id>get-svn-local-revision-before</id>
        <phase>validate</phase>
        <goals>
            <goal>create</goal>
        </goals>
        <configuration>
            <doCheck>false</doCheck>
            <doUpdate>true</doUpdate>
            <buildNumberPropertyName>buildNumberLocal</buildNumberPropertyName>
            <useLastCommittedRevision>true</useLastCommittedRevision>
        </configuration>
    </execution>
    <execution>
        <id>get-svn-remote-revision-before</id>
        <phase>validate</phase>
        <goals>
            <goal>create</goal>
        </goals>
        <configuration>
            <doCheck>false</doCheck>
            <doUpdate>false</doUpdate>
            <buildNumberPropertyName>buildNumberRemote</buildNumberPropertyName>
            <useLastCommittedRevision>false</useLastCommittedRevision>
        </configuration>
    </execution>
    <!-- Repeat after everything is done -->
    <execution>
        <id>get-svn-remote-revision-after</id>
        <phase>verify</phase>
        <goals>
            <goal>create</goal>
        </goals>
        <configuration>
            <doCheck>false</doCheck>
            <doUpdate>false</doUpdate>
            <buildNumberPropertyName>buildNumberRemote</buildNumberPropertyName>
            <useLastCommittedRevision>false</useLastCommittedRevision>
        </configuration>
    </execution>
</executions>
</plugin>
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-enforcer-plugin</artifactId>
    <version>1.3.1</version>
    <executions>
    <execution>
        <id>check-svn-revisions-before</id>
        <phase>process-test-resources</phase>
        <goals>
            <goal>enforce</goal>
        </goals>
        <configuration>
            <rules>
                <evaluateBeanshell>
                     <condition>${buildNumberLocal} == ${buildNumberRemote}</condition>
                     <message>[ERROR] Local build (${buildNumberLocal}) doesn't match remote build (${buildNumberRemote})</message>
                </evaluateBeanshell>
             </rules>
             <fail>true</fail>
        </configuration>
    </execution>
    <!-- Repeat after everything is done -->
    <execution>
        <id>check-svn-revisions-after</id>
        <phase>verify</phase>
        <goals>
            <goal>enforce</goal>
        </goals>
        <configuration>
            <rules>
                <evaluateBeanshell>
                    <condition>${buildNumberLocal} == ${buildNumberRemote}</condition>
                    <message>[ERROR] Local build (${buildNumberLocal}) doesn't match remote build (${buildNumberRemote})</message>
                </evaluateBeanshell>
             </rules>
             <fail>true</fail>
        </configuration>
    </execution>
</executions>
</plugin>
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top