Skip to content

Commit

Permalink
Merge pull request #63 from orbinson/62-get-rid-of-google-guava-depen…
Browse files Browse the repository at this point in the history
…dency

solves #62: Remove all dependencies on Guava
  • Loading branch information
royteeuwen authored Aug 7, 2024
2 parents 04ae721 + b9dda26 commit beb948e
Show file tree
Hide file tree
Showing 21 changed files with 68 additions and 124 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Changed

- Remove all dependencies on Guava [#62](https://github.com/orbinson/aem-groovy-console/issues/62)

## [19.0.5] - 2024-02-10

### Changed
Expand Down
Original file line number Diff line number Diff line change
@@ -1,30 +1,16 @@
package be.orbinson.aem.groovy.console.api

import com.google.common.collect.ImmutableSet
import groovy.transform.TupleConstructor
import org.apache.sling.api.SlingHttpServletRequest
import org.apache.sling.api.resource.ValueMap
import org.apache.sling.event.jobs.Job

import static be.orbinson.aem.groovy.console.constants.GroovyConsoleConstants.CRON_EXPRESSION
import static be.orbinson.aem.groovy.console.constants.GroovyConsoleConstants.DATA
import static be.orbinson.aem.groovy.console.constants.GroovyConsoleConstants.DATE_CREATED
import static be.orbinson.aem.groovy.console.constants.GroovyConsoleConstants.EMAIL_TO
import static be.orbinson.aem.groovy.console.constants.GroovyConsoleConstants.JOB_DESCRIPTION
import static be.orbinson.aem.groovy.console.constants.GroovyConsoleConstants.JOB_PROPERTIES
import static be.orbinson.aem.groovy.console.constants.GroovyConsoleConstants.JOB_TITLE
import static be.orbinson.aem.groovy.console.constants.GroovyConsoleConstants.MEDIA_TYPE
import static be.orbinson.aem.groovy.console.constants.GroovyConsoleConstants.SCHEDULED_JOB_ID
import static be.orbinson.aem.groovy.console.constants.GroovyConsoleConstants.SCRIPT
import static be.orbinson.aem.groovy.console.constants.GroovyConsoleConstants.*

@TupleConstructor
class JobProperties {

private static final Set<String> ALL_JOB_PROPERTIES = new ImmutableSet.Builder<String>()
.addAll(JOB_PROPERTIES)
.add(DATE_CREATED)
.add(SCHEDULED_JOB_ID)
.build()
private static final Set<String> ALL_JOB_PROPERTIES = [*JOB_PROPERTIES.asList(), DATE_CREATED, SCHEDULED_JOB_ID] as Set

Map<String, Object> properties

Expand Down Expand Up @@ -99,4 +85,4 @@ class JobProperties {
Map<String, Object> toMap() {
properties
}
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
package be.orbinson.aem.groovy.console.constants

import com.google.common.base.Charsets
import com.google.common.net.MediaType

class GroovyConsoleConstants {

public static final String SYSTEM_USER_NAME = "aem-groovy-console-service"
Expand All @@ -15,7 +12,7 @@ class GroovyConsoleConstants {

public static final String EXTENSION_GROOVY = ".groovy"

public static final String CHARSET = Charsets.UTF_8.name()
public static final String CHARSET = "UTF-8"

public static final String FORMAT_RUNNING_TIME = "HH:mm:ss.SSS"

Expand Down Expand Up @@ -99,10 +96,10 @@ class GroovyConsoleConstants {
public static final String AUDIT_PATH = "$PATH_CONSOLE_ROOT/$AUDIT_NODE_NAME"

public static final Map<String, String> MEDIA_TYPE_EXTENSIONS = [
(MediaType.CSV_UTF_8.withoutParameters().toString()) : "csv",
(MediaType.PLAIN_TEXT_UTF_8.withoutParameters().toString()): "txt",
(MediaType.HTML_UTF_8.withoutParameters().toString()) : "html",
(MediaType.XML_UTF_8.withoutParameters().toString()) : "xml"
"text/csv" : "csv",
"text/plain": "txt",
"test/html" : "html",
"text/xml" : "xml"
]

private GroovyConsoleConstants() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
@org.osgi.annotation.bundle.Export
@org.osgi.annotation.versioning.Version("19.0.0")
@org.osgi.annotation.versioning.Version("19.0.1")
package be.orbinson.aem.groovy.console.constants;
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,15 @@ import be.orbinson.aem.groovy.console.api.context.JobScriptContext
import be.orbinson.aem.groovy.console.api.context.ScriptContext
import be.orbinson.aem.groovy.console.response.RunScriptResponse
import be.orbinson.aem.groovy.console.table.Table
import org.apache.jackrabbit.JcrConstants
import org.apache.jackrabbit.util.Text
import com.google.common.net.MediaType
import groovy.json.JsonBuilder
import groovy.transform.TupleConstructor
import org.apache.commons.lang3.exception.ExceptionUtils
import org.apache.jackrabbit.JcrConstants
import org.apache.jackrabbit.util.Text
import org.apache.sling.api.resource.Resource
import org.apache.sling.api.resource.ResourceUtil

import static be.orbinson.aem.groovy.console.constants.GroovyConsoleConstants.DATA
import static be.orbinson.aem.groovy.console.constants.GroovyConsoleConstants.DATE_FORMAT_FILE_NAME
import static be.orbinson.aem.groovy.console.constants.GroovyConsoleConstants.EXCEPTION_STACK_TRACE
import static be.orbinson.aem.groovy.console.constants.GroovyConsoleConstants.JOB_ID
import static be.orbinson.aem.groovy.console.constants.GroovyConsoleConstants.MEDIA_TYPE_EXTENSIONS
import static be.orbinson.aem.groovy.console.constants.GroovyConsoleConstants.OUTPUT
import static be.orbinson.aem.groovy.console.constants.GroovyConsoleConstants.RESULT
import static be.orbinson.aem.groovy.console.constants.GroovyConsoleConstants.RUNNING_TIME
import static be.orbinson.aem.groovy.console.constants.GroovyConsoleConstants.SCRIPT
import static be.orbinson.aem.groovy.console.constants.GroovyConsoleConstants.*

@TupleConstructor
class DefaultRunScriptResponse implements RunScriptResponse {
Expand Down Expand Up @@ -114,13 +105,9 @@ class DefaultRunScriptResponse implements RunScriptResponse {
String getMediaType() {
def mediaType

if (jobProperties?.mediaType) {
mediaType = MediaType.parse(jobProperties.mediaType)
} else {
mediaType = MediaType.PLAIN_TEXT_UTF_8
}
mediaType = jobProperties?.mediaType ? jobProperties.mediaType : "text/plain"

mediaType.withoutParameters().toString()
mediaType
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,16 @@ final class GroovyScriptUtils {

def scriptPreview = new StringBuilder()

if (lines.first().length() > 50) {
scriptPreview.append(lines.first().take(50))
scriptPreview.append(" [...]")
} else {
scriptPreview.append(lines.first())

if (lines.size() > 1) {
if(!lines.isEmpty()) {
if (lines.first().length() > 50) {
scriptPreview.append(lines.first().take(50))
scriptPreview.append(" [...]")
} else {
scriptPreview.append(lines.first())

if (lines.size() > 1) {
scriptPreview.append(" [...]")
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package be.orbinson.aem.groovy.console.extension.impl.metaclass

import be.orbinson.aem.groovy.console.extension.MetaClassExtensionProvider
import com.google.common.base.Optional
import groovy.util.logging.Slf4j
import org.osgi.service.component.annotations.Component

Expand All @@ -22,14 +21,6 @@ import javax.servlet.ServletRequest
@Slf4j("LOG")
class SlingMetaClassExtensionProvider implements MetaClassExtensionProvider {

static def OPTIONAL_METACLASS = {
asBoolean {
def optional = delegate as Optional

optional != null && optional.present
}
}

static def SERVLET_REQUEST_METACLASS = {
getAt { String parameterName ->
def request = delegate as ServletRequest
Expand All @@ -47,7 +38,6 @@ class SlingMetaClassExtensionProvider implements MetaClassExtensionProvider {
}

static def DEFAULT_METACLASSES = [
(Optional) : OPTIONAL_METACLASS,
(ServletRequest): SERVLET_REQUEST_METACLASS
]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package be.orbinson.aem.groovy.console.extension.impl.startimport

import be.orbinson.aem.groovy.console.api.StarImport
import be.orbinson.aem.groovy.console.api.StarImportExtensionProvider
import com.google.common.collect.ImmutableSet
import org.osgi.service.component.annotations.Component

@Component(service = StarImportExtensionProvider, immediate = true)
Expand All @@ -12,13 +11,13 @@ class AemStarImportExtensionProvider implements StarImportExtensionProvider {

private static final String JAVADOC_SUFFIX = "package-summary.html"

private static final Set<StarImport> IMPORTS = ImmutableSet.of(
private static final Set<StarImport> IMPORTS = [
new StarImport("com.day.cq.dam.api", "$AEM_JAVADOC_PREFIX/com/day/cq/dam/api/$JAVADOC_SUFFIX"),
new StarImport("com.day.cq.search", "$AEM_JAVADOC_PREFIX/com/day/cq/search/$JAVADOC_SUFFIX"),
new StarImport("com.day.cq.tagging", "$AEM_JAVADOC_PREFIX/com/day/cq/tagging/$JAVADOC_SUFFIX"),
new StarImport("com.day.cq.wcm.api", "$AEM_JAVADOC_PREFIX/com/day/cq/wcm/api/$JAVADOC_SUFFIX"),
new StarImport("com.day.cq.replication", "$AEM_JAVADOC_PREFIX/com/day/cq/replication/$JAVADOC_SUFFIX"),
)
] as Set

// TODO add check to see if it is an AEM system?

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package be.orbinson.aem.groovy.console.extension.impl.startimport

import be.orbinson.aem.groovy.console.api.StarImport
import be.orbinson.aem.groovy.console.api.StarImportExtensionProvider
import com.google.common.collect.ImmutableSet
import org.osgi.service.component.annotations.Component

@Component(service = StarImportExtensionProvider, immediate = true)
Expand All @@ -12,9 +11,9 @@ class JcrStarImportExtensionProvider implements StarImportExtensionProvider {

private static final String JAVADOC_SUFFIX = "package-summary.html"

private static final Set<StarImport> IMPORTS = ImmutableSet.of(
private static final Set<StarImport> IMPORTS = [
new StarImport("javax.jcr", "$JCR_JAVADOC_PREFIX/javax/jcr/$JAVADOC_SUFFIX")
)
] as Set

@Override
Set<StarImport> getStarImports() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package be.orbinson.aem.groovy.console.extension.impl.startimport

import be.orbinson.aem.groovy.console.api.StarImport
import be.orbinson.aem.groovy.console.api.StarImportExtensionProvider
import com.google.common.collect.ImmutableSet
import org.osgi.service.component.annotations.Component

@Component(service = StarImportExtensionProvider, immediate = true)
Expand All @@ -12,11 +11,11 @@ class SlingStarImportExtensionProvider implements StarImportExtensionProvider {

private static final String JAVADOC_SUFFIX = "package-summary.html"

private static final Set<StarImport> IMPORTS = ImmutableSet.of(
private static final Set<StarImport> IMPORTS = [
new StarImport("org.apache.sling.api", "$SLING_JAVADOC_PREFIX/org/apache/sling/api/$JAVADOC_SUFFIX"),
new StarImport("org.apache.sling.api.resource", "$SLING_JAVADOC_PREFIX/org/apache/sling/api/resource/$JAVADOC_SUFFIX"),
new StarImport("org.apache.sling.distribution", "$SLING_JAVADOC_PREFIX/org/apache/sling/api/distribution/$JAVADOC_SUFFIX")
)
] as Set

@Override
Set<StarImport> getStarImports() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import be.orbinson.aem.groovy.console.response.RunScriptResponse
import be.orbinson.aem.groovy.console.response.SaveScriptResponse
import be.orbinson.aem.groovy.console.response.impl.DefaultRunScriptResponse
import be.orbinson.aem.groovy.console.response.impl.DefaultSaveScriptResponse
import com.google.common.net.MediaType
import groovy.transform.Synchronized
import groovy.transform.TimedInterrupt
import groovy.util.logging.Slf4j
Expand Down Expand Up @@ -117,7 +116,7 @@ class DefaultGroovyConsoleService implements GroovyConsoleService {
resourceResolver.commit();
}

saveFile(resourceResolver, folderResource, scriptData.script, fileName, new Date(), MediaType.OCTET_STREAM.toString())
saveFile(resourceResolver, folderResource, scriptData.script, fileName, new Date(), "application/octet-stream")

new DefaultSaveScriptResponse(fileName)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ package be.orbinson.aem.groovy.console.job.consumer
import be.orbinson.aem.groovy.console.GroovyConsoleService
import be.orbinson.aem.groovy.console.api.JobProperties
import be.orbinson.aem.groovy.console.api.context.impl.ScheduledJobScriptContext
import com.google.common.base.Charsets
import groovy.util.logging.Slf4j
import org.apache.sling.api.resource.ResourceResolverFactory
import org.apache.sling.event.jobs.Job
import org.apache.sling.event.jobs.consumer.JobConsumer
import org.osgi.service.component.annotations.Component
import org.osgi.service.component.annotations.Reference

import java.nio.charset.StandardCharsets

@Component(service = JobConsumer, immediate = true, property = [
"job.topics=groovyconsole/job"
])
Expand All @@ -35,7 +36,7 @@ class GroovyConsoleScheduledJobConsumer implements JobConsumer {
def scriptContext = new ScheduledJobScriptContext(
resourceResolver: resourceResolver,
outputStream: outputStream,
printStream: new PrintStream(outputStream, true, Charsets.UTF_8.name()),
printStream: new PrintStream(outputStream, true, StandardCharsets.UTF_8.name()),
jobId: job.id,
jobProperties: JobProperties.fromJob(job)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,16 @@ import be.orbinson.aem.groovy.console.notification.EmailNotificationService
import be.orbinson.aem.groovy.console.notification.NotificationService
import be.orbinson.aem.groovy.console.response.RunScriptResponse
import com.day.cq.mailer.MailService
import com.google.common.base.Charsets
import com.google.common.net.MediaType
import groovy.text.GStringTemplateEngine
import groovy.util.logging.Slf4j
import org.apache.commons.mail.Email
import org.apache.commons.mail.HtmlEmail
import org.apache.commons.mail.MultiPartEmail
import org.osgi.service.component.annotations.Component
import org.osgi.service.component.annotations.Reference
import org.osgi.service.component.annotations.ReferenceCardinality
import org.osgi.service.component.annotations.ReferencePolicy

import javax.mail.util.ByteArrayDataSource
import java.nio.charset.StandardCharsets

@Component(service = [EmailNotificationService, NotificationService], immediate = true)
@Slf4j("LOG")
Expand Down Expand Up @@ -74,15 +71,14 @@ class AemEmailNotificationService implements EmailNotificationService {
}

email.subject = SUBJECT
email.charset = Charsets.UTF_8.name()
email.charset = StandardCharsets.UTF_8.name()

def message = getMessage(response, successTemplate, failureTemplate)

if (attachOutput) {
(email as MultiPartEmail).addPart(message, MediaType.HTML_UTF_8.toString())
(email as MultiPartEmail).addPart(message, "text/html")

def dataSource = new ByteArrayDataSource(response.output.getBytes(Charsets.UTF_8.name()),
MediaType.parse(response.mediaType).toString())
def dataSource = new ByteArrayDataSource(response.output.getBytes(StandardCharsets.UTF_8.name()), response.mediaType)

// attach output file
(email as MultiPartEmail).attach(dataSource, response.outputFileName, null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ import be.orbinson.aem.groovy.console.GroovyConsoleService
import be.orbinson.aem.groovy.console.api.context.ScriptContext
import be.orbinson.aem.groovy.console.api.context.impl.ResourceScriptContext
import be.orbinson.aem.groovy.console.configuration.ConfigurationService
import org.apache.jackrabbit.JcrConstants
import com.google.common.base.Charsets
import groovy.util.logging.Slf4j
import org.apache.jackrabbit.JcrConstants
import org.apache.sling.api.resource.ResourceResolver
import org.apache.sling.api.resource.ResourceResolverFactory
import org.apache.sling.api.resource.observation.ResourceChange
Expand All @@ -16,8 +15,7 @@ import org.osgi.service.component.annotations.Component
import org.osgi.service.component.annotations.Reference

import javax.jcr.Session

import static com.google.common.base.Preconditions.checkNotNull
import java.nio.charset.StandardCharsets

@Component(property = [
"resource.paths=glob:/conf/groovyconsole/replication/*.groovy",
Expand Down Expand Up @@ -52,8 +50,8 @@ public class ReplicatedScriptListener implements ResourceChangeListener {
new ResourceScriptContext(
resourceResolver: resourceResolver,
outputStream: outputStream,
printStream: new PrintStream(outputStream, true, Charsets.UTF_8.name()),
script: checkNotNull(loadScript(resourceResolver, scriptPath), "Script cannot be empty.")
printStream: new PrintStream(outputStream, true, StandardCharsets.UTF_8.name()),
script: Objects.requireNonNull(loadScript(resourceResolver, scriptPath), "Script cannot be empty.")
)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
package be.orbinson.aem.groovy.console.servlets

import be.orbinson.aem.groovy.console.constants.GroovyConsoleConstants
import com.google.common.net.MediaType
import groovy.json.JsonBuilder
import org.apache.sling.api.SlingHttpServletResponse
import org.apache.sling.api.servlets.SlingAllMethodsServlet

abstract class AbstractJsonResponseServlet extends SlingAllMethodsServlet {

void writeJsonResponse(SlingHttpServletResponse response, json) {
response.contentType = MediaType.JSON_UTF_8.withoutParameters().toString()
response.contentType = "application/json"
response.characterEncoding = GroovyConsoleConstants.CHARSET

new JsonBuilder(json).writeTo(response.writer)
Expand Down
Loading

0 comments on commit beb948e

Please sign in to comment.