1 // -*- Mode: Java; indent-tabs-mode: t; tab-width: 4 -*-
2 // ---------------------------------------------------------------------------
3 // Multi-Phasic Applications: SquirrelJME
4 // Copyright (C) Stephanie Gawroriski <xer@multiphasicapps.net>
5 // ---------------------------------------------------------------------------
6 // SquirrelJME is under the GNU General Public License v3+, or later.
7 // See license.mkd for licensing and copyright information.
8 // ---------------------------------------------------------------------------
10 package cc
.squirreljme
.plugin
.util
;
12 import cc
.squirreljme
.plugin
.multivm
.VMHelpers
;
13 import lombok
.ToString
;
14 import org
.gradle
.api
.Project
;
15 import org
.gradle
.api
.artifacts
.ProjectDependency
;
16 import org
.gradle
.api
.capabilities
.Capability
;
17 import org
.gradle
.api
.tasks
.SourceSet
;
20 * Stores a dependency and a source set for proper dependency usage.
25 public class ProjectAndSourceSet
26 implements Comparable
<ProjectAndSourceSet
>
28 /** The project dependency. */
29 public final Project dependency
;
31 /** The source set used. */
32 public final String sourceSet
;
35 * Initializes the container.
37 * @param __depend The dependency to use.
38 * @throws NullPointerException On null arguments.
42 public ProjectAndSourceSet(ProjectDependency __depend
)
43 throws NullPointerException
45 this(__depend
, ProjectAndSourceSet
.__getSourceSet(__depend
));
49 * Initializes the container.
51 * @param __depend The dependency to use.
52 * @param __sourceSet The source set to target.
53 * @throws NullPointerException On null arguments.
56 public ProjectAndSourceSet(ProjectDependency __depend
,
58 throws NullPointerException
60 this(__depend
.getDependencyProject(), __sourceSet
);
64 * Initializes the container.
66 * @param __depend The dependency to use.
67 * @param __sourceSet The source set to target.
68 * @throws NullPointerException On null arguments.
71 public ProjectAndSourceSet(Project __depend
, String __sourceSet
)
72 throws NullPointerException
74 if (__depend
== null || __sourceSet
== null)
75 throw new NullPointerException("NARG");
77 this.dependency
= __depend
;
78 this.sourceSet
= __sourceSet
;
86 public int compareTo(ProjectAndSourceSet __b
)
88 // Compare by name first
89 int byName
= this.dependency
.getPath()
90 .compareTo(__b
.dependency
.getPath());
94 // Then by the source set
95 return this.sourceSet
.compareTo(__b
.sourceSet
);
103 public boolean equals(Object __o
)
108 if (!(__o
instanceof ProjectAndSourceSet
))
111 // Is this the same project?
112 ProjectAndSourceSet o
= (ProjectAndSourceSet
)__o
;
113 return this.sourceSet
.equals(o
.sourceSet
) &&
114 this.dependency
.compareTo(o
.dependency
) == 0;
122 public int hashCode()
124 return this.dependency
.getPath().hashCode() ^
125 this.sourceSet
.hashCode();
129 * Determines if this dependency is for a given source set or not.
131 * @param __depend The dependency to get from.
132 * @return The source set.
133 * @throws NullPointerException On null arguments.
136 private static String
__getSourceSet(ProjectDependency __depend
)
137 throws NullPointerException
139 if (__depend
== null)
140 throw new NullPointerException("NARG");
142 // Use test fixtures source set if the capability has this
143 for (Capability capability
: __depend
.getRequestedCapabilities())
144 if (capability
.getName()
145 .equals(__depend
.getName() + "-test-fixtures"))
146 return VMHelpers
.TEST_FIXTURES_SOURCE_SET_NAME
;
148 // Assume main source set otherwise
149 return SourceSet
.MAIN_SOURCE_SET_NAME
;