<commit_before>package org.xtext.gradle.idea.tasks

import groovy.util.XmlSlurper
import groovy.util.slurpersupport.Node
import java.io.File
import java.net.URL
import java.nio.file.Files
import org.eclipse.xtend.lib.annotations.Accessors
import org.eclipse.xtend.lib.annotations.Data
import org.gradle.api.DefaultTask
import org.gradle.api.tasks.TaskAction

import static extension org.xtext.gradle.idea.tasks.GradleExtensions.*

@Accessors
class DownloadIdeaPlugins extends DefaultTask {
	File destinationDir
	IdeaPluginRepositories pluginRepositories
	IdeaPluginDependencies pluginDependencies

	new() {
		onlyIf [
			if (project.gradle.startParameter.refreshDependencies) {
				return true
			}
			externalPluginDependencies.exists [
				! (destinationDir / id / version).exists
			]
		]
	}

	@TaskAction
	def download() {
		val urlsByPluginId = collectUrlsByPluginId
		externalPluginDependencies.forEach [
			val plugin = new PluginRequest(id, version)
			download(plugin, urlsByPluginId.get(plugin))
		]
	}

	def externalPluginDependencies() {
		pluginDependencies.externalDependencies
	}

	def download(PluginRequest plugin, String downloadUrl) {
		usingTmpDir[ tmp |
			val targetFile = tmp / '''«plugin.id».zip'''
			Files.copy(new URL(downloadUrl).openStream, targetFile.toPath)
			project.copy [
				into(destinationDir / plugin.id / plugin.version)
				from(project.zipTree(targetFile))
				eachFile[cutDirs(1)]<commit_msg>delete plugins folder before download<commit_after>package org.xtext.gradle.idea.tasks

import groovy.util.XmlSlurper
import groovy.util.slurpersupport.Node
import java.io.File
import java.net.URL
import java.nio.file.Files
import org.eclipse.xtend.lib.annotations.Accessors
import org.eclipse.xtend.lib.annotations.Data
import org.gradle.api.DefaultTask
import org.gradle.api.tasks.TaskAction

import static extension org.xtext.gradle.idea.tasks.GradleExtensions.*

@Accessors
class DownloadIdeaPlugins extends DefaultTask {
	File destinationDir
	IdeaPluginRepositories pluginRepositories
	IdeaPluginDependencies pluginDependencies

	new() {
		onlyIf [
			if (project.gradle.startParameter.refreshDependencies) {
				return true
			}
			externalPluginDependencies.exists [
				! (destinationDir / id / version).exists
			]
		]
	}

	@TaskAction
	def download() {
		val urlsByPluginId = collectUrlsByPluginId
		externalPluginDependencies.forEach [
			val plugin = new PluginRequest(id, version)
			download(plugin, urlsByPluginId.get(plugin))
		]
	}

	def externalPluginDependencies() {
		pluginDependencies.externalDependencies
	}

	def download(PluginRequest plugin, String downloadUrl) {
		usingTmpDir[ tmp |
			val targetFile = tmp / '''«plugin.id».zip'''
			Files.copy(new URL(downloadUrl).openStream, targetFile.toPath)
			val pluginFolder = destinationDir / plugin.id / plugin.version
			project.delete(pluginFolder)
			project.copy [
				into(pluginFolder)
				from(project.zipTree(targetFile))
				eachFile[cutDirs(1)]
{'fraction_non_alphanumeric': 0.09186085781830462, 'fraction_numerical': 0.0006754474839581223, 'mean_word_length': 4.773879142300195, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 13, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6027695', 'n_tokens_mistral': 1014, 'n_tokens_neox': 885, 'n_words': 177}