001/*
002 * (C) Copyright 2017 Nuxeo (http://nuxeo.com/) and others.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *     http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 *
016 * Contributors:
017 *     Arnaud Kervern
018 */
019package org.nuxeo.runtime.test.runner;
020
021import java.util.HashSet;
022import java.util.Set;
023
024/**
025 * A TargetExtensions is part of PartialDeploy annotation that is able to deploy only a subset of extensions in a
026 * bundle. A TargetExtensions defined which target component and extension point are allowed to be deployed.
027 *
028 * @since 9.1
029 */
030public abstract class TargetExtensions {
031    protected Set<String> targetExtensions = new HashSet<>();
032
033    protected TargetExtensions() {
034        initialize();
035    }
036
037    public Set<String> getTargetExtensions() {
038        return targetExtensions;
039    }
040
041    public void addTargetExtension(String name, String extension) {
042        targetExtensions.add(newTargetExtension(name, extension));
043    }
044
045    public static String newTargetExtension(String name, String extension) {
046        return String.format("%s:%s", name, extension);
047    }
048
049    protected abstract void initialize();
050
051    /**
052     * White list contributions: TypeService schema and doctype definition, LifecycleService lifecycle and associated
053     * types, SQLDirectoryFactory directories and VersioningService versioning rules.
054     */
055    public static class ContentModel extends TargetExtensions {
056        public ContentModel() {
057            super();
058        }
059
060        @Override
061        protected void initialize() {
062            addTargetExtension("org.nuxeo.ecm.core.schema.TypeService", "schema");
063            addTargetExtension("org.nuxeo.ecm.core.schema.TypeService", "doctype");
064            addTargetExtension("org.nuxeo.ecm.core.lifecycle.LifeCycleService", "types");
065            addTargetExtension("org.nuxeo.ecm.core.lifecycle.LifeCycleService", "lifecycle");
066            addTargetExtension("org.nuxeo.ecm.directory.GenericDirectory", "directories");
067            addTargetExtension("org.nuxeo.ecm.core.api.versioning.VersioningService", "versioningRules");
068        }
069    }
070
071    /**
072     * White list {@link ContentModel} and ContentTemplateService
073     */
074    public static class ContentTemplate extends ContentModel {
075        @Override
076        protected void initialize() {
077            super.initialize();
078            addTargetExtension("org.nuxeo.ecm.platform.content.template.service.ContentTemplateService",
079                    "factoryBinding");
080        }
081    }
082
083    /**
084     * White list {@link ContentModel} and Automation related contributions
085     */
086    public static class Automation extends ContentModel {
087        @Override
088        protected void initialize() {
089            super.initialize();
090            addTargetExtension("org.nuxeo.ecm.core.operation.OperationServiceComponent", "event-handlers");
091            addTargetExtension("org.nuxeo.ecm.core.operation.OperationServiceComponent", "chains");
092            addTargetExtension("org.nuxeo.automation.scripting.internals.AutomationScriptingComponent", "operation");
093        }
094    }
095}