From 068a265cb33dc396bc91d59dc1d80155f1a31ab5 Mon Sep 17 00:00:00 2001 From: Stewart Francis Date: Wed, 10 Jun 2026 15:51:49 +0100 Subject: [PATCH] build a strictly offline Galasa Uber OBR for airgapped environments Signed-off-by: Stewart Francis --- modules/cli/pkg/cmd/runsCleanupLocal.go | 5 +- modules/cli/pkg/cmd/runsSubmitLocal.go | 6 +- modules/cli/pkg/launcher/jvmLauncher.go | 2 - modules/cli/pkg/launcher/jvmLauncherUtils.go | 5 -- .../launcher/resourceCleanupJvmLauncher.go | 1 - .../main/java/dev/galasa/boot/Launcher.java | 2 +- .../plugin/galasa/BuildOBRResources.java | 55 ++++++++++++++++++- modules/obr/dev.galasa.uber.obr/pom.template | 5 ++ 8 files changed, 66 insertions(+), 15 deletions(-) diff --git a/modules/cli/pkg/cmd/runsCleanupLocal.go b/modules/cli/pkg/cmd/runsCleanupLocal.go index 2e3a3a7d12..6d871ff7f0 100644 --- a/modules/cli/pkg/cmd/runsCleanupLocal.go +++ b/modules/cli/pkg/cmd/runsCleanupLocal.go @@ -100,9 +100,10 @@ func (cmd *RunsCleanupLocalCommand) createCobraCmd( "the version of galasa you want to use. This should match the version of the galasa obr you built your resource cleanup providers against.") runsCleanupLocalCobraCmd.Flags().StringSliceVar(&cmd.values.runsCleanupLocalCmdParams.RemoteMavenRepos, "remoteMaven", - []string{"https://repo.maven.apache.org/maven2"}, + []string{}, "the urls of the remote maven repositories where galasa bundles can be loaded from. "+ - "Defaults to maven central.") + "If not specified, no remote Maven repositories will be used and mvn: URIs in OBRs will fail to resolve. "+ + "Multiple repositories can be specified by using this flag multiple times.") runsCleanupLocalCobraCmd.Flags().StringVar(&cmd.values.runsCleanupLocalCmdParams.LocalMaven, "localMaven", "", "The url of a local maven repository are where galasa bundles can be loaded from on your local file system. Defaults to your home .m2/repository file. Please note that this should be in a URL form e.g. 'file:///Users/myuserid/.m2/repository', or 'file://C:/Users/myuserid/.m2/repository'") diff --git a/modules/cli/pkg/cmd/runsSubmitLocal.go b/modules/cli/pkg/cmd/runsSubmitLocal.go index ad6cd61f37..b901266401 100644 --- a/modules/cli/pkg/cmd/runsSubmitLocal.go +++ b/modules/cli/pkg/cmd/runsSubmitLocal.go @@ -99,9 +99,9 @@ func (cmd *RunsSubmitLocalCommand) createRunsSubmitLocalCobraCmd( //currentUserName := runs.GetCurrentSystemUserName() runsSubmitLocalCobraCmd.Flags().StringVar(&cmd.values.runsSubmitLocalCmdParams.RemoteMaven, "remoteMaven", - "https://repo.maven.apache.org/maven2", - "the url of the remote maven where galasa bundles can be loaded from. "+ - "Defaults to maven central.") + "", + "the url of the remote maven repository where galasa bundles can be loaded from. "+ + "If not specified, no remote Maven repository will be used and mvn: URIs in OBRs will fail to resolve.") runsSubmitLocalCobraCmd.Flags().StringVar(&cmd.values.runsSubmitLocalCmdParams.LocalMaven, "localMaven", "", "The url of a local maven repository are where galasa bundles can be loaded from on your local file system. Defaults to your home .m2/repository file. Please note that this should be in a URL form e.g. 'file:///Users/myuserid/.m2/repository', or 'file://C:/Users/myuserid/.m2/repository'") diff --git a/modules/cli/pkg/launcher/jvmLauncher.go b/modules/cli/pkg/launcher/jvmLauncher.go index 5067259890..4ca6fd4a26 100644 --- a/modules/cli/pkg/launcher/jvmLauncher.go +++ b/modules/cli/pkg/launcher/jvmLauncher.go @@ -603,7 +603,6 @@ func (launcher *JvmLauncher) IsLocal() bool { // --remotemaven $REMOTE_MAVEN \ // --bootstrap file:${HOME}/.galasa/bootstrap.properties \ // --overrides file:${HOME}/.galasa/overrides.properties \ -// --obr mvn:dev.galasa/dev.galasa.uber.obr/${OBR_VERSION}/obr \ // --obr mvn:${TEST_OBR_GROUP_ID}/${TEST_OBR_ARTIFACT_ID}/${TEST_OBR_VERSION}/obr \ // --test ${TEST_BUNDLE}/${TEST_JAVA_CLASS} | tee jvm-log.txt | grep "[*][*][*]" | grep -v "[*][*][*][*]" | sed -e "s/[--]*//g" // @@ -614,7 +613,6 @@ func (launcher *JvmLauncher) IsLocal() bool { // --remotemaven https://development.galasa.dev/main/maven-repo/obr/ \ // --bootstrap file:/Users/mcobbett/.galasa/bootstrap.properties \ // --overrides file:/Users/mcobbett/.galasa/overrides.properties \ -// --obr mvn:dev.galasa/dev.galasa.uber.obr/0.26.0/obr \ // --obr mvn:dev.galasa.example.banking/dev.galasa.example.banking.obr/0.0.1-SNAPSHOT/obr \ // --test dev.galasa.example.banking.payee/dev.galasa.example.banking.payee.TestPayee func getCommandSyntax( diff --git a/modules/cli/pkg/launcher/jvmLauncherUtils.go b/modules/cli/pkg/launcher/jvmLauncherUtils.go index ad8f277df6..bea32eeb5b 100644 --- a/modules/cli/pkg/launcher/jvmLauncherUtils.go +++ b/modules/cli/pkg/launcher/jvmLauncherUtils.go @@ -103,11 +103,6 @@ func getBaseCommandSyntax( args = append(args, obrMvnPath) } - // --obr mvn:dev.galasa/dev.galasa.uber.obr/${OBR_VERSION}/obr - args = append(args, "--obr") - galasaUberObrPath := "mvn:dev.galasa/dev.galasa.uber.obr/" + galasaVersionToRun + "/obr" - args = append(args, galasaUberObrPath) - if isTraceEnabled { args = append(args, "--trace") } diff --git a/modules/cli/pkg/launcher/resourceCleanupJvmLauncher.go b/modules/cli/pkg/launcher/resourceCleanupJvmLauncher.go index d27f4b48f8..696e2b4b4b 100644 --- a/modules/cli/pkg/launcher/resourceCleanupJvmLauncher.go +++ b/modules/cli/pkg/launcher/resourceCleanupJvmLauncher.go @@ -192,7 +192,6 @@ func (launcher *ResourceCleanupJvmLauncher) RunResourceCleanup() error { // --localmaven file:${M2_PATH}/repository/ \ // --remotemaven $REMOTE_MAVEN \ // --bootstrap file:${HOME}/.galasa/bootstrap.properties \ -// --obr mvn:dev.galasa/dev.galasa.uber.obr/${OBR_VERSION}/obr \ // --obr mvn:${OBR_GROUP_ID}/${OBR_ARTIFACT_ID}/${OBR_VERSION}/obr \ // --includes-monitor-pattern "dev.galasa.*" // --excludes-monitor-pattern "*MyUnwantedCleanupJob" diff --git a/modules/framework/galasa-parent/galasa-boot/src/main/java/dev/galasa/boot/Launcher.java b/modules/framework/galasa-parent/galasa-boot/src/main/java/dev/galasa/boot/Launcher.java index 906be705d8..c12b2c0bbc 100644 --- a/modules/framework/galasa-parent/galasa-boot/src/main/java/dev/galasa/boot/Launcher.java +++ b/modules/framework/galasa-parent/galasa-boot/src/main/java/dev/galasa/boot/Launcher.java @@ -445,7 +445,7 @@ private void checkForRemoteMaven(CommandLine commandLine) { this.remoteMavenRepos.add(new URL(option.replaceFirst("/*$", ""))); } } - this.remoteMavenRepos.add(new URL("https://repo.maven.apache.org/maven2")); + // No longer automatically adding Maven Central - users must explicitly opt-in via --remotemaven } catch (MalformedURLException e) { logger.error("invalid remote maven urls", e); commandLineError(null); diff --git a/modules/maven/galasa-maven-plugin/src/main/java/dev/galasa/maven/plugin/galasa/BuildOBRResources.java b/modules/maven/galasa-maven-plugin/src/main/java/dev/galasa/maven/plugin/galasa/BuildOBRResources.java index 8e8a13f663..87b411ddee 100644 --- a/modules/maven/galasa-maven-plugin/src/main/java/dev/galasa/maven/plugin/galasa/BuildOBRResources.java +++ b/modules/maven/galasa-maven-plugin/src/main/java/dev/galasa/maven/plugin/galasa/BuildOBRResources.java @@ -8,8 +8,11 @@ import java.io.File; import java.io.FileReader; import java.io.FileWriter; +import java.io.IOException; import java.lang.reflect.Field; import java.net.URI; +import java.nio.file.Files; +import java.nio.file.StandardCopyOption; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Calendar; @@ -39,7 +42,8 @@ public class BuildOBRResources extends AbstractMojo { public enum OBR_URL_TYPE { file, - mvn + mvn, + relative } @Parameter(defaultValue = "${project}", readonly = true) @@ -57,6 +61,12 @@ public enum OBR_URL_TYPE { @Parameter(defaultValue = "false", property = "includeSelf", required = false) private boolean includeSelf; + @Parameter(defaultValue = "false", property = "copyBundles", required = false) + private boolean copyBundles; + + @Parameter(defaultValue = "bundles", property = "bundlesDir", required = false) + private String bundlesDir; + private Field requirementsField; @SuppressWarnings("deprecation") @@ -223,6 +233,17 @@ private void processBundle(DefaultArtifact artifact, File file, RepositoryImpl r name = new URI("mvn:" + artifact.getGroupId() + "/" + artifact.getArtifactId() + "/" + artifact.getBaseVersion() + "/" + artifact.getType()); break; + case relative: + // Include group ID to prevent collisions + String fileName = buildBundleFileName(artifact); + name = new URI(bundlesDir + "/" + fileName); + + // Copy the bundle if requested + if (copyBundles) { + File bundlesDirectory = new File(outputDirectory, bundlesDir); + copyBundleToDirectory(artifact, fileName, bundlesDirectory); + } + break; case file: default: name = artifact.getFile().toURI(); @@ -240,4 +261,36 @@ private void processBundle(DefaultArtifact artifact, File file, RepositoryImpl r } } + private String buildBundleFileName(DefaultArtifact artifact) { + // Include group ID to prevent collisions + return artifact.getGroupId() + "." + + artifact.getArtifactId() + "-" + + artifact.getBaseVersion() + "." + + artifact.getType(); + } + + private void copyBundleToDirectory(DefaultArtifact artifact, String fileName, File bundlesDirectory) + throws MojoExecutionException { + try { + if (!bundlesDirectory.exists()) { + bundlesDirectory.mkdirs(); + getLog().info("BuildOBRResources: Created bundles directory: " + bundlesDirectory.getAbsolutePath()); + } + + File sourceFile = artifact.getFile(); + File targetFile = new File(bundlesDirectory, fileName); + + Files.copy(sourceFile.toPath(), targetFile.toPath(), + StandardCopyOption.REPLACE_EXISTING); + + getLog().info("BuildOBRResources: Copied bundle: " + fileName + " to " + bundlesDirectory.getName() + "/"); + } catch (IOException e) { + throw new MojoExecutionException("Failed to copy bundle " + + artifact.getId() + " to bundles directory", e); + } catch (SecurityException e) { + throw new MojoExecutionException("Security exception while copying bundle " + + artifact.getId() + " to bundles directory", e); + } + } + } diff --git a/modules/obr/dev.galasa.uber.obr/pom.template b/modules/obr/dev.galasa.uber.obr/pom.template index 9467651ebd..479fa3cf93 100644 --- a/modules/obr/dev.galasa.uber.obr/pom.template +++ b/modules/obr/dev.galasa.uber.obr/pom.template @@ -80,6 +80,11 @@ galasa-maven-plugin {{.Release}} true + + relative + true + bundles + deploy-testcatalog