/* (non-Javadoc) * @see de.enough.polish.ant.requirements.Matcher#matches(java.lang.String) */ public boolean matches(String deviceValue) { String[] chunks = StringUtil.splitAndTrim(deviceValue, '.'); int min = Math.min(chunks.length, this.versionNumbers.length); int diff = this.versionNumbers.length - chunks.length; boolean carryFlag = false; for (int i = 0; i < min; i++) { int deviceNumber = Integer.parseInt(chunks[i]); int neededNumber = this.versionNumbers[i]; boolean eqOrGreater = this.equalsOrGreater[i]; if (deviceNumber < neededNumber && !carryFlag) { return false; } else if (deviceNumber > neededNumber) { if (eqOrGreater) { carryFlag = true; } else { return false; } } } if (diff > 0) { // when there are more needed version chunks than the device specifies, // the version only matches, if the last compared version-chunk was greater // than the needed one. // example 1: needed="1.2+.3+" given="1.2" would return false // example 2: needed="1.2+.3+" given="1.3" would return true return carryFlag; } else { return true; } }
/** * Creates a new version matcher. * * @param value the needed version, e.g. "1.3+" or "1.3+.2+" */ public VersionMatcher(String value) { String[] chunks = StringUtil.splitAndTrim(value, '.'); this.versionNumbers = new int[chunks.length]; this.equalsOrGreater = new boolean[chunks.length]; for (int i = 0; i < chunks.length; i++) { IntegerMatcher matcher = new IntegerMatcher(chunks[i]); this.versionNumbers[i] = matcher.number; this.equalsOrGreater[i] = matcher.equalsOrGreater; } }
/** * Sets the locales which should be supported during this build. * * @param supportedLocalesStr The locales which should be supported or "*" for all found locales. */ public void setLocales(String supportedLocalesStr) { if ("*".equals(supportedLocalesStr)) { this.includeAllLocales = true; } else { String[] localeDefs = StringUtil.splitAndTrim(supportedLocalesStr, ','); // LocaleSetting[] locales = new LocaleSetting[ localeDefs.length ]; for (int i = 0; i < localeDefs.length; i++) { String localeDefinition = localeDefs[i]; addConfiguredLocaleSetting(new LocaleSetting(localeDefinition)); } } }
/** * Adds the contents of the corresponding <jadFilter> or <manifestFilter> to this filter-setting. * * @param text the text specifying what elements should be included in what order */ public void addText(String text) { String[] definitions = StringUtil.splitAndTrim(text, ','); this.filterElements = new ArrayList(definitions.length); for (int i = 0; i < definitions.length; i++) { String definition = definitions[i]; FilterElement element = new FilterElement(text, definition); if (element.isRest && (i != definitions.length - 1)) { throw new BuildException( "The attribute-element [" + definition + "] can only be placed at the end of the attributes-filter-list."); } this.filterElements.add(element); } }
/* (non-Javadoc) * @see de.enough.polish.jar.Packager#doPackage(java.io.File, java.io.File, de.enough.polish.Device, de.enough.polish.preprocess.BooleanEvaluator, java.util.Map, org.apache.tools.ant.Project) */ public void createPackage( File sourceDir, File targetFile, Device device, Locale locale, Environment env) throws IOException, BuildException { PackageSetting setting = getSetting(); env.addVariable("polish.packageDir", sourceDir.getAbsolutePath()); String executable = env.writeProperties(setting.getExecutable()); String argumentsStr = env.writeProperties(setting.getArguments()); String[] arguments = StringUtil.splitAndTrim(argumentsStr, ";;"); String[] parameters = new String[arguments.length + 1]; parameters[0] = executable; System.arraycopy(arguments, 0, parameters, 1, arguments.length); Runtime runtime = Runtime.getRuntime(); Process process = runtime.exec(parameters); try { String info = executable; if (info.indexOf(File.separatorChar) != -1) { info = info.substring(info.indexOf(File.separatorChar)); } info += ": "; LoggerThread.log(process, info); int result = process.waitFor(); if (result != 0) { System.err.println("Call to external packager was: "); for (int i = 0; i < parameters.length; i++) { System.err.print(parameters[i] + " "); } System.err.println(); throw new BuildException("External packager failed with result [" + result + "]."); } } catch (InterruptedException e) { e.printStackTrace(); throw new BuildException("External packager was interrupted."); } }
/** @param includes the includes to set */ public void setIncludes(String includes) { this.includes = StringUtil.splitAndTrim(includes, ','); }
/** @param excludes the excludes to set */ public void setExcludes(String excludes) { this.excludes = StringUtil.splitAndTrim(excludes, ','); }