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