From 29e263e9cd739eef3e2abbdc50ecd3d694abee70 Mon Sep 17 00:00:00 2001 From: Sergey Grigoriev Date: Tue, 2 Jul 2024 22:25:40 +0200 Subject: [PATCH] feat: structure of the project is changed to simplify cognitive complexity --- bundles/pom.xml | 355 ------------------ export-package-generator/pom.xml | 51 --- .../thirdparty/bundles/PackageFinder.java | 55 --- .../thirdparty/bundles/PackageFinderTest.java | 32 -- .../org.apache.poi => org.apache.poi}/pom.xml | 8 +- .../src/main/java/dummy/pkg/Dummy.java | 0 .../src/main/resources/META-INF/MANIFEST.MF | 0 pom.xml | 334 +++++++++++++++- src/main/resources/META-INF/MANIFEST.MF | 14 - 9 files changed, 325 insertions(+), 524 deletions(-) delete mode 100644 bundles/pom.xml delete mode 100644 export-package-generator/pom.xml delete mode 100644 export-package-generator/src/main/java/ch/sbb/polarion/thirdparty/bundles/PackageFinder.java delete mode 100644 export-package-generator/src/test/java/ch/sbb/polarion/thirdparty/bundles/PackageFinderTest.java rename {bundles/org.apache.poi => org.apache.poi}/pom.xml (89%) rename {bundles/org.apache.poi => org.apache.poi}/src/main/java/dummy/pkg/Dummy.java (100%) rename {bundles/org.apache.poi => org.apache.poi}/src/main/resources/META-INF/MANIFEST.MF (100%) delete mode 100644 src/main/resources/META-INF/MANIFEST.MF diff --git a/bundles/pom.xml b/bundles/pom.xml deleted file mode 100644 index 9bf1e87..0000000 --- a/bundles/pom.xml +++ /dev/null @@ -1,355 +0,0 @@ - - - 4.0.0 - - - ch.sbb.polarion.thirdparty.bundles - generic - 1.1.0 - - - ch.sbb.polarion.thirdparty.bundles - bundles - 1.1.1-SNAPSHOT - pom - - Custom third-party dependencies - - We have faced the such problem when tried to use Apache POI v5.2.4. This version uses Apache Commons IO v2.13.0, but Polarion has v2.11.0. - As a result it leads to ClassNotFoundExceptions in some cases when Apache POI functionality is called. - This project demonstrates how to solve this problem using the packaging of Apache POI dependency as a separate bundle. - - https://github.com/SchweizerischeBundesbahnen/ch.sbb.polarion.extension.bundles - - - - The SBB License, Version 1.0 - https://github.com/SchweizerischeBundesbahnen/ch.sbb.polarion.extension.bundles/blob/main/LICENSES/SBB.txt - - - - - - SBB Polarion Team - polarion-opensource@sbb.ch - SBB AG - http://www.sbb.ch - - - - - scm:git:git://github.com/SchweizerischeBundesbahnen/ch.sbb.polarion.extension.bundles.git - scm:git:ssh://github.com/SchweizerischeBundesbahnen/ch.sbb.polarion.extension.bundles.git - http://github.com/SchweizerischeBundesbahnen/ch.sbb.polarion.extension.bundles/tree/main - - - - GitHub - https://github.com/SchweizerischeBundesbahnen/ch.sbb.polarion.extension.bundles/issues - - - - - ossrh - https://oss.sonatype.org/content/repositories/snapshots - - - ossrh - https://oss.sonatype.org/service/local/staging/deploy/maven2/ - - - - - org.apache.poi - - - - false - - - 1.0 - 2 - ${maven.build.timestamp} - ${project.groupId}.${project.artifactId} - ${project.groupId}.${project.artifactId};singleton:=true - SBB AG - - ${project.artifact.selectedVersion.majorVersion}.${project.artifact.selectedVersion.minorVersion}.${project.artifact.selectedVersion.incrementalVersion} - - ${Original-Bundle-Version} - - ${Export-Package-Root} - - 3.13.0 - 3.2.4 - 3.7.0 - 3.3.1 - 1.7.0 - - - - - - skip-install-to-local-polarion - - - packaging - pom - - - - true - - - - - install-to-local-polarion - - - - org.apache.maven.plugins - maven-clean-plugin - ${maven-clean-plugin.version} - - - - ${env.POLARION_HOME}/polarion/extensions/${project.groupId}.${project.artifactId}/eclipse/plugins - - **/* - - false - - - - - - - org.apache.maven.plugins - maven-dependency-plugin - ${maven-dependency-plugin.version} - - - copy-to-local-polarion - install - - copy - - - - - ${project.groupId} - ${project.artifactId} - ${project.version} - ${project.packaging} - - - ${env.POLARION_HOME}/polarion/extensions/${project.groupId}.${project.artifactId}/eclipse/plugins - ${skip.copy.to.local.polarion} - - - - - - - - - - gpg-sign - - - - org.apache.maven.plugins - maven-gpg-plugin - - - - - - - nexus-staging - - - - org.sonatype.plugins - nexus-staging-maven-plugin - - - - - - - - - - org.apache.maven.plugins - maven-source-plugin - - - - org.apache.maven.plugins - maven-javadoc-plugin - - - - - - - org.apache.maven.plugins - maven-compiler-plugin - ${maven-compiler-plugin.version} - - - **/*.java - - - - - - org.apache.maven.plugins - maven-dependency-plugin - ${maven-dependency-plugin.version} - - - build-bundle-classpath - compile - - build-classpath - - - libs - , - / - maven-jar-plugin.Bundle-ClassPath - runtime - - - - - copy-dependencies - prepare-package - - copy-dependencies - - - ${basedir}/target/classes/libs - runtime - - - - - - - org.apache.maven.plugins - maven-jar-plugin - ${maven-jar-plugin.version} - - - ${project.build.outputDirectory}/META-INF/MANIFEST.MF - - ${maven-jar-plugin.Manifest-Version} - ${maven-jar-plugin.Bundle-ManifestVersion} - ${maven-jar-plugin.Bundle-Vendor} - ${maven-jar-plugin.Automatic-Module-Name} - ${maven-jar-plugin.Bundle-SymbolicName} - ${maven-jar-plugin.Bundle-Version} - ${maven-jar-plugin.Original-Bundle-Version} - ${maven-jar-plugin.Bundle-Build-Timestamp} - ${maven-jar-plugin.Bundle-ClassPath} - - - - - - - org.codehaus.mojo - exec-maven-plugin - ${exec-maven-plugin.version} - - - - exec - - process-classes - - - - java - - -classpath - - ch.sbb.polarion.thirdparty.bundles.PackageFinder - ${maven-exec-plugin.Export-Package} - - - - - com.google.guava - guava - ${guava.version} - runtime - - - - - - org.sonatype.plugins - nexus-staging-maven-plugin - ${nexus-staging-maven-plugin.version} - true - - ossrh - https://oss.sonatype.org/ - true - - - - - org.apache.maven.plugins - maven-gpg-plugin - ${maven-gpg-plugin.version} - - - sign-artifacts - verify - - sign - - - - - - - org.apache.maven.plugins - maven-source-plugin - ${maven-source-plugin.version} - - - attach-sources - - jar-no-fork - - - - - - - org.apache.maven.plugins - maven-javadoc-plugin - ${maven-javadoc-plugin.version} - - - attach-javadocs - - jar - - - - - ${basedir}/src/main/java - - - - - - - \ No newline at end of file diff --git a/export-package-generator/pom.xml b/export-package-generator/pom.xml deleted file mode 100644 index 3b62e88..0000000 --- a/export-package-generator/pom.xml +++ /dev/null @@ -1,51 +0,0 @@ - - - 4.0.0 - - - ch.sbb.polarion.thirdparty.bundles - generic - 1.1.0 - - - ch.sbb.polarion.thirdparty.bundles - export-package-generator - 1.1.1-SNAPSHOT - jar - - - ${project.groupId}.export_package_generator - - 5.10.3 - - 3.3.0 - - - - - com.google.guava - guava - ${guava.version} - - - - org.junit.jupiter - junit-jupiter-engine - ${junit-jupiter-engine.version} - test - - - - - - - - org.apache.maven.plugins - maven-surefire-plugin - ${maven-surefire-plugin.version} - - - - - - \ No newline at end of file diff --git a/export-package-generator/src/main/java/ch/sbb/polarion/thirdparty/bundles/PackageFinder.java b/export-package-generator/src/main/java/ch/sbb/polarion/thirdparty/bundles/PackageFinder.java deleted file mode 100644 index e0f938a..0000000 --- a/export-package-generator/src/main/java/ch/sbb/polarion/thirdparty/bundles/PackageFinder.java +++ /dev/null @@ -1,55 +0,0 @@ -package ch.sbb.polarion.thirdparty.bundles; - -import com.google.common.reflect.ClassPath; - -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.nio.file.StandardOpenOption; -import java.util.HashSet; -import java.util.Set; -import java.util.TreeSet; -import java.util.stream.Collectors; - -public class PackageFinder { - - private static final String PACKAGES_DELIMITER = "," + System.lineSeparator() + " "; - private static final String MANIFEST_MF = "target/classes/META-INF/MANIFEST.MF"; - - public static void main(String[] args) throws IOException { - Set allExportedPackages = findAllExportedPackages(args); - - String exportPackagesContent = "Export-Package: " + String.join(PACKAGES_DELIMITER, allExportedPackages) + System.lineSeparator(); - - appendToManifest(exportPackagesContent); - } - - public static Set findAllExportedPackages(String[] rootPackages) throws IOException { - Set allExportedPackages = new HashSet<>(); - - for (String rootPackage : rootPackages) { - Set subPackages = findSubPackages(rootPackage); - allExportedPackages.addAll(subPackages); - } - - return allExportedPackages; - } - - public static Set findSubPackages(String packageName) throws IOException { - ClassLoader systemClassLoader = ClassLoader.getSystemClassLoader(); - return ClassPath.from(systemClassLoader) - .getTopLevelClassesRecursive(packageName) - .stream() - .map(ClassPath.ClassInfo::getPackageName) - .collect(Collectors.toCollection(TreeSet::new)); - } - - public static void appendToManifest(String exportPackagesContent) throws IOException { - Path path = Paths.get(MANIFEST_MF); - Files.write(path, exportPackagesContent.getBytes(), StandardOpenOption.APPEND); - - System.out.printf("'Export-Package' entry has been added to file: %s%n", path.toAbsolutePath()); - } - -} diff --git a/export-package-generator/src/test/java/ch/sbb/polarion/thirdparty/bundles/PackageFinderTest.java b/export-package-generator/src/test/java/ch/sbb/polarion/thirdparty/bundles/PackageFinderTest.java deleted file mode 100644 index 38e7aff..0000000 --- a/export-package-generator/src/test/java/ch/sbb/polarion/thirdparty/bundles/PackageFinderTest.java +++ /dev/null @@ -1,32 +0,0 @@ -package ch.sbb.polarion.thirdparty.bundles; - -import org.junit.jupiter.api.Test; - -import java.io.IOException; -import java.util.Set; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -class PackageFinderTest { - - public static final String ORG_JUNIT_JUPITER_API = "org.junit.jupiter.api"; - public static final String COM_GOOGLE_COMMON = "com.google.common"; - public static final String[] ROOT_PACKAGES = {ORG_JUNIT_JUPITER_API, COM_GOOGLE_COMMON}; - - @Test - void findAllExportedPackages() throws IOException { - Set allExportedPackages = PackageFinder.findAllExportedPackages(ROOT_PACKAGES); - - assertEquals(25, allExportedPackages.size()); - } - - @Test - void findSubPackages() throws IOException { - Set subPackages1 = PackageFinder.findSubPackages(ORG_JUNIT_JUPITER_API); - assertEquals(7, subPackages1.size()); - - Set subPackages2 = PackageFinder.findSubPackages(COM_GOOGLE_COMMON); - assertEquals(18, subPackages2.size()); - } - -} \ No newline at end of file diff --git a/bundles/org.apache.poi/pom.xml b/org.apache.poi/pom.xml similarity index 89% rename from bundles/org.apache.poi/pom.xml rename to org.apache.poi/pom.xml index 5c284fb..fcba605 100644 --- a/bundles/org.apache.poi/pom.xml +++ b/org.apache.poi/pom.xml @@ -5,8 +5,8 @@ ch.sbb.polarion.thirdparty.bundles bundles - 1.1.0 - .. + 1.1.1-SNAPSHOT + ../pom.xml Custom Apache POI OSGi bundle @@ -29,9 +29,9 @@ - ch.sbb.polarion.thirdparty.bundles + online.grigoriev.tools export-package-generator - ${project.parent.version} + 1.0.0 runtime diff --git a/bundles/org.apache.poi/src/main/java/dummy/pkg/Dummy.java b/org.apache.poi/src/main/java/dummy/pkg/Dummy.java similarity index 100% rename from bundles/org.apache.poi/src/main/java/dummy/pkg/Dummy.java rename to org.apache.poi/src/main/java/dummy/pkg/Dummy.java diff --git a/bundles/org.apache.poi/src/main/resources/META-INF/MANIFEST.MF b/org.apache.poi/src/main/resources/META-INF/MANIFEST.MF similarity index 100% rename from bundles/org.apache.poi/src/main/resources/META-INF/MANIFEST.MF rename to org.apache.poi/src/main/resources/META-INF/MANIFEST.MF diff --git a/pom.xml b/pom.xml index da33284..bca8cab 100644 --- a/pom.xml +++ b/pom.xml @@ -3,14 +3,58 @@ 4.0.0 ch.sbb.polarion.thirdparty.bundles - generic + bundles 1.1.1-SNAPSHOT pom - - export-package-generator + Custom third-party dependencies + + We have faced the such problem when tried to use Apache POI v5.2.4. This version uses Apache Commons IO v2.13.0, but Polarion has v2.11.0. + As a result it leads to ClassNotFoundExceptions in some cases when Apache POI functionality is called. + This project demonstrates how to solve this problem using the packaging of Apache POI dependency as a separate bundle. + + https://github.com/SchweizerischeBundesbahnen/ch.sbb.polarion.extension.bundles + + + + The SBB License, Version 1.0 + https://github.com/SchweizerischeBundesbahnen/ch.sbb.polarion.extension.bundles/blob/main/LICENSES/SBB.txt + + + + + + SBB Polarion Team + polarion-opensource@sbb.ch + SBB AG + http://www.sbb.ch + + + + + scm:git:git://github.com/SchweizerischeBundesbahnen/ch.sbb.polarion.extension.bundles.git + scm:git:ssh://github.com/SchweizerischeBundesbahnen/ch.sbb.polarion.extension.bundles.git + http://github.com/SchweizerischeBundesbahnen/ch.sbb.polarion.extension.bundles/tree/main + - bundles + + GitHub + https://github.com/SchweizerischeBundesbahnen/ch.sbb.polarion.extension.bundles/issues + + + + + ossrh + https://oss.sonatype.org/content/repositories/snapshots + + + ossrh + https://oss.sonatype.org/service/local/staging/deploy/maven2/ + + + + + org.apache.poi @@ -20,27 +64,291 @@ 17 17 - - 33.2.1-jre - 3.4.0 3.4.2 3.7.1 3.3.0 3.1.2 + + false + + + 1.0 + 2 + ${maven.build.timestamp} + ${project.groupId}.${project.artifactId} + ${project.groupId}.${project.artifactId};singleton:=true + SBB AG + + ${project.artifact.selectedVersion.majorVersion}.${project.artifact.selectedVersion.minorVersion}.${project.artifact.selectedVersion.incrementalVersion} + + ${Original-Bundle-Version} + + ${Export-Package-Root} + + 3.13.0 + 3.2.4 + 3.7.0 + 3.3.1 + 1.7.0 + + + + skip-install-to-local-polarion + + + packaging + pom + + + + true + + + + + install-to-local-polarion + + + + org.apache.maven.plugins + maven-clean-plugin + ${maven-clean-plugin.version} + + + + ${env.POLARION_HOME}/polarion/extensions/${project.groupId}.${project.artifactId}/eclipse/plugins + + **/* + + false + + + + + + + org.apache.maven.plugins + maven-dependency-plugin + ${maven-dependency-plugin.version} + + + copy-to-local-polarion + install + + copy + + + + + ${project.groupId} + ${project.artifactId} + ${project.version} + ${project.packaging} + + + ${env.POLARION_HOME}/polarion/extensions/${project.groupId}.${project.artifactId}/eclipse/plugins + ${skip.copy.to.local.polarion} + + + + + + + + + + gpg-sign + + + + org.apache.maven.plugins + maven-gpg-plugin + + + + + + + nexus-staging + + + + org.sonatype.plugins + nexus-staging-maven-plugin + + + + + + org.apache.maven.plugins - maven-deploy-plugin - ${maven-deploy-plugin.version} - - true - + maven-source-plugin + + + + org.apache.maven.plugins + maven-javadoc-plugin + + + + + org.apache.maven.plugins + maven-compiler-plugin + ${maven-compiler-plugin.version} + + + **/*.java + + + + + + org.apache.maven.plugins + maven-dependency-plugin + ${maven-dependency-plugin.version} + + + build-bundle-classpath + compile + + build-classpath + + + libs + , + / + maven-jar-plugin.Bundle-ClassPath + runtime + + + + + copy-dependencies + prepare-package + + copy-dependencies + + + ${basedir}/target/classes/libs + runtime + + + + + + + org.apache.maven.plugins + maven-jar-plugin + ${maven-jar-plugin.version} + + + ${project.build.outputDirectory}/META-INF/MANIFEST.MF + + ${maven-jar-plugin.Manifest-Version} + ${maven-jar-plugin.Bundle-ManifestVersion} + ${maven-jar-plugin.Bundle-Vendor} + ${maven-jar-plugin.Automatic-Module-Name} + ${maven-jar-plugin.Bundle-SymbolicName} + ${maven-jar-plugin.Bundle-Version} + ${maven-jar-plugin.Original-Bundle-Version} + ${maven-jar-plugin.Bundle-Build-Timestamp} + ${maven-jar-plugin.Bundle-ClassPath} + + + + + + + org.codehaus.mojo + exec-maven-plugin + ${exec-maven-plugin.version} + + + + exec + + process-classes + + + + java + + -classpath + + online.grigoriev.export_package_generator.PackageFinder + ${maven-exec-plugin.Export-Package} + + + + + + org.sonatype.plugins + nexus-staging-maven-plugin + ${nexus-staging-maven-plugin.version} + true + + ossrh + https://oss.sonatype.org/ + true + + + + + org.apache.maven.plugins + maven-gpg-plugin + ${maven-gpg-plugin.version} + + + sign-artifacts + verify + + sign + + + + + + + org.apache.maven.plugins + maven-source-plugin + ${maven-source-plugin.version} + + + attach-sources + + jar-no-fork + + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + ${maven-javadoc-plugin.version} + + + attach-javadocs + + jar + + + + + ${basedir}/src/main/java + + + + - + + \ No newline at end of file diff --git a/src/main/resources/META-INF/MANIFEST.MF b/src/main/resources/META-INF/MANIFEST.MF deleted file mode 100644 index e38ad38..0000000 --- a/src/main/resources/META-INF/MANIFEST.MF +++ /dev/null @@ -1,14 +0,0 @@ -Support-Email: polarion-opensource@sbb.ch -Bundle-Name: Extension for Polarion ALM -Require-Bundle: com.polarion.portal.tomcat, - com.polarion.alm.ui, - com.polarion.platform.guice, - com.polarion.alm.tracker, - org.glassfish.jersey, - com.fasterxml.jackson, - com.fasterxml.jackson.jaxrs, - io.swagger, - org.apache.commons.logging, - slf4j.api, - org.springframework.spring-core, - org.springframework.spring-web