NIFI-12283 Added include-swagger-ui profile with activation by default

Deactivating prevents attempt to download swagger asset from the Internet allowing for offline builds.

This closes #7945

Signed-off-by: David Handermann <exceptionfactory@apache.org>
This commit is contained in:
Mark Bean 2023-10-27 16:38:18 +00:00 committed by exceptionfactory
parent c421172ee2
commit 94e746dc47
No known key found for this signature in database
GPG Key ID: 29B6A52D2AAE8DBA
1 changed files with 78 additions and 64 deletions

View File

@ -147,70 +147,6 @@
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>com.googlecode.maven-download-plugin</groupId>
<artifactId>download-maven-plugin</artifactId>
<version>1.7.1</version>
<executions>
<execution>
<id>download-swagger-ui</id>
<!-- This plugin downloads swagger UI static assets during the build, to be
served by the web app to render the dynamically generated Swagger spec.
For offline development, or to build without the swagger UI, activate
the "no-swagger-ui" maven profile during the build with the "-P" flag -->
<goals>
<goal>wget</goal>
</goals>
<configuration>
<url>https://github.com/swagger-api/swagger-ui/archive/v${swagger.ui.version}.tar.gz</url>
<unpack>true</unpack>
<outputDirectory>${project.build.directory}</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>bundle-swagger-ui</id>
<phase>prepare-package</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
<sequential>
<echo>Copy static Swagger UI files to target</echo>
<copy todir="${project.build.directory}/classes/static/swagger">
<fileset dir="${project.build.directory}/swagger-ui-${swagger.ui.version}/dist">
<include name="**" />
</fileset>
</copy>
<echo>Disable schema validation by removing validatorUrl</echo>
<replace token="https://online.swagger.io/validator" value="" dir="${project.build.directory}/classes/static/swagger">
<include name="swagger-ui-bundle.js" />
<include name="swagger-ui-standalone-preset.js" />
</replace>
<echo>Rename 'index.html' to 'ui.html'</echo>
<move file="${project.build.directory}/classes/static/swagger/index.html" tofile="${project.build.directory}/classes/static/swagger/ui.html" />
<echo>Replace default swagger.json location</echo>
<replace token="http://petstore.swagger.io/v2/swagger.json" value="/nifi-registry-api/swagger/swagger.json" dir="${project.build.directory}/classes/static/swagger">
<include name="ui.html" />
</replace>
<echo>Copy swagger.json into static assets folder</echo>
<copy todir="${project.build.directory}/classes/static/swagger">
<fileset dir="${project.build.directory}/swagger">
<include name="*.json" />
</fileset>
</copy>
</sequential>
</target>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.rat</groupId>
<artifactId>apache-rat-plugin</artifactId>
@ -223,6 +159,84 @@
</plugins>
</build>
<profiles>
<profile>
<id>include-swagger-ui</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<build>
<plugins>
<plugin>
<groupId>com.googlecode.maven-download-plugin</groupId>
<artifactId>download-maven-plugin</artifactId>
<version>1.7.1</version>
<executions>
<execution>
<id>download-swagger-ui</id>
<!-- This plugin downloads swagger UI static assets during the build, to be
served by the web app to render the dynamically generated Swagger spec.
For offline development, or to build without the swagger UI, deactivate
the "include-swagger-ui" maven profile during the build with the following
profile option: -P'!include-swagger-ui' -->
<goals>
<goal>wget</goal>
</goals>
<configuration>
<url>https://github.com/swagger-api/swagger-ui/archive/v${swagger.ui.version}.tar.gz</url>
<unpack>true</unpack>
<outputDirectory>${project.build.directory}</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<id>bundle-swagger-ui</id>
<phase>prepare-package</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
<sequential>
<echo>Copy static Swagger UI files to target</echo>
<copy todir="${project.build.directory}/classes/static/swagger">
<fileset dir="${project.build.directory}/swagger-ui-${swagger.ui.version}/dist">
<include name="**" />
</fileset>
</copy>
<echo>Disable schema validation by removing validatorUrl</echo>
<replace token="https://online.swagger.io/validator" value="" dir="${project.build.directory}/classes/static/swagger">
<include name="swagger-ui-bundle.js" />
<include name="swagger-ui-standalone-preset.js" />
</replace>
<echo>Rename 'index.html' to 'ui.html'</echo>
<move file="${project.build.directory}/classes/static/swagger/index.html" tofile="${project.build.directory}/classes/static/swagger/ui.html" />
<echo>Replace default swagger.json location</echo>
<replace token="http://petstore.swagger.io/v2/swagger.json" value="/nifi-registry-api/swagger/swagger.json" dir="${project.build.directory}/classes/static/swagger">
<include name="ui.html" />
</replace>
<echo>Copy swagger.json into static assets folder</echo>
<copy todir="${project.build.directory}/classes/static/swagger">
<fileset dir="${project.build.directory}/swagger">
<include name="*.json" />
</fileset>
</copy>
</sequential>
</target>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>