Skip to content

Commit

Permalink
O3-3426: Distro Inheritance Tool for the Build-Distro plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
wikumChamith committed Jul 31, 2024
1 parent 393b7ba commit 7b65361
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ public void executeTask() throws MojoExecutionException, MojoFailureException {
if (distroFile.exists()) {
wizard.showMessage("Building distribution from the distro file at " + distroFile + "...\n");
distroProperties = new DistroProperties(distroFile);
distroArtifact = distroProperties.getParentArtifact();
distroProperties = handleParentDistroProperties(distroArtifact, buildDirectory, distroProperties);
} else if (Project.hasProject(userDir)) {
Project config = Project.loadProject(userDir);
distroArtifact = DistroHelper
Expand All @@ -157,6 +159,8 @@ public void executeTask() throws MojoExecutionException, MojoFailureException {
}
} else if (StringUtils.isNotBlank(distro)) {
distroProperties = distroHelper.resolveDistroPropertiesForStringSpecifier(distro, versionsHelper);
distroArtifact = distroProperties.getParentArtifact();
distroProperties = handleParentDistroProperties(distroArtifact, buildDirectory, distroProperties);
}

if (distroProperties == null) {
Expand Down Expand Up @@ -198,6 +202,18 @@ public void executeTask() throws MojoExecutionException, MojoFailureException {
+ buildDirectory.getAbsolutePath() + "\n");
}

private DistroProperties handleParentDistroProperties(Artifact distroArtifact, File buildDirectory, DistroProperties distroProperties) throws MojoExecutionException {
if (StringUtils.isNotBlank(distroArtifact.getArtifactId()) && StringUtils.isNotBlank(distroArtifact.getGroupId()) && StringUtils.isNotBlank(distroArtifact.getVersion())) {
Server tempServer = new Server.ServerBuilder().build();
tempServer.setDistroArtifactId(distroArtifact.getArtifactId());
tempServer.setDistroGroupId(distroArtifact.getGroupId());
tempServer.setVersion(distroArtifact.getVersion());
tempServer.setServerDirectory(buildDirectory);
distroProperties = distroHelper.resolveParentArtifact(distroArtifact, tempServer, distroProperties, appShellVersion);
}
return distroProperties;
}

private File getBuildDirectory() throws MojoExecutionException {
final File targetDir;
if (StringUtils.isBlank(dir)) {
Expand Down
16 changes: 1 addition & 15 deletions maven-plugin/src/main/java/org/openmrs/maven/plugins/Setup.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Properties;

import net.lingala.zip4j.core.ZipFile;
import net.lingala.zip4j.exception.ZipException;
Expand Down Expand Up @@ -219,20 +218,7 @@ private DistroProperties resolveDistroProperties(Server server) throws MojoExecu
default: // distro properties from current directory
Artifact distroArtifact = distroProperties.getParentArtifact();
if (StringUtils.isNotBlank(distroArtifact.getArtifactId()) && StringUtils.isNotBlank(distroArtifact.getGroupId()) && StringUtils.isNotBlank(distroArtifact.getVersion())) {
server.setDistroArtifactId(distroArtifact.getArtifactId());
server.setDistroGroupId(distroArtifact.getGroupId());
server.setVersion(distroArtifact.getVersion());
Properties properties = distroHelper.getArtifactProperties(distroArtifact, server, appShellVersion);
for (Object key : distroProperties.getAllKeys()) {
String keyStr = (String) key;
properties.setProperty(keyStr, distroProperties.getParam(keyStr));
}
List<String> exclusions = distroProperties.getExclusions();

for (String exclusion : exclusions) {
properties.remove(exclusion);
}
distroProperties = new DistroProperties(properties);
distroProperties = distroHelper.resolveParentArtifact(distroArtifact, server, distroProperties, appShellVersion);
} else {
server.setPlatformVersion(
distroProperties.getPlatformVersion(distroHelper, server.getServerTmpDirectory()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -517,4 +517,21 @@ public Properties getArtifactProperties(Artifact artifact, Server server, String
return properties;
}

public DistroProperties resolveParentArtifact(Artifact parentArtifact, Server server, DistroProperties distroProperties, String appShellVersion) throws MojoExecutionException {
server.setDistroArtifactId(parentArtifact.getArtifactId());
server.setDistroGroupId(parentArtifact.getGroupId());
server.setVersion(parentArtifact.getVersion());
Properties properties = getArtifactProperties(parentArtifact, server, appShellVersion);
for (Object key : distroProperties.getAllKeys()) {
String keyStr = (String) key;
properties.setProperty(keyStr, distroProperties.getParam(keyStr));
}
List<String> exclusions = distroProperties.getExclusions();

for (String exclusion : exclusions) {
properties.remove(exclusion);
}
return new DistroProperties(properties);
}

}

0 comments on commit 7b65361

Please sign in to comment.