-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
O3-3434: SDK Command: Remove dependencies from distro.properties (#289)
- Loading branch information
1 parent
1747463
commit 8be79d8
Showing
3 changed files
with
124 additions
and
0 deletions.
There are no files selected for viewing
51 changes: 51 additions & 0 deletions
51
integration-tests/src/test/java/org/openmrs/maven/plugins/RemoveDependencyTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package org.openmrs.maven.plugins; | ||
|
||
import org.apache.maven.plugin.MojoExecutionException; | ||
import org.junit.After; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.openmrs.maven.plugins.model.DistroProperties; | ||
import org.openmrs.maven.plugins.utility.DistroHelper; | ||
|
||
import java.io.File; | ||
|
||
import static org.junit.Assert.assertFalse; | ||
import static org.junit.Assert.assertNotNull; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
public class RemoveDependencyTest extends AbstractSdkIntegrationTest { | ||
|
||
private String distroFile; | ||
|
||
|
||
private DistroProperties originalProperties; | ||
|
||
@Before | ||
public void setUp() { | ||
distroFile = testDirectory + File.separator + "openmrs-distro.properties"; | ||
originalProperties = DistroHelper.getDistroPropertiesFromFile(new File(distroFile)); | ||
} | ||
|
||
@Test | ||
public void shouldRemoveExistingDependency() throws Exception { | ||
DistroProperties distroProperties = DistroHelper.getDistroPropertiesFromFile(new File(distroFile)); | ||
assertNotNull(distroProperties); | ||
|
||
assertTrue(distroProperties.getAllKeys().contains("omod.uicommons")); | ||
|
||
addTaskParam("distro", distroFile); | ||
addTaskParam("property", "omod.uicommons"); | ||
|
||
executeTask("remove"); | ||
assertSuccess(); | ||
|
||
distroProperties = DistroHelper.getDistroPropertiesFromFile(new File(distroFile)); | ||
assertFalse(distroProperties.getAllKeys().contains("omod.uicommons")); | ||
} | ||
|
||
@After | ||
public void reset() throws MojoExecutionException { | ||
originalProperties.saveTo(new File(distroFile).getParentFile()); | ||
} | ||
|
||
} |
62 changes: 62 additions & 0 deletions
62
maven-plugin/src/main/java/org/openmrs/maven/plugins/RemoveDependency.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package org.openmrs.maven.plugins; | ||
|
||
import org.apache.commons.lang.StringUtils; | ||
import org.apache.maven.plugin.MojoExecutionException; | ||
import org.apache.maven.plugin.MojoFailureException; | ||
import org.apache.maven.plugins.annotations.Mojo; | ||
import org.apache.maven.plugins.annotations.Parameter; | ||
import org.openmrs.maven.plugins.model.DistroProperties; | ||
|
||
import java.io.File; | ||
import java.util.ArrayList; | ||
|
||
@Mojo(name = "remove", requiresProject = false) | ||
public class RemoveDependency extends AbstractTask { | ||
|
||
/** | ||
* Path to the openmrs-distro.properties file to modify | ||
*/ | ||
@Parameter(property = "distro") | ||
private String distro; | ||
|
||
/** | ||
* Name of the property you want to remove | ||
*/ | ||
@Parameter(property = "property") | ||
private String property; | ||
|
||
@Override | ||
public void executeTask() throws MojoExecutionException, MojoFailureException { | ||
|
||
if (distro == null) { | ||
File userDir = new File(System.getProperty("user.dir")); | ||
File distroFile = new File(userDir, DistroProperties.DISTRO_FILE_NAME); | ||
if (distroFile.exists()) { | ||
distro = distroFile.getAbsolutePath(); | ||
} else { | ||
throw new MojoFailureException("Please specify a distro file"); | ||
} | ||
} | ||
|
||
DistroProperties properties = null; | ||
|
||
if (StringUtils.isNotBlank(distro)) { | ||
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, new ArrayList<>(properties.getPropertyNames())); | ||
} | ||
|
||
if (StringUtils.isNotBlank(property)) { | ||
properties.removeProperty(property); | ||
properties.saveTo(new File(distro).getParentFile()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters