Skip to content

Commit

Permalink
Merge pull request #327 from sonalshingavi/master
Browse files Browse the repository at this point in the history
Ability for users to provide application archives folder to upload th…
  • Loading branch information
SujataDarekar authored Jul 9, 2019
2 parents 08c1e97 + bca75c3 commit 66396e6
Showing 1 changed file with 29 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@
import java.util.List;
import java.util.Properties;
import java.util.jar.Manifest;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

import org.apache.commons.io.FileUtils;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
Expand Down Expand Up @@ -118,6 +122,9 @@ public class BWEARInstallerMojo extends AbstractMojo {

@Parameter(property="deploymentConfigfile")
private String deploymentConfigfile;

@Parameter(property = "externalEarLoc")
private String externalEarLoc;

private String earLoc;
private String earName;
Expand All @@ -144,13 +151,22 @@ public void execute() throws MojoExecutionException {
getLog().info("Deploy To Admin is set to False. Skipping EAR Deployment.");
return;
}

File [] files = BWFileUtils.getFilesForType(outputDirectory, ".ear");
if(files.length == 0) {
throw new Exception("EAR file not found for the Application");
}

deriveEARInformation(files[0]);

if(externalEarLocExists()){
File f = new File(externalEarLoc);
Path p = Paths.get(externalEarLoc + "/" +files[0].getName());

Files.deleteIfExists(p);
FileUtils.copyFileToDirectory(files[0], f);
deriveEARInformation(p.toFile());
} else
deriveEARInformation(files[0]);

applicationName = manifest.getMainAttributes().getValue(Constants.BUNDLE_SYMBOLIC_NAME);

RemoteDeployer deployer = new RemoteDeployer(agentHost, Integer.parseInt(agentPort), agentAuth, agentUsername, agentPassword, agentSSL, trustPath, trustPassword, keyPath, keyPassword);
Expand Down Expand Up @@ -184,7 +200,7 @@ public void execute() throws MojoExecutionException {
throw new MojoExecutionException("Failed to deploy BW Application ", e);
}
}

private void deriveEARInformation(File file) {
earLoc = file.getAbsolutePath();
earLoc = earLoc.replace("\\", "/");
Expand All @@ -205,6 +221,14 @@ private boolean deploymentConfigExists() {
getLog().info("Deployment Config File found. Loading configuration from the same.");
return true;
}

private boolean externalEarLocExists() {
if(externalEarLoc == null || externalEarLoc.isEmpty()){
return false;
}
getLog().info("Deploying the Ear from external Ear location: " + externalEarLoc);
return true;
}

private void loadFromDeploymentProperties() {
File file = new File(deploymentConfigfile);
Expand Down Expand Up @@ -250,6 +274,7 @@ private void loadFromDeploymentProperties() {
backupLocation = deployment.getProperty("backupLocation");
externalProfile=Boolean.parseBoolean(deployment.getProperty("externalProfile"));
externalProfileLoc=deployment.getProperty("externalProfileLoc");
externalEarLoc=deployment.getProperty("externalEarLoc");
} catch(Exception e) {
deployToAdmin = false;
getLog().error(e);
Expand Down

0 comments on commit 66396e6

Please sign in to comment.