Search in sources :

Example 1 with BuildLocally

use of com.twinsoft.convertigo.engine.localbuild.BuildLocally in project convertigo by convertigo.

the class BuildLocallyAction method run.

@Override
public void run() {
    String actionID = action.getId();
    Engine.logEngine.debug("Running " + actionID + " action");
    parentShell = getParentShell();
    mobilePlatform = getMobilePlatform();
    final String buildDir = ConvertigoPlugin.getLocalBuildFolder();
    buildLocally = new BuildLocally(getMobilePlatform().getObject()) {

        @Override
        protected void logException(Throwable e, String message) {
            ConvertigoPlugin.logException(e, message);
        }

        @Override
        protected String getLocalBuildAdditionalPath() {
            return ConvertigoPlugin.getLocalBuildAdditionalPath();
        }

        @Override
        protected void showLocationInstallFile(final MobilePlatform mobilePlatform, final int exitValue, final String errorLines, final String buildOption) {
            ConvertigoPlugin.getDisplay().asyncExec(new Runnable() {

                @Override
                public void run() {
                    File builtFile = getAbsolutePathOfBuiltFile(mobilePlatform, buildOption);
                    BuildLocallyEndingDialog buildSuccessDialog = new BuildLocallyEndingDialog(ConvertigoPlugin.getMainShell(), builtFile, exitValue, errorLines, mobilePlatform);
                    buildSuccessDialog.open();
                }
            });
        }

        @Override
        public File getCordovaDir() {
            return new File(buildDir + "/" + ProductVersion.productVersion + "/" + mobilePlatform.getProject().getName() + "/" + mobilePlatform.getName());
        }
    };
    if (actionID.equals("convertigo.action.buildLocallyRelease")) {
        build("release", false, "");
    }
    if (actionID.equals("convertigo.action.buildLocallyDebug")) {
        build("debug", false, "");
    }
    if (actionID.equals("convertigo.action.runLocally")) {
        build("debug", true, "device");
    }
    if (actionID.equals("convertigo.action.emulateLocally")) {
        build("debug", true, "emulator");
    }
    if (actionID.equals("convertigo.action.removeCordovaDirectory")) {
        buildLocally.removeCordovaDirectory();
    }
}
Also used : BuildLocally(com.twinsoft.convertigo.engine.localbuild.BuildLocally) MobilePlatform(com.twinsoft.convertigo.beans.core.MobilePlatform) BuildLocallyEndingDialog(com.twinsoft.convertigo.eclipse.dialogs.BuildLocallyEndingDialog) File(java.io.File)

Example 2 with BuildLocally

use of com.twinsoft.convertigo.engine.localbuild.BuildLocally in project convertigo by convertigo.

the class CLI method movePackage.

public void movePackage(Map<String, BuildLocally> localBuilders, File dir) {
    for (Entry<String, BuildLocally> localBuilder : localBuilders.entrySet()) {
        File pkg = localBuilder.getValue().getMobilePackage();
        if (pkg != null && pkg.exists()) {
            try {
                String ext = pkg.getName().replaceAll(".*(\\..*?)$", "$1");
                File dest = new File(dir, localBuilder.getValue().getMobilePlatform().getParent().getComputedApplicationName() + "_" + localBuilder.getKey() + ext);
                Engine.logEngine.info("Move package from " + pkg + " to " + dest);
                FileUtils.deleteQuietly(dest);
                dest.getParentFile().mkdirs();
                Files.move(pkg, dest);
            } catch (IOException e) {
                Engine.logConvertigo.error("Failed to move for " + localBuilder.getKey() + " package " + pkg + " to " + dir + " cause by " + e, e);
            }
        }
    }
}
Also used : BuildLocally(com.twinsoft.convertigo.engine.localbuild.BuildLocally) IOException(java.io.IOException) File(java.io.File)

Example 3 with BuildLocally

use of com.twinsoft.convertigo.engine.localbuild.BuildLocally in project convertigo by convertigo.

the class CLI method cordovaBuild.

