Example #1
0
 /* (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;
   }
 }
Example #2
0
 /**
  * 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;
   }
 }
Example #3
0
 /**
  * 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));
     }
   }
 }
Example #4
0
 /**
  * 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.");
    }
  }
Example #6
0
  /**
   * Adds a CSS block to this style sheet. A CSS block contains either a style or the colors, fonts,
   * borders or backgrounds areas.
   *
   * @param cssBlock the block containing CSS declarations
   */
  public void addCssBlock(CssBlock cssBlock) {
    this.isInitialised = false;
    String selector = cssBlock.getSelector().toLowerCase();
    String[] groupNames = cssBlock.getGroupNames();
    AttributesGroup[] groups = new AttributesGroup[groupNames.length];
    for (int i = 0; i < groups.length; i++) {
      groups[i] = cssBlock.getGroupDeclarations(groupNames[i]);
    }
    Map<String, AttributesGroup> target = null;
    if ("colors".equals(selector)) {
      target = this.colors;
    } else if ("fonts".equals(selector)) {
      target = this.fonts;
    } else if ("backgrounds".equals(selector)) {
      target = this.backgrounds;
    } else if ("borders".equals(selector)) {
      target = this.borders;
    }
    if (target != null) {
      for (int i = 0; i < groups.length; i++) {
        String name = groupNames[i];
        AttributesGroup group = groups[i];
        AttributesGroup targetGroup = (AttributesGroup) target.get(name);
        if (targetGroup == null) {
          target.put(name, group);
        } else {
          targetGroup.putAll(group);
        }
      }
    } else { // this is a style:
      String parent = null;
      int extendsPos = selector.indexOf(" extends ");
      int colonPos = selector.indexOf(':');
      if (extendsPos != -1) {
        if (colonPos != -1) {
          throw new BuildException(
              "Invalid CSS: the CSS style \""
                  + selector
                  + "\" is a pseudo style that uses an extends clause. Please either use a pseudo style (:hover, etc) or use the extends clause. Pseudo styles inherit from their base styles automatically. Please adjust your polish.css design settings.");
        }
        parent = selector.substring(extendsPos + 9).trim();
        if (parent.charAt(0) == '.') {
          parent = parent.substring(1);
        }
        selector = selector.substring(0, extendsPos).trim();
        if ("default".equals(selector)) {
          throw new BuildException(
              "Invalid CSS code: The style [default] must not extend any other style.");
        }
      }
      // check for the "[parentStyleName]:hover" "[parentStyleName]:pressed" etc syntax:
      if (colonPos != -1) {
        // allow any number of levels of pseudo styles, e.g. myStyle:hover:visited:pressed
        String subName = null;
        Style parentStyle = null;
        while (colonPos != -1) {
          subName = selector.substring(colonPos + 1);
          int subNameColonIndex = subName.indexOf(':');
          if (subNameColonIndex != -1) {
            subName = subName.substring(0, subNameColonIndex).trim();
          }
          parent = selector.substring(0, colonPos).trim();
          if (parent.charAt(0) == '.') {
            parent = parent.substring(1);
          }

          parentStyle = getStyle(parent);
          if (parentStyle == null && this.mediaQueryCondition == null) {
            throw new BuildException(
                "Invalid CSS: the :"
                    + subName
                    + " CSS style \""
                    + selector
                    + "\" needs to follow AFTER the referenced style definition. Please adjust your polish.css design settings.");
          }
          // found parent style, now set the implicit focused-style attribute:
          String newStyleName = subName;
          if (subName.equals("hover")) {
            newStyleName = "focused";
          }

          selector =
              (selector.substring(0, colonPos).trim()
                      + newStyleName
                      + selector.substring(colonPos + subName.length() + 1).trim())
                  .trim();
          subName = newStyleName;
          //					System.out.println("selector: " + selector );
          //					System.out.println( "subname: [" + subName + "]");
          colonPos = selector.indexOf(':');
        }
        cssBlock.setSelector(selector);
        if (parentStyle != null) {
          AttributesGroup referenceMap = new AttributesGroup(parentStyle, subName, 1);
          referenceMap.put("style", parent + subName);
          parentStyle.addGroup(subName, referenceMap);
        }
      }
      boolean isDynamicStyle = false;
      // check if this style is dynamic:
      isDynamicStyle =
          (selector.indexOf(' ') != -1)
              || (selector.indexOf('\t') != -1)
              || (selector.indexOf('>') != -1)
              || (selector.indexOf('*') != -1);
      if (selector.charAt(0) == '.') {
        selector = selector.substring(1);
        if (PSEUDO_CLASSES.get(selector) != null) {
          throw new BuildException(
              "Invalid CSS code: The style [."
                  + selector
                  + "] uses a reserved name, please choose another one or remove the leading dot of the name.");
        }
      } else {
        // this could be a DYNAMIC style:
        if (PSEUDO_CLASSES.get(selector) == null && selector.indexOf(':') == -1) {
          isDynamicStyle = true;
        }
      }
      if (isDynamicStyle) {
        this.containsDynamicStyles = true;
        // System.out.println("project uses dynamic style: [" + selector + "]");
      }
      // check for reserved names of the style-selector:
      if (KEYWORDS.get(selector) != null) {
        throw new BuildException(
            "Invalid CSS code: The style-selector ["
                + selector
                + "] uses a reserved keyword, please choose another name.");
      }
      if (selector.startsWith("@media ")) {
        addMediaQuery(selector.substring("@media ".length()).trim(), cssBlock);
      } else {
        // this is a traditional style:
        String styleName = StringUtil.replace(selector, '-', '_');
        if (isDynamicStyle) {
          selector = StringUtil.replace(selector, ".", "");
          selector = StringUtil.replace(selector, '\t', ' ');
          selector = StringUtil.replace(selector, " > ", ">");
          selector = StringUtil.replace(selector, " > ", ">");
          selector = StringUtil.replace(selector, " * ", "*");
          selector = StringUtil.replace(selector, "  ", " ");
          styleName = StringUtil.replace(selector, ' ', '_');
          styleName = StringUtil.replace(styleName, ">", "__");
          styleName = StringUtil.replace(styleName, "*", "___");
        }

        // check style name for invalid characters:
        if ((styleName.indexOf('.') != -1)
            || (styleName.indexOf('"') != -1)
            || (styleName.indexOf('\'') != -1)
            || (styleName.indexOf('*') != -1)
            || (styleName.indexOf('+') != -1)
            || (styleName.indexOf('-') != -1)
            || (styleName.indexOf('/') != -1)
            || (styleName.indexOf(':') != -1)
            || (styleName.indexOf('=') != -1)
            || (styleName.indexOf('|') != -1)
            || (styleName.indexOf('&') != -1)
            || (styleName.indexOf('~') != -1)
            || (styleName.indexOf('!') != -1)
            || (styleName.indexOf('^') != -1)
            || (styleName.indexOf('(') != -1)
            || (styleName.indexOf(')') != -1)
            || (styleName.indexOf('%') != -1)
            || (styleName.indexOf('?') != -1)
            || (styleName.indexOf('#') != -1)
            || (styleName.indexOf('$') != -1)
            || (styleName.indexOf('@') != -1)) {
          throw new BuildException(
              "Invalid CSS code: The style-selector ["
                  + selector
                  + "] contains invalid characters, please use only alpha-numeric characters for style-names.");
        }

        Style style = (Style) this.stylesByName.get(styleName);
        if (style == null) {
          style = new Style(selector, styleName, isDynamicStyle, parent, cssBlock);
          this.styles.add(style);
          // System.out.println("added new style [" + style.getStyleName() + "].");
          this.stylesByName.put(selector, style);
        } else {
          style.add(cssBlock);
        }
      }
    }
  }
Example #7
0
 /** @param includes the includes to set */
 public void setIncludes(String includes) {
   this.includes = StringUtil.splitAndTrim(includes, ',');
 }
Example #8
0
 /** @param excludes the excludes to set */
 public void setExcludes(String excludes) {
   this.excludes = StringUtil.splitAndTrim(excludes, ',');
 }