Skip to content

Commit

Permalink
O3-3434: SDK Command: Remove dependencies from distro.properties
Browse files Browse the repository at this point in the history
  • Loading branch information
wikumChamith committed Aug 28, 2024
1 parent b17292a commit 96d86f5
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 16 deletions.
4 changes: 0 additions & 4 deletions integration-tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,5 @@
<artifactId>hamcrest-library</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@
import org.openmrs.maven.plugins.model.DistroProperties;

import java.io.File;
import java.util.Properties;
import java.util.stream.Collectors;
import java.util.ArrayList;

@Mojo(name = "rm-dependency", requiresProject = false)
@Mojo(name = "remove", requiresProject = false)
public class RemoveDependency extends AbstractTask {

/**
Expand All @@ -34,28 +33,33 @@ public void executeTask() throws MojoExecutionException, MojoFailureException {
File distroFile = new File(userDir, DistroProperties.DISTRO_FILE_NAME);
if (distroFile.exists()) {
distro = distroFile.getAbsolutePath();
} else {
throw new MojoFailureException("Please specify a distro file");
}
}

Properties properties = new Properties();
DistroProperties properties = null;

if (StringUtils.isNotBlank(distro)) {
properties = distroHelper.resolveDistroPropertiesForStringSpecifier(distro, versionsHelper).getProperties();
properties = distroHelper.resolveDistroPropertiesForStringSpecifier(distro, versionsHelper);

}

if (properties == null) {
throw new MojoFailureException("Invalid distro file");
}

if (StringUtils.isBlank(property)) {
property = wizard.promptForMissingValueWithOptions("Enter the property you want to remove",
null, null, properties.keySet().stream().map(prop -> (String) prop).collect(Collectors.toList()));
null, null, new ArrayList<>(properties.getPropertyNames()));
}

if (StringUtils.isNotBlank(property)) {
if (!properties.containsKey(property)) {
if (!properties.getPropertyNames().contains(property)) {
throw new MojoExecutionException("The property " + property + " was not found in the distro");
}
properties.remove(property);
DistroProperties distroProperties = new DistroProperties(properties);
distroProperties.saveTo(new File(distro).getParentFile());
properties.removeProperty(property);
properties.saveTo(new File(distro).getParentFile());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -271,8 +271,12 @@ public List<String> getExclusions() {
return Arrays.asList(exclusions.split(","));
}

public Properties getProperties() {
return properties;
public Set<String> getPropertyNames() {
return properties.stringPropertyNames();
}

public void removeProperty(String property) {
properties.remove(property);
}

private String getPlaceholderKey(String string){
Expand Down

0 comments on commit 96d86f5

Please sign in to comment.