use of org.eclipse.wst.server.core.util.PublishHelper in project webtools.servertools by eclipse.
the class TomcatServerBehaviour method publishModule.
/*
* Publishes the given module to the server.
*/
protected void publishModule(int kind, int deltaKind, IModule[] moduleTree, IProgressMonitor monitor) throws CoreException {
if (getServer().getServerState() != IServer.STATE_STOPPED) {
if (deltaKind == ServerBehaviourDelegate.ADDED || deltaKind == ServerBehaviourDelegate.REMOVED)
setServerRestartState(true);
}
if (getTomcatServer().isTestEnvironment())
return;
Properties p = loadModulePublishLocations();
PublishHelper helper = new PublishHelper(getRuntimeBaseDirectory().append("temp").toFile());
// If parent web module
if (moduleTree.length == 1) {
publishDir(deltaKind, p, moduleTree, helper, monitor);
} else // Else a child module
{
// Try to determine the URI for the child module
IWebModule webModule = (IWebModule) moduleTree[0].loadAdapter(IWebModule.class, monitor);
String childURI = null;
if (webModule != null) {
childURI = webModule.getURI(moduleTree[1]);
}
// Try to determine if child is binary
IJ2EEModule childModule = (IJ2EEModule) moduleTree[1].loadAdapter(IJ2EEModule.class, monitor);
boolean isBinary = false;
if (childModule != null) {
isBinary = childModule.isBinary();
}
if (isBinary) {
publishArchiveModule(childURI, kind, deltaKind, p, moduleTree, helper, monitor);
} else {
publishJar(childURI, kind, deltaKind, p, moduleTree, helper, monitor);
}
}
setModulePublishState(moduleTree, IServer.PUBLISH_STATE_NONE);
saveModulePublishLocations(p);
}
use of org.eclipse.wst.server.core.util.PublishHelper in project webtools.servertools by eclipse.
the class HttpServerBehaviour method publishModule.
/*
* Publishes the given module to the server.
*/
protected void publishModule(int kind, int deltaKind, IModule[] moduleTree, IProgressMonitor monitor) throws CoreException {
if (!getHttpServer().isPublishing())
return;
String contextRoot = null;
IModule module = moduleTree[moduleTree.length - 1];
IStaticWeb sw = (IStaticWeb) module.loadAdapter(IStaticWeb.class, monitor);
if (sw != null)
contextRoot = sw.getContextRoot();
else
contextRoot = module.getName();
IPath to = getServer().getRuntime().getLocation();
File temp = null;
try {
if (to.removeLastSegments(1).toFile().exists())
temp = to.removeLastSegments(1).append("temp").toFile();
} catch (Exception e) {
// ignore - use null temp folder
}
if (contextRoot != null && !contextRoot.equals(""))
to = to.append(contextRoot);
IModuleResource[] res = getResources(moduleTree);
PublishHelper pubHelper = new PublishHelper(temp);
IStatus[] status = pubHelper.publishSmart(res, to, monitor);
if (temp.exists())
temp.delete();
throwException(status);
setModulePublishState(moduleTree, IServer.PUBLISH_STATE_NONE);
}
use of org.eclipse.wst.server.core.util.PublishHelper in project mdw-designer by CenturyLinkCloud.
the class TomcatServerBehavior method publishModule.
/**
* For client apps with no workflow webapp, we take care of publishing in
* ProjectUpdater.deployCloudWar().
*/
@Override
protected void publishModule(int kind, int deltaKind, IModule[] moduleTree, IProgressMonitor monitor) throws CoreException {
IProject webProject = getWebProject();
boolean isClientWf = false;
if (// not
webProject == null && moduleTree[0].getProject() != null)
// framework
isClientWf = WorkflowProjectManager.getInstance().getWorkflowProject(moduleTree[0].getProject()) != null;
if (// nothing to publish -- just refresh
isClientWf) {
// refresh the project's deploy folder after full publish
WorkflowProject project = getProject();
if (project != null)
project.getDeployFolder().refreshLocal(IResource.DEPTH_INFINITE, new SubProgressMonitor(monitor, 500));
} else {
IPath publishPath = getModuleDeployDirectory(moduleTree[0]);
if (moduleTree.length > 1 && !"jst.web".equals(moduleTree[1].getModuleType().getId()))
// non-web
publishPath = publishPath.append("WEB-INF/classes");
// child
// module
File publishDir = publishPath.toFile();
// passes
if (moduleTree.length == 1 && kind == IServer.PUBLISH_CLEAN || deltaKind == ServerBehaviourDelegate.REMOVED || getTomcatServer().isServeModulesWithoutPublish()) {
if (publishPath != null && publishDir.exists())
showError(PublishHelper.deleteDirectory(publishDir, monitor));
if (deltaKind == ServerBehaviourDelegate.REMOVED || getTomcatServer().isServeModulesWithoutPublish()) {
setModulePublishState(moduleTree, IServer.PUBLISH_STATE_NONE);
return;
}
} else if (!publishDir.exists() && !publishDir.mkdirs()) {
PluginMessages.log("Error creating directory: " + publishDir);
showError("Error creating directory: " + publishDir, "Server Deploy", getProject());
return;
}
PublishHelper publishHelper = new PublishHelper(null);
if (kind == IServer.PUBLISH_CLEAN || kind == IServer.PUBLISH_FULL) {
if (// publish everything in top level
moduleTree.length == 1) // module to prevent overwriting by submodules
{
// referenced projects first so that main module overrides any conflicts
IModule[] submods = getTomcatServer().getChildModules(moduleTree);
for (IModule submod : submods) {
if ("mdw-web".equals(submod.getName()) || "mdw-taskmgr".equals(submod.getName()))
continue;
IModuleResource[] mrs = getResources(new IModule[] { submod });
IPath submodPath = publishPath;
if (!"jst.web".equals(submod.getModuleType().getId()))
submodPath = submodPath.append("WEB-INF/classes");
// deployment assembly designates
IStatus[] statuses = publishHelper.publishFull(mrs, submodPath, monitor);
if (showError(statuses))
return;
monitor.worked(2000 / submods.length);
}
// main module publish
IModuleResource[] mrs = getResources(moduleTree);
IStatus[] statuses = publishHelper.publishFull(mrs, publishPath, monitor);
if (showError(statuses))
return;
monitor.worked(1000);
// wtp components cover deps)
try {
OsgiBuildFile buildFile = new GradleBuildFile(moduleTree[0].getProject());
if (!buildFile.exists())
// fall
buildFile = new MavenBuildFile(moduleTree[0].getProject());
// back
// to
// pom.xml
buildFile.parse();
if (!buildFile.exists()) {
PluginMessages.log("neither build.gradle nor pom.xml was found");
// can happen when project deleted from
return;
// workspace
}
String archiveName = buildFile.getArtifactName();
if (archiveName.startsWith("mdw-hub-") || archiveName.startsWith("mdwhub-")) {
// first delete conflicting jsf dependencies
File toDelete = publishPath.append("WEB-INF/lib/mdwweb-" + buildFile.getVersion() + ".jar").toFile();
if (toDelete.exists() && !toDelete.delete())
throw new IOException("Unable to delete file: " + toDelete);
archiveName = "mdw-" + buildFile.getVersion() + ".war";
}
if (!archiveName.endsWith(".war"))
archiveName += ".war";
File archive;
if (// relative
buildFile.getArtifactGenDir().startsWith(".."))
// path
// one
// level
// too
// high
archive = new File(moduleTree[0].getProject().getLocation().toFile().toString() + buildFile.getArtifactGenDir().substring(2) + "/" + archiveName);
else
archive = new File(moduleTree[0].getProject().getLocation().toFile().toString() + "/" + buildFile.getArtifactGenDir() + "/" + archiveName);
if (!archive.exists()) {
PluginMessages.log("Unable to locate web archive: " + archive);
showError("Unable to locate web archive: " + archive, "Server Deploy", getProject());
return;
}
copyWebInfLibArchiveEntriesToDir(archive, publishDir);
// refresh the project's deploy folder after full publish
WorkflowProject project = getProject();
if (project != null)
project.getDeployFolder().refreshLocal(IResource.DEPTH_INFINITE, new SubProgressMonitor(monitor, 500));
} catch (OperationCanceledException ex) {
// do nothing
} catch (Exception ex) {
PluginMessages.log(ex);
showError(ex.toString(), "Server Publish", getProject());
}
}
} else {
IModuleResourceDelta[] deltas = getPublishedResourceDelta(moduleTree);
IStatus[] statuses = publishHelper.publishDelta(deltas, publishPath, monitor);
if (showError(statuses))
return;
}
}
setModulePublishState(moduleTree, IServer.PUBLISH_STATE_NONE);
}
Aggregations