String deviceSpecificBuildPath = File.separatorChar + device.getVendorName() + File.separatorChar + device.getName(); deviceSpecificBuildPath = deviceSpecificBuildPath.replace(' ', '_' ); String buildPath = this.buildSetting.getWorkDir().getAbsolutePath() + deviceSpecificBuildPath; if (locale != null) { buildPath += File.separatorChar + locale.toString(); } device.setBaseDir( buildPath );
	public void initialize( Device device, Locale locale ) {		this.extensionManager.preInitialize(device, locale);		// intialise the environment		this.environment.initialize(device, locale);		device.setEnvironment( this.environment );		// set variables and symbols:		//this.environment.setSymbols( device.getFeatures() );		//this.environment.setVariables( device.getCapabilities() );		this.environment.addVariable( "polish.identifier", device.getIdentifier() );		this.environment.addVariable( "polish.name", device.getName() );		this.environment.addVariable( "polish.vendor", device.getVendorName() );		this.environment.addVariable( "polish.version", this.infoSetting.getVersion() );		// set localization-variables:		if (locale != null || (this.localizationSetting != null && this.localizationSetting.isDynamic())) {			if (locale == null) {				locale = this.localizationSetting.getDefaultLocale();				this.environment.addSymbol("polish.i18n.useDynamicTranslations");				this.environment.setLocale( locale );			}			this.environment.addVariable("polish.SupportedLocales", this.localizationSetting.getSupportedLocalesAsString() );			this.environment.addVariable("polish.locale", locale.toString() );			this.environment.addVariable("polish.language", locale.getLanguage() );			String country = locale.getCountry();			if ( country == null || country.length() == 0 ) {				this.environment.removeVariable( "polish.country" );			} else {				this.environment.addVariable("polish.country", country );			}		}		// set info-variables:		String jarName = this.infoSetting.getJarName();		jarName = this.environment.writeProperties( jarName, true );		this.environment.addVariable( "polish.jarName", jarName );						// enable the support for the J2ME Polish GUI, part 1: 		// check if a preprocessing variable is set for using the Polish GUI:		String usePolishGuiVariable = this.environment.getVariable("polish.usePolishGui");		boolean usePolishGui = (this.buildSetting.usePolishGui()		  && ( device.supportsPolishGui() || this.buildSetting.alwaysUsePolishGui()))		  || (( "true".equals( usePolishGuiVariable) || "yes".equals( usePolishGuiVariable ) || "always".equals( usePolishGuiVariable )) );		  		if ( usePolishGui) {			this.environment.addSymbol("polish.usePolishGui");		}				// set conditional variables:		BooleanEvaluator evaluator = this.environment.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.environment.addVariable(var.getName(), var.getValue() );		}		ClassSetting dojaSetting = this.buildSetting.getDojaClassSetting();		if (dojaSetting != null && dojaSetting.isActive( evaluator, antProject ) ) {			this.environment.addVariable("polish.classes.iapplication", dojaSetting.getClassName() );		}		ClassSetting mainSetting = this.buildSetting.getMainClassSetting();		if (mainSetting != null && mainSetting.isActive( evaluator, antProject ) ) {			this.environment.addVariable("polish.classes.main", mainSetting.getClassName() );		}		// now set the full-screen-settings:		String value = this.environment.getVariable("polish.FullScreen");		if (value != null) {			if ("menu".equalsIgnoreCase(value)) {				this.environment.addSymbol("polish.useMenuFullScreen");				this.environment.addSymbol("polish.useFullScreen");								} else if ("yes".equalsIgnoreCase( value ) || "true".equalsIgnoreCase(value)) {				this.environment.addSymbol("polish.useFullScreen");								}		} else {			FullScreenSetting fullScreenSetting = this.buildSetting.getFullScreenSetting();			if (fullScreenSetting != null) {				if (fullScreenSetting.isMenu()) {					this.environment.addSymbol("polish.useMenuFullScreen");					this.environment.addSymbol("polish.useFullScreen");				} else if (fullScreenSetting.isEnabled()) {					this.environment.addSymbol("polish.useFullScreen");				}			}		}				jarName = this.environment.getVariable( "polish.jarName" );		String destPath = this.buildSetting.getDestDir( this.environment ).getAbsolutePath() + File.separatorChar;		String jarPath = destPath + jarName;		this.environment.addVariable( "polish.jarPath", jarPath );		String jadName = jarName.substring(0, jarName.lastIndexOf('.') ) + ".jad";		this.environment.addVariable( "polish.jadName", jadName );		String jadPath = destPath + jadName;		this.environment.addVariable( "polish.jadPath", jadPath );		// add info attributes:		Attribute[] jadAttributes = this.infoSetting.getJadAttributes( this.environment );		for (int i = 0; i < jadAttributes.length; i++) {			Attribute attribute = jadAttributes[i];			this.environment.addVariable( attribute.getName(), attribute.getValue() );		}		String copyright = this.infoSetting.getCopyright();		if (copyright != null) {			this.environment.addVariable( "MIDlet-Copyrigh", copyright );		}						// set support for the J2ME Polish GUI, part 2:		usePolishGuiVariable = this.environment.getVariable("polish.usePolishGui");		if (usePolishGuiVariable != null) {			if ("true".equalsIgnoreCase(usePolishGuiVariable) || "yes".equalsIgnoreCase(usePolishGuiVariable) || "always".equalsIgnoreCase(usePolishGuiVariable)) {				usePolishGui = true;									this.environment.addSymbol("polish.usePolishGui");			} else {				usePolishGui = false;									this.environment.removeSymbol("polish.usePolishGui");			}		}				// okay, now initialize extension manager:		this.extensionManager.initialize(device, locale, this.environment);				// check if there is an active obfuscator with the "useDefaultPackage" option:		this.useDefaultPackage =  "true".equals( this.environment.getVariable("polish.useDefaultPackage"));		this.preprocessor.setUseDefaultPackage( this.useDefaultPackage );		// adjust polish.classes.ImageLoader in case the default package is used:		if (this.useDefaultPackage) {			String imageLoaderClass = this.environment.getVariable("polish.classes.ImageLoader");			if (imageLoaderClass != null) {				int classStartIndex = imageLoaderClass.lastIndexOf('.');				if (classStartIndex != -1) {					imageLoaderClass = imageLoaderClass.substring( classStartIndex + 1 );					this.environment.addVariable("polish.classes.ImageLoader", imageLoaderClass );				}			}		}		// add primary midlet-class-definition:		String[] midletClassNames = this.buildSetting.getMidletClassNames( this.useDefaultPackage, this.environment );		if (midletClassNames.length > 0) {			this.environment.addVariable("polish.midlet.class", midletClassNames[0] );			for (int i = 0; i < midletClassNames.length; i++) {				this.environment.addVariable("polish.classes.midlet-" + (i+1), midletClassNames[i] );						}		}						// check settings:		String version = this.environment.getVariable( "MIDlet-Version");		if (version != null) {			String[] versionChunks = StringUtil.split( version, '.' );			for (int i = 0; i < versionChunks.length; i++) {				String versionChunk = versionChunks[i];				int versionNumber = Integer.parseInt( versionChunk );				if (versionNumber > 99) {					if ( this.environment.hasSymbol("polish.Bugs.VersionNumberMustNotExceed99") ) {						throw new BuildException("Invalid MIDlet-Version [" + version + "]: each version-part must not exceed 99 on the " + device.getIdentifier() + "." );					} else {						System.out.println("WARNING: the MIDlet-Version [" + version + "] contains a number greater than 99, This can cause problems on some devices.");					}				}			}		}				this.extensionManager.postInitialize(device, locale, this.environment);										this.environment.set( "polish.home", this.polishHomeDir );		this.environment.set( "polish.apidir", this.buildSetting.getApiDir() );				// set the absolute path to polish.home  - this minimizes problems resolving paths		// relative to polish.home (since the polish.home can be relative		// to the build.xml script).		this.environment.addVariable( "polish.home", this.polishHomeDir.getAbsolutePath() );				//TODO call initialialize on all active extensions		// 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);			}		}		*/	}