-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SDK-373 - Add goal to packager plugin to facilitate transition from c… #28
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
135 changes: 135 additions & 0 deletions
135
...gin/src/main/java/org/openmrs/maven/plugins/packager/config/CreateContentPackageMojo.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,135 @@ | ||
/** | ||
* This Source Code Form is subject to the terms of the Mozilla Public License, | ||
* v. 2.0. If a copy of the MPL was not distributed with this file, You can | ||
* obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under | ||
* the terms of the Healthcare Disclaimer located at http://openmrs.org/license. | ||
* | ||
* Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS | ||
* graphic logo is a trademark of OpenMRS Inc. | ||
*/ | ||
package org.openmrs.maven.plugins.packager.config; | ||
|
||
import org.apache.commons.io.FileUtils; | ||
import org.apache.maven.plugin.MojoExecutionException; | ||
import org.apache.maven.plugins.annotations.LifecyclePhase; | ||
import org.apache.maven.plugins.annotations.Mojo; | ||
import org.apache.maven.plugins.annotations.Parameter; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
import java.util.Enumeration; | ||
import java.util.List; | ||
import java.util.Properties; | ||
|
||
import static org.twdata.maven.mojoexecutor.MojoExecutor.configuration; | ||
import static org.twdata.maven.mojoexecutor.MojoExecutor.element; | ||
import static org.twdata.maven.mojoexecutor.MojoExecutor.executeMojo; | ||
import static org.twdata.maven.mojoexecutor.MojoExecutor.goal; | ||
import static org.twdata.maven.mojoexecutor.MojoExecutor.plugin; | ||
|
||
/** | ||
* The purpose of this Mojo is to support the migration away from config packages to content packages | ||
* The intent is to bundle up the same configurations as content packages | ||
*/ | ||
@Mojo(name = "create-content-package", defaultPhase = LifecyclePhase.COMPILE) | ||
public class CreateContentPackageMojo extends AbstractPackagerConfigMojo { | ||
|
||
@Parameter(property = "name", defaultValue = "${project.name}") | ||
private String name; | ||
|
||
@Parameter(property = "version", defaultValue = "${project.version}") | ||
private String version; | ||
|
||
@Parameter(property = "sourceConfigurationDir", defaultValue = "${project.basedir}/configuration") | ||
private File sourceConfigurationDir; | ||
|
||
@Parameter(property = "sourceFrontendSubdir", defaultValue = "frontend") | ||
private String sourceFrontendSubdir; | ||
|
||
// Dependency configurations that this project wishes to import from other projects | ||
@Parameter(property = "dependencyFile", defaultValue = "dependencies.yml") | ||
private File dependenciesFile; | ||
|
||
@Parameter(property = "targetDir", defaultValue = "${project.build.directory}/package") | ||
private File targetDir; | ||
|
||
/** | ||
* @throws MojoExecutionException if an error occurs | ||
*/ | ||
public void execute() throws MojoExecutionException { | ||
List<String> contentProperties = new ArrayList<>(); | ||
contentProperties.add("# Content Package"); | ||
contentProperties.add("name=" + name); | ||
contentProperties.add("version=" + version); | ||
|
||
Properties constants = loadPropertiesFromFile(getCompiledConstantsFile()); | ||
if (constants != null && !constants.isEmpty()) { | ||
contentProperties.add(""); | ||
contentProperties.add("# Constants"); | ||
Enumeration<Object> e = constants.keys(); | ||
while (e.hasMoreElements()) { | ||
Object key = e.nextElement(); | ||
contentProperties.add("var." + key + "=" + constants.get(key)); | ||
} | ||
} | ||
|
||
File contentPropertiesFile = new File(targetDir, "content.properties"); | ||
try { | ||
FileUtils.writeLines(contentPropertiesFile, "UTF-8", contentProperties); | ||
} | ||
catch (IOException e) { | ||
throw new MojoExecutionException("Unable to write content.properties", e); | ||
} | ||
|
||
File targetConfigurationDir = new File(targetDir, "configuration"); | ||
File backendTargetDir = new File(targetConfigurationDir, "backend_configuration"); | ||
|
||
executeMojo( | ||
plugin("org.apache.maven.plugins", "maven-resources-plugin", "3.1.0"), | ||
goal("copy-resources"), | ||
configuration( | ||
element("outputDirectory", backendTargetDir.getAbsolutePath()), | ||
element("encoding", "UTF-8"), | ||
element("overwrite", "true"), | ||
element("resources", | ||
element("resource", | ||
element("directory", sourceConfigurationDir.getAbsolutePath()), | ||
element("filtering", "false"), | ||
element("includes", | ||
element("include", "**/*") | ||
), | ||
element("excludes", | ||
element("exclude", sourceFrontendSubdir + "/**/*") | ||
) | ||
) | ||
) | ||
), | ||
getMavenExecutionEnvironment() | ||
); | ||
|
||
File frontendSourceDir = new File(sourceConfigurationDir, sourceFrontendSubdir); | ||
File frontendTargetDir = new File(targetConfigurationDir, "frontend_configuration"); | ||
|
||
executeMojo( | ||
plugin("org.apache.maven.plugins", "maven-resources-plugin", "3.1.0"), | ||
goal("copy-resources"), | ||
configuration( | ||
element("outputDirectory", frontendTargetDir.getAbsolutePath()), | ||
element("encoding", "UTF-8"), | ||
element("overwrite", "true"), | ||
element("resources", | ||
element("resource", | ||
element("directory", frontendSourceDir.getAbsolutePath()), | ||
element("filtering", "false"), | ||
element("includes", | ||
element("include", "**/*") | ||
) | ||
) | ||
) | ||
), | ||
getMavenExecutionEnvironment() | ||
); | ||
|
||
} | ||
} |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Config packages never lived outside of PIH, did they, or am I forgetting? Might be worth referencing these as "PIH" config packages in the comments to help people 10 years from now remember what they were (or just realize they can ignore them)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, right, the packager plugin... maybe just reference that in the comments?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Duh, sorry for all the spam... I was thinking this change was in the SDK... of course you don't need to reference the packager plugin since this is the package plugin... anyway, LGTM, ignore my comments...