// Note that changeReferences assumes that the number of the source/patch
 // has *already been set*.  If this is not true, it will simply do nothing
 public void changeReferences(int oldPatchNumber) {
   Specfile specfile = this.getSpecfile();
   Pattern patchPattern;
   if (oldPatchNumber == 0) {
     patchPattern =
         Pattern.compile("%patch" + oldPatchNumber + "|%patch"); // $NON-NLS-1$ //$NON-NLS-2$
   } else {
     patchPattern = Pattern.compile("%patch" + oldPatchNumber); // $NON-NLS-1$
   }
   for (int lineNumber : getLinesUsed()) {
     String line;
     try {
       line = specfile.getLine(lineNumber);
       Matcher patchMatcher = patchPattern.matcher(line);
       if (!patchMatcher.find()) {
         System.out.println(
             Messages.getString("SpecfileSource.0") + patchPattern.pattern()); // $NON-NLS-1$
         //					throw new BadLocationException("can't match " + patchPattern);
       }
       specfile.changeLine(
           lineNumber,
           line.replaceAll(
               patchPattern.pattern(),
               Messages.getString("SpecfileSource.1") + number)); // $NON-NLS-1$
     } catch (BadLocationException e) {
       SpecfileLog.logError(e);
     }
   }
 }
Exemple #2
0
  /**
   * Get the file from the URL if any.
   *
   * @param url The URL to get the file from.
   * @return Return the filename.
   */
  public static String getURLFilename(String url) {
    String rc = ""; // $NON-NLS-1$

    try {
      // URL#getPath will ignore any queries after the filename
      String fileName = new URL(url).getPath();
      int lastSegment = fileName.lastIndexOf('/') + 1;
      rc = fileName.substring(lastSegment).trim();
    } catch (IndexOutOfBoundsException e) {
      SpecfileLog.logError(e);
    } catch (MalformedURLException e) {
      SpecfileLog.logError(e);
    }

    return rc;
  }
 public void changeDeclaration(int oldPatchNumber) {
   Specfile specfile = this.getSpecfile();
   Pattern patchPattern;
   if (oldPatchNumber == 0) {
     patchPattern =
         Pattern.compile("Patch" + oldPatchNumber + "|Patch"); // $NON-NLS-1$ //$NON-NLS-2$
   } else {
     patchPattern = Pattern.compile("Patch" + oldPatchNumber); // $NON-NLS-1$
   }
   String line;
   try {
     line = specfile.getLine(lineNumber);
     Matcher patchMatcher = patchPattern.matcher(line);
     if (!patchMatcher.find()) {
       // TODO: Maybe we can throw a exception here.
       System.out.println(
           Messages.getString("SpecfileSource.2") + patchPattern.pattern()); // $NON-NLS-1$
     }
     specfile.changeLine(
         lineNumber, line.replaceAll(patchPattern.pattern(), "Patch" + number)); // $NON-NLS-1$
   } catch (BadLocationException e) {
     SpecfileLog.logError(e);
   }
 }