Skip to content

Commit 8931298

Browse files
fix
1 parent aaa1914 commit 8931298

File tree

3 files changed

+16
-19
lines changed

3 files changed

+16
-19
lines changed

core/esmf-aspect-meta-model-java/src/main/java/org/eclipse/esmf/aspectmodel/loader/AspectModelLoader.java

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2024 Robert Bosch Manufacturing Solutions GmbH
2+
* Copyright (c) 2025 Robert Bosch Manufacturing Solutions GmbH
33
*
44
* See the AUTHORS file(s) distributed with this work for additional
55
* information regarding authorship.
@@ -17,6 +17,7 @@
1717
import java.io.FileInputStream;
1818
import java.io.IOException;
1919
import java.io.InputStream;
20+
import java.net.JarURLConnection;
2021
import java.net.URI;
2122
import java.nio.file.Path;
2223
import java.util.ArrayDeque;
@@ -121,7 +122,7 @@ public AspectModelLoader( final ResolutionStrategy resolutionStrategy ) {
121122
*/
122123
public AspectModelLoader( final List<ResolutionStrategy> resolutionStrategies ) {
123124
TurtleLoader.init();
124-
if ( resolutionStrategies.size() == 1 ) {
125+
if ( 1 == resolutionStrategies.size() ) {
125126
resolutionStrategy = resolutionStrategies.get( 0 );
126127
} else if ( resolutionStrategies.isEmpty() ) {
127128
resolutionStrategy = DEFAULT_STRATEGY.get();
@@ -416,7 +417,7 @@ public AspectModel loadNamespacePackage( final byte[] binaryContent, final URI l
416417
* {@code https://example.com/package.zip}, the files in the package will have a location URI such as
417418
* {@code jar:file:/some/path/package.zip!/com.example.namespace/1.0.0/AspectModel.ttl} or
418419
* {@code jar:https://example.com/package.zip!/com.example.namespace/1.0.0/AspectModel.ttl}, respectively, as described in
419-
* the JavaDoc for {@link java.net.JarURLConnection}.
420+
* the JavaDoc for {@link JarURLConnection}.
420421
*
421422
* @param location the source location
422423
* @param inputStream the input stream to load the ZIP content from
@@ -473,7 +474,8 @@ private String replaceLegacyBammUrn( final String urn ) {
473474
private boolean containsType( final Model model, final String urn ) {
474475
if ( model.contains( model.createResource( urn ), RDF.type, (RDFNode) null ) ) {
475476
return true;
476-
} else if ( urn.startsWith( AspectModelUrn.PROTOCOL_AND_NAMESPACE_PREFIX ) ) {
477+
}
478+
if ( urn.startsWith( AspectModelUrn.PROTOCOL_AND_NAMESPACE_PREFIX ) ) {
477479
// when deriving a URN from file (via "fileToUrn" method - mainly in samm-cli scenarios),
478480
// we assume new "samm" format, but could actually have been the old "bamm"
479481
return model.contains( model.createResource( toLegacyBammUrn( urn ) ), RDF.type, (RDFNode) null );
@@ -495,7 +497,7 @@ private Optional<AspectModelFile> applyResolutionStrategy( final String urn ) {
495497

496498
try {
497499
final AspectModelUrn aspectModelUrn = AspectModelUrn.fromUrn( replaceLegacyBammUrn( urn ) );
498-
if ( aspectModelUrn.getElementType() != ElementType.NONE ) {
500+
if ( ElementType.NONE != aspectModelUrn.getElementType() ) {
499501
return Optional.empty();
500502
}
501503
final AspectModelFile resolutionResult = resolutionStrategy.apply( aspectModelUrn, this );
@@ -586,14 +588,18 @@ private void resolve( final List<AspectModelFile> inputFiles, final LoaderContex
586588
@Override
587589
public boolean containsDefinition( final AspectModelFile aspectModelFile, final AspectModelUrn urn ) {
588590
final Model model = aspectModelFile.sourceModel();
591+
boolean result = model.contains( model.createResource( urn.toString() ), RDF.type, (RDFNode) null );
592+
if ( result ) {
593+
LOG.debug( "Checking if model contains {}: {}", urn, result );
594+
return result;
595+
}
589596
if ( model.getNsPrefixMap().values().stream().anyMatch( prefixUri -> prefixUri.startsWith( "urn:bamm:" ) ) ) {
590-
final boolean result = model.contains(
597+
result = model.contains(
591598
model.createResource( urn.toString().replace( AspectModelUrn.PROTOCOL_AND_NAMESPACE_PREFIX, "urn:bamm:" ) ), RDF.type,
592599
(RDFNode) null );
593600
LOG.debug( "Checking if model contains {}: {}", urn, result );
594601
return result;
595602
}
596-
final boolean result = model.contains( model.createResource( urn.toString() ), RDF.type, (RDFNode) null );
597603
LOG.debug( "Checking if model contains {}: {}", urn, result );
598604
return result;
599605
}
@@ -674,7 +680,7 @@ public AspectModel loadAspectModelFiles( final Collection<AspectModelFile> input
674680
.findFirst()
675681
.ifPresent( aspect -> mergedModel.setNsPrefix( "", aspect.urn().getUrnPrefix() ) );
676682
for ( final AspectModelFile file : files ) {
677-
if ( file.aspects().size() > 1 ) {
683+
if ( 1 < file.aspects().size() ) {
678684
throw new AspectLoadingException(
679685
"Aspect Model file " + file.humanReadableLocation() + " contains " + file.aspects().size()
680686
+ " aspects, but may only contain one." );
@@ -709,7 +715,7 @@ private void setNamespaces( final Collection<AspectModelFile> files, final Colle
709715
MetaModelBaseAttributes namespaceDefinition = null;
710716
AspectModelFile fileContainingNamespaceDefinition = null;
711717
final List<ModelElement> elementsForUrn = elementsGroupedByNamespaceUrn.get( namespaceUrn );
712-
if ( elementsForUrn != null ) {
718+
if ( null != elementsForUrn ) {
713719
for ( final ModelElement element : elementsForUrn ) {
714720
final AspectModelFile elementFile = element.getSourceFile();
715721
if ( elementFile.sourceModel().contains( null, RDF.type, SammNs.SAMM.Namespace() ) ) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public File determineAspectModelFile( final AspectModelUrn urn ) {
7070
private static File resolveByCanonicalPath( final Path path ) {
7171
File file = path.toFile();
7272
try {
73-
if ( Objects.equals( path.normalize().toString(), file.getCanonicalPath() ) ) {
73+
if ( file.exists() && Objects.equals( path.normalize().toString(), file.getCanonicalPath() ) ) {
7474
return file;
7575
}
7676
} catch ( IOException exception ) {

core/esmf-aspect-meta-model-java/src/test/java/org/eclipse/esmf/aspectmodel/resolver/fs/ModelsRootTest.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,6 @@ void resolveByCanonicalPathShouldReturnEmptyFileWhenCanonicalPathDoesNotMatch()
5757
assertThat( result ).isEqualTo( EMPTY_FILE );
5858
}
5959

60-
@Test
61-
void resolveByCanonicalPathShouldReturnEmptyFileWhenIoExceptionOccurs() throws Exception {
62-
Path pathCausingIoException = Paths.get( "pathCausingIoException" );
63-
64-
File result = invokeResolveByCanonicalPath( pathCausingIoException );
65-
66-
assertThat( result ).isEqualTo( EMPTY_FILE );
67-
}
68-
6960
private static File invokeResolveByCanonicalPath( Path path ) throws Exception {
7061
Method method = ModelsRoot.class.getDeclaredMethod( "resolveByCanonicalPath", Path.class );
7162
method.setAccessible( true );

0 commit comments

Comments
 (0)