Search in sources :

Example 6 with Specfile

use of org.eclipse.linuxtools.rpm.ui.editor.parser.Specfile in project linuxtools by eclipse.

the class SpecfileEditorPrepareSourcesActionDelegate method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    final Shell shell = HandlerUtil.getActiveShellChecked(event);
    final SpecfileParser specparser = new SpecfileParser();
    final IResource resource = RPMHandlerUtils.getResource(event);
    final RPMProject rpj = RPMHandlerUtils.getRPMProject(resource);
    final IFile workFile = (IFile) rpj.getSpecFile();
    final Specfile specfile = specparser.parse(workFile);
    if (!downloadFile(shell, rpj, specfile)) {
        return null;
    }
    Job job = new // $NON-NLS-1$
    Job(// $NON-NLS-1$
    "Preparing sources") {

        @Override
        protected IStatus run(IProgressMonitor monitor) {
            monitor.beginTask(NLS.bind(Messages.PrepareSources_prepareSources, rpj.getSpecFile().getName()), IProgressMonitor.UNKNOWN);
            // $NON-NLS-1$
            int offset = rpj.getSpecFile().getName().lastIndexOf(".");
            MessageConsoleStream out = getConsole(rpj.getSpecFile().getName().substring(0, offset)).newMessageStream();
            IStatus is = null;
            try {
                is = rpj.buildPrep(out);
            } catch (CoreException e) {
                SpecfileLog.logError(Messages.PrepareSources_coreException, e);
                RPMUtils.showErrorDialog(shell, Messages.PrepareSources_error, Messages.PrepareSources_coreException);
                return is;
            } finally {
                monitor.done();
            }
            return is;
        }
    };
    // suppress UI. That's done in encapsulated
    job.setUser(true);
    job.schedule();
    return null;
}
Also used : Specfile(org.eclipse.linuxtools.rpm.ui.editor.parser.Specfile) Shell(org.eclipse.swt.widgets.Shell) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IStatus(org.eclipse.core.runtime.IStatus) IFile(org.eclipse.core.resources.IFile) CoreException(org.eclipse.core.runtime.CoreException) RPMProject(org.eclipse.linuxtools.rpm.core.RPMProject) MessageConsoleStream(org.eclipse.ui.console.MessageConsoleStream) DownloadJob(org.eclipse.linuxtools.rpm.core.utils.DownloadJob) Job(org.eclipse.core.runtime.jobs.Job) SpecfileParser(org.eclipse.linuxtools.rpm.ui.editor.parser.SpecfileParser) IResource(org.eclipse.core.resources.IResource)

Example 7 with Specfile

use of org.eclipse.linuxtools.rpm.ui.editor.parser.Specfile in project linuxtools by eclipse.

the class SpecStructureCreator method parseSpecfile.

private void parseSpecfile(DocumentRangeNode root, IDocument doc, IFile file) {
    SpecfileParser parser = new SpecfileParser();
    // FIXME: error markers do not show
    if (file != null) {
        FileEditorInput fei = new FileEditorInput(file);
        // without it, the compare editor is blank
        try {
            SpecfileEditor.getSpecfileDocumentProvider().disconnect(fei);
            SpecfileEditor.getSpecfileDocumentProvider().connect(fei);
        } catch (CoreException e) {
            SpecfileLog.logError(e);
        }
        parser.setErrorHandler(new SpecfileErrorHandler(fei, doc));
        parser.setTaskHandler(new SpecfileTaskHandler(fei, doc));
        Specfile specfile = parser.parse(doc);
        String id = specfile.getName();
        // Be a child under parent node of specfileSectionRoot (would be
        // rootNode)
        SpecNode fileNode = new SpecNode((DocumentRangeNode) root.getParentNode(), 1, id, doc, 0, doc.getLength());
        for (SpecfileSection sec : specfile.getSections()) {
            try {
                addNode(root, doc, sec.getName(), doc.getLineOffset(sec.getLineNumber()), doc.getLineOffset(sec.getSectionEndLine()) - doc.getLineOffset(sec.getLineNumber()), 2);
            } catch (BadLocationException e) {
                SpecfileLog.logError(e);
            }
        }
        // Be a child under the parent file node
        for (SpecfilePackage sPackage : specfile.getPackages().getPackages()) {
            try {
                SpecNode pNode = addNode(fileNode, doc, sPackage.getPackageName(), doc.getLineOffset(sPackage.getLineNumber()), doc.getLineOffset(sPackage.getSectionEndLine()) - doc.getLineOffset(sPackage.getLineNumber()), 3);
                for (SpecfileSection section : sPackage.getSections()) {
                    addNode(pNode, doc, section.getName(), doc.getLineOffset(section.getLineNumber()), doc.getLineOffset(section.getSectionEndLine()) - doc.getLineOffset(section.getLineNumber()), 4);
                }
            } catch (BadLocationException e) {
                SpecfileLog.logError(e);
            }
        }
    }
}
Also used : Specfile(org.eclipse.linuxtools.rpm.ui.editor.parser.Specfile) SpecfileSection(org.eclipse.linuxtools.rpm.ui.editor.parser.SpecfileSection) SpecfileTaskHandler(org.eclipse.linuxtools.rpm.ui.editor.markers.SpecfileTaskHandler) CoreException(org.eclipse.core.runtime.CoreException) FileEditorInput(org.eclipse.ui.part.FileEditorInput) SpecfileErrorHandler(org.eclipse.linuxtools.rpm.ui.editor.markers.SpecfileErrorHandler) SpecfileParser(org.eclipse.linuxtools.rpm.ui.editor.parser.SpecfileParser) SpecfilePackage(org.eclipse.linuxtools.rpm.ui.editor.parser.SpecfilePackage) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 8 with Specfile

