• Intro Headers Instructions Macros Commands
Fork me on GitHub
    • Getting Started
      • How to install bnd
      • Guided Tour
      • Guided Tour Workspace & Projects
      • FAQ - Frequently Asked Questions
    • Concepts and Practices
      • Introduction
      • Concepts
      • Best practices
    • Build and Development
      • Project Setup
      • Generating JARs
      • Versioning
      • Baselining
      • Service Components
      • Metatype
      • Contracts
      • Bundle Annotations
      • Accessor Properties
      • SPI Annotations
    • Dependency and Launching
      • Resolving Dependencies
      • Launching
      • Startlevels
    • Testing
      • Testing
      • Testing with Launchpad
    • Packaging and Distribution
      • Packaging Applications
      • JPMS Libraries
      • Wrapping Libraries to OSGi Bundles
    • Documentation and Tools
      • Generating Documentation
      • Commands
      • For Developers
      • Templates for Workspaces
      • Tips for Windows users
      • Tools bound to bnd
    • Reference Material
      • Reference
      • Headers
      • Instruction Reference
      • Instruction Index
      • Macro Reference
      • Macro Index
      • Plugins
      • External Plugins
    • Configuration and Troubleshooting
      • Settings
      • Errors
      • Warnings
  • if ';' STRING ';' STRING ( ';' STRING )?
    Macro

    Conditional macro that depending on a condition returns either a value for true or optionally for false.

    if         ::= 'if' ';' condition ';' expansion ( ';' expansion )?
    condition  ::= true | false
    false      ::= 'false' | ''
    true       ::= ! false
    expansion  ::= ...
    

    The ${if} macro allows a conditional expansion. The first argument is the condition. the condition is either false (empty or ‘false’) or otherwise true. If the condition is true, the value of the macro is the second argument, the first expansion. Otherwise, if a third argument is specified this is returned. If no third argument is specified, an empty string is returned.

    Notice that if a macro is not set, it will revert to its literal value. This can be confusing. For example, if the macro foo is not set, the ${if;${foo};TRUE;FALSE} will be TRUE. If you want to handle unset as false, the def might be of use.

    Examples

    # expands to 'B'
    aorb = ${if;;A;B}
    
    # Display ${foo} if set to a non-empty string that is not false, otherwise 'Ouch'. See also ${def} 
    whatisfoo = ${if;${foo};${foo};Ouch}
    
    # Include a file conditionally. If ${test} is not empty or false, the file is included
    -include ${if;${test};test.bnd}
    
Search
    • Home