Skip to content

Commit

Permalink
Merge maven-config-setup-helper with maven-base
Browse files Browse the repository at this point in the history
  • Loading branch information
tiagobento committed Oct 1, 2024
1 parent d06f2ca commit 73d8570
Show file tree
Hide file tree
Showing 50 changed files with 90 additions and 360 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

const buildEnv = require("./env");
const { setupMavenConfigFile, buildTailFromPackageJsonDependencies } = require("@kie-tools/maven-config-setup-helper");
const { setupMavenConfigFile, buildTailFromPackageJsonDependencies } = require("@kie-tools/maven-base");

setupMavenConfigFile(`
-Drevision=${buildEnv.env.droolsProcessUsertasksQuarkusExample.version}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
"@kie-tools/maven-base": "workspace:*"
},
"devDependencies": {
"@kie-tools/maven-config-setup-helper": "workspace:*",
"@kie-tools/root-env": "workspace:*",
"run-script-os": "^1.1.6"
},
Expand Down
6 changes: 1 addition & 5 deletions examples/jbpm-compact-architecture-example/mvn.bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,7 @@
*/

const buildEnv = require("./env");
const {
setupMavenConfigFile,
setPomProperty,
buildTailFromPackageJsonDependencies,
} = require("@kie-tools/maven-config-setup-helper");
const { setupMavenConfigFile, setPomProperty, buildTailFromPackageJsonDependencies } = require("@kie-tools/maven-base");

setupMavenConfigFile(`
-Drevision=${buildEnv.env.jbpmCompactArchitectureExample.version}
Expand Down
1 change: 0 additions & 1 deletion examples/jbpm-compact-architecture-example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
"devDependencies": {
"@kie-tools/kogito-management-console": "workspace:*",
"@kie-tools/kogito-task-console": "workspace:*",
"@kie-tools/maven-config-setup-helper": "workspace:*",
"@kie-tools/root-env": "workspace:*",
"run-script-os": "^1.1.6"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

const buildEnv = require("./env");
const { setupMavenConfigFile, buildTailFromPackageJsonDependencies } = require("@kie-tools/maven-config-setup-helper");
const { setupMavenConfigFile, buildTailFromPackageJsonDependencies } = require("@kie-tools/maven-base");

setupMavenConfigFile(`
-Drevision=${buildEnv.env.sonataflowGreetingQuarkus.version}
Expand Down
1 change: 0 additions & 1 deletion examples/sonataflow-greeting-quarkus-example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
"@kie-tools/sonataflow-quarkus-devui": "workspace:*"
},
"devDependencies": {
"@kie-tools/maven-config-setup-helper": "workspace:*",
"@kie-tools/root-env": "workspace:*",
"run-script-os": "^1.1.6"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/dashbuilder/mvn.bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

const buildEnv = require("./env");
const { setupMavenConfigFile, buildTailFromPackageJsonDependencies } = require("@kie-tools/maven-config-setup-helper");
const { setupMavenConfigFile, buildTailFromPackageJsonDependencies } = require("@kie-tools/maven-base");

setupMavenConfigFile(`
-Drevision=${buildEnv.env.dashbuilder.version}
Expand Down
1 change: 0 additions & 1 deletion packages/dashbuilder/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
},
"devDependencies": {
"@kie-tools/dashbuilder-component-assembler": "workspace:*",
"@kie-tools/maven-config-setup-helper": "workspace:*",
"@kie-tools/root-env": "workspace:*",
"copyfiles": "^2.4.1",
"rimraf": "^3.0.2",
Expand Down
6 changes: 1 addition & 5 deletions packages/dev-deployment-base-image/mvn.bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,7 @@
*/

const buildEnv = require("./env");
const {
setupMavenConfigFile,
installMvnw,
buildTailFromPackageJsonDependencies,
} = require("@kie-tools/maven-config-setup-helper");
const { setupMavenConfigFile, installMvnw, buildTailFromPackageJsonDependencies } = require("@kie-tools/maven-base");

setupMavenConfigFile(`
-Drevision=${buildEnv.env.devDeploymentBaseImage.version}
Expand Down
1 change: 0 additions & 1 deletion packages/dev-deployment-base-image/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
"devDependencies": {
"@kie-tools/dev-deployment-upload-service": "workspace:*",
"@kie-tools/image-builder": "workspace:*",
"@kie-tools/maven-config-setup-helper": "workspace:*",
"@kie-tools/root-env": "workspace:*",
"rimraf": "^3.0.2",
"run-script-os": "^1.1.6"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

const buildEnv = require("./env");
const { setupMavenConfigFile } = require("@kie-tools/maven-config-setup-helper");
const { setupMavenConfigFile } = require("@kie-tools/maven-base");

setupMavenConfigFile(`
-Drevision=${buildEnv.env.devDeploymentKogitoQuarkusBlankAppImage.version}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"image:docker:build": "kie-tools--image-builder build --allowHostNetworkAccess -r \"$(build-env devDeploymentKogitoQuarkusBlankAppImage.registry)\" -a \"$(build-env devDeploymentKogitoQuarkusBlankAppImage.account)\" -n \"$(build-env devDeploymentKogitoQuarkusBlankAppImage.name)\" -t \"$(build-env devDeploymentKogitoQuarkusBlankAppImage.buildTag)\" --build-arg BUILDER_IMAGE_ARG=\"$(build-env devDeploymentKogitoQuarkusBlankAppImage.builderImage)\" --build-arg ROOT_PATH=/",
"install": "node install.js",
"m2-repo-via-http:container:kill": "(docker container kill m2-repo-via-http || true) && (docker container rm m2-repo-via-http || true)",
"m2-repo-via-http:container:prepare-m2-repo-volume": "node -e 'require(`@kie-tools/maven-config-setup-helper`).prepareHardLinkedM2ForPackage(`./dist/tmp-m2/repository`, `./node_modules/@kie-tools/dev-deployment-kogito-quarkus-blank-app`)'",
"m2-repo-via-http:container:prepare-m2-repo-volume": "node -e 'require(`@kie-tools/maven-base`).prepareHardLinkedM2ForPackage(`./dist/tmp-m2/repository`, `./node_modules/@kie-tools/dev-deployment-kogito-quarkus-blank-app`)'",
"m2-repo-via-http:container:run": "(pnpm m2-repo-via-http:container:kill || true) && pnpm m2-repo-via-http:container:prepare-m2-repo-volume && docker run -p 8888:80 --name m2-repo-via-http -v \"./dist/tmp-m2/repository:/var/www/html\" -dit $(build-env devDeploymentKogitoQuarkusBlankAppImage.dev.mavenM2RepoViaHttpImage)",
"powershell": "@powershell -NoProfile -ExecutionPolicy Unrestricted -Command"
},
Expand All @@ -41,7 +41,7 @@
},
"devDependencies": {
"@kie-tools/image-builder": "workspace:*",
"@kie-tools/maven-config-setup-helper": "workspace:*",
"@kie-tools/maven-base": "workspace:*",
"@kie-tools/maven-m2-repo-via-http-image": "workspace:*",
"@kie-tools/root-env": "workspace:*",
"rimraf": "^3.0.2",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,7 @@
*/

const buildEnv = require("./env");
const {
setupMavenConfigFile,
installMvnw,
buildTailFromPackageJsonDependencies,
} = require("@kie-tools/maven-config-setup-helper");
const { setupMavenConfigFile, installMvnw, buildTailFromPackageJsonDependencies } = require("@kie-tools/maven-base");

setupMavenConfigFile(
`
Expand Down
4 changes: 2 additions & 2 deletions packages/dev-deployment-kogito-quarkus-blank-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@
"quarkus:dev:win32": "mvn clean package quarkus:dev `-DskipTests"
},
"dependencies": {
"@kie-tools/jbpm-quarkus-devui": "workspace:*"
"@kie-tools/jbpm-quarkus-devui": "workspace:*",
"@kie-tools/maven-base": "workspace:*"
},
"devDependencies": {
"@kie-tools/maven-config-setup-helper": "workspace:*",
"@kie-tools/root-env": "workspace:*",
"run-script-os": "^1.1.6"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/dmn-testing-models/mvn.bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

const buildEnv = require("./env");
const { setupMavenConfigFile, buildTailFromPackageJsonDependencies } = require("@kie-tools/maven-config-setup-helper");
const { setupMavenConfigFile, buildTailFromPackageJsonDependencies } = require("@kie-tools/maven-base");

setupMavenConfigFile(`
-Drevision=${buildEnv.env.dmnTestingModels.version}
Expand Down
1 change: 0 additions & 1 deletion packages/dmn-testing-models/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
"@kie-tools/maven-base": "workspace:*"
},
"devDependencies": {
"@kie-tools/maven-config-setup-helper": "workspace:*",
"@kie-tools/root-env": "workspace:*",
"copyfiles": "^2.4.1",
"rimraf": "^3.0.2",
Expand Down
2 changes: 1 addition & 1 deletion packages/extended-services-java/mvn.bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

const buildEnv = require("./env");
const { setupMavenConfigFile, buildTailFromPackageJsonDependencies } = require("@kie-tools/maven-config-setup-helper");
const { setupMavenConfigFile, buildTailFromPackageJsonDependencies } = require("@kie-tools/maven-base");

setupMavenConfigFile(`
-Drevision=${buildEnv.env.extendedServicesJava.version}
Expand Down
1 change: 0 additions & 1 deletion packages/extended-services-java/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
"@kie-tools/maven-base": "workspace:*"
},
"devDependencies": {
"@kie-tools/maven-config-setup-helper": "workspace:*",
"@kie-tools/root-env": "workspace:*",
"copyfiles": "^2.4.1",
"rimraf": "^3.0.2",
Expand Down
2 changes: 1 addition & 1 deletion packages/jbpm-quarkus-devui/mvn.bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*/

const buildEnv = require("./env");
const { setupMavenConfigFile, buildTailFromPackageJsonDependencies } = require("@kie-tools/maven-config-setup-helper");
const { setupMavenConfigFile, buildTailFromPackageJsonDependencies } = require("@kie-tools/maven-base");

setupMavenConfigFile(`
-Drevision=${buildEnv.env.jbpmQuarkusDevuiExtension.version}
Expand Down
1 change: 0 additions & 1 deletion packages/jbpm-quarkus-devui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
"@kie-tools/maven-base": "workspace:*"
},
"devDependencies": {
"@kie-tools/maven-config-setup-helper": "workspace:*",
"@kie-tools/root-env": "workspace:*",
"@kie-tools/runtime-tools-process-dev-ui-webapp": "workspace:*",
"run-script-os": "^1.1.6"
Expand Down
6 changes: 3 additions & 3 deletions packages/kn-plugin-workflow/e2e-tests/quarkus_convert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,13 @@ func RunQuarkusConvertTest(t *testing.T, cfgTestInputCreateConvert CfgTestInputC
projectName := GetCreateProjectName(t, cfgTestInputCreateConvert)
projectDir := filepath.Join(TempTestsPath, projectName)

// Create the project
RunCreateTest(t, cfgTestInputCreateConvert)

err = os.Chdir(projectDir)
require.NoErrorf(t, err, "Expected nil error, got %v", err)
WriteMavenConfigFileWithTailDirs(projectDir)

// Create the project
RunCreateTest(t, cfgTestInputCreateConvert)

// Run `quarkus convert` command
_, err = ExecuteKnWorkflowQuarkus(transformQuarkusConvertCmdCfgToArgs(t, test.input)...)
require.NoErrorf(t, err, "Expected nil error, got %v", err)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@

<!-- Used to query default maven properties -->
<groupId>org.apache.kie</groupId>
<artifactId>kie-tools-maven-config-setup-helper-empty-pom</artifactId>
<artifactId>kie-tools-maven-base-empty-pom</artifactId>
<version>0.0.0-SNAPSHOT</version>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
* under the License.
*/

const { execSync } = require("child_process");
const fs = require("fs");
const path = require("path");

Expand All @@ -28,23 +27,22 @@ const MVN_CONFIG_FILE_PATH = path.join(".mvn", "maven.config");
// This package's constants.
const MVNW_VERSION = "3.3.0";
const EMPTY_POM_XML_PATH = path.join(__dirname, "empty-pom.xml");
const BUILD_SETTINGS_XML_PATH = path.join(__dirname, "build-settings.xml");
const BOOTSTRAP_SETTINGS_XML_PATH = path.join(__dirname, "bootstrap-settings.xml");
const SETTINGS_XML_PATH = path.join(__dirname, "settings.xml");

const DEFAULT_MAVEN_CONFIG = `
-Dstyle.color=always
--batch-mode
--settings=${BUILD_SETTINGS_XML_PATH}
--settings=${SETTINGS_XML_PATH}
`.trim();

const DEFAULT_LOCAL_REPO = String(
execSync(`mvn help:evaluate -Dexpression=settings.localRepository -q -DforceStdout -f ${EMPTY_POM_XML_PATH}`, {
fs.execSync(`mvn help:evaluate -Dexpression=settings.localRepository -q -DforceStdout -f ${EMPTY_POM_XML_PATH}`, {
stdio: "pipe",
encoding: "utf-8",
})
).trim();

const BOOTSTRAP_CLI_ARGS = `-P'!kie-tools--maven-profile--1st-party-dependencies' --settings=${BOOTSTRAP_SETTINGS_XML_PATH}`;
const BOOTSTRAP_CLI_ARGS = `-P'!kie-tools--maven-profile--1st-party-dependencies' --settings=${SETTINGS_XML_PATH}`;

module.exports = {
/**
Expand All @@ -66,12 +64,12 @@ module.exports = {
* Installs `mvnw` on the same directory of invocation.
* */
installMvnw: () => {
console.info(`[maven-config-setup-helper] Installing mvnw...`);
console.time(`[maven-config-setup-helper] Installing mvnw...`);
execSync(`mvn -e org.apache.maven.plugins:maven-wrapper-plugin:${MVNW_VERSION}:wrapper ${BOOTSTRAP_CLI_ARGS}`, {
console.info(`[maven-base] Installing mvnw...`);
console.time(`[maven-base] Installing mvnw...`);
fs.execSync(`mvn -e org.apache.maven.plugins:maven-wrapper-plugin:${MVNW_VERSION}:wrapper ${BOOTSTRAP_CLI_ARGS}`, {
stdio: "inherit",
});
console.timeEnd(`[maven-config-setup-helper] Installing mvnw...`);
console.timeEnd(`[maven-base] Installing mvnw...`);
},

/**
Expand Down Expand Up @@ -99,15 +97,17 @@ module.exports = {
fs.mkdirSync(resolvedTmpM2Dir, { recursive: true });

// head
execSync(`cp -nal ${DEFAULT_LOCAL_REPO}/* ${resolvedTmpM2Dir}`, { stdio: "inherit" });
fs.execSync(`cp -nal ${DEFAULT_LOCAL_REPO}/* ${resolvedTmpM2Dir}`, { stdio: "inherit" });

const cwd = path.resolve(".", relativePackagePath);
const packageName = require(path.resolve(cwd, "package.json")).name;
const tail = deepResolveMavenLocalRepoTail(cwd, packageName);

// tail
for (const t of tail) {
execSync(`cp -al ${path.resolve(t)}/* ${resolvedTmpM2Dir}`, { stdio: "inherit" });
if (fs.existsSync(path.resolve(t))) {
fs.execSync(`cp -al ${path.resolve(t)}/* ${resolvedTmpM2Dir}`, { stdio: "inherit" });
}
}
},

Expand All @@ -117,23 +117,23 @@ module.exports = {
* @param entry An object with `key` and `value` properties
*/
setPomProperty: ({ key, value }) => {
if (!key || !value) {
console.error("[maven-config-setup-helper] Wrong values provided");
if (!key || value === undefined) {
console.error("[maven-base] Can't set a POM property without proper `key` and `value`.");
process.exit(1);
}

console.info(`[maven-config-setup-helper] Setting property '${key}' with value '${value}'...`);
console.time(`[maven-config-setup-helper] Setting property '${key}' with value '${value}'...`);
console.info(`[maven-base] Setting property '${key}' with value '${value}'...`);
console.time(`[maven-base] Setting property '${key}' with value '${value}'...`);

const cmd = `mvn versions:set-property -Dproperty=${key} -DnewVersion=${value} -DgenerateBackupPoms=false ${BOOTSTRAP_CLI_ARGS}`;

if (process.platform === "win32") {
execSync(cmd.replaceAll(" -", " `-"), { stdio: "inherit", shell: "powershell.exe" });
fs.execSync(cmd.replaceAll(" -", " `-"), { stdio: "inherit", shell: "powershell.exe" });
} else {
execSync(cmd, { stdio: "inherit" });
fs.execSync(cmd, { stdio: "inherit" });
}

console.timeEnd(`[maven-config-setup-helper] Setting property '${key}' with value '${value}'...`);
console.timeEnd(`[maven-base] Setting property '${key}' with value '${value}'...`);
},

/**
Expand All @@ -143,23 +143,24 @@ module.exports = {
* @param args An object with a `ignoreDefault: boolean` property.
*/
setupMavenConfigFile: (mavenConfigString, args) => {
console.info(`[maven-config-setup-helper] Configuring Maven through .mvn/maven.config...`);
console.time(`[maven-config-setup-helper] Configuring Maven through .mvn/maven.config...`);
console.info(`[maven-base] Configuring Maven through .mvn/maven.config...`);
console.time(`[maven-base] Configuring Maven through .mvn/maven.config...`);

let originalMvnConfigString;
if (fs.existsSync(MVN_CONFIG_ORIGINAL_FILE_PATH)) {
console.info(`[maven-config-setup-helper] Found '${MVN_CONFIG_ORIGINAL_FILE_PATH}'.`);
console.info(`[maven-base] Found '${MVN_CONFIG_ORIGINAL_FILE_PATH}'.`);
originalMvnConfigString = fs.readFileSync(MVN_CONFIG_ORIGINAL_FILE_PATH, "utf-8");
} else if (fs.existsSync(MVN_CONFIG_FILE_PATH)) {
console.info(`[maven-config-setup-helper] Found '${MVN_CONFIG_FILE_PATH}'.`);
console.info(`[maven-base] Found '${MVN_CONFIG_FILE_PATH}'.`);
originalMvnConfigString = fs.readFileSync(MVN_CONFIG_FILE_PATH, "utf-8");
} else {
console.info(`[maven-config-setup-helper] No previous config found.`);
console.info(`[maven-base] No previous config found.`);
originalMvnConfigString = "";
}

fs.mkdirSync(".mvn", { recursive: true });

console.info(`[maven-config-setup-helper] Writing '${MVN_CONFIG_ORIGINAL_FILE_PATH}'...`);
console.info(`[maven-base] Writing '${MVN_CONFIG_ORIGINAL_FILE_PATH}'...`);
console.info(`${originalMvnConfigString}` || "<empty>");
fs.writeFileSync(MVN_CONFIG_ORIGINAL_FILE_PATH, originalMvnConfigString);

Expand All @@ -172,7 +173,7 @@ module.exports = {
const newMavenConfigString = `${originalMvnConfigString ? `\n${originalMvnConfigString}\n` : ``}
${trimmedMavenConfigString.trim()}`;

console.info(`[maven-config-setup-helper] Writing '${MVN_CONFIG_FILE_PATH}'...`);
console.info(`[maven-base] Writing '${MVN_CONFIG_FILE_PATH}'...`);
console.info(newMavenConfigString);

const defaultMavenConfigString = args?.ignoreDefault
Expand All @@ -182,10 +183,12 @@ ${trimmedMavenConfigString.trim()}`;
${DEFAULT_MAVEN_CONFIG}`;

fs.writeFileSync(MVN_CONFIG_FILE_PATH, `${newMavenConfigString}${defaultMavenConfigString}`);
console.timeEnd(`[maven-config-setup-helper] Configuring Maven through .mvn/maven.config...`);
console.timeEnd(`[maven-base] Configuring Maven through .mvn/maven.config...`);
},
};

// private functions

function deepResolveMavenLocalRepoTail(cwd) {
const packageJsonDependencies = require(path.resolve(cwd, "package.json")).dependencies ?? {};
return [
Expand Down
9 changes: 1 addition & 8 deletions packages/maven-base/mvn.bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,10 @@
*/

const buildEnv = require("./env");
const {
setupMavenConfigFile,
setPomProperty,
buildTailFromPackageJsonDependencies,
} = require("@kie-tools/maven-config-setup-helper");
const { setupMavenConfigFile, setPomProperty, buildTailFromPackageJsonDependencies } = require(".");

setupMavenConfigFile(
`
--batch-mode
-Dstyle.color=always
-Drevision=${buildEnv.env.mavenBase.version}
-Dmaven.repo.local.tail=${buildTailFromPackageJsonDependencies()}
`,
{ ignoreDefault: true }
Expand Down
Loading

0 comments on commit 73d8570

Please sign in to comment.