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;
}
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);
}
}
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;
}
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;
}
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);
}
}
Aggregations