Search in sources :

Example 86 with Status

use of org.eclipse.core.runtime.Status in project sling by apache.

the class JcrNode method handleDropResource.

private IStatus handleDropResource(IFolder targetFolder, IResource droppedResourceRoot, int detail) throws CoreException {
    if (targetFolder == null) {
        return new Status(IStatus.CANCEL, Activator.PLUGIN_ID, 1, "Cannot drop on this type of element (yet)", null);
    }
    if (droppedResourceRoot == null) {
        throw new IllegalArgumentException("droppedResourceRoot must not be null");
    }
    IFile copyToFile = targetFolder.getFile(droppedResourceRoot.getName());
    IPath copyToPath = copyToFile.getFullPath();
    switch(detail) {
        case DND.DROP_COPY:
            {
                droppedResourceRoot.copy(copyToPath, true, new NullProgressMonitor());
                break;
            }
        case DND.DROP_MOVE:
            {
                droppedResourceRoot.move(copyToPath, true, new NullProgressMonitor());
                break;
            }
        default:
            {
                throw new IllegalStateException("Unknown drop action (detail: " + detail + ")");
            }
    }
    return Status.OK_STATUS;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath)

Example 87 with Status

use of org.eclipse.core.runtime.Status in project sling by apache.

the class JcrNode method handleDrop.

public IStatus handleDrop(Object data, int detail) throws CoreException {
    IFolder folder = (IFolder) this.resource;
    if (data instanceof IStructuredSelection) {
        IStructuredSelection sel = (IStructuredSelection) data;
        Object firstElem = sel.getFirstElement();
        if (firstElem instanceof IResource) {
            IResource resource = (IResource) firstElem;
            return handleDropResource(folder, resource, detail);
        } else if (firstElem instanceof JcrNode) {
            JcrNode node = (JcrNode) firstElem;
            return handleDropNode(folder, node, detail);
        } else {
            return new Status(IStatus.CANCEL, Activator.PLUGIN_ID, 1, "Cannot drop on this type of element (yet) [1]", null);
        }
    } else {
        return new Status(IStatus.CANCEL, Activator.PLUGIN_ID, 1, "Cannot drop this type of selection", null);
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IResource(org.eclipse.core.resources.IResource) IFolder(org.eclipse.core.resources.IFolder)

Example 88 with Status

use of org.eclipse.core.runtime.Status in project sling by apache.

the class ServiceComponentHeaderValidator method findMissingScrDescriptors.

/**
     * Finds missing SCR descriptor files referenced in the manifest
     * 
     * <p>
     * Only acts if the Manifest is located under the project's output directory at
     * </p>
     * 
     * @param manifest the location of the manifest to parse for the Service-Component header
     * @return a list of missing files, empty if no problems are found
     * @throws CoreException any errors
     */
public List<IFile> findMissingScrDescriptors(IFile manifest) throws CoreException {
    IProject project = manifest.getProject();
    Logger pluginLogger = Activator.getDefault().getPluginLogger();
    IJavaProject javaProject = ProjectHelper.asJavaProject(project);
    IFolder outputFolder = (IFolder) project.getWorkspace().getRoot().findMember(javaProject.getOutputLocation());
    if (!outputFolder.getFullPath().isPrefixOf(manifest.getFullPath())) {
        pluginLogger.trace("Ignoring manifest found at {0} since it is not under the output directory at {1}", manifest.getFullPath(), outputFolder.getFullPath());
        return Collections.emptyList();
    }
    List<IFile> missingDescriptors = new ArrayList<>();
    try (InputStream contents = manifest.getContents()) {
        Manifest mf = new Manifest(contents);
        String serviceComponentHeader = mf.getMainAttributes().getValue("Service-Component");
        if (serviceComponentHeader != null) {
            String[] entries = serviceComponentHeader.split(",");
            for (String entry : entries) {
                entry = entry.trim();
                if (entry.contains("*")) {
                    pluginLogger.trace("Ignoring wildcard Service-Component entry {0}", entry);
                    continue;
                }
                IFile descriptor = outputFolder.getFile(entry);
                if (descriptor.exists()) {
                    pluginLogger.trace("Found matching resource for Service-Component entry {0}", entry);
                    continue;
                }
                missingDescriptors.add(descriptor);
                pluginLogger.trace("Raising error for missing DS descriptor entry {0}", entry);
            }
        }
    } catch (IOException e) {
        throw new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Unable to access " + manifest.getFullPath(), e));
    }
    return missingDescriptors;
}
Also used : Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) IFile(org.eclipse.core.resources.IFile) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) IOException(java.io.IOException) Logger(org.apache.sling.ide.log.Logger) Manifest(java.util.jar.Manifest) IProject(org.eclipse.core.resources.IProject) IJavaProject(org.eclipse.jdt.core.IJavaProject) CoreException(org.eclipse.core.runtime.CoreException) IFolder(org.eclipse.core.resources.IFolder)

