if (setting == null || setting.isActive( evaluator, getProject() ) ) { this.preprocessor.addCustomPreprocessor(processor); }
if (setting == null || setting.isActive( evaluator, antProject ) ) { this.preprocessor.addCustomPreprocessor( processor ); } }  Extension[] autoStartPreprocessors = this.extensionManager.getAutoStartExtensions( ExtensionManager.TYPE_PREPROCESSOR, device, locale, this.environment ); for (int i = 0; i < autoStartPreprocessors.length; i++) { Extension extension = autoStartPreprocessors[i]; this.preprocessor.addCustomPreprocessor( (CustomPreprocessor) extension );
	private void preprocess( Device device, Locale locale ) {		System.out.println("preprocessing for device [" +  device.getIdentifier() + "]." );		try {			this.numberOfChangedFiles = 0;			String deviceSpecificBuildPath = File.separatorChar + device.getVendorName() 											+ File.separatorChar + device.getName();			deviceSpecificBuildPath = deviceSpecificBuildPath.replace(' ', '_' );			String targetDir = this.buildSetting.getWorkDir().getAbsolutePath() + deviceSpecificBuildPath;			if (locale != null) {				targetDir += File.separatorChar + locale.toString();			}			device.setBaseDir( targetDir );			targetDir += File.separatorChar + "source";			device.setSourceDir(targetDir);			// initialise the preprocessor:			this.preprocessor.setTargetDir( targetDir );			// set variables and symbols:			/*			this.preprocessor.setSymbols( device.getFeatures() );			this.preprocessor.setVariables( device.getCapabilities() );			this.preprocessor.addVariable( "polish.identifier", device.getIdentifier() );			this.preprocessor.addVariable( "polish.name", device.getName() );			this.preprocessor.addVariable( "polish.vendor", device.getVendorName() );			this.preprocessor.addVariable( "polish.version", this.infoSetting.getVersion() );			if (this.useDefaultPackage) {				this.preprocessor.addSymbol("polish.useDefaultPackage");				this.preprocessor.addVariable("polish.useDefaultPackage", "true");			}			*/			long lastLocaleModification = 0;			TranslationManager translationManager = null;			// set localization-variables:			if (locale != null || (this.localizationSetting != null && this.localizationSetting.isDynamic())) {				if (locale == null) {					locale = this.localizationSetting.getDefaultLocale();					//this.preprocessor.addSymbol("polish.i18n.useDynamicTranslations");				}				/*				this.preprocessor.addVariable("polish.locale", locale.toString() );				this.preprocessor.addVariable("polish.language", locale.getLanguage() );				String country = locale.getCountry();				if ( country == null || country.length() == 0 ) {					this.preprocessor.removeVariable( "polish.country" );				} else {					this.preprocessor.addVariable("polish.country", country );				}				*/				// load localized messages, this also sets localized variables automatically:				translationManager = this.resourceManager.getTranslationManager(device, locale );				this.translationPreprocessor.setTranslationManager( translationManager );				lastLocaleModification = translationManager.getLastModificationTime();			}			// set info-variables:			/*			String jarName = this.infoSetting.getJarName();			jarName = PropertyUtil.writeProperties(jarName, this.preprocessor.getVariables());			this.preprocessor.addVariable( "polish.jarName", jarName );			String jarPath = this.buildSetting.getDestDir().getAbsolutePath() + File.separator + jarName;			this.preprocessor.addVariable( "polish.jarPath", jarPath );			String jadName = jarName.substring(0, jarName.lastIndexOf('.') ) + ".jad";			this.preprocessor.addVariable( "polish.jadName", jadName );			String jadPath = this.buildSetting.getDestDir().getAbsolutePath() + File.separator + jadName;			this.preprocessor.addVariable( "polish.jadPath", jadPath );			// set conditional variables:			BooleanEvaluator evaluator = this.preprocessor.getBooleanEvaluator();			Project antProject = getProject();			Variable[] vars = this.variables.getVariables( antProject, evaluator, this.environment );			for (int i = 0; i < vars.length; i++) {				Variable var = vars[i];				this.preprocessor.addVariable(var.getName(), var.getValue() );			}			*/			/*			if (this.conditionalVariables != null) {				// add variables which fulfill the conditions: 				BooleanEvaluator evaluator = this.preprocessor.getBooleanEvaluator();				for (int i = 0; i < this.conditionalVariables.length; i++) {					Variable var = this.conditionalVariables[i];					if (var.isConditionFulfilled( evaluator, getProject() )) {						this.preprocessor.addVariable(var.getName(), var.getValue() );					}				}			}			*/			// now set the full-screen-settings:			/*			String value = this.preprocessor.getVariable("polish.FullScreen");			if (value != null) {				if ("menu".equalsIgnoreCase(value)) {					this.preprocessor.addSymbol("polish.useMenuFullScreen");					this.preprocessor.addSymbol("polish.useFullScreen");									} else if ("yes".equalsIgnoreCase( value ) || "true".equalsIgnoreCase(value)) {					this.preprocessor.addSymbol("polish.useFullScreen");									}			} else {				FullScreenSetting fullScreenSetting = this.buildSetting.getFullScreenSetting();				if (fullScreenSetting != null) {					if (fullScreenSetting.isMenu()) {						this.preprocessor.addSymbol("polish.useMenuFullScreen");						this.preprocessor.addSymbol("polish.useFullScreen");					} else if (fullScreenSetting.isEnabled()) {						this.preprocessor.addSymbol("polish.useFullScreen");					}				}			}			// adjust polish.classes.ImageLoader in case the default package is used:			if (this.useDefaultPackage) {				String imageLoaderClass = this.preprocessor.getVariable("polish.classes.ImageLoader");				if (imageLoaderClass != null) {					int classStartIndex = imageLoaderClass.lastIndexOf('.');					if (classStartIndex != -1) {						imageLoaderClass = imageLoaderClass.substring( classStartIndex + 1 );						this.preprocessor.addVariable("polish.classes.ImageLoader", imageLoaderClass );					}				}			}			// add settings of active postcompilers:			// let postcompilers adjust the bootclasspath:			if (this.doPostCompile) {				PostCompiler[] compilers = getActivePostCompilers();				for (int i = 0; i < compilers.length; i++) {					PostCompiler postCompiler = compilers[i];					postCompiler.addPreprocessingSettings(device, this.preprocessor);				}			}			*/			BooleanEvaluator evaluator = this.environment.getBooleanEvaluator();			// add custom preprocessors			CustomPreprocessor[] preprocessors = (CustomPreprocessor[]) this.customPreprocessors.toArray( new CustomPreprocessor[ this.customPreprocessors.size() ] );			this.preprocessor.clearCustomPreprocessors();			for (int i = 0; i < preprocessors.length; i++) {				CustomPreprocessor processor = preprocessors[i];				PreprocessorSetting setting = processor.getSetting();				if (setting == null || setting.isActive( evaluator, getProject() ) ) {					this.preprocessor.addCustomPreprocessor(processor);				}			}						// get the last modfication time of the build.xml file			// so that it can be checked whether there are any changes at all:			File buildXml = new File( getProject().getBaseDir().getAbsolutePath() 						+ File.separatorChar + "build.xml" );			long buildXmlLastModified = buildXml.lastModified();			// check if the polish gui is used at all:			boolean usePolishGui = this.environment.hasSymbol("polish.usePolishGui");			//this.preprocessor.setUsePolishGui(usePolishGui);			long lastCssModification = lastLocaleModification;			StyleSheet cssStyleSheet = null;			if (usePolishGui) {				cssStyleSheet = this.resourceManager.loadStyleSheet( this.styleSheet, device, locale );				if (cssStyleSheet.lastModified() > lastLocaleModification) {					lastCssModification = cssStyleSheet.lastModified();				}			}			this.preprocessor.setSyleSheet( cssStyleSheet, device );			this.preprocessor.notifyDevice(device, usePolishGui);			this.preprocessor.notifyLocale( locale );			// preprocess each source file:			for (int i = 0; i < this.sourceSettings.length; i++) {				SourceSetting setting = this.sourceSettings[i];				if (setting.isActive(evaluator, getProject())) {					File sourceDir = setting.getDir();					//System.out.println("Preprocessing source dir [" + sourceDir.getAbsolutePath() + "]");					TextFile[] files = this.sourceFiles[i];					processSourceDir(sourceDir, files, device, usePolishGui, targetDir, buildXmlLastModified, lastCssModification, false);				}			} // for each source folder			this.preprocessor.notifyPolishPackageStart();			// now process the J2ME package files:			processSourceDir(this.polishSourceDir, this.polishSourceFiles, device, usePolishGui, targetDir, buildXmlLastModified, lastCssModification, true);			// notify preprocessor about the end of preprocessing:			this.preprocessor.notifyDeviceEnd( device, usePolishGui );									// now all files have been preprocessed.			// Now the StyleSheet.java file needs to be written,			// but only when the polish GUI should be used:			File baseDirectory = new File( targetDir );			if (usePolishGui) {				// check if the CSS declarations have changed since the last run:				File targetFile =  this.styleSheetSourceFile.getTargetFile( baseDirectory, this.useDefaultPackage );					//new File( targetDir + File.separatorChar + this.styleSheetSourceFile.getFilePath() );								boolean cssIsNew = (!targetFile.exists())					|| ( lastCssModification > targetFile.lastModified() )					|| ( buildXmlLastModified > targetFile.lastModified() );				if (cssIsNew) {					//System.out.println("CSS is new and the style sheet will be generated.");					if (this.styleSheetCode == null) {						// the style sheet has not been preprocessed:						this.styleSheetCode = new StringList( this.styleSheetSourceFile.getContent() );						String className = "de.enough.polish.ui.StyleSheet";						this.preprocessor.preprocess( className, this.styleSheetCode );					}					// now insert the CSS information for this device					// into the StyleSheet.java source-code:					CssConverter cssConverter = new CssConverter( this.cssAttributesManager );					this.styleSheetCode.reset();					cssConverter.convertStyleSheet(this.styleSheetCode, 							this.preprocessor.getStyleSheet(),							device,							this.preprocessor ); 									//this.styleSheetSourceFile.saveToDir(targetDir, this.styleSheetCode.getArray(), false );					if (this.useDefaultPackage) {						this.styleSheetCode.reset();						this.importConverter.processImports(true, device.isMidp1(), this.styleSheetCode, device, this.preprocessor);						this.styleSheetCode.reset();						this.importConverter.removeDirectPackages( this.styleSheetCode, this.preprocessor.getTextFileManager() );					}					FileUtil.writeTextFile(targetFile, this.styleSheetCode.getArray());					this.numberOfChangedFiles++;				//} else {				//	System.out.println("CSSS is not new - last CSS modification == " + lastCssModification + " <= StyleSheet.java.lastModified() == " + targetFile.lastModified() );				}							}			// now check if the de.enough.polish.util.Locale.java needs to be rewritten:			if (locale != null) {				File targetFile =  this.localeSourceFile.getTargetFile( baseDirectory, this.useDefaultPackage );				//File targetFile = new File( targetDir + File.separatorChar + this.localeSourceFile.getFilePath() );								boolean localizationIsNew = (!targetFile.exists())					|| ( lastLocaleModification > targetFile.lastModified() )					|| ( buildXmlLastModified > targetFile.lastModified() );				if (localizationIsNew) {					//System.out.println("Localization is new and the Locale.java will be generated.");					if (this.localeCode == null) {						// the style sheet has not been preprocessed:						this.localeCode = new StringList( this.localeSourceFile.getContent() );						String className = "de.enough.polish.util.Locale";						this.preprocessor.preprocess( className, this.localeCode );					}										// now insert the localozation data for this device					// into the Locale.java source-code:					if (!translationManager.isDynamic()) {						translationManager.processLocaleCode( this.localeCode );						//this.localeSourceFile.saveToDir(targetDir, this.localeCode.getArray(), false );					} else {						translationManager.insertDynamicFields( this.localeCode );					}					if (this.useDefaultPackage) {						this.localeCode.reset();						this.importConverter.processImports(true, device.isMidp1(), this.localeCode, device, this.preprocessor);					}					FileUtil.writeTextFile(targetFile, this.localeCode.getArray());					this.numberOfChangedFiles++;				}			}			device.setNumberOfChangedFiles( this.numberOfChangedFiles );		} catch (FileNotFoundException e) {			e.printStackTrace();			throw new BuildException( e.getMessage() );		} catch (IOException e) {			e.printStackTrace();			throw new BuildException( e.getMessage() );		} catch (BuildException e) {			e.printStackTrace();			throw new BuildException( e.getMessage() );		}	}