Skip to content

Commit 3e8cea3

Browse files
committed
Snyk fixes and code quality fixes
1 parent 5d3dcab commit 3e8cea3

File tree

3 files changed

+47
-46
lines changed

3 files changed

+47
-46
lines changed

.mvn/wrapper/MavenWrapperDownloader.java

+36-30
Original file line numberDiff line numberDiff line change
@@ -22,30 +22,32 @@ public class MavenWrapperDownloader {
2222

2323
private static final String WRAPPER_VERSION = "0.5.6";
2424
/**
25-
* Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided.
25+
* Default URL to download the maven-wrapper.jar from, if no 'downloadUrl'
26+
* is provided.
2627
*/
2728
private static final String DEFAULT_DOWNLOAD_URL = "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/"
28-
+ WRAPPER_VERSION + "/maven-wrapper-" + WRAPPER_VERSION + ".jar";
29+
+ WRAPPER_VERSION + "/maven-wrapper-" + WRAPPER_VERSION + ".jar";
2930

3031
/**
31-
* Path to the maven-wrapper.properties file, which might contain a downloadUrl property to
32-
* use instead of the default one.
32+
* Path to the maven-wrapper.properties file, which might contain a
33+
* downloadUrl property to use instead of the default one.
3334
*/
34-
private static final String MAVEN_WRAPPER_PROPERTIES_PATH =
35-
".mvn/wrapper/maven-wrapper.properties";
35+
private static final String MAVEN_WRAPPER_PROPERTIES_PATH
36+
= ".mvn/wrapper/maven-wrapper.properties";
3637

3738
/**
3839
* Path where the maven-wrapper.jar will be saved to.
3940
*/
40-
private static final String MAVEN_WRAPPER_JAR_PATH =
41-
".mvn/wrapper/maven-wrapper.jar";
41+
private static final String MAVEN_WRAPPER_JAR_PATH
42+
= ".mvn/wrapper/maven-wrapper.jar";
4243

4344
/**
44-
* Name of the property which should be used to override the default download url for the wrapper.
45+
* Name of the property which should be used to override the default
46+
* download url for the wrapper.
4547
*/
4648
private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl";
4749

48-
public static void main(String args[]) {
50+
public static void main(String args[]) throws Exception {
4951
System.out.println("- Downloader started");
5052
File baseDirectory = new File(args[0]);
5153
System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath());
@@ -54,30 +56,34 @@ public static void main(String args[]) {
5456
// wrapperUrl parameter.
5557
File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH);
5658
String url = DEFAULT_DOWNLOAD_URL;
57-
if(mavenWrapperPropertyFile.exists()) {
58-
FileInputStream mavenWrapperPropertyFileInputStream = null;
59-
try {
60-
mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile);
61-
Properties mavenWrapperProperties = new Properties();
62-
mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream);
63-
url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url);
64-
} catch (IOException e) {
65-
System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'");
66-
} finally {
59+
try {
60+
if (mavenWrapperPropertyFile.exists() && mavenWrapperPropertyFile.getCanonicalPath().startsWith(baseDirectory.getCanonicalPath())) {
61+
FileInputStream mavenWrapperPropertyFileInputStream = null;
6762
try {
68-
if(mavenWrapperPropertyFileInputStream != null) {
69-
mavenWrapperPropertyFileInputStream.close();
70-
}
63+
mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile);
64+
Properties mavenWrapperProperties = new Properties();
65+
mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream);
66+
url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url);
7167
} catch (IOException e) {
72-
// Ignore ...
68+
System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'");
69+
} finally {
70+
try {
71+
if (mavenWrapperPropertyFileInputStream != null) {
72+
mavenWrapperPropertyFileInputStream.close();
73+
}
74+
} catch (IOException e) {
75+
// Ignore ...
76+
}
7377
}
7478
}
79+
} catch (IOException e) {
80+
System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'");
7581
}
7682
System.out.println("- Downloading from: " + url);
7783

