Search in sources :

Example 1 with SpecfileParseException

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

the class SpecfileParser method parseSection.

private SpecfileSection parseSection(String lineText, Specfile specfile, int lineNumber) {
    List<String> tokens = Arrays.asList(lineText.split(SPACE_REGEX));
    SpecfileSection toReturn = null;
    boolean isSimpleSection = false;
    for (Iterator<String> iter = tokens.iterator(); iter.hasNext(); ) {
        String token = iter.next();
        // Simple Section Headers
        for (String simpleSection : simpleSections) {
            if (token.equals(simpleSection)) {
                toReturn = new SpecfileSection(token.substring(1), specfile);
                specfile.addSection(toReturn);
                isSimpleSection = true;
            }
        }
        // Complex Section Headers
        for (String complexSection : complexSections) {
            if (token.equals(complexSection)) {
                String name = token.substring(1);
                if (!name.equals("package")) {
                    // $NON-NLS-1$
                    toReturn = new SpecfileSection(name, specfile);
                    specfile.addComplexSection(toReturn);
                }
                while (iter.hasNext()) {
                    String nextToken = iter.next();
                    if (nextToken.equals("-n")) {
                        // $NON-NLS-1$
                        if (!iter.hasNext()) {
                            errorHandler.handleError(new SpecfileParseException(// $NON-NLS-1$
                            Messages.getString("SpecfileParser.1") + name + // $NON-NLS-1$
                            Messages.getString("SpecfileParser.2"), lineNumber, 0, lineText.length(), IMarker.SEVERITY_ERROR));
                            continue;
                        }
                        nextToken = iter.next();
                        if (nextToken.startsWith("-")) {
                            // $NON-NLS-1$
                            errorHandler.handleError(new SpecfileParseException(// $NON-NLS-1$
                            Messages.getString("SpecfileParser.3") + nextToken + // $NON-NLS-1$
                            Messages.getString("SpecfileParser.4"), lineNumber, 0, lineText.length(), IMarker.SEVERITY_ERROR));
                        }
                    } else if (nextToken.equals("-p")) {
                        // FIXME: rest of line is the actual section
                        break;
                    } else if (nextToken.equals("-f")) {
                        // $NON-NLS-1$
                        break;
                    }
                    // this is a package
                    if (toReturn == null) {
                        SpecfilePackage tmpPackage = specfile.getPackage(nextToken);
                        if (tmpPackage == null) {
                            tmpPackage = new SpecfilePackage(nextToken, specfile);
                            specfile.addPackage(tmpPackage);
                        }
                        activePackage = tmpPackage;
                        return tmpPackage;
                    }
                    // this is another section
                    SpecfilePackage enclosingPackage = specfile.getPackage(nextToken);
                    if (enclosingPackage == null) {
                        enclosingPackage = new SpecfilePackage(nextToken, specfile);
                        specfile.addPackage(enclosingPackage);
                    }
                    toReturn.setPackage(enclosingPackage);
                    enclosingPackage.addSection(toReturn);
                }
            }
        }
    }
    // it
    if (toReturn != null && toReturn.getPackage() == null) {
        SpecfilePackage topPackage = specfile.getPackage(specfile.getName());
        if (topPackage == null) {
            topPackage = new SpecfilePackage(specfile.getName(), specfile);
            specfile.addPackage(topPackage);
        }
        if (!isSimpleSection) {
            topPackage.addSection(toReturn);
        }
    }
    if (lastSection != null) {
        lastSection.setSectionEndLine(lineNumber);
    }
    return toReturn;
}
Also used : SpecfileParseException(org.eclipse.linuxtools.internal.rpm.ui.editor.parser.SpecfileParseException)

Example 2 with SpecfileParseException

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

the class SpecfileParser method parsePatch.

private SpecfileElement parsePatch(String lineText, int lineNumber) {
    SpecfilePatchMacro toReturn = null;
    List<String> tokens = Arrays.asList(lineText.split(SPACE_REGEX));
    for (String token : tokens) {
        // %patchN+
        try {
            if (token.startsWith("%patch")) {
                // $NON-NLS-1$
                int patchNumber = 0;
                if (token.length() > 6) {
                    patchNumber = Integer.parseInt(token.substring(6));
                }
                toReturn = new SpecfilePatchMacro(patchNumber);
            }
        } catch (NumberFormatException e) {
            errorHandler.handleError(new // $NON-NLS-1$
            SpecfileParseException(// $NON-NLS-1$
            Messages.getString("SpecfileParser.5"), lineNumber, 0, lineText.length(), IMarker.SEVERITY_ERROR));
            return null;
        }
    }
    return toReturn;
}
Also used : SpecfileParseException(org.eclipse.linuxtools.internal.rpm.ui.editor.parser.SpecfileParseException) SpecfilePatchMacro(org.eclipse.linuxtools.internal.rpm.ui.editor.parser.SpecfilePatchMacro)

Example 3 with SpecfileParseException

use of org.eclipse.linuxtools.internal.rpm.ui.editor.parser.SpecfileParseException 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

SpecfileParseException (org.eclipse.linuxtools.internal.rpm.ui.editor.parser.SpecfileParseException)3 SpecfilePatchMacro (org.eclipse.linuxtools.internal.rpm.ui.editor.parser.SpecfilePatchMacro)1 SpecfileTag (org.eclipse.linuxtools.internal.rpm.ui.editor.parser.SpecfileTag)1