diff --git a/bundles/org.dbunit.eclipse.dataset.ui/about.ini b/bundles/org.dbunit.eclipse.dataset.ui/about.ini new file mode 100644 index 00000000..83ad2e0e --- /dev/null +++ b/bundles/org.dbunit.eclipse.dataset.ui/about.ini @@ -0,0 +1,4 @@ +# Read by the About dialog through the plugin attribute of the feature in feature.xml. +# featureImage: the 32x32 icon of the feature, relative to the root of this bundle. +featureImage=icons/about/dbunit32.png +aboutText=Edit dbUnit dataset files like a spreadsheet diff --git a/bundles/org.dbunit.eclipse.dataset.ui/build.properties b/bundles/org.dbunit.eclipse.dataset.ui/build.properties index 91767b1b..f173bc79 100644 --- a/bundles/org.dbunit.eclipse.dataset.ui/build.properties +++ b/bundles/org.dbunit.eclipse.dataset.ui/build.properties @@ -10,5 +10,6 @@ bin.includes = META-INF/,\ .,\ plugin.properties,\ plugin.xml,\ + about.ini,\ icons/,\ css/ diff --git a/bundles/org.dbunit.eclipse.dataset.ui/icons/about/dbunit32.png b/bundles/org.dbunit.eclipse.dataset.ui/icons/about/dbunit32.png new file mode 100644 index 00000000..b77cb779 Binary files /dev/null and b/bundles/org.dbunit.eclipse.dataset.ui/icons/about/dbunit32.png differ diff --git a/bundles/org.dbunit.eclipse.dataset.ui/icons/about/dbunit32@2x.png b/bundles/org.dbunit.eclipse.dataset.ui/icons/about/dbunit32@2x.png new file mode 100644 index 00000000..17d995fa Binary files /dev/null and b/bundles/org.dbunit.eclipse.dataset.ui/icons/about/dbunit32@2x.png differ diff --git a/bundles/org.dbunit.eclipse.dataset.ui/pom.xml b/bundles/org.dbunit.eclipse.dataset.ui/pom.xml index 6108156d..1b11e9b9 100644 --- a/bundles/org.dbunit.eclipse.dataset.ui/pom.xml +++ b/bundles/org.dbunit.eclipse.dataset.ui/pom.xml @@ -120,6 +120,8 @@ ${project.build.directory} + + ${project.basedir}/../../features/org.dbunit.eclipse.feature diff --git a/bundles/org.dbunit.eclipse.dataset.ui/src/test/java/org/dbunit/eclipse/dataset/ui/BundleBrandingTest.java b/bundles/org.dbunit.eclipse.dataset.ui/src/test/java/org/dbunit/eclipse/dataset/ui/BundleBrandingTest.java new file mode 100644 index 00000000..d6d44342 --- /dev/null +++ b/bundles/org.dbunit.eclipse.dataset.ui/src/test/java/org/dbunit/eclipse/dataset/ui/BundleBrandingTest.java @@ -0,0 +1,236 @@ +/* + * + * The DbUnit Database Testing Framework + * Copyright (C)2002-2026, DbUnit.org + * + * This library 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 library 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 library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ +package org.dbunit.eclipse.dataset.ui; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assumptions.assumeTrue; + +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.Dictionary; +import java.util.Properties; + +import javax.xml.XMLConstants; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; + +import org.eclipse.core.runtime.FileLocator; +import org.eclipse.core.runtime.IPath; +import org.eclipse.swt.graphics.ImageData; +import org.eclipse.swt.graphics.Point; +import org.junit.jupiter.api.Test; +import org.osgi.framework.Bundle; +import org.osgi.framework.Constants; +import org.osgi.framework.FrameworkUtil; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.xml.sax.SAXException; + +/** + * Guards what the About dialog needs to show the feature. It finds the feature icon in the about.ini of the + * bundle that the plugin attribute of the feature names, and lists the name and provider from the manifest + * of that bundle. The tests that read the feature run under Maven, whose UI pom passes its directory. + */ +class BundleBrandingTest +{ + private static final String ABOUT_INI = "$nl$/about.ini"; + + private static final String FEATURE_IMAGE_KEY = "featureImage"; + + private static final String FEATURE_NAME_KEY = "featureName"; + + private static final String PROVIDER_NAME_KEY = "providerName"; + + private static final String DOUBLE_SIZE_SUFFIX = "@2x"; + + private static final String FEATURE_DIRECTORY_PROPERTY = "dbunit.feature.directory"; + + private static final String ABOUT_INI_ADVICE = + "about.ini must be at the root of the bundle: list it in bin.includes of build.properties."; + + private static final String FEATURE_IMAGE_KEY_ADVICE = + "about.ini must set featureImage to the path of the feature image."; + + private static final String FEATURE_IMAGE_ADVICE = + "The feature image must be in the bundle: list its folder in bin.includes of build.properties."; + + private static final String IMAGE_SIZE_ADVICE = + "The About dialog shows the image at its own size, so it must be 32 by 32 pixels."; + + private static final String DOUBLE_SIZE_IMAGE_ADVICE = + "The feature image needs a copy named with @2x before its extension, for high-DPI displays."; + + private static final String DOUBLE_SIZE_ADVICE = + "A 200% display shows the @2x image at half its size, so it must be 64 by 64 pixels."; + + private static final String BRANDING_ADVICE = + "The About dialog lists the feature by the Bundle-Name and Bundle-Vendor of its branding" + + " bundle, so they must equal featureName and providerName in feature.properties."; + + private static final String FEATURE_PLUGIN_ADVICE = + "The plugin attribute of feature.xml must name the bundle that has about.ini," + + " or the About dialog leaves the feature out."; + + private static final String FEATURE_DIRECTORY_ADVICE = "The UI pom passes the feature directory as the" + + " system property " + FEATURE_DIRECTORY_PROPERTY + "."; + + private record Branding(String name, String provider) + { + } + + @Test + void testAboutIni_whenLocatedLikeTheAboutDialog_isPackagedAtTheRootOfTheBundle() + { + final Bundle bundle = FrameworkUtil.getBundle(DatasetUiPlugin.class); + + final URL aboutIni = findAboutIni(bundle); + + assertThat(aboutIni).as(ABOUT_INI_ADVICE).isNotNull(); + } + + @Test + void testFeatureImage_whenResolvedLikeTheAboutDialog_isAnImageOf32By32Pixels() throws IOException + { + final Bundle bundle = FrameworkUtil.getBundle(DatasetUiPlugin.class); + final String featureImage = readFeatureImagePath(bundle); + + final Point size = readImageSize(bundle, featureImage, FEATURE_IMAGE_ADVICE); + + assertThat(size).as(IMAGE_SIZE_ADVICE).isEqualTo(new Point(32, 32)); + } + + @Test + void testFeatureImage_whenResolvedForHighDpiDisplays_isAnImageOf64By64Pixels() throws IOException + { + final Bundle bundle = FrameworkUtil.getBundle(DatasetUiPlugin.class); + final String featureImage = readFeatureImagePath(bundle); + final String doubleSizeImage = withDoubleSizeSuffix(featureImage); + + final Point size = readImageSize(bundle, doubleSizeImage, DOUBLE_SIZE_IMAGE_ADVICE); + + assertThat(size).as(DOUBLE_SIZE_ADVICE).isEqualTo(new Point(64, 64)); + } + + @Test + void testBundleHeaders_whenListedByTheAboutDialog_matchTheNameAndProviderOfTheFeature() throws IOException + { + final Bundle bundle = FrameworkUtil.getBundle(DatasetUiPlugin.class); + final Dictionary headers = bundle.getHeaders(); + final String bundleName = headers.get(Constants.BUNDLE_NAME); + final String bundleVendor = headers.get(Constants.BUNDLE_VENDOR); + final Branding bundleBranding = new Branding(bundleName, bundleVendor); + final Properties featureProperties = readFeatureProperties(); + final String featureName = featureProperties.getProperty(FEATURE_NAME_KEY); + final String providerName = featureProperties.getProperty(PROVIDER_NAME_KEY); + final Branding featureBranding = new Branding(featureName, providerName); + + assertThat(bundleBranding).as(BRANDING_ADVICE).isEqualTo(featureBranding); + } + + @Test + void testFeature_whenReadFromTheFeatureProject_namesTheUiBundleAsItsBrandingPlugin() + throws IOException, ParserConfigurationException, SAXException + { + final Path featureXml = featureDirectory().resolve("feature.xml"); + final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true); + final DocumentBuilder builder = factory.newDocumentBuilder(); + final String brandingPlugin; + try (InputStream stream = Files.newInputStream(featureXml)) + { + final Document feature = builder.parse(stream); + final Element root = feature.getDocumentElement(); + brandingPlugin = root.getAttribute("plugin"); + } + + assertThat(brandingPlugin).as(FEATURE_PLUGIN_ADVICE).isEqualTo(DatasetUiPlugin.PLUGIN_ID); + } + + private static URL findAboutIni(final Bundle bundle) + { + final IPath aboutIniPath = IPath.fromOSString(ABOUT_INI); + return FileLocator.find(bundle, aboutIniPath, null); + } + + private static Properties readAboutIni(final Bundle bundle) throws IOException + { + final URL aboutIni = findAboutIni(bundle); + assertThat(aboutIni).as(ABOUT_INI_ADVICE).isNotNull(); + final Properties properties = new Properties(); + try (InputStream stream = aboutIni.openStream()) + { + properties.load(stream); + } + return properties; + } + + private static String readFeatureImagePath(final Bundle bundle) throws IOException + { + final Properties aboutIni = readAboutIni(bundle); + final String featureImage = aboutIni.getProperty(FEATURE_IMAGE_KEY); + assertThat(featureImage).as(FEATURE_IMAGE_KEY_ADVICE).isNotNull(); + return featureImage; + } + + private static Point readImageSize(final Bundle bundle, final String path, final String advice) + throws IOException + { + final IPath imagePath = IPath.fromOSString(path); + final URL imageUrl = FileLocator.find(bundle, imagePath, null); + assertThat(imageUrl).as(advice).isNotNull(); + try (InputStream stream = imageUrl.openStream()) + { + final ImageData image = new ImageData(stream); + return new Point(image.width, image.height); + } + } + + private static String withDoubleSizeSuffix(final String imagePath) + { + final int extensionStart = imagePath.lastIndexOf('.'); + final String name = imagePath.substring(0, extensionStart); + final String extension = imagePath.substring(extensionStart); + return name + DOUBLE_SIZE_SUFFIX + extension; + } + + private static Properties readFeatureProperties() throws IOException + { + final Path featureProperties = featureDirectory().resolve("feature.properties"); + final Properties properties = new Properties(); + try (InputStream stream = Files.newInputStream(featureProperties)) + { + properties.load(stream); + } + return properties; + } + + private static Path featureDirectory() + { + final String directory = System.getProperty(FEATURE_DIRECTORY_PROPERTY); + assumeTrue(directory != null, FEATURE_DIRECTORY_ADVICE); + final Path featureDirectory = Path.of(directory); + return featureDirectory.normalize(); + } +} diff --git a/features/org.dbunit.eclipse.feature/feature.xml b/features/org.dbunit.eclipse.feature/feature.xml index 4c91b4ba..35095e78 100644 --- a/features/org.dbunit.eclipse.feature/feature.xml +++ b/features/org.dbunit.eclipse.feature/feature.xml @@ -3,7 +3,13 @@ id="org.dbunit.eclipse.feature" label="%featureName" version="1.0.1.qualifier" - provider-name="%providerName"> + provider-name="%providerName" + plugin="org.dbunit.eclipse.dataset.ui"> + + %description diff --git a/src/changes/changes.xml b/src/changes/changes.xml index 7ab5b50a..e2724790 100644 --- a/src/changes/changes.xml +++ b/src/changes/changes.xml @@ -7,7 +7,8 @@ - + + Add the dbUnit icon to the Eclipse About dialog. Add the dbUnit Dataset Editor, a spreadsheet-like editor for dbUnit flat XML dataset files.