Esempio n. 1
0
  public static void run(String[] args)
      throws UnableToCreateEntityException, UnableToLoadEntityException, UCMEntityNotFoundException,
          UnknownEntityException, TagException, UnableToGetEntityException,
          UnableToInitializeEntityException {
    Options o = new Options();

    Option oentity = new Option("entity", "e", true, 1, "The UCM entity");
    Option otag = new Option("tag", "t", true, 1, "The tag. Given as: \"key1=val1&key2=val2\"");
    Option otagtype = new Option("tagtype", "y", true, 1, "The tag type");
    Option otagid = new Option("tagid", "i", true, 1, "The tag id");

    o.setOption(oentity);
    o.setOption(otag);
    o.setOption(otagtype);
    o.setOption(otagid);

    o.setDefaultOptions();

    o.setHeader("Set a tag for an UCM entity");
    o.setSyntax("SetTag -e <entity> -t <tag> -y <tag type> -i <tag id>");
    o.setDescription(
        "Examples:"
            + Options.linesep
            + "SetTag -e baseline:bls@\\somevob -T \"key1=val1&key2=val2\" -y myjob -i 10101"
            + Options.linesep
            + "SetTag -e baseline:bls@\\somevob -T \"key1=&key2=val2\" -y myjob -i 10101"
            + Options.linesep
            + "The last example will remove key1 from the tag");

    o.parse(args);

    try {
      o.checkOptions();
    } catch (Exception e) {
      logger.severe("Incorrect option: " + e.getMessage());
      o.display();
      System.exit(1);
    }

    UCMEntity e = null;

    e = UCMEntity.getEntity(oentity.getString()).load();

    Tag tag = e.getTag(otagtype.getString(), otagid.getString());

    /* Split key value structure */
    String[] tags = otag.getString().split("&");

    for (String t : tags) {

      String[] entry = t.split("=");

      try {
        logger.config("+(" + entry[0] + ", " + entry[1] + ") ");

        tag.setEntry(entry[0].trim(), entry[1].trim());
      } catch (ArrayIndexOutOfBoundsException ea) {
        logger.info("-(" + entry[0] + ") ");
        tag.removeEntry(entry[0]);
      }
    }

    try {
      tag.persist();
    } catch (TagException ex) {
      if (ex.getType().equals(Type.CREATION_FAILED)) {
        logger.severe("Could not persist the tag.");
        System.exit(1);
      }
    }

    if (tag.isCreated()) {
      logger.info("Tag created.");
    } else {
      logger.info("Tag updated.");
    }
  }
Esempio n. 2
0
  public static void main(String[] args) {
    Options o = new Options(net.praqma.vans.Version.version);

    Option ofile = new Option("file", "f", true, 1, "The file to parse. *.ewp");
    Option orel =
        new Option("relative", "r", false, 0, "If set, only the relative path is provided");
    Option ocut = new Option("cutoff", "c", false, 1, "Cutoff a given string from the path");

    o.setOption(ofile);
    o.setOption(orel);
    o.setOption(ocut);

    o.setDefaultOptions();

    o.setSyntax("IARParse -f <file> [ -r ] [ -c <cutoff> ]");
    o.setHeader("Parse an IAR project file for files.");
    o.setDescription("Examples:" + Options.linesep + "IARParse -f test.ewp -c c:\\data");

    o.parse(args);

    try {
      o.checkOptions();
    } catch (Exception e) {
      System.err.println("Incorrect option: " + e.getMessage());
      o.display();
      System.exit(1);
    }

    File file = new File(ofile.getString());

    if (!file.exists()) {
      System.err.println("The file does not exist");
      System.exit(1);
    }

    if (o.verbose()) {
      o.print();
    }

    boolean relative = orel.used ? true : false;
    String cutoff = ocut.used ? ocut.getString().toLowerCase() : "";

    try {
      IARParser p = new IARParser(file);
      int length = p.getPath().length();

      for (File f : p.getFiles()) {
        String d = "";
        if (relative) {
          d = f.getAbsolutePath().substring(length);
        } else {
          d = f.getAbsolutePath();
        }

        if (cutoff.length() > 0) {
          if (d.toLowerCase().startsWith(cutoff)) {
            d = d.substring(cutoff.length());
          }
        }

        System.out.println(d);
      }
    } catch (IOException e) {
      System.err.println("The file was not an acceptable project file: " + e.getMessage());
      System.exit(1);
    }
  }