/*
 * Copyright 2020 DiffPlug
 *
 * 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
 *
 *     https://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.diffplug.gradle.eclipse;


import com.diffplug.gradle.ProjectPlugin;
import groovy.util.Node;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
import org.gradle.api.Project;

/**
 * Eclipse projects can have [resource filters](https://help.eclipse.org/neon/index.jsp?topic=%2Forg.eclipse.platform.doc.user%2Fconcepts%2Fresourcefilters.htm)
 * which include or exclude certain files.
 * 
 * ![Screenshot](https://i.stack.imgur.com/7eIVE.png)
 * 
 * This plugin allows you to easily configure these settings.
 *
 * ```groovy
 * apply plugin: 'com.diffplug.gradle.eclipse.resourcefilters'
 * eclipseResourceFilters {
 *     exclude().folders().name('build')
 *     include().folders().projectRelativePath('main/src/*')
 *     exclude().files().name('*.class').recursive()
 * }
 * ```
 * 
 * For full details on what filters you can create, see {@link ResourceFilter}.
 */
public class ResourceFiltersPlugin extends ProjectPlugin {
	ResourceFiltersExtension extension;

	@SuppressWarnings("unchecked")
	@Override
	protected void applyOnce(Project project) {
		extension = project.getExtensions().create(ResourceFiltersExtension.NAME, ResourceFiltersExtension.class);
		EclipseProjectPlugin.modifyEclipseProject(project, eclipseModel -> {
			eclipseModel.getProject().getFile().getXmlTransformer().addAction(xmlProvider -> {
				Node rootNode = (Node) xmlProvider.asNode();
				// remove the old filteredResources
				List<Node> toRemove = ((List<Node>) rootNode.children()).stream()
						.filter(Objects::nonNull)
						.filter(node -> FILTERED_RESOURCES.equals(node.name()))
						.collect(Collectors.toList());
				toRemove.forEach(rootNode::remove);
				// now add ours
				Node filteredResources = rootNode.appendNode(FILTERED_RESOURCES);
				for (ResourceFilter toExclude : extension.filters) {
					toExclude.appendToFilteredResources(filteredResources);
				}
			});
		});
	}

	static final String FILTERED_RESOURCES = "filteredResources";
}

@@ -625,16 +625,57 @@
 ipse;%0A%0A%0A
+import com.diffplug.gradle.LegacyPlugin;%0A
 import c
@@ -1225,31 +1225,24 @@
 om.diffplug.
-gradle.
 eclipse.reso
@@ -1596,16 +1596,174 @@
 lugin %7B%0A
+%09public static class Legacy extends LegacyPlugin %7B%0A%09%09public Legacy() %7B%0A%09%09%09super(ResourceFiltersPlugin.class, %22com.diffplug.eclipse.resourcefilters%22);%0A%09%09%7D%0A%09%7D%0A%0A
 %09Resourc
@@ -1880,16 +1880,60 @@
 ject) %7B%0A
+%09%09project.getPlugins().apply(Legacy.class);%0A
 %09%09extens

Update `com.diffplug.eclipse.resourcefilters`