Creating a Java build specificationCreating a Java build specificationKlocwork integrates with your build, capturing all of the information it needs to provide a centralized view of the entire code stream. Klocwork stores this information in a text file we call a build specification. The build specification is the basis of the Klocwork analysis. It's important that the build specification is an accurate and up-to-date representation of your build. If the build specification is inaccurate, the Klocwork analysis will be inaccurate too. A build specification is required at both the integration and local build levels.
You can analyze Klocwork Java projects from one or more build specification files based on the information in your build files. You can use the following automation tools to build your Java projects:
The Klocwork build specification for Java projects is a semi-colon-separated text file containing the following information about the source code that will comprise your Klocwork project:
Prerequisites Before you can create a build specification
Using kwgradle to create a Java build specificationTo create a build specification with kwgradle:
Continue to Checking your build specification file. Using kwgradlew to create a Java build specificationTo create a build specification with kwgradlew:
Continue to Checking your build specification file. Using kwmaven to create a build specificationTo create a build specification with kwmaven:
Continue to Checking your build specification file. Using kwant to create a Java build specificationTo create a build specification with kwant:
Continue to Checking your build specification file. Manual integration -- editing the Ant build fileEditing the Ant build.xml file allows you to generate a build specification with greater control over all stages of the build. In this case, you add the exec-listener task to your Ant build file, which will use the Klocwork Ant build listener (KwAntListener) to produce a build file. To edit the Ant build file and produce a build specification:
Example <project name="MyProject" default="dist" basedir="."> <!-- Insert the following code --> <property name="kwout" location="kwant.out"/> <property name="rep.inst" location="full path to the installation directory"/> <!-- Included for integration builds --> <property name="buildspecUpdate" value="true"/> <taskdef name="exec-listener" classname="com.klocwork.kwant.KwAntListener"> <classpath> <pathelement location="${rep.inst}\class\kwant.jar"/> <pathelement location="${rep.inst}\class\buildspec.jar"/> <pathelement location="${rep.inst}\class\kwutils.jar"/> <pathelement location="${rep.inst}\class\log4j.jar"/> <pathelement location="${rep.inst}\class\jdom.jar"/> <pathelement location="${rep.inst}\class\commons-io-1.4.jar"/> <pathelement location="${rep.inst}\class\datautils.jar"/> <pathelement location="${rep.inst}\class\buildutils.jar"/> </classpath> </taskdef> <exec-listener/> </project> The output file is saved to the specified location. You can now use the build specification to build the project. When running in incremental mode (the buildspecUpdate property is set to true), manual integration will only pick up compiled files at build time. Any previously compiled files won't be added to the build specification for analysis. To get those files, you must recompile your project (for example: ant clean build). Build specifications for projects that contain .jsp filesFor a project that contains .jsp files, you create two build specifications:
You then use both build specifications when you run a Klocwork analysis on the project. Checking your build specification fileOpen the build specification you just created and confirm the existence of jconfig and jcompile lines. For more details on the format of this file, see Build specification file format . If the jconfig and jcompile lines are present, you are ready to move to the next step: Running the Java integration build analysis. If your build specification file doesn't contain jconfig or jcompile lines, here are a few things you can try:
When to update your build specificationYou need to update or create a new build specification in the following situations:
If you reuse an existing build specification or try to modify it manually in these situations, the analysis results will not be accurate. Note: If you have done a clean build (full rebuild of your source files), we recommend that you create a new build specification and perform a full build analysis. See Running a full build analysis.
What's next?
|