diff --git a/pom.xml b/pom.xml index 0d78e339e..6ae638425 100644 --- a/pom.xml +++ b/pom.xml @@ -174,6 +174,21 @@ + + org.osgi + org.osgi.service.component.annotations + 1.3.0 + + + org.osgi + org.osgi.annotation + 6.0.0 + + + org.osgi + org.osgi.service.metatype.annotations + 1.3.0 + org.osgi org.osgi.core @@ -668,7 +683,7 @@ org.codehaus.mojo sonar-maven-plugin - 3.4.1.1168 + 3.4.1.1168 org.jacoco diff --git a/rest-endpoint/pom.xml b/rest-endpoint/pom.xml index f352b8c7c..a6b5183fc 100644 --- a/rest-endpoint/pom.xml +++ b/rest-endpoint/pom.xml @@ -63,10 +63,6 @@ org.apache.commons commons-lang3 - - org.apache.sling - org.apache.sling.commons.osgi - javax.validation validation-api @@ -81,8 +77,16 @@ - org.apache.felix - org.apache.felix.scr.annotations + org.osgi + org.osgi.service.component.annotations + + + org.osgi + org.osgi.annotation + + + org.osgi + org.osgi.service.metatype.annotations @@ -93,18 +97,6 @@ - - org.apache.felix - maven-scr-plugin - - - generate-scr-scrdescriptor - - scr - - - - org.apache.felix maven-bundle-plugin diff --git a/rest-endpoint/src/main/java/com/cognifide/aet/rest/ArtifactServlet.java b/rest-endpoint/src/main/java/com/cognifide/aet/rest/ArtifactServlet.java index 5a60e9583..144a5ec67 100644 --- a/rest-endpoint/src/main/java/com/cognifide/aet/rest/ArtifactServlet.java +++ b/rest-endpoint/src/main/java/com/cognifide/aet/rest/ArtifactServlet.java @@ -24,17 +24,19 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.commons.io.IOUtils; -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.Reference; -import org.apache.felix.scr.annotations.Service; +import org.osgi.service.component.annotations.Activate; +import org.osgi.service.component.annotations.Component; +import org.osgi.service.component.annotations.Deactivate; +import org.osgi.service.component.annotations.Reference; +import org.osgi.service.http.HttpService; -@Service -@Component(label = "ArtifactDataContent", description = "Data Storage information service", immediate = true) +@Component(immediate = true) public class ArtifactServlet extends BasicDataServlet { - private static final long serialVersionUID = 1867870883439947956L; + private static final long serialVersionUID = -8115349502567690275L; + + @Reference + private transient HttpService httpService; @Reference private ArtifactsDAO artifactsDAO; @@ -60,6 +62,16 @@ protected void process(DBKey dbKey, HttpServletRequest req, HttpServletResponse } } + @Override + protected HttpService getHttpService() { + return httpService; + } + + @Override + protected void setHttpService(HttpService httpService) { + this.httpService = httpService; + } + @Activate public void start() { register(Helper.getArtifactPath()); diff --git a/rest-endpoint/src/main/java/com/cognifide/aet/rest/BasicDataServlet.java b/rest-endpoint/src/main/java/com/cognifide/aet/rest/BasicDataServlet.java index 036d8677b..6f0fa8d92 100644 --- a/rest-endpoint/src/main/java/com/cognifide/aet/rest/BasicDataServlet.java +++ b/rest-endpoint/src/main/java/com/cognifide/aet/rest/BasicDataServlet.java @@ -26,24 +26,18 @@ import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import org.apache.felix.scr.annotations.Component; -import org.apache.felix.scr.annotations.Reference; import org.osgi.service.http.HttpService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -@Component abstract class BasicDataServlet extends HttpServlet { - private static final long serialVersionUID = -6301708910829830328L; + private static final long serialVersionUID = -5819760668750910009L; private static final Logger LOGGER = LoggerFactory.getLogger(BasicDataServlet.class); private static final Gson GSON = new Gson(); - @Reference - private transient HttpService httpService; - /*** * Returns JSON representation of Suite based correlationId or suite name * Returned test suite is always in newest version. @@ -77,18 +71,17 @@ protected void doGet(HttpServletRequest req, HttpServletResponse resp) void register(String servletPath) { LOGGER.debug("Registering servlet at ", servletPath); try { - httpService.registerServlet(servletPath, this, null, null); + getHttpService().registerServlet(servletPath, this, null, null); } catch (Exception e) { LOGGER.error("Failed to register servlet at ", servletPath, e); } } void unregister(String servletPath) { - httpService.unregister(servletPath); - httpService = null; + getHttpService().unregister(servletPath); + setHttpService(null); } - boolean isValidName(String suiteName) { return ValidatorProvider.getValidator().validateValue(Suite.class, "name", suiteName).isEmpty(); } @@ -105,6 +98,10 @@ protected String responseAsJson(String format, Object... args) { return GSON.toJson(new ErrorMessage(format, args)); } + protected abstract HttpService getHttpService(); + + protected abstract void setHttpService(HttpService httpService); + private static class ErrorMessage { private final String message; diff --git a/rest-endpoint/src/main/java/com/cognifide/aet/rest/ConfigsServlet.java b/rest-endpoint/src/main/java/com/cognifide/aet/rest/ConfigsServlet.java index a4dca44b3..0d5778be7 100644 --- a/rest-endpoint/src/main/java/com/cognifide/aet/rest/ConfigsServlet.java +++ b/rest-endpoint/src/main/java/com/cognifide/aet/rest/ConfigsServlet.java @@ -32,20 +32,18 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.commons.lang3.StringUtils; -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.Reference; -import org.apache.felix.scr.annotations.Service; +import org.osgi.service.component.annotations.Activate; +import org.osgi.service.component.annotations.Component; +import org.osgi.service.component.annotations.Deactivate; +import org.osgi.service.component.annotations.Reference; import org.osgi.service.http.HttpService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -@Service -@Component(label = "ConfigsServlet", description = "Provides config for clients a", immediate = true) +@Component(immediate = true) public class ConfigsServlet extends HttpServlet { - private static final long serialVersionUID = 101244102274582495L; + private static final long serialVersionUID = -8757845025924429010L; private static final Logger LOGGER = LoggerFactory.getLogger(ConfigsServlet.class); diff --git a/rest-endpoint/src/main/java/com/cognifide/aet/rest/LockService.java b/rest-endpoint/src/main/java/com/cognifide/aet/rest/LockService.java index 842b9e408..336d1a834 100644 --- a/rest-endpoint/src/main/java/com/cognifide/aet/rest/LockService.java +++ b/rest-endpoint/src/main/java/com/cognifide/aet/rest/LockService.java @@ -22,19 +22,16 @@ import java.io.Serializable; import java.util.Map; import java.util.concurrent.TimeUnit; -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.Service; +import org.osgi.service.component.annotations.Activate; +import org.osgi.service.component.annotations.Component; +import org.osgi.service.component.annotations.Deactivate; import org.slf4j.Logger; import org.slf4j.LoggerFactory; - -@Service(LockService.class) -@Component(label = "LockService", description = "Provides lock service", immediate = true) +@Component(service = LockService.class, immediate = true) public class LockService implements Serializable { - private static final long serialVersionUID = 101244102266582495L; + private static final long serialVersionUID = -2029917823742862618L; private static final Logger LOGGER = LoggerFactory.getLogger(LockService.class); diff --git a/rest-endpoint/src/main/java/com/cognifide/aet/rest/LockServlet.java b/rest-endpoint/src/main/java/com/cognifide/aet/rest/LockServlet.java index 0f1937a89..fc381274b 100644 --- a/rest-endpoint/src/main/java/com/cognifide/aet/rest/LockServlet.java +++ b/rest-endpoint/src/main/java/com/cognifide/aet/rest/LockServlet.java @@ -24,21 +24,18 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.commons.lang3.StringUtils; -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.Reference; -import org.apache.felix.scr.annotations.Service; +import org.osgi.service.component.annotations.Activate; +import org.osgi.service.component.annotations.Component; +import org.osgi.service.component.annotations.Deactivate; +import org.osgi.service.component.annotations.Reference; import org.osgi.service.http.HttpService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; - -@Service -@Component(label = "LocksServlet", description = "Provides lock services for clients", immediate = true) +@Component(immediate = true) public class LockServlet extends HttpServlet { - private static final long serialVersionUID = 101244102274582495L; + private static final long serialVersionUID = 638302620021335857L; private static final Logger LOGGER = LoggerFactory.getLogger(LockServlet.class); diff --git a/rest-endpoint/src/main/java/com/cognifide/aet/rest/MetadataServlet.java b/rest-endpoint/src/main/java/com/cognifide/aet/rest/MetadataServlet.java index 7345521c0..46531f604 100644 --- a/rest-endpoint/src/main/java/com/cognifide/aet/rest/MetadataServlet.java +++ b/rest-endpoint/src/main/java/com/cognifide/aet/rest/MetadataServlet.java @@ -35,19 +35,18 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.commons.lang3.BooleanUtils; -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.Reference; -import org.apache.felix.scr.annotations.Service; +import org.osgi.service.component.annotations.Activate; +import org.osgi.service.component.annotations.Component; +import org.osgi.service.component.annotations.Deactivate; +import org.osgi.service.component.annotations.Reference; +import org.osgi.service.http.HttpService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -@Service -@Component(label = "MetadataServlet", description = "Returns Suite Metadata", immediate = true) +@Component(immediate = true) public class MetadataServlet extends BasicDataServlet { - private static final long serialVersionUID = 100244101178249562L; + private static final long serialVersionUID = 7233205495217724069L; private static final Logger LOGGER = LoggerFactory.getLogger(MetadataServlet.class); @@ -61,6 +60,9 @@ public class MetadataServlet extends BasicDataServlet { @Reference private LockService lockService; + @Reference + private transient HttpService httpService; + @Override protected void process(DBKey dbKey, HttpServletRequest req, HttpServletResponse resp) throws IOException { @@ -103,6 +105,16 @@ protected void process(DBKey dbKey, HttpServletRequest req, HttpServletResponse } } + @Override + protected HttpService getHttpService() { + return this.httpService; + } + + @Override + protected void setHttpService(HttpService httpService) { + this.httpService = httpService; + } + /*** * Saves Suite parsed from json provided in post body. * It also increments Version of Suite. diff --git a/rest-endpoint/src/main/java/com/cognifide/aet/rest/XUnitServlet.java b/rest-endpoint/src/main/java/com/cognifide/aet/rest/XUnitServlet.java index dde86cbac..3bdcec00d 100644 --- a/rest-endpoint/src/main/java/com/cognifide/aet/rest/XUnitServlet.java +++ b/rest-endpoint/src/main/java/com/cognifide/aet/rest/XUnitServlet.java @@ -35,27 +35,29 @@ import javax.xml.bind.JAXBException; import javax.xml.bind.Marshaller; import org.apache.commons.io.IOUtils; -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.Reference; -import org.apache.felix.scr.annotations.Service; +import org.osgi.service.component.annotations.Activate; +import org.osgi.service.component.annotations.Component; +import org.osgi.service.component.annotations.Deactivate; +import org.osgi.service.component.annotations.Reference; +import org.osgi.service.http.HttpService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -@Service -@Component(label = "XUnitServlet", description = "Provides xunit test result", immediate = true) +@Component(immediate = true) public class XUnitServlet extends BasicDataServlet { - private static final Logger LOGGER = LoggerFactory.getLogger(XUnitServlet.class); + private static final long serialVersionUID = -5583065996820534015L; - private static final long serialVersionUID = 2459345654081429533L; + private static final Logger LOGGER = LoggerFactory.getLogger(XUnitServlet.class); private static final String XML_HEADER = "\n"; @Reference private MetadataDAO metadataDAO; + @Reference + private transient HttpService httpService; + @Activate public void start() { register(Helper.getXUnitPath()); @@ -84,6 +86,16 @@ protected void process(DBKey dbKey, HttpServletRequest request, HttpServletRespo } } + @Override + protected HttpService getHttpService() { + return this.httpService; + } + + @Override + protected void setHttpService(HttpService httpService) { + this.httpService = httpService; + } + private Suite getSuite(DBKey dbKey, String correlationId, String suiteName) throws RestServiceException { final Suite suite; diff --git a/rest-endpoint/src/main/java/com/cognifide/aet/rest/helpers/ReportConfigurationManager.java b/rest-endpoint/src/main/java/com/cognifide/aet/rest/helpers/ReportConfigurationManager.java index b32434e74..bda140a3a 100644 --- a/rest-endpoint/src/main/java/com/cognifide/aet/rest/helpers/ReportConfigurationManager.java +++ b/rest-endpoint/src/main/java/com/cognifide/aet/rest/helpers/ReportConfigurationManager.java @@ -15,33 +15,23 @@ */ package com.cognifide.aet.rest.helpers; -import java.util.Map; -import org.apache.felix.scr.annotations.Activate; -import org.apache.felix.scr.annotations.Component; -import org.apache.felix.scr.annotations.Property; -import org.apache.felix.scr.annotations.Service; -import org.apache.sling.commons.osgi.PropertiesUtil; +import com.cognifide.aet.rest.helpers.configuration.ReportConfigurationManagerConf; +import org.osgi.service.component.annotations.Activate; +import org.osgi.service.component.annotations.Component; +import org.osgi.service.metatype.annotations.Designate; -@Service(ReportConfigurationManager.class) -@Component(metatype = true, description = "AET Report Application Configuration", - label = "AET Report Application Configuration") +@Component(service = ReportConfigurationManager.class) +@Designate(ocd = ReportConfigurationManagerConf.class) public class ReportConfigurationManager { - private static final String REPORT_DOMAIN_PROPERTY_NAME = "report-domain"; - - private static final String DEFAULT_REPORT_DOMAIN = "http://aet-vagrant"; - - @Property(name = REPORT_DOMAIN_PROPERTY_NAME, label = "Report application domain", - description = "Report application domain", value = DEFAULT_REPORT_DOMAIN) - private String reportDomain; + ReportConfigurationManagerConf config; @Activate - public void activate(Map properties) { - reportDomain = PropertiesUtil - .toString(properties.get(REPORT_DOMAIN_PROPERTY_NAME), DEFAULT_REPORT_DOMAIN); + public void activate(ReportConfigurationManagerConf config) { + this.config = config; } public String getReportDomain() { - return reportDomain; + return config.reportDomain(); } } diff --git a/rest-endpoint/src/main/java/com/cognifide/aet/rest/helpers/configuration/ReportConfigurationManagerConf.java b/rest-endpoint/src/main/java/com/cognifide/aet/rest/helpers/configuration/ReportConfigurationManagerConf.java new file mode 100644 index 000000000..0702c5edc --- /dev/null +++ b/rest-endpoint/src/main/java/com/cognifide/aet/rest/helpers/configuration/ReportConfigurationManagerConf.java @@ -0,0 +1,35 @@ +/** + * AET + * + * 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. + */ +package com.cognifide.aet.rest.helpers.configuration; + +import org.osgi.service.metatype.annotations.AttributeDefinition; +import org.osgi.service.metatype.annotations.AttributeType; +import org.osgi.service.metatype.annotations.ObjectClassDefinition; + +@ObjectClassDefinition(name = "AET Report Application Configuration", description = "AET Report Application Configuration") +public @interface ReportConfigurationManagerConf { + + String REPORT_DOMAIN_PROPERTY_NAME = "report-domain"; + + String DEFAULT_REPORT_DOMAIN = "http://aet-vagrant"; + + @AttributeDefinition( + name = REPORT_DOMAIN_PROPERTY_NAME, + description = "Report application domain", + type = AttributeType.STRING) + String reportDomain() default DEFAULT_REPORT_DOMAIN; + +}