Search in sources :

Example 26 with IModuleResource

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
        }
    }
}
Also used : Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) IModuleResource(org.eclipse.wst.server.core.model.IModuleResource) ProjectModule(org.eclipse.wst.server.core.util.ProjectModule) IStatus(org.eclipse.core.runtime.IStatus) CoreException(org.eclipse.core.runtime.CoreException) IOException(java.io.IOException)

Example 27 with IModuleResource

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;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IModuleResource(org.eclipse.wst.server.core.model.IModuleResource) IModule(org.eclipse.wst.server.core.IModule) IStatus(org.eclipse.core.runtime.IStatus) IJ2EEModule(org.eclipse.jst.server.core.IJ2EEModule) IPath(org.eclipse.core.runtime.IPath) IWebModule(org.eclipse.jst.server.core.IWebModule) ProjectModule(org.eclipse.wst.server.core.util.ProjectModule) CoreException(org.eclipse.core.runtime.CoreException)

Example 28 with IModuleResource

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);
}
Also used : IModuleResource(org.eclipse.wst.server.core.model.IModuleResource) IModule(org.eclipse.wst.server.core.IModule) IStatus(org.eclipse.core.runtime.IStatus) IPath(org.eclipse.core.runtime.IPath)

Example 29 with IModuleResource

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);
}
Also used : IModuleResource(org.eclipse.wst.server.core.model.IModuleResource) IModule(org.eclipse.wst.server.core.IModule) IStatus(org.eclipse.core.runtime.IStatus) IStaticWeb(org.eclipse.wst.server.core.util.IStaticWeb) IPath(org.eclipse.core.runtime.IPath) PublishHelper(org.eclipse.wst.server.core.util.PublishHelper) File(java.io.File) CoreException(org.eclipse.core.runtime.CoreException)

Example 30 with IModuleResource

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);
}
Also used : IModuleResource(org.eclipse.wst.server.core.model.IModuleResource) IModuleFolder(org.eclipse.wst.server.core.model.IModuleFolder) IStatus(org.eclipse.core.runtime.IStatus) IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) IProject(org.eclipse.core.resources.IProject)

Aggregations

IModuleResource (org.eclipse.wst.server.core.model.IModuleResource)45 IPath (org.eclipse.core.runtime.IPath)24 IModuleFolder (org.eclipse.wst.server.core.model.IModuleFolder)21 IFile (org.eclipse.core.resources.IFile)17 IStatus (org.eclipse.core.runtime.IStatus)17 IModule (org.eclipse.wst.server.core.IModule)12 File (java.io.File)11 IModuleFile (org.eclipse.wst.server.core.model.IModuleFile)10 ModuleFile (org.eclipse.wst.server.core.util.ModuleFile)9 IProject (org.eclipse.core.resources.IProject)8 CoreException (org.eclipse.core.runtime.CoreException)8 IModuleResourceDelta (org.eclipse.wst.server.core.model.IModuleResourceDelta)8 ArrayList (java.util.ArrayList)7 ModuleFolder (org.eclipse.wst.server.core.util.ModuleFolder)7 ModuleDelegate (org.eclipse.wst.server.core.model.ModuleDelegate)5 IContainer (org.eclipse.core.resources.IContainer)4 Path (org.eclipse.core.runtime.Path)4 Status (org.eclipse.core.runtime.Status)4 IOException (java.io.IOException)3 ProjectModule (org.eclipse.wst.server.core.util.ProjectModule)3