Search in sources :

Example 91 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 92 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 93 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)

Example 94 with Status

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

the class ResourceChangeCommandFactory method buildResourceAndInfo.

/**
     * Convenience method which builds a <tt>ResourceAndInfo</tt> info for a specific <tt>IResource</tt>
     * 
     * @param resource the resource to process
     * @param repository the repository, used to extract serialization information for different resource types
     * @return the build object, or null if one could not be built
     * @throws CoreException
     * @throws SerializationException
     * @throws IOException
     */
public ResourceAndInfo buildResourceAndInfo(IResource resource, Repository repository) throws CoreException, IOException {
    if (ignoredFileNames.contains(resource.getName())) {
        return null;
    }
    Long modificationTimestamp = (Long) resource.getSessionProperty(ResourceUtil.QN_IMPORT_MODIFICATION_TIMESTAMP);
    if (modificationTimestamp != null && modificationTimestamp >= resource.getModificationStamp()) {
        Activator.getDefault().getPluginLogger().trace("Change for resource {0} ignored as the import timestamp {1} >= modification timestamp {2}", resource, modificationTimestamp, resource.getModificationStamp());
        return null;
    }
    if (resource.isTeamPrivateMember(IResource.CHECK_ANCESTORS)) {
        Activator.getDefault().getPluginLogger().trace("Skipping team-private resource {0}", resource);
        return null;
    }
    FileInfo info = createFileInfo(resource);
    Activator.getDefault().getPluginLogger().trace("For {0} built fileInfo {1}", resource, info);
    File syncDirectoryAsFile = ProjectUtil.getSyncDirectoryFullPath(resource.getProject()).toFile();
    IFolder syncDirectory = ProjectUtil.getSyncDirectory(resource.getProject());
    Filter filter = ProjectUtil.loadFilter(resource.getProject());
    ResourceProxy resourceProxy = null;
    if (serializationManager.isSerializationFile(resource.getLocation().toOSString())) {
        IFile file = (IFile) resource;
        try (InputStream contents = file.getContents()) {
            String resourceLocation = file.getFullPath().makeRelativeTo(syncDirectory.getFullPath()).toPortableString();
            resourceProxy = serializationManager.readSerializationData(resourceLocation, contents);
            normaliseResourceChildren(file, resourceProxy, syncDirectory, repository);
            // TODO - not sure if this 100% correct, but we definitely should not refer to the FileInfo as the
            // .serialization file, since for nt:file/nt:resource nodes this will overwrite the file contents
            String primaryType = (String) resourceProxy.getProperties().get(Repository.JCR_PRIMARY_TYPE);
            if (Repository.NT_FILE.equals(primaryType)) {
                // TODO move logic to serializationManager
                File locationFile = new File(info.getLocation());
                String locationFileParent = locationFile.getParent();
                int endIndex = locationFileParent.length() - ".dir".length();
                File actualFile = new File(locationFileParent.substring(0, endIndex));
                String newLocation = actualFile.getAbsolutePath();
                String newName = actualFile.getName();
                String newRelativeLocation = actualFile.getAbsolutePath().substring(syncDirectoryAsFile.getAbsolutePath().length());
                info = new FileInfo(newLocation, newRelativeLocation, newName);
                Activator.getDefault().getPluginLogger().trace("Adjusted original location from {0} to {1}", resourceLocation, newLocation);
            }
        } catch (IOException e) {
            Status s = new Status(Status.WARNING, Activator.PLUGIN_ID, "Failed reading file at " + resource.getFullPath(), e);
            StatusManager.getManager().handle(s, StatusManager.LOG | StatusManager.SHOW);
            return null;
        }
    } else {
        // possible .dir serialization holder
        if (resource.getType() == IResource.FOLDER && resource.getName().endsWith(".dir")) {
            IFolder folder = (IFolder) resource;
            IResource contentXml = folder.findMember(".content.xml");
            // .dir serialization holder ; nothing to process here, the .content.xml will trigger the actual work
            if (contentXml != null && contentXml.exists() && serializationManager.isSerializationFile(contentXml.getLocation().toOSString())) {
                return null;
            }
        }
        resourceProxy = buildResourceProxyForPlainFileOrFolder(resource, syncDirectory, repository);
    }
    FilterResult filterResult = getFilterResult(resource, resourceProxy, filter);
    switch(filterResult) {
        case ALLOW:
            return new ResourceAndInfo(resourceProxy, info);
        case PREREQUISITE:
            // never try to 'create' the root node, we assume it exists
            if (!resourceProxy.getPath().equals("/")) {
                // suited one ( typically nt:unstructured )
                return new ResourceAndInfo(new ResourceProxy(resourceProxy.getPath()), null, true);
            }
        // falls through
        case DENY:
        default:
            return null;
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IFile(org.eclipse.core.resources.IFile) InputStream(java.io.InputStream) IOException(java.io.IOException) ResourceProxy(org.apache.sling.ide.transport.ResourceProxy) FileInfo(org.apache.sling.ide.transport.FileInfo) Filter(org.apache.sling.ide.filter.Filter) FilterResult(org.apache.sling.ide.filter.FilterResult) IFile(org.eclipse.core.resources.IFile) File(java.io.File) IResource(org.eclipse.core.resources.IResource) IFolder(org.eclipse.core.resources.IFolder)

Example 95 with Status

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

the class SlingLaunchpadBehaviour method publishContentModule.

private void publishContentModule(int kind, int deltaKind, IModule[] module, IProgressMonitor monitor) throws CoreException, SerializationException, IOException {
    Logger logger = Activator.getDefault().getPluginLogger();
    Repository repository = ServerUtil.getConnectedRepository(getServer(), monitor);
    if (repository == null) {
        throw new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Unable to find a repository for server " + getServer()));
    }
    Batcher batcher = Activator.getDefault().getBatcherFactory().createBatcher();
    // TODO it would be more efficient to have a module -> filter mapping
    // it would be simpler to implement this in SlingContentModuleAdapter, but
    // the behaviour for resources being filtered out is deletion, and that
    // would be an incorrect ( or at least suprising ) behaviour at development time
    List<IModuleResource> addedOrUpdatedResources = new ArrayList<>();
    IModuleResource[] allResources = getResources(module);
    Set<IPath> handledPaths = new HashSet<>();
    switch(deltaKind) {
        case ServerBehaviourDelegate.CHANGED:
            for (IModuleResourceDelta resourceDelta : getPublishedResourceDelta(module)) {
                StringBuilder deltaTrace = new StringBuilder();
                deltaTrace.append("- processing delta kind ");
                switch(resourceDelta.getKind()) {
                    case IModuleResourceDelta.ADDED:
                        deltaTrace.append("ADDED ");
                        break;
                    case IModuleResourceDelta.CHANGED:
                        deltaTrace.append("CHANGED ");
                        break;
                    case IModuleResourceDelta.NO_CHANGE:
                        deltaTrace.append("NO_CHANGE ");
                        break;
                    case IModuleResourceDelta.REMOVED:
                        deltaTrace.append("REMOVED ");
                        break;
                    default:
                        deltaTrace.append("UNKNOWN - ").append(resourceDelta.getKind());
                }
                deltaTrace.append("for resource ").append(resourceDelta.getModuleResource());
                logger.trace(deltaTrace.toString());
                switch(resourceDelta.getKind()) {
                    case IModuleResourceDelta.ADDED:
                    case IModuleResourceDelta.CHANGED:
                    case // TODO is this needed?
                    IModuleResourceDelta.NO_CHANGE:
                        Command<?> command = addFileCommand(repository, resourceDelta.getModuleResource());
                        if (command != null) {
                            ensureParentIsPublished(resourceDelta.getModuleResource(), repository, allResources, handledPaths, batcher);
                            addedOrUpdatedResources.add(resourceDelta.getModuleResource());
                        }
                        enqueue(batcher, command);
                        break;
                    case IModuleResourceDelta.REMOVED:
                        enqueue(batcher, removeFileCommand(repository, resourceDelta.getModuleResource()));
                        break;
                }
            }
            break;
        case ServerBehaviourDelegate.ADDED:
        case // TODO is this correct ?
        ServerBehaviourDelegate.NO_CHANGE:
            for (IModuleResource resource : getResources(module)) {
                Command<?> command = addFileCommand(repository, resource);
                enqueue(batcher, command);
                if (command != null) {
                    addedOrUpdatedResources.add(resource);
                }
            }
            break;
        case ServerBehaviourDelegate.REMOVED:
            for (IModuleResource resource : getResources(module)) {
                enqueue(batcher, removeFileCommand(repository, resource));
            }
            break;
    }
    // reorder the child nodes at the end, when all create/update/deletes have been processed
    for (IModuleResource resource : addedOrUpdatedResources) {
        enqueue(batcher, reorderChildNodesCommand(repository, resource));
    }
    execute(batcher);
    // set state to published
    super.publishModule(kind, deltaKind, module, monitor);
    setModulePublishState(module, IServer.PUBLISH_STATE_NONE);
//        setServerPublishState(IServer.PUBLISH_STATE_NONE);
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IModuleResource(org.eclipse.wst.server.core.model.IModuleResource) IPath(org.eclipse.core.runtime.IPath) ArrayList(java.util.ArrayList) IModuleResourceDelta(org.eclipse.wst.server.core.model.IModuleResourceDelta) Logger(org.apache.sling.ide.log.Logger) Repository(org.apache.sling.ide.transport.Repository) CoreException(org.eclipse.core.runtime.CoreException) Batcher(org.apache.sling.ide.transport.Batcher) HashSet(java.util.HashSet)

Aggregations

Status (org.eclipse.core.runtime.Status)305 IStatus (org.eclipse.core.runtime.IStatus)282 CoreException (org.eclipse.core.runtime.CoreException)132 IOException (java.io.IOException)66 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)64 InvocationTargetException (java.lang.reflect.InvocationTargetException)40 File (java.io.File)38 ArrayList (java.util.ArrayList)37 IFile (org.eclipse.core.resources.IFile)37 MultiStatus (org.eclipse.core.runtime.MultiStatus)30 IResource (org.eclipse.core.resources.IResource)27 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)26 IProject (org.eclipse.core.resources.IProject)24 IPath (org.eclipse.core.runtime.IPath)24 ITask (com.cubrid.common.core.task.ITask)23 PartInitException (org.eclipse.ui.PartInitException)23 InputStream (java.io.InputStream)18 GridData (org.eclipse.swt.layout.GridData)17 GridLayout (org.eclipse.swt.layout.GridLayout)17 Composite (org.eclipse.swt.widgets.Composite)16