public void cordovaBuild(Map<String, BuildLocally> localBuilders, String mode) throws EngineException {
    for (Entry<String, BuildLocally> localBuilder : localBuilders.entrySet()) {
        Engine.logConvertigo.info("Build and run on emulator ...");
        Status status;
        switch(mode) {
            case "release":
                status = localBuilder.getValue().runBuild("release", false, "device");
                break;
            case "emulator":
                status = localBuilder.getValue().runBuild("debug", true, "emulator");
                break;
            case "device":
                status = localBuilder.getValue().runBuild("debug", true, "device");
                break;
            default:
                status = localBuilder.getValue().runBuild("debug", false, "device");
                break;
        }
        Engine.logConvertigo.info("Build and run status for " + localBuilder.getKey() + ": " + status);
        File pkg = localBuilder.getValue().getMobilePackage();
        if (pkg != null) {
            Engine.logConvertigo.info("Mobile package for " + localBuilder.getKey() + ": " + pkg);
        }
    }
}
Also used : BuildLocally(com.twinsoft.convertigo.engine.localbuild.BuildLocally) Status(com.twinsoft.convertigo.engine.localbuild.BuildLocally.Status) GetBuildStatus(com.twinsoft.convertigo.engine.admin.services.mobiles.GetBuildStatus) File(java.io.File)

Example 4 with BuildLocally

use of com.twinsoft.convertigo.engine.localbuild.BuildLocally in project convertigo by convertigo.

the class CLI method main.

