Search in sources :

Example 1 with SpecfileTag

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

the class MainPackagePage method createFormContent.

@Override
protected void createFormContent(IManagedForm managedForm) {
    super.createFormContent(managedForm);
    FormToolkit toolkit = managedForm.getToolkit();
    ScrolledForm form = managedForm.getForm();
    form.setText(Messages.MainPackagePage_2);
    GridLayout layout = new GridLayout();
    layout.marginWidth = layout.marginHeight = 5;
    layout.numColumns = 2;
    RowLayout rowLayout = new RowLayout();
    rowLayout.type = SWT.VERTICAL;
    rowLayout.justify = true;
    rowLayout.fill = true;
    form.getBody().setLayout(rowLayout);
    form.getBody().setLayoutData(rowLayout);
    layout.numColumns = 2;
    GridData gd = new GridData();
    gd.horizontalSpan = 2;
    gd.horizontalAlignment = SWT.FILL;
    final Section mainPackageSection = toolkit.createSection(form.getBody(), ExpandableComposite.TITLE_BAR | ExpandableComposite.TWISTIE | ExpandableComposite.EXPANDED);
    mainPackageSection.setText(Messages.MainPackagePage_3);
    mainPackageSection.setLayout(new GridLayout());
    Composite mainPackageClient = toolkit.createComposite(mainPackageSection);
    GridLayout gridLayout = new GridLayout();
    gridLayout.marginWidth = gridLayout.marginHeight = 5;
    gridLayout.numColumns = 2;
    mainPackageClient.setLayout(gridLayout);
    new RpmTagText(mainPackageClient, RpmTags.NAME, specfile);
    new RpmTagText(mainPackageClient, RpmTags.VERSION, specfile);
    new RpmTagText(mainPackageClient, RpmTags.RELEASE, specfile);
    new RpmTagText(mainPackageClient, RpmTags.URL, specfile);
    new RpmTagText(mainPackageClient, RpmTags.LICENSE, specfile);
    new RpmTagText(mainPackageClient, RpmTags.GROUP, specfile);
    new RpmTagText(mainPackageClient, RpmTags.EPOCH, specfile);
    new RpmTagText(mainPackageClient, RpmTags.BUILD_ROOT, specfile);
    new RpmTagText(mainPackageClient, RpmTags.BUILD_ARCH, specfile);
    new RpmTagText(mainPackageClient, RpmTags.SUMMARY, specfile, SWT.MULTI);
    // BuildRequires
    final Section buildRequiresSection = toolkit.createSection(mainPackageClient, ExpandableComposite.TITLE_BAR | ExpandableComposite.TWISTIE | ExpandableComposite.EXPANDED);
    buildRequiresSection.setText(Messages.MainPackagePage_4);
    buildRequiresSection.setLayout(rowLayout);
    buildRequiresSection.setExpanded(false);
    Composite buildRequiresClient = toolkit.createComposite(buildRequiresSection);
    buildRequiresClient.setLayout(gridLayout);
    for (SpecfileTag buildRequire : specfile.getBuildRequires()) {
        new RpmTagText(buildRequiresClient, buildRequire, specfile);
    }
    buildRequiresSection.setClient(buildRequiresClient);
    toolkit.paintBordersFor(buildRequiresClient);
    toolkit.paintBordersFor(buildRequiresSection);
    // Requires
    final Section requiresSection = toolkit.createSection(mainPackageClient, ExpandableComposite.TITLE_BAR | ExpandableComposite.TWISTIE | ExpandableComposite.EXPANDED);
    requiresSection.setText(Messages.MainPackagePage_5);
    requiresSection.setLayout(rowLayout);
    requiresSection.setExpanded(false);
    Composite requiresClient = toolkit.createComposite(requiresSection);
    requiresClient.setLayout(gridLayout);
    requiresClient.setLayoutData(gd);
    for (SpecfileTag require : specfile.getRequires()) {
        new RpmTagText(requiresClient, require, specfile);
    }
    requiresSection.setClient(requiresClient);
    toolkit.paintBordersFor(requiresClient);
    toolkit.paintBordersFor(requiresSection);
    mainPackageSection.setClient(mainPackageClient);
    toolkit.paintBordersFor(mainPackageClient);
    toolkit.paintBordersFor(mainPackageSection);
    // subpackages
    final Section packagesSection = toolkit.createSection(form.getBody(), ExpandableComposite.TITLE_BAR | ExpandableComposite.TWISTIE | ExpandableComposite.EXPANDED);
    packagesSection.setText(Messages.MainPackagePage_6);
    packagesSection.setLayout(gridLayout);
    Composite packagesClient = toolkit.createComposite(packagesSection);
    packagesClient.setLayout(gridLayout);
    packagesClient.setLayoutData(gd);
    for (SpecfilePackage specfilePackage : specfile.getPackages().getPackages()) {
        if (specfilePackage.isMainPackage()) {
            continue;
        }
        final Section packageSection = toolkit.createSection(packagesClient, ExpandableComposite.TITLE_BAR | ExpandableComposite.TWISTIE | ExpandableComposite.EXPANDED);
        packageSection.setText(specfilePackage.getFullPackageName());
        packageSection.setExpanded(false);
        packageSection.setLayout(rowLayout);
        Composite packageClient = toolkit.createComposite(packageSection);
        packageClient.setLayout(gridLayout);
        packageClient.setLayoutData(gd);
        new RpmTagText(packageClient, RpmTags.SUMMARY, specfile, specfilePackage, SWT.MULTI);
        new RpmTagText(packageClient, RpmTags.GROUP, specfile, specfilePackage, SWT.MULTI);
        final Section packageRequiresSection = toolkit.createSection(packageClient, ExpandableComposite.TITLE_BAR | ExpandableComposite.TWISTIE | ExpandableComposite.EXPANDED);
        packageRequiresSection.setText(Messages.MainPackagePage_7);
        packageRequiresSection.setLayout(rowLayout);
        packageRequiresSection.setLayoutData(gd);
        Composite packageRequiresClient = toolkit.createComposite(packageRequiresSection);
        packageRequiresClient.setLayout(gridLayout);
        packageRequiresClient.setLayoutData(gd);
        for (SpecfileTag require : specfilePackage.getRequires()) {
            new RpmTagText(packageRequiresClient, require, specfile);
        }
        packageRequiresSection.setClient(packageRequiresClient);
        toolkit.paintBordersFor(packageRequiresClient);
        toolkit.paintBordersFor(packageRequiresSection);
        packageSection.setClient(packageClient);
        toolkit.paintBordersFor(packageClient);
        toolkit.paintBordersFor(packageSection);
    }
    packagesSection.setClient(packagesClient);
    toolkit.paintBordersFor(packagesClient);
    toolkit.paintBordersFor(packagesSection);
    managedForm.refresh();
}
Also used : GridLayout(org.eclipse.swt.layout.GridLayout) FormToolkit(org.eclipse.ui.forms.widgets.FormToolkit) Composite(org.eclipse.swt.widgets.Composite) ExpandableComposite(org.eclipse.ui.forms.widgets.ExpandableComposite) ScrolledForm(org.eclipse.ui.forms.widgets.ScrolledForm) SpecfileTag(org.eclipse.linuxtools.internal.rpm.ui.editor.parser.SpecfileTag) RowLayout(org.eclipse.swt.layout.RowLayout) GridData(org.eclipse.swt.layout.GridData) Section(org.eclipse.ui.forms.widgets.Section) SpecfilePackage(org.eclipse.linuxtools.rpm.ui.editor.parser.SpecfilePackage)

