Java Code Examples for org.springframework.boot.configurationmetadata.ConfigurationMetadataProperty#getDeprecation()

The following examples show how to use org.springframework.boot.configurationmetadata.ConfigurationMetadataProperty#getDeprecation() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Utils.java    From nb-springboot with Apache License 2.0 5 votes vote down vote up
/**
 * Builds an HTML formatted string with details on a Spring Boot configuration property extracted from its
 * {@code ItemMetadata}.
 *
 * @param cfgMeta the configuration property metadata object
 * @return the HTML formatted configuration property details
 */
public static String cfgPropDetailsHtml(ConfigurationMetadataProperty cfgMeta) {
    StringBuilder sb = new StringBuilder();
    // deprecation (optional)
    Deprecation deprecation = cfgMeta.getDeprecation();
    if (deprecation != null) {
        sb.append("<b>");
        if (isErrorDeprecated(cfgMeta)) {
            sb.append("REMOVED");
        } else {
            sb.append("Deprecated");
        }
        sb.append("</b>");
        // deprecation reason if present
        String reason = deprecation.getReason();
        if (reason != null) {
            sb.append(": ").append(simpleHtmlEscape(reason));
        }
        sb.append("<br/>");
        String replacement = deprecation.getReplacement();
        if (replacement != null) {
            sb.append("<i>Replaced by:</i> <tt>").append(replacement).append("</tt><br/>");
        }
    }
    // description (optional)
    final String description = cfgMeta.getDescription();
    if (description != null) {
        sb.append(description).append("<br/>");
    }
    // type
    sb.append("<tt>").append(simpleHtmlEscape(shortenJavaType(cfgMeta.getType()))).append("</tt>");
    return sb.toString();
}
 
Example 2
Source File: DeprecatedPropsHighlightingTask.java    From nb-springboot with Apache License 2.0 4 votes vote down vote up
@Override
protected void internalRun(CfgPropsParser.CfgPropsParserResult cfgResult, SchedulerEvent se, BaseDocument document,
        List<ErrorDescription> errors, Severity unused) {
    logger.fine("Highlighting deprecated properties");
    final Project prj = Utils.getActiveProject();
    if (prj != null) {
        final SpringBootService sbs = prj.getLookup().lookup(SpringBootService.class);
        if (sbs != null) {
            for (PairElement pair : cfgResult.getCfgFile().getElements()) {
                final CfgElement key = pair.getKey();
                final CfgElement value = pair.getValue();
                final String pName = key.getText();
                ConfigurationMetadataProperty cfgMeta = sbs.getPropertyMetadata(pName);
                if (cfgMeta != null && cfgMeta.getDeprecation() != null) {
                    try {
                        final Deprecation deprecation = cfgMeta.getDeprecation();
                        List<Fix> fixes = new ArrayList<>();
                        final int start = key.getIdxStart();
                        int end = value != null ? value.getIdxEnd() : key.getIdxEnd();
                        fixes.add(new DeletePropFix((StyledDocument) document, key.getText(), key.getIdxStart(), end));
                        if (deprecation.getReplacement() != null) {
                            end = key.getIdxEnd();
                            fixes.add(new ReplacePropFix((StyledDocument) document, start, end, deprecation.getReplacement()));
                        }
                        Deprecation.Level deprLevel = deprecation.getLevel();
                        ErrorDescription errDesc;
                        if (deprLevel == ERROR) {
                            errDesc = ErrorDescriptionFactory.createErrorDescription(
                                    Severity.ERROR,
                                    String.format("No more supported Spring Boot property '%s'", pName),
                                    fixes,
                                    document,
                                    document.createPosition(start),
                                    document.createPosition(end)
                            );
                        } else {
                            errDesc = ErrorDescriptionFactory.createErrorDescription(
                                    Severity.WARNING,
                                    String.format("Deprecated Spring Boot property '%s'", pName),
                                    fixes,
                                    document,
                                    document.createPosition(start),
                                    document.createPosition(end)
                            );
                        }
                        errors.add(errDesc);
                    } catch (BadLocationException ex) {
                        Exceptions.printStackTrace(ex);
                    }
                }
                if (canceled) {
                    break;
                }
            }
        }
    }
    if (!errors.isEmpty()) {
        logger.log(Level.FINE, "Found {0} deprecated properties", errors.size());
    }
}
 
Example 3
Source File: Utils.java    From nb-springboot with Apache License 2.0 4 votes vote down vote up
public static boolean isErrorDeprecated(ConfigurationMetadataProperty meta) {
    Deprecation depr = meta.getDeprecation();
    return depr != null && depr.getLevel() != null && depr.getLevel().equals(Deprecation.Level.ERROR);
}
 
Example 4
Source File: BootApplicationConfigurationMetadataResolver.java    From spring-cloud-dataflow with Apache License 2.0 2 votes vote down vote up
/**
 * Checks if property is error deprecated.
 *
 * @param property the configuration property
 * @return if property is error deprecated
 */
private boolean isDeprecatedError(ConfigurationMetadataProperty property) {
	return property.getDeprecation() != null && property.getDeprecation().getLevel() == Level.ERROR;
}