Skip to content

Commit

Permalink
Merge pull request MobiVM#707 from dkimitsa/maintenance/gradle
Browse files Browse the repository at this point in the history
* maintenance -- gradle
  • Loading branch information
Tom-Ski authored Mar 20, 2023
2 parents 5ef5e46 + 84dd669 commit b9f3ca9
Show file tree
Hide file tree
Showing 11 changed files with 134 additions and 79 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1779,7 +1779,7 @@ public void read(Reader reader, File wd) throws IOException {
} catch (IOException | RuntimeException e) {
throw e;
} catch (Exception e) {
throw new IOException(e);
throw new IOException(e.getLocalizedMessage(), e);
}
// <roots> was renamed to <forceLinkClasses> but we still support
// <roots>. We need to copy <roots> to <forceLinkClasses> and set
Expand Down
13 changes: 7 additions & 6 deletions plugins/gradle/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,30 @@ To use the RoboVM plugin, include in your build script:
```groovy
// Pull the plugin from Maven Central
buildscript {
project.ext.roboVMVersion = "2.0.0-SNAPSHOT"
project.ext.roboVMGradleVersion = "2.0.0-SNAPSHOT"
ext.roboVMVersion = "2.3.19-SNAPSHOT"
repositories {
mavenCentral()
maven { url 'https://oss.sonatype.org/content/repositories/snapshots' }
}
dependencies {
classpath group: 'com.mobidevelop.robovm', name: 'robovm-gradle-plugin', version: project.roboVMGradleVersion
classpath "com.mobidevelop.robovm:robovm-gradle-plugin:${roboVMVersion}"
}
}
apply plugin: 'java'
// Apply the plugin
apply plugin: 'robovm'
repositories {
mavenLocal()
mavenCentral()
maven { url 'https://oss.sonatype.org/content/repositories/snapshots' }
}
dependencies {
compile group: 'com.mobidevelop.robovm', name: 'robovm-rt', version: project.roboVMVersion
compile group: 'com.mobidevelop.robovm', name: 'robovm-cocoatouch', version: project.roboVMVersion
implementation "com.mobidevelop.robovm:robovm-rt:${roboVMVersion}"
implementation "com.mobidevelop.robovm:robovm-cocoatouch:${roboVMVersion}"
}
robovm {
Expand Down
5 changes: 5 additions & 0 deletions plugins/gradle/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,11 @@ shadowJar {
relocate 'org.objectweb.asm', 'com.mobidevelop.robovm.asm'
}

// suppress "warning: no comment"
tasks.withType(Javadoc) {
options.addBooleanOption("Xdoclint:-missing", true)
}

signing {
required { !version.endsWith('SNAPSHOT') && gradle.taskGraph.hasTask("publish") }
sign publishing.publications.mavenJava
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package org.robovm.gradle;

import org.gradle.api.GradleException;

import javax.annotation.Nullable;
import java.util.HashSet;
import java.util.Set;

public class RoboVMGradleException extends GradleException {
public RoboVMGradleException() {
}

public RoboVMGradleException(String message) {
super(message);
}

public RoboVMGradleException(String message, @Nullable Throwable cause) {
super(buildMessage(message, cause), cause);
}

@Override
public String getLocalizedMessage() {
return super.getLocalizedMessage();
}

private static String buildMessage(String message, Throwable cause) {
if (cause == null)
return message;

try {
// combine all cause messages into single multi-line string
StringBuilder sb = new StringBuilder();
sb.append(message);
Set<Throwable> visitedCause = new HashSet<>();
Throwable c = cause;
String lastMessage = message;
int deep = 10;
while (c != null && !visitedCause.contains(c) && deep > 0) {
if (visitedCause.contains(c))
break;

visitedCause.add(c);
deep--;
String m = c.getLocalizedMessage();
if (m != null && !m.isEmpty() && (lastMessage == null || !lastMessage.equals(m))) {
sb.append('\n');
sb.append(m);
lastMessage = m;
}

if (c instanceof RoboVMGradleException) {
// its localized message has all causes already built, nothing to add there
break;
}

c = c.getCause();
}
return sb.toString();
} catch (Exception ignored) {
return message;
}
}
}
52 changes: 22 additions & 30 deletions plugins/gradle/src/main/java/org/robovm/gradle/RoboVMPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,10 @@
import org.gradle.api.Task;
import org.gradle.tooling.provider.model.ToolingModelBuilderRegistry;
import org.robovm.compiler.Version;
import org.robovm.gradle.tasks.ArchiveTask;
import org.robovm.gradle.tasks.ConsoleTask;
import org.robovm.gradle.tasks.IOSDeviceTask;
import org.robovm.gradle.tasks.IPadSimulatorTask;
import org.robovm.gradle.tasks.IPhoneSimulatorTask;
import org.robovm.gradle.tasks.InstallTask;
import org.robovm.gradle.tasks.*;
import org.robovm.gradle.tooling.ModelBuilder;

import javax.inject.Inject;
import java.util.HashMap;
import java.util.Map;

/**
* Gradle plugin that extends the Java plugin for RoboVM development.
Expand All @@ -55,31 +48,30 @@ public void apply(Project project) {
registry.register(new ModelBuilder());

project.getExtensions().create(RoboVMPluginExtension.NAME, RoboVMPluginExtension.class, project);
project.task(params(IPhoneSimulatorTask.class, "Runs your iOS app in the iPhone simulator"),
"launchIPhoneSimulator");
project.task(params(IPadSimulatorTask.class,"Runs your iOS app in the iPad simulator"),
"launchIPadSimulator");
project.task(params(IOSDeviceTask.class, "Runs your iOS app on a connected iOS device."),
"launchIOSDevice");
project.task(params(ConsoleTask.class, "Runs a console app"),"launchConsole");
project.task(params(ArchiveTask.class, "Creates .ipa file. This is an alias for the robovmArchive task"),
"createIPA");
project.task(params(ArchiveTask.class, "Compiles a binary, archives it in a format suitable for distribution and saves it to build/robovm/"),
"robovmArchive");
project.task(params(InstallTask.class, "Compiles a binary and installs it to build/robovm/"),
"robovmInstall");
registerTask(project, "launchIPhoneSimulator", IPhoneSimulatorTask.class,
"Runs your iOS app in the iPhone simulator");
registerTask(project, "launchIPadSimulator", IPadSimulatorTask.class,
"Runs your iOS app in the iPad simulator");
registerTask(project, "launchIOSDevice", IOSDeviceTask.class,
"Runs your iOS app on a connected iOS device.");
registerTask(project, "launchConsole", ConsoleTask.class, "Runs a console app");
registerTask(project, "createIPA", ArchiveTask.class,
"Creates .ipa file. This is an alias for the robovmArchive task");
registerTask(project,"robovmArchive", ArchiveTask.class,
"Compiles a binary, archives it in a format suitable for distribution and saves it to build/robovm/");
registerTask(project,"robovmInstall", InstallTask.class,
"Compiles a binary and installs it to build/robovm/");
}

private Map<String, Object> params(Class<? extends Task> task, String description) {
return params(task, description, "build"); // by default depends on build

private <T extends Task> void registerTask(Project project, String name, Class<T> type, String description) {
registerTask(project, name, type, description, "build");
}

private Map<String, Object> params(Class<? extends Task> task, String description, String... dependencies) {
Map<String, Object> params = new HashMap<>();
params.put(Task.TASK_TYPE, task);
params.put(Task.TASK_DESCRIPTION, description);
if (dependencies != null)
params.put(Task.TASK_DEPENDS_ON, dependencies);
return params;
private <T extends Task> void registerTask(Project project, String name, Class<T> type, String description, String ... dependencies) {
project.getTasks().register(name, type, task -> {
task.dependsOn((Object[]) dependencies);
task.setDescription(description);
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -216,10 +216,6 @@ public void setInstallDir(String installDir) {
this.installDir = installDir;
}

public String getLicenseKey() {
return project.hasProperty("robovm.licenseKey") ? project.getProperties().get("robovm.licenseKey").toString() : null;
}

public void setCachedir(String cacheDir) {
this.cacheDir = cacheDir;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
*/
package org.robovm.gradle.tasks;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import org.gradle.api.GradleException;
import org.robovm.compiler.AppCompiler;
import org.robovm.compiler.config.Arch;
import org.robovm.compiler.config.Config;
import org.robovm.gradle.RoboVMGradleException;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
*
Expand Down Expand Up @@ -54,9 +54,9 @@ public void invoke() {
}
} catch (IOException e) {
if (shouldArchive()) {
throw new GradleException("Failed to create archive", e);
throw new RoboVMGradleException("Failed to create archive", e);
} else {
throw new GradleException("Failed to install", e);
throw new RoboVMGradleException("Failed to install", e);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@
import org.robovm.compiler.AppCompiler;
import org.robovm.compiler.config.Arch;
import org.robovm.compiler.config.Config;
import org.robovm.compiler.config.Environment;
import org.robovm.compiler.config.OS;
import org.robovm.compiler.log.Logger;
import org.robovm.compiler.target.ios.ProvisioningProfile;
import org.robovm.compiler.target.ios.SigningIdentity;
import org.robovm.gradle.RoboVMGradleException;
import org.robovm.gradle.RoboVMPlugin;
import org.robovm.gradle.RoboVMPluginExtension;
import org.sonatype.aether.RepositorySystem;
Expand Down Expand Up @@ -106,7 +106,7 @@ public AppCompiler build(OS os, Arch arch, String targetType) {
getLogger().info("Compile RoboVM app completed.");
return compiler;
} catch (IOException e) {
throw new GradleException("Error building RoboVM executable for app", e);
throw new RoboVMGradleException("Error building RoboVM executable for app", e);
}
}

Expand All @@ -117,20 +117,20 @@ protected Config.Builder configure(Config.Builder builder) {
File propertiesFile = new File(extension.getPropertiesFile());

if (!propertiesFile.exists()) {
throw new GradleException("Invalid 'propertiesFile' specified for RoboVM compile: " + propertiesFile);
throw new RoboVMGradleException("Invalid 'propertiesFile' specified for RoboVM compile: " + propertiesFile);
}
try {
getLogger().debug(
"Including properties file in RoboVM compiler config: " + propertiesFile.getAbsolutePath());
builder.addProperties(propertiesFile);
} catch (IOException e) {
throw new GradleException("Failed to add properties file to RoboVM config: " + propertiesFile);
throw new RoboVMGradleException("Failed to add properties file to RoboVM config: " + propertiesFile);
}
} else {
try {
builder.readProjectProperties(project.getProjectDir(), false);
} catch (IOException e) {
throw new GradleException(
throw new RoboVMGradleException(
"Failed to read RoboVM project properties file(s) in "
+ project.getProjectDir().getAbsolutePath(), e);
}
Expand All @@ -140,19 +140,19 @@ protected Config.Builder configure(Config.Builder builder) {
File configFile = new File(extension.getConfigFile());

if (!configFile.exists()) {
throw new GradleException("Invalid 'configFile' specified for RoboVM compile: " + configFile);
throw new RoboVMGradleException("Invalid 'configFile' specified for RoboVM compile: " + configFile);
}
try {
getLogger().debug("Loading config file for RoboVM compiler: " + configFile.getAbsolutePath());
builder.read(configFile);
} catch (Exception e) {
throw new GradleException("Failed to read RoboVM config file: " + configFile);
throw new RoboVMGradleException("Failed to read RoboVM config file: " + configFile);
}
} else {
try {
builder.readProjectConfig(project.getProjectDir(), false);
} catch (Exception e) {
throw new GradleException(
throw new RoboVMGradleException(
"Failed to read project RoboVM config file in "
+ project.getProjectDir().getAbsolutePath(), e);
}
Expand All @@ -174,11 +174,11 @@ protected Config.Builder configure(Config.Builder builder) {
try {
FileUtils.deleteDirectory(temporaryDirectory);
} catch (IOException e) {
throw new GradleException("Failed to clean output dir " + temporaryDirectory, e);
throw new RoboVMGradleException("Failed to clean output dir " + temporaryDirectory, e);
}
temporaryDirectory.mkdirs();

builder.home(new Config.Home(unpack()))
builder.home(new Config.Home(extractSdk()))
.tmpDir(temporaryDirectory)
.skipInstall(true)
.installDir(installDir)
Expand Down Expand Up @@ -254,7 +254,9 @@ protected Config.Builder configure(Config.Builder builder) {
@TaskAction
abstract public void invoke();

protected File unpack() throws GradleException {
protected File extractSdk() throws GradleException {
getLogger().info("Checking for RoboVM SDK (downloading if required)...");

final Artifact artifact = resolveArtifact("com.mobidevelop.robovm:robovm-dist:tar.gz:nocompiler:"
+ RoboVMPlugin.getRoboVMVersion());
final File distTarFile = artifact.getFile();
Expand All @@ -269,17 +271,17 @@ protected File unpack() throws GradleException {
getLogger().info("Extracting '" + distTarFile + "' to: " + unpackedDirectory);

if (!unpackedDirectory.exists() && !unpackedDirectory.mkdirs()) {
throw new GradleException("Unable to create base directory to unpack into: " + unpackedDirectory);
throw new RoboVMGradleException("Unable to create base directory to unpack into: " + unpackedDirectory);
}

try {
extractTarGz(distTarFile, unpackedDirectory);
} catch (IOException e) {
throw new GradleException("Couldn't extract distribution tar.gz", e);
throw new RoboVMGradleException("Couldn't extract distribution tar.gz", e);
}

if (!unpackedDistDirectory.exists()) {
throw new GradleException("Unable to unpack archive");
throw new RoboVMGradleException("Unable to unpack archive");
}
}

Expand Down Expand Up @@ -307,7 +309,7 @@ protected Artifact resolveArtifact(String artifactLocator) throws GradleExceptio
try {
result = repositorySystem.resolveArtifact(repositorySystemSession, request);
} catch (ArtifactResolutionException e) {
throw new GradleException(e.getMessage(), e);
throw new RoboVMGradleException(e.getMessage(), e);
}

getLogger().debug(
Expand Down
Loading

0 comments on commit b9f3ca9

Please sign in to comment.