Skip to content

Commit 7292baf

Browse files
authored
fix properties; break loops (#70)
1 parent 8d524d4 commit 7292baf

File tree

2 files changed

+24
-16
lines changed

2 files changed

+24
-16
lines changed

gradle.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { readdirSync } from 'fs';
44

55
export const getJSFromFile = async (filename) => {
66
try {
7-
// const baseGradle = await g2js.parseFile(filename);
87
const parsedGradleFiles = [];
98
const files = [];
109
readdirSync('./', { recursive: true }).forEach((file) => {
@@ -80,8 +79,8 @@ export const retrieveSimilarGradlePackages = async (parsedGradle, springBootVers
8079

8180
if (defaultVersions.length) {
8281
const declaredPackages = [];
83-
gradleDependenciesWithVersions.forEach((gradleDependency) =>
84-
defaultVersions.forEach((bootPackage) => {
82+
for (const gradleDependency of gradleDependenciesWithVersions) {
83+
for (const bootPackage of defaultVersions) {
8584
if (gradleDependency.group === bootPackage.group && gradleDependency.name === bootPackage.name) {
8685
const existingMatches = declaredPackages.find(
8786
(declaredPackage) => declaredPackage.group === gradleDependency.group && declaredPackage.name === gradleDependency.name,
@@ -90,10 +89,11 @@ export const retrieveSimilarGradlePackages = async (parsedGradle, springBootVers
9089
declaredPackages.push(
9190
new Package(gradleDependency.group, gradleDependency.name, gradleDependency.version, bootPackage.version),
9291
);
92+
break;
9393
}
9494
}
95-
}),
96-
);
95+
}
96+
}
9797

9898
console.log('Declared Gradle Package Count -', declaredPackages.length);
9999
if (declaredPackages.length) {

pom.js

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,8 @@ export const getPomSpringBootVersion = async (parsedPom) => {
9898
}
9999
}
100100
if (
101-
parsedPom.project?.dependencyManagement?.[0]?.dependencies.dependency.groupId === 'org.springframework.boot' &&
102-
parsedPom.project?.dependencyManagement?.[0]?.dependencies.dependency.artifactId === 'spring-boot-dependencies'
101+
parsedPom.project?.dependencyManagement?.[0]?.dependencies?.dependency?.groupId === 'org.springframework.boot' &&
102+
parsedPom.project?.dependencyManagement?.[0]?.dependencies?.dependency?.artifactId === 'spring-boot-dependencies'
103103
) {
104104
return replaceVariable(parsedPom.project.properties, parsedPom.project.dependencyManagement[0].dependencies.dependency.version);
105105
}
@@ -120,19 +120,20 @@ export const retrieveSimilarPomPackages = async (parsedPom, springBootVersion) =
120120

121121
if (defaultVersions.length) {
122122
const declaredPackages = [];
123-
pomDependenciesWithVersions.forEach((pomDependency) =>
124-
defaultVersions.forEach((bootPackage) => {
123+
for (const pomDependency of pomDependenciesWithVersions) {
124+
for (const bootPackage of defaultVersions) {
125125
if (pomDependency.groupId === bootPackage.group && pomDependency.artifactId === bootPackage.name) {
126126
const pomVersion = replaceVariable(parsedPom.project.properties, pomDependency.version);
127127
const existingMatches = declaredPackages.find(
128128
(declaredPackage) => declaredPackage.group === pomDependency.groupId && declaredPackage.name === pomDependency.artifactId,
129129
);
130130
if (!existingMatches) {
131131
declaredPackages.push(new Package(pomDependency.groupId, pomDependency.artifactId, pomVersion, bootPackage.version));
132+
break;
132133
}
133134
}
134-
}),
135-
);
135+
}
136+
}
136137

137138
console.log('Declared Pom Package Count -', declaredPackages.length);
138139
if (declaredPackages.length) {
@@ -154,13 +155,14 @@ export const retrieveSimilarPomProperties = async (parsedPom, springBootVersion)
154155

155156
if (defaultProperties.length) {
156157
const declaredProperties = [];
157-
pomProperties.forEach((pomProperty) =>
158-
defaultProperties.forEach((defaultProperty) => {
158+
for (const pomProperty of pomProperties) {
159+
for (const defaultProperty of defaultProperties) {
159160
if (pomProperty === defaultProperty.property) {
160161
declaredProperties.push(pomProperty);
162+
break;
161163
}
162-
}),
163-
);
164+
}
165+
}
164166

165167
console.log('Declared Pom Properties Count -', declaredProperties.length);
166168
if (declaredProperties.length) {
@@ -190,8 +192,14 @@ const getSpringDefaultProperties = async (springBootVersion) => {
190192

191193
const replaceVariable = (properties, version) => {
192194
if (String(version).startsWith('${')) {
195+
const flatProperties = {};
196+
properties.forEach((property) => {
197+
for (const [key, value] of Object.entries(property)) {
198+
flatProperties[key] = value;
199+
}
200+
});
193201
const variableName = version.replace('${', '').replace('}', '');
194-
return properties[0][variableName];
202+
return flatProperties[variableName];
195203
}
196204
return version;
197205
};

0 commit comments

Comments
 (0)