<commit_before>/*
 * Copyright 2013-2016 consulo.io
 *
 * 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 consulo.unity3d;

import com.intellij.ide.BrowserUtil;
import com.intellij.ide.plugins.PluginManager;
import com.intellij.notification.Notification;
import com.intellij.notification.NotificationDisplayType;
import com.intellij.notification.NotificationGroup;
import com.intellij.notification.NotificationType;
import com.intellij.openapi.application.Application;
import com.intellij.openapi.application.ReadAction;
import com.intellij.openapi.command.WriteCommandAction;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.module.ModuleManager;
import com.intellij.openapi.progress.Task;
import com.intellij.openapi.project.DumbService;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.project.ProjectManager;
import com.intellij.openapi.project.ProjectManagerListener;
import com.intellij.openapi.roots.ModifiableRootModel;
import com.intellij.openapi.roots.ModuleRootManager;
import com.intellij.openapi.roots.libraries.Library;
import com.intellij.openapi.roots.libraries.LibraryTable;
import com.intellij.openapi.util.ThrowableComputable;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.vfs.LocalFileSystem;
import com.intellij.openapi.vfs.VfsUtilCore;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.util.Consumer;
import com.intellij.util.PathUtil;
import com.intellij.util.SmartList;
import consulo.annotation.access.RequiredReadAction;
import consulo.dotnet.dll.DotNetModuleFileType;
import consulo.roots.ModifiableModuleRootLayer;
import consulo.roots.ModuleRootLayer;
import consulo.roots.types.BinariesOrderRootType;
import consulo.unity3d.bundle.Unity3dDefineByVersion;
import consulo.unity3d.module.Unity3dModuleExtensionUtil;
import consulo.unity3d.module.Unity3dRootModuleExtension;
import consulo.unity3d.projectImport.Unity3dProjectImportUtil;
import consulo.vfs.util.ArchiveVfsUtil;

import javax.annotation.Nonnull;
import javax.inject.Inject;
import javax.inject.Singleton;
import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * @author VISTALL
 * @since 26-Jul-16
 */
@Singleton
public class UnityPluginFileValidator
{
	private static final Logger LOGGER = Logger.getInstance(UnityPluginFileValidator.class);

	private static final String ourPath = "Assets/Editor/Plugins";
	private static final NotificationGroup ourGroup = new NotificationGroup("consulo.unity", NotificationDisplayType.STICKY_BALLOON, true);

	@Inject
	public UnityPluginFileValidator(Application application, Project project)
	{
		if(project.isDefault())
		{
			return;
		}

		application.getMessageBus().connect(project).subscribe(ProjectManager.TOPIC, new ProjectManagerListener()
		{
			@Override
			public void projectOpened(Project target)
			{
				if(project == target)
				{
					runValidation(project);
				}
			}
		});
	}

	public static void runValidation(@Nonnull final Project project)
	{
		DumbService.getInstance(project).runWhenSmart(() -> notifyAboutPluginFile(project));
	}

