Skip to content

Commit

Permalink
Gradle maintenance (#292)
Browse files Browse the repository at this point in the history
* * added dependency to 'build' task and description to RoboVM related commands

* * added logic to clean cache if sdk files changed. also sdk folder now is not unpacked on every launch

* * added debugger

* * typos and wording update
  • Loading branch information
dkimitsa authored and florianf committed May 19, 2018
1 parent a67781c commit 73c3cdd
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 43 deletions.
1 change: 1 addition & 0 deletions plugins/gradle/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ dependencies {
compileOnly localGroovy()
compile "org.apache.commons:commons-compress:1.5"
compile "com.mobidevelop.robovm:robovm-dist-compiler:${roboVMVersion}"
compile "com.mobidevelop.robovm:robovm-debugger:${roboVMVersion}"
compile 'org.sonatype.aether:aether:1.13.1'
compile 'org.sonatype.aether:aether-connector-wagon:1.13.1'
compile 'org.apache.maven:maven-aether-provider:3.0.4'
Expand Down
39 changes: 30 additions & 9 deletions plugins/gradle/src/main/java/org/robovm/gradle/RoboVMPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@
*/
package org.robovm.gradle;

import java.util.Collections;

import org.gradle.api.Plugin;
import org.gradle.api.Project;
import org.gradle.api.Task;
import org.robovm.compiler.Version;
import org.robovm.gradle.tasks.ArchiveTask;
import org.robovm.gradle.tasks.ConsoleTask;
Expand All @@ -27,6 +26,9 @@
import org.robovm.gradle.tasks.IPhoneSimulatorTask;
import org.robovm.gradle.tasks.InstallTask;

import java.util.HashMap;
import java.util.Map;

/**
* Gradle plugin that extends the Java plugin for RoboVM development.
*
Expand All @@ -41,12 +43,31 @@ public static String getRoboVMVersion() {
@Override
public void apply(Project project) {
project.getExtensions().create(RoboVMPluginExtension.NAME, RoboVMPluginExtension.class, project);
project.task(Collections.singletonMap("type", IPhoneSimulatorTask.class), "launchIPhoneSimulator");
project.task(Collections.singletonMap("type", IPadSimulatorTask.class), "launchIPadSimulator");
project.task(Collections.singletonMap("type", IOSDeviceTask.class), "launchIOSDevice");
project.task(Collections.singletonMap("type", ConsoleTask.class), "launchConsole");
project.task(Collections.singletonMap("type", ArchiveTask.class), "createIPA");
project.task(Collections.singletonMap("type", ArchiveTask.class), "robovmArchive");
project.task(Collections.singletonMap("type", InstallTask.class), "robovmInstall");
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");
}

private Map<String, Object> params(Class<? extends Task> task, String description) {
return params(task, description, "build"); // by default depends on 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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,6 @@
*/
package org.robovm.gradle.tasks;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Set;
import java.util.zip.GZIPInputStream;

import org.apache.commons.compress.archivers.ArchiveEntry;
import org.apache.commons.compress.archivers.tar.TarArchiveEntry;
import org.apache.commons.compress.archivers.tar.TarArchiveInputStream;
Expand Down Expand Up @@ -61,6 +50,17 @@
import org.sonatype.aether.spi.connector.RepositoryConnectorFactory;
import org.sonatype.aether.util.artifact.DefaultArtifact;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Set;
import java.util.zip.GZIPInputStream;

/**
*
* @author Junji Takakura
Expand Down Expand Up @@ -254,20 +254,14 @@ protected File unpack() throws GradleException {
final File unpackedDirectory = new File(distTarFile.getParent(), "unpacked");
final File unpackedDistDirectory = new File(unpackedDirectory, "robovm-" + RoboVMPlugin.getRoboVMVersion());

if (unpackedDirectory.exists() && artifact.isSnapshot()) {
getAnt().invokeMethod("delete", new HashMap<String, Object>() {
{
put("dir", unpackedDirectory.getAbsolutePath());
}
});
}

if (unpackedDirectory.exists()) {
// for snapshot -- don't remove entire directory just override over existing files
if (unpackedDirectory.exists() && !artifact.isSnapshot()) {
getLogger().debug("Archive '" + distTarFile + "' was already unpacked in: " + unpackedDirectory);
} else {
getLogger().info("Extracting '" + distTarFile + "' to: " + unpackedDirectory);

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

Expand All @@ -280,8 +274,6 @@ protected File unpack() throws GradleException {
if (!unpackedDistDirectory.exists()) {
throw new GradleException("Unable to unpack archive");
}

getLogger().debug("Archive '" + distTarFile + "' unpacked to: " + unpackedDirectory);
}

getAnt().invokeMethod("chmod", new HashMap<String, Object>() {
Expand Down Expand Up @@ -371,32 +363,57 @@ private List<RemoteRepository> createRemoteRepositories() {
return repositories;
}

private static void extractTarGz(File archive, File destDir) throws IOException {
private void extractTarGz(File archive, File destDir) throws IOException {
TarArchiveInputStream in = null;
try {
boolean filesWereUpdated = false;
in = new TarArchiveInputStream(new GZIPInputStream(new FileInputStream(archive)));
ArchiveEntry entry = null;
while ((entry = in.getNextEntry()) != null) {
File f = new File(destDir, entry.getName());
if (entry.isDirectory()) {
f.mkdirs();
} else {
// skip extracting if file looks to be same as in archive (ts and size matches)
if (f.exists() && f.lastModified() == entry.getLastModifiedDate().getTime() && f.length() == entry.getSize()) {
continue;
}
f.getParentFile().mkdirs();
OutputStream out = null;
try {
out = new FileOutputStream(f);
IOUtils.copy(in, out);
} finally {
IOUtils.closeQuietly(out);
out = null;
// set last modification time stamp as it was inside tar otherwise
// robovm will see new time stamp and will rebuild all classes that were inside jar
f.setLastModified(entry.getLastModifiedDate().getTime());
} finally {
if (out != null)
IOUtils.closeQuietly(out);
}
}
f.setLastModified(entry.getLastModifiedDate().getTime());
if (entry instanceof TarArchiveEntry) {
int mode = ((TarArchiveEntry) entry).getMode();
if ((mode & 00100) > 0) {
// Preserve execute permissions
f.setExecutable(true, (mode & 00001) == 0);

if (entry instanceof TarArchiveEntry) {
int mode = ((TarArchiveEntry) entry).getMode();
if ((mode & 00100) > 0) {
// Preserve execute permissions
f.setExecutable(true, (mode & 00001) == 0);
}
}

// mark that there was a change to SDK files
filesWereUpdated = true;
}
}

if (filesWereUpdated) {
getLogger().debug("Archive '" + archive + "' unpacked to: " + destDir);
getLogger().info("Clearing ~/.robovm/cache folder due SDK files changed.");

File cacheDir = new File(System.getProperty("user.home"), ".robovm/cache");
try {
FileUtils.deleteDirectory(cacheDir);
} catch (IOException ignored) {
}
}
} finally {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
org.robovm.debugger.DebuggerLaunchPlugin
5 changes: 2 additions & 3 deletions plugins/idea/src/main/java/org/robovm/idea/RoboVmPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,6 @@ public static Sdk getSdk() {
private static void extractArchive(String archive, File dest) {
archive = "/" + archive;
TarArchiveInputStream in = null;
// boolean isSnapshot = Version.getVersion().toLowerCase().contains("snapshot");
try {
boolean filesWereUpdated = false;
in = new TarArchiveInputStream(new GZIPInputStream(RoboVmPlugin.class.getResourceAsStream(archive)));
Expand All @@ -427,7 +426,7 @@ private static void extractArchive(String archive, File dest) {
if (entry.isDirectory()) {
f.mkdirs();
} else {
// skip extracting if file looks to be same as it archive (ts and size matches)
// skip extracting if file looks to be same as in archive (ts and size matches)
if (f.exists() && f.lastModified() == entry.getLastModifiedDate().getTime() && f.length() == entry.getSize()) {
continue;
}
Expand All @@ -454,7 +453,7 @@ private static void extractArchive(String archive, File dest) {

if (filesWereUpdated) {
File cacheLog = new File(System.getProperty("user.home"), ".robovm/cache");
logInfo(null, "Clearing cache log folder due SDK files changed.");
logInfo(null, "Clearing ~/.robovm/cache folder due SDK files changed.");
try {
FileUtils.deleteDirectory(cacheLog);
} catch (IOException ignored) {
Expand Down

0 comments on commit 73c3cdd

Please sign in to comment.