this.polishProject.addDirectCapability( var ); }
if (var.hasCondition()) { conditionalVarsList.add( var ); } else { this.polishProject.addDirectCapability( var ); } } this.conditionalVariables = (Variable[]) conditionalVarsList.toArray( new Variable[ conditionalVarsList.size() ]);
	private void initProject() {		// create debug manager:		boolean isDebugEnabled = this.buildSetting.isDebugEnabled(); 		DebugManager debugManager = null;		if (isDebugEnabled) {			try {				debugManager = new DebugManager( this.buildSetting.getDebugSetting() );			} catch (BuildException e) {				throw new BuildException( e.getMessage(), e );			}		}		// create project settings:		this.polishProject = new PolishProject( this.buildSetting.usesPolishGui(), isDebugEnabled, debugManager );		if (debugManager != null && debugManager.isVerbose()) {			this.polishProject.addFeature("debugVerbose");		}		if (debugManager != null && this.buildSetting.getDebugSetting().showLogOnError()) {			this.polishProject.addFeature("showLogOnError");		}		this.polishProject.addCapability("license", this.infoSetting.getlicense() );		if (isDebugEnabled) {			this.polishProject.addFeature("debugEnabled");		}		// add some specified features:		this.polishProject.addFeature(this.buildSetting.getImageLoadStrategy());		if (debugManager != null && this.buildSetting.getDebugSetting().useGui()) {			this.polishProject.addFeature("useDebugGui");		}		FullScreenSetting fullScreenSetting = this.buildSetting.getFullScreenSetting();		if (fullScreenSetting != null) {			if (fullScreenSetting.isMenu()) {				this.polishProject.addFeature("useMenuFullScreen");				this.polishProject.addFeature("useFullScreen");			} else if (fullScreenSetting.isEnabled()) {				this.polishProject.addFeature("useFullScreen");			}		}		// add all ant properties if desired: 		if (this.buildSetting.includeAntProperties()) {			Hashtable antProperties = this.project.getProperties();			Set keySet = antProperties.keySet();			for (Iterator iter = keySet.iterator(); iter.hasNext();) {				String key = (String) iter.next();				this.polishProject.addDirectCapability( key, (String) antProperties.get(key) );			}		}		// add all variables from the build.xml:		Variable[] variables = this.buildSetting.getVariables();		if (variables != null) {			for (int i = 0; i < variables.length; i++) {				Variable var = variables[i];				//System.out.println("adding variable [" + var.getName() + "]." );				this.polishProject.addDirectCapability( var );			}		}		// add all symbols from the build.xml:		String symbolDefinition = this.buildSetting.getSymbols();		if (symbolDefinition != null) {			String[] symbols = TextUtil.splitAndTrim( symbolDefinition, ',' );			for (int i = 0; i < symbols.length; i++) {				this.polishProject.addDirectFeature( symbols[i] );			}		}				// create LibraryManager:		try {			this.libraryManager = new LibraryManager( this.project.getProperties(), this.buildSetting.getApiDir().getAbsolutePath(), this.wtkHome, this.buildSetting.getPreverify().getAbsolutePath(), this.buildSetting.openApis() );		} catch (JDOMException e) {			throw new BuildException("unable to create api manager: " + e.getMessage(), e );		} catch (IOException e) {			throw new BuildException("unable to create api manager: " + e.getMessage(), e );		} catch (InvalidComponentException e) {			throw new BuildException("unable to create api manager: " + e.getMessage(), e );		}		// create vendor/group/device manager:		try {			VendorManager vendorManager = new VendorManager( this.polishProject, this.buildSetting.getVendors());			DeviceGroupManager groupManager = new DeviceGroupManager( this.buildSetting.getGroups() ); 			this.deviceManager = new DeviceManager( vendorManager, groupManager, this.libraryManager, this.buildSetting.getDevices() );		} catch (JDOMException e) {			throw new BuildException("unable to create device manager: " + e.getMessage(), e );		} catch (IOException e) {			throw new BuildException("unable to create device manager: " + e.getMessage(), e );		} catch (InvalidComponentException e) {			throw new BuildException("unable to create device manager: " + e.getMessage(), e );		}				// create preprocessor:		this.preprocessor = new Preprocessor( this.polishProject, null, null, null, false, true, null );		// init line processors:		PreprocessorSetting[] settings = this.buildSetting.getPreprocessors();		CustomProcessor[] processors = new CustomProcessor[ settings.length + 1];		// add the default line processor:		CustomProcessor lineProcessor = new PolishProcessor();		lineProcessor.init(this.preprocessor);		processors[0] = lineProcessor;		for (int i = 0; i < settings.length; i++) {			PreprocessorSetting setting = settings[i];			processors[ i + 1] = CustomProcessor.getInstance(setting, this.preprocessor, this.project );		}		this.preprocessor.setLineProcessors( processors );				//	initialise the preprocessing-source-directories:		DirectoryScanner dirScanner = new DirectoryScanner();		dirScanner.setIncludes( new String[]{"**/*.java"} );		File[] dirs = this.buildSetting.getSourceDirs();		this.sourceDirs = new File[ dirs.length];		this.sourceFiles = new TextFile[ dirs.length][];		if (this.buildSetting.getPolishDir() != null) {			// there is an explicit J2ME Polish directory:			this.polishSourceDir = this.buildSetting.getPolishDir();			dirScanner.setBasedir(this.polishSourceDir);			dirScanner.scan();			this.polishSourceFiles = getTextFiles( this.polishSourceDir,  dirScanner.getIncludedFiles() );		} else {			// the J2ME Polish sources need to be loaded from the jar-file:			long lastModificationTime = 0;			File jarFile = new File( this.buildSetting.getApiDir().getAbsolutePath() 					+ File.separator + "enough-j2mepolish-build.jar");			if (jarFile.exists()) {				lastModificationTime = jarFile.lastModified();			} else {				jarFile = new File("import/enough-j2mepolish-build.jar");				if (jarFile.exists()) {					lastModificationTime = jarFile.lastModified();				}			}			this.polishSourceDir = new File("src");			try {				String[] fileNames = this.resourceUtil.readTextFile( ".", "build/j2mepolish.index.txt");				this.polishSourceFiles = getTextFiles( "src", fileNames, lastModificationTime );			} catch (IOException e) {				throw new BuildException("Unable to load the J2ME source files from enough-j2mepolish-build.jar: " + e.getMessage(), e );			}		}		// load the normal source files:		for (int i = 0; i < dirs.length; i++) {			File dir = dirs[i];			if (!dir.exists()) {				throw new BuildException("The source-directory [" + dir.getAbsolutePath() + "] does not exist. Please check your settings in the [sourceDir] attribute of the <build> element.");			}			this.sourceDirs[i] = dir; 			dirScanner.setBasedir(dir);			dirScanner.scan();			this.sourceFiles[i] = getTextFiles( dir,  dirScanner.getIncludedFiles() );		}		if (this.buildSetting.usesPolishGui() && this.styleSheetFile == null) {			throw new BuildException("Did not find the file [StyleSheet.java] of the J2ME Polish GUI framework. Please adjust the [polishDir] attribute of the <build> element in the [build.xml] file. The [polishDir]-attribute should point to the directory which contains the J2ME Polish-Java-sources.");		}				// init boot class path:		this.midp1BootClassPath = new Path( this.project, this.buildSetting.getMidp1Path().getAbsolutePath());		this.midp2BootClassPath = new Path( this.project, this.buildSetting.getMidp2Path().getAbsolutePath());						// init obfuscator:		ObfuscatorSetting obfuscatorSetting = this.buildSetting.getObfuscatorSetting();		if ((obfuscatorSetting != null) && (obfuscatorSetting.isEnabled())) {			String[] keepClasses = obfuscatorSetting.getPreserveClassNames();			String[] midletClasses = this.buildSetting.getMidletClassNames();			this.preserveClasses = new String[ keepClasses.length + midletClasses.length ];			System.arraycopy( keepClasses, 0, this.preserveClasses, 0,  keepClasses.length );			System.arraycopy( midletClasses, 0, this.preserveClasses, keepClasses.length, midletClasses.length  );			this.obfuscator = Obfuscator.getInstance( obfuscatorSetting, this.project, this.buildSetting.getApiDir(), this.libraryManager );		}				// init import manager:		this.importConverter = new ImportConverter();				// init base style sheet:		if (this.buildSetting.usesPolishGui()) {			File cssFile = new File( this.buildSetting.getResDir().getAbsolutePath() + File.separatorChar + "polish.css");			if (!cssFile.exists()) {				log("Unable to find polish.css at [" + cssFile.getAbsolutePath() + "] - you should create this file when you want to make most of the J2ME Polish GUI.", Project.MSG_WARN );				this.styleSheet = new StyleSheet();			} else {				CssReader cssReader = new CssReader();				try {					cssReader.add(cssFile);				} catch (IOException e) {					throw new BuildException("Unable to load polish.css: " + e.getMessage(), e );				}				this.styleSheet = cssReader.getStyleSheet();			}		}				// set the names of the midlets:		this.midletClassesByName = new HashMap();		String[] midletClasses = this.buildSetting.getMidletClassNames();		for (int i = 0; i < midletClasses.length; i++) {			this.midletClassesByName.put( midletClasses[i], Boolean.TRUE );					}				//check if there has been an error at the last run:		this.errorLock = new File( this.buildSetting.getWorkDir().getAbsolutePath()				+ File.separator + "error.lock");		if (this.errorLock.exists()) {			this.lastRunFailed = true;		} else {			this.lastRunFailed = false;			try {				this.errorLock.createNewFile();			} catch (IOException e) {				System.err.println("Warning: unable to create temporary lock file: " + e.toString() );			}		}	}