use of fish.payara.deployment.util.GAVConvertor in project Payara by payara.
the class PayaraMicroImpl method getGAVURLs.
/**
* Converts the GAVs provided to a URLs, and stores them in the
* deploymentURLsMap.
*/
private void getGAVURLs() throws GlassFishException {
GAVConvertor gavConvertor = new GAVConvertor();
for (String gav : GAVs) {
try {
Map.Entry<String, URL> artefactMapEntry = gavConvertor.getArtefactMapEntry(gav, repositoryURLs);
if (deploymentURLsMap == null) {
deploymentURLsMap = new LinkedHashMap<>();
}
String contextRoot = artefactMapEntry.getKey();
if ("ROOT".equals(contextRoot)) {
contextRoot = "/";
}
deploymentURLsMap.put(contextRoot, artefactMapEntry.getValue());
} catch (MalformedURLException ex) {
throw new GlassFishException(ex.getMessage());
}
}
}
use of fish.payara.deployment.util.GAVConvertor in project Payara by payara.
the class DeployRemoteArchiveCommand method execute.
@Override
public void execute(AdminCommandContext context) {
CommandRunner commandRunner = serviceLocator.getService(CommandRunner.class);
ActionReport actionReport = context.getActionReport();
// Initialise to null so we can do a null check later
File fileToDeploy = null;
// Assume only Http or Https connections are direct URLs
if (path.startsWith("http://") || path.startsWith("https://")) {
try {
// Download the file to temp, and return a File object to pass to the deploy command
fileToDeploy = convertUriToFile(new URI(path));
} catch (IOException | URISyntaxException ex) {
logger.log(Level.SEVERE, ex.getMessage());
actionReport.setMessage("Exception converting URI to File: " + path);
actionReport.setActionExitCode(ActionReport.ExitCode.FAILURE);
}
// If a name hasn't been provided, get it from the URI
if (name == null) {
if (path.endsWith(".jar")) {
name = path.substring(path.lastIndexOf("/") + 1, path.indexOf(".jar"));
} else if (path.endsWith(".war")) {
name = path.substring(path.lastIndexOf("/") + 1, path.indexOf(".war"));
} else if (path.endsWith(".ear")) {
name = path.substring(path.lastIndexOf("/") + 1, path.indexOf(".ear"));
}
}
// If a context root hasn't been provided, get it from the URI
if (contextroot == null) {
if (path.endsWith(".jar")) {
contextroot = "/" + path.substring(path.lastIndexOf("/") + 1, path.indexOf(".jar"));
} else if (path.endsWith(".war")) {
contextroot = "/" + path.substring(path.lastIndexOf("/") + 1, path.indexOf(".war"));
} else if (path.endsWith(".ear")) {
contextroot = "/" + path.substring(path.lastIndexOf("/") + 1, path.indexOf(".ear"));
}
}
} else {
try {
// If the path String doesn't start with Http or Https, then assume it's a GAV coordinate
logger.log(Level.FINE, "Path does not appear to be a URL, will attempt to read as GAV coordinate");
// Convert the Array to a List of Urls, and append "/" to the Urls if they don't already end with one
List<URL> repositoryUrls = formatRepositoryUrls(additionalRepositories);
// Get the URL for the given GAV coordinate
GAVConvertor gavConvertor = new GAVConvertor();
Entry<String, URL> artefactEntry = gavConvertor.getArtefactMapEntry(path, repositoryUrls);
// Download the file to temp, and return a File object to pass to the deploy command
fileToDeploy = convertUriToFile(artefactEntry.getValue().toURI());
// If a name hasn't been provided, get it from the artefact name
if (name == null) {
name = artefactEntry.getKey();
}
// If a context root hasn't been provided, get it from the artefact name
if (contextroot == null) {
contextroot = "/" + artefactEntry.getKey();
}
} catch (MalformedURLException ex) {
logger.log(Level.SEVERE, ex.getMessage());
actionReport.setMessage("Exception converting GAV to URL: " + path);
actionReport.setActionExitCode(ActionReport.ExitCode.FAILURE);
} catch (IOException | URISyntaxException ex) {
logger.log(Level.SEVERE, ex.getMessage());
actionReport.setMessage("Exception converting URI to File: " + path);
actionReport.setActionExitCode(ActionReport.ExitCode.FAILURE);
}
}
// Only continue if we actually have a file to deploy
if (fileToDeploy != null) {
ActionReport subReport = actionReport.addSubActionsReport();
CommandRunner.CommandInvocation commandInvocation = commandRunner.getCommandInvocation("deploy", subReport, context.getSubject());
ParameterMap parameters = createAndPopulateParameterMap(fileToDeploy);
commandInvocation.parameters(parameters);
commandInvocation.execute();
} else {
actionReport.setMessage("Provided path does not appear to be a valid URL or GAV coordinate: " + path + "\nSee the server log for more details");
actionReport.setActionExitCode(ActionReport.ExitCode.FAILURE);
}
}
Aggregations