469 - Maven Plugin - AMP files order

Modify the Alfresco Maven Plugin in order to take into
account the order in which the AMP modules were defined
as the same order of the AMPs to be applied to the war
files.
This commit is contained in:
Jose Luis Osorno
2019-01-21 15:16:46 +01:00
parent 709b820f2c
commit 9d1c2feaf2

View File

@@ -95,6 +95,8 @@ public abstract class AbstractRunMojo extends AbstractMojo {
.add(new Pair(TOMCAT_EMBED_GROUP_ID,"tomcat-embed-logging-log4j")) .add(new Pair(TOMCAT_EMBED_GROUP_ID,"tomcat-embed-logging-log4j"))
.build(); .build();
private static final String AMP_LOCATION_PATTERN = "%s/%s-%s.amp";
@Component @Component
protected MavenProject project; protected MavenProject project;
@@ -1227,18 +1229,7 @@ public abstract class AbstractRunMojo extends AbstractMojo {
); );
// Then apply all these amps to the unpacked war // Then apply all these amps to the unpacked war
// Call the Alfresco Maven Plugin Install Mojo directly, so we don't have to keep SDK version info here applyAMPs(warName, modules);
String ampsLocation = project.getBuild().getDirectory() + "/" + ampsModuleDir;
String warLocation = project.getBuild().getDirectory() + "/" + getWarName(warName);
InstallMojo installMojo = new InstallMojo();
installMojo.setAmpLocation(new File(ampsLocation));
installMojo.setWarLocation(new File(warLocation));
installMojo.setForce(true);
try {
installMojo.execute();
} catch (MojoFailureException e) {
e.printStackTrace();
}
} }
// Then copy all JAR dependencies to the unpacked war /target/<warName>-war/WEB-INF/lib // Then copy all JAR dependencies to the unpacked war /target/<warName>-war/WEB-INF/lib
@@ -1847,4 +1838,56 @@ public abstract class AbstractRunMojo extends AbstractMojo {
tomcatPluginDependencies.add(dependency(tomcatDependency.getFirst(),tomcatDependency.getSecond(),tomcatVersion)); tomcatPluginDependencies.add(dependency(tomcatDependency.getFirst(),tomcatDependency.getSecond(),tomcatVersion));
} }
} }
/**
* Apply a list of AMPs to a specific war file.
*
* @param warName the name of the war file to apply the AMPs to
* @param modules the list of proposed modules to be applied to the war file. Only the AMP files will be applied
* @throws MojoExecutionException when any problem appears applying the AMPs to the war
*/
private void applyAMPs(String warName, List<ModuleDependency> modules) throws MojoExecutionException {
final String ampsModuleDir = "modules/" + warName + "/amps";
final String ampsLocation = project.getBuild().getDirectory() + "/" + ampsModuleDir;
final String warLocation = project.getBuild().getDirectory() + "/" + getWarName(warName);
// Apply one AMP module each time to preserve the order applying the AMPs to the war
for(ModuleDependency module : modules) {
if(module.isAmp()) {
applyAMP(ampsLocation, warLocation, module);
}
}
}
/**
* Apply an AMP to a specific war file.
*
* @param ampsLocation the location of the folder where the AMP is located
* @param warLocation the location of the war file to apply the AMP to
* @param ampModule the module that represents the AMP to apply
* @throws MojoExecutionException when any problem appears applying the AMP to the war
*/
private void applyAMP(String ampsLocation, String warLocation, ModuleDependency ampModule) throws MojoExecutionException {
// Call the Alfresco Maven Plugin Install Mojo directly, so we don't have to keep SDK version info here
InstallMojo installMojo = new InstallMojo();
installMojo.setAmpLocation(new File(getAMPLocation(ampsLocation, ampModule)));
installMojo.setWarLocation(new File(warLocation));
installMojo.setForce(true);
try {
installMojo.execute();
} catch (MojoFailureException e) {
getLog().error(e);
}
}
/**
* Build the location of an AMP file.
*
* @param ampsLocation the location of the folder where the AMPs are located
* @param ampModule the {@link ModuleDependency} of the AMP to build its location
* @return the location of the AMP file
*/
private String getAMPLocation(String ampsLocation, ModuleDependency ampModule) {
return String.format(AMP_LOCATION_PATTERN, ampsLocation, ampModule.getArtifactId(), ampModule.getVersion());
}
} }