/**
 * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
 *
 * 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.liferay.blade.gradle.plugin;

import com.liferay.blade.gradle.model.CustomModel;
import com.liferay.blade.gradle.model.DefaultModel;

import java.io.File;

import java.util.HashSet;
import java.util.Set;

import javax.inject.Inject;

import org.gradle.api.Plugin;
import org.gradle.api.Project;
import org.gradle.api.Task;
import org.gradle.tooling.provider.model.ToolingModelBuilder;
import org.gradle.tooling.provider.model.ToolingModelBuilderRegistry;

/**
 * @author Gregory Amerson
 */
public class CustomModelPlugin implements Plugin<Project> {

	@Inject
	public CustomModelPlugin(ToolingModelBuilderRegistry registry) {
		this.registry = registry;
	}

	@Override
	public void apply(Project project) {
		registry.register(new CustomModelBuilder());
	}

	private final ToolingModelBuilderRegistry registry;

	private static class CustomModelBuilder implements ToolingModelBuilder {

		@Override
		public Object buildAll(String modelName, Project project) {
			Set<String> pluginClassNames = new HashSet<>();

			for (Plugin<?> plugin : project.getPlugins()) {
				Class<?> clazz = plugin.getClass();

				pluginClassNames.add(clazz.getName());
			}

			Set<Task> jarTasks = project.getTasksByName("jar", true);

			Set<Task> buildTasks = project.getTasksByName("build", true);

			Set<File> outputFiles = new HashSet<>();

			for (Task task : jarTasks) {
				outputFiles.addAll(task.getOutputs().getFiles().getFiles());
			}

			for (Task task : buildTasks) {
				outputFiles.addAll(task.getOutputs().getFiles().getFiles());
			}

			return new DefaultModel(pluginClassNames, outputFiles);
		}

		@Override
		public boolean canBuild(String modelName) {
			return modelName.equals(CustomModel.class.getName());
		}

	}

}
@@ -792,17 +792,16 @@
 o.File;%0A
-%0A
 import j
@@ -959,16 +959,299 @@
 i.Task;%0A
+import org.gradle.api.artifacts.Configuration;%0Aimport org.gradle.api.artifacts.ConfigurationContainer;%0Aimport org.gradle.api.artifacts.Dependency;%0Aimport org.gradle.api.artifacts.PublishArtifactSet;%0Aimport org.gradle.api.file.FileCollection;%0Aimport org.gradle.api.tasks.TaskOutputs;%0A
 import o
@@ -2087,19 +2087,21 @@
 t%3CTask%3E 
-jar
+build
 Tasks = 
@@ -2124,19 +2124,21 @@
 ByName(%22
-jar
+build
 %22, true)
@@ -2145,37 +2145,35 @@
 ;%0A%0A%09%09%09Set%3CTask%3E 
-build
+jar
 Tasks = project.
@@ -2184,36 +2184,130 @@
 asksByName(%22
-build%22, true
+jar%22, true);%0A%0A%09%09%09Set%3CTask%3E tasks = new HashSet%3C%3E();%0A%0A%09%09%09tasks.addAll(buildTasks);%0A%09%09%09tasks.addAll(jarTasks
 );%0A%0A%09%09%09Set%3CF
@@ -2363,20 +2363,17 @@
  task : 
-jarT
+t
 asks) %7B%0A
@@ -2380,110 +2380,454 @@
 %09%09%09%09
-outputFiles.addAll(task.getOutputs().getFiles().getFiles());%0A%09%09%09%7D%0A%0A%09%09%09for (Task task : buildTasks) %7B%0A%09
+TaskOutputs outputs = task.getOutputs();%0A%0A%09%09%09%09FileCollection fileCollection = outputs.getFiles();%0A%0A%09%09%09%09Set%3CFile%3E files = fileCollection.getFiles();%0A%0A%09%09%09%09outputFiles.addAll(files);%0A%09%09%09%7D%0A%0A%09%09%09ConfigurationContainer configurations = project.getConfigurations();%0A%0A%09%09%09Configuration archivesConfiguration =%0A%09%09%09%09configurations.getByName(%0A%09%09%09%09%09%09Dependency.ARCHIVES_CONFIGURATION);%0A%0A%09%09%09PublishArtifactSet artifacts = archivesConfiguration.getArtifacts();%0A%0A
 %09%09%09o
@@ -2844,33 +2844,25 @@
 .addAll(
-task.getOutputs()
+artifacts
 .getFile
@@ -2873,29 +2873,24 @@
 getFiles());
-%0A%09%09%09%7D
 %0A%0A%09%09%09return 

Add support for archives configurations