Skip to content
Closed
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions datamodel/odata-v4/odata-v4-generator/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,6 @@
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
</dependency>
<dependency>
<groupId>com.sun.codemodel</groupId>
<artifactId>codemodel</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@
import java.io.InputStream;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.nio.file.FileSystem;
import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.PathMatcher;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
Expand All @@ -33,7 +36,6 @@
import org.apache.olingo.commons.api.edm.provider.CsdlTerm;
import org.apache.olingo.commons.api.format.ContentType;
import org.slf4j.Logger;
import org.springframework.util.AntPathMatcher;

import com.google.common.collect.Multimap;
import com.sap.cloud.sdk.cloudplatform.util.StringUtils;
Expand Down Expand Up @@ -392,16 +394,14 @@ private String getCanonicalPath( @Nullable final File outputDir )
private boolean excludePatternMatch( final String excludeFilePattern, final String serviceMetadataFilename )
{
final List<String> excludeFilePatternEach = new ArrayList<>(Arrays.asList(excludeFilePattern.split(",")));
final AntPathMatcher antPathMatcher = new AntPathMatcher();
final FileSystem fileSystem = FileSystems.getDefault();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


for( final String filePattern : excludeFilePatternEach ) {
if( antPathMatcher.match(filePattern, serviceMetadataFilename) ) {
logger
.info(
String
.format(
"Excluding metadata file %s, as it matches with the excludes pattern.",
serviceMetadataFilename));
final PathMatcher pathMatcher = fileSystem.getPathMatcher("glob:" + filePattern.trim());

if( pathMatcher.matches(Paths.get(serviceMetadataFilename)) ) {
final String msg = "Excluding metadata file %s, as it matches with the excludes pattern.";
logger.info(String.format(msg, serviceMetadataFilename));
return true;
}
}
Expand Down
4 changes: 0 additions & 4 deletions datamodel/odata/odata-generator/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,6 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
</dependency>
<dependency>
<groupId>com.sun.codemodel</groupId>
<artifactId>codemodel</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@
import java.lang.reflect.Field;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.nio.file.FileSystem;
import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.PathMatcher;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
Expand All @@ -29,7 +32,6 @@
import org.apache.olingo.odata2.core.edm.provider.EdmImplProv;
import org.apache.olingo.odata2.core.edm.provider.EdmxProvider;
import org.slf4j.Logger;
import org.springframework.util.AntPathMatcher;

import com.google.common.collect.Lists;
import com.google.common.collect.Multimap;
Expand Down Expand Up @@ -349,19 +351,17 @@ private String getCanonicalPath( @Nullable final File outputDir )
}
}

private boolean excludePatternMatch( final String excludeFilePattern, final String serviceMetadataFilename )
static boolean excludePatternMatch( final String excludeFilePattern, final String serviceMetadataFilename )
{
final List<String> excludeFilePatternEach = new ArrayList<>(Arrays.asList(excludeFilePattern.split(",")));
final AntPathMatcher antPathMatcher = new AntPathMatcher();
final FileSystem fileSystem = FileSystems.getDefault();

for( final String filePattern : excludeFilePatternEach ) {
if( antPathMatcher.match(filePattern, serviceMetadataFilename) ) {
logger
.info(
String
.format(
"Excluding metadata file %s, as it matches with the excludes pattern.",
serviceMetadataFilename));
final PathMatcher pathMatcher = fileSystem.getPathMatcher("glob:" + filePattern.trim());

if( pathMatcher.matches(Paths.get(serviceMetadataFilename)) ) {
final String msg = "Excluding metadata file %s, as it matches with the excludes pattern.";
logger.info(String.format(msg, serviceMetadataFilename));
return true;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.sap.cloud.sdk.datamodel.odata.generator;

import static com.sap.cloud.sdk.datamodel.odata.generator.ODataToVdmGenerator.excludePatternMatch;

import java.io.File;

import org.assertj.core.api.SoftAssertions;
import org.junit.jupiter.api.Test;

public class ODataToVdmGeneratorTest
{
@Test
void testExcludePatternMatch()
{
// Get file-name only, without path
final String fileName = new File("src/test/resources/sample/Spec.edmx").getName();

final SoftAssertions softly = new SoftAssertions();
for( final String pattern : new String[] { "*.edmx", "*.*", "sp*c.edmx", "*.EDMX" } )
softly
.assertThat(excludePatternMatch(pattern, fileName))
.describedAs("%s matches %s", pattern, fileName)
.isTrue();

for( final String pattern : new String[] { "F", "*/*", "/resources/*/*.edmx", "/resources/*/*" } )
softly
.assertThat(excludePatternMatch(pattern, fileName))
.describedAs("%s not matches %s", pattern, fileName)
.isFalse();

softly.assertThat(excludePatternMatch("A,B,spec.edmx", fileName)).describedAs("fallback").isTrue();
softly.assertAll();
}
}
6 changes: 6 additions & 0 deletions datamodel/openapi/openapi-api-sample/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<exclusions>
<exclusion>
<artifactId>commons-logging</artifactId>
<groupId>commons-logging</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
Expand Down
6 changes: 6 additions & 0 deletions datamodel/openapi/openapi-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<exclusions>
<exclusion>
<artifactId>commons-logging</artifactId>
<groupId>commons-logging</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
<!-- Spring dependencies -->
<!-- Keep these versions consistent with the ones from the SAP Java Buildpack (after their 2.0 release) -->
<!-- see https://github.wdf.sap.corp/xs2-java/xs-java-buildpack/blob/master/resources/pom.xml -->
<spring.version>6.2.12</spring.version>
<spring.version>7.0.0</spring.version>
<spring-security.version>6.1.5</spring-security.version>
<slf4j.version>2.0.17</slf4j.version>
<assertj-core.version>3.27.6</assertj-core.version>
Expand Down
Loading