/*
 * Copyright 2016 the original author or authors.
 *
 * 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 org.gradle.plugin.devel;

import com.google.common.base.Objects;
import org.gradle.api.Incubating;
import org.gradle.api.Named;

import java.io.Serializable;
import java.util.Collection;
import java.util.Collections;

/**
 * Describes a Gradle plugin under development.
 *
 * @see org.gradle.plugin.devel.plugins.JavaGradlePluginPlugin
 * @since 2.14
 */
public class PluginDeclaration implements Named, Serializable { // TODO: Shouldn't be serializable, remove the interface in Gradle 8.0.
    private final String name;
    private String id;
    private String implementationClass;
    private String displayName;
    private String description;
    private Collection<String> tags;

    public PluginDeclaration(String name) {
        this.name = name;
    }

    @Override
    public String getName() {
        return name;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getImplementationClass() {
        return implementationClass;
    }

    public void setImplementationClass(String implementationClass) {
        this.implementationClass = implementationClass;
    }

    /**
     * Returns the display name for this plugin declaration.
     *
     * <p>The display name is used when publishing this plugin to repositories
     * that support human-readable artifact names.
     *
     * @since 4.10
     */
    public String getDisplayName() {
        return displayName;
    }

    /**
     * Sets the display name for this plugin declaration.
     *
     * <p>The display name is used when publishing this plugin to repositories
     * that support human-readable artifact names.
     *
     * @since 4.10
     */
    public void setDisplayName(String displayName) {
        this.displayName = displayName;
    }

    /**
     * Returns the description for this plugin declaration.
     *
     * <p>The description is used when publishing this plugin to repositories
     * that support providing descriptions for artifacts.
     *
     * @since 4.10
     */
    public String getDescription() {
        return description;
    }

    /**
     * Sets the description for this plugin declaration.
     *
     * <p>The description is used when publishing this plugin to repositories
     * that support providing descriptions for artifacts.
     *
     * @since 4.10
     */
    public void setDescription(String description) {
        this.description = description;
    }

    /**
     * Returns the tags for this plugin declaration.
     *
     * <p>Tags are used when publishing this plugin to repositories that support tagging plugins,
     * for example the <a href="http://plugins.gradle.org">Gradle Plugin Portal</a>.
     *
     * @since 7.6
     */
    @Incubating
    public Collection<String> getTags() {
        if (tags == null) {
            return Collections.emptyList();
        }
        return tags;
    }

    /**
     * Set the tags for this plugin declaration. Tags describe the categories this plugin covers.
     *
     * <p>Tags are used when publishing this plugin to repositories that support tagging plugins,
     * for example the <a href="http://plugins.gradle.org">Gradle Plugin Portal</a>.
     *
     * @since 7.6
     */
    @Incubating
    public void setTags(Collection<String> tags) {
        this.tags = tags;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj instanceof PluginDeclaration) {
            PluginDeclaration other = (PluginDeclaration) obj;
            return Objects.equal(name, other.name)
                && Objects.equal(id, other.id)
                && Objects.equal(implementationClass, other.implementationClass)
                && Objects.equal(displayName, other.displayName)
                && Objects.equal(description, other.description)
                && Objects.equal(tags, other.tags);
        }
        return false;
    }

    @Override
    public int hashCode() {
        return Objects.hashCode(name, id, implementationClass, displayName, description, tags);
    }
}

@@ -648,47 +648,8 @@
 l;%0A%0A
-import com.google.common.base.Objects;%0A
 impo
@@ -711,95 +711,111 @@
 ed;%0A
-%0A
 import 
-java.io.Serializable;%0Aimport java.util.Collection;%0Aimport java.util.Collections
+org.gradle.api.Project;%0Aimport org.gradle.api.provider.SetProperty;%0A%0Aimport java.io.Serializable
 ;%0A%0A/
@@ -1256,26 +1256,27 @@
 private 
-Collection
+SetProperty
 %3CString%3E
@@ -1308,24 +1308,41 @@
 Declaration(
+Project project, 
 String name)
@@ -1366,24 +1366,92 @@
 ame = name;%0A
+        this.tags = project.getObjects().setProperty(String.class);%0A
     %7D%0A%0A    @
@@ -3187,32 +3187,41 @@
 eturns the tags 
+property 
 for this plugin 
@@ -3487,1347 +3487,66 @@
 lic 
-Collection%3CString%3E getTags() %7B%0A        if (tags == null) %7B%0A            return Collections.emptyList();%0A        %7D%0A        return tags;%0A    %7D%0A%0A    /**%0A     * Set the tags for this plugin declaration. Tags describe the categories this plugin covers.%0A     *%0A     * %3Cp%3ETags are used when publishing this plugin to repositories that support tagging plugins,%0A     * for example the %3Ca href=%22http://plugins.gradle.org%22%3EGradle Plugin Portal%3C/a%3E.%0A     *%0A     * @since 7.6%0A     */%0A    @Incubating%0A    public void setTags(Collection%3CString%3E tags) %7B%0A        this.tags = tags;%0A    %7D%0A%0A    @Override%0A    public boolean equals(Object obj) %7B%0A        if (this == obj) %7B%0A            return true;%0A        %7D%0A        if (obj instanceof PluginDeclaration) %7B%0A            PluginDeclaration other = (PluginDeclaration) obj;%0A            return Objects.equal(name, other.name)%0A                && Objects.equal(id, other.id)%0A                && Objects.equal(implementationClass, other.implementationClass)%0A                && Objects.equal(displayName, other.displayName)%0A                && Objects.equal(description, other.description)%0A                && Objects.equal(tags, other.tags);%0A        %7D%0A        return false;%0A    %7D%0A%0A    @Override%0A    public int hashCode() %7B%0A        return Objects.hashCode(name, id, implementationClass, displayName, description, tags);%0A    %7D
+SetProperty%3CString%3E getTags() %7B%0A        return tags;%0A    %7D%0A
 %0A%7D%0A

Convert tags into a property