mirror of
https://github.com/renovatebot/renovate.git
synced 2025-01-12 06:56:24 +00:00
refactor(maven): externalize update and extract
This commit is contained in:
parent
ec7ad01faa
commit
431588a27a
3 changed files with 46 additions and 41 deletions
|
@ -135,8 +135,31 @@ function extractDependencies(raw) {
|
|||
return result;
|
||||
}
|
||||
|
||||
async function extractAllPackageFiles(config, packageFiles) {
|
||||
const mavenFiles = [];
|
||||
for (const packageFile of packageFiles) {
|
||||
const content = await platform.getFile(packageFile);
|
||||
if (content) {
|
||||
const deps = extractDependencies(content);
|
||||
if (deps) {
|
||||
mavenFiles.push({
|
||||
packageFile,
|
||||
manager: 'maven',
|
||||
...deps,
|
||||
});
|
||||
} else {
|
||||
logger.info({ packageFile }, 'can not read dependencies');
|
||||
}
|
||||
} else {
|
||||
logger.info({ packageFile }, 'packageFile has no content');
|
||||
}
|
||||
}
|
||||
return mavenFiles;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
containsPlaceholder,
|
||||
parsePom,
|
||||
extractDependencies,
|
||||
extractAllPackageFiles,
|
||||
};
|
||||
|
|
|
@ -1,44 +1,5 @@
|
|||
const { extractDependencies } = require('./extract');
|
||||
|
||||
async function extractAllPackageFiles(config, packageFiles) {
|
||||
const mavenFiles = [];
|
||||
for (const packageFile of packageFiles) {
|
||||
const content = await platform.getFile(packageFile);
|
||||
if (content) {
|
||||
const deps = extractDependencies(content);
|
||||
if (deps) {
|
||||
mavenFiles.push({
|
||||
packageFile,
|
||||
manager: 'maven',
|
||||
...deps,
|
||||
});
|
||||
} else {
|
||||
logger.info({ packageFile }, 'can not read dependencies');
|
||||
}
|
||||
} else {
|
||||
logger.info({ packageFile }, 'packageFile has no content');
|
||||
}
|
||||
}
|
||||
return mavenFiles;
|
||||
}
|
||||
|
||||
function updateDependency(fileContent, upgrade) {
|
||||
const { currentValue, newValue, fileReplacePosition } = upgrade;
|
||||
const leftPart = fileContent.slice(0, fileReplacePosition);
|
||||
const rightPart = fileContent.slice(fileReplacePosition);
|
||||
const versionClosePosition = rightPart.indexOf('</');
|
||||
const restPart = rightPart.slice(versionClosePosition);
|
||||
const versionPart = rightPart.slice(0, versionClosePosition);
|
||||
const version = versionPart.trim();
|
||||
if (version === newValue) {
|
||||
return fileContent;
|
||||
}
|
||||
if (version === currentValue) {
|
||||
const replacedPart = versionPart.replace(currentValue, newValue);
|
||||
return leftPart + replacedPart + restPart;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
const { extractAllPackageFiles } = require('./extract');
|
||||
const { updateDependency } = require('./update');
|
||||
|
||||
module.exports = {
|
||||
extractAllPackageFiles,
|
||||
|
|
21
lib/manager/maven/update.js
Normal file
21
lib/manager/maven/update.js
Normal file
|
@ -0,0 +1,21 @@
|
|||
module.exports = {
|
||||
updateDependency,
|
||||
};
|
||||
|
||||
function updateDependency(fileContent, upgrade) {
|
||||
const { currentValue, newValue, fileReplacePosition } = upgrade;
|
||||
const leftPart = fileContent.slice(0, fileReplacePosition);
|
||||
const rightPart = fileContent.slice(fileReplacePosition);
|
||||
const versionClosePosition = rightPart.indexOf('</');
|
||||
const restPart = rightPart.slice(versionClosePosition);
|
||||
const versionPart = rightPart.slice(0, versionClosePosition);
|
||||
const version = versionPart.trim();
|
||||
if (version === newValue) {
|
||||
return fileContent;
|
||||
}
|
||||
if (version === currentValue) {
|
||||
const replacedPart = versionPart.replace(currentValue, newValue);
|
||||
return leftPart + replacedPart + restPart;
|
||||
}
|
||||
return null;
|
||||
}
|
Loading…
Reference in a new issue