Example 2 with SpecfileTag

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

the class SpecfileParser method parse.

public Specfile parse(IDocument specfileDocument) {
    // instantiated.
    if (errorHandler != null) {
        errorHandler.removeExistingMarkers();
    }
    if (taskHandler != null) {
        taskHandler.removeExistingMarkers();
    }
    LineNumberReader reader = new LineNumberReader(new StringReader(specfileDocument.get()));
    // $NON-NLS-1$
    String line = "";
    int lineStartPosition = 0;
    Specfile specfile = new Specfile();
    specfile.setDocument(specfileDocument);
    try {
        while ((line = reader.readLine()) != null) {
            if (taskHandler != null) {
                generateTaskMarker(reader.getLineNumber() - 1, line);
            }
            // IDocument.getLine(#) is 0-indexed whereas
            // reader.getLineNumber appears to be 1-indexed
            SpecfileElement element = parseLine(line, specfile, reader.getLineNumber() - 1);
            if (element != null) {
                element.setLineNumber(reader.getLineNumber() - 1);
                element.setLineStartPosition(lineStartPosition);
                element.setLineEndPosition(lineStartPosition + line.length());
                if (element.getClass() == SpecfileTag.class) {
                    SpecfileTag tag = (SpecfileTag) element;
                    specfile.addDefine(tag);
                } else if ((element.getClass() == SpecfilePatchMacro.class)) {
                    SpecfilePatchMacro thisPatchMacro = (SpecfilePatchMacro) element;
                    if (thisPatchMacro != null) {
                        thisPatchMacro.setSpecfile(specfile);
                    }
                    SpecfileSource thisPatch = specfile.getPatch(thisPatchMacro.getPatchNumber());
                    if (thisPatch != null) {
                        thisPatch.addLineUsed(reader.getLineNumber() - 1);
                        thisPatch.setSpecfile(specfile);
                    }
                } else if ((element.getClass() == SpecfileDefine.class)) {
                    specfile.addDefine((SpecfileDefine) element);
                } else if ((element.getClass() == SpecfileSource.class)) {
                    SpecfileSource source = (SpecfileSource) element;
                    source.setLineNumber(reader.getLineNumber() - 1);
                    if (source.getSourceType() == SpecfileSource.SourceType.SOURCE) {
                        specfile.addSource(source);
                    } else {
                        specfile.addPatch(source);
                    }
                }
            }
            // This is for the purpose of making DocumentRangeNode work
            if (lastSection != null) {
                lastSection.setSectionEndLine(specfileDocument.getNumberOfLines() - 1);
            }
            // The +1 is for the line delimiter. FIXME: will we end up off
            // by one on the last line?
            lineStartPosition += line.length() + 1;
        }
    } catch (IOException e) {
        // FIXME
        SpecfileLog.logError(e);
    }
    return specfile;
}
Also used : SpecfileSource(org.eclipse.linuxtools.internal.rpm.ui.editor.parser.SpecfileSource) SpecfileTag(org.eclipse.linuxtools.internal.rpm.ui.editor.parser.SpecfileTag) StringReader(java.io.StringReader) SpecfilePatchMacro(org.eclipse.linuxtools.internal.rpm.ui.editor.parser.SpecfilePatchMacro) IOException(java.io.IOException) LineNumberReader(java.io.LineNumberReader)