public static void main(String[] args) throws Exception {
    Options opts = new Options().addOption(Option.builder("p").longOpt("project").optionalArg(false).argName("dir").hasArg().desc("<dir> set the directory to load as project (default current folder).").build()).addOption(Option.builder("gc").longOpt("gitContainer").optionalArg(true).argName("path").hasArg().desc("git dependencies can be extrated to the <gitContainer> folder instead of defaults.").build()).addOption(Option.builder("g").longOpt("generate").optionalArg(true).argName("mode").hasArg().desc("generate mobilebuilder code into _private/ionic: <mode> can be production (default) or debugplus, debug, fast. If omitted, build mode is used.").build()).addOption(Option.builder("b").longOpt("build").optionalArg(true).argName("mode").hasArg().desc("build generated mobilebuilder code with NPM into DisplayObject/mobile: <mode> can be production (default) or debug. If omitted, generate mode is used.").build()).addOption(Option.builder("c").longOpt("car").desc("export as <projectName>.car file").build()).addOption(Option.builder("icdv").longOpt("installCordova").optionalArg(true).argName("platforms").hasArg().desc("check and install the cordova needed by the project for a specific platform, a list of platform separated by comma, or empty for all.").build()).addOption(Option.builder("iosprof").longOpt("iosProfile").optionalArg(false).argName("provisioningProfile").hasArg().desc("use the specified provisioningProfile for iOS builds.").build()).addOption(Option.builder("iossignid").longOpt("iosSignIdentity").optionalArg(false).argName("signIdentity").hasArg().desc("override default sign identity for ios builds (iPhone Developer / iPhone Distribution).").build()).addOption(Option.builder("andks").longOpt("androidKeystore").optionalArg(false).argName("keystore").hasArg().desc("use the specified keystore for Android builds.").build()).addOption(Option.builder("andkspass").longOpt("androidKeystorePassword").optionalArg(false).argName("keystorePassword").hasArg().desc("use this password to unlock the Android keystore.").build()).addOption(Option.builder("andalias").longOpt("androidAlias").optionalArg(false).argName("alias").hasArg().desc("use this alias to choose the right certificate in the Android keystore.").build()).addOption(Option.builder("andpass").longOpt("androidPassword").optionalArg(false).argName("password").hasArg().desc("use this password to unlock the Android private key.").build()).addOption(Option.builder("cdv").longOpt("cordovaBuild").optionalArg(true).argName("mode").hasArg().desc("perform a cordova build need parameter: debug (default), release, emulator, device.").build()).addOption(Option.builder("mp").longOpt("movePackage").optionalArg(false).argName("dir").hasArg().desc("move native mobile package after a cordova build to the <dir> folder.").build()).addOption(Option.builder("nb").longOpt("nativeBuild").optionalArg(true).argName("platforms").hasArg().desc("perform and download a remote cordova build of the application. Launch build and download for all mobile platforms or add the optional <platforms> parameter with list of plaform separated by coma: Android,IOs.").build()).addOption(Option.builder("lrb").longOpt("launchRemoteBuild").optionalArg(true).argName("platforms").hasArg().desc("perform a remote cordova build of the application. Launch build for all mobile platforms or add the optional <platforms> parameter with list of plaform separated by coma: Android,IOs.").build()).addOption(Option.builder("drb").longOpt("downloadRemoteBuild").optionalArg(true).argName("platforms").hasArg().desc("download a remote cordova build of the application. Download from previous launch, all mobile platforms or add the optional <platforms> parameter with list of plaform separated by coma: Android,IOs.").build()).addOption(Option.builder("noTC").longOpt("excludeTestCases").desc("when export or deploy, do not include TestCases.").build()).addOption(Option.builder("noS").longOpt("excludeStubs").desc("when export or deploy, do not include Stubs.").build()).addOption(Option.builder("noMA").longOpt("excludeMobileApp").desc("when export or deploy, do not include built MobileApp.").build()).addOption(Option.builder("noMAA").longOpt("excludeMobileAppAssets").desc("when export or deploy, do not include built MobileApp assets.").build()).addOption(Option.builder("noDS").longOpt("excludeDataset").desc("when export or deploy, do not include mobile dataset.").build()).addOption(Option.builder("noPA").longOpt("excludePlatformAssets").desc("when export or deploy, do not include mobile platform assets.").build()).addOption(Option.builder("d").longOpt("deploy").optionalArg(false).argName("server").hasArg().desc("deploy the current project to <server> using user/password credentials.").build()).addOption(Option.builder("u").longOpt("user").optionalArg(false).argName("user").hasArg().desc("<user> used by the deploy action, default is 'admin'.").build()).addOption(Option.builder("w").longOpt("password").optionalArg(false).argName("password").hasArg().desc("<password> used by the deploy action, default is 'admin'.").build()).addOption(Option.builder("trust").longOpt("trustAllCertificates").desc("deploy over an https <server> without checking certificates.").build()).addOption(Option.builder("retry").longOpt("deployRetry").desc("deploy will retry <retry> times in case of failure.").build()).addOption(Option.builder("xsl").longOpt("assembleXsl").desc("assemble XSL files on deploy.").build()).addOption(Option.builder("v").longOpt("version").optionalArg(false).argName("version").hasArg().desc("change the 'version' property of the loaded <project>.").build()).addOption(Option.builder("l").longOpt("log").optionalArg(true).argName("level").hasArg().desc("optional <level> (default debug): error, info, warn, debug, trace.").build()).addOption(new Option("h", "help", false, "show this help"));
    CommandLine cmd = new DefaultParser().parse(opts, args, true);
    if (cmd.getOptions().length == 0 || cmd.hasOption("help")) {
        HelpFormatter help = new HelpFormatter();
        help.printHelp("cli", opts);
        return;
    }
    try {
        Level level = Level.OFF;
        if (cmd.hasOption("log")) {
            level = Level.toLevel(cmd.getOptionValue("log", "debug"));
        }
        Logger.getRootLogger().setLevel(level);
        Logger.getLogger("org").setLevel(Level.WARN);
        Logger.getLogger("httpclient").setLevel(Level.WARN);
        File projectDir = new File(cmd.hasOption("project") ? cmd.getOptionValue("project") : ".").getCanonicalFile();
        CLI cli = new CLI();
        String version = cmd.getOptionValue("version", null);
        String mobileApplicationEndpoint = cmd.getOptionValue("mobileApplicationEndpoint", null);
        Project project = cli.loadProject(projectDir, version, mobileApplicationEndpoint, cmd.getOptionValue("gitContainer"));
        String gMode = cmd.getOptionValue("generate", null);
        String bMode = cmd.getOptionValue("build", null);
        if (cmd.hasOption("generate") || cmd.hasOption("build")) {
            if (gMode == null && bMode != null) {
                gMode = bMode;
            }
            cli.generateMobileBuilder(project, gMode);
        }
        if (cmd.hasOption("build")) {
            if (bMode == null) {
                bMode = (gMode == null || gMode.equals("production")) ? "production" : "debug";
            }
            cli.compileMobileBuilder(project, bMode);
        }
        File file = null;
        if (cmd.hasOption("car") || cmd.hasOption("deploy")) {
            cli.export(project);
            File out = new File(projectDir, "build");
            Engine.logConvertigo.info("Building  : " + projectDir);
            file = cli.exportToCar(project, out, !cmd.hasOption("excludeTestCases"), !cmd.hasOption("excludeStubs"), !cmd.hasOption("excludeMobileApp"), !cmd.hasOption("excludeMobileAppAssets"), !cmd.hasOption("excludeDataset"), !cmd.hasOption("excludePlatformAssets"));
            Engine.logConvertigo.info("Built to: " + file);
        }
        if (cmd.hasOption("deploy")) {
            String server = cmd.getOptionValue("deploy");
            String user = cmd.getOptionValue("user", "admin");
            String password = cmd.getOptionValue("password", "admin");
            int retry = Integer.parseInt(cmd.getOptionValue("retry", "5"));
            boolean trustAllCertificates = cmd.hasOption("trust");
            boolean assembleXsl = cmd.hasOption("xsl");
            cli.deploy(file, server, user, password, trustAllCertificates, assembleXsl, retry);
        }
        if (cmd.hasOption("launchRemoteBuild") || cmd.hasOption("remoteBuild")) {
            String opt = cmd.getOptionValue("remoteBuild");
            if (opt == null) {
                opt = cmd.getOptionValue("launchRemoteBuild");
            }
            List<String> platforms = opt == null ? Collections.emptyList() : Arrays.asList(opt.split(","));
            cli.launchRemoteBuild(project, platforms);
        }
        if (cmd.hasOption("downloadRemoteBuild") || cmd.hasOption("remoteBuild")) {
            String opt = cmd.getOptionValue("remoteBuild");
            if (opt == null) {
                opt = cmd.getOptionValue("downloadRemoteBuild");
            }
            List<String> platforms = opt == null ? Collections.emptyList() : Arrays.asList(opt.split(","));
            List<File> files = cli.downloadRemoteBuild(project, platforms, new File(project.getDirFile(), "build"));
            Engine.logConvertigo.info("Downloaded application: " + files);
        }
        Map<String, BuildLocally> localBuilders = null;
        if (cmd.hasOption("icdv") || cmd.hasOption("cdv")) {
            String opt = cmd.getOptionValue("icdv");
            List<String> platforms = opt == null ? Collections.emptyList() : Arrays.asList(opt.split(","));
            localBuilders = cli.installCordova(project, platforms);
        }
        if (cmd.hasOption("iosprof") && cmd.hasOption("cdv")) {
            String provisioningProfile = cmd.getOptionValue("iosprof");
            String signId = cmd.getOptionValue("iossignid");
            cli.configureSignIOS(localBuilders, new File(provisioningProfile), signId);
        }
        if (cmd.hasOption("andks") && cmd.hasOption("cdv")) {
            String keystore = cmd.getOptionValue("andks");
            String keystorePassword = cmd.getOptionValue("andkspass");
            String alias = cmd.getOptionValue("alias");
            String password = cmd.getOptionValue("andpass");
            cli.configureSignAndroid(localBuilders, new File(keystore), keystorePassword, alias, password);
        }
        if (cmd.hasOption("cdv")) {
            String opt = cmd.getOptionValue("cdv");
            cli.cordovaBuild(localBuilders, opt);
        }
        if (cmd.hasOption("mp")) {
            File dir = new File(cmd.getOptionValue("mp"));
            cli.movePackage(localBuilders, dir);
        }
        Engine.logConvertigo.info("Operations terminated!");
    } finally {
    }
}
Also used : BuildLocally(com.twinsoft.convertigo.engine.localbuild.BuildLocally) Options(org.apache.commons.cli.Options) HelpFormatter(org.apache.commons.cli.HelpFormatter) Project(com.twinsoft.convertigo.beans.core.Project) CommandLine(org.apache.commons.cli.CommandLine) Option(org.apache.commons.cli.Option) ArchiveExportOption(com.twinsoft.convertigo.engine.enums.ArchiveExportOption) Level(org.apache.log4j.Level) File(java.io.File) DefaultParser(org.apache.commons.cli.DefaultParser)

Example 5 with BuildLocally

use of com.twinsoft.convertigo.engine.localbuild.BuildLocally in project convertigo by convertigo.

the class CLI method installCordova.

public Map<String, BuildLocally> installCordova(Project project, List<String> platforms) throws EngineException {
    List<MobilePlatform> mobilePlatforms;
    MobileApplication mobileApplication = project.getMobileApplication();
    if (platforms == null || platforms.isEmpty()) {
        mobilePlatforms = mobileApplication.getMobilePlatformList();
    } else {
        mobilePlatforms = new ArrayList<>(platforms.size());
        for (String platform : platforms) {
            try {
                mobilePlatforms.add(mobileApplication.getMobilePlatformByName(platform));
            } catch (EngineException e) {
                Engine.logConvertigo.error("Failed to find the mobile platform: " + platform, e);
            }
        }
    }
    Map<String, BuildLocally> localBuilders = new HashMap<>(mobilePlatforms.size());
    for (MobilePlatform platform : mobilePlatforms) {
        if (platform instanceof IOs && !Engine.isMac()) {
            Engine.logConvertigo.info("Skip IOs build because this is not Mac OS.");
            continue;
        }
        BuildLocally localBuilder = new BuildLocally(platform) {

            @Override
            protected void showLocationInstallFile(MobilePlatform mobilePlatform, int exitValue, String errorLines, String buildOption) {
                Engine.logConvertigo.error("BuildLocally location: " + exitValue + " error: " + errorLines + " options: " + buildOption);
            }

            @Override
            protected void logException(Throwable e, String message) {
                Engine.logConvertigo.error("BuildLocally exception: " + message, e);
            }

            @Override
            protected String getLocalBuildAdditionalPath() {
                // TODO Auto-generated method stub
                return null;
            }
        };
        Engine.logConvertigo.info("Checking cordova ...");
        Status status = localBuilder.installCordova();
        Engine.logConvertigo.info("Cordova: " + status);
        localBuilders.put(platform.getName(), localBuilder);
    }
    return localBuilders;
}
Also used : BuildLocally(com.twinsoft.convertigo.engine.localbuild.BuildLocally) Status(com.twinsoft.convertigo.engine.localbuild.BuildLocally.Status) GetBuildStatus(com.twinsoft.convertigo.engine.admin.services.mobiles.GetBuildStatus) MobilePlatform(com.twinsoft.convertigo.beans.core.MobilePlatform) HashMap(java.util.HashMap) MobileApplication(com.twinsoft.convertigo.beans.core.MobileApplication) IOs(com.twinsoft.convertigo.beans.mobileplatforms.IOs)

Aggregations

BuildLocally (com.twinsoft.convertigo.engine.localbuild.BuildLocally)6 File (java.io.File)4 MobilePlatform (com.twinsoft.convertigo.beans.core.MobilePlatform)2 GetBuildStatus (com.twinsoft.convertigo.engine.admin.services.mobiles.GetBuildStatus)2 Status (com.twinsoft.convertigo.engine.localbuild.BuildLocally.Status)2 MobileApplication (com.twinsoft.convertigo.beans.core.MobileApplication)1 Project (com.twinsoft.convertigo.beans.core.Project)1 IOs (com.twinsoft.convertigo.beans.mobileplatforms.IOs)1 BuildLocallyEndingDialog (com.twinsoft.convertigo.eclipse.dialogs.BuildLocallyEndingDialog)1 CLI (com.twinsoft.convertigo.engine.CLI)1 ArchiveExportOption (com.twinsoft.convertigo.engine.enums.ArchiveExportOption)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 CommandLine (org.apache.commons.cli.CommandLine)1 DefaultParser (org.apache.commons.cli.DefaultParser)1 HelpFormatter (org.apache.commons.cli.HelpFormatter)1 Option (org.apache.commons.cli.Option)1 Options (org.apache.commons.cli.Options)1 Level (org.apache.log4j.Level)1 TaskAction (org.gradle.api.tasks.TaskAction)1