ada.project/src/org/netbeans/modules/ada/project/ui/actions/CleanCommand.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@15779
    42
import java.util.ArrayList;
raster@14461
    43
import org.netbeans.api.ada.platform.AdaPlatform;
raster@14698
    44
import org.netbeans.modules.ada.platform.compiler.gnat.GnatCompiler;
raster@14352
    45
import org.netbeans.modules.ada.project.AdaActionProvider;
raster@14352
    46
import org.netbeans.modules.ada.project.AdaProject;
raster@14461
    47
import org.netbeans.modules.ada.project.AdaProjectUtil;
raster@15779
    48
import org.netbeans.modules.ada.project.options.AdaOptions;
raster@14698
    49
import org.netbeans.modules.ada.project.ui.properties.AdaProjectProperties;
raster@15779
    50
import org.openide.filesystems.FileObject;
raster@14720
    51
import org.openide.filesystems.FileUtil;
raster@14352
    52
import org.openide.util.Lookup;
raster@14352
    53
raster@14352
    54
/**
raster@14352
    55
 *
raster@14352
    56
 * @author Andrea Lucarelli
raster@14352
    57
 */
raster@14352
    58
public class CleanCommand extends Command {
raster@14352
    59
raster@14352
    60
    private static final String COMMAND_ID = AdaActionProvider.COMMAND_CLEAN;
raster@14352
    61
raster@14352
    62
    public CleanCommand(AdaProject project) {
raster@14352
    63
        super(project);
raster@14352
    64
    }
raster@14352
    65
raster@14352
    66
    @Override
raster@14352
    67
    public String getCommandId() {
raster@14352
    68
        return COMMAND_ID;
raster@14352
    69
    }
raster@14352
    70
raster@14352
    71
    @Override
raster@14352
    72
    public void invokeAction(Lookup context) throws IllegalArgumentException {
raster@14461
    73
        final AdaProject project = getProject();
raster@14698
    74
raster@14698
    75
        // Start clean
raster@16367
    76
        ActionsUtil.getCompilerFactory(project, COMMAND_ID).Clean();
raster@14352
    77
    }
raster@14352
    78
raster@14352
    79
    @Override
raster@14352
    80
    public boolean isActionEnabled(Lookup context) throws IllegalArgumentException {
raster@15779
    81
        final AdaProject project = getProject();
raster@15779
    82
        AdaPlatform platform = AdaProjectUtil.getActivePlatform(project);
raster@14461
    83
        if (platform == null) {
raster@14461
    84
            return false;
raster@15779
    85
        } else {
raster@16367
    86
            String mainFile = project.getEvaluator().getProperty(AdaProjectProperties.MAIN_FILE);
raster@16367
    87
            if (mainFile == null) {
raster@16367
    88
                return false;
raster@16367
    89
            }
raster@15779
    90
            if (!new File(FileUtil.toFile(project.getProjectDirectory()), "build").isDirectory() ||
raster@16367
    91
                    !new File(FileUtil.toFile(project.getProjectDirectory()), "dist").isDirectory()) {
raster@15779
    92
                return false;
raster@15779
    93
            }
raster@14461
    94
        }
raster@14461
    95
        return true;
raster@14461
    96
    }
raster@14352
    97
}