Search in sources :

Example 41 with IModuleResource

use of org.eclipse.wst.server.core.model.IModuleResource in project liferay-ide by liferay.

the class BundleModulelDelegate method members.

@Override
public IModuleResource[] members() throws CoreException {
    List<IModuleResource> retval = new ArrayList<>();
    IModuleResource[] members = super.members();
    IBundleProject bundleProject = LiferayCore.create(IBundleProject.class, getProject());
    for (IModuleResource moduleResource : members) {
        IPath path = moduleResource.getModuleRelativePath().append(moduleResource.getName());
        if (bundleProject.filterResource(path)) {
            continue;
        }
        retval.add(moduleResource);
    }
    return retval.toArray(new IModuleResource[0]);
}
Also used : IModuleResource(org.eclipse.wst.server.core.model.IModuleResource) IBundleProject(com.liferay.ide.core.IBundleProject) IPath(org.eclipse.core.runtime.IPath) ArrayList(java.util.ArrayList)

Example 42 with IModuleResource

use of org.eclipse.wst.server.core.model.IModuleResource in project liferay-ide by liferay.

the class RemoteServerBehavior method shouldPublishModuleFull.

protected boolean shouldPublishModuleFull(IModuleResourceDelta[] deltas) {
    boolean retval = false;
    if (ListUtil.isNotEmpty(deltas)) {
        for (IModuleResourceDelta delta : deltas) {
            if (shouldPublishModuleFull(delta.getAffectedChildren())) {
                retval = true;
                break;
            } else {
                final IModuleResource resource = delta.getModuleResource();
                final IFile resourceFile = (IFile) resource.getAdapter(IFile.class);
                if (resourceFile != null) {
                    final IWebProject lrproject = LiferayCore.create(IWebProject.class, resourceFile.getProject());
                    if (lrproject != null) {
                        final IPath docrootPath = lrproject.getDefaultDocrootFolder().getFullPath();
                        if (lrproject.findDocrootResource(resourceFile.getFullPath().makeRelativeTo(docrootPath)) != null) {
                            if (resource.getName().equals("web.xml") || resource.getName().equals(ILiferayConstants.LIFERAY_PLUGIN_PACKAGE_PROPERTIES_FILE)) {
                                break;
                            } else if (resource.getName().equals("portlet.xml")) {
                                break;
                            }
                        }
                    }
                }
            }
        }
    }
    return retval;
}
Also used : IModuleResource(org.eclipse.wst.server.core.model.IModuleResource) IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) IWebProject(com.liferay.ide.core.IWebProject) IModuleResourceDelta(org.eclipse.wst.server.core.model.IModuleResourceDelta)

Example 43 with IModuleResource

use of org.eclipse.wst.server.core.model.IModuleResource in project liferay-ide by liferay.

the class LiferayPublishOperation method publishJar.

