Introduction to Software Build Technology


Published on

Published in: Technology
  • Be the first to comment

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Introduction to Software Build Technology

  1. 1. Introduction to Software Build Technology Philip Johnson Collaborative Software Development Laboratory Information and Computer Sciences University of Hawaii Honolulu HI 96822
  2. 2. Objectives <ul><li>Understand motivation for build and packaging technologies. </li></ul><ul><ul><li>Why was running your classmate ’s Robocode robot so hard? </li></ul></ul><ul><li>Become familiar with a sample of build technologies. </li></ul><ul><li>Get introduced to the build technologies and standards to be used in this class. </li></ul>
  3. 3. Motivation <ul><li>Modern team-based, cross-platform development involves: </li></ul><ul><ul><li>Multiple developers and users. </li></ul></ul><ul><ul><li>System is developed/used on multiple platforms: </li></ul></ul><ul><ul><ul><li>Win2K, Linux, Win98, Solaris </li></ul></ul></ul><ul><ul><li>Developers/users have different environments: </li></ul></ul><ul><ul><ul><li>c:jdk1.5.0_08, d:jdk1.5, c:myjava </li></ul></ul></ul><ul><ul><li>Differences between user and developer distributions: </li></ul></ul><ul><ul><ul><li>Source distribution for developers </li></ul></ul></ul><ul><ul><ul><li>Binary distribution for users </li></ul></ul></ul><ul><ul><li>Developers may prefer different IDEs: </li></ul></ul><ul><ul><ul><li>Eclipse, JBuilder, Emacs, RationalRose </li></ul></ul></ul><ul><ul><li>Users may not have any IDE at all. </li></ul></ul><ul><ul><li>Frequent releases and distributions. </li></ul></ul><ul><ul><li>Dependence on third party libraries (which may themselves be released frequently). </li></ul></ul><ul><li>These issues are not unique to Java development! </li></ul>
  4. 4. Motivation (cont.) <ul><li>Build/packaging techniques should allow: </li></ul><ul><ul><li>Users to build and test the system without IDE. </li></ul></ul><ul><ul><li>Developers to build and test the system using their IDE of choice. </li></ul></ul><ul><ul><li>Developers to build and test the way users build and test. </li></ul></ul><ul><ul><li>Configuration to different platforms and different environments within a platform. </li></ul></ul><ul><ul><li>Multiple release configurations </li></ul></ul><ul><ul><li>Automated build to prevent errors </li></ul></ul><ul><ul><li>Rapid release, deployment, testing </li></ul></ul><ul><ul><li>Simplified installation and updating of third-party libraries </li></ul></ul><ul><li>Our (Java-specific) solution: </li></ul><ul><ul><li>Ant </li></ul></ul><ul><ul><li>Ivy </li></ul></ul><ul><ul><li>Build/packaging standards </li></ul></ul>
  5. 5. A quick tour of build tools
  6. 7. Make <ul><li>‘ Make’ is the canonical build tool. </li></ul><ul><li>Make features: </li></ul><ul><ul><li>File-level dependency analysis </li></ul></ul><ul><ul><ul><li>Example: compile only changed files </li></ul></ul></ul><ul><ul><li>Unix-based (but ported to other platforms) </li></ul></ul><ul><ul><li>Language independent (Java, C++, etc.) </li></ul></ul><ul><ul><li>ASCII configuration file syntax </li></ul></ul><ul><ul><ul><li>Tab characters required—Yikes! </li></ul></ul></ul><ul><ul><li>Supports invocation of any shell command. </li></ul></ul><ul><ul><li>Does not support library-level dependency management. </li></ul></ul><ul><ul><li>Related: imake, cmake, scons </li></ul></ul>
  7. 9. Ant <ul><li>Java-based build tool by Apache </li></ul><ul><ul><li> </li></ul></ul><ul><li>Features: </li></ul><ul><ul><li>Java-based </li></ul></ul><ul><ul><li>Cross-platform </li></ul></ul><ul><ul><li>Extensible </li></ul></ul><ul><ul><li>XML configuration files </li></ul></ul><ul><ul><li>Open source </li></ul></ul><ul><ul><li>Defacto standard for Java projects </li></ul></ul><ul><ul><ul><li>Maven is making headway. </li></ul></ul></ul><ul><ul><li>File-level, but not library-level dependency management. </li></ul></ul>
  8. 10. Ant vs. Make <ul><li>Advantages of Make (and related tools): </li></ul><ul><ul><li>More popular and widespread </li></ul></ul><ul><ul><li>Supports any programming language. </li></ul></ul><ul><ul><li>Provides ‘glue’ for invoking any shell command. </li></ul></ul><ul><li>Advantages of Ant: </li></ul><ul><ul><li>Java-based, active development community </li></ul></ul><ul><ul><li>Built-in support for Java and its tools. </li></ul></ul><ul><ul><li>build.xml simpler and easier than Makefile. </li></ul></ul><ul><ul><li>Simplifies cross-platform Java development </li></ul></ul><ul><ul><li>Easier to extend in a portable manner. </li></ul></ul><ul><li>Current recommendation: </li></ul><ul><ul><li>Always use Ant over Make for Java-based development </li></ul></ul><ul><ul><li>Use Make for other development, at least for now. </li></ul></ul>
  9. 12. Maven <ul><li>“ Project Management” technology </li></ul><ul><ul><li>Build based on Ant. </li></ul></ul><ul><ul><li>Documentation and reporting plugins. </li></ul></ul><ul><ul><li>File-level dependency management </li></ul></ul><ul><ul><li>Library-level dependency management </li></ul></ul><ul><ul><li>Library repository definition & management </li></ul></ul><ul><li>“ Convention over configuration” </li></ul><ul><ul><li>Maven builds in conventions for project layout and workflow to simplify use. </li></ul></ul><ul><ul><ul><li>Great if you like them. </li></ul></ul></ul>
  10. 14. Ivy <ul><li>A “standalone” library-level dependency management tool. </li></ul><ul><li>Ant + Ivy = </li></ul><ul><ul><li>Much of what Maven offers. </li></ul></ul><ul><ul><ul><li>No built-in reporting/documentation </li></ul></ul></ul><ul><ul><li>Without Maven “conventions”. </li></ul></ul><ul><ul><li>Better representations for dependencies </li></ul></ul><ul><ul><ul><li>configurations </li></ul></ul></ul>
  11. 15. Ant+Ivy vs. Maven <ul><li>Very strong feelings on both sides. </li></ul><ul><li>Maven advocates: </li></ul><ul><ul><li>Maven is the future; deal with it. </li></ul></ul><ul><li>Ant+Ivy advocates: </li></ul><ul><ul><li>Maven is a black box; customization is much harder than Mavenites portray. </li></ul></ul><ul><li>My opinion: </li></ul><ul><ul><li>If you can live with Maven conventions, it provides more built-in functionality. </li></ul></ul>
  12. 16. Our approach <ul><li>We will use Ant+Ivy </li></ul><ul><ul><li>Ant is still more popular than Maven, so it is useful for you to gain experience with it. </li></ul></ul><ul><ul><li>Moving from Ant+Ivy -> Maven should not be too bad. </li></ul></ul><ul><li>You will also learn some “best practices” for Ant-based projects. </li></ul><ul><ul><li>Support for useful third party tools. </li></ul></ul><ul><ul><li>Ivy-based library-level dependency management. </li></ul></ul>
  13. 17. Basic Ant concepts <ul><li>Every project requires an Ant build file </li></ul><ul><ul><li>named build.xml by default. </li></ul></ul><ul><li>Each build file is composed of targets . </li></ul><ul><ul><li>Typical targets: compile, junit, etc. </li></ul></ul><ul><li>Each target is composed of tasks </li></ul><ul><ul><li>Ex: copy .java files to build/src, invoke javac... </li></ul></ul><ul><li>Targets can have dependencies </li></ul><ul><ul><li>Ex: modified sources must be recompiled before testing. </li></ul></ul>
  14. 18. Ant targets <ul><li>Dependent targets are executed exactly once. </li></ul><ul><ul><li>Example: </li></ul></ul><ul><ul><ul><li>test depends upon compile </li></ul></ul></ul><ul><ul><ul><li>deploy depends upon compile </li></ul></ul></ul><ul><ul><ul><li>all depends upon test, deploy </li></ul></ul></ul><ul><ul><li>Compile will be executed only once. </li></ul></ul><ul><li>Some targets are executed only when needed. </li></ul><ul><ul><li>Sources recompiled only if changed. </li></ul></ul>
  15. 19. Example Ant target <ul><li><target name=&quot;compile&quot; </li></ul><ul><li>depends= “init&quot; </li></ul><ul><li>description=&quot;Compiles code.&quot;> </li></ul><ul><li><javac srcdir=&quot;${src.dir}&quot; </li></ul><ul><li>destdir=&quot;${build.dir}/classes “/> </li></ul><ul><li></target> </li></ul>
  16. 20. Best practices <ul><li>Ant provides a simple, powerful language for building Java-based systems. </li></ul><ul><li>How do we use this language effectively? </li></ul><ul><li>The next section describes my best approach so far on how to employ Ant to achieve the Three Prime Directives of Open Source Software Engineering. </li></ul><ul><li>The “robocode-pmj-dacruzer” example project provides you with a template structure to get you off and running quickly. </li></ul>
  17. 21. robocode-pmj-dacruzer: An example Ant-based build system <ul><li>Implements a pretty lame Robocode robot. </li></ul><ul><ul><li>Not very interesting. </li></ul></ul><ul><li>It ’s the build system that’s interesting: </li></ul><ul><ul><li>Provides a template </li></ul></ul><ul><ul><ul><li>Easy to adapt to your own projects. </li></ul></ul></ul><ul><ul><li>Integrates third-party build tools </li></ul></ul><ul><ul><ul><li>Checkstyle, PMD, FindBugs, etc. </li></ul></ul></ul><ul><ul><li>Is modular and extensible </li></ul></ul><ul><ul><ul><li>You can grow or shrink it to your needs. </li></ul></ul></ul><ul><ul><li>Well suited to build automation and project hosting: </li></ul></ul><ul><ul><ul><li>Continuous integration (Hudson) </li></ul></ul></ul><ul><ul><li>Uses Ivy to download/install/manage third-party libraries. </li></ul></ul><ul><li>Result is Maven-ish, but without the “black box” </li></ul><ul><ul><li>If you want to change something, it ’s just Ant code. </li></ul></ul>
  18. 22. Top-level directory contents <ul><li>build.xml </li></ul><ul><ul><li>top-level build file. </li></ul></ul><ul><li>*.build.xml </li></ul><ul><ul><li>“ module” build files, generally one per tool. </li></ul></ul><ul><li>src/ </li></ul><ul><ul><li>the system source files </li></ul></ul><ul><li>lib/ </li></ul><ul><ul><li>library files: maintained by Ivy. </li></ul></ul><ul><li>build/ </li></ul><ul><ul><li>derived files: generated by build process </li></ul></ul>
  19. 23. Build operations <ul><li>compile </li></ul><ul><ul><li>compile system </li></ul></ul><ul><li>jar </li></ul><ul><ul><li>create jar file </li></ul></ul><ul><li>junit </li></ul><ul><ul><li>run junit tests </li></ul></ul><ul><li>javadoc </li></ul><ul><ul><li>build javadoc docs </li></ul></ul><ul><li>clean </li></ul><ul><ul><li>delete build dir. </li></ul></ul><ul><li>dist </li></ul><ul><ul><li>create zip dist file. </li></ul></ul><ul><li>checkstyle </li></ul><ul><ul><li>analyze source code </li></ul></ul><ul><li>findbugs </li></ul><ul><ul><li>analyze byte code </li></ul></ul><ul><li>pmd </li></ul><ul><ul><li>analyze source code </li></ul></ul><ul><li>sclc </li></ul><ul><ul><li>compute size of system </li></ul></ul><ul><li>jacoco </li></ul><ul><ul><li>compute coverage of test cases. </li></ul></ul><ul><li>(Others to be added later in semester!) </li></ul>
  20. 24. Build System Scalability Issues <ul><li>Modularity: </li></ul><ul><ul><li>putting all targets in one build.xml file creates a very large build.xml file that is difficult to understand and maintain. </li></ul></ul><ul><li>Incrementality: </li></ul><ul><ul><li>you may not want to require all developers to have to install every possible third party tool. </li></ul></ul><ul><li>Coupling: </li></ul><ul><ul><li>dependencies between target and property definitions should be minimal and easily visible. </li></ul></ul>
  21. 25. Build system architecture build.xml *.build.xml build.xml contains most project- specific definitions. *.build.xml files import the build.xml file and provide an implementation of a single extension. boilerplate code
  22. 26. build.xml <ul><li>build.xml provides most (but unfortunately not all) of the project-specific definitions: </li></ul><ul><ul><li>version number </li></ul></ul><ul><ul><li>dependency libraries </li></ul></ul><ul><ul><li>project name </li></ul></ul><ul><ul><li>etc. </li></ul></ul><ul><li>Most other *.build.xml files can be used with little to no changes. </li></ul><ul><ul><li>Typical exceptions:,, </li></ul></ul>
  23. 27. *.build.xml responsibilities <ul><li>Implements support for a single tool/function: </li></ul><ul><ul><li>Checkstyle, Jar, JavaDoc, PMD, Distribution, etc. </li></ul></ul><ul><li>Typical tasks (assume a tool called 'foo'): </li></ul><ul><ul><li>Download foo using Ivy, install in lib/foo </li></ul></ul><ul><ul><li>Download a configuration file for foo, store in lib/configfiles. </li></ul></ul><ul><ul><li>Provide three standard tasks: </li></ul></ul><ul><ul><ul><li>foo.tool: runs foo tool, generates data. </li></ul></ul></ul><ul><ul><ul><li> creates HTML file. </li></ul></ul></ul><ul><ul><ul><li>foo: runs foo.tool and </li></ul></ul></ul><ul><ul><li>Make 'foo' the default task. </li></ul></ul>
  24. 28. User Interface <ul><li>To do initial installation and compilation: </li></ul><ul><ul><li>ant </li></ul></ul><ul><li>For other operations, use -f <filename>: </li></ul><ul><ul><li>ant -f </li></ul></ul><ul><ul><li>ant -f </li></ul></ul><ul><ul><li>ant -f </li></ul></ul><ul><ul><li>ant -f </li></ul></ul><ul><ul><li>ant -f </li></ul></ul><ul><ul><li>etc. </li></ul></ul>
  25. 29. Considerations <ul><li>This approach provides the following: </li></ul><ul><ul><li>Minimal coupling: *.build.xml files depend only on definitions in build.xml </li></ul></ul><ul><ul><li>Modularity: individual *.build.xml files are small. </li></ul></ul><ul><ul><li>Reporting: &quot;report&quot; targets provide details on what the &quot;tool&quot; targets generated. </li></ul></ul><ul><li>One problem: </li></ul><ul><ul><li>How to &quot;verify&quot; that all analyses &quot;passed&quot;? </li></ul></ul>
  26. 30. <ul><li>Provides “one stop shop” for system analysis: </li></ul><ul><ul><li>Imports not just build.xml, but other *.build.xml files as well. </li></ul></ul><ul><ul><li>Runs all &quot;tool&quot; analyses, failing build if they generate any warnings/errors. </li></ul></ul><ul><ul><ul><li>Compile, Junit, PMD, Checkstyle, JavaDoc, FindBugs </li></ul></ul></ul><ul><li>User interface: </li></ul><ul><ul><li>ant -f </li></ul></ul>
  27. 31. The lib/ directory <ul><li>Contains third-party libraries required by project: </li></ul><ul><ul><li>robocode </li></ul></ul><ul><ul><li>checkstyle </li></ul></ul><ul><ul><li>pmd </li></ul></ul><ul><ul><li>findbugs </li></ul></ul><ul><ul><li>etc. </li></ul></ul><ul><li>Contains configuration files for analysis tools. </li></ul><ul><ul><li>lib/configfiles/checkstyle.modules.xml </li></ul></ul><ul><ul><li>lib/configfiles/pmd.rulesets.xml </li></ul></ul><ul><ul><li>lib/configfiles/findbugs.filter.xml </li></ul></ul>
  28. 32. The build/ directory <ul><li>Contains files derived from build process. </li></ul><ul><li>Can be deleted and reconstructed. </li></ul><ul><li>Not included in version control or distribution .zip. </li></ul><ul><li>Build subdirs: Targets creating them: </li></ul><ul><ul><li>build/javadoc/ javadoc </li></ul></ul><ul><ul><li>build/classes/ compile </li></ul></ul><ul><ul><li>build/dist/ dist </li></ul></ul><ul><ul><li>build/sclc/ size </li></ul></ul><ul><ul><li>build/junit/ junit </li></ul></ul>
  29. 33. build/ vs. bin/ <ul><li>Both Ant and Eclipse (or any other IDE) compiles files. </li></ul><ul><li>It causes problems if Ant and Eclipse are using the same output directories for compilation/etc. </li></ul><ul><li>Therefore, Eclipse writes to the bin/ directory, not the build/ directory. </li></ul><ul><ul><li>Set in Project | Properties | Java Build Path | Source </li></ul></ul>
  30. 34. Testing Notes <ul><li>There are two kinds of “tests” in this system: </li></ul><ul><ul><li>Manual QA using JUnit </li></ul></ul><ul><ul><ul><li>Ensures your code satisfies its specifications (if you write good test cases.) </li></ul></ul></ul><ul><ul><li>Automated QA using Checkstyle, FindBugs, PMD </li></ul></ul><ul><ul><ul><li>Ensures your code obeys best practices for coding style. </li></ul></ul></ul><ul><li>Encourages incremental testing and formatting. </li></ul>
  31. 35. Traditional release numbering <ul><li>Traditional approach (i.e. </li></ul><ul><ul><li>, where: </li></ul></ul><ul><ul><ul><li>MM = Major release number (major redesign or incompatible changes) </li></ul></ul></ul><ul><ul><ul><li>mm = Minor release number (minor enhancements, backward compatible) </li></ul></ul></ul><ul><ul><ul><li>bb = Bugfix release number (bug fix, no new functionality) </li></ul></ul></ul><ul><ul><li>All numbers maintained manually. </li></ul></ul><ul><li>Advantage: </li></ul><ul><ul><li>Release number comparison indicates degree of change. </li></ul></ul><ul><li>Disadvantage: </li></ul><ul><ul><li>Requires manual editing of release value every time which leads to errors (easy to forget to do this.) </li></ul></ul>
  32. 36. Our release numbering <ul><li>Our approach (i.e. </li></ul><ul><ul><li>Major.minor.timestamp, where: </li></ul></ul><ul><ul><ul><li>Major = major release number </li></ul></ul></ul><ul><ul><ul><li>Minor= minor release number </li></ul></ul></ul><ul><ul><ul><li>Timestamp= time of bugfix release ( </li></ul></ul></ul><ul><ul><li>Major and minor release number maintained manually. </li></ul></ul><ul><ul><li>Bugfix timestamp generated automatically. </li></ul></ul><ul><li>Advantages: </li></ul><ul><ul><li>Automatic except when incrementing major/minor release. </li></ul></ul><ul><ul><li>Release number provides timestamp of release. </li></ul></ul><ul><li>Disadvantages: </li></ul><ul><ul><li>Number of bugfix releases not indicated by release number. </li></ul></ul><ul><ul><li>Very long version number. </li></ul></ul>
  33. 37. IDE integration <ul><li>Important to maintain independence from IDE. </li></ul><ul><ul><li>All build functions should be possible without any IDE. </li></ul></ul><ul><li>But it ’s fine to provide IDE-specific files to facilitate development. </li></ul><ul><ul><li>Example: .class and .project files in top-level directory for Eclipse. </li></ul></ul><ul><li>Provide additional files/directories for other IDEs if desired. </li></ul>
  34. 38. robocode-pmj-dacruzer as a standard <ul><li>From now on, all projects must be developed, packaged, and submitted using the standard build conventions embodied in this package. </li></ul>
  35. 39. robocode-pmj-dacruzer as a template <ul><li>You can use robocode-pmj-dacruzer as a template for your own projects: </li></ul><ul><ul><li>Download a fresh version. </li></ul></ul><ul><ul><li>Remove dacruzer-specific info </li></ul></ul><ul><ul><li>Add your project info. </li></ul></ul><ul><li>See the template instruction page in the course website for step-by-step instructions. </li></ul>
  36. 40. Ant/Eclipse integration <ul><li>Eclipse has nice support for Ant, but: </li></ul><ul><ul><li>You will also need to tell Eclipse about ANT_HOME: </li></ul></ul><ul><ul><ul><li>Window | Preferences | Ant | Runtime | Ant Home… </li></ul></ul></ul><ul><ul><li>Make sure Eclipse writes to the bin/ directory </li></ul></ul><ul><ul><ul><li>Project | Properties | Java Build Path | Source </li></ul></ul></ul>
  37. 41. Limitations of example <ul><li>The robocode-pmj-dacruzer template provides a framework plus basic build functionality, but has limitations: </li></ul><ul><ul><li>No SVN integration </li></ul></ul><ul><ul><li>No support for web app development. </li></ul></ul><ul><ul><li>No support for automated metrics collection. </li></ul></ul><ul><li>We will enhance this initial template during the semester. </li></ul>
  38. 42. Meta-level goal <ul><li>Ant provides an efficient solution to satisfying both </li></ul><ul><ul><li>PD#2 (users can install system) and </li></ul></ul><ul><ul><li>PD#3 (developers can understand and enhance system) </li></ul></ul><ul><li>Other approaches exist: </li></ul><ul><ul><li>InstallAnywhere for PD#2 (more work) </li></ul></ul><ul><ul><li>IDE-specific solution for PD#3 (limited) </li></ul></ul><ul><li>With good installation documentation, I believe Ant-based build can satisfy both PD#2 and PD#3. </li></ul>