mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

Gaetan Boismal
09.49.2016 184c555add883a82495a5fe8bebcd5f97f841ec6
Minor makeldif fixes

* Prints a correct line number in warning/error messages
The line number variable is used to access the lines array so the
first line number is 0. It's misleading for UI messages beacause file
editors usually starts with line 1.
* Do not try to replace constants on a commented line
* Improve makeldif error messages readability
2 files modified
53 ■■■■ changed files
opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldif/TemplateFile.java 47 ●●●●● patch | view | raw | blame | history
opendj-sdk/opendj-core/src/main/resources/com/forgerock/opendj/ldap/core.properties 6 ●●●● patch | view | raw | blame | history
opendj-sdk/opendj-core/src/main/java/org/forgerock/opendj/ldif/TemplateFile.java
@@ -425,8 +425,13 @@
        TemplateData templateData = new TemplateData();
        for (int lineNumber = 0; lineNumber < lines.length; lineNumber++) {
            final String line = replaceConstants(lines[lineNumber], lineNumber, constants, warnings);
            final String currentRawLine = lines[lineNumber];
            if (currentRawLine.isEmpty() || currentRawLine.startsWith("#")) {
                // This is a comment or a blank line, so we'll ignore it.
                continue;
            }
            final String line = replaceConstants(currentRawLine, lineNumber, constants, warnings);
            final String lowerLine = line.toLowerCase();
            if (line.length() == 0 || line.startsWith("#")) {
                // This is a comment or a blank line, so we'll ignore it.
@@ -441,7 +446,7 @@
                lineNumber = parseTemplate(lineNumber, line, lines, templateData, warnings);
            } else {
                throw DecodeException.fatalError(
                        ERR_ENTRY_GENERATOR_UNEXPECTED_TEMPLATE_FILE_LINE.get(line, lineNumber));
                        ERR_ENTRY_GENERATOR_UNEXPECTED_TEMPLATE_FILE_LINE.get(line, lineNumber + 1));
            }
        }
@@ -506,17 +511,17 @@
        // an equal sign, and the constant value.
        final int equalPos = line.indexOf('=', DEFINE_LABEL.length());
        if (equalPos < 0) {
            throw DecodeException.fatalError(ERR_ENTRY_GENERATOR_DEFINE_MISSING_EQUALS.get(lineNumber));
            throw DecodeException.fatalError(ERR_ENTRY_GENERATOR_DEFINE_MISSING_EQUALS.get(lineNumber + 1));
        }
        final String name = line.substring(DEFINE_LABEL.length(), equalPos).trim();
        if (name.length() == 0) {
            throw DecodeException.fatalError(ERR_ENTRY_GENERATOR_DEFINE_NAME_EMPTY.get(lineNumber));
            throw DecodeException.fatalError(ERR_ENTRY_GENERATOR_DEFINE_NAME_EMPTY.get(lineNumber + 1));
        }
        final String value = line.substring(equalPos + 1);
        if (value.length() == 0) {
            warnings.add(ERR_ENTRY_GENERATOR_WARNING_DEFINE_VALUE_EMPTY.get(name, lineNumber));
            warnings.add(ERR_ENTRY_GENERATOR_WARNING_DEFINE_VALUE_EMPTY.get(name, lineNumber + 1));
        }
        final String lowerName = name.toLowerCase();
@@ -537,7 +542,7 @@
        final DN branchDN = branch.getBranchDN();
        if (templateData.branches.containsKey(branchDN)) {
            throw DecodeException.fatalError(
                    ERR_ENTRY_GENERATOR_CONFLICTING_BRANCH_DN.get(String.valueOf(branchDN), startLineNumber));
                    ERR_ENTRY_GENERATOR_CONFLICTING_BRANCH_DN.get(String.valueOf(branchDN), startLineNumber + 1));
        }
        templateData.branches.put(branchDN, branch);
        // position to next line after end of branch
@@ -557,7 +562,7 @@
        final String lowerName = template.getName().toLowerCase();
        if (templateData.templates.containsKey(lowerName)) {
            throw DecodeException.fatalError(ERR_ENTRY_GENERATOR_CONFLICTING_TEMPLATE_NAME.get(
                    String.valueOf(template.getName()), startLineNumber));
                    String.valueOf(template.getName()), startLineNumber + 1));
        }
        templateData.templates.put(lowerName, template);
        // position to next line after end of template
@@ -635,7 +640,7 @@
                    if (constantValue != null) {
                        lineBuffer.replace(openPos, closePos + 1, constantValue);
                    } else {
                        warnings.add(WARN_ENTRY_GENERATOR_WARNING_UNDEFINED_CONSTANT.get(constantName, lineNumber));
                        warnings.add(WARN_ENTRY_GENERATOR_WARNING_UNDEFINED_CONSTANT.get(constantName, lineNumber + 1));
                    }
                }
                if (openPos >= 0) {
@@ -676,8 +681,8 @@
        try {
            branchDN = DN.valueOf(dnString, schema);
        } catch (Exception e) {
            throw DecodeException.fatalError(ERR_ENTRY_GENERATOR_CANNOT_DECODE_BRANCH_DN.get(
                    dnString, startLineNumber));
            throw DecodeException.fatalError(
                    ERR_ENTRY_GENERATOR_CANNOT_DECODE_BRANCH_DN.get(dnString, startLineNumber + 1));
        }
        final Branch branch = new Branch(this, branchDN, schema);
@@ -751,7 +756,7 @@
                parentTemplate = definedTemplates.get(parentTemplateName.toLowerCase());
                if (parentTemplate == null) {
                    throw DecodeException.fatalError(ERR_ENTRY_GENERATOR_TEMPLATE_INVALID_PARENT_TEMPLATE.get(
                            parentTemplateName, lineNumber, templateName));
                            parentTemplateName, lineNumber + 1, templateName));
                }
            } else if (lowerLine.startsWith(RDNATTR_LABEL)) {
                // This is the set of RDN attributes. If there are multiple,
@@ -833,11 +838,11 @@
                numEntries = Integer.parseInt(line.substring(colonPos + 1).trim());
                if (numEntries == 0) {
                    warnings.add(WARN_ENTRY_GENERATOR_SUBORDINATE_ZERO_ENTRIES.get(
                            lineNumber, element.getLabel(), elementName, templateName));
                            lineNumber + 1, element.getLabel(), elementName, templateName));
                }
            } catch (NumberFormatException nfe) {
                throw DecodeException.fatalError(ERR_ENTRY_GENERATOR_SUBORDINATE_CANT_PARSE_NUMENTRIES.get(
                        templateName, lineNumber, element.getLabel(), elementName));
                        templateName, lineNumber + 1, element.getLabel(), elementName));
            }
        }
