Search in sources :

Example 1 with IJ2EEModule

use of org.eclipse.jst.server.core.IJ2EEModule in project liferay-ide by liferay.

the class LiferayPublishOperation method execute.

/**
 * @see PublishOperation#execute(IProgressMonitor, IAdaptable)
 */
public void execute(IProgressMonitor monitor, IAdaptable info) throws CoreException {
    List status = new ArrayList();
    // If parent web module
    if (module.length == 1) {
        if (!ServerUtil.isExtProject(module[0].getProject())) {
            publishDir(module[0], status, monitor);
        }
    } else // Else a child module
    {
        Properties p = server.loadModulePublishLocations();
        // Try to determine the URI for the child module
        IWebModule webModule = (IWebModule) module[0].loadAdapter(IWebModule.class, monitor);
        String childURI = null;
        if (webModule != null) {
            childURI = webModule.getURI(module[1]);
        }
        // Try to determine if child is binary
        IJ2EEModule childModule = (IJ2EEModule) module[1].loadAdapter(IJ2EEModule.class, monitor);
        boolean isBinary = false;
        if (childModule != null) {
            isBinary = childModule.isBinary();
        }
        if (isBinary) {
            publishArchiveModule(childURI, p, status, monitor);
        } else {
            publishJar(childURI, p, status, monitor);
        }
        server.saveModulePublishLocations(p);
    }
    throwException(status);
    server.setModulePublishState2(module, IServer.PUBLISH_STATE_NONE);
}
Also used : IJ2EEModule(org.eclipse.jst.server.core.IJ2EEModule) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) IWebModule(org.eclipse.jst.server.core.IWebModule) Properties(java.util.Properties)

Example 2 with IJ2EEModule

use of org.eclipse.jst.server.core.IJ2EEModule in project webtools.servertools by eclipse.

the class EarModuleAssembler method assemble.

public IPath assemble(IProgressMonitor monitor) throws CoreException {
    // copy ear root to the temporary assembly directory
    IPath parent = fAssembleRoot;
    final IModule[] rootMod = { fModule };
    boolean shouldCopy = (IServer.PUBLISH_STATE_NONE != fServer.getServer().getModulePublishState(rootMod));
    if (shouldCopy)
        copyModule(fModule, monitor);
    IEnterpriseApplication earModule = (IEnterpriseApplication) fModule.loadAdapter(IEnterpriseApplication.class, monitor);
    IModule[] childModules = earModule.getModules();
    for (int i = 0; i < childModules.length; i++) {
        IModule module = childModules[i];
        String uri = earModule.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
            // just copy
            ProjectModule pm = (ProjectModule) module.loadAdapter(ProjectModule.class, null);
            IModuleResource[] resources = pm.members();
            publishHelper.publishToPath(resources, parent.append(uri), monitor);
            // done! no need to go further
            continue;
        }
        if (shouldRepack(module)) {
            packModule(module, uri, parent);
        }
    }
    return parent;
}
Also used : Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) 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) IEnterpriseApplication(org.eclipse.jst.server.core.IEnterpriseApplication) ProjectModule(org.eclipse.wst.server.core.util.ProjectModule) CoreException(org.eclipse.core.runtime.CoreException)

Example 3 with IJ2EEModule

use of org.eclipse.jst.server.core.IJ2EEModule 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);
}
Also used : IJ2EEModule(org.eclipse.jst.server.core.IJ2EEModule) PublishHelper(org.eclipse.wst.server.core.util.PublishHelper) IModulePublishHelper(org.eclipse.wst.server.core.internal.IModulePublishHelper) IWebModule(org.eclipse.jst.server.core.IWebModule) Properties(java.util.Properties)

Example 4 with IJ2EEModule

use of org.eclipse.jst.server.core.IJ2EEModule in project webtools.servertools by eclipse.

the class TomcatServerBehaviour method publishDir.

/**
 * Publish a web module.
 *
 * @param deltaKind
 * @param p
 * @param module
 * @param monitor
 * @throws CoreException
 */
private void publishDir(int deltaKind, Properties p, IModule[] module, PublishHelper helper, IProgressMonitor monitor) throws CoreException {
    List<IStatus> status = new ArrayList<IStatus>();
    // Remove if requested or if previously published and are now serving without publishing
    if (deltaKind == REMOVED || getTomcatServer().isServeModulesWithoutPublish()) {
        String publishPath = (String) p.get(module[0].getId());
        if (publishPath != null) {
            try {
                File f = new File(publishPath);
                if (f.exists()) {
                    IStatus[] stat = PublishHelper.deleteDirectory(f, monitor);
                    PublishOperation2.addArrayToList(status, stat);
                }
            } catch (Exception e) {
                throw new CoreException(new Status(IStatus.WARNING, TomcatPlugin.PLUGIN_ID, 0, NLS.bind(Messages.errorPublishCouldNotRemoveModule, module[0].getName()), e));
            }
            p.remove(module[0].getId());
        }
    } else {
        IPath path = getModuleDeployDirectory(module[0]);
        IModuleResource[] mr = getResources(module);
        IPath[] jarPaths = null;
        IWebModule webModule = (IWebModule) module[0].loadAdapter(IWebModule.class, monitor);
        IModule[] childModules = getServer().getChildModules(module, monitor);
        if (childModules != null && childModules.length > 0) {
            jarPaths = new IPath[childModules.length];
            for (int i = 0; i < childModules.length; i++) {
                if (webModule != null) {
                    jarPaths[i] = new Path(webModule.getURI(childModules[i]));
                } else {
                    IJ2EEModule childModule = (IJ2EEModule) childModules[i].loadAdapter(IJ2EEModule.class, monitor);
                    if (childModule != null && childModule.isBinary()) {
                        jarPaths[i] = new Path("WEB-INF/lib").append(childModules[i].getName());
                    } else {
                        jarPaths[i] = new Path("WEB-INF/lib").append(childModules[i].getName() + ".jar");
                    }
                }
            }
        }
        IStatus[] stat = helper.publishSmart(mr, path, jarPaths, monitor);
        PublishOperation2.addArrayToList(status, stat);
        p.put(module[0].getId(), path.toOSString());
    }
    PublishOperation2.throwException(status);
}
Also used : IJ2EEModule(org.eclipse.jst.server.core.IJ2EEModule) ArrayList(java.util.ArrayList) IWebModule(org.eclipse.jst.server.core.IWebModule) IOException(java.io.IOException) File(java.io.File)

Example 5 with IJ2EEModule

use of org.eclipse.jst.server.core.IJ2EEModule 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)

Aggregations

IJ2EEModule (org.eclipse.jst.server.core.IJ2EEModule)8 IWebModule (org.eclipse.jst.server.core.IWebModule)6 ArrayList (java.util.ArrayList)5 IModule (org.eclipse.wst.server.core.IModule)4 Properties (java.util.Properties)3 IEnterpriseApplication (org.eclipse.jst.server.core.IEnterpriseApplication)3 List (java.util.List)2 CoreException (org.eclipse.core.runtime.CoreException)2 IPath (org.eclipse.core.runtime.IPath)2 IStatus (org.eclipse.core.runtime.IStatus)2 Status (org.eclipse.core.runtime.Status)2 IModuleResource (org.eclipse.wst.server.core.model.IModuleResource)2 ProjectModule (org.eclipse.wst.server.core.util.ProjectModule)2 File (java.io.File)1 IOException (java.io.IOException)1 IModulePublishHelper (org.eclipse.wst.server.core.internal.IModulePublishHelper)1 PublishHelper (org.eclipse.wst.server.core.util.PublishHelper)1