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";
String targetDir = device.getBaseDir() + File.separatorChar + "source";
	protected 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);			this.environment.addVariable("polish.sourcedir", targetDir);			notifyPolishBuildListeners( PolishBuildListener.EVENT_PREPROCESS_SOURCE_DIR, new File( targetDir ) );			// initialise the preprocessor (other initialisation is done in the initialized() method):			this.preprocessor.setTargetDir( targetDir );			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();				}				// load localized messages, this also sets localized variables automatically:				translationManager = this.resourceManager.getTranslationManager(device, locale );				this.translationPreprocessor.setTranslationManager( translationManager );				lastLocaleModification = translationManager.getLastModificationTime();			}			BooleanEvaluator evaluator = this.environment.getBooleanEvaluator();			Project antProject = getProject();			// 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, antProject ) ) {					this.preprocessor.addCustomPreprocessor( processor );				}			}			// add autostart preprocessors:			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 );			}						// 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, locale, device, usePolishGui, targetDir, buildXmlLastModified, lastCssModification, false);				}			} // for each source folder			this.preprocessor.notifyPolishPackageStart();			// now process the J2ME package files:			processSourceDir(this.polishSourceDir, this.polishSourceFiles, locale, 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 = this.lastRunFailed					|| (!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;					String cssConverterClassName = this.environment.getVariable( "polish.classes.CssConverter" );					if ( cssConverterClassName != null ) { 						try {							cssConverter = (CssConverter) Class.forName( cssConverterClassName ).newInstance();							System.out.println("Using CSS Converter [" + cssConverterClassName + "]...");						} catch (Exception e) {							e.printStackTrace();							throw new BuildException("Unable to initialize CSS converter [" + cssConverterClassName + "]: " + e.toString(), e );						}					} else {						// use default CSS converter						cssConverter = new CssConverter();					}					cssConverter.setAttributesManager( this.cssAttributesManager );										this.styleSheetCode.reset();					cssConverter.convertStyleSheet(this.styleSheetCode, 							this.preprocessor.getStyleSheet(),							device,							this.preprocessor,							this.environment ); 									//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:										translationManager.processLocaleCode( 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) {			throw e;//		} catch (Exception e) {//			e.printStackTrace();//			throw new BuildException( e.getMessage() );		}	}