use of org.eclipse.wst.server.core.model.IModuleResource in project webtools.servertools by eclipse.
the class AbstractModuleAssembler method packModule.
protected void packModule(IModule module, String deploymentUnitName, IPath destination) throws CoreException {
String dest = destination.append(deploymentUnitName).toString();
ModulePackager packager = null;
try {
packager = new ModulePackager(dest, false);
ProjectModule pm = (ProjectModule) module.loadAdapter(ProjectModule.class, null);
IModuleResource[] resources = pm.members();
for (int i = 0; i < resources.length; i++) {
doPackModule(resources[i], packager);
}
} catch (IOException e) {
IStatus status = new Status(IStatus.ERROR, CorePlugin.PLUGIN_ID, 0, "unable to assemble module", // $NON-NLS-1$
e);
throw new CoreException(status);
} finally {
try {
packager.finished();
} catch (IOException e) {
// unhandled
}
}
}
use of org.eclipse.wst.server.core.model.IModuleResource in project webtools.servertools by eclipse.
the class WarModuleAssembler method assemble.
public IPath assemble(IProgressMonitor monitor) throws CoreException {
IPath parent = copyModule(fModule, monitor);
IWebModule webModule = (IWebModule) fModule.loadAdapter(IWebModule.class, monitor);
IModule[] childModules = webModule.getModules();
for (int i = 0; i < childModules.length; i++) {
IModule module = childModules[i];
String uri = webModule.getURI(module);
if (uri == null) {
// The bad memories of WTP 1.0
// $NON-NLS-1$
IStatus status = new Status(IStatus.ERROR, CorePlugin.PLUGIN_ID, 0, "unable to assemble module null uri", null);
throw new CoreException(status);
}
IJ2EEModule jeeModule = (IJ2EEModule) module.loadAdapter(IJ2EEModule.class, monitor);
if (jeeModule != null && jeeModule.isBinary()) {
// Binary module
ProjectModule pm = (ProjectModule) module.loadAdapter(ProjectModule.class, null);
IModuleResource[] resources = pm.members();
publishHelper.publishToPath(resources, parent.append(uri), monitor);
} else {
// Project module
packModule(module, uri, parent);
}
}
return parent;
}
use of org.eclipse.wst.server.core.model.IModuleResource in project webtools.servertools by eclipse.
the class PreviewServerBehaviour method publishModule.
/*
* Publishes the given module to the server.
*/
protected void publishModule(int kind, int deltaKind, IModule[] moduleTree, IProgressMonitor monitor) throws CoreException {
IModule module = moduleTree[moduleTree.length - 1];
if (isSingleRootStructure(module))
return;
IPath to = getModulePublishDirectory(module);
if (kind == IServer.PUBLISH_CLEAN || deltaKind == ServerBehaviourDelegate.REMOVED) {
IStatus[] status = PublishUtil.deleteDirectory(to.toFile(), monitor);
throwException(status);
}
IModuleResource[] res = getResources(moduleTree);
IStatus[] status = PublishUtil.publishSmart(res, to, monitor);
throwException(status);
setModulePublishState(moduleTree, IServer.PUBLISH_STATE_NONE);
}
use of org.eclipse.wst.server.core.model.IModuleResource 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.model.IModuleResource in project webtools.servertools by eclipse.
the class PublishUtilTestCase method test02PartialCopy.
public void test02PartialCopy() throws Exception {
// wait to ensure time stamps differ
Thread.sleep(1000);
IProject project = getTestProject();
// Modify all file contents, but not the time stamps on the "B" files
IFile rootFileA = project.getFile("rootFileA.txt");
setFileContents(rootFileA, "rootFileA contents", true);
IFile rootFileB = project.getFile("rootFileB.txt");
setFileContents(rootFileB, "rootFileB contents", false);
IFile folderAFileA = project.getFile("FolderA/folderAFileA.txt");
setFileContents(folderAFileA, "folderAFileA contents", true);
IFile folderAFileB = project.getFile("FolderA/folderAFileB.txt");
setFileContents(folderAFileB, "folderAFileB contents", false);
IFile folderBFileA = project.getFile("FolderB/folderBFileA.txt");
setFileContents(folderBFileA, "folderBFileA contents", true);
IFile folderBFileB = project.getFile("FolderB/folderBFileB.txt");
setFileContents(folderBFileB, "folderBFileB contents", false);
// Publish all resources
IPath dest = getDestination();
assertNotNull(dest);
IModuleResource[] resources = getModuleResources();
IStatus[] result = PublishUtil.publishSmart(resources, dest, null, null);
assertNotNull(result);
assertTrue(getResultMessage(result), result.length == 0);
// Verify the "A" files were copied, but not the "B" files since the time stamps didn't change
String contents = getContents(dest.append(resources[0].getModuleRelativePath()));
assertEquals("rootFileA contents", contents);
contents = getContents(dest.append(resources[1].getModuleRelativePath()));
assertEquals("rootFileB contents 2", contents);
IModuleFolder mf = (IModuleFolder) resources[2];
contents = getContents(dest.append(mf.members()[0].getModuleRelativePath()));
assertEquals("folderAFileA contents", contents);
contents = getContents(dest.append(mf.members()[1].getModuleRelativePath()));
assertEquals("folderAFileB contents 2", contents);
mf = (IModuleFolder) resources[3];
contents = getContents(dest.append(mf.members()[0].getModuleRelativePath()));
assertEquals("folderBFileA contents", contents);
contents = getContents(dest.append(mf.members()[1].getModuleRelativePath()));
assertEquals("folderBFileB contents 2", contents);
}
Aggregations