7884
File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH);
79-
if(!outputFile.getParentFile().exists()) {
80-
if(!outputFile.getParentFile().mkdirs()) {
85+
if (!outputFile.getParentFile().exists()) {
86+
if (!outputFile.getParentFile().mkdirs()) {
8187
System.out.println(
8288
"- ERROR creating output directory '" + outputFile.getParentFile().getAbsolutePath() + "'");
8389
}
@@ -87,7 +93,7 @@ public static void main(String args[]) {
8793
downloadFileFromURL(url, outputFile);
8894
System.out.println("Done");
8995
System.exit(0);
90-
} catch (Throwable e) {
96+
} catch (IOException e) {
9197
System.out.println("- Error downloading");
9298
e.printStackTrace();
9399
System.exit(1);
@@ -108,9 +114,9 @@ protected PasswordAuthentication getPasswordAuthentication() {
108114
URL website = new URL(urlString);
109115
ReadableByteChannel rbc;
110116
rbc = Channels.newChannel(website.openStream());
111-
FileOutputStream fos = new FileOutputStream(destination);
112-
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
113-
fos.close();
117+
try (FileOutputStream fos = new FileOutputStream(destination.getCanonicalPath().replaceAll("^/+", "").split("\\?")[0])) {
118+
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
119+
}
114120
rbc.close();
115121
}
116122

pom.xml

+4-12
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<groupId>org.springframework.boot</groupId>
88
<artifactId>spring-boot-starter-parent</artifactId>
9-
<version>3.1.4</version>
9+
<version>3.4.0</version>
1010
<relativePath/> <!-- lookup parent from repository -->
1111
</parent>
1212
<groupId>com.contentstack</groupId>
@@ -16,57 +16,50 @@
1616
<description>Demo project for graphql-springboot-api-integration</description>
1717
<properties>
1818
<java.version>1.8</java.version>
19-
<spring-boot.version>3.1.4</spring-boot.version>
20-
<json-smart.version>5.2.2</json-smart.version>
19+
<spring-boot.version>3.4.0</spring-boot.version>
20+
<json-smart.version>2.5.2</json-smart.version>
2121
</properties>
2222

2323
<dependencies>
2424
<dependency>
2525
<groupId>org.springframework.boot</groupId>
2626
<artifactId>spring-boot-starter-web</artifactId>
27-
<version>${spring-boot.version}</version>
2827
</dependency>
2928
<dependency>
3029
<groupId>org.springframework.boot</groupId>
3130
<artifactId>spring-boot-starter-freemarker</artifactId>
32-
<version>${spring-boot.version}</version>
3331
</dependency>
3432
<dependency>
3533
<groupId>org.springframework.boot</groupId>
3634
<artifactId>spring-boot-starter-thymeleaf</artifactId>
37-
<version>${spring-boot.version}</version>
3835
</dependency>
3936
<dependency>
4037
<groupId>org.springframework.boot</groupId>
4138
<artifactId>spring-boot-starter</artifactId>
42-
<version>${spring-boot.version}</version>
4339
</dependency>
4440
<dependency>
4541
<groupId>io.github.cdimascio</groupId>
4642
<artifactId>java-dotenv</artifactId>
47-
<version>${json-smart.version}</version>
43+
<version>5.2.2</version>
4844
</dependency>
4945

5046
<!-- https://mvnrepository.com/artifact/org.projectlombok/lombok -->
5147
<dependency>
5248
<groupId>org.projectlombok</groupId>
5349
<artifactId>lombok</artifactId>
54-
<version>1.18.30</version>
5550
<scope>provided</scope>
5651
</dependency>
5752

5853
<!-- https://mvnrepository.com/artifact/net.minidev/json-smart -->
5954
<dependency>
6055
<groupId>net.minidev</groupId>
6156
<artifactId>json-smart</artifactId>
62-
<version>2.5.0</version>
6357
</dependency>
6458

6559
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-test -->
6660
<dependency>
6761
<groupId>org.springframework.boot</groupId>
6862
<artifactId>spring-boot-test</artifactId>
69-
<version>${spring-boot.version}</version>
7063
<scope>test</scope>
7164
</dependency>
7265

@@ -78,7 +71,6 @@
7871
<plugin>
7972
<groupId>org.springframework.boot</groupId>
8073
<artifactId>spring-boot-maven-plugin</artifactId>
81-
<version>3.1.4</version>
8274
</plugin>
8375
</plugins>
8476
</build>

src/main/java/com/contentstack/gqlspring/Contentstack.java

+7-4
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,13 @@
55
import com.fasterxml.jackson.core.JsonProcessingException;
66
import com.fasterxml.jackson.databind.JsonNode;
77
import com.fasterxml.jackson.databind.ObjectMapper;
8+
89
import io.github.cdimascio.dotenv.Dotenv;
10+
911
import org.jetbrains.annotations.NotNull;
1012

1113
import java.util.Collections;
14+
import java.util.logging.Logger;
1215

1316
public class Contentstack {
1417

@@ -26,7 +29,7 @@ public static <T> T convertToObject(Class<T> clazz, String jsonString) {
2629
ObjectMapper mapper = new ObjectMapper();
2730
return mapper.readValue(jsonString, clazz);
2831
} catch (Exception e) {
29-
e.printStackTrace();
32+
Logger.getLogger(Contentstack.class.getName()).severe(e.getMessage());
3033
return null;
3134
}
3235
}
@@ -63,7 +66,7 @@ public Object getQuery(@NotNull String query, @NotNull String nodeBy, Class<?> c
6366
return convertToObject(cls, jsonNode.toString());
6467

6568
} catch (Exception e) {
66-
e.printStackTrace();
69+
Logger.getLogger(Contentstack.class.getName()).severe(e.getMessage());
6770
}
6871
return null;
6972
}
@@ -73,7 +76,7 @@ private Object toListObject(Class<?> cls, String string) {
7376
try {
7477
return Collections.singletonList(new ObjectMapper().readValue(string, cls)).get(0);
7578
} catch (JsonProcessingException e) {
76-
e.printStackTrace();
79+
Logger.getLogger(Contentstack.class.getName()).severe(e.getMessage());
7780
}
7881
return null;
7982
}
@@ -132,7 +135,7 @@ public Object blogPostById(String id, Class<?> cls) {
132135
JsonNode strResponse = graphqlBuilderInstance.fetch().get("data").get("all_blog_post").get(ITEMS).get(0);
133136
return convertToObject(cls, strResponse.toString());
134137
} catch (Exception e) {
135-
e.printStackTrace();
138+
Logger.getLogger(Contentstack.class.getName()).severe(e.getMessage());
136139
throw new IllegalArgumentException("Invalid = graphql query");
137140
}
138141
}

0 commit comments

Comments
 (0)