diff --git a/bundle/src/main/java/com/cognifide/cq/cqsm/api/actions/ActionFactory.java b/bundle/src/main/java/com/cognifide/cq/cqsm/api/actions/ActionFactory.java index 7058e785c..e3bc9d69a 100644 --- a/bundle/src/main/java/com/cognifide/cq/cqsm/api/actions/ActionFactory.java +++ b/bundle/src/main/java/com/cognifide/cq/cqsm/api/actions/ActionFactory.java @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -20,16 +20,13 @@ package com.cognifide.cq.cqsm.api.actions; import com.cognifide.cq.cqsm.api.exceptions.ActionCreationException; - import java.util.List; import java.util.Map; public interface ActionFactory { - ActionDescriptor evaluate(final String parameters) throws ActionCreationException; - - boolean update(); + ActionDescriptor evaluate(final String parameters) throws ActionCreationException; - List> refer(); + List> refer(); } diff --git a/bundle/src/main/java/com/cognifide/cq/cqsm/core/actions/ActionFactoryImpl.java b/bundle/src/main/java/com/cognifide/cq/cqsm/core/actions/ActionFactoryImpl.java index d3c3d6e8c..2d53eab1b 100644 --- a/bundle/src/main/java/com/cognifide/cq/cqsm/core/actions/ActionFactoryImpl.java +++ b/bundle/src/main/java/com/cognifide/cq/cqsm/core/actions/ActionFactoryImpl.java @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -23,23 +23,9 @@ import com.cognifide.cq.cqsm.api.actions.ActionDescriptor; import com.cognifide.cq.cqsm.api.actions.ActionFactory; import com.cognifide.cq.cqsm.api.actions.ActionMapper; -import com.cognifide.cq.cqsm.api.actions.annotations.Mapper; import com.cognifide.cq.cqsm.api.actions.annotations.Mapping; import com.cognifide.cq.cqsm.api.exceptions.ActionCreationException; import com.cognifide.cq.cqsm.core.Cqsm; -import com.cognifide.cq.cqsm.core.actions.scanner.AnnotatedClassRegistry; - -import org.apache.felix.scr.annotations.Activate; -import org.apache.felix.scr.annotations.Component; -import org.apache.felix.scr.annotations.Deactivate; -import org.apache.felix.scr.annotations.Properties; -import org.apache.felix.scr.annotations.Property; -import org.apache.felix.scr.annotations.Service; -import org.osgi.framework.Constants; -import org.osgi.service.component.ComponentContext; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.lang.reflect.Type; @@ -51,161 +37,122 @@ import java.util.Map; import java.util.regex.Matcher; import java.util.regex.Pattern; +import org.apache.felix.scr.annotations.Component; +import org.apache.felix.scr.annotations.Properties; +import org.apache.felix.scr.annotations.Property; +import org.apache.felix.scr.annotations.Reference; +import org.apache.felix.scr.annotations.Service; +import org.osgi.framework.Constants; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; @Component(immediate = true) @Service -@Properties({@Property(name = Constants.SERVICE_DESCRIPTION, value = "Action factory service"), - @Property(name = Constants.SERVICE_VENDOR, value = Cqsm.VENDOR_NAME)}) +@Properties({ + @Property(name = Constants.SERVICE_DESCRIPTION, value = "Action factory service"), + @Property(name = Constants.SERVICE_VENDOR, value = Cqsm.VENDOR_NAME) +}) public class ActionFactoryImpl implements ActionFactory { - private static final Logger LOG = LoggerFactory.getLogger(ActionFactoryImpl.class); - - private static final String BUNDLE_HEADER = "CQ-Security-Management-Actions"; - - private AnnotatedClassRegistry registry; - - private List mappers = Collections.synchronizedList(new ArrayList<>()); - - private boolean updated = false; - - @Activate - public void activate(ComponentContext componentContext) { - registry = new AnnotatedClassRegistry(componentContext.getBundleContext(), BUNDLE_HEADER, - Mapper.class); - registry.open(); - } - - @Deactivate - public void deactivate() { - if (registry != null) { - registry.close(); - } - } - - @Override - public ActionDescriptor evaluate(String command) throws ActionCreationException { - for (Object mapper : getMappers()) { - for (Method method : mapper.getClass().getDeclaredMethods()) { - if (!method.isAnnotationPresent(Mapping.class)) { - continue; - } - - final Mapping annotation = method.getAnnotation(Mapping.class); - - for (final String regex : annotation.value()) { - final Pattern pattern = Pattern.compile("^" + regex + "$"); - final Matcher matcher = pattern.matcher(command); - - if (matcher.matches()) { - final List args = new ArrayList<>(); - final List rawArgs = new ArrayList<>(); - final Type[] parameterTypes = method.getGenericParameterTypes(); - - for (int i = 1; i <= matcher.groupCount(); i++) { - rawArgs.add(matcher.group(i)); - - if (mapper instanceof ActionMapper) { - args.add(((ActionMapper) mapper) - .mapParameter(matcher.group(i), parameterTypes[i - 1])); - } else { - args.add(matcher.group(i)); - } - } - - try { - return new ActionDescriptor(command, - (Action) method.invoke(mapper, args.toArray()), rawArgs); - } catch (IllegalAccessException e) { - LOG.error("Cannot access action mapper method: {} while processing command: {}", - e.getMessage(), command); - } catch (InvocationTargetException e) { - LOG.error("Cannot invoke action mapper method: {} while processing command: {}", - e.getMessage(), command); - } - } - } - } - } - - throw new ActionCreationException(String.format("Cannot find action for command: %s", command)); - } - - @Override - public synchronized boolean update() { - if (registry == null) { - LOG.error("Cannot update action factory (bundle not activated)"); - - return false; - } - - final List> classes = registry.getClasses(); - - mappers.clear(); - for (Class clazz : classes) { - try { - mappers.add(clazz.newInstance()); - } catch (InstantiationException e) { - LOG.error("Cannot instantiate action mapper: {}", e.getMessage()); - } catch (IllegalAccessException e) { - LOG.error("Cannot construct action mapper, is constructor non public? {}", e.getMessage()); - } - } - - if (LOG.isDebugEnabled()) { - LOG.debug("Created {} action mappers from {} classes", mappers.size(), classes.size()); - } - - return true; - } - - @Override - public List> refer() { - final List> references = new ArrayList<>(); - - for (Object mapper : getMappers()) { - for (Method method : mapper.getClass().getDeclaredMethods()) { - if (!method.isAnnotationPresent(Mapping.class) || !(mapper instanceof ActionMapper)) { - continue; - } - - final Mapping mapping = method.getAnnotation(Mapping.class); - final List commands = ((ActionMapper) mapper).referMapping(mapping); - - HashMap reference = new HashMap<>(); - reference.put("commands", commands); - reference.put("pattern", mapping.value()); - reference.put("args", mapping.args()); - reference.put("reference", mapping.reference()); - - references.add(reference); - } - } - - sortReferences(references); - - return references; - } - - private void sortReferences(List> references) { - Collections.sort(references, new Comparator>() { - @Override - public int compare(Map object1, Map object2) { - List commands1 = (List) object1.get("commands"); - List commands2 = (List) object2.get("commands"); - String command1 = commands1.get(0); - String command2 = commands2.get(0); - return command1.compareToIgnoreCase(command2); - } - }); - } - - protected synchronized List getMappers() { - if (!updated) { - update(); - updated = true; - } - - return mappers; - } - + private static final Logger LOG = LoggerFactory.getLogger(ActionFactoryImpl.class); + + @Reference + private ActionMapperRegistry registry; + + @Override + public ActionDescriptor evaluate(String command) throws ActionCreationException { + for (Object mapper : registry.getMappers()) { + ActionDescriptor descriptor = tryToEvaluateCommand(mapper, command); + if (descriptor != null) { + return descriptor; + } + } + + throw new ActionCreationException(String.format("Cannot find action for command: %s", command)); + } + + private ActionDescriptor tryToEvaluateCommand(Object mapper, String command) throws ActionCreationException { + for (Method method : mapper.getClass().getDeclaredMethods()) { + if (!method.isAnnotationPresent(Mapping.class)) { + continue; + } + + final Mapping annotation = method.getAnnotation(Mapping.class); + + for (final String regex : annotation.value()) { + final Pattern pattern = Pattern.compile("^" + regex + "$"); + final Matcher matcher = pattern.matcher(command); + + if (matcher.matches()) { + final List args = new ArrayList<>(); + final List rawArgs = new ArrayList<>(); + final Type[] parameterTypes = method.getGenericParameterTypes(); + + for (int i = 1; i <= matcher.groupCount(); i++) { + rawArgs.add(matcher.group(i)); + + if (mapper instanceof ActionMapper) { + args.add(((ActionMapper) mapper) + .mapParameter(matcher.group(i), parameterTypes[i - 1])); + } else { + args.add(matcher.group(i)); + } + } + + try { + return new ActionDescriptor(command, + (Action) method.invoke(mapper, args.toArray()), rawArgs); + } catch (IllegalAccessException e) { + LOG.error("Cannot access action mapper method: {} while processing command: {}", + e.getMessage(), command); + } catch (InvocationTargetException e) { + LOG.error("Cannot invoke action mapper method: {} while processing command: {}", + e.getMessage(), command); + } + } + } + } + return null; + } + + @Override + public List> refer() { + final List> references = new ArrayList<>(); + + for (Object mapper : registry.getMappers()) { + for (Method method : mapper.getClass().getDeclaredMethods()) { + if (!method.isAnnotationPresent(Mapping.class) || !(mapper instanceof ActionMapper)) { + continue; + } + + final Mapping mapping = method.getAnnotation(Mapping.class); + final List commands = ((ActionMapper) mapper).referMapping(mapping); + + HashMap reference = new HashMap<>(); + reference.put("commands", commands); + reference.put("pattern", mapping.value()); + reference.put("args", mapping.args()); + reference.put("reference", mapping.reference()); + + references.add(reference); + } + } + + sortReferences(references); + + return references; + } + + private void sortReferences(List> references) { + Collections.sort(references, new Comparator>() { + @Override + public int compare(Map object1, Map object2) { + List commands1 = (List) object1.get("commands"); + List commands2 = (List) object2.get("commands"); + String command1 = commands1.get(0); + String command2 = commands2.get(0); + return command1.compareToIgnoreCase(command2); + } + }); + } } diff --git a/bundle/src/main/java/com/cognifide/cq/cqsm/core/actions/ActionMapperRegistry.java b/bundle/src/main/java/com/cognifide/cq/cqsm/core/actions/ActionMapperRegistry.java new file mode 100644 index 000000000..934841ea0 --- /dev/null +++ b/bundle/src/main/java/com/cognifide/cq/cqsm/core/actions/ActionMapperRegistry.java @@ -0,0 +1,28 @@ +/* + * ========================LICENSE_START================================= + * AEM Permission Management + * %% + * Copyright (C) 2013 Cognifide Limited + * %% + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * =========================LICENSE_END================================== + */ + +package com.cognifide.cq.cqsm.core.actions; + +import java.util.List; + +public interface ActionMapperRegistry { + + List getMappers(); +} diff --git a/bundle/src/main/java/com/cognifide/cq/cqsm/core/actions/ActionMapperRegistryImpl.java b/bundle/src/main/java/com/cognifide/cq/cqsm/core/actions/ActionMapperRegistryImpl.java new file mode 100644 index 000000000..dc24e7106 --- /dev/null +++ b/bundle/src/main/java/com/cognifide/cq/cqsm/core/actions/ActionMapperRegistryImpl.java @@ -0,0 +1,100 @@ +/* + * ========================LICENSE_START================================= + * AEM Permission Management + * %% + * Copyright (C) 2013 Cognifide Limited + * %% + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * =========================LICENSE_END================================== + */ + +package com.cognifide.cq.cqsm.core.actions; + +import com.cognifide.cq.cqsm.api.actions.annotations.Mapper; +import com.cognifide.cq.cqsm.core.Cqsm; +import com.cognifide.cq.cqsm.core.actions.scanner.AnnotatedClassRegistry; +import com.cognifide.cq.cqsm.core.actions.scanner.RegistryChangedListener; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.Lists; +import java.util.Collections; +import java.util.List; +import java.util.concurrent.atomic.AtomicReference; +import org.apache.felix.scr.annotations.Activate; +import org.apache.felix.scr.annotations.Component; +import org.apache.felix.scr.annotations.Deactivate; +import org.apache.felix.scr.annotations.Properties; +import org.apache.felix.scr.annotations.Property; +import org.apache.felix.scr.annotations.Service; +import org.osgi.framework.Constants; +import org.osgi.service.component.ComponentContext; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +@Component(immediate = true) +@Service(ActionMapperRegistry.class) +@Properties({ + @Property(name = Constants.SERVICE_DESCRIPTION, value = "Action mapper registry service"), + @Property(name = Constants.SERVICE_VENDOR, value = Cqsm.VENDOR_NAME) +}) +public class ActionMapperRegistryImpl implements RegistryChangedListener, ActionMapperRegistry { + + private static final Logger LOG = LoggerFactory.getLogger(ActionMapperRegistryImpl.class); + + private static final String BUNDLE_HEADER = "CQ-Security-Management-Actions"; + + private AnnotatedClassRegistry registry; + + private volatile AtomicReference> mappers = new AtomicReference<>(Collections.emptyList()); + + @Activate + public void activate(ComponentContext componentContext) { + registry = new AnnotatedClassRegistry(componentContext.getBundleContext(), BUNDLE_HEADER, Mapper.class); + registry.addChangeListener(this); + registry.open(); + } + + @Deactivate + public void deactivate() { + if (registry != null) { + registry.close(); + } + } + + @Override + public void registryChanged(List> registeredClasses) { + this.mappers.set(ImmutableList.copyOf(createActionMappers(registeredClasses))); + } + + @Override + public List getMappers() { + return mappers.get(); + } + + private static List createActionMappers(List> classes) { + List mappers = Lists.newArrayListWithExpectedSize(classes.size()); + for (Class clazz : classes) { + try { + mappers.add(clazz.newInstance()); + } catch (InstantiationException e) { + LOG.error("Cannot instantiate action mapper: {}", e.getMessage()); + } catch (IllegalAccessException e) { + LOG.error("Cannot construct action mapper, is constructor non public? {}", e.getMessage()); + } + } + + if (LOG.isDebugEnabled()) { + LOG.debug("Created {} action mappers from {} classes", mappers.size(), classes.size()); + } + return mappers; + } +} diff --git a/bundle/src/main/java/com/cognifide/cq/cqsm/core/actions/scanner/AnnotatedClassRegistry.java b/bundle/src/main/java/com/cognifide/cq/cqsm/core/actions/scanner/AnnotatedClassRegistry.java index 996208ad2..f88589f16 100644 --- a/bundle/src/main/java/com/cognifide/cq/cqsm/core/actions/scanner/AnnotatedClassRegistry.java +++ b/bundle/src/main/java/com/cognifide/cq/cqsm/core/actions/scanner/AnnotatedClassRegistry.java @@ -7,9 +7,9 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -19,6 +19,14 @@ */ package com.cognifide.cq.cqsm.core.actions.scanner; +import com.google.common.collect.ImmutableList; +import java.lang.annotation.Annotation; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; import org.osgi.framework.Bundle; import org.osgi.framework.BundleContext; import org.osgi.framework.BundleEvent; @@ -27,96 +35,103 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.lang.annotation.Annotation; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; - /** * Aggregator for classes with specified annotation

When bundle is state is changed (added, removed, * modified), then it is executed class scanner which looks for classes with prefixes specified in bundle * header */ -public class AnnotatedClassRegistry implements BundleTrackerCustomizer { - - private static final Logger LOG = LoggerFactory.getLogger(AnnotatedClassRegistry.class); - - private final BundleTracker tracker; - - private final Map>> classes = new ConcurrentHashMap<>(); - - private final Class annotationClass; - - private final String bundleHeader; - - private final BundleContext bundleContext; - - public AnnotatedClassRegistry(BundleContext bundleContext, String bundleHeader, - Class annotationClass) { - this.bundleContext = bundleContext; - this.bundleHeader = bundleHeader; - this.annotationClass = annotationClass; - - tracker = new BundleTracker(bundleContext, Bundle.RESOLVED | Bundle.ACTIVE, this); - } - - @Override - public Object addingBundle(Bundle bundle, BundleEvent event) { - final List> scanned = new ClassScanner(bundle, bundleContext) - .findClasses(bundleHeader, annotationClass); - - if (scanned.size() > 0) { - if (LOG.isDebugEnabled()) { - LOG.debug("Adding classes ({}) from bundle: {}", scanned.size(), bundle.getSymbolicName()); - } - - classes.put(bundle.getBundleId(), scanned); - } - - return null; - } - - @Override - public void modifiedBundle(Bundle bundle, BundleEvent event, Object object) { - final List> scanned = new ClassScanner(bundle, bundleContext) - .findClasses(bundleHeader, annotationClass); - - classes.remove(bundle.getBundleId()); - if (scanned.size() > 0) { - if (LOG.isDebugEnabled()) { - LOG.debug("Updating classes ({}) from bundle: {}", scanned.size(), bundle.getSymbolicName()); - } - - classes.put(bundle.getBundleId(), scanned); - } - } - - @Override - public void removedBundle(Bundle bundle, BundleEvent event, Object object) { - final List> registered = classes.get(bundle.getBundleId()); - - if (LOG.isDebugEnabled()) { - LOG.debug("Removing classes ({}) from bundle: {}", registered.size(), bundle.getSymbolicName()); - } - - classes.remove(bundle.getBundleId()); - } - - public synchronized List> getClasses() { - List> flattened = new ArrayList<>(); - for (Map.Entry>> entry : classes.entrySet()) { - flattened.addAll(entry.getValue()); - } - - return flattened; - } - - public void open() { - tracker.open(); - } - - public void close() { - tracker.close(); - } +public class AnnotatedClassRegistry { + + private static final Logger LOG = LoggerFactory.getLogger(AnnotatedClassRegistry.class); + + private final BundleTracker tracker; + + private final Map>> classes = new ConcurrentHashMap<>(); + + private final Class annotationClass; + + private final String bundleHeader; + + private final BundleContext bundleContext; + + private final Set listeners = new HashSet<>(); + + public AnnotatedClassRegistry(final BundleContext bundleContext, final String bundleHeader, + final Class annotationClass) { + this.bundleContext = bundleContext; + this.bundleHeader = bundleHeader; + this.annotationClass = annotationClass; + + this.tracker = new BundleTracker(bundleContext, Bundle.ACTIVE, new BundleTrackerCustomizer() { + + @Override + public Bundle addingBundle(Bundle bundle, BundleEvent bundleEvent) { + if (null != bundle.getHeaders().get(bundleHeader)) { + registerClasses(bundle); + return bundle; + } + return null; + } + + @Override + public void modifiedBundle(Bundle bundle, BundleEvent bundleEvent, Bundle bundle2) { + //do nothing + } + + @Override + public void removedBundle(Bundle bundle, BundleEvent bundleEvent, Bundle bundle2) { + unregisterClasses(bundle); + } + + }); + } + + public void addChangeListener(RegistryChangedListener changeListener) { + this.listeners.add(changeListener); + } + + public List> getClasses() { + List> flattened = new ArrayList<>(); + for (Map.Entry>> entry : classes.entrySet()) { + flattened.addAll(entry.getValue()); + } + + return ImmutableList.copyOf(flattened); + } + + private void registerClasses(Bundle bundle) { + final List> scanned = new ClassScanner(bundle, bundleContext) + .findClasses(bundleHeader, annotationClass); + if (scanned.size() > 0) { + classes.put(bundle.getBundleId(), scanned); + notifyChangeListeners(); + } + if (LOG.isDebugEnabled()) { + LOG.debug("Adding classes ({}) from bundle: {}", scanned.size(), bundle.getSymbolicName()); + } + } + + private void unregisterClasses(Bundle bundle) { + final List> registered = classes.get(bundle.getBundleId()); + if (LOG.isDebugEnabled()) { + LOG.debug("Removing classes ({}) from bundle: {}", registered.size(), bundle.getSymbolicName()); + } + classes.remove(bundle.getBundleId()); + notifyChangeListeners(); + } + + private void notifyChangeListeners() { + List> classes = getClasses(); + for (RegistryChangedListener listener : listeners) { + listener.registryChanged(classes); + } + } + + public void open() { + tracker.open(); + } + + public void close() { + tracker.close(); + } } diff --git a/bundle/src/main/java/com/cognifide/cq/cqsm/core/actions/scanner/RegistryChangedListener.java b/bundle/src/main/java/com/cognifide/cq/cqsm/core/actions/scanner/RegistryChangedListener.java new file mode 100644 index 000000000..13b0e724b --- /dev/null +++ b/bundle/src/main/java/com/cognifide/cq/cqsm/core/actions/scanner/RegistryChangedListener.java @@ -0,0 +1,28 @@ +/* + * ========================LICENSE_START================================= + * AEM Permission Management + * %% + * Copyright (C) 2013 Cognifide Limited + * %% + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * =========================LICENSE_END================================== + */ + +package com.cognifide.cq.cqsm.core.actions.scanner; + +import java.util.List; + +public interface RegistryChangedListener { + + void registryChanged(List> registeredClasses); +} diff --git a/bundle/src/main/java/com/cognifide/cq/cqsm/core/scripts/ScriptManagerImpl.java b/bundle/src/main/java/com/cognifide/cq/cqsm/core/scripts/ScriptManagerImpl.java index 300d52841..e9f546526 100644 --- a/bundle/src/main/java/com/cognifide/cq/cqsm/core/scripts/ScriptManagerImpl.java +++ b/bundle/src/main/java/com/cognifide/cq/cqsm/core/scripts/ScriptManagerImpl.java @@ -19,8 +19,6 @@ */ package com.cognifide.cq.cqsm.core.scripts; -import com.google.common.collect.Maps; - import com.cognifide.cq.cqsm.api.actions.Action; import com.cognifide.cq.cqsm.api.actions.ActionDescriptor; import com.cognifide.cq.cqsm.api.actions.ActionFactory; @@ -46,21 +44,7 @@ import com.cognifide.cq.cqsm.core.progress.ProgressImpl; import com.cognifide.cq.cqsm.core.sessions.SessionSavingMode; import com.cognifide.cq.cqsm.core.sessions.SessionSavingPolicy; - -import org.apache.commons.io.IOUtils; -import org.apache.commons.io.LineIterator; -import org.apache.felix.scr.annotations.Component; -import org.apache.felix.scr.annotations.Properties; -import org.apache.felix.scr.annotations.Property; -import org.apache.felix.scr.annotations.Reference; -import org.apache.felix.scr.annotations.Service; -import org.apache.jackrabbit.api.JackrabbitSession; -import org.apache.sling.api.resource.PersistenceException; -import org.apache.sling.api.resource.ResourceResolver; -import org.osgi.framework.Constants; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - +import com.google.common.collect.Maps; import java.io.ByteArrayInputStream; import java.io.InputStream; import java.io.StringReader; @@ -73,9 +57,21 @@ import java.util.List; import java.util.Map; import java.util.TreeMap; - import javax.jcr.RepositoryException; import javax.jcr.Session; +import org.apache.commons.io.IOUtils; +import org.apache.commons.io.LineIterator; +import org.apache.felix.scr.annotations.Component; +import org.apache.felix.scr.annotations.Properties; +import org.apache.felix.scr.annotations.Property; +import org.apache.felix.scr.annotations.Reference; +import org.apache.felix.scr.annotations.Service; +import org.apache.jackrabbit.api.JackrabbitSession; +import org.apache.sling.api.resource.PersistenceException; +import org.apache.sling.api.resource.ResourceResolver; +import org.osgi.framework.Constants; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; @Component @Service @@ -110,7 +106,6 @@ private Progress execute(Script script, final Mode mode, Map cus final String path = script.getPath(); - actionFactory.update(); LOG.info(String.format("Script execution started: %s [%s]", path, mode)); Progress progress = new ProgressImpl(resolver.getUserID()); final List descriptors = parseAllDescriptors(script, customDefinitions, resolver); diff --git a/bundle/src/test/java/com/cognifide/cq/cqsm/core/actions/ActionFactoryImplTest.java b/bundle/src/test/java/com/cognifide/cq/cqsm/core/actions/ActionFactoryImplTest.java index 2c304f37f..f9f43f1f6 100644 --- a/bundle/src/test/java/com/cognifide/cq/cqsm/core/actions/ActionFactoryImplTest.java +++ b/bundle/src/test/java/com/cognifide/cq/cqsm/core/actions/ActionFactoryImplTest.java @@ -23,29 +23,18 @@ import static org.mockito.Matchers.anyString; import static org.mockito.Mockito.when; -import java.util.ArrayList; -import java.util.Arrays; - -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; -import org.mockito.Mockito; - import com.cognifide.cq.cqsm.api.exceptions.ActionCreationException; import com.cognifide.cq.cqsm.foundation.actions.addtogroup.AddToGroup; -import com.cognifide.cq.cqsm.foundation.actions.addtogroup.AddToGroupMapper; import com.cognifide.cq.cqsm.foundation.actions.allow.Allow; -import com.cognifide.cq.cqsm.foundation.actions.allow.AllowMapper; import com.cognifide.cq.cqsm.foundation.actions.createauthorizable.CreateAuthorizable; -import com.cognifide.cq.cqsm.foundation.actions.createauthorizable.CreateGroupMapper; -import com.cognifide.cq.cqsm.foundation.actions.createauthorizable.CreateSystemUserMapper; -import com.cognifide.cq.cqsm.foundation.actions.createauthorizable.CreateUserMapper; import com.cognifide.cq.cqsm.foundation.actions.deny.Deny; -import com.cognifide.cq.cqsm.foundation.actions.deny.DenyMapper; import com.cognifide.cq.cqsm.foundation.actions.save.Save; -import com.cognifide.cq.cqsm.foundation.actions.save.SaveMapper; +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; +import org.mockito.Mockito; @Ignore // TODO: FixThis - all tests in this class are causing stack overflow exception !!! public class ActionFactoryImplTest { @@ -60,15 +49,15 @@ public void before() throws ActionCreationException { factory = Mockito.mock(ActionFactoryImpl.class); when(factory.evaluate(anyString())).thenCallRealMethod(); - when(factory.getMappers()).thenReturn(new ArrayList(Arrays.asList( - new AddToGroupMapper(), - new AllowMapper(), - new DenyMapper(), - new CreateUserMapper(), - new CreateSystemUserMapper(), - new CreateGroupMapper(), - new SaveMapper() - ))); +// when(factory.getMappers()).thenReturn(new ArrayList(Arrays.asList( +// new AddToGroupMapper(), +// new AllowMapper(), +// new DenyMapper(), +// new CreateUserMapper(), +// new CreateSystemUserMapper(), +// new CreateGroupMapper(), +// new SaveMapper() +// ))); } @Test