Example 89 with Status

use of org.eclipse.core.runtime.Status in project sling by apache.

the class JVMDebuggerConnection method connectInDebugMode.

boolean connectInDebugMode(ILaunch launch, IServer iServer, IProgressMonitor monitor) throws CoreException {
    long start = System.currentTimeMillis();
    this.launch = launch;
    boolean success = false;
    IVMConnector connector = null;
    connector = JavaRuntime.getVMConnector(IJavaLaunchConfigurationConstants.ID_SOCKET_ATTACH_VM_CONNECTOR);
    if (connector == null) {
        connector = JavaRuntime.getDefaultVMConnector();
    }
    if (connector == null) {
        throw new CoreException(new Status(IStatus.ERROR, "org.apache.sling.ide.eclipse.wst", "Could not get jvm connctor"));
    }
    ISlingLaunchpadServer launchpadServer = (ISlingLaunchpadServer) iServer.loadAdapter(SlingLaunchpadServer.class, monitor);
    ISlingLaunchpadConfiguration configuration = launchpadServer.getConfiguration();
    int debugPort = configuration.getDebugPort();
    if (debugPort <= 0) {
        throw new CoreException(new Status(IStatus.ERROR, "org.apache.sling.ide.eclipse.wst", "debug port not configured"));
    }
    Map<String, String> connectMap = new HashMap<>();
    connectMap.put("hostname", iServer.getHost());
    connectMap.put("port", String.valueOf(debugPort));
    //			Map argMap = null;//configuration.getAttribute(IJavaLaunchConfigurationConstants.ATTR_CONNECT_MAP, (Map)null);
    int connectTimeout = JavaRuntime.getPreferences().getInt(JavaRuntime.PREF_CONNECT_TIMEOUT);
    //$NON-NLS-1$
    connectMap.put("timeout", Integer.toString(connectTimeout));
    // set the default source locator if required
    @SuppressWarnings("restriction") ISourceLookupDirector sourceLocator = new JavaSourceLookupDirector();
    sourceLocator.setSourcePathComputer(DebugPlugin.getDefault().getLaunchManager().getSourcePathComputer(//$NON-NLS-1$
    "org.eclipse.jdt.launching.sourceLookup.javaSourcePathComputer"));
    List<IRuntimeClasspathEntry> classpathEntries = new ArrayList<>();
    // 1. add java projects first
    for (IJavaProject javaProject : ProjectHelper.getAllJavaProjects()) {
        classpathEntries.add(JavaRuntime.newProjectRuntimeClasspathEntry(javaProject));
    }
    // 2. add the other modules deployed on server
    // 5/30
    ProgressUtils.advance(monitor, 5);
    // 30 - 5 - 1
    int workTicksForReferences = 24;
    SourceReferenceResolver resolver = Activator.getDefault().getSourceReferenceResolver();
    if (resolver != null && configuration.resolveSourcesInDebugMode()) {
        try {
            List<SourceReference> references = osgiClient.findSourceReferences();
            SubMonitor subMonitor = SubMonitor.convert(monitor, "Resolving source references", workTicksForReferences).setWorkRemaining(references.size());
            for (SourceReference reference : references) {
                try {
                    subMonitor.setTaskName("Resolving source reference: " + reference);
                    IRuntimeClasspathEntry classpathEntry = resolver.resolve(reference);
                    if (classpathEntry != null) {
                        classpathEntries.add(classpathEntry);
                    }
                    ProgressUtils.advance(subMonitor, 1);
                } catch (CoreException e) {
                    // don't fail the debug launch for artifact resolution errors
                    Activator.getDefault().getPluginLogger().warn("Failed resolving source reference", e);
                }
            }
            // 29/30
            subMonitor.done();
        } catch (OsgiClientException e1) {
            throw new CoreException(new Status(Status.ERROR, Activator.PLUGIN_ID, e1.getMessage(), e1));
        }
    } else {
        monitor.worked(workTicksForReferences);
    }
    // 3. add the JRE entry
    classpathEntries.add(JavaRuntime.computeJREEntry(launch.getLaunchConfiguration()));
    IRuntimeClasspathEntry[] resolved = JavaRuntime.resolveSourceLookupPath(classpathEntries.toArray(new IRuntimeClasspathEntry[0]), launch.getLaunchConfiguration());
    sourceLocator.setSourceContainers(JavaRuntime.getSourceContainers(resolved));
    sourceLocator.initializeParticipants();
    launch.setSourceLocator(sourceLocator);
    // connect to remote VM
    try {
        // 30/30
        connector.connect(connectMap, monitor, launch);
        success = true;
        long elapsedMillis = System.currentTimeMillis() - start;
        Activator.getDefault().getPluginLogger().tracePerformance("Debug connection to {0}", elapsedMillis, iServer.getName());
    } catch (Exception e) {
        throw new CoreException(new Status(IStatus.ERROR, "org.apache.sling.ide.eclipse.wst", "could not establish debug connection to " + iServer.getHost() + " : " + debugPort, e));
    }
    return success;
}
Also used : HashMap(java.util.HashMap) JavaSourceLookupDirector(org.eclipse.jdt.internal.launching.JavaSourceLookupDirector) ISourceLookupDirector(org.eclipse.debug.core.sourcelookup.ISourceLookupDirector) ArrayList(java.util.ArrayList) SourceReferenceResolver(org.apache.sling.ide.eclipse.core.launch.SourceReferenceResolver) IVMConnector(org.eclipse.jdt.launching.IVMConnector) SourceReference(org.apache.sling.ide.osgi.SourceReference) OsgiClientException(org.apache.sling.ide.osgi.OsgiClientException) ISlingLaunchpadServer(org.apache.sling.ide.eclipse.core.ISlingLaunchpadServer) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) SubMonitor(org.eclipse.core.runtime.SubMonitor) IRuntimeClasspathEntry(org.eclipse.jdt.launching.IRuntimeClasspathEntry) CoreException(org.eclipse.core.runtime.CoreException) DebugException(org.eclipse.debug.core.DebugException) OsgiClientException(org.apache.sling.ide.osgi.OsgiClientException) IJavaProject(org.eclipse.jdt.core.IJavaProject) CoreException(org.eclipse.core.runtime.CoreException) ISlingLaunchpadConfiguration(org.apache.sling.ide.eclipse.core.ISlingLaunchpadConfiguration) ISlingLaunchpadServer(org.apache.sling.ide.eclipse.core.ISlingLaunchpadServer)

