Search in sources :

Example 1 with SpecfileSection

use of org.eclipse.linuxtools.rpm.ui.editor.parser.SpecfileSection 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 2 with SpecfileSection

use of org.eclipse.linuxtools.rpm.ui.editor.parser.SpecfileSection 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 3 with SpecfileSection

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

the class HeaderRecognitionTest method testGetComplexSectionName5.

@Test
public void testGetComplexSectionName5() {
    // FIXME: check for rest of line when -p is implemented
    // "blah bleh" should become the actual text of the section
    String testText = "%post -n name -p blah bleh";
    String[] tokens = testText.split("\\s+");
    SpecfileElement element;
    newFile(testText);
    element = parser.parseLine(testText, specfile, 0);
    assertEquals(SpecfileSection.class, element.getClass());
    SpecfileSection section = (SpecfileSection) element;
    assertEquals(tokens[0].substring(1), section.getName());
    assertEquals(tokens[2], section.getPackage().getPackageName());
}
Also used : SpecfileSection(org.eclipse.linuxtools.rpm.ui.editor.parser.SpecfileSection) SpecfileElement(org.eclipse.linuxtools.rpm.ui.editor.parser.SpecfileElement) Test(org.junit.Test)

Example 4 with SpecfileSection

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

the class HeaderRecognitionTest method testGetComplexSectionName1.

@Test
public void testGetComplexSectionName1() {
    String testText = "%post";
    SpecfileElement element;
    newFile(testText);
    element = parser.parseLine(testText, specfile, 0);
    assertEquals(SpecfileSection.class, element.getClass());
    SpecfileSection section = (SpecfileSection) element;
    assertEquals(testText.substring(1), section.getName());
    assertNull(section.getPackage());
}
Also used : SpecfileSection(org.eclipse.linuxtools.rpm.ui.editor.parser.SpecfileSection) SpecfileElement(org.eclipse.linuxtools.rpm.ui.editor.parser.SpecfileElement) Test(org.junit.Test)

Example 5 with SpecfileSection

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

the class HeaderRecognitionTest method testGetComplexSectionName3.

@Test
public void testGetComplexSectionName3() {
    String testText = "%post -n name";
    String[] tokens = testText.split("\\s+");
    SpecfileElement element;
    newFile(testText);
    element = parser.parseLine(testText, specfile, 0);
    assertEquals(SpecfileSection.class, element.getClass());
    SpecfileSection section = (SpecfileSection) element;
    assertEquals(tokens[0].substring(1), section.getName());
    assertEquals(tokens[2], section.getPackage().getPackageName());
}
Also used : SpecfileSection(org.eclipse.linuxtools.rpm.ui.editor.parser.SpecfileSection) SpecfileElement(org.eclipse.linuxtools.rpm.ui.editor.parser.SpecfileElement) Test(org.junit.Test)

Aggregations

SpecfileSection (org.eclipse.linuxtools.rpm.ui.editor.parser.SpecfileSection)7 SpecfileElement (org.eclipse.linuxtools.rpm.ui.editor.parser.SpecfileElement)6 Test (org.junit.Test)5 Specfile (org.eclipse.linuxtools.rpm.ui.editor.parser.Specfile)2 SpecfilePackage (org.eclipse.linuxtools.rpm.ui.editor.parser.SpecfilePackage)2 CoreException (org.eclipse.core.runtime.CoreException)1 BadLocationException (org.eclipse.jface.text.BadLocationException)1 SpecfilePreamble (org.eclipse.linuxtools.internal.rpm.ui.editor.parser.SpecfilePreamble)1 SpecfileErrorHandler (org.eclipse.linuxtools.rpm.ui.editor.markers.SpecfileErrorHandler)1 SpecfileTaskHandler (org.eclipse.linuxtools.rpm.ui.editor.markers.SpecfileTaskHandler)1 SpecfilePackageContainer (org.eclipse.linuxtools.rpm.ui.editor.parser.SpecfilePackageContainer)1 SpecfileParser (org.eclipse.linuxtools.rpm.ui.editor.parser.SpecfileParser)1 FileEditorInput (org.eclipse.ui.part.FileEditorInput)1