我正在尝试为pathbrowser实现自定义OSGI服务谓词。如果有人知道这个代码有什么问题:)下面有例外。也许它与@Component或依赖
有关<path jcr:primaryType="nt:unstructured"
sling:resourceType="granite/ui/components/foundation/form/pathbrowser"
fieldDescription="List item link"
fieldLabel="List Item link"
name="./path"
predicate="predicate"
rootPath="/content">
</path>
谓词实施:
import org.apache.commons.collections.Predicate;
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.Service;
import org.apache.sling.api.resource.Resource;
import com.day.cq.commons.predicate.AbstractResourcePredicate;
import com.day.cq.wcm.api.Page;
@Component(label = "Content-page Predicate", description = "This predicate is used to restricted to allow selection of pages that have template content-page")
@Service(value = Predicate.class)
@Properties({
@Property(label = "Predicate Name", name = "predicate.name", value = "predicate", propertyPrivate = true) })
public class ContentPagePredicate extends AbstractResourcePredicate {
private static final String CQ_TEMPLATE_CONTENT = "/conf/xxx-lab/settings/wcm/templates/content-page";
@Override
public boolean evaluate(Resource resource) {
if (null != resource) {
if (!resource.getResourceType().equals("cq:Page")) {
return false;
}
Page page = resource.adaptTo(Page.class);
return page.getTemplate().getName().equals(CQ_TEMPLATE_CONTENT);
}
return false;
}
}
Maven构建输出:
[ERROR] Failed to execute goal org.apache.felix:maven-scr-plugin:1.20.0:scr (generate-scr-scrdescriptor) on project SomethingDemo.core: Execution generate-scr-scrdescriptor of goal org.apache.felix:maven-scr-plugin:1.20.0:scr failed: An API incompatibility was encountered while executing org.apache.felix:maven-scr-plugin:1.20.0:scr: java.lang.VerifyError: Constructor must call super() or this() before return
[ERROR] Exception Details:
[ERROR] Location:
[ERROR] com/day/cq/commons/predicate/AbstractNodePredicate.<init>()V @1: return
[ERROR] Reason:
[ERROR] Error exists in the bytecode
[ERROR] Bytecode:
[ERROR] 0x0000000: 2ab1
答案 0 :(得分:2)
当您从使用SCR注释(用于生成OSGi包描述符)注释的AEM API扩展类时,您看到的错误可能会发生,并且同时在您正在使用的Uber Jar中进行模糊处理。
您可以在Adobe's public Maven repository中找到您正在使用的AEM版本的未经模糊处理的Uber Jar。
如果您代表客户或合作伙伴,您还应该能够从帮助网站https://daycare.day.com/home/products/uberjar.html
下载一个客户或合作伙伴。如果您的项目使用的是已经存在未经模糊处理的Jar的存储库,那么它应该像更改依赖项一样简单。
例如,在使用带有模糊类的AEM 6.2 Uber Jar的项目中
<dependency>
<groupId>com.adobe.aem</groupId>
<artifactId>uber-jar</artifactId>
<version>6.2.0</version>
<scope>provided</scope>
<classifier>obfuscated-apis</classifier>
</dependency>
只需更改分类器即可获得未经模糊处理的版本:
<dependency>
<groupId>com.adobe.aem</groupId>
<artifactId>uber-jar</artifactId>
<version>6.2.0</version>
<scope>provided</scope>
<classifier>apis</classifier>
</dependency>
查看此Github issue,了解有关非常类似问题的更广泛讨论。
您可能还会发现此Adobe Help Forum thread有趣, 虽然它属于测试版。
答案 1 :(得分:1)
尝试实施org.apache.commons.collections.Predicate
。
另外:resource.getResourceType().equals("cq:Page")
永远不会是true
,因为cq:Page
是资源的jcr:pimaryType
。 page.getTemplate()
不适用于发布:
public booean evaluate(Resource resource) {
if (null == resource) return false;
final ValueMap map = resource.getValueMap();
return "cq:Page".equals(map.get("jcr:primaryType", "")
&& CQ_TEMPLATE_CONTENT.equals(map.get("cq:template", "")
}