diff --git a/src/main/java/io/wcm/handler/media/CropDimension.java b/src/main/java/io/wcm/handler/media/CropDimension.java index a4016b2e..37aea47c 100644 --- a/src/main/java/io/wcm/handler/media/CropDimension.java +++ b/src/main/java/io/wcm/handler/media/CropDimension.java @@ -148,6 +148,7 @@ public String toString() { * @return Crop dimension instance * @throws IllegalArgumentException if crop string syntax is invalid */ + @SuppressWarnings("java:S1192") // ignore duplicated strings public static @NotNull CropDimension fromCropString(@NotNull String cropString) { if (StringUtils.isEmpty(cropString)) { throw new IllegalArgumentException("Invalid crop string: '" + cropString + "'."); diff --git a/src/main/java/io/wcm/handler/media/MediaArgs.java b/src/main/java/io/wcm/handler/media/MediaArgs.java index fdafb934..af283690 100644 --- a/src/main/java/io/wcm/handler/media/MediaArgs.java +++ b/src/main/java/io/wcm/handler/media/MediaArgs.java @@ -767,6 +767,7 @@ public boolean equals(Object obj) { } @Override + @SuppressWarnings("java:S3776") // ignore complexity public String toString() { ToStringBuilder sb = new ToStringBuilder(this, ToStringStyle.NO_CLASS_NAME_STYLE); if (mediaFormatOptions != null && mediaFormatOptions.length > 0) { @@ -851,10 +852,9 @@ public String toString() { * Custom clone-method for {@link MediaArgs} * @return the cloned {@link MediaArgs} */ - // CHECKSTYLE:OFF @Override + @SuppressWarnings({ "java:S2975", "java:S1182", "checkstyle:SuperCloneCheck" }) // ignore clone warnings public MediaArgs clone() { //NOPMD - // CHECKSTYLE:ON MediaArgs clone = new MediaArgs(); clone.mediaFormatOptions = ArrayUtils.clone(this.mediaFormatOptions); diff --git a/src/main/java/io/wcm/handler/media/format/MediaFormat.java b/src/main/java/io/wcm/handler/media/format/MediaFormat.java index 0e97bd71..87eb592f 100644 --- a/src/main/java/io/wcm/handler/media/format/MediaFormat.java +++ b/src/main/java/io/wcm/handler/media/format/MediaFormat.java @@ -67,7 +67,7 @@ public final class MediaFormat implements Comparable { private String ratioDisplayString; private String combinedTitle; - //CHECKSTYLE:OFF + @SuppressWarnings({ "java:S107", "checkstyle:ParameterNumberCheck" }) // ignore parameter count MediaFormat(String name, String label, String description, long width, long minWidth, long maxWidth, long height, long minHeight, long maxHeight, long minWidthHeight, double ratio, double ratioWidth, double ratioHeight, long fileSizeMax, String[] extensions, @@ -93,7 +93,6 @@ public final class MediaFormat implements Comparable { this.ranking = ranking; this.properties = properties; } - //CHECKSTYLE:ON /** * @return Media format name @@ -479,6 +478,7 @@ public Dimension getMinDimension() { * @return User-friendly combined title of current media format name and dimension. */ @JsonIgnore + @SuppressWarnings({ "java:S3776", "java:S6541" }) // ignore complexity String getCombinedTitle() { if (combinedTitle == null) { StringBuilder sb = new StringBuilder(); diff --git a/src/main/java/io/wcm/handler/media/format/impl/MediaFormatHandlerImpl.java b/src/main/java/io/wcm/handler/media/format/impl/MediaFormatHandlerImpl.java index 380e1d62..a6fa2379 100644 --- a/src/main/java/io/wcm/handler/media/format/impl/MediaFormatHandlerImpl.java +++ b/src/main/java/io/wcm/handler/media/format/impl/MediaFormatHandlerImpl.java @@ -116,6 +116,7 @@ public MediaFormat getMediaFormat(@NotNull String mediaFormatName) { * @return Matching media formats, sorted by size (biggest first), ranking, name */ @Override + @SuppressWarnings({ "java:S3776", "java:S1066" }) //ignore complexity public @NotNull SortedSet getSameBiggerMediaFormats(@NotNull MediaFormat mediaFormatRequested, boolean filterRenditionGroup) { SortedSet matchingFormats = new TreeSet<>(new MediaFormatSizeRankingComparator()); @@ -163,6 +164,7 @@ public MediaFormat getMediaFormat(@NotNull String mediaFormatName) { * @return Matching media formats, sorted by size (biggest first), ranking, name */ @Override + @SuppressWarnings({ "java:S3776", "java:S1066" }) //ignore complexity public @NotNull SortedSet getSameSmallerMediaFormats(@NotNull MediaFormat mediaFormatRequested, boolean filterRenditionGroup) { SortedSet matchingFormats = new TreeSet<>(new MediaFormatSizeRankingComparator()); @@ -290,6 +292,7 @@ public MediaFormat detectMediaFormat(@Nullable String extension, long fileSize, * @return Matching media formats sorted by their ranking or an empty list if no matching format was found */ @Override + @SuppressWarnings("java:S3776") //ignore complexity public @NotNull SortedSet detectMediaFormats(@Nullable String extension, long fileSize, long width, long height) { // sort media formats by ranking diff --git a/src/main/java/io/wcm/handler/media/impl/AbstractMediaFileServlet.java b/src/main/java/io/wcm/handler/media/impl/AbstractMediaFileServlet.java index 9b14f78d..22cb9da3 100644 --- a/src/main/java/io/wcm/handler/media/impl/AbstractMediaFileServlet.java +++ b/src/main/java/io/wcm/handler/media/impl/AbstractMediaFileServlet.java @@ -19,6 +19,9 @@ */ package io.wcm.handler.media.impl; +import static io.wcm.handler.media.impl.MediaFileServletConstants.HEADER_CONTENT_DISPOSITION; +import static io.wcm.handler.media.impl.MediaFileServletConstants.SELECTOR_DOWNLOAD; + import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -47,16 +50,6 @@ abstract class AbstractMediaFileServlet extends SlingSafeMethodsServlet { private static final long serialVersionUID = 1L; - /** - * Selector for forcing a "save-as" dialog in the browser - */ - public static final String SELECTOR_DOWNLOAD = "download_attachment"; - - /** - * Content disposition header - */ - public static final String HEADER_CONTENT_DISPOSITION = "Content-Disposition"; - @Override @SuppressFBWarnings("RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE") protected void doGet(@NotNull SlingHttpServletRequest request, @NotNull SlingHttpServletResponse response) throws ServletException, IOException { diff --git a/src/main/java/io/wcm/handler/media/impl/AssetRenditionContentDispositionFilter.java b/src/main/java/io/wcm/handler/media/impl/AssetRenditionContentDispositionFilter.java index d37e3519..c3133168 100644 --- a/src/main/java/io/wcm/handler/media/impl/AssetRenditionContentDispositionFilter.java +++ b/src/main/java/io/wcm/handler/media/impl/AssetRenditionContentDispositionFilter.java @@ -23,7 +23,7 @@ import static com.day.cq.commons.jcr.JcrConstants.JCR_MIMETYPE; import static com.day.cq.commons.jcr.JcrConstants.JCR_PRIMARYTYPE; import static com.day.cq.commons.jcr.JcrConstants.NT_FILE; -import static io.wcm.handler.media.impl.AbstractMediaFileServlet.HEADER_CONTENT_DISPOSITION; +import static io.wcm.handler.media.impl.MediaFileServletConstants.HEADER_CONTENT_DISPOSITION; import static org.apache.sling.api.servlets.HttpConstants.METHOD_GET; import java.io.IOException; diff --git a/src/main/java/io/wcm/handler/media/impl/ImageFileServlet.java b/src/main/java/io/wcm/handler/media/impl/ImageFileServlet.java index 354fe98d..6d567dd8 100644 --- a/src/main/java/io/wcm/handler/media/impl/ImageFileServlet.java +++ b/src/main/java/io/wcm/handler/media/impl/ImageFileServlet.java @@ -49,7 +49,7 @@ * Optional support for Content-Disposition header ("download_attachment"). */ @Component(service = Servlet.class, immediate = true, property = { - "sling.servlet.extensions=" + MediaFileServlet.EXTENSION, + "sling.servlet.extensions=" + MediaFileServletConstants.EXTENSION, "sling.servlet.selectors=" + ImageFileServlet.SELECTOR, "sling.servlet.resourceTypes=" + JcrConstants.NT_FILE, "sling.servlet.resourceTypes=" + JcrConstants.NT_RESOURCE, diff --git a/src/main/java/io/wcm/handler/media/impl/ImageFileServletSelector.java b/src/main/java/io/wcm/handler/media/impl/ImageFileServletSelector.java index f49395f4..b5dd9f84 100644 --- a/src/main/java/io/wcm/handler/media/impl/ImageFileServletSelector.java +++ b/src/main/java/io/wcm/handler/media/impl/ImageFileServletSelector.java @@ -159,7 +159,7 @@ else if (imageQualityPercentage != null) { } } if (contentDispositionAttachment) { - result.append(".").append(AbstractMediaFileServlet.SELECTOR_DOWNLOAD); + result.append(".").append(MediaFileServletConstants.SELECTOR_DOWNLOAD); } return result.toString(); diff --git a/src/main/java/io/wcm/handler/media/impl/MediaFileServlet.java b/src/main/java/io/wcm/handler/media/impl/MediaFileServlet.java index 84173c23..7b442115 100644 --- a/src/main/java/io/wcm/handler/media/impl/MediaFileServlet.java +++ b/src/main/java/io/wcm/handler/media/impl/MediaFileServlet.java @@ -31,8 +31,8 @@ * Optional support for Content-Disposition header ("download_attachment"). */ @Component(service = Servlet.class, immediate = true, property = { - "sling.servlet.extensions=" + MediaFileServlet.EXTENSION, - "sling.servlet.selectors=" + MediaFileServlet.SELECTOR, + "sling.servlet.extensions=" + MediaFileServletConstants.EXTENSION, + "sling.servlet.selectors=" + MediaFileServletConstants.SELECTOR, "sling.servlet.resourceTypes=" + JcrConstants.NT_FILE, "sling.servlet.resourceTypes=" + JcrConstants.NT_RESOURCE, "sling.servlet.methods=" + HttpConstants.METHOD_GET @@ -40,14 +40,6 @@ public final class MediaFileServlet extends AbstractMediaFileServlet { private static final long serialVersionUID = 1L; - /** - * Selector - */ - public static final String SELECTOR = "media_file"; - - /** - * Extension - */ - public static final String EXTENSION = "file"; + // inherits all functionality } diff --git a/src/main/java/io/wcm/handler/media/impl/MediaFileServletConstants.java b/src/main/java/io/wcm/handler/media/impl/MediaFileServletConstants.java new file mode 100644 index 00000000..a6b4be71 --- /dev/null +++ b/src/main/java/io/wcm/handler/media/impl/MediaFileServletConstants.java @@ -0,0 +1,51 @@ +/* + * #%L + * wcm.io + * %% + * Copyright (C) 2024 wcm.io + * %% + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * #L% + */ +package io.wcm.handler.media.impl; + +/** + * Constants for {@link MediaFileServlet} and {@link ImageFileServlet}. + */ +public final class MediaFileServletConstants { + + /** + * Selector for forcing a "save-as" dialog in the browser + */ + public static final String SELECTOR_DOWNLOAD = "download_attachment"; + + /** + * Content disposition header + */ + public static final String HEADER_CONTENT_DISPOSITION = "Content-Disposition"; + + /** + * Selector + */ + public static final String SELECTOR = "media_file"; + + /** + * Extension + */ + public static final String EXTENSION = "file"; + + private MediaFileServletConstants() { + // constants only + } + +} diff --git a/src/main/java/io/wcm/handler/media/impl/MediaHandlerImpl.java b/src/main/java/io/wcm/handler/media/impl/MediaHandlerImpl.java index 9af095a6..7d0c2a6b 100644 --- a/src/main/java/io/wcm/handler/media/impl/MediaHandlerImpl.java +++ b/src/main/java/io/wcm/handler/media/impl/MediaHandlerImpl.java @@ -114,9 +114,13 @@ public final class MediaHandlerImpl implements MediaHandler { * @param mediaRequest Media request * @return Media metadata (never null) */ - @SuppressWarnings({ "null", "unused" }) - @SuppressFBWarnings({ "CORRECTNESS", "STYLE" }) @NotNull + @SuppressWarnings({ + "null", "unused", + "java:S3776", "java:S6541", // ignore complexity + "java:S112" // allow runtime exception + }) + @SuppressFBWarnings({ "CORRECTNESS", "STYLE" }) Media processRequest(@NotNull final MediaRequest mediaRequest) { // detect media source @@ -286,6 +290,7 @@ private boolean resolveDownloadMediaFormats(MediaArgs mediaArgs) { } @Override + @SuppressWarnings("java:S112") // allow runtime exception public Media invalid() { // build invalid media with first media source Class mediaSourceClass = mediaHandlerConfig.getSources().stream().findFirst().orElse(null); diff --git a/src/main/java/io/wcm/handler/media/markup/DummyImageMediaMarkupBuilder.java b/src/main/java/io/wcm/handler/media/markup/DummyImageMediaMarkupBuilder.java index 726a3e9f..79674768 100644 --- a/src/main/java/io/wcm/handler/media/markup/DummyImageMediaMarkupBuilder.java +++ b/src/main/java/io/wcm/handler/media/markup/DummyImageMediaMarkupBuilder.java @@ -72,7 +72,7 @@ && getWcmMode() != WCMMode.DISABLED && mediaArgs.isDummyImage(); } - @SuppressWarnings({ "null", "unused" }) + @SuppressWarnings({ "null", "unused", "java:S2589" }) @SuppressFBWarnings("STYLE") @Override public HtmlElement build(@NotNull Media media) { diff --git a/src/main/java/io/wcm/handler/media/markup/MediaMarkupBuilderUtil.java b/src/main/java/io/wcm/handler/media/markup/MediaMarkupBuilderUtil.java index 5031ded1..e8a30e11 100644 --- a/src/main/java/io/wcm/handler/media/markup/MediaMarkupBuilderUtil.java +++ b/src/main/java/io/wcm/handler/media/markup/MediaMarkupBuilderUtil.java @@ -74,7 +74,10 @@ private MediaMarkupBuilderUtil() { * @param request Servlet request * @param mediaHandlerConfig Media handler config (can be null, but should not be null) */ - @SuppressWarnings("null") + @SuppressWarnings({ + "null", + "java:S3776" // ignore complexity + }) @SuppressFBWarnings("NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE") public static void addDiffDecoration(@NotNull HtmlElement mediaElement, @NotNull Resource resource, @NotNull String refProperty, @NotNull SlingHttpServletRequest request, @Nullable MediaHandlerConfig mediaHandlerConfig) { diff --git a/src/main/java/io/wcm/handler/media/markup/SimpleImageMediaMarkupBuilder.java b/src/main/java/io/wcm/handler/media/markup/SimpleImageMediaMarkupBuilder.java index 96fe7e3c..5b88bb28 100644 --- a/src/main/java/io/wcm/handler/media/markup/SimpleImageMediaMarkupBuilder.java +++ b/src/main/java/io/wcm/handler/media/markup/SimpleImageMediaMarkupBuilder.java @@ -108,6 +108,7 @@ public final HtmlElement build(@NotNull Media media) { * @param media Media metadata * @return img element with properties or null if media metadata is invalid */ + @SuppressWarnings("java:S3776") // ignore complexity protected @Nullable HtmlElement getPictureElement(@NotNull Media media) { PictureSource[] pictureSources = media.getMediaRequest().getMediaArgs().getPictureSources(); @@ -165,6 +166,7 @@ public final HtmlElement build(@NotNull Media media) { * @param media Media metadata * @return img element with properties or null if media metadata is invalid */ + @SuppressWarnings({ "java:S3776", "java:S2589" }) // ignore complexity protected @Nullable HtmlElement getImageElement(@NotNull Media media) { Image img = null; diff --git a/src/main/java/io/wcm/handler/media/ui/MediaPlaceholder.java b/src/main/java/io/wcm/handler/media/ui/MediaPlaceholder.java index 687a3031..7b5dc437 100644 --- a/src/main/java/io/wcm/handler/media/ui/MediaPlaceholder.java +++ b/src/main/java/io/wcm/handler/media/ui/MediaPlaceholder.java @@ -88,7 +88,7 @@ else if (media instanceof ResourceMedia) { return ((ResourceMedia)media).getMetadata(); } log.warn("Invalid 'media' parameter passed to MediaPlaceholder model. " - + "Expected: " + Media.class.getName() + ", actual: " + media.getClass().getName()); + + "Expected: {}, actual: {}", Media.class.getName(), media.getClass().getName()); return null; } diff --git a/src/main/java/io/wcm/handler/mediasource/dam/DamMediaSource.java b/src/main/java/io/wcm/handler/mediasource/dam/DamMediaSource.java index d1df51c4..8766b9bd 100644 --- a/src/main/java/io/wcm/handler/mediasource/dam/DamMediaSource.java +++ b/src/main/java/io/wcm/handler/mediasource/dam/DamMediaSource.java @@ -122,7 +122,10 @@ public boolean accepts(@Nullable String mediaRef) { } @Override - @SuppressWarnings("null") + @SuppressWarnings({ + "null", + "java:S3776" // ignore complexity + }) @SuppressFBWarnings("NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE") public @NotNull Media resolveMedia(@NotNull Media media) { String mediaRef = getMediaRef(media.getMediaRequest(), mediaHandlerConfig); @@ -180,7 +183,7 @@ else if (StringUtils.isNotEmpty(mediaRef)) { } @Override - @SuppressWarnings("null") + @SuppressWarnings({ "null", "java:S2589" }) public void enableMediaDrop(@NotNull HtmlElement element, @NotNull MediaRequest mediaRequest) { if (wcmMode == WCMMode.DISABLED || wcmMode == null) { return; diff --git a/src/main/java/io/wcm/handler/mediasource/dam/impl/DamAsset.java b/src/main/java/io/wcm/handler/mediasource/dam/impl/DamAsset.java index 05d3a653..430eb5b8 100644 --- a/src/main/java/io/wcm/handler/mediasource/dam/impl/DamAsset.java +++ b/src/main/java/io/wcm/handler/mediasource/dam/impl/DamAsset.java @@ -52,7 +52,7 @@ */ public final class DamAsset extends SlingAdaptable implements Asset { - private final com.day.cq.dam.api.Asset damAsset; + private final com.day.cq.dam.api.Asset asset; private final CropDimension cropDimension; private final Integer rotation; private final MediaArgs defaultMediaArgs; @@ -60,21 +60,21 @@ public final class DamAsset extends SlingAdaptable implements Asset { /** * @param media Media metadata - * @param damAsset DAM asset + * @param asset DAM asset * @param mediaHandlerConfig Media handler config * @param dynamicMediaSupportService Dynamic media support service * @param webOptimizedImageDeliveryService Web optimized image delivery service * @param adaptable Adaptable from current context */ - public DamAsset(Media media, com.day.cq.dam.api.Asset damAsset, MediaHandlerConfig mediaHandlerConfig, + public DamAsset(Media media, com.day.cq.dam.api.Asset asset, MediaHandlerConfig mediaHandlerConfig, DynamicMediaSupportService dynamicMediaSupportService, WebOptimizedImageDeliveryService webOptimizedImageDeliveryService, Adaptable adaptable) { - this.damAsset = damAsset; - this.cropDimension = rescaleCropDimension(damAsset, media.getCropDimension()); + this.asset = asset; + this.cropDimension = rescaleCropDimension(asset, media.getCropDimension()); this.rotation = media.getRotation(); this.defaultMediaArgs = media.getMediaRequest().getMediaArgs(); - this.damContext = new DamContext(damAsset, defaultMediaArgs, mediaHandlerConfig, + this.damContext = new DamContext(asset, defaultMediaArgs, mediaHandlerConfig, dynamicMediaSupportService, webOptimizedImageDeliveryService, adaptable); } @@ -107,7 +107,7 @@ public String getTitle() { * @return Single value */ private @Nullable String getPropertyAwareOfArray(@NotNull String propertyName) { - Object valueObject = damAsset.getMetadataValueFromJcr(propertyName); + Object valueObject = asset.getMetadataValueFromJcr(propertyName); String value = null; if (valueObject != null) { if (valueObject instanceof Object[]) { @@ -146,7 +146,7 @@ public String getDescription() { @Override public @NotNull ValueMap getProperties() { - return new ValueMapDecorator(damAsset.getMetadata()); + return new ValueMapDecorator(asset.getMetadata()); } @Override diff --git a/src/main/java/io/wcm/handler/mediasource/dam/impl/DamRendition.java b/src/main/java/io/wcm/handler/mediasource/dam/impl/DamRendition.java index ea45960f..4d77843f 100644 --- a/src/main/java/io/wcm/handler/mediasource/dam/impl/DamRendition.java +++ b/src/main/java/io/wcm/handler/mediasource/dam/impl/DamRendition.java @@ -60,6 +60,7 @@ class DamRendition extends SlingAdaptable implements Rendition { * @param mediaArgs Media args * @param damContext DAM context objects */ + @SuppressWarnings("java:S3776") // ignore complexity DamRendition(CropDimension cropDimension, Integer rotation, MediaArgs mediaArgs, DamContext damContext) { this.damContext = damContext; this.mediaArgs = mediaArgs; diff --git a/src/main/java/io/wcm/handler/mediasource/dam/impl/DamUriTemplate.java b/src/main/java/io/wcm/handler/mediasource/dam/impl/DamUriTemplate.java index f6ecc8e5..5218090e 100644 --- a/src/main/java/io/wcm/handler/mediasource/dam/impl/DamUriTemplate.java +++ b/src/main/java/io/wcm/handler/mediasource/dam/impl/DamUriTemplate.java @@ -36,7 +36,7 @@ import io.wcm.handler.media.UriTemplateType; import io.wcm.handler.media.impl.ImageFileServlet; import io.wcm.handler.media.impl.ImageFileServletSelector; -import io.wcm.handler.media.impl.MediaFileServlet; +import io.wcm.handler.media.impl.MediaFileServletConstants; import io.wcm.handler.mediasource.dam.impl.dynamicmedia.DynamicMediaPath; import io.wcm.handler.mediasource.dam.impl.dynamicmedia.NamedDimension; import io.wcm.handler.mediasource.dam.impl.dynamicmedia.SmartCrop; @@ -99,7 +99,7 @@ private static String buildUriTemplateDam(@NotNull UriTemplateType type, @NotNul MediaArgs mediaArgs = damContext.getMediaArgs(); String mediaPath = RenditionMetadata.buildMediaPath(rendition.getPath() + "." + ImageFileServletSelector.build(DUMMY_WIDTH, DUMMY_HEIGHT, cropDimension, rotation, imageQualityPercentage, false) - + "." + MediaFileServlet.EXTENSION, + + "." + MediaFileServletConstants.EXTENSION, ImageFileServlet.getImageFileName(damContext.getAsset().getName(), mediaArgs.getEnforceOutputFileExtension())); UrlHandler urlHandler = AdaptTo.notNull(damContext, UrlHandler.class); String url = urlHandler.get(mediaPath).urlMode(mediaArgs.getUrlMode()) diff --git a/src/main/java/io/wcm/handler/mediasource/dam/impl/DefaultRenditionHandler.java b/src/main/java/io/wcm/handler/mediasource/dam/impl/DefaultRenditionHandler.java index 6541597a..cda10b60 100644 --- a/src/main/java/io/wcm/handler/mediasource/dam/impl/DefaultRenditionHandler.java +++ b/src/main/java/io/wcm/handler/mediasource/dam/impl/DefaultRenditionHandler.java @@ -354,6 +354,7 @@ private boolean isSizeMatchingRequest(MediaArgs mediaArgs, String[] requestedFil * @param mediaArgs Media args * @return Rendition or null if none found */ + @SuppressWarnings("java:S3776") // ignore complexity private RenditionMetadata getExactMatchRendition(final Set candidates, MediaArgs mediaArgs) { MediaFormat[] mediaFormats = mediaArgs.getMediaFormats(); // check for fixed width and/or height request diff --git a/src/main/java/io/wcm/handler/mediasource/dam/impl/RenditionMetadata.java b/src/main/java/io/wcm/handler/mediasource/dam/impl/RenditionMetadata.java index 557ed96e..cbfb609c 100644 --- a/src/main/java/io/wcm/handler/mediasource/dam/impl/RenditionMetadata.java +++ b/src/main/java/io/wcm/handler/mediasource/dam/impl/RenditionMetadata.java @@ -42,7 +42,7 @@ import io.wcm.handler.media.format.MediaFormat; import io.wcm.handler.media.format.Ratio; import io.wcm.handler.media.impl.ImageFileServlet; -import io.wcm.handler.media.impl.MediaFileServlet; +import io.wcm.handler.media.impl.MediaFileServletConstants; import io.wcm.handler.mediasource.dam.AssetRendition; import io.wcm.handler.mediasource.dam.impl.dynamicmedia.DynamicMediaPath; import io.wcm.handler.mediasource.dam.impl.weboptimized.WebOptimizedImageDeliveryParams; @@ -179,13 +179,13 @@ public void setMediaFormat(MediaFormat mediaFormat) { */ public @NotNull String getMediaPath(boolean contentDispositionAttachment) { if (contentDispositionAttachment) { - return RenditionMetadata.buildMediaPath(getRendition().getPath() + "." + MediaFileServlet.SELECTOR - + "." + MediaFileServlet.SELECTOR_DOWNLOAD - + "." + MediaFileServlet.EXTENSION, getFileName(contentDispositionAttachment)); + return RenditionMetadata.buildMediaPath(getRendition().getPath() + "." + MediaFileServletConstants.SELECTOR + + "." + MediaFileServletConstants.SELECTOR_DOWNLOAD + + "." + MediaFileServletConstants.EXTENSION, getFileName(contentDispositionAttachment)); } else if (MediaFileType.isVectorImage(getFileExtension())) { - return RenditionMetadata.buildMediaPath(getRendition().getPath() + "." + MediaFileServlet.SELECTOR - + "." + MediaFileServlet.EXTENSION, getFileName(contentDispositionAttachment)); + return RenditionMetadata.buildMediaPath(getRendition().getPath() + "." + MediaFileServletConstants.SELECTOR + + "." + MediaFileServletConstants.EXTENSION, getFileName(contentDispositionAttachment)); } else if (MediaFileType.isBrowserImage(getFileExtension()) || !MediaFileType.isImage(getFileExtension())) { // use "deep URL" to reference rendition directly @@ -196,7 +196,7 @@ else if (MediaFileType.isBrowserImage(getFileExtension()) || !MediaFileType.isIm // image rendition uses a file extension that cannot be displayed in browser directly - render via ImageFileServlet return RenditionMetadata.buildMediaPath(getRendition().getPath() + "." + ImageFileServlet.SELECTOR + "." + getWidth() + "." + getHeight() - + "." + MediaFileServlet.EXTENSION, getFileName(contentDispositionAttachment)); + + "." + MediaFileServletConstants.EXTENSION, getFileName(contentDispositionAttachment)); } } @@ -240,6 +240,7 @@ else if ((MediaFileType.isBrowserImage(getFileExtension()) * @param checkHeight Height * @return true if matches */ + @SuppressWarnings("java:S1126") public boolean matches(long checkWidth, long checkHeight) { if (checkWidth != 0 && checkWidth != getWidth()) { return false; @@ -304,6 +305,7 @@ public boolean equals(Object obj) { } @Override + @SuppressWarnings("java:S3776") // ignore complexity public int compareTo(RenditionMetadata obj) { // always prefer the virtual rendition boolean thisIsVirtualRendition = this instanceof VirtualTransformedRenditionMetadata; diff --git a/src/main/java/io/wcm/handler/mediasource/dam/impl/VirtualRenditionMetadata.java b/src/main/java/io/wcm/handler/mediasource/dam/impl/VirtualRenditionMetadata.java index 1f6dd6e2..5807b2c4 100644 --- a/src/main/java/io/wcm/handler/mediasource/dam/impl/VirtualRenditionMetadata.java +++ b/src/main/java/io/wcm/handler/mediasource/dam/impl/VirtualRenditionMetadata.java @@ -31,7 +31,7 @@ import io.wcm.handler.media.impl.ImageFileServlet; import io.wcm.handler.media.impl.ImageFileServletSelector; -import io.wcm.handler.media.impl.MediaFileServlet; +import io.wcm.handler.media.impl.MediaFileServletConstants; import io.wcm.handler.mediasource.dam.impl.dynamicmedia.DynamicMediaPath; import io.wcm.handler.mediasource.dam.impl.weboptimized.WebOptimizedImageDeliveryParams; @@ -90,7 +90,7 @@ public long getHeight() { return RenditionMetadata.buildMediaPath(getRendition().getPath() + "." + ImageFileServletSelector.build(getWidth(), getHeight(), null, null, this.imageQualityPercentage, contentDispositionAttachment) - + "." + MediaFileServlet.EXTENSION, getFileName(contentDispositionAttachment)); + + "." + MediaFileServletConstants.EXTENSION, getFileName(contentDispositionAttachment)); } @Override diff --git a/src/main/java/io/wcm/handler/mediasource/dam/impl/VirtualTransformedRenditionMetadata.java b/src/main/java/io/wcm/handler/mediasource/dam/impl/VirtualTransformedRenditionMetadata.java index 3aa8ca1a..18e9eb94 100644 --- a/src/main/java/io/wcm/handler/mediasource/dam/impl/VirtualTransformedRenditionMetadata.java +++ b/src/main/java/io/wcm/handler/mediasource/dam/impl/VirtualTransformedRenditionMetadata.java @@ -37,7 +37,7 @@ import io.wcm.handler.media.impl.ImageFileServlet; import io.wcm.handler.media.impl.ImageFileServletSelector; import io.wcm.handler.media.impl.ImageTransformation; -import io.wcm.handler.media.impl.MediaFileServlet; +import io.wcm.handler.media.impl.MediaFileServletConstants; import io.wcm.handler.mediasource.dam.AssetRendition; import io.wcm.handler.mediasource.dam.impl.dynamicmedia.DynamicMediaPath; import io.wcm.handler.mediasource.dam.impl.weboptimized.WebOptimizedImageDeliveryParams; @@ -101,7 +101,7 @@ public Integer getRotation() { return RenditionMetadata.buildMediaPath(getRendition().getPath() + "." + ImageFileServletSelector.build(getWidth(), getHeight(), this.cropDimension, this.rotation, this.imageQualityPercentage, contentDispositionAttachment) - + "." + MediaFileServlet.EXTENSION, getFileName(contentDispositionAttachment)); + + "." + MediaFileServletConstants.EXTENSION, getFileName(contentDispositionAttachment)); } @Override diff --git a/src/main/java/io/wcm/handler/mediasource/dam/impl/metadata/RenditionMetadataListenerService.java b/src/main/java/io/wcm/handler/mediasource/dam/impl/metadata/RenditionMetadataListenerService.java index e5dc9714..7c5744e9 100644 --- a/src/main/java/io/wcm/handler/mediasource/dam/impl/metadata/RenditionMetadataListenerService.java +++ b/src/main/java/io/wcm/handler/mediasource/dam/impl/metadata/RenditionMetadataListenerService.java @@ -135,16 +135,11 @@ private void activate(ComponentContext componentContext, Config config) { } @Deactivate - private void deactivate() { + private void deactivate() throws InterruptedException { this.enabled = false; if (executorService != null) { executorService.shutdown(); - try { - executorService.awaitTermination(10, TimeUnit.SECONDS); - } - catch (InterruptedException ex) { - // ignore - } + executorService.awaitTermination(10, TimeUnit.SECONDS); executorService = null; } } diff --git a/src/main/java/io/wcm/handler/mediasource/inline/InlineAutoCropping.java b/src/main/java/io/wcm/handler/mediasource/inline/InlineAutoCropping.java index 1c12c67e..8a8008e8 100644 --- a/src/main/java/io/wcm/handler/mediasource/inline/InlineAutoCropping.java +++ b/src/main/java/io/wcm/handler/mediasource/inline/InlineAutoCropping.java @@ -58,10 +58,8 @@ public List calculateAutoCropDimensions() { private CropDimension calculateAutoCropDimension(@NotNull MediaFormat mediaFormat) { double ratio = mediaFormat.getRatio(); - if (ratio > 0) { - if (imageDimension.getWidth() > 0 && imageDimension.getHeight() > 0) { - return ImageTransformation.calculateAutoCropDimension(imageDimension.getWidth(), imageDimension.getHeight(), ratio); - } + if (ratio > 0 && imageDimension.getWidth() > 0 && imageDimension.getHeight() > 0) { + return ImageTransformation.calculateAutoCropDimension(imageDimension.getWidth(), imageDimension.getHeight(), ratio); } return null; } diff --git a/src/main/java/io/wcm/handler/mediasource/inline/InlineRendition.java b/src/main/java/io/wcm/handler/mediasource/inline/InlineRendition.java index e5f45095..a739bec7 100644 --- a/src/main/java/io/wcm/handler/mediasource/inline/InlineRendition.java +++ b/src/main/java/io/wcm/handler/mediasource/inline/InlineRendition.java @@ -58,7 +58,7 @@ import io.wcm.handler.media.impl.ImageFileServletSelector; import io.wcm.handler.media.impl.ImageTransformation; import io.wcm.handler.media.impl.JcrBinary; -import io.wcm.handler.media.impl.MediaFileServlet; +import io.wcm.handler.media.impl.MediaFileServletConstants; import io.wcm.handler.media.spi.MediaHandlerConfig; import io.wcm.handler.url.UrlHandler; import io.wcm.sling.commons.adapter.AdaptTo; @@ -96,6 +96,7 @@ final class InlineRendition extends SlingAdaptable implements Rendition { * @param mediaArgs Media args * @param fileName File name */ + @SuppressWarnings("java:S3776") // ignore complexity InlineRendition(Resource resource, Media media, MediaArgs mediaArgs, MediaHandlerConfig mediaHandlerConfig, String fileName, Adaptable adaptable) { this.resource = resource; @@ -393,7 +394,7 @@ private String buildScaledMediaUrl(@NotNull Dimension dimension, @Nullable CropD + "." + ImageFileServletSelector.build(dimension.getWidth(), dimension.getHeight(), mediaUrlCropDimension, this.rotation, this.mediaArgs.getImageQualityPercentage(), this.mediaArgs.isContentDispositionAttachment()) - + "." + MediaFileServlet.EXTENSION + "/" + + "." + MediaFileServletConstants.EXTENSION + "/" // replace extension based on the format supported by ImageFileServlet for rendering for this rendition + ImageFileServlet.getImageFileName(getFileName(), mediaArgs.getEnforceOutputFileExtension()); @@ -418,9 +419,9 @@ private String buildDownloadMediaUrl() { } // URL to render scaled image via {@link InlineRenditionServlet} - String path = resourcePath + "." + MediaFileServlet.SELECTOR - + "." + MediaFileServlet.SELECTOR_DOWNLOAD - + "." + MediaFileServlet.EXTENSION + "/" + getFileName(); + String path = resourcePath + "." + MediaFileServletConstants.SELECTOR + + "." + MediaFileServletConstants.SELECTOR_DOWNLOAD + + "." + MediaFileServletConstants.EXTENSION + "/" + getFileName(); // build externalized URL UrlHandler urlHandler = AdaptTo.notNull(this.adaptable, UrlHandler.class); diff --git a/src/main/java/io/wcm/handler/mediasource/inline/InlineUriTemplate.java b/src/main/java/io/wcm/handler/mediasource/inline/InlineUriTemplate.java index 8b650df6..8968d533 100644 --- a/src/main/java/io/wcm/handler/mediasource/inline/InlineUriTemplate.java +++ b/src/main/java/io/wcm/handler/mediasource/inline/InlineUriTemplate.java @@ -36,7 +36,7 @@ import io.wcm.handler.media.impl.ImageFileServlet; import io.wcm.handler.media.impl.ImageFileServletSelector; import io.wcm.handler.media.impl.JcrBinary; -import io.wcm.handler.media.impl.MediaFileServlet; +import io.wcm.handler.media.impl.MediaFileServletConstants; import io.wcm.handler.url.UrlHandler; import io.wcm.sling.commons.adapter.AdaptTo; @@ -74,7 +74,7 @@ private static String buildUriTemplate(@NotNull UriTemplateType type, @NotNull R String path = resourcePath + "." + ImageFileServletSelector.build(DUMMY_WIDTH, DUMMY_HEIGHT, cropDimension, rotation, mediaArgs.getImageQualityPercentage(), false) - + "." + MediaFileServlet.EXTENSION + + "." + MediaFileServletConstants.EXTENSION // replace extension based on the format supported by ImageFileServlet for rendering for this rendition + "/" + ImageFileServlet.getImageFileName(fileName, mediaArgs.getEnforceOutputFileExtension()); diff --git a/src/test/java/io/wcm/handler/media/CropDimensionTest.java b/src/test/java/io/wcm/handler/media/CropDimensionTest.java index 3ad90bb0..4efcecbe 100644 --- a/src/test/java/io/wcm/handler/media/CropDimensionTest.java +++ b/src/test/java/io/wcm/handler/media/CropDimensionTest.java @@ -50,6 +50,7 @@ void testSimple() { } @Test + @SuppressWarnings("java:S5961") // ignore number of asserts void testEquals() { CropDimension dimension1 = new CropDimension(15, 5, 20, 10); CropDimension dimension2 = new CropDimension(15, 5, 20, 10); diff --git a/src/test/java/io/wcm/handler/media/MediaArgsTest.java b/src/test/java/io/wcm/handler/media/MediaArgsTest.java index c6bf636f..a6b0281f 100644 --- a/src/test/java/io/wcm/handler/media/MediaArgsTest.java +++ b/src/test/java/io/wcm/handler/media/MediaArgsTest.java @@ -153,7 +153,10 @@ void testInvalidForceOutputFileExtensions() { } @Test - @SuppressWarnings("deprecation") + @SuppressWarnings({ + "deprecation", + "java:S5961" // ignore number of asserts + }) void testClone() { MediaFormatOption[] mediaFormatOptions = new MediaFormatOption[] { new MediaFormatOption(EDITORIAL_1COL, true), diff --git a/src/test/java/io/wcm/handler/media/format/MediaFormatBuilderTest.java b/src/test/java/io/wcm/handler/media/format/MediaFormatBuilderTest.java index aadbafce..d315af8c 100644 --- a/src/test/java/io/wcm/handler/media/format/MediaFormatBuilderTest.java +++ b/src/test/java/io/wcm/handler/media/format/MediaFormatBuilderTest.java @@ -134,6 +134,7 @@ void testBuilder_MinWidthHeight() { } @Test + @SuppressWarnings("java:S5778") void testNullName() { assertThrows(IllegalArgumentException.class, () -> { MediaFormatBuilder.create(null).build(); @@ -141,6 +142,7 @@ void testNullName() { } @Test + @SuppressWarnings("java:S5778") void testIllegalName() { assertThrows(IllegalArgumentException.class, () -> { MediaFormatBuilder.create("name with spaces").build(); @@ -148,6 +150,7 @@ void testIllegalName() { } @Test + @SuppressWarnings("java:S5778") void testMinWidthHeight_withOtherWidthHeightRestrictions() { assertThrows(IllegalArgumentException.class, () -> { MediaFormatBuilder.create("name") diff --git a/src/test/java/io/wcm/handler/media/imagemap/impl/ImageMapParserImplTest.java b/src/test/java/io/wcm/handler/media/imagemap/impl/ImageMapParserImplTest.java index 6babff16..e50e67f0 100644 --- a/src/test/java/io/wcm/handler/media/imagemap/impl/ImageMapParserImplTest.java +++ b/src/test/java/io/wcm/handler/media/imagemap/impl/ImageMapParserImplTest.java @@ -79,37 +79,32 @@ public class ImageMapParserImplTest { @Test void testMap_WithLinkResolver() { context.registerService(ImageMapLinkResolver.class, new DummyImageMapLinkResolver(context)); - ImageMapParser underTest = AdaptTo.notNull(context.request(), ImageMapParser.class); - assertEquals(EXPECTED_AREAS_RESOLVED, underTest.parseMap(MAP_STRING)); + assertEquals(EXPECTED_AREAS_RESOLVED, getImageMapParser().parseMap(MAP_STRING)); } @Test void testMap_WithoutLinkResolver() { - ImageMapParser underTest = AdaptTo.notNull(context.request(), ImageMapParser.class); - - assertEquals(EXPECTED_AREAS_UNRESOLVED, underTest.parseMap(MAP_STRING)); + assertEquals(EXPECTED_AREAS_UNRESOLVED, getImageMapParser().parseMap(MAP_STRING)); } @Test void testNull() { - ImageMapParser underTest = AdaptTo.notNull(context.request(), ImageMapParser.class); - - assertNull(underTest.parseMap(null)); + assertNull(getImageMapParser().parseMap(null)); } @Test void testEmptyString() { - ImageMapParser underTest = AdaptTo.notNull(context.request(), ImageMapParser.class); - - assertNull(underTest.parseMap("")); + assertNull(getImageMapParser().parseMap("")); } @Test void testInvalidString() { - ImageMapParser underTest = AdaptTo.notNull(context.request(), ImageMapParser.class); + assertNull(getImageMapParser().parseMap("[xyz][")); + } - assertNull(underTest.parseMap("[xyz][")); + private ImageMapParser getImageMapParser() { + return AdaptTo.notNull(context.request(), ImageMapParser.class); } } diff --git a/src/test/java/io/wcm/handler/media/impl/AssetRenditionContentDispositionFilterTest.java b/src/test/java/io/wcm/handler/media/impl/AssetRenditionContentDispositionFilterTest.java index dd61f152..40f084ee 100644 --- a/src/test/java/io/wcm/handler/media/impl/AssetRenditionContentDispositionFilterTest.java +++ b/src/test/java/io/wcm/handler/media/impl/AssetRenditionContentDispositionFilterTest.java @@ -19,9 +19,9 @@ */ package io.wcm.handler.media.impl; -import static io.wcm.handler.media.impl.AbstractMediaFileServlet.HEADER_CONTENT_DISPOSITION; import static io.wcm.handler.media.impl.AssetRenditionContentDispositionFilter.ALLOW_EMPTY_MIME; import static io.wcm.handler.media.impl.AssetRenditionContentDispositionFilter.BLACK_LIST_MIME_TYPE_CONFIG; +import static io.wcm.handler.media.impl.MediaFileServletConstants.HEADER_CONTENT_DISPOSITION; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNull; diff --git a/src/test/java/io/wcm/handler/media/impl/ImageFileServletTest.java b/src/test/java/io/wcm/handler/media/impl/ImageFileServletTest.java index c2374e04..a6a1fcde 100644 --- a/src/test/java/io/wcm/handler/media/impl/ImageFileServletTest.java +++ b/src/test/java/io/wcm/handler/media/impl/ImageFileServletTest.java @@ -40,6 +40,7 @@ import io.wcm.wcm.commons.contenttype.ContentType; @ExtendWith(AemContextExtension.class) +@SuppressWarnings("java:S5976") // ignore similar tests class ImageFileServletTest { private final AemContext context = AppAemContext.newAemContext(); diff --git a/src/test/java/io/wcm/handler/media/impl/MediaFileServletTest.java b/src/test/java/io/wcm/handler/media/impl/MediaFileServletTest.java index b683749c..61afcbc6 100644 --- a/src/test/java/io/wcm/handler/media/impl/MediaFileServletTest.java +++ b/src/test/java/io/wcm/handler/media/impl/MediaFileServletTest.java @@ -19,6 +19,8 @@ */ package io.wcm.handler.media.impl; +import static io.wcm.handler.media.impl.MediaFileServletConstants.HEADER_CONTENT_DISPOSITION; +import static io.wcm.handler.media.impl.MediaFileServletConstants.SELECTOR_DOWNLOAD; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNull; @@ -58,7 +60,7 @@ void testGet() throws Exception { assertEquals(ContentType.JPEG, context.response().getContentType()); assertEquals(EXPECTED_CONTENT_LENGTH, context.response().getOutput().length); assertEquals(EXPECTED_CONTENT_LENGTH, context.response().getContentLength()); - assertNull(context.response().getHeader(AbstractMediaFileServlet.HEADER_CONTENT_DISPOSITION)); + assertNull(context.response().getHeader(HEADER_CONTENT_DISPOSITION)); } @Test @@ -72,12 +74,12 @@ void testGet_SVG() throws Exception { assertEquals(EXPECTED_CONTENT_LENGTH_SVG, context.response().getOutput().length); assertEquals(EXPECTED_CONTENT_LENGTH_SVG, context.response().getContentLength()); // forced content disposition header for SVG to prevent stored XSS - assertEquals("attachment;", context.response().getHeader(AbstractMediaFileServlet.HEADER_CONTENT_DISPOSITION)); + assertEquals("attachment;", context.response().getHeader(HEADER_CONTENT_DISPOSITION)); } @Test void testGet_Download() throws Exception { - context.requestPathInfo().setSelectorString(AbstractMediaFileServlet.SELECTOR_DOWNLOAD); + context.requestPathInfo().setSelectorString(SELECTOR_DOWNLOAD); underTest.service(context.request(), context.response()); @@ -85,12 +87,12 @@ void testGet_Download() throws Exception { assertEquals(ContentType.DOWNLOAD, context.response().getContentType()); assertEquals(EXPECTED_CONTENT_LENGTH, context.response().getOutput().length); assertEquals(EXPECTED_CONTENT_LENGTH, context.response().getContentLength()); - assertEquals("attachment;", context.response().getHeader(AbstractMediaFileServlet.HEADER_CONTENT_DISPOSITION)); + assertEquals("attachment;", context.response().getHeader(HEADER_CONTENT_DISPOSITION)); } @Test void testGet_Download_Suffix() throws Exception { - context.requestPathInfo().setSelectorString(AbstractMediaFileServlet.SELECTOR_DOWNLOAD); + context.requestPathInfo().setSelectorString(SELECTOR_DOWNLOAD); context.requestPathInfo().setSuffix("sample_image.jpg"); underTest.service(context.request(), context.response()); @@ -99,7 +101,7 @@ void testGet_Download_Suffix() throws Exception { assertEquals(ContentType.DOWNLOAD, context.response().getContentType()); assertEquals(EXPECTED_CONTENT_LENGTH, context.response().getOutput().length); assertEquals(EXPECTED_CONTENT_LENGTH, context.response().getContentLength()); - assertEquals("attachment;filename=\"sample_image.jpg\"", context.response().getHeader(AbstractMediaFileServlet.HEADER_CONTENT_DISPOSITION)); + assertEquals("attachment;filename=\"sample_image.jpg\"", context.response().getHeader(HEADER_CONTENT_DISPOSITION)); } @Test diff --git a/src/test/java/io/wcm/handler/media/impl/MediaHandlerImplImageFileTypesEnd2EndDynamicMediaNoFallbackTest.java b/src/test/java/io/wcm/handler/media/impl/MediaHandlerImplImageFileTypesEnd2EndDynamicMediaNoFallbackTest.java index 60333195..c82e3117 100644 --- a/src/test/java/io/wcm/handler/media/impl/MediaHandlerImplImageFileTypesEnd2EndDynamicMediaNoFallbackTest.java +++ b/src/test/java/io/wcm/handler/media/impl/MediaHandlerImplImageFileTypesEnd2EndDynamicMediaNoFallbackTest.java @@ -39,6 +39,7 @@ * with rendering via dynamic media. The fallback to AEM-rendered renditions is disabled. */ @ExtendWith(AemContextExtension.class) +@SuppressWarnings("java:S5976") // ignore similar tests class MediaHandlerImplImageFileTypesEnd2EndDynamicMediaNoFallbackTest extends MediaHandlerImplImageFileTypesEnd2EndTest { @Override diff --git a/src/test/java/io/wcm/handler/media/impl/MediaHandlerImplImageFileTypesEnd2EndTest.java b/src/test/java/io/wcm/handler/media/impl/MediaHandlerImplImageFileTypesEnd2EndTest.java index c078e0cb..a5cb9430 100644 --- a/src/test/java/io/wcm/handler/media/impl/MediaHandlerImplImageFileTypesEnd2EndTest.java +++ b/src/test/java/io/wcm/handler/media/impl/MediaHandlerImplImageFileTypesEnd2EndTest.java @@ -64,6 +64,7 @@ * and renders the result using the ImageFileServlet. */ @ExtendWith(AemContextExtension.class) +@SuppressWarnings("java:S5976") // ignore similar tests class MediaHandlerImplImageFileTypesEnd2EndTest { final AemContext context = AppAemContext.newAemContext(); diff --git a/src/test/java/io/wcm/handler/media/markup/SimpleImageMediaMarkupBuilderTest.java b/src/test/java/io/wcm/handler/media/markup/SimpleImageMediaMarkupBuilderTest.java index 3a0f907f..ad3e3b2c 100644 --- a/src/test/java/io/wcm/handler/media/markup/SimpleImageMediaMarkupBuilderTest.java +++ b/src/test/java/io/wcm/handler/media/markup/SimpleImageMediaMarkupBuilderTest.java @@ -350,7 +350,7 @@ void testBuild_PreviewMode_DiffDecoration() { media.setRenditions(List.of(rendition)); when(rendition.getUrl()).thenReturn("/media/dummy.gif"); - builder.build(media); + assertNotNull(builder.build(media)); } @Test diff --git a/src/test/java/io/wcm/handler/mediasource/dam/impl/TransformedRenditionHandlerTest.java b/src/test/java/io/wcm/handler/mediasource/dam/impl/TransformedRenditionHandlerTest.java index e26ccf43..1a13547b 100644 --- a/src/test/java/io/wcm/handler/mediasource/dam/impl/TransformedRenditionHandlerTest.java +++ b/src/test/java/io/wcm/handler/mediasource/dam/impl/TransformedRenditionHandlerTest.java @@ -47,6 +47,7 @@ * Tests for {@link TransformedRenditionHandler} */ @ExtendWith(AemContextExtension.class) +@SuppressWarnings("java:S2699") // all tests have assertions class TransformedRenditionHandlerTest { private AemContext context = AppAemContext.newAemContext(); diff --git a/src/test/java/io/wcm/handler/mediasource/dam/impl/dynamicmedia/SmartCropTest.java b/src/test/java/io/wcm/handler/mediasource/dam/impl/dynamicmedia/SmartCropTest.java index d8669bbb..6fd63595 100644 --- a/src/test/java/io/wcm/handler/mediasource/dam/impl/dynamicmedia/SmartCropTest.java +++ b/src/test/java/io/wcm/handler/mediasource/dam/impl/dynamicmedia/SmartCropTest.java @@ -54,6 +54,7 @@ import io.wcm.wcm.commons.contenttype.ContentType; @ExtendWith(AemContextExtension.class) +@SuppressWarnings("java:S2699") // all tests have assertions class SmartCropTest { private final AemContext context = AppAemContext.newAemContext(); diff --git a/src/test/java/io/wcm/handler/mediasource/dam/impl/metadata/RenditionMetadataListenerServiceTest.java b/src/test/java/io/wcm/handler/mediasource/dam/impl/metadata/RenditionMetadataListenerServiceTest.java index 96a8c85d..394d4088 100644 --- a/src/test/java/io/wcm/handler/mediasource/dam/impl/metadata/RenditionMetadataListenerServiceTest.java +++ b/src/test/java/io/wcm/handler/mediasource/dam/impl/metadata/RenditionMetadataListenerServiceTest.java @@ -126,6 +126,7 @@ void testUpdateRendition() throws PersistenceException { } @Test + @SuppressWarnings("java:S2925") // allow Thread.sleep() void testUpdateRendition_LastModified() throws PersistenceException, InterruptedException { underTest = context.registerInjectActivateService(new RenditionMetadataListenerService(), "threadPoolSize", 0); diff --git a/src/test/java/io/wcm/handler/mediasource/dam/impl/metadata/RenditionMetadataWorkflowProcessTest.java b/src/test/java/io/wcm/handler/mediasource/dam/impl/metadata/RenditionMetadataWorkflowProcessTest.java index 293a35e9..ca690709 100644 --- a/src/test/java/io/wcm/handler/mediasource/dam/impl/metadata/RenditionMetadataWorkflowProcessTest.java +++ b/src/test/java/io/wcm/handler/mediasource/dam/impl/metadata/RenditionMetadataWorkflowProcessTest.java @@ -25,6 +25,7 @@ import static io.wcm.handler.mediasource.dam.impl.metadata.RenditionMetadataNameConstants.PN_IMAGE_HEIGHT; import static io.wcm.handler.mediasource.dam.impl.metadata.RenditionMetadataNameConstants.PN_IMAGE_WIDTH; import static io.wcm.handler.mediasource.dam.impl.metadata.WorkflowTestUtil.PKG_ROOT; +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNull; @@ -86,7 +87,7 @@ void testWithInvalidPayload() { when(workflowData.getPayload()).thenReturn("/invalid/path"); // execute, ensure no exceptions are thrown - underTest.execute(workItem, workflowSession, metaDataMap); + assertDoesNotThrow(() -> underTest.execute(workItem, workflowSession, metaDataMap)); } @Test diff --git a/src/test/java/io/wcm/handler/mediasource/inline/InlineMediaSourceTest.java b/src/test/java/io/wcm/handler/mediasource/inline/InlineMediaSourceTest.java index 27aa8b68..661f46dd 100644 --- a/src/test/java/io/wcm/handler/mediasource/inline/InlineMediaSourceTest.java +++ b/src/test/java/io/wcm/handler/mediasource/inline/InlineMediaSourceTest.java @@ -72,7 +72,7 @@ import io.wcm.handler.media.format.MediaFormat; import io.wcm.handler.media.imagemap.impl.ImageMapParserImplTest; import io.wcm.handler.media.impl.ImageFileServlet; -import io.wcm.handler.media.impl.MediaFileServlet; +import io.wcm.handler.media.impl.MediaFileServletConstants; import io.wcm.handler.media.spi.ImageMapLinkResolver; import io.wcm.handler.media.spi.MediaHandlerConfig; import io.wcm.handler.media.testcontext.DummyImageMapLinkResolver; @@ -401,6 +401,7 @@ void testWithUrlMode() { } @Test + @SuppressWarnings("java:S5961") // ignore complexity void testWithFixedDimensions() { MediaHandler mediaHandler = AdaptTo.notNull(adaptable(), MediaHandler.class); Rendition rendition; @@ -476,6 +477,7 @@ void testWithFixedDimensions() { } @Test + @SuppressWarnings("java:S5961") // ignore complexity void testWithMediaFormats() { MediaHandler mediaHandler = AdaptTo.notNull(adaptable(), MediaHandler.class); Media media; @@ -641,7 +643,7 @@ void testDownloadMediaElement() { assertNotNull(media.getAsset(), "asset?"); assertNotNull(media.getRendition(), "rendition?"); assertEquals(ROOTPATH_CONTENT + "/_jcr_content/resourceMediaInlineSampleImage/mediaInline." - + MediaFileServlet.SELECTOR + "." + MediaFileServlet.SELECTOR_DOWNLOAD + ".file/sample_image_215x102.jpg", + + MediaFileServletConstants.SELECTOR + "." + MediaFileServletConstants.SELECTOR_DOWNLOAD + ".file/sample_image_215x102.jpg", media.getRendition().getUrl(), "rendition.mediaUrl"); }