-
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-3439: Add exclusions to distro.properties
- Loading branch information
1 parent
8be79d8
commit c68e257
Showing
5 changed files
with
148 additions
and
0 deletions.
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
integration-tests/src/test/java/org/openmrs/maven/plugins/AddExclusionIntegrationTest.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,49 @@ | ||
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 AddExclusionIntegrationTest 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 shouldAddExclusion() throws Exception { | ||
DistroProperties distroProperties = DistroHelper.getDistroPropertiesFromFile(new File(distroFile)); | ||
assertNotNull(distroProperties); | ||
assertFalse(distroProperties.getExclusions().contains("omod.uicommons")); | ||
|
||
addTaskParam("distro", distroFile); | ||
addTaskParam("property", "omod.uicommons"); | ||
executeTask("exclusion"); | ||
|
||
assertSuccess(); | ||
|
||
distroProperties = DistroHelper.getDistroPropertiesFromFile(new File(distroFile)); | ||
assertTrue(distroProperties.getExclusions().contains("omod.uicommons")); | ||
} | ||
|
||
|
||
@After | ||
public void reset() throws MojoExecutionException { | ||
originalProperties.saveTo(new File(distroFile).getParentFile()); | ||
} | ||
} |
82 changes: 82 additions & 0 deletions
82
maven-plugin/src/main/java/org/openmrs/maven/plugins/AddExclusion.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,82 @@ | ||
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.Artifact; | ||
import org.openmrs.maven.plugins.model.DistroProperties; | ||
|
||
import java.io.File; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
@Mojo(name = "exclusion", requiresProject = false) | ||
public class AddExclusion extends AbstractTask { | ||
|
||
/** | ||
* Path to the openmrs-distro.properties file to modify | ||
*/ | ||
@Parameter(property = "distro") | ||
private String distro; | ||
|
||
/** | ||
* Name of the property you want to exclude | ||
*/ | ||
@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 originalDistroProperties = null; | ||
|
||
if (StringUtils.isNotBlank(distro)) { | ||
originalDistroProperties = distroHelper.resolveDistroPropertiesForStringSpecifier(distro, versionsHelper); | ||
|
||
} | ||
|
||
if (originalDistroProperties == null) { | ||
throw new MojoFailureException("Invalid distro file"); | ||
} | ||
|
||
Artifact distroArtifact = originalDistroProperties.getParentArtifact(); | ||
if (StringUtils.isNotBlank(distroArtifact.getArtifactId()) && StringUtils.isNotBlank(distroArtifact.getGroupId()) && StringUtils.isNotBlank(distroArtifact.getVersion())) { | ||
DistroProperties distroProperties = distroHelper.resolveParentArtifact(distroArtifact, new File(distro).getParentFile(), originalDistroProperties, null); | ||
if (StringUtils.isBlank(property)) { | ||
List<String> currentExclusions = distroProperties.getExclusions(); | ||
List<String> options = distroProperties.getPropertyNames().stream().filter(prop -> !currentExclusions.contains(prop)).collect(Collectors.toList()); | ||
property = wizard.promptForMissingValueWithOptions("Enter the property you want to exclude", | ||
null, null, options); | ||
} else { | ||
if (!distroProperties.getPropertyNames().contains(property)) { | ||
wizard.showWarning("The property is not included in the parent distro"); | ||
} | ||
} | ||
|
||
} else { | ||
wizard.showWarning("This distro properties file does not contain a valid parent distro"); | ||
if (StringUtils.isBlank(property)) { | ||
property = wizard.promptForValueIfMissing(null, "property to exclude"); | ||
if (StringUtils.isBlank(property)) { | ||
throw new MojoFailureException("Invalid property name"); | ||
} | ||
} | ||
} | ||
originalDistroProperties.addExclusion(property); | ||
wizard.showMessage(property + " is added to exclusions"); | ||
originalDistroProperties.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
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
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