use of com.liferay.ide.core.remote.APIException in project liferay-ide by liferay.
the class RemoteServerBehavior method publishModuleDelta.
protected int publishModuleDelta(IModule[] module, IProgressMonitor monitor) throws CoreException {
if (monitor == null) {
monitor = new NullProgressMonitor();
}
IProject moduleProject = module[0].getProject();
IModuleResourceDelta[] delta = getPublishedResourceDelta(module);
if (shouldPublishModuleFull(delta)) {
return publishModuleFull(module, CHANGED, monitor);
}
final String appName = ComponentUtilities.getServerContextRoot(moduleProject);
// $NON-NLS-1$ //$NON-NLS-2$
monitor.subTask("Creating partial " + moduleProject.getName() + " update archive...");
final ILiferayProject liferayProject = LiferayCore.create(moduleProject);
final IRemoteServerPublisher publisher = liferayProject.adapt(IRemoteServerPublisher.class);
if (publisher == null) {
setModuleStatus(module, null);
throw new CoreException(LiferayServerCore.error(Msgs.publishingModuleProject));
}
final IPath warPath = publisher.publishModuleDelta(appName + ".war", delta, "liferay", true);
monitor.worked(25);
if (monitor != null && monitor.isCanceled()) {
return IServer.PUBLISH_STATE_UNKNOWN;
}
monitor.subTask(Msgs.gettingLiferayConnection);
IServerManagerConnection connection = getServerManagerConnection();
monitor.subTask(NLS.bind(Msgs.updatingModuleProject, moduleProject.getName()));
Object error = null;
try {
error = connection.updateApplication(appName, warPath.toOSString(), monitor);
} catch (APIException e) {
error = e.getMessage();
}
monitor.worked(90);
if (error != null) {
throw new CoreException(LiferayServerCore.error(error.toString()));
}
monitor.done();
return IServer.PUBLISH_STATE_NONE;
}
use of com.liferay.ide.core.remote.APIException in project liferay-ide by liferay.
the class RemoteServerBehavior method removeModule.
protected int removeModule(IModule[] module, IProgressMonitor monitor) throws CoreException {
if (module == null) {
throw new CoreException(LiferayServerCore.error(// $NON-NLS-1$
"Cannot publish module with length " + (module != null ? module.length : 0)));
}
if (monitor == null) {
monitor = new NullProgressMonitor();
}
IModule publishModule = module[0];
IProject moduleProject = publishModule.getProject();
if (moduleProject == null) {
// just return this is a dead module
setModuleStatus(module, null);
return IServer.PUBLISH_STATE_UNKNOWN;
}
/*
* First look to see if this module (ear plugin) is actually installed on liferay, and if it is then uninstall
* it
*/
monitor.beginTask(NLS.bind(Msgs.undeployingModuleProject, moduleProject.getName()), 100);
final String appName = ComponentUtilities.getServerContextRoot(moduleProject);
setModuleStatus(module, LiferayServerCore.info(Msgs.uninstalling));
monitor.subTask(Msgs.gettingRemoteConnection);
IServerManagerConnection remoteConnection = getServerManagerConnection();
// 25%
monitor.worked(25);
// File scriptFile = getScriptFile( "publish/uninstallApplicationScript.groovy" );
monitor.subTask(NLS.bind(Msgs.uninstallingModuleProject, moduleProject.getName()));
Object error = null;
try {
error = remoteConnection.uninstallApplication(appName, monitor);
} catch (APIException e) {
error = e.getMessage();
}
// 100%
monitor.worked(75);
if (error != null) {
throw new CoreException(LiferayServerCore.error(error.toString()));
}
setModuleStatus(module, null);
return IServer.PUBLISH_STATE_NONE;
}
use of com.liferay.ide.core.remote.APIException in project liferay-ide by liferay.
the class ServerManagerConnection method updateApplication.
public Object updateApplication(String appName, String absolutePath, IProgressMonitor monitor) throws APIException {
try {
final File file = new File(absolutePath);
final FileBody fileBody = new FileBody(file);
final MultipartEntity entity = new MultipartEntity();
entity.addPart(file.getName(), fileBody);
final HttpPut httpPut = new HttpPut();
httpPut.setEntity(entity);
Object response = httpJSONAPI(httpPut, getUpdateURI(appName));
if (response instanceof JSONObject) {
JSONObject json = (JSONObject) response;
if (isSuccess(json)) {
// $NON-NLS-1$
System.out.println("updateApplication: success.\n\n");
} else {
if (isError(json)) {
// $NON-NLS-1$
return json.getString("error");
} else {
// $NON-NLS-1$
return "updateApplication error " + getDeployURI(appName);
}
}
}
httpPut.releaseConnection();
} catch (Exception e) {
e.printStackTrace();
return e.getMessage();
}
return null;
}
use of com.liferay.ide.core.remote.APIException in project liferay-ide by liferay.
the class ServerManagerConnection method isLiferayPluginStarted.
public boolean isLiferayPluginStarted(String appName) throws APIException {
final Object response = getJSONAPI(getPluginURI(appName));
if (response instanceof JSONObject) {
JSONObject json = (JSONObject) response;
try {
if (isSuccess(json)) {
JSONObject jsonOutput = getJSONOutput(json);
boolean installed = jsonOutput.getBoolean("started");
if (installed) {
return true;
}
}
} catch (Exception e) {
throw new APIException(getPluginURI(appName), e);
}
}
return false;
}
use of com.liferay.ide.core.remote.APIException in project liferay-ide by liferay.
the class ServerManagerConnection method installApplication.
public Object installApplication(String absolutePath, String appName, IProgressMonitor submon) throws APIException {
try {
FileBody fileBody = new FileBody(new File(absolutePath));
MultipartEntity entity = new MultipartEntity();
// $NON-NLS-1$
entity.addPart("deployWar", fileBody);
HttpPost httpPost = new HttpPost();
httpPost.setEntity(entity);
Object response = httpJSONAPI(httpPost, getDeployURI(appName));
if (response instanceof JSONObject) {
JSONObject json = (JSONObject) response;
if (isSuccess(json)) {
// $NON-NLS-1$
System.out.println("installApplication: Sucess.\n\n");
} else {
if (isError(json)) {
// $NON-NLS-1$
return json.getString("error");
} else {
// $NON-NLS-1$
return "installApplication error " + getDeployURI(appName);
}
}
}
httpPost.releaseConnection();
} catch (Exception e) {
e.printStackTrace();
return e.getMessage();
}
return null;
}
Aggregations