Commonize into PathUtils; On Linux/BSD try to use xdg-open/x-www-browser if Java...
[SquirrelJME.git] / buildSrc / src / main / java / cc / squirreljme / plugin / util / ProjectAndSourceSet.java
blob65ac16e38908d55bc01ff2d90ab52d38e5e9a039
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;
19 /**
20 * Stores a dependency and a source set for proper dependency usage.
22 * @since 2022/08/07
24 @ToString
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;
34 /**
35 * Initializes the container.
37 * @param __depend The dependency to use.
38 * @throws NullPointerException On null arguments.
39 * @since 2022/08/07
42 public ProjectAndSourceSet(ProjectDependency __depend)
43 throws NullPointerException
45 this(__depend, ProjectAndSourceSet.__getSourceSet(__depend));
48 /**
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.
54 * @since 2022/08/07
56 public ProjectAndSourceSet(ProjectDependency __depend,
57 String __sourceSet)
58 throws NullPointerException
60 this(__depend.getDependencyProject(), __sourceSet);
63 /**
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.
69 * @since 2022/08/07
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;
81 /**
82 * {@inheritDoc}
83 * @since 2022/08/07
85 @Override
86 public int compareTo(ProjectAndSourceSet __b)
88 // Compare by name first
89 int byName = this.dependency.getPath()
90 .compareTo(__b.dependency.getPath());
91 if (byName != 0)
92 return byName;
94 // Then by the source set
95 return this.sourceSet.compareTo(__b.sourceSet);
98 /**
99 * {@inheritDoc}
100 * @since 2022/08/07
102 @Override
103 public boolean equals(Object __o)
105 if (__o == this)
106 return true;
108 if (!(__o instanceof ProjectAndSourceSet))
109 return false;
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;
118 * {@inheritDoc}
119 * @since 2022/08/07
121 @Override
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.
134 * @since 2022/08/07
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;