use of org.apache.sling.ide.log.Logger in project sling by apache.
the class SlingLaunchpadBehaviour method ensureParentIsPublished.
/**
* Ensures that the parent of this resource has been published to the repository
*
* <p>
* Note that the parents explicitly do not have their child nodes reordered, this will happen when they are
* published due to a resource change
* </p>
*
* @param moduleResource the current resource
* @param repository the repository to publish to
* @param allResources all of the module's resources
* @param handledPaths the paths that have been handled already in this publish operation, but possibly not
* registered as published
* @param batcher
* @throws IOException
* @throws SerializationException
* @throws CoreException
*/
private void ensureParentIsPublished(IModuleResource moduleResource, Repository repository, IModuleResource[] allResources, Set<IPath> handledPaths, Batcher batcher) throws CoreException, SerializationException, IOException {
Logger logger = Activator.getDefault().getPluginLogger();
IPath currentPath = moduleResource.getModuleRelativePath();
logger.trace("Ensuring that parent of path {0} is published", currentPath);
// we assume the root is always published
if (currentPath.segmentCount() == 0) {
logger.trace("Path {0} can not have a parent, skipping", currentPath);
return;
}
IPath parentPath = currentPath.removeLastSegments(1);
// already published by us, a parent of another resource that was published in this execution
if (handledPaths.contains(parentPath)) {
logger.trace("Parent path {0} was already handled, skipping", parentPath);
return;
}
for (IModuleResource maybeParent : allResources) {
if (maybeParent.getModuleRelativePath().equals(parentPath)) {
// handle the parent's parent first, if needed
ensureParentIsPublished(maybeParent, repository, allResources, handledPaths, batcher);
// create this resource
enqueue(batcher, addFileCommand(repository, maybeParent));
handledPaths.add(maybeParent.getModuleRelativePath());
logger.trace("Ensured that resource at path {0} is published", parentPath);
return;
}
}
throw new IllegalArgumentException("Resource at " + moduleResource.getModuleRelativePath() + " has parent path " + parentPath + " but no resource with that path is in the module's resources.");
}
use of org.apache.sling.ide.log.Logger 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);
}
use of org.apache.sling.ide.log.Logger in project sling by apache.
the class PluginLoggerRegistrar method register.
/**
* Registers a new tracer for the specified plugin
*
* @param plugin the plugin to register for
* @return the service registration
*/
public static ServiceRegistration<Logger> register(Plugin plugin) {
Dictionary<String, Object> props = new Hashtable<>();
props.put(DebugOptions.LISTENER_SYMBOLICNAME, plugin.getBundle().getSymbolicName());
BundleContext ctx = plugin.getBundle().getBundleContext();
// safe to downcast since we are registering the Tracer which implements Logger
@SuppressWarnings("unchecked") ServiceRegistration<Logger> serviceRegistration = (ServiceRegistration<Logger>) ctx.registerService(new String[] { DebugOptionsListener.class.getName(), Logger.class.getName() }, new Tracer(plugin), props);
return serviceRegistration;
}
use of org.apache.sling.ide.log.Logger in project sling by apache.
the class SlingLaunchpadBehaviour method publishModule.
@Override
protected void publishModule(int kind, int deltaKind, IModule[] module, IProgressMonitor monitor) throws CoreException {
Logger logger = Activator.getDefault().getPluginLogger();
if (commandFactory == null) {
commandFactory = new ResourceChangeCommandFactory(Activator.getDefault().getSerializationManager(), Activator.getDefault().getPreferences().getIgnoredFileNamesForSync());
}
logger.trace(traceOperation(kind, deltaKind, module));
if (getServer().getServerState() == IServer.STATE_STOPPED) {
logger.trace("Ignoring request to publish module when the server is stopped");
setModulePublishState(module, IServer.PUBLISH_STATE_NONE);
return;
}
if ((kind == IServer.PUBLISH_AUTO || kind == IServer.PUBLISH_INCREMENTAL) && deltaKind == ServerBehaviourDelegate.NO_CHANGE) {
logger.trace("Ignoring request to publish the module when no resources have changed; most likely another module has changed");
setModulePublishState(module, IServer.PUBLISH_STATE_NONE);
return;
}
if (kind == IServer.PUBLISH_FULL && deltaKind == ServerBehaviourDelegate.REMOVED) {
logger.trace("Ignoring request to unpublish all of the module resources");
setModulePublishState(module, IServer.PUBLISH_STATE_NONE);
return;
}
try {
if (ProjectHelper.isBundleProject(module[0].getProject())) {
String serverMode = getServer().getMode();
if (!serverMode.equals(ILaunchManager.DEBUG_MODE) || kind == IServer.PUBLISH_CLEAN) {
// in debug mode, we rely on the hotcode replacement feature of eclipse/jvm
// otherwise, for run and profile modes we explicitly publish the bundle module
// TODO: make this configurable as part of the server config
// SLING-3655 : when doing PUBLISH_CLEAN, the bundle deployment mechanism should
// still be triggered
publishBundleModule(module, monitor);
}
} else if (ProjectHelper.isContentProject(module[0].getProject())) {
try {
publishContentModule(kind, deltaKind, module, monitor);
} catch (SerializationException e) {
throw new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "Serialization error for " + traceOperation(kind, deltaKind, module).toString(), e));
} catch (IOException e) {
throw new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "IO error for " + traceOperation(kind, deltaKind, module).toString(), e));
}
}
} catch (CoreException e) {
// in case of errors always require full redeployment of the whole module
setModulePublishState(module, IServer.PUBLISH_STATE_FULL);
throw e;
}
}
use of org.apache.sling.ide.log.Logger in project sling by apache.
the class SightlyFacetInstallDelegate method execute.
@Override
public void execute(IProject project, IProjectFacetVersion version, Object config, IProgressMonitor monitor) throws CoreException {
Logger logger = Activator.getDefault().getLogger();
Validator[] validators = ValManager.getDefault().getValidators(project);
ValidatorMutable[] mutis = new ValidatorMutable[validators.length];
for (int i = 0; i < validators.length; i++) {
mutis[i] = new ValidatorMutable(validators[i]);
}
boolean changed = false;
for (ValidatorMutable validator : mutis) {
if (HTML_VALIDATOR_ID.equals(validator.getId())) {
if (validator.isManualValidation() || validator.isBuildValidation()) {
validator.setBuildValidation(false);
validator.setManualValidation(false);
changed = true;
logger.trace("Disabled {0} for project {1}", validator, project.getName());
break;
}
}
}
ProjectPreferences projectPreferences = ValManager.getDefault().getProjectPreferences(project);
if (!projectPreferences.getOverride()) {
projectPreferences = new ProjectPreferences(project, true, projectPreferences.getSuspend(), null);
}
if (changed || !projectPreferences.getOverride()) {
ValPrefManagerProject prefManager = new ValPrefManagerProject(project);
prefManager.savePreferences(projectPreferences, mutis);
}
}
Aggregations