Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Random failure picking up formatter@toFile #1

Open
dharkness opened this issue Mar 19, 2014 · 1 comment
Open

Random failure picking up formatter@toFile #1

dharkness opened this issue Mar 19, 2014 · 1 comment

Comments

@dharkness
Copy link

I have defined the task, macro, and target as follows, and this works 99% of the time:

<taskdef name="phpmdexe"
         classname="org.phpmd.ant.PHPMDTask"/>

<macrodef name="phpmd">
    <attribute name="dir" default="${src.dir}"/>
    <attribute name="rulesets" default="codesize,unusedcode,naming"/>
    <attribute name="failonviolation" default="off"/>
    <attribute name="failonerror" default="off"/>
    <sequential>
        <echo>Output: ${log.dir}/pmd.xml</echo>    <!-- added for debugging -->
        <phpmdexe
                  taskname="mess"
                  rulesetfiles="@{rulesets}"
                  failOnRuleViolation="@{failonviolation}"
                  failonerror="@{failonerror}">    <!-- line 72 in stack trace below -->
            <formatter type="xml" toFile="${log.dir}/pmd.xml"/>
            <fileset dir="@{dir}">
                <include name="**/*.php"/>
            </fileset>
        </phpmdexe>
    </sequential>
</macrodef>

<target name="mess" depends="init">
    <phpmd/>
</target>

Every once in a while the build fails in Jenkins (we don't run these Ant builds outside Jenkins) like so:

mess:
[mess] Output: /var/lib/jenkins/jobs/nws/workspace/build/logs/pmd.xml
BUILD FAILED
/var/lib/jenkins/jobs/build-base.xml:72: Attribute formatter@toFile must be defined.

I suspect some sort of concurrency issue because I'm using the PHP Template Job for Jenkins which executes the code-quality tools in parallel, but I can't see how it could fail given that outputting the formatter@toFile value immediately before calling the PHPMD Ant task (all in the same thread) works fine.

My best guess (just came to me) since this started happening several months ago is that there must be a race condition when setting the ${log.dir} property from each parallel subtask (they all depend on the init target)--even though each is using the same value and properties are immutable in Ant.

I'm stumped, but I'm going to remove the depends="init" from each parallel task as a test. I added them only so you could call any individual task directly.

Has anyone else seen this problem?

@dharkness
Copy link
Author

Meh, the init target doesn't set properties--it creates the directories. And it's depended on by the default build target as well.

<target name="init">
    <mkdir dir="${build.dir}"/>
    <mkdir dir="${api.dir}"/>
    <mkdir dir="${code.dir}"/>
    <mkdir dir="${coverage.dir}"/>
    <mkdir dir="${log.dir}"/>
    <mkdir dir="${pdepend.dir}"/>
</target>

The properties, including log.dir are declared at the top of build.xml. Since the PHPMD Ant task only checks if the toFile attribute is non-empty--it doesn't look for a directory--I am back to square one and have no clue why it fails like this. :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant