// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package org.jetbrains.plugins.gradle.model.data;

import com.intellij.openapi.externalSystem.model.Key;
import com.intellij.openapi.externalSystem.model.ProjectKeys;
import com.intellij.openapi.externalSystem.model.ProjectSystemId;
import com.intellij.openapi.externalSystem.model.project.AbstractExternalEntityData;
import com.intellij.serialization.PropertyMapping;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.io.File;
import java.io.Serializable;
import java.util.List;
import java.util.Set;

public final class BuildScriptClasspathData extends AbstractExternalEntityData {
  @NotNull
  public static final Key<BuildScriptClasspathData> KEY =
    Key.create(BuildScriptClasspathData.class, ProjectKeys.LIBRARY_DEPENDENCY.getProcessingWeight() + 1);

  @Nullable
  private File gradleHomeDir;

  @NotNull
  private final List<ClasspathEntry> classpathEntries;

  @PropertyMapping({"owner", "classpathEntries"})
  public BuildScriptClasspathData(@NotNull ProjectSystemId owner, @NotNull List<ClasspathEntry> classpathEntries) {
    super(owner);

    this.classpathEntries = classpathEntries;
  }

  @Nullable
  public File getGradleHomeDir() {
    return gradleHomeDir;
  }

  public void setGradleHomeDir(@Nullable File gradleHomeDir) {
    this.gradleHomeDir = gradleHomeDir;
  }

  @NotNull
  public List<ClasspathEntry> getClasspathEntries() {
    return classpathEntries;
  }

  public static class ClasspathEntry implements Serializable {

    private static final long serialVersionUID = 1L;

    @NotNull
    private final Set<String> myClassesFile;

    @NotNull
    private final Set<String> mySourcesFile;

    @NotNull
    private final Set<String> myJavadocFile;

    public ClasspathEntry(@NotNull Set<String> classesFile, @NotNull Set<String> sourcesFile, @NotNull Set<String> javadocFile) {
      myClassesFile = classesFile;
      mySourcesFile = sourcesFile;
      myJavadocFile = javadocFile;
    }

    @NotNull
    public Set<String> getClassesFile() {
      return myClassesFile;
    }

    @NotNull
    public Set<String> getSourcesFile() {
      return mySourcesFile;
    }

    @NotNull
    public Set<String> getJavadocFile() {
      return myJavadocFile;
    }

    @Override
    public boolean equals(Object o) {
      if (this == o) return true;
      if (!(o instanceof ClasspathEntry)) return false;

      ClasspathEntry entry = (ClasspathEntry)o;

      if (!myClassesFile.equals(entry.myClassesFile)) return false;
      if (!myJavadocFile.equals(entry.myJavadocFile)) return false;
      if (!mySourcesFile.equals(entry.mySourcesFile)) return false;

      return true;
    }

    @Override
    public int hashCode() {
      int result = myClassesFile.hashCode();
      result = 31 * result + mySourcesFile.hashCode();
      result = 31 * result + myJavadocFile.hashCode();
      return result;
    }
  }
}

@@ -613,37 +613,8 @@
 le;%0A
-import java.io.Serializable;%0A
 impo
@@ -1559,16 +1559,22 @@
  static 
+final 
 class Cl
@@ -1590,88 +1590,9 @@
 try 
-implements Serializable %7B%0A%0A    private static final long serialVersionUID = 1L;%0A
+%7B
 %0A   
@@ -1631,19 +1631,17 @@
 String%3E 
-myC
+c
 lassesFi
@@ -1688,19 +1688,17 @@
 String%3E 
-myS
+s
 ourcesFi
@@ -1745,19 +1745,17 @@
 String%3E 
-myJ
+j
 avadocFi
@@ -1755,24 +1755,92 @@
 vadocFile;%0A%0A
+    @PropertyMapping(%7B%22classesFile%22, %22sourcesFile%22, %22javadocFile%22%7D)%0A
     public C
@@ -1963,19 +1963,22 @@
 %7B%0A      
-myC
+this.c
 lassesFi
@@ -2001,19 +2001,22 @@
 ;%0A      
-myS
+this.s
 ourcesFi
@@ -2039,19 +2039,22 @@
 ;%0A      
-myJ
+this.j
 avadocFi
@@ -2146,19 +2146,17 @@
  return 
-myC
+c
 lassesFi
@@ -2234,19 +2234,17 @@
  return 
-myS
+s
 ourcesFi
@@ -2322,19 +2322,17 @@
  return 
-myJ
+j
 avadocFi
@@ -2545,19 +2545,17 @@
    if (!
-myC
+c
 lassesFi
@@ -2570,19 +2570,17 @@
 s(entry.
-myC
+c
 lassesFi
@@ -2609,19 +2609,17 @@
    if (!
-myJ
+j
 avadocFi
@@ -2634,19 +2634,17 @@
 s(entry.
-myJ
+j
 avadocFi
@@ -2673,19 +2673,17 @@
    if (!
-myS
+s
 ourcesFi
@@ -2698,19 +2698,17 @@
 s(entry.
-myS
+s
 ourcesFi
@@ -2818,11 +2818,9 @@
 t = 
-myC
+c
 lass
@@ -2871,11 +2871,9 @@
 t + 
-myS
+s
 ourc
@@ -2924,11 +2924,9 @@
 t + 
-myJ
+j
 avad

annotate ClasspathEntry