ada.platform/src/org/netbeans/modules/ada/platform/compiler/jgnat/commands/JRun.java
author Andrea Lucarelli <raster@netbeans.org>
Sun, 22 Aug 2010 23:37:11 +0200
branchrelease68
changeset 16367 d2820c029d3a
permissions -rw-r--r--
Add JVM compiler support.
raster@16367
     1
/*
raster@16367
     2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
raster@16367
     3
 *
raster@16367
     4
 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
raster@16367
     5
 *
raster@16367
     6
 * The contents of this file are subject to the terms of either the GNU
raster@16367
     7
 * General Public License Version 2 only ("GPL") or the Common
raster@16367
     8
 * Development and Distribution License("CDDL") (collectively, the
raster@16367
     9
 * "License"). You may not use this file except in compliance with the
raster@16367
    10
 * License. You can obtain a copy of the License at
raster@16367
    11
 * http://www.netbeans.org/cddl-gplv2.html
raster@16367
    12
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
raster@16367
    13
 * specific language governing permissions and limitations under the
raster@16367
    14
 * License.  When distributing the software, include this License Header
raster@16367
    15
 * Notice in each file and include the License file at
raster@16367
    16
 * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
raster@16367
    17
 * particular file as subject to the "Classpath" exception as provided
raster@16367
    18
 * by Sun in the GPL Version 2 section of the License file that
raster@16367
    19
 * accompanied this code. If applicable, add the following below the
raster@16367
    20
 * License Header, with the fields enclosed by brackets [] replaced by
raster@16367
    21
 * your own identifying information:
raster@16367
    22
 * "Portions Copyrighted [year] [name of copyright owner]"
raster@16367
    23
 *
raster@16367
    24
 * If you wish your version of this file to be governed by only the CDDL
raster@16367
    25
 * or only the GPL Version 2, indicate your decision by adding
raster@16367
    26
 * "[Contributor] elects to include this software in this distribution
raster@16367
    27
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
raster@16367
    28
 * single choice of license, a recipient has the option to distribute
raster@16367
    29
 * your version of this file under either the CDDL, the GPL Version 2 or
raster@16367
    30
 * to extend the choice of license to its licensees as provided above.
raster@16367
    31
 * However, if you add GPL Version 2 code and therefore, elected the GPL
raster@16367
    32
 * Version 2 license, then the option applies only if the new code is
raster@16367
    33
 * made subject to such option by the copyright holder.
raster@16367
    34
 *
raster@16367
    35
 * Contributor(s):
raster@16367
    36
 *
raster@16367
    37
 * Portions Copyrighted 2008 Sun Microsystems, Inc.
raster@16367
    38
 */
raster@16367
    39
package org.netbeans.modules.ada.platform.compiler.jgnat.commands;
raster@16367
    40
raster@16367
    41
import java.util.concurrent.Future;
raster@16367
    42
import org.netbeans.api.ada.platform.AdaException;
raster@16367
    43
import org.netbeans.api.ada.platform.AdaExecution;
raster@16367
    44
import org.netbeans.modules.ada.platform.compiler.jgnat.JGnatProject;
raster@16367
    45
import org.netbeans.modules.ada.platform.compiler.jgnat.JGnatCompiler;
raster@16367
    46
import org.openide.util.Exceptions;
raster@16367
    47
raster@16367
    48
/**
raster@16367
    49
 *
raster@16367
    50
 * @author Andrea Lucarelli
raster@16367
    51
 */
raster@16367
    52
public class JRun extends JGnatCommand {
raster@16367
    53
raster@16367
    54
    private static final String COMMAND_ID = RUN;
raster@16367
    55
raster@16367
    56
    public JRun(JGnatCompiler jgnatCompiler) {
raster@16367
    57
        super(jgnatCompiler);
raster@16367
    58
    }
raster@16367
    59
raster@16367
    60
    @Override
raster@16367
    61
    public String getCommandId() {
raster@16367
    62
        return COMMAND_ID;
raster@16367
    63
    }
raster@16367
    64
raster@16367
    65
    @Override
raster@16367
    66
    public void invokeCommand(String displayTitle, String args) throws IllegalArgumentException, AdaException {
raster@16367
    67
raster@16367
    68
        // Make the GPR file
raster@16367
    69
        JGnatProject gpr = new JGnatProject(this.getJGnatCompiler());
raster@16367
    70
        gpr.write();
raster@16367
    71
raster@16367
    72
        try {
raster@16367
    73
            AdaExecution adaExec = new AdaExecution();
raster@16367
    74
            adaExec.setCommand(this.getJGnatCompiler().getProjectPath() + "/dist/" + this.getJGnatCompiler().getExecutableFile());
raster@16367
    75
            adaExec.setCommandArgs(args);
raster@16367
    76
            adaExec.setWorkingDirectory(this.getJGnatCompiler().getProjectPath());
raster@16367
    77
            adaExec.setDisplayName(displayTitle);
raster@16367
    78
            adaExec.setShowControls(true);
raster@16367
    79
            adaExec.setShowInput(false);
raster@16367
    80
            adaExec.setShowWindow(true);
raster@16367
    81
            adaExec.setShowProgress(true);
raster@16367
    82
            adaExec.setShowSuspended(true);
raster@16367
    83
            //adaExec.attachOutputProcessor();
raster@16367
    84
            adaExec.setRedirectError(true);
raster@16367
    85
            Future<Integer> result = adaExec.run();
raster@16367
    86
            Integer value = result.get();
raster@16367
    87
            if (value.intValue() == 0) {
raster@16367
    88
            } else {
raster@16367
    89
            }
raster@16367
    90
        } catch (Exception ex) {
raster@16367
    91
            Exceptions.printStackTrace(ex);
raster@16367
    92
        }
raster@16367
    93
raster@16367
    94
    }
raster@16367
    95
}