/** * Returns the key to the label to use as a label for the rendered link. * * @return the key to the label to use as a label for the rendered link. */ public String getLabelKey() { return strategy.getConfig().getLabelKey(); }
/** * Default constructor. * * @param config the configuration of this strategy instance. * @throws NullArgumentException if <code>config</code> is <code>null</code>. */ protected AbstractLinkConstructorStrategy( final LinkConstructorStrategyConfig config) throws NullArgumentException { checkArguments(config); this.config = config; }
/** * Constructs a link to the given Java element. * * @param packageName packageName the name of the package. * @param typeName typeName the name of the Java type. * @param method the test method to link to. * @return the requested relative link. */ public String constructLink(final String packageName, final String typeName, final MethodInfo method) { final JavaElementRef ref = new JavaElementRef(packageName, typeName, method); return constructLink(ref); }
/** * Constructs a path to the specified Java element. * * @param baseLink the base link to prepend. * @param ref the element in the report to reference. * @return the path to the element or <code>null</code> if the referenced * element does not exit (only the existence of the file is checked, * not the element within the file). */ public String constructLink(final String baseLink, final JavaElementRef ref) { if (isReferencedReportExisting(ref)) { final StringBuilder buffer = new StringBuilder(64); buffer.append(baseLink); appendBasePathSeparator(buffer); addQualifiedType(buffer, ref); final MethodInfo memberName = ref.getElementName(); if (config.isReferenceMember() && memberName != null) { appendMemberPart(buffer, memberName); } return buffer.toString(); } return null; }
void renderTestMethodLink(final ExternalReport report) { final String messageKey = report.getLabelKey(); final Type type = getType(); final String link = report.constructLink(type.getPackageName(), type.getTypeName(), getTestMethod()); if (link != null) { sink.link(link); final String label = messages.getLabel(messageKey); sink.text(label); sink.link_(); } }
/** * Adds package and type part of the element reference. * * @param buffer the buffer to append to. * @param ref the element in the report to reference. */ protected void addQualifiedType(final StringBuilder buffer, final JavaElementRef ref) { final String packageName = ref.getPackageName(); if (StringUtils.isNotBlank(packageName)) { addPackagePart(buffer, packageName); } final String typeName = ref.getTypeName(); appendTypePart(buffer, typeName); }
private String createRelativeReportLocationLink(final ReportId reportId, final LinkConstructorStrategy strategy) { final LinkConstructorStrategyConfig config = strategy.getConfig(); final File reportLocation = config.getReportLocation(); final String reportArtifactId = reportId.getReportArtifactId(); final String location; if (reportLocation.exists() || isReportPluginRegistered(reportArtifactId)) { location = calcRelativePath(reportLocation); } else { location = null; if (log != null && log.isWarnEnabled()) { log.warn("Cannot locate report of '" + reportArtifactId + "'. Disabling references to that report."); } } return location; }
private ReportId provideLinkConstructor( // NOPMD final boolean addReport, final String reportArtifactId, final String reportType, final File location, final boolean linkToMember, final String labelKey) throws MavenReportException { final LinkConstructorStrategy strategy = createStrategy(reportArtifactId, location, linkToMember, labelKey); final ReportId reportId = new ReportId(reportArtifactId, reportType); if (reports.registerReport(addReport, reportId, strategy)) { return reportId; } return null; }
private boolean isReferencedReportExisting(final JavaElementRef ref) { final File baseDir = config.getReportLocation(); final StringBuilder buffer = new StringBuilder(); constructFilePath(buffer, ref); final String filePath = buffer.toString(); final File file = new File(baseDir, filePath); return file.exists(); }
factory.createExternalReport(reportId, strategy); final boolean created = report != null; if (created)
/** * Adds package and type part of the element reference. * * @param buffer the buffer to append to. * @param ref the element in the report to reference. */ protected void constructFilePath(final StringBuilder buffer, final JavaElementRef ref) { addQualifiedType(buffer, ref); }
/** * Constructs a link to the given Java Element. * * @param ref the element to link to. * @return the requested relative link. */ public String constructLink(final JavaElementRef ref) { return strategy.constructLink(basePath, ref); }
/** * Default constructor. * * @param reportArtifactId the report artifact ID this strategy is constructed * for. * @param reportType the type of report generated by the * {@link #getReportArtifactId()} to reference. */ public ReportId(final String reportArtifactId, final String reportType) { checkArguments(reportArtifactId, reportType); this.reportArtifactId = reportArtifactId; this.reportType = reportType; }
/** * Default constructor. * * @param packageName the name of the package. * @param typeName the name of the Java class. * @param elementName the name of the element. * @throws IllegalArgumentException if <code>typeName</code> is blank or * <code>packageName</code> is empty or consists only of * whitespaces. * @todo All elements are currently provided to be fully URL encoded. */ public JavaElementRef(final String packageName, final String typeName, final MethodInfo elementName) throws IllegalArgumentException { checkArguments(packageName, typeName); this.packageName = packageName; this.typeName = typeName; this.elementName = elementName; }
/** * Default constructor. * * @param reportId the report ID this strategy is constructed for. * @param basePath the base path to the report to prefix the constructed link. * @param strategy the strategy to construct the link suffix to the base path. * @throws IllegalArgumentException if <code>helper</code> or * <code>reportLocation</code> is <code>null</code> or * <code>reportArtifactId</code> is blank. */ public ExternalReport(final ReportId reportId, final String basePath, final LinkConstructorStrategy strategy) throws IllegalArgumentException { checkArguments(reportId, basePath, strategy); this.reportId = reportId; this.basePath = basePath; this.strategy = strategy; }
/** * Adds the type part of the link. * * @param buffer the buffer to append to. * @param typeName the name of the package to render. * @impl The default implementation adds the extension separated by a dot. */ protected void appendTypePart(final StringBuilder buffer, final String typeName) { buffer.append(typeName).append('.').append(config.getExtension()); }
/** * Creates the congfiguration instance. * * @return the congfiguration instance. */ public LinkConstructorStrategyConfig build() { if (reportLocation == null) { throw new IllegalArgumentException( "The report location must not be 'null'"); } if (StringUtils.isBlank(labelKey)) { throw new IllegalArgumentException( "The label for the link must not be blank."); } return new LinkConstructorStrategyConfig(this); }
/** * {@inheritDoc} */ public ExternalReport createExternalReport(final ReportId reportId, final LinkConstructorStrategy strategy) { if (reportId == null) { throw new IllegalArgumentException("The report ID is required."); } if (strategy == null) { throw new IllegalArgumentException( "The link construction strategy is required."); } final String reportBasePath = createRelativeReportLocationLink(reportId, strategy); if (reportBasePath != null) { return new ExternalReport(reportId, reportBasePath, strategy); } else { return null; } }
void renderTestMethodLink(final ExternalReport report) { final String messageKey = report.getLabelKey(); final Type type = getType(); final String link = report.constructLink(type.getPackageName(), type.getTypeName(), getTestMethod()); if (link != null) { sink.link(link); final String label = messages.getLabel(messageKey); sink.text(label); sink.link_(); } }
private ReportId provideLinkConstructor( // NOPMD final boolean addReport, final String reportArtifactId, final String reportType, final File location, final boolean linkToMember, final String labelKey) throws MavenReportException { final LinkConstructorStrategy strategy = createStrategy(reportArtifactId, location, linkToMember, labelKey); final ReportId reportId = new ReportId(reportArtifactId, reportType); if (reports.registerReport(addReport, reportId, strategy)) { return reportId; } return null; }