diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 9f8472b35..b7c22e37f 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -48,7 +48,6 @@ Below is short list of things that will help us maintaining APM quality and acce - update [documentation](https://github.com/wttech/apm/tree/master/documentation) and include changes in the same pull request which modifies the code, - when committing an improvement, try to show it in local demo example, - when logging use proper levels: `INFO` and `WARNING` should log only very important messages. -- to generate getters and setters use [Lombok](https://projectlombok.org/). Plugins available both on Eclipse & Intellij IDE ## Mailing List To get notification about build changes add your email to .travis.yml in email section. More configuration for notification available in [documentation](https://docs.travis-ci.com/user/notifications#Email-notifications) diff --git a/app/aem/actions.main/build.gradle.kts b/app/aem/actions.main/build.gradle.kts index 5a2548076..39030890e 100644 --- a/app/aem/actions.main/build.gradle.kts +++ b/app/aem/actions.main/build.gradle.kts @@ -26,9 +26,6 @@ aem { dependencies { implementation(project(":app:aem:api")) - - compileOnly("org.projectlombok:lombok:1.18.8") - annotationProcessor("org.projectlombok:lombok:1.18.8") } tasks { diff --git a/app/aem/actions.main/src/main/java/com/cognifide/apm/main/RandomPasswordGenerator.java b/app/aem/actions.main/src/main/java/com/cognifide/apm/main/RandomPasswordGenerator.java index 6137e8b88..813f6333f 100644 --- a/app/aem/actions.main/src/main/java/com/cognifide/apm/main/RandomPasswordGenerator.java +++ b/app/aem/actions.main/src/main/java/com/cognifide/apm/main/RandomPasswordGenerator.java @@ -21,10 +21,7 @@ import java.math.BigInteger; import java.security.SecureRandom; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; -@NoArgsConstructor(access = AccessLevel.PRIVATE) public final class RandomPasswordGenerator { private static final int MAX_BITS = 130; @@ -33,6 +30,10 @@ public final class RandomPasswordGenerator { private static final SecureRandom random = new SecureRandom(); + private RandomPasswordGenerator() { + // intentionally empty + } + public static String getRandomPassword() { return new BigInteger(MAX_BITS, random).toString(RADIX); } diff --git a/app/aem/actions.main/src/main/java/com/cognifide/apm/main/permissions/Restrictions.java b/app/aem/actions.main/src/main/java/com/cognifide/apm/main/permissions/Restrictions.java index d4d71357b..b0e08d4cf 100644 --- a/app/aem/actions.main/src/main/java/com/cognifide/apm/main/permissions/Restrictions.java +++ b/app/aem/actions.main/src/main/java/com/cognifide/apm/main/permissions/Restrictions.java @@ -32,12 +32,8 @@ import javax.jcr.Value; import javax.jcr.ValueFactory; import javax.jcr.ValueFormatException; -import lombok.Getter; -import lombok.ToString; import org.apache.commons.lang3.StringUtils; -@Getter -@ToString public class Restrictions { private static final String STRICT = "STRICT"; @@ -82,7 +78,6 @@ public Map getSingleValueRestrictions(ValueFactory valueFactory) for (Map.Entry entry : customRestrictions.entrySet()) { if (!isMultivalue(entry)) { String value; - if (entry.getValue() instanceof String) { value = (String) entry.getValue(); } else { @@ -154,4 +149,20 @@ private boolean isMultivalue(Map.Entry entry) { } return result; } + + public String getGlob() { + return glob; + } + + public List getNtNames() { + return ntNames; + } + + public List getItemNames() { + return itemNames; + } + + public Map getCustomRestrictions() { + return customRestrictions; + } } diff --git a/app/aem/actions.main/src/main/java/com/cognifide/apm/main/utils/PathUtils.java b/app/aem/actions.main/src/main/java/com/cognifide/apm/main/utils/PathUtils.java index 8a3d7133d..38bb83dbb 100644 --- a/app/aem/actions.main/src/main/java/com/cognifide/apm/main/utils/PathUtils.java +++ b/app/aem/actions.main/src/main/java/com/cognifide/apm/main/utils/PathUtils.java @@ -19,12 +19,12 @@ */ package com.cognifide.apm.main.utils; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; - -@NoArgsConstructor(access = AccessLevel.PRIVATE) public final class PathUtils { + private PathUtils() { + // intentionally empty + } + public static boolean isAppsOrLibsPath(String path) { return path.startsWith("/apps") || path.startsWith("/libs"); } diff --git a/app/aem/api/build.gradle.kts b/app/aem/api/build.gradle.kts index 7dbb0e8ff..b64e926d8 100644 --- a/app/aem/api/build.gradle.kts +++ b/app/aem/api/build.gradle.kts @@ -1,4 +1,3 @@ -import com.cognifide.gradle.aem.bundle.tasks.bundle import org.gradle.jvm.tasks.Jar plugins { diff --git a/app/aem/api/src/main/java/com/cognifide/apm/api/scripts/LaunchMode.java b/app/aem/api/src/main/java/com/cognifide/apm/api/scripts/LaunchMode.java index 1a9f90b4a..88eafaf37 100644 --- a/app/aem/api/src/main/java/com/cognifide/apm/api/scripts/LaunchMode.java +++ b/app/aem/api/src/main/java/com/cognifide/apm/api/scripts/LaunchMode.java @@ -35,6 +35,11 @@ public enum LaunchMode { */ ON_SCHEDULE, + /** + * Executed on CRON expression + */ + ON_CRON_EXPRESSION, + /** * Executed always on bundle start */ diff --git a/app/aem/api/src/main/java/com/cognifide/apm/api/scripts/Script.java b/app/aem/api/src/main/java/com/cognifide/apm/api/scripts/Script.java index fac23ca13..68e0ecb84 100644 --- a/app/aem/api/src/main/java/com/cognifide/apm/api/scripts/Script.java +++ b/app/aem/api/src/main/java/com/cognifide/apm/api/scripts/Script.java @@ -50,6 +50,11 @@ public interface Script { */ Date getLaunchSchedule(); + /** + * Get CRON expression + */ + String getCronExpression(); + /** * Get last execution date */ diff --git a/app/aem/api/src/main/java/com/cognifide/apm/api/scripts/TransientScript.java b/app/aem/api/src/main/java/com/cognifide/apm/api/scripts/TransientScript.java index 9da0b72bf..cfd84bd77 100644 --- a/app/aem/api/src/main/java/com/cognifide/apm/api/scripts/TransientScript.java +++ b/app/aem/api/src/main/java/com/cognifide/apm/api/scripts/TransientScript.java @@ -82,6 +82,11 @@ public Date getLaunchSchedule() { return null; } + @Override + public String getCronExpression() { + return null; + } + @Override public Date getLastExecuted() { return null; diff --git a/app/aem/core/build.gradle.kts b/app/aem/core/build.gradle.kts index 6e7203095..64a725ef9 100644 --- a/app/aem/core/build.gradle.kts +++ b/app/aem/core/build.gradle.kts @@ -46,9 +46,6 @@ dependencies { antlr("org.antlr:antlr4:4.7.2") - compileOnly("org.projectlombok:lombok:1.18.8") - annotationProcessor("org.projectlombok:lombok:1.18.8") - compileOnly(kotlin("stdlib-jdk8")) compileOnly(kotlin("reflect")) } diff --git a/app/aem/core/src/main/java/com/cognifide/apm/core/actions/ActionDescriptor.java b/app/aem/core/src/main/java/com/cognifide/apm/core/actions/ActionDescriptor.java index b2d15cd1e..28293293f 100644 --- a/app/aem/core/src/main/java/com/cognifide/apm/core/actions/ActionDescriptor.java +++ b/app/aem/core/src/main/java/com/cognifide/apm/core/actions/ActionDescriptor.java @@ -21,15 +21,28 @@ import com.cognifide.apm.api.actions.Action; import com.cognifide.apm.core.grammar.argument.Arguments; -import lombok.Getter; -import lombok.RequiredArgsConstructor; -@Getter -@RequiredArgsConstructor public final class ActionDescriptor { private final String command; private final Action action; private final Arguments arguments; + public ActionDescriptor(String command, Action action, Arguments arguments) { + this.command = command; + this.action = action; + this.arguments = arguments; + } + + public String getCommand() { + return command; + } + + public Action getAction() { + return action; + } + + public Arguments getArguments() { + return arguments; + } } diff --git a/app/aem/core/src/main/java/com/cognifide/apm/core/actions/ActionResultImpl.java b/app/aem/core/src/main/java/com/cognifide/apm/core/actions/ActionResultImpl.java index 93ff6d75f..c7b99cae7 100644 --- a/app/aem/core/src/main/java/com/cognifide/apm/core/actions/ActionResultImpl.java +++ b/app/aem/core/src/main/java/com/cognifide/apm/core/actions/ActionResultImpl.java @@ -28,18 +28,14 @@ import java.util.ArrayList; import java.util.LinkedList; import java.util.List; -import lombok.Getter; import org.apache.commons.lang3.StringUtils; public class ActionResultImpl implements ActionResult { - @Getter private String authorizable; - @Getter private List messages; - @Getter private Status status; public ActionResultImpl(String authorizable) { @@ -127,11 +123,23 @@ private static String checkCommonAuthorizable(List actionResults) for (ActionResult actionResult : actionResults) { String current = actionResult.getAuthorizable(); if (current != null && !StringUtils.equals(current, pattern)) { - String error = format("Cannot create CompositeActionResult, mismatch of authorizables. Found: {} Expected: {}", + String error = format("Cannot create CompositeActionResult, mismatch of authorizables. Found: %s Expected: %s", actionResult.getAuthorizable(), pattern); throw new IllegalArgumentException(error); } } return pattern; } + + public String getAuthorizable() { + return authorizable; + } + + public List getMessages() { + return messages; + } + + public Status getStatus() { + return status; + } } diff --git a/app/aem/core/src/main/java/com/cognifide/apm/core/actions/ArgumentDescription.java b/app/aem/core/src/main/java/com/cognifide/apm/core/actions/ArgumentDescription.java index 5d38e3242..252a2b279 100644 --- a/app/aem/core/src/main/java/com/cognifide/apm/core/actions/ArgumentDescription.java +++ b/app/aem/core/src/main/java/com/cognifide/apm/core/actions/ArgumentDescription.java @@ -20,15 +20,27 @@ package com.cognifide.apm.core.actions; -import lombok.Getter; -import lombok.RequiredArgsConstructor; - -@Getter -@RequiredArgsConstructor public class ArgumentDescription { private final String name; private final String type; private final String description; + public ArgumentDescription(String name, String type, String description) { + this.name = name; + this.type = type; + this.description = description; + } + + public String getName() { + return name; + } + + public String getType() { + return type; + } + + public String getDescription() { + return description; + } } diff --git a/app/aem/core/src/main/java/com/cognifide/apm/core/actions/CommandDescription.java b/app/aem/core/src/main/java/com/cognifide/apm/core/actions/CommandDescription.java index daa101db6..77c5c348e 100644 --- a/app/aem/core/src/main/java/com/cognifide/apm/core/actions/CommandDescription.java +++ b/app/aem/core/src/main/java/com/cognifide/apm/core/actions/CommandDescription.java @@ -21,11 +21,7 @@ package com.cognifide.apm.core.actions; import java.util.List; -import lombok.Getter; -import lombok.RequiredArgsConstructor; -@Getter -@RequiredArgsConstructor public class CommandDescription { private final String name; @@ -34,4 +30,31 @@ public class CommandDescription { private final String description; private final List arguments; + public CommandDescription(String name, String group, List examples, String description, List arguments) { + this.name = name; + this.group = group; + this.examples = examples; + this.description = description; + this.arguments = arguments; + } + + public String getName() { + return name; + } + + public String getGroup() { + return group; + } + + public List getExamples() { + return examples; + } + + public String getDescription() { + return description; + } + + public List getArguments() { + return arguments; + } } diff --git a/app/aem/core/src/main/java/com/cognifide/apm/core/actions/MapperContext.java b/app/aem/core/src/main/java/com/cognifide/apm/core/actions/MapperContext.java index 995a619dd..cdc5fd684 100644 --- a/app/aem/core/src/main/java/com/cognifide/apm/core/actions/MapperContext.java +++ b/app/aem/core/src/main/java/com/cognifide/apm/core/actions/MapperContext.java @@ -22,7 +22,6 @@ import com.cognifide.apm.core.Property; import com.cognifide.apm.core.crypto.DecryptionService; -import lombok.Getter; import org.osgi.service.component.annotations.Component; import org.osgi.service.component.annotations.Reference; @@ -33,10 +32,12 @@ Property.VENDOR } ) -@Getter public class MapperContext { @Reference private DecryptionService decryptionService; + public DecryptionService getDecryptionService() { + return decryptionService; + } } diff --git a/app/aem/core/src/main/java/com/cognifide/apm/core/actions/MapperDescriptor.java b/app/aem/core/src/main/java/com/cognifide/apm/core/actions/MapperDescriptor.java index e5659cdfd..c4db956c3 100644 --- a/app/aem/core/src/main/java/com/cognifide/apm/core/actions/MapperDescriptor.java +++ b/app/aem/core/src/main/java/com/cognifide/apm/core/actions/MapperDescriptor.java @@ -23,12 +23,7 @@ import com.cognifide.apm.api.actions.Action; import com.cognifide.apm.core.grammar.argument.Arguments; import java.util.List; -import lombok.AccessLevel; -import lombok.Getter; -import lombok.RequiredArgsConstructor; -@Getter -@RequiredArgsConstructor(access = AccessLevel.PACKAGE) public class MapperDescriptor { private final Object mapper; @@ -36,6 +31,13 @@ public class MapperDescriptor { private final String group; private final List mappingDescriptors; + MapperDescriptor(Object mapper, String name, String group, List mappingDescriptors) { + this.mapper = mapper; + this.name = name; + this.group = group; + this.mappingDescriptors = mappingDescriptors; + } + public boolean handles(Arguments arguments) { return mappingDescriptors.stream().anyMatch(it -> it.handles(arguments)); } @@ -46,4 +48,20 @@ public Action handle(Arguments arguments, MapperContext mapperContext) { .orElseThrow(() -> new RuntimeException("Cannot find matching mapping method")) .handle(mapper, arguments, mapperContext); } + + public Object getMapper() { + return mapper; + } + + public String getName() { + return name; + } + + public String getGroup() { + return group; + } + + public List getMappingDescriptors() { + return mappingDescriptors; + } } diff --git a/app/aem/core/src/main/java/com/cognifide/apm/core/actions/MappingDescriptor.java b/app/aem/core/src/main/java/com/cognifide/apm/core/actions/MappingDescriptor.java index f81b87f7b..f9238f640 100644 --- a/app/aem/core/src/main/java/com/cognifide/apm/core/actions/MappingDescriptor.java +++ b/app/aem/core/src/main/java/com/cognifide/apm/core/actions/MappingDescriptor.java @@ -32,18 +32,16 @@ import java.util.List; import java.util.Set; import java.util.stream.Collectors; -import lombok.Getter; import org.apache.commons.collections4.ListUtils; public class MappingDescriptor { - @Getter private final String name; - @Getter + private final String group; - @Getter + private final String description; - @Getter + private final List examples; private final Method method; @@ -96,4 +94,20 @@ public Action handle(Object mapper, Arguments arguments, MapperContext mapperCon throw new RuntimeException("Cannot invoke mapping method", e); } } + + public String getName() { + return name; + } + + public String getGroup() { + return group; + } + + public String getDescription() { + return description; + } + + public List getExamples() { + return examples; + } } diff --git a/app/aem/core/src/main/java/com/cognifide/apm/core/actions/ParameterDescriptor.java b/app/aem/core/src/main/java/com/cognifide/apm/core/actions/ParameterDescriptor.java index 06559e7a1..133226269 100644 --- a/app/aem/core/src/main/java/com/cognifide/apm/core/actions/ParameterDescriptor.java +++ b/app/aem/core/src/main/java/com/cognifide/apm/core/actions/ParameterDescriptor.java @@ -31,15 +31,15 @@ import java.util.Arrays; import java.util.List; import java.util.stream.Collectors; -import lombok.Getter; -import lombok.RequiredArgsConstructor; -@Getter -@RequiredArgsConstructor public abstract class ParameterDescriptor { private final Class type; + public ParameterDescriptor(Class type) { + this.type = type; + } + abstract Object getArgument(Arguments arguments, DecryptionService decryptionService); abstract boolean handles(Arguments arguments); @@ -50,7 +50,10 @@ protected boolean sameType(ApmType apmType) { return this.type.equals(apmType.getClass()); } - @Getter + public Class getType() { + return type; + } + public static class RequiredParameterDescriptor extends ParameterDescriptor { private final int index; @@ -80,9 +83,16 @@ boolean handles(Arguments arguments) { List toArgumentDescriptions() { return argumentDescriptions; } + + public int getIndex() { + return index; + } + + public List getArgumentDescriptions() { + return argumentDescriptions; + } } - @Getter public static class NamedParameterDescriptor extends ParameterDescriptor { private final String name; @@ -110,9 +120,16 @@ boolean handles(Arguments arguments) { List toArgumentDescriptions() { return argumentDescriptions; } + + public String getName() { + return name; + } + + public List getArgumentDescriptions() { + return argumentDescriptions; + } } - @Getter public static class FlagsParameterDescriptor extends ParameterDescriptor { private final List argumentDescriptions; @@ -138,9 +155,12 @@ boolean handles(Arguments arguments) { List toArgumentDescriptions() { return argumentDescriptions; } + + public List getArgumentDescriptions() { + return argumentDescriptions; + } } - @Getter public static class FlagParameterDescriptor extends ParameterDescriptor { private final List argumentDescriptions; @@ -166,5 +186,13 @@ boolean handles(Arguments arguments) { List toArgumentDescriptions() { return argumentDescriptions; } + + public List getArgumentDescriptions() { + return argumentDescriptions; + } + + public String getFlag() { + return flag; + } } } diff --git a/app/aem/core/src/main/java/com/cognifide/apm/core/executors/ContextImpl.java b/app/aem/core/src/main/java/com/cognifide/apm/core/executors/ContextImpl.java index 484677d6e..96174d574 100644 --- a/app/aem/core/src/main/java/com/cognifide/apm/core/executors/ContextImpl.java +++ b/app/aem/core/src/main/java/com/cognifide/apm/core/executors/ContextImpl.java @@ -30,8 +30,6 @@ import javax.jcr.RepositoryException; import javax.jcr.ValueFactory; import javax.jcr.security.AccessControlManager; -import lombok.Getter; -import lombok.Setter; import org.apache.jackrabbit.api.JackrabbitSession; import org.apache.jackrabbit.api.security.user.Authorizable; import org.apache.jackrabbit.api.security.user.Group; @@ -39,22 +37,16 @@ public final class ContextImpl implements Context { - @Getter private final AccessControlManager accessControlManager; - @Getter private final AuthorizableManager authorizableManager; - @Getter private final SessionSavingPolicy savingPolicy; - @Getter private final JackrabbitSession session; - @Setter private Authorizable currentAuthorizable; - @Getter private final boolean compositeNodeStore; public ContextImpl(JackrabbitSession session, boolean compositeNodeStore) throws RepositoryException { @@ -124,4 +116,27 @@ public Context newContext() { return new ContextImpl(accessControlManager, authorizableManager, savingPolicy, session, compositeNodeStore); } + public AccessControlManager getAccessControlManager() { + return accessControlManager; + } + + public AuthorizableManager getAuthorizableManager() { + return authorizableManager; + } + + public SessionSavingPolicy getSavingPolicy() { + return savingPolicy; + } + + public JackrabbitSession getSession() { + return session; + } + + public boolean isCompositeNodeStore() { + return compositeNodeStore; + } + + public void setCurrentAuthorizable(Authorizable currentAuthorizable) { + this.currentAuthorizable = currentAuthorizable; + } } \ No newline at end of file diff --git a/app/aem/core/src/main/java/com/cognifide/apm/core/history/HistoryAutocleanService.java b/app/aem/core/src/main/java/com/cognifide/apm/core/history/HistoryAutocleanService.java index 5195b4e92..106db7314 100644 --- a/app/aem/core/src/main/java/com/cognifide/apm/core/history/HistoryAutocleanService.java +++ b/app/aem/core/src/main/java/com/cognifide/apm/core/history/HistoryAutocleanService.java @@ -23,7 +23,6 @@ import com.cognifide.apm.core.services.ResourceResolverProvider; import com.cognifide.apm.core.utils.sling.SlingHelper; import java.util.Calendar; -import lombok.extern.slf4j.Slf4j; import org.apache.sling.api.resource.PersistenceException; import org.apache.sling.api.resource.Resource; import org.apache.sling.api.resource.ResourceResolver; @@ -35,12 +34,15 @@ import org.osgi.service.metatype.annotations.AttributeType; import org.osgi.service.metatype.annotations.Designate; import org.osgi.service.metatype.annotations.ObjectClassDefinition; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; -@Slf4j @Component @Designate(ocd = HistoryAutocleanService.Config.class) public class HistoryAutocleanService implements Runnable { + private static final Logger LOGGER = LoggerFactory.getLogger(HistoryAutocleanService.class); + private Config config; @Reference @@ -63,7 +65,7 @@ public void run() { private void deleteHistoryByEntries(ResourceResolver resolver) { if (config.maxEntries() >= 0) { - log.info("Looking for items exceeding limit of {} items", config.maxEntries()); + LOGGER.info("Looking for items exceeding limit of {} items", config.maxEntries()); history.findAllResources(resolver) .stream() .skip(config.maxEntries()) @@ -73,7 +75,7 @@ private void deleteHistoryByEntries(ResourceResolver resolver) { private void deleteHistoryByDays(ResourceResolver resolver) { if (config.maxDays() >= 0) { - log.info("Looking for items older than {} days", config.maxDays()); + LOGGER.info("Looking for items older than {} days", config.maxDays()); Calendar calendar = Calendar.getInstance(); calendar.add(Calendar.DAY_OF_MONTH, -config.maxDays()); history.findAllResources(resolver) @@ -88,7 +90,7 @@ private void deleteHistoryByDays(ResourceResolver resolver) { private void deleteItem(ResourceResolver resolver, Resource resource) { try { - log.info("Deleting: {}", resource.getPath()); + LOGGER.info("Deleting: {}", resource.getPath()); resolver.delete(resource); } catch (PersistenceException e) { throw new RuntimeException(e); diff --git a/app/aem/core/src/main/java/com/cognifide/apm/core/history/HistoryEntryImpl.java b/app/aem/core/src/main/java/com/cognifide/apm/core/history/HistoryEntryImpl.java index 0ff243030..b4de975b1 100644 --- a/app/aem/core/src/main/java/com/cognifide/apm/core/history/HistoryEntryImpl.java +++ b/app/aem/core/src/main/java/com/cognifide/apm/core/history/HistoryEntryImpl.java @@ -28,16 +28,12 @@ import javax.annotation.PostConstruct; import javax.inject.Inject; import javax.inject.Named; -import lombok.EqualsAndHashCode; -import lombok.Getter; import org.apache.sling.api.resource.Resource; import org.apache.sling.models.annotations.Default; import org.apache.sling.models.annotations.DefaultInjectionStrategy; import org.apache.sling.models.annotations.Model; -@Getter @Model(adaptables = Resource.class, defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL) -@EqualsAndHashCode public class HistoryEntryImpl implements HistoryEntry { public static final String AUTHOR = "author"; @@ -129,4 +125,63 @@ private void afterCreated() { executionTimeCalendar = CalendarUtils.asCalendar(executionTime); } + public String getAuthor() { + return author; + } + + public Date getExecutionTime() { + return executionTime; + } + + public Long getExecutionDuration() { + return executionDuration; + } + + public String getExecutor() { + return executor; + } + + public String getScriptPath() { + return scriptPath; + } + + public String getScriptName() { + return scriptName; + } + + public boolean isRunSuccessful() { + return isRunSuccessful; + } + + public String getMode() { + return mode; + } + + public String getChecksum() { + return checksum; + } + + public Date getUploadTime() { + return uploadTime; + } + + public String getExecutionSummaryJson() { + return executionSummaryJson; + } + + public String getScriptContentPath() { + return scriptContentPath; + } + + public String getInstanceName() { + return instanceName; + } + + public String getPath() { + return path; + } + + public Calendar getExecutionTimeCalendar() { + return executionTimeCalendar; + } } \ No newline at end of file diff --git a/app/aem/core/src/main/java/com/cognifide/apm/core/history/HistoryEntryWriter.java b/app/aem/core/src/main/java/com/cognifide/apm/core/history/HistoryEntryWriter.java index b53b1538e..36f1aa062 100644 --- a/app/aem/core/src/main/java/com/cognifide/apm/core/history/HistoryEntryWriter.java +++ b/app/aem/core/src/main/java/com/cognifide/apm/core/history/HistoryEntryWriter.java @@ -21,12 +21,10 @@ package com.cognifide.apm.core.history; import java.util.Calendar; -import lombok.Builder; import org.apache.sling.api.resource.ModifiableValueMap; import org.apache.sling.api.resource.Resource; -@Builder -public class HistoryEntryWriter { +public final class HistoryEntryWriter { private final String author; private final Calendar executionTime; @@ -39,6 +37,23 @@ public class HistoryEntryWriter { private final String progressLog; private final String instanceName; + private HistoryEntryWriter(String author, Calendar executionTime, String executor, long executionDuration, String fileName, String filePath, Boolean isRunSuccessful, String mode, String progressLog, String instanceName) { + this.author = author; + this.executionTime = executionTime; + this.executor = executor; + this.executionDuration = executionDuration; + this.fileName = fileName; + this.filePath = filePath; + this.isRunSuccessful = isRunSuccessful; + this.mode = mode; + this.progressLog = progressLog; + this.instanceName = instanceName; + } + + public static HistoryEntryWriterBuilder builder() { + return new HistoryEntryWriterBuilder(); + } + public void writeTo(Resource historyLogResource) { ModifiableValueMap valueMap = historyLogResource.adaptTo(ModifiableValueMap.class); valueMap.put(HistoryEntryImpl.SCRIPT_NAME, fileName); @@ -52,4 +67,76 @@ public void writeTo(Resource historyLogResource) { valueMap.put(HistoryEntryImpl.EXECUTOR, executor); valueMap.put(HistoryEntryImpl.INSTANCE_NAME, instanceName); } + + public static class HistoryEntryWriterBuilder { + + private String author; + private Calendar executionTime; + private String executor; + private long executionDuration; + private String fileName; + private String filePath; + private Boolean isRunSuccessful; + private String mode; + private String progressLog; + private String instanceName; + + private HistoryEntryWriterBuilder() { + // intentionally empty + } + + public HistoryEntryWriterBuilder author(String author) { + this.author = author; + return this; + } + + public HistoryEntryWriterBuilder executionTime(Calendar executionTime) { + this.executionTime = executionTime; + return this; + } + + public HistoryEntryWriterBuilder executor(String executor) { + this.executor = executor; + return this; + } + + public HistoryEntryWriterBuilder executionDuration(long executionDuration) { + this.executionDuration = executionDuration; + return this; + } + + public HistoryEntryWriterBuilder fileName(String fileName) { + this.fileName = fileName; + return this; + } + + public HistoryEntryWriterBuilder filePath(String filePath) { + this.filePath = filePath; + return this; + } + + public HistoryEntryWriterBuilder isRunSuccessful(Boolean isRunSuccessful) { + this.isRunSuccessful = isRunSuccessful; + return this; + } + + public HistoryEntryWriterBuilder mode(String mode) { + this.mode = mode; + return this; + } + + public HistoryEntryWriterBuilder progressLog(String progressLog) { + this.progressLog = progressLog; + return this; + } + + public HistoryEntryWriterBuilder instanceName(String instanceName) { + this.instanceName = instanceName; + return this; + } + + public HistoryEntryWriter build() { + return new HistoryEntryWriter(author, executionTime, executor, executionDuration, fileName, filePath, isRunSuccessful, mode, progressLog, instanceName); + } + } } diff --git a/app/aem/core/src/main/java/com/cognifide/apm/core/history/ScriptHistoryImpl.java b/app/aem/core/src/main/java/com/cognifide/apm/core/history/ScriptHistoryImpl.java index 55fea9cad..04f765fa0 100644 --- a/app/aem/core/src/main/java/com/cognifide/apm/core/history/ScriptHistoryImpl.java +++ b/app/aem/core/src/main/java/com/cognifide/apm/core/history/ScriptHistoryImpl.java @@ -22,7 +22,6 @@ import javax.inject.Inject; import javax.inject.Named; -import lombok.Getter; import org.apache.sling.api.resource.Resource; import org.apache.sling.models.annotations.DefaultInjectionStrategy; import org.apache.sling.models.annotations.Model; @@ -46,22 +45,18 @@ public class ScriptHistoryImpl implements ScriptHistory { private History history; @Inject - @Getter @Named(SCRIPT_PATH) private String scriptPath; @Inject - @Getter @Named(LAST_LOCAL_RUN) private String lastLocalRunPath; @Inject - @Getter @Named(LAST_LOCAL_DRY_RUN) private String lastLocalDryRunPath; @Inject - @Getter @Named(LAST_CHECKSUM) private String lastChecksum; @@ -95,4 +90,19 @@ private HistoryEntry getHistoryEntry(HistoryEntry entry, String historyEntryPath return historyEntry; } + public String getScriptPath() { + return scriptPath; + } + + public String getLastLocalRunPath() { + return lastLocalRunPath; + } + + public String getLastLocalDryRunPath() { + return lastLocalDryRunPath; + } + + public String getLastChecksum() { + return lastChecksum; + } } diff --git a/app/aem/core/src/main/java/com/cognifide/apm/core/jobs/JobResultsCache.java b/app/aem/core/src/main/java/com/cognifide/apm/core/jobs/JobResultsCache.java index 06e7bbc16..f540f0bb5 100644 --- a/app/aem/core/src/main/java/com/cognifide/apm/core/jobs/JobResultsCache.java +++ b/app/aem/core/src/main/java/com/cognifide/apm/core/jobs/JobResultsCache.java @@ -25,8 +25,6 @@ import com.google.common.cache.CacheBuilder; import java.io.Serializable; import java.util.concurrent.TimeUnit; -import lombok.AccessLevel; -import lombok.RequiredArgsConstructor; import org.osgi.service.component.annotations.Activate; import org.osgi.service.component.annotations.Component; @@ -56,13 +54,18 @@ public ExecutionSummary get(String id) { return cache.getIfPresent(id); } - @RequiredArgsConstructor(access = AccessLevel.PRIVATE) public static class ExecutionSummary implements Serializable { private final boolean finished; private final ExecutionResult result; private final String path; + private ExecutionSummary(boolean finished, ExecutionResult result, String path) { + this.finished = finished; + this.result = result; + this.path = path; + } + public static ExecutionSummary running() { return new ExecutionSummary(false, null, null); } diff --git a/app/aem/core/src/main/java/com/cognifide/apm/core/launchers/ApmInstallService.java b/app/aem/core/src/main/java/com/cognifide/apm/core/launchers/ApmInstallService.java new file mode 100644 index 000000000..b94b85330 --- /dev/null +++ b/app/aem/core/src/main/java/com/cognifide/apm/core/launchers/ApmInstallService.java @@ -0,0 +1,61 @@ +/*- + * ========================LICENSE_START================================= + * AEM Permission Management + * %% + * Copyright (C) 2013 Wunderman Thompson Technology + * %% + * 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.apm.core.launchers; + +import com.cognifide.apm.api.scripts.Script; +import com.cognifide.apm.api.services.ScriptFinder; +import com.cognifide.apm.api.services.ScriptManager; +import com.cognifide.apm.core.services.ResourceResolverProvider; +import com.cognifide.apm.core.utils.RuntimeUtils; +import com.cognifide.apm.core.utils.sling.SlingHelper; +import java.util.Collections; + +public class ApmInstallService extends AbstractLauncher implements Runnable { + + private final String scriptPath; + + private final ResourceResolverProvider resolverProvider; + + private final ScriptManager scriptManager; + + private final ScriptFinder scriptFinder; + + public ApmInstallService(String scriptPath, ResourceResolverProvider resolverProvider, ScriptManager scriptManager, ScriptFinder scriptFinder) { + this.scriptPath = scriptPath; + this.resolverProvider = resolverProvider; + this.scriptManager = scriptManager; + this.scriptFinder = scriptFinder; + } + + @Override + public void run() { + SlingHelper.operateTraced(resolverProvider, resolver -> { + if (RuntimeUtils.isMutableContentInstance(resolver)) { + Script script = scriptFinder.find(scriptPath, resolver); + processScripts(Collections.singletonList(script), resolver); + } + }); + } + + @Override + protected ScriptManager getScriptManager() { + return scriptManager; + } +} diff --git a/app/aem/core/src/main/java/com/cognifide/apm/core/launchers/ScheduledScriptLauncher.java b/app/aem/core/src/main/java/com/cognifide/apm/core/launchers/ScheduledScriptLauncher.java deleted file mode 100644 index 85b213ffc..000000000 --- a/app/aem/core/src/main/java/com/cognifide/apm/core/launchers/ScheduledScriptLauncher.java +++ /dev/null @@ -1,100 +0,0 @@ -/*- - * ========================LICENSE_START================================= - * AEM Permission Management - * %% - * Copyright (C) 2013 Wunderman Thompson Technology - * %% - * 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.apm.core.launchers; - -import static com.cognifide.apm.core.scripts.ScriptFilters.onSchedule; - -import com.cognifide.apm.api.scripts.LaunchEnvironment; -import com.cognifide.apm.api.scripts.Script; -import com.cognifide.apm.api.services.RunModesProvider; -import com.cognifide.apm.api.services.ScriptFinder; -import com.cognifide.apm.api.services.ScriptManager; -import com.cognifide.apm.core.Property; -import com.cognifide.apm.core.launchers.ScheduledScriptLauncher.ScheduleExecutorConfiguration; -import com.cognifide.apm.core.services.ResourceResolverProvider; -import com.cognifide.apm.core.utils.sling.SlingHelper; -import java.util.Date; -import java.util.List; -import org.apache.sling.api.resource.PersistenceException; -import org.apache.sling.api.resource.ResourceResolver; -import org.osgi.service.component.annotations.Activate; -import org.osgi.service.component.annotations.Component; -import org.osgi.service.component.annotations.Modified; -import org.osgi.service.component.annotations.Reference; -import org.osgi.service.metatype.annotations.AttributeDefinition; -import org.osgi.service.metatype.annotations.Designate; -import org.osgi.service.metatype.annotations.ObjectClassDefinition; - -@Component( - property = { - Property.DESCRIPTION + "APM Launches scheduled scripts", - Property.VENDOR, - Property.SCHEDULER + "0 * * * * ?" - } -) -@Designate(ocd = ScheduleExecutorConfiguration.class) -public class ScheduledScriptLauncher extends AbstractLauncher implements Runnable { - - @Reference - private ScriptManager scriptManager; - - @Reference - private ScriptFinder scriptFinder; - - @Reference - private RunModesProvider runModesProvider; - - @Reference - private ResourceResolverProvider resolverProvider; - - private boolean enabled = true; - - @Activate - @Modified - public void activate(ScheduleExecutorConfiguration config) { - enabled = !config.disableScheduleExecutor(); - } - - @Override - public void run() { - if (enabled) { - SlingHelper.operateTraced(resolverProvider, this::runScheduled); - } - } - - private void runScheduled(ResourceResolver resolver) throws PersistenceException { - LaunchEnvironment environment = LaunchEnvironment.of(runModesProvider); - List