Search in sources :

Example 6 with IModuleResourceDelta

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

the class MavenProjectRemoteServerPublisher method processResourceDeltas.

@Override
public void processResourceDeltas(IModuleResourceDelta[] deltas, ZipOutputStream zip, Map<ZipEntry, String> deleteEntries, String deletePrefix, String deltaPrefix, boolean adjustGMTOffset) throws CoreException, IOException {
    for (IModuleResourceDelta delta : deltas) {
        IResource deltaResource = (IResource) delta.getModuleResource().getAdapter(IResource.class);
        IProject deltaProject = deltaResource.getProject();
        IWebProject lrproject = LiferayCore.create(IWebProject.class, deltaProject);
        if ((lrproject == null) || (lrproject.getDefaultDocrootFolder() == null)) {
            continue;
        }
        IFolder webappRoot = lrproject.getDefaultDocrootFolder();
        int deltaKind = delta.getKind();
        IPath deltaFullPath = deltaResource.getFullPath();
        boolean deltaZip = false;
        IPath deltaPath = null;
        if (FileUtil.exists(webappRoot)) {
            IPath containerFullPath = webappRoot.getFullPath();
            if (containerFullPath.isPrefixOf(deltaFullPath)) {
                deltaZip = true;
                deltaPath = new Path(deltaPrefix + deltaFullPath.makeRelativeTo(containerFullPath));
            }
        }
        if ((deltaZip == false) && new Path("WEB-INF").isPrefixOf(delta.getModuleRelativePath())) {
            List<IFolder> folders = CoreUtil.getSourceFolders(JavaCore.create(deltaProject));
            for (IFolder folder : folders) {
                IPath folderPath = folder.getFullPath();
                if (folderPath.isPrefixOf(deltaFullPath)) {
                    deltaZip = true;
                    break;
                }
            }
        }
        if ((deltaZip == false) && ((deltaKind == IModuleResourceDelta.ADDED) || (deltaKind == IModuleResourceDelta.CHANGED) || (deltaKind == IModuleResourceDelta.REMOVED))) {
            IPath targetPath = JavaCore.create(deltaProject).getOutputLocation();
            deltaZip = true;
            deltaPath = new Path("WEB-INF/classes").append(deltaFullPath.makeRelativeTo(targetPath));
        }
        if (deltaZip) {
            if ((deltaKind == IModuleResourceDelta.ADDED) || (deltaKind == IModuleResourceDelta.CHANGED)) {
                addToZip(deltaPath, deltaResource, zip, adjustGMTOffset);
            } else if (deltaKind == IModuleResourceDelta.REMOVED) {
                addRemoveProps(deltaPath, deltaResource, zip, deleteEntries, deletePrefix);
            } else if (deltaKind == IModuleResourceDelta.NO_CHANGE) {
                IModuleResourceDelta[] children = delta.getAffectedChildren();
                processResourceDeltas(children, zip, deleteEntries, deletePrefix, deltaPrefix, adjustGMTOffset);
            }
        }
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IPath(org.eclipse.core.runtime.IPath) IWebProject(com.liferay.ide.core.IWebProject) IModuleResourceDelta(org.eclipse.wst.server.core.model.IModuleResourceDelta) IResource(org.eclipse.core.resources.IResource) IProject(org.eclipse.core.resources.IProject) IFolder(org.eclipse.core.resources.IFolder)

Example 7 with IModuleResourceDelta

use of org.eclipse.wst.server.core.model.IModuleResourceDelta in project webtools.servertools by eclipse.

the class PublishHelper method publishDelta.

/**
 * Handle a delta publish.
 *
 * @param delta a module resource delta
 * @param path the path to publish to
 * @param monitor a progress monitor, or <code>null</code> if progress
 *    reporting and cancellation are not desired
 * @return a possibly-empty array of error and warning status
 */
public IStatus[] publishDelta(IModuleResourceDelta delta, IPath path, IProgressMonitor monitor) {
    List<IStatus> status = new ArrayList<IStatus>(2);
    IModuleResource resource = delta.getModuleResource();
    int kind2 = delta.getKind();
    if (resource instanceof IModuleFile) {
        IModuleFile file = (IModuleFile) resource;
        try {
            if (kind2 == IModuleResourceDelta.REMOVED)
                deleteFile(path, file);
            else {
                IPath path2 = path.append(file.getModuleRelativePath()).append(file.getName());
                File f = path2.toFile().getParentFile();
                if (!f.exists())
                    f.mkdirs();
                copyFile(file, path2);
            }
        } catch (CoreException ce) {
            status.add(ce.getStatus());
        }
        IStatus[] stat = new IStatus[status.size()];
        status.toArray(stat);
        return stat;
    }
    if (kind2 == IModuleResourceDelta.ADDED) {
        IPath path2 = path.append(resource.getModuleRelativePath()).append(resource.getName());
        File file = path2.toFile();
        if (!file.exists() && !file.mkdirs()) {
            status.add(new Status(IStatus.ERROR, ServerPlugin.PLUGIN_ID, 0, NLS.bind(Messages.errorMkdir, path2), null));
            IStatus[] stat = new IStatus[status.size()];
            status.toArray(stat);
            return stat;
        }
    }
    IModuleResourceDelta[] childDeltas = delta.getAffectedChildren();
    int size = childDeltas.length;
    for (int i = 0; i < size; i++) {
        IStatus[] stat = publishDelta(childDeltas[i], path, monitor);
        addArrayToList(status, stat);
    }
    if (kind2 == IModuleResourceDelta.REMOVED) {
        IPath path2 = path.append(resource.getModuleRelativePath()).append(resource.getName());
        File file = path2.toFile();
        if (file.exists() && !file.delete()) {
            status.add(new Status(IStatus.ERROR, ServerPlugin.PLUGIN_ID, 0, NLS.bind(Messages.errorDeleting, path2), null));
        }
    }
    IStatus[] stat = new IStatus[status.size()];
    status.toArray(stat);
    return stat;
}
Also used : IModuleResource(org.eclipse.wst.server.core.model.IModuleResource) ArrayList(java.util.ArrayList) IModuleResourceDelta(org.eclipse.wst.server.core.model.IModuleResourceDelta) IModuleFile(org.eclipse.wst.server.core.model.IModuleFile) IModuleFile(org.eclipse.wst.server.core.model.IModuleFile) IFile(org.eclipse.core.resources.IFile)

Example 8 with IModuleResourceDelta

use of org.eclipse.wst.server.core.model.IModuleResourceDelta 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 9 with IModuleResourceDelta

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

the class ComponentUtil method containsMember.

public static boolean containsMember(IModuleResourceDelta delta, String[] paths) {
    if (delta == null) {
        return false;
    }
    // iterate over the path and find matching child delta
    IModuleResourceDelta[] currentChildren = delta.getAffectedChildren();
    if (currentChildren == null) {
        IFile file = (IFile) delta.getModuleResource().getAdapter(IFile.class);
        if (file != null) {
            String filePath = file.getFullPath().toString();
            for (String path : paths) {
                if (filePath.contains(path)) {
                    return true;
                }
            }
        }
        return false;
    }
    for (int j = 0, jmax = currentChildren.length; j < jmax; j++) {
        IPath moduleRelativePath = currentChildren[j].getModuleRelativePath();
        String moduleRelativePathValue = moduleRelativePath.toString();
        String moduleRelativeLastSegment = moduleRelativePath.lastSegment();
        for (String path : paths) {
            if (moduleRelativePathValue.equals(path) || moduleRelativeLastSegment.equals(path)) {
                return true;
            }
        }
        boolean childContains = containsMember(currentChildren[j], paths);
        if (childContains) {
            return true;
        }
    }
    return false;
}
Also used : IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) IModuleResourceDelta(org.eclipse.wst.server.core.model.IModuleResourceDelta)

Example 10 with IModuleResourceDelta

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

the class AbstractRemoteServerPublisher method processResourceDeltas.

protected void processResourceDeltas(IModuleResourceDelta[] deltas, ZipOutputStream zip, Map<ZipEntry, String> deleteEntries, String deletePrefix, String deltaPrefix, boolean adjustGMTOffset) throws IOException, CoreException {
    for (IModuleResourceDelta delta : deltas) {
        final int deltaKind = delta.getKind();
        final IResource deltaResource = (IResource) delta.getModuleResource().getAdapter(IResource.class);
        final IProject deltaProject = deltaResource.getProject();
        // IDE-110 IDE-648
        final IWebProject lrproject = LiferayCore.create(IWebProject.class, deltaProject);
        if (lrproject != null) {
            final IFolder webappRoot = lrproject.getDefaultDocrootFolder();
            IPath deltaPath = null;
            if (webappRoot != null && webappRoot.exists()) {
                final IPath deltaFullPath = deltaResource.getFullPath();
                final IPath containerFullPath = webappRoot.getFullPath();
                deltaPath = new Path(deltaPrefix + deltaFullPath.makeRelativeTo(containerFullPath));
                if (deltaPath != null && deltaPath.segmentCount() > 0) {
                    break;
                }
            }
            if (deltaKind == IModuleResourceDelta.ADDED || deltaKind == IModuleResourceDelta.CHANGED) {
                addToZip(deltaPath, deltaResource, zip, adjustGMTOffset);
            } else if (deltaKind == IModuleResourceDelta.REMOVED) {
                addRemoveProps(deltaPath, deltaResource, zip, deleteEntries, deletePrefix);
            } else if (deltaKind == IModuleResourceDelta.NO_CHANGE) {
                IModuleResourceDelta[] children = delta.getAffectedChildren();
                processResourceDeltas(children, zip, deleteEntries, deletePrefix, deltaPrefix, adjustGMTOffset);
            }
        }
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IPath(org.eclipse.core.runtime.IPath) IWebProject(com.liferay.ide.core.IWebProject) IModuleResourceDelta(org.eclipse.wst.server.core.model.IModuleResourceDelta) IResource(org.eclipse.core.resources.IResource) IProject(org.eclipse.core.resources.IProject) IFolder(org.eclipse.core.resources.IFolder)

Aggregations

IModuleResourceDelta (org.eclipse.wst.server.core.model.IModuleResourceDelta)12 IPath (org.eclipse.core.runtime.IPath)10 IModuleResource (org.eclipse.wst.server.core.model.IModuleResource)8 IFile (org.eclipse.core.resources.IFile)7 IProject (org.eclipse.core.resources.IProject)5 CoreException (org.eclipse.core.runtime.CoreException)5 IStatus (org.eclipse.core.runtime.IStatus)5 File (java.io.File)4 IWebProject (com.liferay.ide.core.IWebProject)3 ArrayList (java.util.ArrayList)3 Path (org.eclipse.core.runtime.Path)3 ModuleFile (org.eclipse.wst.server.core.util.ModuleFile)3 IFolder (org.eclipse.core.resources.IFolder)2 IResource (org.eclipse.core.resources.IResource)2 IModule (org.eclipse.wst.server.core.IModule)2 GradleBuildFile (com.centurylink.mdw.plugin.project.model.GradleBuildFile)1 MavenBuildFile (com.centurylink.mdw.plugin.project.model.MavenBuildFile)1 OsgiBuildFile (com.centurylink.mdw.plugin.project.model.OsgiBuildFile)1 WorkflowProject (com.centurylink.mdw.plugin.project.model.WorkflowProject)1 IBundleProject (com.liferay.ide.core.IBundleProject)1