Example 90 with Status

use of org.eclipse.core.runtime.Status in project sling by apache.

the class ResourceChangeCommandFactory method normaliseResourceChildren.

/**
     * Normalises the of the specified <tt>resourceProxy</tt> by comparing the serialization data and the filesystem
     * data
     * 
     * @param serializationFile the file which contains the serialization data
     * @param resourceProxy the resource proxy
     * @param syncDirectory the sync directory
     * @param repository TODO
     * @throws CoreException
     */
private void normaliseResourceChildren(IFile serializationFile, ResourceProxy resourceProxy, IFolder syncDirectory, Repository repository) throws CoreException {
    // TODO - this logic should be moved to the serializationManager
    try {
        SerializationKindManager skm = new SerializationKindManager();
        skm.init(repository);
        String primaryType = (String) resourceProxy.getProperties().get(Repository.JCR_PRIMARY_TYPE);
        List<String> mixinTypesList = getMixinTypes(resourceProxy);
        SerializationKind serializationKind = skm.getSerializationKind(primaryType, mixinTypesList);
        if (serializationKind == SerializationKind.METADATA_FULL) {
            return;
        }
    } catch (RepositoryException e) {
        throw new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Failed creating a " + SerializationDataBuilder.class.getName(), e));
    }
    IPath serializationDirectoryPath = serializationFile.getFullPath().removeLastSegments(1);
    Iterator<ResourceProxy> childIterator = resourceProxy.getChildren().iterator();
    Map<String, IResource> extraChildResources = new HashMap<>();
    for (IResource member : serializationFile.getParent().members()) {
        if (member.equals(serializationFile)) {
            continue;
        }
        extraChildResources.put(member.getName(), member);
    }
    while (childIterator.hasNext()) {
        ResourceProxy child = childIterator.next();
        String childName = PathUtil.getName(child.getPath());
        String osPath = serializationManager.getOsPath(childName);
        // covered children might have a FS representation, depending on their child nodes, so
        // accept a directory which maps to their name
        extraChildResources.remove(osPath);
        // covered children do not need a filesystem representation
        if (resourceProxy.covers(child.getPath())) {
            continue;
        }
        IPath childPath = serializationDirectoryPath.append(osPath);
        IResource childResource = ResourcesPlugin.getWorkspace().getRoot().findMember(childPath);
        if (childResource == null) {
            Activator.getDefault().getPluginLogger().trace("For resource at with serialization data {0} the serialized child resource at {1} does not exist in the filesystem and will be ignored", serializationFile, childPath);
            childIterator.remove();
        }
    }
    for (IResource extraChildResource : extraChildResources.values()) {
        IPath extraChildResourcePath = extraChildResource.getFullPath().makeRelativeTo(syncDirectory.getFullPath()).makeAbsolute();
        resourceProxy.addChild(new ResourceProxy(serializationManager.getRepositoryPath(extraChildResourcePath.toPortableString())));
        Activator.getDefault().getPluginLogger().trace("For resource at with serialization data {0} the found a child resource at {1} which is not listed in the serialized child resources and will be added", serializationFile, extraChildResource);
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IPath(org.eclipse.core.runtime.IPath) HashMap(java.util.HashMap) RepositoryException(org.apache.sling.ide.transport.RepositoryException) ResourceProxy(org.apache.sling.ide.transport.ResourceProxy) SerializationKindManager(org.apache.sling.ide.serialization.SerializationKindManager) CoreException(org.eclipse.core.runtime.CoreException) SerializationKind(org.apache.sling.ide.serialization.SerializationKind) IResource(org.eclipse.core.resources.IResource)

Aggregations

Status (org.eclipse.core.runtime.Status)538 IStatus (org.eclipse.core.runtime.IStatus)513 CoreException (org.eclipse.core.runtime.CoreException)248 IOException (java.io.IOException)110 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)84 ArrayList (java.util.ArrayList)62 InvocationTargetException (java.lang.reflect.InvocationTargetException)60 IFile (org.eclipse.core.resources.IFile)54 File (java.io.File)53 MultiStatus (org.eclipse.core.runtime.MultiStatus)43 IResource (org.eclipse.core.resources.IResource)41 IPath (org.eclipse.core.runtime.IPath)41 InputStream (java.io.InputStream)36 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)34 PartInitException (org.eclipse.ui.PartInitException)32 IProject (org.eclipse.core.resources.IProject)31 IConfigurationElement (org.eclipse.core.runtime.IConfigurationElement)25 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)24 SubMonitor (org.eclipse.core.runtime.SubMonitor)24 ITask (com.cubrid.common.core.task.ITask)23