/**
  * Return the ouput of the <code>rpm --eval</code> command for a given macro.
  *
  * @param macroName The macro name to eval.
  * @return the resolved macro content.
  */
 public static String getMacroEval(String macroName) {
   String eval = EMPTY_STRING;
   try {
     eval = Utils.runCommandToString("rpm", "--eval", macroName); // $NON-NLS-1$//$NON-NLS-2$
   } catch (IOException e) {
     SpecfileLog.logError(e);
   }
   return eval.trim();
 }
 /**
  * Add macro definition to the map
  *
  * @param filename macro file definition.
  */
 private void addMacroToMap(String filename) {
   String line = EMPTY_STRING;
   BufferedReader reader = null;
   try {
     reader = new BufferedReader(new InputStreamReader(new FileInputStream(filename)));
     line = reader.readLine();
     String key = EMPTY_STRING, value = EMPTY_STRING;
     while (line != null) {
       if (line.startsWith("%")) { // $NON-NLS-1$
         String[] item = line.split("\t+| ", 2); // $NON-NLS-1$
         try {
           // Get values on more than one line
           if (line.trim().endsWith("\\")) { // $NON-NLS-1$
             value = "\n"; // $NON-NLS-1$
             boolean isKeyLine = true;
             while (line.trim().endsWith("\\")) { // $NON-NLS-1$
               if (isKeyLine) {
                 isKeyLine = false;
                 key = item[0];
                 if (item.length > 1) {
                   value += item[1].replaceAll("\\", "\n\n"); // $NON-NLS-1$//$NON-NLS-2$
                 }
               } else {
                 value += line.substring(0, line.length() - 1).trim() + "\n\t"; // $NON-NLS-1$
               }
               line = reader.readLine();
             }
           } else {
             key = item[0];
             value = item[1];
           }
           key = key.trim();
           value = value.trim();
           macroMap.put(key, value);
           toStringStr += key + ": " + value + "\n"; // $NON-NLS-1$ //$NON-NLS-2$
         } catch (Exception e) {
           line = reader.readLine();
           continue;
         }
         value = EMPTY_STRING;
         key = EMPTY_STRING;
       }
       line = reader.readLine();
     }
   } catch (IOException e) {
     SpecfileLog.logError(e);
   } finally {
     if (reader != null) {
       try {
         reader.close();
       } catch (IOException e) {
       }
     }
   }
 }
예제 #3
0
  public TemplateStore getTemplateStore() {
    if (fTemplateStore == null) {
      fTemplateStore =
          new ContributionTemplateStore(
              getContextTypeRegistry(), getPreferenceStore(), "templates"); // $NON-NLS-1$
      try {
        fTemplateStore.load();
      } catch (IOException e) {
        SpecfileLog.logError(e);
      }
    }

    return fTemplateStore;
  }
예제 #4
0
  public List<String> getRpmGroups() {
    if (rpmGroups.isEmpty()) {
      // FIXME: Can we assume that all distros place
      // documentations files in the below path?
      String docDir = "/usr/share/doc/"; // $NON-NLS-1$
      File dir = new File(docDir);
      if (dir.exists()) {
        File files[] =
            dir.listFiles(
                new FilenameFilter() {
                  public boolean accept(File dir, String name) {
                    return name.startsWith("rpm-"); // $NON-NLS-1$
                  }
                });
        try {
          // We can not be sure that there is only one directory here
          // starting with rpm-
          // (e.g. rpm-apidocs is the wrong directory.)
          for (File file : files) {
            File groupsFile = new File(file, "GROUPS"); // $NON-NLS-1$
            if (groupsFile.exists()) {

              LineNumberReader reader = null;
              try {
                reader = new LineNumberReader(new FileReader(groupsFile));
                String line;
                while ((line = reader.readLine()) != null) {
                  rpmGroups.add(line);
                }
              } finally {
                if (reader != null) {
                  reader.close();
                }
              }
              break;
            }
          }
        } catch (IOException e) {
          SpecfileLog.logError(e);
        }
      }
    }
    return rpmGroups;
  }