Skip to content

Commit 0febb31

Browse files
fix
1 parent 8931298 commit 0febb31

File tree

3 files changed

+32
-11
lines changed

3 files changed

+32
-11
lines changed

core/esmf-aspect-meta-model-java/src/main/java/org/eclipse/esmf/aspectmodel/resolver/FileSystemStrategy.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public FileSystemStrategy( final ModelsRoot modelsRoot ) {
8484
public AspectModelFile apply( final AspectModelUrn aspectModelUrn, final ResolutionStrategySupport resolutionStrategySupport ) {
8585
final List<ModelResolutionException.LoadingFailure> checkedLocations = new ArrayList<>();
8686

87-
final File namedResourceFile = modelsRoot.determineAspectModelFile( aspectModelUrn );
87+
final File namedResourceFile = modelsRoot.resolveAspectModelFile( aspectModelUrn );
8888
if ( namedResourceFile.exists() ) {
8989
final Try<RawAspectModelFile> tryFile = Try.of( () -> AspectModelFileLoader.load( namedResourceFile ) );
9090
if ( tryFile.isFailure() ) {

core/esmf-aspect-meta-model-java/src/main/java/org/eclipse/esmf/aspectmodel/resolver/fs/ModelsRoot.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,22 +51,30 @@ public Stream<Path> paths() {
5151

5252
public abstract Path directoryForNamespace( final AspectModelUrn urn );
5353

54+
public File determineAspectModelFile( final AspectModelUrn urn ) {
55+
return constructAspectModelFilePath( urn ).toFile();
56+
}
57+
5458
/**
55-
* Determines the aspect model file for the given {@link AspectModelUrn}.
59+
* Resolve the aspect model file for the given {@link AspectModelUrn}.
5660
*
5761
* <p>Constructs the file path by resolving the namespace directory.
5862
* Validates the file using its canonical path.
5963
*
60-
* <p>Returns an empty file if the resolution fails.
64+
* <p>Returns an empty file if the resolution fails.s
6165
*
6266
* @param urn the {@link AspectModelUrn} representing the aspect model.
6367
* @return the resolved {@link File}, or an empty file if resolution fails.
6468
*/
65-
public File determineAspectModelFile( final AspectModelUrn urn ) {
66-
Path path = directoryForNamespace( urn ).resolve( urn.getName() + ".ttl" );
69+
public File resolveAspectModelFile( final AspectModelUrn urn ) {
70+
Path path = constructAspectModelFilePath( urn );
6771
return resolveByCanonicalPath( path );
6872
}
6973

74+
private Path constructAspectModelFilePath( final AspectModelUrn urn ) {
75+
return directoryForNamespace( urn ).resolve( urn.getName() + ".ttl" );
76+
}
77+
7078
private static File resolveByCanonicalPath( final Path path ) {
7179
File file = path.toFile();
7280
try {

tools/samm-cli/src/main/java/org/eclipse/esmf/aas/to/AasToAspectCommand.java

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
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+
114
package org.eclipse.esmf.aas.to;
215

316
import java.io.BufferedWriter;
@@ -43,13 +56,13 @@ public class AasToAspectCommand extends AbstractCommand {
4356
names = { "--output-directory", "-d" },
4457
description = "Output directory to write files to"
4558
)
46-
private String outputPath = ".";
59+
private final String outputPath = ".";
4760

4861
@CommandLine.Option(
4962
names = { "--submodel-template", "-s" },
5063
description = "Select the submodel template(s) to include, as returned by the aas list command"
5164
)
52-
private List<Integer> selectedOptions = new ArrayList<>();
65+
private final List<Integer> selectedOptions = new ArrayList<>();
5366

5467
@CommandLine.Mixin
5568
private LoggingMixin loggingMixin;
@@ -58,7 +71,7 @@ public class AasToAspectCommand extends AbstractCommand {
5871
public void run() {
5972
final String path = parentCommand.parentCommand.getInput();
6073
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 ) ) {
6275
throw new CommandException( "Input file name must be an .xml, .aasx or .json file" );
6376
}
6477
generateAspects( AasToAspectModelGenerator.fromFile( new File( path ) ) );
@@ -76,12 +89,12 @@ private void generateAspects( final AasToAspectModelGenerator generator ) {
7689

7790
for ( final Aspect aspect : filteredAspects ) {
7891
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();
8293
if ( !directory.exists() && !directory.mkdirs() ) {
8394
throw new CommandException( "Could not create directory: " + directory.getAbsolutePath() );
8495
}
96+
final File targetFile = modelsRoot.determineAspectModelFile( aspect.urn() );
97+
LOG.info( "Writing {}", targetFile.getAbsolutePath() );
8598
try ( final Writer writer = new BufferedWriter( new FileWriter( targetFile ) ) ) {
8699
writer.write( aspectString );
87100
} catch ( final IOException exception ) {

0 commit comments

Comments
 (0)