	@RequiredReadAction
	private static void notifyAboutPluginFile(@Nonnull final Project project)
	{
		Unity3dRootModuleExtension moduleExtension = Unity3dModuleExtensionUtil.getRootModuleExtension(project);
		if(moduleExtension == null)
		{
			return;
		}

		Unity3dDefineByVersion unity3dDefineByVersion = Unity3dProjectImportUtil.getUnity3dDefineByVersion(moduleExtension.getSdk());
		final String pluginFileName = unity3dDefineByVersion.getPluginFileName();
		if(pluginFileName == null)
		{
			return;
		}

		File pluginPath = PluginManager.getPluginPath(UnityPluginFileValidator.class);

		final File unityPluginFile = new File(pluginPath, "UnityEditorConsuloPlugin/" + pluginFileName);
		if(!unityPluginFile.exists())
		{
			return;
		}

		VirtualFile baseDir = project.getBaseDir();
		if(baseDir == null)
		{
			return;
		}

		List<VirtualFile> targetFiles = new SmartList<>();

		VirtualFile fileByRelativePath = baseDir.findFileByRelativePath(ourPath);
		if(fileByRelativePath != null)
		{<commit_msg>skip if we have source version<commit_after>/*
 * Copyright 2013-2016 consulo.io
 *
 * 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 consulo.unity3d;

import com.intellij.ide.BrowserUtil;
import com.intellij.notification.Notification;
import com.intellij.notification.NotificationDisplayType;
import com.intellij.notification.NotificationGroup;
import com.intellij.notification.NotificationType;
import com.intellij.openapi.application.Application;
import com.intellij.openapi.application.ReadAction;
import com.intellij.openapi.command.WriteCommandAction;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.module.ModuleManager;
import com.intellij.openapi.progress.Task;
import com.intellij.openapi.project.DumbService;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.project.ProjectManager;
import com.intellij.openapi.project.ProjectManagerListener;
import com.intellij.openapi.roots.ModifiableRootModel;
import com.intellij.openapi.roots.ModuleRootManager;
import com.intellij.openapi.roots.libraries.Library;
import com.intellij.openapi.roots.libraries.LibraryTable;
import com.intellij.openapi.util.ThrowableComputable;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.openapi.vfs.LocalFileSystem;
import com.intellij.openapi.vfs.VfsUtilCore;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.util.Consumer;
import com.intellij.util.PathUtil;
import com.intellij.util.SmartList;
import consulo.annotation.access.RequiredReadAction;
import consulo.container.plugin.PluginManager;
import consulo.dotnet.dll.DotNetModuleFileType;
import consulo.dotnet.psi.DotNetTypeDeclaration;
import consulo.dotnet.resolve.DotNetPsiSearcher;
import consulo.logging.Logger;
import consulo.roots.ModifiableModuleRootLayer;
import consulo.roots.ModuleRootLayer;
import consulo.roots.types.BinariesOrderRootType;
import consulo.ui.UIAccess;
import consulo.unity3d.bundle.Unity3dDefineByVersion;
import consulo.unity3d.module.Unity3dModuleExtensionUtil;
import consulo.unity3d.module.Unity3dRootModuleExtension;
import consulo.unity3d.projectImport.Unity3dProjectImportUtil;
import consulo.vfs.util.ArchiveVfsUtil;

import javax.annotation.Nonnull;
import javax.inject.Inject;
import javax.inject.Singleton;
import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * @author VISTALL
 * @since 26-Jul-16
 */
@Singleton
public class UnityPluginFileValidator
{
	private static final Logger LOGGER = Logger.getInstance(UnityPluginFileValidator.class);

	private static final String ourPath = "Assets/Editor/Plugins";
	private static final NotificationGroup ourGroup = new NotificationGroup("consulo.unity", NotificationDisplayType.STICKY_BALLOON, true);

	@Inject
	public UnityPluginFileValidator(Application application, Project project)
	{
		if(project.isDefault())
		{
			return;
		}

		application.getMessageBus().connect(project).subscribe(ProjectManager.TOPIC, new ProjectManagerListener()
		{
			@Override
			public void projectOpened(Project target, UIAccess uiAccess)
			{
				if(project == target)
				{
					runValidation(project);
				}
			}
		});
	}

	public static void runValidation(@Nonnull final Project project)
	{
		DumbService.getInstance(project).runWhenSmart(() -> notifyAboutPluginFile(project));
	}

	@RequiredReadAction
	private static void notifyAboutPluginFile(@Nonnull final Project project)
	{
		Unity3dRootModuleExtension moduleExtension = Unity3dModuleExtensionUtil.getRootModuleExtension(project);
		if(moduleExtension == null)
		{
			return;
		}

		Unity3dDefineByVersion unity3dDefineByVersion = Unity3dProjectImportUtil.getUnity3dDefineByVersion(moduleExtension.getSdk());
		final String pluginFileName = unity3dDefineByVersion.getPluginFileName();
		if(pluginFileName == null)
		{
			return;
		}

		File pluginPath = PluginManager.getPluginPath(UnityPluginFileValidator.class);

		final File unityPluginFile = new File(pluginPath, "UnityEditorConsuloPlugin/" + pluginFileName);
		if(!unityPluginFile.exists())
		{
			return;
		}

		VirtualFile baseDir = project.getBaseDir();
		if(baseDir == null)
		{
			return;
		}

		DotNetTypeDeclaration consuloIntegration = DotNetPsiSearcher.getInstance(project).findType("Consulo.Internal.UnityEditor.ConsuloIntegration", GlobalSearchScope.allScope(project));
		if(consuloIntegration != null)
		{
			return;
		}

		List<VirtualFile> targetFiles = new SmartList<>();

		VirtualFile fileByRelativePath = baseDir.findFileByRelativePath(ourPath);
		if(fileByRelativePath != null)
		{
{'fraction_non_alphanumeric': 0.09267653873274907, 'fraction_numerical': 0.006447063564017326, 'mean_word_length': 5.884882108183079, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5107432', 'n_tokens_mistral': 3172, 'n_tokens_neox': 2938, 'n_words': 594}