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 Mozilla Public License Version 2.0.
7 // See license.mkd for licensing and copyright information.
8 // ---------------------------------------------------------------------------
10 package cc
.squirreljme
.cicd
;
12 import cc
.squirreljme
.cicd
.circleci
.CircleCiArtifact
;
13 import cc
.squirreljme
.cicd
.circleci
.CircleCiJob
;
14 import cc
.squirreljme
.cicd
.circleci
.CircleCiJobArtifacts
;
15 import cc
.squirreljme
.cicd
.circleci
.CircleCiWorkflowJobs
;
16 import cc
.squirreljme
.runtime
.cldc
.util
.StreamUtils
;
17 import java
.io
.IOException
;
18 import java
.io
.InputStream
;
20 import java
.nio
.file
.Path
;
21 import java
.nio
.file
.Paths
;
22 import java
.util
.Arrays
;
34 * @param __args Program arguments.
35 * @throws IOException On read/write errors.
38 public static void main(String
... __args
)
41 // Needs to have something
42 if (__args
== null || __args
.length
< 1)
43 throw new IllegalArgumentException(
44 "Usage: [version] [task=output...]");
46 // Get the SquirrelJME version
47 String version
= __args
[0];
49 // Upload files into the un-versioned space
50 // romNanoCoatRelease=/home/.../squirreljme.jar
51 FossilCommand fossil
= FossilCommand
.instance();
53 for (String arg
: Arrays
.asList(__args
).subList(1, __args
.length
))
55 int eq
= arg
.indexOf('=');
59 // Split task name and the target file
60 String name
= arg
.substring(0, eq
);
61 Path path
= Paths
.get(arg
.substring(eq
+ 1));
63 // Determine target name
64 String target
= Main
.uvTarget(version
, name
);
66 // Store into un-versioned space
67 System
.err
.printf("Storing `%s` as `%s`...%n",
69 fossil
.add(path
, target
);
72 // Read in workflow jobs
73 String workflowId
= System
.getenv("CIRCLE_WORKFLOW_ID");
74 if (workflowId
!= null)
76 CircleCiWorkflowJobs jobs
= CircleCiComm
.workflowJobs(workflowId
);
78 // Go through all jobs
79 for (CircleCiJob job
: jobs
.getItems())
81 // Is this a job we care about?
85 target
= Main
.uvTarget(version
, job
.getName());
89 catch (IllegalArgumentException __ignored
)
94 // Get artifacts for this job
95 CircleCiJobArtifacts artifacts
=
96 CircleCiComm
.jobArtifacts(job
.getJobNumber());
97 for (CircleCiArtifact artifact
: artifacts
.getItems())
99 // Get the URL to the artifact
100 System
.err
.printf("Downloading `%s` as `%s`...%n",
101 artifact
.getUrl(), target
);
102 try (InputStream in
= URI
.create(artifact
.getUrl())
103 .toURL().openStream())
105 // Store into un-versioned space
106 fossil
.add(StreamUtils
.readAll(1048576, in
),
110 // Only care about the first
118 * Determines the un-versioned space target.
120 * @param __version The version of SquirrelJME.
121 * @param __name The task name.
122 * @return The resultant target.
123 * @throws IllegalArgumentException If the target is unknown.
124 * @throws NullPointerException On null arguments.
127 public static String
uvTarget(String __version
, String __name
)
128 throws IllegalArgumentException
, NullPointerException
130 if (__version
== null || __name
== null)
131 throw new NullPointerException("NARG");
133 // Determine actual name
137 case "romNanoCoatRelease":
138 name
= "squirreljme-%s-fast.jar";
141 case "romNanoCoatDebug":
142 name
= "squirreljme-%s-slow.jar";
145 case "romTestNanoCoatDebug":
146 name
= "squirreljme-%s-slow-test.jar";
149 case "build_windows_i386_standalone":
150 name
= "squirreljme-standalone-%s-windows-x86.jar";
153 case "build_windows_amd64_standalone":
154 name
= "squirreljme-standalone-%s-windows-amd64.jar";
157 case "build_macosx_arm64_standalone":
158 name
= "squirreljme-standalone-%s-macos-aarch64.jar";
161 case "build_macosx_amd64_standalone":
162 name
= "squirreljme-standalone-%s-macos-x86_64.jar";
165 case "build_linux_arm64_standalone":
166 name
= "squirreljme-standalone-%s-linux-arm64.jar";
169 case "build_linux_amd64_standalone":
170 name
= "squirreljme-standalone-%s-linux-amd64.jar";
173 case "build_linux_arm64_standalone_flatpak":
174 name
= "squirreljme-%s-arm64.flatpak";
177 case "build_linux_amd64_standalone_flatpak":
178 name
= "squirreljme-%s-amd64.flatpak";
182 throw new IllegalArgumentException(
183 "Unknown target: " + __name
);
187 return String
.format("unstable/%s",
188 String
.format(name
, __version
));