• 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
  • Bundle-Activator CLASS
    Header

    The Bundle-Activator header specifies the name of the class used to start and stop the bundle

    private void verifyActivator() throws Exception {
    	String bactivator = main.get(Constants.BUNDLE_ACTIVATOR);
    	if (bactivator != null) {
    		TypeRef ref = analyzer.getTypeRefFromFQN(bactivator);
    		if (analyzer.getClassspace().containsKey(ref)) {
    			Clazz activatorClazz = analyzer.getClassspace().get(ref);
    			
    			if (activatorClazz.isInterface()) {
    				registerActivatorErrorLocation(error("The Bundle Activator " + bactivator + 
    						" is an interface and therefore cannot be instantiated."),
    						bactivator, ActivatorErrorType.IS_INTERFACE);
    			} else {
    				if(activatorClazz.isAbstract()) {
    					registerActivatorErrorLocation(error("The Bundle Activator " + bactivator + 
    							" is abstract and therefore cannot be instantiated."),
    							bactivator, ActivatorErrorType.IS_ABSTRACT);
    				}
    				if(!activatorClazz.isPublic()) {
    					registerActivatorErrorLocation(error("Bundle Activator classes must be public, and " + 
    							bactivator + " is not."), bactivator, ActivatorErrorType.NOT_PUBLIC);
    				}
    				if(!activatorClazz.hasPublicNoArgsConstructor()) {
    					registerActivatorErrorLocation(error("Bundle Activator classes must have a public zero-argument constructor and " + 
    							bactivator + " does not."), bactivator, ActivatorErrorType.NO_SUITABLE_CONSTRUCTOR);
    				}
    
    				if (!activatorClazz.is(QUERY.IMPLEMENTS, 
    						new Instruction("org.osgi.framework.BundleActivator"), analyzer)) {
    					registerActivatorErrorLocation(error("The Bundle Activator " + bactivator + 
    							" does not implement BundleActivator."), bactivator, ActivatorErrorType.NOT_AN_ACTIVATOR);
    				}
    			}
    			return;
    		}
    
    		PackageRef packageRef = ref.getPackageRef();
    		if (packageRef.isDefaultPackage())
    			registerActivatorErrorLocation(error("The Bundle Activator is not in the bundle and it is in the default package "),
    					bactivator, ActivatorErrorType.DEFAULT_PACKAGE);
    		else if (!analyzer.isImported(packageRef)) {
    			registerActivatorErrorLocation(error(Constants.BUNDLE_ACTIVATOR + 
    					" not found on the bundle class path nor in imports: " + bactivator),
    					bactivator, ActivatorErrorType.NOT_ACCESSIBLE);
    		} else {
    			registerActivatorErrorLocation(warning(Constants.BUNDLE_ACTIVATOR + " " + bactivator + 
    					" is being imported into the bundle rather than being contained inside it. This is usually a bundle packaging error"),
    					bactivator, ActivatorErrorType.IS_IMPORTED);
    		}
    	}
    }
    
    
    
    
    			String s = getProperty(BUNDLE_ACTIVATOR);
    		if (s != null) {
    			activator = getTypeRefFromFQN(s);
    			referTo(activator);
    			trace("activator %s %s", s, activator);
    		}
    
Search
    • Home