diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.yml index 0a9e135..a400242 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.yml +++ b/.github/ISSUE_TEMPLATE/bug_report.yml @@ -38,14 +38,8 @@ body: required: true - type: input attributes: - label: Polarion version - description: 2310, 2404, etc... - validations: - required: true - - type: input - attributes: - label: Extension Version - description: It can be found under https://<>/polarion/#/project/dev/administration/<>/About + label: Version + description: Version of the software where the bug was found. validations: required: true - type: textarea diff --git a/.github/ISSUE_TEMPLATE/feature_request.yml b/.github/ISSUE_TEMPLATE/feature_request.yml index 216f9c3..0218d30 100644 --- a/.github/ISSUE_TEMPLATE/feature_request.yml +++ b/.github/ISSUE_TEMPLATE/feature_request.yml @@ -1,6 +1,6 @@ --- name: Feature request -description: Request an enhancement for this Polarion extension +description: Request an enhancement for this project labels: [enhancement] body: - type: markdown diff --git a/.github/workflows/maven-release.yml b/.github/workflows/maven-release.yml index 8e6ab4f..4161c88 100644 --- a/.github/workflows/maven-release.yml +++ b/.github/workflows/maven-release.yml @@ -20,25 +20,8 @@ jobs: gpg-private-key: ${{ secrets.COM_SONATYPE_CENTRAL_POLARION_OPENSOURCE_GPG_PRIVATE_KEY }} - uses: whelk-io/maven-settings-xml-action@9dc09b23833fa9aa7f27b63db287951856f3433d # v22 with: - repositories: > - [ - { - "id": "s3", - "name": "s3.sbb.polarion.maven.repo", - "url": "s3://sbb-polarion-maven-repo/polarion.mvn", - "releases": { - "enabled": "true", - "updatePolicy": "never" - } - } - ] servers: > [ - { - "id": "s3", - "username": "${{ secrets.S3_SBB_POLARION_MAVEN_REPO_RW_ACCESS_KEY }}", - "password": "${{ secrets.S3_SBB_POLARION_MAVEN_REPO_RW_SECRET_ACCESS_KEY }}" - }, { "id": "github", "username": "${env.GITHUB_ACTOR}", diff --git a/.mvn/extensions.xml b/.mvn/extensions.xml deleted file mode 100644 index 4d1f8b9..0000000 --- a/.mvn/extensions.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - com.github.seahen - maven-s3-wagon - 1.3.3 - - diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index fbeaf36..c763f57 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -21,19 +21,16 @@ These are mostly guidelines, not rules. Use your best judgment, and feel free to ## Prerequisites This project and everyone participating in it are governed by our [Code of Conduct](https://github.com/SchweizerischeBundesbahnen/.github/blob/main/CODE_OF_CONDUCT.md). By participating, you are expected to uphold this code. -All contributors must have an active Polarion license. An active Polarion license means that the contributor has access to a valid Polarion license issued by Siemens, including but not limited to customer, partner, academic, trial, or demo Polarion license. - ## Asking questions Do not know how something in this project works? Curious if this project can achieve your desired functionality? Please ask questions in this project discussions [here](../../discussions) ## What should I know before I get started? ### Tools and Packages -All extensions provided by SBB Polarion Team can be built, tested and packaged using Maven. -It is only possible when the dependencies are extract from Polarion installer. The process must be performed by each contributor. Please consider to use https://github.com/SchweizerischeBundesbahnen/polarion-artifacts-deployer to extract the dependencies for your own Polarion installer version. - -### Design Decisions -The generic implementation for extensions provided by SBB Polarion Team is located in [ch.sbb.polarion.extension.generic](https://github.com/SchweizerischeBundesbahnen/ch.sbb.polarion.extension.generic) +This project can be built, tested and packaged using Maven. +```shell +mvn clean package +``` ## How Can I Contribute? diff --git a/README.md b/README.md index 069a77b..73461ef 100644 --- a/README.md +++ b/README.md @@ -1,36 +1,55 @@ -# Polarion ALM extension to <...> +# Export-Package Generator + +This project is used to find all exported packages and append them to the MANIFEST.MF file. It searches for sub-packages within the specified root packages and creates an "Export-Package" entry in the manifest file. -This Polarion extension provides possibility to <...> ## Build -This extension can be produced using maven: -```bash +The binary artefact can be produced using maven: +```shell mvn clean package ``` -## Installation to Polarion - -To install the extension to Polarion `ch.sbb.polarion.extension.-.jar` -should be copied to `/polarion/extensions/ch.sbb.polarion.extension./eclipse/plugins` -It can be done manually or automated using maven build: -```bash -mvn clean install -P install-to-local-polarion -``` -For automated installation with maven env variable `POLARION_HOME` should be defined and point to folder where Polarion is installed. - -Changes only take effect after restart of Polarion. - -## Polarion configuration - -<...> - - -## Extension Configuration - -<...> - - ## Usage -<...> - +To use the Export-Package Generator the following changes in `pom.xml` are required: + +```xml + + + ch.sbb + export-package-generator + 1.0.0 + runtime + + ... + + + + + + org.codehaus.mojo + exec-maven-plugin + ${exec-maven-plugin.version} + + + + exec + + process-classes + + + + java + + -classpath + + ch.sbb.export_package_generator.PackageFinder + org.apache.poi + + + + ... + +... + +``` diff --git a/pom.xml b/pom.xml index 41e93fb..a3cc150 100644 --- a/pom.xml +++ b/pom.xml @@ -2,24 +2,19 @@ 4.0.0 - - ch.sbb.polarion.extensions - ch.sbb.polarion.extension.generic - 6.0.1 - - - ch.sbb.polarion.extension.extension-name - 0.0.0-SNAPSHOT + ch.sbb + export-package-generator + 1.0.0-SNAPSHOT jar - ... extension of Polarion ALM - This is a Polarion extension which provides ... - https://github.com/SchweizerischeBundesbahnen/ch.sbb.polarion.extension.extension-name + Export-Package Generator + This project is used to find all exported packages and append them to the MANIFEST.MF file. It searches for sub-packages within the specified root packages and creates an "Export-Package" entry in the manifest file. + https://github.com/SchweizerischeBundesbahnen/ch.sbb.export-package-generator The SBB License, Version 1.0 - https://github.com/SchweizerischeBundesbahnen/ch.sbb.polarion.extension.extension-name/blob/main/LICENSES/SBB.txt + https://github.com/SchweizerischeBundesbahnen/ch.sbb.export-package-generator/blob/main/LICENSES/SBB.txt @@ -33,62 +28,144 @@ - scm:git:git://github.com/SchweizerischeBundesbahnen/ch.sbb.polarion.extension.extension-name.git - scm:git:ssh://github.com/SchweizerischeBundesbahnen/ch.sbb.polarion.extension.extension-name.git - http://github.com/SchweizerischeBundesbahnen/ch.sbb.polarion.extension.extension-name/tree/main + scm:git:git://github.com/SchweizerischeBundesbahnen/ch.sbb.export-package-generator.git + scm:git:ssh://github.com/SchweizerischeBundesbahnen/ch.sbb.export-package-generator.git + http://github.com/SchweizerischeBundesbahnen/ch.sbb.export-package-generator/tree/main GitHub - https://github.com/SchweizerischeBundesbahnen/ch.sbb.polarion.extension.extension-name/issues + https://github.com/SchweizerischeBundesbahnen/ch.sbb.export-package-generator/issues - extension-name - ch.sbb.polarion.extension.extension_name + UTF-8 + yyyy-MM-dd HH:mm - ${maven-jar-plugin.Extension-Context} + 17 + 17 + + 33.2.1-jre + 5.10.3 + + + 3.4.0 + 3.13.0 + 3.2.4 + 3.7.0 + 3.3.1 + 3.3.0 + + 1.7.0 - ch.sbb.polarion.extensions - ch.sbb.polarion.extension.generic.app - ${project.parent.version} + com.google.guava + guava + ${guava.version} + + + + org.junit.jupiter + junit-jupiter-engine + ${junit-jupiter-engine.version} + test + + + gpg-sign + + + + org.apache.maven.plugins + maven-gpg-plugin + ${maven-gpg-plugin.version} + + + sign-artifacts + verify + + sign + + + + + + + + + + nexus-staging + + + + org.sonatype.plugins + nexus-staging-maven-plugin + ${nexus-staging-maven-plugin.version} + true + + ossrh + https://oss.sonatype.org/ + true + + + + + + + + org.apache.maven.plugins - maven-dependency-plugin + maven-clean-plugin + ${maven-clean-plugin.version} org.apache.maven.plugins - maven-jar-plugin + maven-compiler-plugin + ${maven-compiler-plugin.version} org.apache.maven.plugins - maven-surefire-plugin - - - - org.jacoco - jacoco-maven-plugin + 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 + + + org.apache.maven.plugins - maven-source-plugin + maven-surefire-plugin + ${maven-surefire-plugin.version} + diff --git a/src/main/java/ch/sbb/export_package_generator/PackageFinder.java b/src/main/java/ch/sbb/export_package_generator/PackageFinder.java new file mode 100644 index 0000000..4f68946 --- /dev/null +++ b/src/main/java/ch/sbb/export_package_generator/PackageFinder.java @@ -0,0 +1,94 @@ +package ch.sbb.export_package_generator; + +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; + +/** + * The {@code PackageFinder} class is responsible for finding and appending all exported packages + * to the project's MANIFEST.MF file. It scans for subpackages within specified root packages + * and generates an 'Export-Package' entry in the manifest file. + */ +public class PackageFinder { + + /** + * Delimiter used to separate package names in the 'Export-Package' entry. + */ + private static final String PACKAGES_DELIMITER = "," + System.lineSeparator() + " "; + + /** + * Path to the MANIFEST.MF file within the target/classes/META-INF directory. + */ + private static final String MANIFEST_MF = "target/classes/META-INF/MANIFEST.MF"; + + /** + * Main method that finds all exported packages from the specified root packages and appends them + * to the MANIFEST.MF file. + * + * @param args Array of root package names to scan for exported packages. + * @throws IOException If an I/O error occurs writing to the manifest file. + */ + 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); + } + + /** + * Finds all exported packages starting from the specified root packages. + * + * @param rootPackages Array of root package names to start the search from. + * @return A set of all exported package names. + * @throws IOException If an I/O error occurs during package search. + */ + 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; + } + + /** + * Finds all subpackages for a given package name. + * + * @param packageName The name of the package to find subpackages for. + * @return A set of subpackage names. + * @throws IOException If an I/O error occurs during classpath scanning. + */ + 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)); + } + + /** + * Appends the 'Export-Package' entry to the MANIFEST.MF file. + * + * @param exportPackagesContent The content to append to the manifest file. + * @throws IOException If an I/O error occurs writing to the manifest file. + */ + 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/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 diff --git a/src/test/java/ch/sbb/export_package_generator/PackageFinderTest.java b/src/test/java/ch/sbb/export_package_generator/PackageFinderTest.java new file mode 100644 index 0000000..394032e --- /dev/null +++ b/src/test/java/ch/sbb/export_package_generator/PackageFinderTest.java @@ -0,0 +1,32 @@ +package ch.sbb.export_package_generator; + +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