private void publishJar(String jarURI, Properties p, List status, IProgressMonitor monitor) throws CoreException {
    IPath path = server.getModuleDeployDirectory(module[0]);
    boolean moving = false;
    // Get URI used for previous publish, if known
    String oldURI = (String) p.get(module[1].getId());
    if (oldURI != null) {
        // If old URI found, detect if jar is moving or changing its name
        if (jarURI != null) {
            moving = !oldURI.equals(jarURI);
        }
    }
    // If we don't have a jar URI, make a guess so we have one if we need it
    if (jarURI == null) {
        // $NON-NLS-1$//$NON-NLS-2$
        jarURI = "WEB-INF/lib/" + module[1].getName() + ".jar";
    }
    IPath jarPath = path.append(jarURI);
    // Make our best determination of the path to the old jar
    IPath oldJarPath = jarPath;
    if (oldURI != null) {
        oldJarPath = path.append(oldURI);
    }
    // Establish the destination directory
    path = jarPath.removeLastSegments(1);
    // Remove if requested or if previously published and are now serving without publishing
    if (moving || kind == IServer.PUBLISH_CLEAN || deltaKind == ServerBehaviourDelegate.REMOVED || server.getTomcatServer().isServeModulesWithoutPublish()) {
        File file = oldJarPath.toFile();
        if (file.exists())
            file.delete();
        p.remove(module[1].getId());
        if (deltaKind == ServerBehaviourDelegate.REMOVED || server.getTomcatServer().isServeModulesWithoutPublish())
            return;
    }
    if (!moving && kind != IServer.PUBLISH_CLEAN && kind != IServer.PUBLISH_FULL) {
        // avoid changes if no changes to module since last publish
        IModuleResourceDelta[] delta = server.getPublishedResourceDelta(module);
        if (ListUtil.isEmpty(delta)) {
            return;
        }
    }
    // make directory if it doesn't exist
    if (!path.toFile().exists())
        path.toFile().mkdirs();
    IModuleResource[] mr = server.getResources(module);
    IStatus[] stat = helper.publishZip(mr, jarPath, monitor);
    addArrayToList(status, stat);
    p.put(module[1].getId(), jarURI);
}
Also used : IModuleResource(org.eclipse.wst.server.core.model.IModuleResource) IStatus(org.eclipse.core.runtime.IStatus) IPath(org.eclipse.core.runtime.IPath) IModuleResourceDelta(org.eclipse.wst.server.core.model.IModuleResourceDelta) ModuleFile(org.eclipse.wst.server.core.util.ModuleFile) IFile(org.eclipse.core.resources.IFile) File(java.io.File)

Example 44 with IModuleResource

use of org.eclipse.wst.server.core.model.IModuleResource in project liferay-ide by liferay.

the class LiferayPublishOperation method clearWebXmlDescriptors.

private void clearWebXmlDescriptors(IProject project, IPath path, IProgressMonitor monitor) {
    // copy over web.xml so the liferay deployer doesn't copy web.xml filters incorrectly
    IModuleResource webXmlRes = getWebXmlFile(project, path);
    if (webXmlRes != null) {
        helper.publishToPath(new IModuleResource[] { webXmlRes }, path.append(WEB_XML_PATH), monitor);
    } else {
        File webXmlFile = path.append(WEB_XML_PATH).toFile();
        File liferayWebXmlFile = path.append(LIFERAY_WEB_XML_PATH).toFile();
        if (webXmlFile.exists()) {
            if (!webXmlFile.delete()) {
                ProjectUtil.createDefaultWebXml(webXmlFile, project.getName());
            }
        }
        if (liferayWebXmlFile.exists()) {
            if (!liferayWebXmlFile.delete()) {
                ProjectUtil.createDefaultWebXml(liferayWebXmlFile, project.getName());
            }
        }
    }
}
Also used : IModuleResource(org.eclipse.wst.server.core.model.IModuleResource) ModuleFile(org.eclipse.wst.server.core.util.ModuleFile) IFile(org.eclipse.core.resources.IFile) File(java.io.File)

Example 45 with IModuleResource

use of org.eclipse.wst.server.core.model.IModuleResource 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);
}
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) GradleBuildFile(com.centurylink.mdw.plugin.project.model.GradleBuildFile) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) IModuleResourceDelta(org.eclipse.wst.server.core.model.IModuleResourceDelta) WorkflowProject(com.centurylink.mdw.plugin.project.model.WorkflowProject) IOException(java.io.IOException) IProject(org.eclipse.core.resources.IProject) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor) OsgiBuildFile(com.centurylink.mdw.plugin.project.model.OsgiBuildFile) CoreException(org.eclipse.core.runtime.CoreException) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) IOException(java.io.IOException) MavenBuildFile(com.centurylink.mdw.plugin.project.model.MavenBuildFile) PublishHelper(org.eclipse.wst.server.core.util.PublishHelper) JarFile(java.util.jar.JarFile) OsgiBuildFile(com.centurylink.mdw.plugin.project.model.OsgiBuildFile) MavenBuildFile(com.centurylink.mdw.plugin.project.model.MavenBuildFile) GradleBuildFile(com.centurylink.mdw.plugin.project.model.GradleBuildFile) File(java.io.File)

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