[maven] collect cases when user has added module/library to an imported project
authorAnton Makeev <Anton.Makeev@jetbrains.com>
Wed, 18 May 2022 17:47:49 +0000 (19:47 +0200)
committerintellij-monorepo-bot <intellij-monorepo-bot-no-reply@jetbrains.com>
Thu, 19 May 2022 16:21:56 +0000 (16:21 +0000)
GitOrigin-RevId: f22d6bda7885c16505d4b196b684ddc7992e9f5c

plugins/maven/src/main/java/org/jetbrains/idea/maven/importing/MavenProjectImporterImpl.java
plugins/maven/src/main/java/org/jetbrains/idea/maven/importing/MavenRootModelAdapterLegacyImpl.java
plugins/maven/src/main/java/org/jetbrains/idea/maven/statistics/MavenImportCollector.kt [new file with mode: 0644]
plugins/maven/src/main/resources/META-INF/plugin.xml

index 6835746b37413b1aa139b4a7abb0bc0b838e8e4d..2a1e3ed2280504870dca78493bb466a51666a47c 100644 (file)
@@ -36,6 +36,7 @@ import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
 import org.jetbrains.idea.maven.model.MavenId;
 import org.jetbrains.idea.maven.project.*;
+import org.jetbrains.idea.maven.statistics.MavenImportCollector;
 import org.jetbrains.idea.maven.utils.MavenLog;
 import org.jetbrains.idea.maven.utils.MavenUtil;
 import org.jetbrains.jps.model.java.compiler.JpsJavaCompilerOptions;
@@ -615,9 +616,14 @@ class MavenProjectImporterImpl extends MavenProjectImporterBase {
 
     boolean removed = false;
     for (Library each : unusedLibraries) {
-      if (!isDisposed(each) && MavenRootModelAdapter.isMavenLibrary(each) && !MavenRootModelAdapter.isChangedByUser(each)) {
-        myModelsProvider.removeLibrary(each);
-        removed = true;
+      if (!isDisposed(each) && MavenRootModelAdapter.isMavenLibrary(each)) {
+        if (!MavenRootModelAdapter.isChangedByUser(each)) {
+          myModelsProvider.removeLibrary(each);
+          removed = true;
+        }
+        else {
+          MavenImportCollector.HAS_USER_MODIFIED_IMPORTED_LIBRARY.log(myProject);
+        }
       }
     }
     return removed;
index ff3850ff772751c7e4630a3ef0fa1e0082bf4a9a..b470cdddfd08fcfc53eae4ad188f33fe52f10baa 100644 (file)
@@ -20,6 +20,7 @@ import org.jetbrains.idea.maven.model.MavenArtifact;
 import org.jetbrains.idea.maven.model.MavenConstants;
 import org.jetbrains.idea.maven.project.MavenProject;
 import org.jetbrains.idea.maven.project.MavenProjectsManager;
+import org.jetbrains.idea.maven.statistics.MavenImportCollector;
 import org.jetbrains.idea.maven.utils.MavenUtil;
 import org.jetbrains.idea.maven.utils.Path;
 import org.jetbrains.idea.maven.utils.Url;
@@ -94,10 +95,16 @@ public class MavenRootModelAdapterLegacyImpl implements MavenRootModelAdapterInt
 
       if (e instanceof LibraryOrderEntry) {
         if (Registry.is("maven.always.remove.bad.entries")) {
-          if (!isMavenLibrary((LibraryOrderEntry)e)) continue;
+          if (!isMavenLibrary((LibraryOrderEntry)e)) {
+            MavenImportCollector.HAS_USER_ADDED_LIBRARY_DEP.log(myRootModel.getProject());
+            continue;
+          }
         }
         else {
-          if (!isMavenLibrary(((LibraryOrderEntry)e).getLibrary())) continue;
+          if (!isMavenLibrary(((LibraryOrderEntry)e).getLibrary())) {
+            MavenImportCollector.HAS_USER_ADDED_LIBRARY_DEP.log(myRootModel.getProject());
+            continue;
+          }
         }
       }
       if (e instanceof ModuleOrderEntry) {
@@ -105,6 +112,7 @@ public class MavenRootModelAdapterLegacyImpl implements MavenRootModelAdapterInt
         if (m != null &&
             !MavenProjectsManager.getInstance(myRootModel.getProject()).isMavenizedModule(m) &&
             ExternalSystemModulePropertyManager.getInstance(m).getExternalSystemId() == null) {
+          MavenImportCollector.HAS_USER_ADDED_MODULE_DEP.log(myRootModel.getProject());
           continue;
         }
       }
diff --git a/plugins/maven/src/main/java/org/jetbrains/idea/maven/statistics/MavenImportCollector.kt b/plugins/maven/src/main/java/org/jetbrains/idea/maven/statistics/MavenImportCollector.kt
new file mode 100644 (file)
index 0000000..1159d89
--- /dev/null
@@ -0,0 +1,24 @@
+// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
+package org.jetbrains.idea.maven.statistics
+
+import com.intellij.internal.statistic.eventLog.EventLogGroup
+import com.intellij.internal.statistic.service.fus.collectors.CounterUsagesCollector
+
+class MavenImportCollector : CounterUsagesCollector() {
+  companion object {
+    val GROUP = EventLogGroup("maven.import", 1)
+
+    @JvmField
+    val HAS_USER_ADDED_LIBRARY_DEP = GROUP.registerEvent("hasUserAddedLibraryDependency")
+
+    @JvmField
+    val HAS_USER_ADDED_MODULE_DEP = GROUP.registerEvent("hasUserAddedModuleDependency")
+
+    @JvmField
+    val HAS_USER_MODIFIED_IMPORTED_LIBRARY = GROUP.registerEvent("hasUserModifiedImportedLibrary")
+  }
+
+  override fun getGroup(): EventLogGroup {
+    return GROUP
+  }
+}
\ No newline at end of file
index 45558e1f1bfa0a8c24d7c375a72ca5a011cbb16a..ca01272c406c5e0db7a90682959a0b232a5c5c67 100644 (file)
 
     <statistics.projectUsagesCollector implementation="org.jetbrains.idea.maven.statistics.MavenSettingsCollector"/>
     <statistics.counterUsagesCollector implementationClass="org.jetbrains.idea.maven.statistics.MavenActionsUsagesCollector"/>
+    <statistics.counterUsagesCollector implementationClass="org.jetbrains.idea.maven.statistics.MavenImportCollector"/>
     <statistics.counterUsagesCollector groupId="build.maven.packagesearch" version="2"/>
 
     <registryKey key="maven.linear.import" defaultValue="false"