Skip to content

Commit 176befd

Browse files
authored
Merge pull request #174 from bci-oss/feature/OMP-SDK-168-milestone-disclaimer
Show milestone banner when prettyprinting.
2 parents 71b4a19 + 2443e1d commit 176befd

File tree

3 files changed

+44
-2
lines changed

3 files changed

+44
-2
lines changed

core/sds-aspect-model-serializer/pom.xml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,22 @@
8484
</annotationProcessorPaths>
8585
</configuration>
8686
</plugin>
87+
<plugin>
88+
<groupId>org.codehaus.mojo</groupId>
89+
<artifactId>properties-maven-plugin</artifactId>
90+
<version>1.0.0</version>
91+
<executions>
92+
<execution>
93+
<phase>generate-resources</phase>
94+
<goals>
95+
<goal>write-project-properties</goal>
96+
</goals>
97+
<configuration>
98+
<outputFile>${project.build.outputDirectory}/pom.properties</outputFile>
99+
</configuration>
100+
</execution>
101+
</executions>
102+
</plugin>
87103
</plugins>
88104
</build>
89105
</project>

core/sds-aspect-model-serializer/src/main/java/io/openmanufacturing/sds/aspectmodel/serializer/PrettyPrinter.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313

1414
package io.openmanufacturing.sds.aspectmodel.serializer;
1515

16+
import java.io.IOException;
17+
import java.io.InputStream;
1618
import java.io.PrintWriter;
1719
import java.util.ArrayDeque;
1820
import java.util.ArrayList;
@@ -22,6 +24,7 @@
2224
import java.util.List;
2325
import java.util.Map;
2426
import java.util.Optional;
27+
import java.util.Properties;
2528
import java.util.Queue;
2629
import java.util.Set;
2730
import java.util.stream.Collectors;
@@ -159,10 +162,33 @@ private Comparator<Map.Entry<String, String>> createPredefinedPrefixOrder() {
159162
.thenComparing( Map.Entry::getKey );
160163
}
161164

165+
private Properties loadProperties( final String filename ) {
166+
final Properties properties = new Properties();
167+
final InputStream propertiesResource = PrettyPrinter.class.getClassLoader().getResourceAsStream( filename );
168+
try {
169+
properties.load( propertiesResource );
170+
} catch ( final IOException exception ) {
171+
throw new RuntimeException( "Failed to load Properties: " + filename );
172+
}
173+
return properties;
174+
}
175+
176+
private void showMilestoneBanner() {
177+
// property file generated by properties-maven-plugin at build time
178+
final Properties applicationProperties = loadProperties( "pom.properties" );
179+
final String version = applicationProperties.get( "aspect-meta-model-version" ).toString();
180+
if ( version.contains( "-M" ) ) {
181+
writer.println( "# This model was created using BAMM version " + version + " and is not intended for productive usage." );
182+
writer.println();
183+
}
184+
}
185+
162186
/**
163187
* Print to the PrintWriter given in the constructor. This method does not close the PrintWriter.
164188
*/
165189
public void print() {
190+
showMilestoneBanner();
191+
166192
prefixMap.entrySet().stream().sorted( prefixOrder ).forEach( entry -> writer.format( "@prefix %s: <%s> .%n", entry.getKey(), entry.getValue() ) );
167193
writer.println();
168194

tools/bamm-cli/src/test/java/io/openmanufacturing/sds/ApplicationIntegrationTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ public void testPrettyPrintingToFile( final KnownVersion metaModelVersion ) {
288288
@MethodSource( value = "allVersions" )
289289
public void testPrettyPrintingToStdout( final KnownVersion metaModelVersion ) {
290290
createValidArgsExecution( metaModelVersion, "prettyprint" );
291-
assertThat( stdoutBuffer.toString( StandardCharsets.UTF_8 ) ).startsWith( "@prefix" );
291+
assertThat( stdoutBuffer.toString( StandardCharsets.UTF_8 ) ).contains( "@prefix" );
292292
}
293293

294294
@ParameterizedTest
@@ -303,7 +303,7 @@ public void testVersionMigrationToFile( final KnownVersion metaModelVersion ) {
303303
@MethodSource( value = "allVersions" )
304304
public void testVersionMigrationToStdout( final KnownVersion metaModelVersion ) {
305305
createValidArgsExecution( metaModelVersion, "migrate" );
306-
assertThat( stdoutBuffer.toString( StandardCharsets.UTF_8 ) ).startsWith( "@prefix" );
306+
assertThat( stdoutBuffer.toString( StandardCharsets.UTF_8 ) ).contains( "@prefix" );
307307
}
308308

309309
@ParameterizedTest

0 commit comments

Comments
 (0)