ada.project/src/org/netbeans/modules/ada/project/ui/actions/RebuildCommand.java
author Andrea Lucarelli <raster@netbeans.org>
Sun, 22 Aug 2010 23:37:11 +0200
branchrelease68
changeset 16367 d2820c029d3a
parent 15779 367c7fdb5d23
permissions -rw-r--r--
Add JVM compiler support.
raster@14352
     1
/*
raster@14352
     2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
raster@14352
     3
 *
raster@14352
     4
 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
raster@14352
     5
 *
raster@14352
     6
 * The contents of this file are subject to the terms of either the GNU
raster@14352
     7
 * General Public License Version 2 only ("GPL") or the Common
raster@14352
     8
 * Development and Distribution License("CDDL") (collectively, the
raster@14352
     9
 * "License"). You may not use this file except in compliance with the
raster@14352
    10
 * License. You can obtain a copy of the License at
raster@14352
    11
 * http://www.netbeans.org/cddl-gplv2.html
raster@14352
    12
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
raster@14352
    13
 * specific language governing permissions and limitations under the
raster@14352
    14
 * License.  When distributing the software, include this License Header
raster@14352
    15
 * Notice in each file and include the License file at
raster@14352
    16
 * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
raster@14352
    17
 * particular file as subject to the "Classpath" exception as provided
raster@14352
    18
 * by Sun in the GPL Version 2 section of the License file that
raster@14352
    19
 * accompanied this code. If applicable, add the following below the
raster@14352
    20
 * License Header, with the fields enclosed by brackets [] replaced by
raster@14352
    21
 * your own identifying information:
raster@14352
    22
 * "Portions Copyrighted [year] [name of copyright owner]"
raster@14352
    23
 *
raster@14352
    24
 * If you wish your version of this file to be governed by only the CDDL
raster@14352
    25
 * or only the GPL Version 2, indicate your decision by adding
raster@14352
    26
 * "[Contributor] elects to include this software in this distribution
raster@14352
    27
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
raster@14352
    28
 * single choice of license, a recipient has the option to distribute
raster@14352
    29
 * your version of this file under either the CDDL, the GPL Version 2 or
raster@14352
    30
 * to extend the choice of license to its licensees as provided above.
raster@14352
    31
 * However, if you add GPL Version 2 code and therefore, elected the GPL
raster@14352
    32
 * Version 2 license, then the option applies only if the new code is
raster@14352
    33
 * made subject to such option by the copyright holder.
raster@14352
    34
 *
raster@14352
    35
 * Contributor(s):
raster@14352
    36
 *
raster@14352
    37
 * Portions Copyrighted 2008 Sun Microsystems, Inc.
raster@14352
    38
 */
raster@14352
    39
package org.netbeans.modules.ada.project.ui.actions;
raster@14352
    40
raster@15779
    41
import java.io.File;
raster@14352
    42
import org.netbeans.api.ada.platform.AdaPlatform;
raster@14352
    43
import org.netbeans.modules.ada.project.AdaActionProvider;
raster@14352
    44
import org.netbeans.modules.ada.project.AdaProject;
raster@14352
    45
import org.netbeans.modules.ada.project.AdaProjectUtil;
raster@14698
    46
import org.netbeans.modules.ada.project.ui.properties.AdaProjectProperties;
raster@14720
    47
import org.openide.filesystems.FileUtil;
raster@14352
    48
import org.openide.util.Lookup;
raster@14352
    49
raster@14352
    50
/**
raster@14352
    51
 *
raster@14352
    52
 * @author Andrea Lucarelli
raster@14352
    53
 */
raster@14352
    54
public class RebuildCommand extends Command {
raster@14352
    55
raster@14352
    56
    private static final String COMMAND_ID = AdaActionProvider.COMMAND_REBUILD;
raster@14352
    57
raster@14352
    58
    public RebuildCommand(AdaProject project) {
raster@14352
    59
        super(project);
raster@14352
    60
    }
raster@14352
    61
raster@14352
    62
    @Override
raster@14352
    63
    public String getCommandId() {
raster@14352
    64
        return COMMAND_ID;
raster@14352
    65
    }
raster@14352
    66
raster@14352
    67
    @Override
raster@14352
    68
    public void invokeAction(Lookup context) throws IllegalArgumentException {
raster@16367
    69
        // Retrieve project
raster@14698
    70
        final AdaProject project = getProject();
raster@15779
    71
raster@14698
    72
        // Init compiler factory
raster@16367
    73
        org.netbeans.spi.ada.platform.Compiler compiler = ActionsUtil.getCompilerFactory(project, COMMAND_ID);
raster@14698
    74
raster@14698
    75
        // Start rebuild
raster@16367
    76
        compiler.Clean();
raster@16367
    77
        compiler.Build();
raster@14352
    78
    }
raster@14352
    79
raster@14352
    80
    @Override
raster@14352
    81
    public boolean isActionEnabled(Lookup context) throws IllegalArgumentException {
raster@15779
    82
        final AdaProject project = getProject();
raster@15779
    83
        AdaPlatform platform = AdaProjectUtil.getActivePlatform(project);
raster@14352
    84
        if (platform == null) {
raster@14352
    85
            return false;
raster@15779
    86
        } else {
raster@16367
    87
            String mainFile = project.getEvaluator().getProperty(AdaProjectProperties.MAIN_FILE);
raster@16367
    88
            if (mainFile == null) {
raster@16367
    89
                return false;
raster@16367
    90
            }
raster@15779
    91
            if (!new File(FileUtil.toFile(project.getProjectDirectory()), "build").isDirectory() ||
raster@16367
    92
                    !new File(FileUtil.toFile(project.getProjectDirectory()), "dist").isDirectory()) {
raster@15779
    93
                return false;
raster@15779
    94
            }
raster@14461
    95
        }
raster@14698
    96
        return true;
raster@14352
    97
    }
raster@14352
    98
}