Skip to content
Snippets Groups Projects
Unverified Commit b1b81509 authored by Clément Aubin's avatar Clément Aubin
Browse files

XWIKI-14937: Move the Image (com.xpn.xwiki.plugin.image) plugin in xwiki-platform-image

* Move the Image plugin in xwiki-platform-image-plugin
* Apply codestyle
* Move ImageProcessor API into xwiki-platform-image-api
parent b0edb28b
No related branches found
No related tags found
No related merge requests found
Showing
with 235 additions and 43 deletions
......@@ -191,6 +191,7 @@
<module>xwiki-platform-groovy</module>
<module>xwiki-platform-help</module>
<module>xwiki-platform-icon</module>
<module>xwiki-platform-image</module>
<module>xwiki-platform-index</module>
<module>xwiki-platform-instance</module>
<module>xwiki-platform-invitation</module>
......
<?xml version="1.0" encoding="UTF-8"?>
<!--
* See the NOTICE file distributed with this work for additional
* information regarding copyright ownership.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.xwiki.platform</groupId>
<artifactId>xwiki-platform-core</artifactId>
<version>10.0-SNAPSHOT</version>
</parent>
<artifactId>xwiki-platform-image</artifactId>
<name>XWiki Platform - Image - Parent POM</name>
<description>Code related to image processing</description>
<packaging>pom</packaging>
<modules>
<module>xwiki-platform-image-api</module>
<module>xwiki-platform-image-plugin</module>
</modules>
</project>
<?xml version="1.0" encoding="UTF-8"?>
<!--
* See the NOTICE file distributed with this work for additional
* information regarding copyright ownership.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.xwiki.platform</groupId>
<artifactId>xwiki-platform-image</artifactId>
<version>10.0-SNAPSHOT</version>
</parent>
<artifactId>xwiki-platform-image-api</artifactId>
<name>XWiki Platform - Image - API</name>
<properties>
<thumbnailator.version>0.4.8</thumbnailator.version>
</properties>
<dependencies>
<dependency>
<groupId>org.xwiki.platform</groupId>
<artifactId>xwiki-platform-component-multi</artifactId>
<version>${project.version}</version>
</dependency>
<!-- Used by the image plugin to resize the images (i.e. create thumbnails) on the server side. -->
<dependency>
<groupId>net.coobird</groupId>
<artifactId>thumbnailator</artifactId>
<version>${thumbnailator.version}</version>
</dependency>
</dependencies>
</project>
com.xpn.xwiki.internal.plugin.image.DefaultImageProcessor
com.xpn.xwiki.internal.plugin.image.ThumbnailatorImageProcessor
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<!--
* See the NOTICE file distributed with this work for additional
* information regarding copyright ownership.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.xwiki.platform</groupId>
<artifactId>xwiki-platform-image</artifactId>
<version>10.0-SNAPSHOT</version>
</parent>
<artifactId>xwiki-platform-image-plugin</artifactId>
<name>XWiki Platform - Image - Plugin</name>
<description>Deprecated Image plugin</description>
<properties>
<checkstyle.suppressions.location>${basedir}/src/main/checkstyle/checkstyle-suppressions.xml</checkstyle.suppressions.location>
<xwiki.jacoco.instructionRatio>0.54</xwiki.jacoco.instructionRatio>
</properties>
<dependencies>
<dependency>
<groupId>org.xwiki.platform</groupId>
<artifactId>xwiki-platform-image-api</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.xwiki.platform</groupId>
<artifactId>xwiki-platform-oldcore</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<scope>compile</scope>
</dependency>
<!-- Test dependencies -->
<dependency>
<groupId>org.xwiki.platform</groupId>
<artifactId>xwiki-platform-oldcore</artifactId>
<version>${project.version}</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.xwiki.commons</groupId>
<artifactId>xwiki-commons-tool-test-component</artifactId>
<version>${commons.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
<?xml version="1.0" encoding="UTF-8"?>
<!--
* See the NOTICE file distributed with this work for additional
* information regarding copyright ownership.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-->
<!DOCTYPE suppressions PUBLIC
"-//Puppy Crawl//DTD Suppressions 1.0//EN"
"http://www.puppycrawl.com/dtds/suppressions_1_0.dtd">
<suppressions>
<suppress checks="NPathComplexity" files="ImagePlugin.java"/>
</suppressions>
\ No newline at end of file
......@@ -26,9 +26,12 @@
import java.io.OutputStream;
import org.apache.commons.codec.binary.Base64;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.mockito.ArgumentMatchers;
import org.mockito.Mockito;
import org.xwiki.cache.Cache;
import org.xwiki.cache.CacheManager;
......@@ -39,10 +42,6 @@
import com.xpn.xwiki.test.MockitoOldcoreRule;
import com.xpn.xwiki.web.XWikiServletRequest;
import static org.junit.Assert.*;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*;
/**
* Unit tests for the {@link ImagePlugin} class.
*
......@@ -98,13 +97,14 @@ public class ImagePluginTest
public void configure() throws Exception
{
XWiki xwiki = this.oldCore.getSpyXWiki();
doReturn("10").when(xwiki).Param("xwiki.plugin.image.cache.capacity");
doReturn("test").when(xwiki).Param(eq("xwiki.plugin.image.processorHint"), anyString());
Mockito.doReturn("10").when(xwiki).Param("xwiki.plugin.image.cache.capacity");
Mockito.doReturn("test").when(xwiki).Param(
ArgumentMatchers.eq("xwiki.plugin.image.processorHint"), ArgumentMatchers.anyString());
this.oldCore.getMocker().registerMockComponent(CacheManager.class);
this.imageProcessor = this.oldCore.getMocker().registerMockComponent(ImageProcessor.class, "test");
when(this.imageProcessor.isMimeTypeSupported("image/png")).thenReturn(true);
Mockito.when(this.imageProcessor.isMimeTypeSupported("image/png")).thenReturn(true);
this.plugin = new ImagePlugin("image", ImagePlugin.class.getName(), this.oldCore.getXWikiContext());
}
......@@ -112,9 +112,9 @@ public void configure() throws Exception
@Test
public void testDownloadAttachmentWithUnsupportedFileType()
{
XWikiAttachment attachment = mock(XWikiAttachment.class);
when(attachment.getMimeType()).thenReturn("image/notsupported");
assertSame(attachment, plugin.downloadAttachment(attachment, new XWikiContext()));
XWikiAttachment attachment = Mockito.mock(XWikiAttachment.class);
Mockito.when(attachment.getMimeType()).thenReturn("image/notsupported");
Assert.assertSame(attachment, plugin.downloadAttachment(attachment, new XWikiContext()));
}
@Test
......@@ -122,43 +122,44 @@ public void testCacheOfScaledAttachment() throws Exception
{
XWikiContext xcontext = this.oldCore.getXWikiContext();
XWikiAttachment attachment = mock(XWikiAttachment.class);
when(attachment.getMimeType(xcontext)).thenReturn("image/png");
XWikiAttachment attachment = Mockito.mock(XWikiAttachment.class);
Mockito.when(attachment.getMimeType(xcontext)).thenReturn("image/png");
InputStream attachmentInputStream = new ByteArrayInputStream(testPngImageContent);
when(attachment.getContentInputStream(xcontext)).thenReturn(attachmentInputStream);
when(attachment.clone()).thenReturn(attachment);
Mockito.when(attachment.getContentInputStream(xcontext)).thenReturn(attachmentInputStream);
Mockito.when(attachment.clone()).thenReturn(attachment);
XWikiAttachmentContent attachmentContent = mock(XWikiAttachmentContent.class);
when(attachment.getAttachment_content()).thenReturn(attachmentContent);
when(attachmentContent.getContentInputStream()).thenReturn(attachmentInputStream);
OutputStream attachmentOutputStream = mock(OutputStream.class);
when(attachmentContent.getContentOutputStream()).thenReturn(attachmentOutputStream);
XWikiAttachmentContent attachmentContent = Mockito.mock(XWikiAttachmentContent.class);
Mockito.when(attachment.getAttachment_content()).thenReturn(attachmentContent);
Mockito.when(attachmentContent.getContentInputStream()).thenReturn(attachmentInputStream);
OutputStream attachmentOutputStream = Mockito.mock(OutputStream.class);
Mockito.when(attachmentContent.getContentOutputStream()).thenReturn(attachmentOutputStream);
CacheManager cacheManager = this.oldCore.getMocker().getInstance(CacheManager.class);
Cache<Object> imageCache = mock(Cache.class);
when(cacheManager.createNewLocalCache(any())).thenReturn(imageCache);
Cache<Object> imageCache = Mockito.mock(Cache.class);
Mockito.when(cacheManager.createNewLocalCache(ArgumentMatchers.any())).thenReturn(imageCache);
XWikiServletRequest request = mock(XWikiServletRequest.class);
when(request.getParameter("width")).thenReturn("30");
when(request.getParameter("height")).thenReturn("30");
XWikiServletRequest request = Mockito.mock(XWikiServletRequest.class);
Mockito.when(request.getParameter("width")).thenReturn("30");
Mockito.when(request.getParameter("height")).thenReturn("30");
xcontext.setRequest(request);
Image image = mock(Image.class);
when(image.getWidth(null)).thenReturn(400);
when(image.getHeight(null)).thenReturn(300);
when(imageProcessor.readImage(attachmentInputStream)).thenReturn(image);
RenderedImage renderedImage = mock(RenderedImage.class);
when(imageProcessor.scaleImage(image, 30, 30)).thenReturn(renderedImage);
Image image = Mockito.mock(Image.class);
Mockito.when(image.getWidth(null)).thenReturn(400);
Mockito.when(image.getHeight(null)).thenReturn(300);
Mockito.when(imageProcessor.readImage(attachmentInputStream)).thenReturn(image);
RenderedImage renderedImage = Mockito.mock(RenderedImage.class);
Mockito.when(imageProcessor.scaleImage(image, 30, 30)).thenReturn(renderedImage);
XWikiAttachment scaled = plugin.downloadAttachment(attachment, xcontext);
String cacheKey = "0;null;30;30;false;-1.0";
when(imageCache.get(cacheKey)).thenReturn(scaled);
Mockito.when(imageCache.get(cacheKey)).thenReturn(scaled);
// Load again, this time from cache.
assertSame(scaled, plugin.downloadAttachment(attachment, xcontext));
Assert.assertSame(scaled, plugin.downloadAttachment(attachment, xcontext));
verify(imageProcessor, times(1)).writeImage(renderedImage, "image/png", .5F, attachmentOutputStream);
verify(imageCache, times(1)).set(cacheKey, attachment);
Mockito.verify(imageProcessor, Mockito.times(1)).writeImage(renderedImage,
"image/png", .5F, attachmentOutputStream);
Mockito.verify(imageCache, Mockito.times(1)).set(cacheKey, attachment);
}
}
......@@ -260,12 +260,6 @@
<groupId>com.sun.mail</groupId>
<artifactId>javax.mail</artifactId>
</dependency>
<!-- Used by the image plugin to resize the images (i.e. create thumbnails) on the server side. -->
<dependency>
<groupId>net.coobird</groupId>
<artifactId>thumbnailator</artifactId>
<version>0.4.8</version>
</dependency>
<!-- Other XWiki modules -->
<dependency>
......@@ -325,6 +319,12 @@
<artifactId>xwiki-platform-model</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.xwiki.platform</groupId>
<artifactId>xwiki-platform-image-api</artifactId>
<version>${project.version}</version>
</dependency>
<!-- TODO: This dependency shouldn't be in this module since it means we're tying this module and all other
modules using it to the Servlet environment, which is pretty bad. To be able to remove this dependency
we first need to be able to split DefaultVelocityManager so that the part that is related to the Servlet
......@@ -757,7 +757,6 @@
**/objects/ObjectInterface.java,
**/objects/PropertyInterface.java,
**/objects/StringListProperty.java,
**/plugin/image/ImagePlugin.java,
**/plugin/autotag/FrenchStemmer.java,
**/plugin/mail/MailPluginApi.java,
**/plugin/mail/MailPlugin.java,
......
......@@ -114,8 +114,6 @@ com.xpn.xwiki.internal.store.hibernate.HibernateStore
com.xpn.xwiki.internal.template.DefaultTemplateManager
com.xpn.xwiki.internal.template.InternalTemplateManager
com.xpn.xwiki.internal.template.TemplateListener
com.xpn.xwiki.internal.plugin.image.DefaultImageProcessor
com.xpn.xwiki.internal.plugin.image.ThumbnailatorImageProcessor
com.xpn.xwiki.internal.query.ConfiguredQueryExecutorProvider
com.xpn.xwiki.internal.query.CurrentLanguageQueryFilter
com.xpn.xwiki.script.sheet.SheetScriptService
......
......@@ -55,6 +55,11 @@
<artifactId>xwiki-platform-scheduler-api</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.xwiki.platform</groupId>
<artifactId>xwiki-platform-image-api</artifactId>
<version>${project.version}</version>
</dependency>
<!-- Default implementation of the mail-send-api. -->
<dependency>
<groupId>org.xwiki.platform</groupId>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment