diff --git a/plugins/gradle/build.gradle b/plugins/gradle/build.gradle index 7fcfaede9..67b3f351d 100644 --- a/plugins/gradle/build.gradle +++ b/plugins/gradle/build.gradle @@ -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' diff --git a/plugins/gradle/src/main/java/org/robovm/gradle/RoboVMPlugin.java b/plugins/gradle/src/main/java/org/robovm/gradle/RoboVMPlugin.java index 7ba8a3a95..8da5dce25 100755 --- a/plugins/gradle/src/main/java/org/robovm/gradle/RoboVMPlugin.java +++ b/plugins/gradle/src/main/java/org/robovm/gradle/RoboVMPlugin.java @@ -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; @@ -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. * @@ -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 params(Class task, String description) { + return params(task, description, "build"); // by default depends on build + } + + private Map params(Class task, String description, String... dependencies) { + Map 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; } } diff --git a/plugins/gradle/src/main/java/org/robovm/gradle/tasks/AbstractRoboVMTask.java b/plugins/gradle/src/main/java/org/robovm/gradle/tasks/AbstractRoboVMTask.java index ed5c092d5..3deb9ee89 100755 --- a/plugins/gradle/src/main/java/org/robovm/gradle/tasks/AbstractRoboVMTask.java +++ b/plugins/gradle/src/main/java/org/robovm/gradle/tasks/AbstractRoboVMTask.java @@ -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; @@ -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 @@ -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() { - { - 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); } @@ -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() { @@ -371,9 +363,10 @@ private List 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) { @@ -381,22 +374,46 @@ private static void extractTarGz(File archive, File destDir) throws IOException 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 { diff --git a/plugins/gradle/src/main/resources/META-INF/services/org.robovm.compiler.plugin.LaunchPlugin b/plugins/gradle/src/main/resources/META-INF/services/org.robovm.compiler.plugin.LaunchPlugin new file mode 100755 index 000000000..c5b6e36da --- /dev/null +++ b/plugins/gradle/src/main/resources/META-INF/services/org.robovm.compiler.plugin.LaunchPlugin @@ -0,0 +1 @@ +org.robovm.debugger.DebuggerLaunchPlugin diff --git a/plugins/idea/src/main/java/org/robovm/idea/RoboVmPlugin.java b/plugins/idea/src/main/java/org/robovm/idea/RoboVmPlugin.java index b79a3e1b2..510e97844 100755 --- a/plugins/idea/src/main/java/org/robovm/idea/RoboVmPlugin.java +++ b/plugins/idea/src/main/java/org/robovm/idea/RoboVmPlugin.java @@ -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))); @@ -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; } @@ -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) {