1
+ /*
2
+ * Copyright (c) 2025 Robert Bosch Manufacturing Solutions GmbH
3
+ *
4
+ * See the AUTHORS file(s) distributed with this work for additional
5
+ * information regarding authorship.
6
+ *
7
+ * This Source Code Form is subject to the terms of the Mozilla Public
8
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
9
+ * file, You can obtain one at https://mozilla.org/MPL/2.0/.
10
+ *
11
+ * SPDX-License-Identifier: MPL-2.0
12
+ */
13
+
1
14
package org .eclipse .esmf .aas .to ;
2
15
3
16
import java .io .BufferedWriter ;
@@ -43,13 +56,13 @@ public class AasToAspectCommand extends AbstractCommand {
43
56
names = { "--output-directory" , "-d" },
44
57
description = "Output directory to write files to"
45
58
)
46
- private String outputPath = "." ;
59
+ private final String outputPath = "." ;
47
60
48
61
@ CommandLine .Option (
49
62
names = { "--submodel-template" , "-s" },
50
63
description = "Select the submodel template(s) to include, as returned by the aas list command"
51
64
)
52
- private List <Integer > selectedOptions = new ArrayList <>();
65
+ private final List <Integer > selectedOptions = new ArrayList <>();
53
66
54
67
@ CommandLine .Mixin
55
68
private LoggingMixin loggingMixin ;
@@ -58,7 +71,7 @@ public class AasToAspectCommand extends AbstractCommand {
58
71
public void run () {
59
72
final String path = parentCommand .parentCommand .getInput ();
60
73
final String extension = FilenameUtils .getExtension ( path );
61
- if ( !extension .equals ( "xml" ) && !extension .equals ( "json" ) && !extension .equals ( "aasx" ) ) {
74
+ if ( !"xml" .equals ( extension ) && !"json" .equals ( extension ) && !"aasx" .equals ( extension ) ) {
62
75
throw new CommandException ( "Input file name must be an .xml, .aasx or .json file" );
63
76
}
64
77
generateAspects ( AasToAspectModelGenerator .fromFile ( new File ( path ) ) );
@@ -76,12 +89,12 @@ private void generateAspects( final AasToAspectModelGenerator generator ) {
76
89
77
90
for ( final Aspect aspect : filteredAspects ) {
78
91
final String aspectString = AspectSerializer .INSTANCE .aspectToString ( aspect );
79
- final File targetFile = modelsRoot .determineAspectModelFile ( aspect .urn () );
80
- LOG .info ( "Writing {}" , targetFile .getAbsolutePath () );
81
- final File directory = targetFile .getParentFile ();
92
+ final File directory = modelsRoot .directoryForNamespace ( aspect .urn () ).toFile ();
82
93
if ( !directory .exists () && !directory .mkdirs () ) {
83
94
throw new CommandException ( "Could not create directory: " + directory .getAbsolutePath () );
84
95
}
96
+ final File targetFile = modelsRoot .determineAspectModelFile ( aspect .urn () );
97
+ LOG .info ( "Writing {}" , targetFile .getAbsolutePath () );
85
98
try ( final Writer writer = new BufferedWriter ( new FileWriter ( targetFile ) ) ) {
86
99
writer .write ( aspectString );
87
100
} catch ( final IOException exception ) {
0 commit comments