Ant

<?xml version="1.0" encoding="UTF-8"?>
<project name="baby-console" default="war file" basedir=".." xmlns:jacoco="antlib:org.jacoco.ant">
    <taskdef uri="antlib:org.jacoco.ant" resource="org/jacoco/ant/antlib.xml">
        <classpath path="${basedir}/lib_coverage/jacocoant.jar">
        </classpath>
    </taskdef>
    <property name="warFileName" value="baby-console.war">
    </property>
    <!-- 加载变量 -->
    <property file="build.properties" description="properties" />
    <!-- 加载版本 -->
    <property file="version.properties" description="ver_properties" />
    <path id="project.lib">
        <fileset dir="${basedir}/WebContent/WEB-INF/lib">
            <include name="**/*.jar" />
        </fileset>
    </path>
    <path id="provided.lib">
        <fileset dir="${basedir}/lib_provided">
            <include name="**/*.jar" />
        </fileset>
    </path>
    <path id="test.lib">
        <fileset dir="${basedir}/lib_test">
            <include name="**/*.jar" />
        </fileset>
    </path>
    <!--将file加入进来-->
    <path id="config.file">
        <fileset dir="${basedir}/config">
            <include name="**/*.*" />
        </fileset>
    </path>
    <target name="clean">
        <delete dir="${basedir}/build/build" />
        <mkdir dir="${basedir}/build/build" />
        <mkdir dir="${basedir}/build/build/classes" />
        <mkdir dir="${basedir}/build/build/testclasses" />
        <mkdir dir="${basedir}/build/build/UTReport" />
        <mkdir dir="${basedir}/build/build/UTCoverageReport" />
    </target>
    <target name="compile" depends="clean">
        <javac source="1.6" target="1.6" srcdir="${basedir}/src" destdir="${basedir}/build/build/classes" includeantruntime="false" debug="on">
            <compilerarg line="-encoding UTF-8 " />
            <classpath refid="project.lib" />
            <classpath refid="provided.lib" />
            <classpath refid="config.file" />
            <classpath>
                <pathelement location="${basedir}/config" />
            </classpath>
        </javac>
    </target>
    <target name="copy config" depends="compile">
        <copy todir="${basedir}/build/build/classes">
            <fileset dir="${basedir}/config" />
        </copy>
    </target>


    <target name="unit test compile" depends="copy config">
        <javac source="1.6" target="1.6" srcdir="${basedir}/test" destdir="${basedir}/build/build/testclasses" includeantruntime="false" debug="on">
            <compilerarg line="-encoding UTF-8 " />
            <classpath refid="project.lib" />
            <classpath refid="provided.lib" />
            <classpath refid="test.lib" />
            <classpath>
                <pathelement location="${basedir}/build/build/classes" />
            </classpath>
            <include name="**/*UT.java" />
            <include name="**/*Test.java"/>
        </javac>
    </target>

    <target name="unit test junit report" depends="unit test compile">
        <junit printsummary="on" fork="true" showoutput="true">
            <classpath refid="project.lib" />
            <classpath refid="provided.lib" />
            <classpath refid="test.lib" />
            <classpath>
                <pathelement location="${basedir}/build/build/classes" />
            </classpath>
            <classpath>
                <pathelement location="${basedir}/build/build/testclasses" />
            </classpath>
            <formatter type="xml" />
            <batchtest todir="${basedir}/build/build/UTReport">
                <fileset dir="${basedir}/build/build/testclasses">
                    <include name="**/*UT*.*" />
                </fileset>
            </batchtest>
        </junit>
        <junitreport todir="${basedir}/build/build/UTReport">
            <fileset dir="${basedir}/build/build/UTReport">
                <include name="UT-*.xml" />
            </fileset>
            <report format="frames" todir="${basedir}/build/build/UTReport" />
        </junitreport>
    </target>
    <target name="war file" depends="copy config">
        <delete file="${basedir}/baby-console.war" />
        <war destfile="${basedir}/${warFileName}" webxml="${basedir}/WebContent/WEB-INF/web.xml">
            <fileset dir="${basedir}/WebContent">
                <include name="**/**.*" />
                <exclude name="**/*.jar" />
                <exclude name="**/*.class" />
            </fileset>

            <lib dir="${basedir}/WebContent/WEB-INF/lib" />
            <classes dir="${basedir}/build/build/classes" />

        </war>
    </target>
    <target name="test war file" depends="unit test junit report">
        <delete file="${basedir}/baby-console.war" />

        <war destfile="${basedir}/${warFileName}" webxml="${basedir}/WebContent/WEB-INF/web.xml">
            <fileset dir="${basedir}/WebContent">
                <include name="**/**.*" />
                <exclude name="**/*.jar" />
                <exclude name="**/*.class" />
            </fileset>

            <lib dir="${basedir}/WebContent/WEB-INF/lib" />
            <lib dir="${basedir}/lib_test"/>
            <classes dir="${basedir}/build/build/classes" />
            <classes dir="${basedir}/build/build/testclasses" />
        </war>
    </target>
    <target name="ut coverage">
        <jacoco:coverage destfile="${basedir}/build/jacocoUT.exec">
            <junit haltonfailure="false" fork="true" printsummary="true">
                <classpath refid="project.lib">
                </classpath>
                <classpath refid="provided.lib">
                </classpath>
                <classpath refid="test.lib">
                </classpath>

                <classpath>
                    <pathelement location="${basedir}/build/build/classes" />
                </classpath>
                <classpath>
                    <pathelement location="${basedir}/build/build/testclasses" />
                </classpath>
                <formatter type="xml" />
                <batchtest todir="${basedir}/build/build/UTCoverageReport">
                    <fileset dir="${basedir}/build/build/testclasses">
                        <include name="**/*UT.class" />
                    </fileset>
                </batchtest>
            </junit>
        </jacoco:coverage>
    </target>

    <target name="ut coverage report" depends="ut coverage">
        <jacoco:report>
            <executiondata>
                <file file="${basedir}/build/jacocoUT.exec" />
            </executiondata>
            <structure name="unit test coverage rate report">
                <classfiles>
                    <fileset dir="${basedir}/build/build/classes" />
                </classfiles>
                <sourcefiles encoding="UTF-8">
                    <fileset dir="${basedir}/src" />
                </sourcefiles>
            </structure>
            <html footer="baby-console ut coverage report" destdir="${basedir}/build/build/UTCoverageReport" />
            <csv destfile="${basedir}/build/build/UTCoverageReport/coverage-report.csv" />
            <xml destfile="${basedir}/build/build/UTCoverageReport/coverage-report.xml" />
        </jacoco:report>
    </target>
    <target name="junit integration test" depends="ut coverage report">
            <junit printsummary="on" fork="true" showoutput="true">
                <classpath refid="project.lib" />
                <classpath refid="provided.lib" />
                <classpath refid="test.lib" />
                <classpath>
                    <pathelement location="${basedir}/build/build/classes" />
                </classpath>
                <classpath>
                    <pathelement location="${basedir}/build/build/testclasses" />
                </classpath>
                <formatter type="xml" />
                <batchtest>
                    <fileset dir="${basedir}/build/build/testclasses">
                        <include name="**/*IT.*" />
                    </fileset>
                </batchtest>
            </junit>
    </target>
    <target name="it coverage" depends="junit integration test">
        <jacoco:dump address="172.31.20.46" reset="true" destfile="${basedir}/build/jacocoIT.exec" port="5000" append="true">
        </jacoco:dump>
    </target>
    <target name="it coverage report" depends="it coverage">
        <delete dir="${basedir}/build/build/ITCoverageReport" />
        <mkdir dir="${basedir}/build/build/ITCoverageReport" />
        <jacoco:report>
            <executiondata>
                <file file="${basedir}/build/jacocoIT.exec" />
            </executiondata>
            <structure name="integration test coverage rate report">
                <group name="Check Order Related">
                    <classfiles>
                        <fileset dir="${basedir}/build/build/classes" />
                    </classfiles>
                    <sourcefiles encoding="UTF-8">
                        <fileset dir="${basedir}/src" />
                    </sourcefiles>
                </group>
            </structure>
            <html footer="baby-console it coverage report" destdir="${basedir}/build/build/ITCoverageReport" />
            <csv destfile="${basedir}/build/build/ITCoverageReport/coverage-report.csv" />
            <xml destfile="${basedir}/build/build/ITCoverageReport/coverage-report.xml" />
        </jacoco:report>
    </target>
</project>

SonarQube Scanner

sonar.projectKey=com.ideal.baby.school:baby-console
sonar.projectName=baby-console
sonar.projectBaseDir=.
sonar.projectVersion=1.0.0-SNAPSHOT
sonar.sourceEncoding=UTF-8
sonar.sources=src,WebContent/WEB-INF/
sonar.tests=test
sonar.dynamicAnalysis=reuseReports
sonar.binaries=build/build/classes,build/build/testclasses
sonar.junit.reportsPath=build/build/UTReport
sonar.java.coveragePlugin=jacoco
sonar.jacoco.reportPath=build/jacocoUT.exec
sonar.jacoco.itReportPath=build/jacocoIT.exec
sonar.host.url=http://172.31.20.46:9000
Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