@@ -882,10 +887,10 @@
        final int colonPos = lowerLine.indexOf(':');
        if (colonPos < 0) {
            throw DecodeException.fatalError(ERR_ENTRY_GENERATOR_NO_COLON_IN_TEMPLATE_LINE.get(
                    lineNumber, element.getLabel(), elementName));
                    lineNumber + 1, element.getLabel(), elementName));
        } else if (colonPos == 0) {
            throw DecodeException.fatalError(ERR_ENTRY_GENERATOR_NO_ATTR_IN_TEMPLATE_LINE.get(
                    lineNumber, element.getLabel(), elementName));
                    lineNumber + 1, element.getLabel(), elementName));
        }
        final AttributeType attributeType = schema.getAttributeType(lowerLine.substring(0, colonPos));
@@ -913,7 +918,7 @@
            // We've hit the end of the line with no value.
            // We'll allow it, but add a warning.
            warnings.add(WARN_ENTRY_GENERATOR_NO_VALUE_IN_TEMPLATE_LINE.get(
                    lineNumber, element.getLabel(), elementName));
                    lineNumber + 1, element.getLabel(), elementName));
        }
        int phase = PARSING_STATIC_TEXT;
@@ -1011,7 +1016,7 @@
                tagList.add(t);
            }
        } else {
            throw DecodeException.fatalError(ERR_ENTRY_GENERATOR_INCOMPLETE_TAG.get(lineNumber));
            throw DecodeException.fatalError(ERR_ENTRY_GENERATOR_INCOMPLETE_TAG.get(lineNumber + 1));
        }
        return new TemplateLine(attributeType, lineNumber, tagList, valueIsURL, valueIsBase64);
@@ -1053,7 +1058,7 @@
        if (tag == null) {
            tag = tags.get(lowerTagName);
            if (tag == null) {
                throw DecodeException.fatalError(ERR_ENTRY_GENERATOR_NO_SUCH_TAG.get(tagName, lineNumber));
                throw DecodeException.fatalError(ERR_ENTRY_GENERATOR_NO_SUCH_TAG.get(tagName, lineNumber + 1));
            }
        }
@@ -1068,7 +1073,7 @@
            newTag = tag.getClass().newInstance();
        } catch (Exception e) {
            throw DecodeException.fatalError(ERR_ENTRY_GENERATOR_CANNOT_INSTANTIATE_NEW_TAG.get(
                    tagName, lineNumber, String.valueOf(e)), e);
                    tagName, lineNumber + 1, String.valueOf(e)), e);
        }
        if (branch == null) {
@@ -1076,8 +1081,8 @@
        } else if (newTag.allowedInBranch()) {
            newTag.initializeForBranch(schema, this, branch, arguments, lineNumber, warnings);
        } else {
            throw DecodeException.fatalError(ERR_ENTRY_GENERATOR_TAG_NOT_ALLOWED_IN_BRANCH.get(newTag.getName(),
                    lineNumber));
            throw DecodeException.fatalError(
                    ERR_ENTRY_GENERATOR_TAG_NOT_ALLOWED_IN_BRANCH.get(newTag.getName(), lineNumber + 1));
        }
        return newTag;
    }
opendj-sdk/opendj-core/src/main/resources/com/forgerock/opendj/ldap/core.properties
@@ -1475,14 +1475,14 @@
 class %s because the tag name %s conflicts with the name of another tag that \
 has already been registered
WARN_ENTRY_GENERATOR_WARNING_UNDEFINED_CONSTANT=Possible reference to an \
 undefined constant %s on line %d
 undefined constant '%s' on line %d
ERR_ENTRY_GENERATOR_DEFINE_MISSING_EQUALS=The constant definition on line \
 %d is missing an equal sign to delimit the constant name from the value
ERR_ENTRY_GENERATOR_DEFINE_NAME_EMPTY=The constant definition on line %d \
 does not include a name for the constant
ERR_ENTRY_GENERATOR_WARNING_DEFINE_VALUE_EMPTY=Constant %s defined on line \
ERR_ENTRY_GENERATOR_WARNING_DEFINE_VALUE_EMPTY=Constant '%s' defined on line \
 %d has not been assigned a value
ERR_ENTRY_GENERATOR_CONFLICTING_BRANCH_DN=The branch definition %s starting \
ERR_ENTRY_GENERATOR_CONFLICTING_BRANCH_DN=The branch definition '%s' starting \
 on line %d conflicts with an earlier branch definition contained in the \
 template file
ERR_ENTRY_GENERATOR_CONFLICTING_TEMPLATE_NAME=The template definition %s \