Example 3 with SpecfileTag

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

the class SpecfileParser method parseDirectDefinition.

private SpecfileElement parseDirectDefinition(String lineText, Specfile specfile, int lineNumber) {
    String[] parts = lineText.split(DEFINE_SEPARATOR, 2);
    SpecfileTag directDefinition;
    if (parts.length == 2) {
        directDefinition = new SpecfileTag(parts[0], parts[1].trim(), specfile, activePackage);
        directDefinition.setLineNumber(lineNumber);
    } else {
        errorHandler.handleError(new // $NON-NLS-1$
        SpecfileParseException(// $NON-NLS-1$
        parts[0] + Messages.getString("SpecfileParser.14"), // $NON-NLS-1$
        lineNumber, 0, lineText.length(), IMarker.SEVERITY_ERROR));
        directDefinition = null;
    }
    return directDefinition;
}
Also used : SpecfileTag(org.eclipse.linuxtools.internal.rpm.ui.editor.parser.SpecfileTag)

Example 4 with SpecfileTag

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

the class SpecfileParser method parseSimpleDefinition.

private SpecfileElement parseSimpleDefinition(String lineText, Specfile specfile, int lineNumber, boolean warnMultipleValues) {
    List<String> tokens = Arrays.asList(lineText.split(SPACE_REGEX));
    SpecfileTag toReturn = null;
    for (Iterator<String> iter = tokens.iterator(); iter.hasNext(); ) {
        String token = iter.next();
        if (token.length() <= 0) {
            break;
        }
        if (iter.hasNext()) {
            String possValue = iter.next();
            if (possValue.startsWith("%") && iter.hasNext()) {
                // $NON-NLS-1$
                possValue += ' ' + iter.next();
            }
            toReturn = new SpecfileTag(token.substring(0, token.length() - 1).toLowerCase(), possValue, specfile, null);
            if (iter.hasNext() && !warnMultipleValues) {
                errorHandler.handleError(new SpecfileParseException(// $NON-NLS-1$
                token.substring(0, token.length() - 1) + Messages.getString("SpecfileParser.13"), lineNumber, 0, lineText.length(), IMarker.SEVERITY_ERROR));
                return null;
            }
        } else {
            errorHandler.handleError(new SpecfileParseException(// $NON-NLS-1$
            token.substring(0, token.length() - 1) + Messages.getString("SpecfileParser.14"), // $NON-NLS-1$
            lineNumber, 0, lineText.length(), IMarker.SEVERITY_ERROR));
            toReturn = null;
        }
    }
    if ((toReturn != null)) {
        String returnStringValue = toReturn.getStringValue();
        if (returnStringValue != null) {
            try {
                int intValue = Integer.parseInt(returnStringValue);
                toReturn.setValue(intValue);
            } catch (NumberFormatException e) {
                if (toReturn.getName().equalsIgnoreCase(RpmTags.EPOCH)) {
                    errorHandler.handleError(new // $NON-NLS-1$
                    SpecfileParseException(// $NON-NLS-1$
                    Messages.getString("SpecfileParser.16"), // $NON-NLS-1$
                    lineNumber, 0, lineText.length(), IMarker.SEVERITY_ERROR));
                    toReturn = null;
                }
            }
        }
    }
    return toReturn;
}
Also used : SpecfileParseException(org.eclipse.linuxtools.internal.rpm.ui.editor.parser.SpecfileParseException) SpecfileTag(org.eclipse.linuxtools.internal.rpm.ui.editor.parser.SpecfileTag)