use of org.eclipse.linuxtools.rpm.ui.editor.parser.Specfile in project linuxtools by eclipse.

the class SpecfileFormEditor method addPages.

@Override
protected void addPages() {
    try {
        int index = addPage(editor, getEditorInput());
        setPageText(index, Messages.SpecfileFormEditor_0);
        Specfile specfile = editor.getSpecfile();
        FormPage mainPackage = new MainPackagePage(this, specfile);
        addPage(0, mainPackage);
        addPage(1, new RpmSectionPage(this, specfile, RpmSections.PREP_SECTION));
        addPage(2, new RpmSectionPage(this, specfile, RpmSections.BUILD_SECTION));
        addPage(3, new RpmSectionPage(this, specfile, RpmSections.INSTALL_SECTION));
    } catch (PartInitException e) {
    // 
    }
}
Also used : Specfile(org.eclipse.linuxtools.rpm.ui.editor.parser.Specfile) FormPage(org.eclipse.ui.forms.editor.FormPage) PartInitException(org.eclipse.ui.PartInitException)

Example 9 with Specfile

use of org.eclipse.linuxtools.rpm.ui.editor.parser.Specfile in project linuxtools by eclipse.

the class SpecfileLabelProvider method getText.

@Override
public String getText(Object element) {
    // $NON-NLS-1$
    String str = "";
    if (element instanceof SpecfileSection) {
        SpecfileSection specfileSection = (SpecfileSection) element;
        str = specfileSection.toString();
    } else if (element instanceof Specfile) {
        str = ((Specfile) element).getName();
    } else if (element instanceof SpecfilePackageContainer) {
        str = Messages.SpecfileLabelProvider_0;
    } else if (element instanceof SpecfilePreamble) {
        str = Messages.SpecfileLabelProvider_1;
    } else if (element instanceof SpecfileElement) {
        SpecfileElement specfileElement = (SpecfileElement) element;
        str = specfileElement.getName();
    } else if (element instanceof String) {
        str = (String) element;
    } else if (element instanceof SpecfilePackage) {
        str = ((SpecfilePackage) element).getName();
    }
    return filterMacros(str.trim());
}
Also used : Specfile(org.eclipse.linuxtools.rpm.ui.editor.parser.Specfile) SpecfileSection(org.eclipse.linuxtools.rpm.ui.editor.parser.SpecfileSection) SpecfileElement(org.eclipse.linuxtools.rpm.ui.editor.parser.SpecfileElement) SpecfilePreamble(org.eclipse.linuxtools.internal.rpm.ui.editor.parser.SpecfilePreamble) SpecfilePackage(org.eclipse.linuxtools.rpm.ui.editor.parser.SpecfilePackage) SpecfilePackageContainer(org.eclipse.linuxtools.rpm.ui.editor.parser.SpecfilePackageContainer)

Example 10 with Specfile

use of org.eclipse.linuxtools.rpm.ui.editor.parser.Specfile in project linuxtools by eclipse.

the class SpecfileSource method changeReferences.

// 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) {
        // $NON-NLS-1$ //$NON-NLS-2$
        patchPattern = Pattern.compile("%patch" + oldPatchNumber + "|%patch");
    } else {
        // $NON-NLS-1$
        patchPattern = Pattern.compile("%patch" + oldPatchNumber);
    }
    for (int lineNumber : getLinesUsed()) {
        String line;
        try {
            line = specfile.getLine(lineNumber);
            Matcher patchMatcher = patchPattern.matcher(line);
            if (!patchMatcher.find()) {
            // throw new BadLocationException("can't match " +
            // patchPattern);
            }
            specfile.changeLine(lineNumber, // $NON-NLS-1$
            line.replaceAll(patchPattern.pattern(), Messages.getString("SpecfileSource.1") + number));
        } catch (BadLocationException e) {
            SpecfileLog.logError(e);
        }
    }
}
Also used : Specfile(org.eclipse.linuxtools.rpm.ui.editor.parser.Specfile) Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) BadLocationException(org.eclipse.jface.text.BadLocationException)

Aggregations

Specfile (org.eclipse.linuxtools.rpm.ui.editor.parser.Specfile)13 BadLocationException (org.eclipse.jface.text.BadLocationException)6 SpecfileParser (org.eclipse.linuxtools.rpm.ui.editor.parser.SpecfileParser)6 Matcher (java.util.regex.Matcher)2 Pattern (java.util.regex.Pattern)2 IFile (org.eclipse.core.resources.IFile)2 IResource (org.eclipse.core.resources.IResource)2 CoreException (org.eclipse.core.runtime.CoreException)2 Job (org.eclipse.core.runtime.jobs.Job)2 IDocument (org.eclipse.jface.text.IDocument)2 RPMProject (org.eclipse.linuxtools.rpm.core.RPMProject)2 DownloadJob (org.eclipse.linuxtools.rpm.core.utils.DownloadJob)2 SpecfileDefine (org.eclipse.linuxtools.rpm.ui.editor.parser.SpecfileDefine)2 SpecfilePackage (org.eclipse.linuxtools.rpm.ui.editor.parser.SpecfilePackage)2 SpecfileSection (org.eclipse.linuxtools.rpm.ui.editor.parser.SpecfileSection)2 Shell (org.eclipse.swt.widgets.Shell)2 IOException (java.io.IOException)1 HttpURLConnection (java.net.HttpURLConnection)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1