Skip to content

Commit e448191

Browse files
committed
Show milestone banner when prettyprinting.
1 parent c89278d commit e448191

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
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 has been created by SDS SDK 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

0 commit comments

Comments
 (0)