Aggregations

SpecfileTag (org.eclipse.linuxtools.internal.rpm.ui.editor.parser.SpecfileTag)4 IOException (java.io.IOException)1 LineNumberReader (java.io.LineNumberReader)1 StringReader (java.io.StringReader)1 SpecfileParseException (org.eclipse.linuxtools.internal.rpm.ui.editor.parser.SpecfileParseException)1 SpecfilePatchMacro (org.eclipse.linuxtools.internal.rpm.ui.editor.parser.SpecfilePatchMacro)1 SpecfileSource (org.eclipse.linuxtools.internal.rpm.ui.editor.parser.SpecfileSource)1 SpecfilePackage (org.eclipse.linuxtools.rpm.ui.editor.parser.SpecfilePackage)1 GridData (org.eclipse.swt.layout.GridData)1 GridLayout (org.eclipse.swt.layout.GridLayout)1 RowLayout (org.eclipse.swt.layout.RowLayout)1 Composite (org.eclipse.swt.widgets.Composite)1 ExpandableComposite (org.eclipse.ui.forms.widgets.ExpandableComposite)1 FormToolkit (org.eclipse.ui.forms.widgets.FormToolkit)1 ScrolledForm (org.eclipse.ui.forms.widgets.ScrolledForm)1 Section (org.eclipse.ui.forms.widgets.Section)1