Пример #1
0
 /**
  * Writes the given contents to a file with the given fileName in the specified project.
  *
  * @param projectName The name of the project to put the file into.
  * @throws CoreException Thrown when the project doesn't exist.
  */
 public void writeContent(String projectName) throws CoreException {
   String fileName = model.getPackageName().toLowerCase() + ".spec";
   String contents = generateSpecfile();
   InputStream contentInputStream = new ByteArrayInputStream(contents.getBytes());
   IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
   IResource resource = root.findMember(new Path(projectName));
   if (!resource.exists() || !(resource instanceof IContainer)) {
     throwCoreException("Project \"" + projectName + "\" does not exist.");
   }
   IContainer container = (IContainer) resource;
   final IFile file = container.getFile(new Path(fileName));
   try {
     InputStream stream = contentInputStream;
     if (file.exists()) {
       file.setContents(stream, true, true, null);
     } else {
       file.create(stream, true, null);
     }
     stream.close();
   } catch (IOException e) {
     StubbyLog.logError(e);
   }
   StubbyPlugin.getActiveWorkbenchShell()
       .getDisplay()
       .asyncExec(
           new Runnable() {
             public void run() {
               IWorkbenchPage page =
                   PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
               try {
                 IDE.openEditor(page, file, true);
               } catch (PartInitException e) {
                 StubbyLog.logError(e);
               }
             }
           });
 }
Пример #2
0
  /**
   * Generates a RPM specfile based on the parsed data from the pom file.
   *
   * @return The generated specfile.
   */
  public String generateSpecfile() {
    StringBuilder buffer = new StringBuilder();
    String packageName = model.getPackageName();
    buffer.append("Name:           " + packageName.toLowerCase() + "\n");
    buffer.append("Version:        " + model.getVersion() + "\n");
    buffer.append("Release:        1%{?dist}" + "\n");
    buffer.append("Summary:        " + model.getSummary() + "\n\n");
    buffer.append("Group:          Development/Libraries\n");
    buffer.append("License:        " + model.getLicense() + "\n");
    buffer.append("URL:            " + model.getURL() + "\n");
    buffer.append("Source0:        #FIXME\n");
    buffer.append("BuildArch: noarch\n\n");
    generateRequires(buffer);
    buffer.append("\n%description\n" + model.getDescription() + "\n\n");
    generateJavadocSubpackage(buffer);
    generatePrepSection(buffer);
    generateBuildSection(buffer);
    generateInstallSection(buffer);
    generatePostPostun(buffer);
    generateFilesSections(buffer);
    generateChangelog(buffer);

    return buffer.toString();
  }