ada.project/src/org/netbeans/modules/ada/project/ui/actions/ActionsUtil.java
branchrelease68
changeset 16367 d2820c029d3a
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/ada.project/src/org/netbeans/modules/ada/project/ui/actions/ActionsUtil.java	Sun Aug 22 23:37:11 2010 +0200
     1.3 @@ -0,0 +1,112 @@
     1.4 +/*
     1.5 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
     1.6 + *
     1.7 + * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
     1.8 + *
     1.9 + * The contents of this file are subject to the terms of either the GNU
    1.10 + * General Public License Version 2 only ("GPL") or the Common
    1.11 + * Development and Distribution License("CDDL") (collectively, the
    1.12 + * "License"). You may not use this file except in compliance with the
    1.13 + * License. You can obtain a copy of the License at
    1.14 + * http://www.netbeans.org/cddl-gplv2.html
    1.15 + * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
    1.16 + * specific language governing permissions and limitations under the
    1.17 + * License.  When distributing the software, include this License Header
    1.18 + * Notice in each file and include the License file at
    1.19 + * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
    1.20 + * particular file as subject to the "Classpath" exception as provided
    1.21 + * by Sun in the GPL Version 2 section of the License file that
    1.22 + * accompanied this code. If applicable, add the following below the
    1.23 + * License Header, with the fields enclosed by brackets [] replaced by
    1.24 + * your own identifying information:
    1.25 + * "Portions Copyrighted [year] [name of copyright owner]"
    1.26 + *
    1.27 + * If you wish your version of this file to be governed by only the CDDL
    1.28 + * or only the GPL Version 2, indicate your decision by adding
    1.29 + * "[Contributor] elects to include this software in this distribution
    1.30 + * under the [CDDL or GPL Version 2] license." If you do not indicate a
    1.31 + * single choice of license, a recipient has the option to distribute
    1.32 + * your version of this file under either the CDDL, the GPL Version 2 or
    1.33 + * to extend the choice of license to its licensees as provided above.
    1.34 + * However, if you add GPL Version 2 code and therefore, elected the GPL
    1.35 + * Version 2 license, then the option applies only if the new code is
    1.36 + * made subject to such option by the copyright holder.
    1.37 + *
    1.38 + * Contributor(s):
    1.39 + *
    1.40 + * Portions Copyrighted 2009 Sun Microsystems, Inc.
    1.41 + */
    1.42 +package org.netbeans.modules.ada.project.ui.actions;
    1.43 +
    1.44 +import java.util.ArrayList;
    1.45 +import org.netbeans.api.ada.platform.AdaPlatform;
    1.46 +import org.netbeans.modules.ada.platform.compiler.gnat.GnatCompiler;
    1.47 +import org.netbeans.modules.ada.platform.compiler.jgnat.JGnatCompiler;
    1.48 +import org.netbeans.modules.ada.project.AdaProject;
    1.49 +import org.netbeans.modules.ada.project.AdaProjectUtil;
    1.50 +import org.netbeans.modules.ada.project.options.AdaOptions;
    1.51 +import org.netbeans.modules.ada.project.ui.properties.AdaProjectProperties;
    1.52 +import org.openide.filesystems.FileObject;
    1.53 +import org.openide.filesystems.FileUtil;
    1.54 +
    1.55 +/**
    1.56 + *
    1.57 + * @author alucarelli
    1.58 + */
    1.59 +public class ActionsUtil {
    1.60 +
    1.61 +    public static org.netbeans.spi.ada.platform.Compiler getCompilerFactory(AdaProject project, String displayTitle) {
    1.62 +        org.netbeans.spi.ada.platform.Compiler compiler = null;
    1.63 +
    1.64 +        // Retrieve project and platform
    1.65 +        AdaPlatform platform = AdaProjectUtil.getActivePlatform(project);
    1.66 +        assert platform != null;
    1.67 +
    1.68 +        ArrayList<String> sources = new ArrayList<String>();
    1.69 +        FileObject[] files;
    1.70 +
    1.71 +        // Retrieve main file
    1.72 +        String mainFile = project.getEvaluator().getProperty(AdaProjectProperties.MAIN_FILE);
    1.73 +        assert mainFile != null;
    1.74 +
    1.75 +        files = project.getSourcesDirectory();
    1.76 +        for (int index = 0; index < files.length; index++) {
    1.77 +            sources.add(FileUtil.toFile(files[index]).getAbsolutePath());
    1.78 +        }
    1.79 +
    1.80 +        // Init compiler factory
    1.81 +        if (project.getEvaluator().getProperty(AdaProjectProperties.OUTPUT_BUILD_FORMAT).equalsIgnoreCase(AdaProjectProperties.NATIVE_FORMAT)) {
    1.82 +            compiler = new GnatCompiler(
    1.83 +                    platform,
    1.84 +                    project.getName(), // project name
    1.85 +                    FileUtil.toFile(project.getProjectDirectory()).getAbsolutePath(), // project location
    1.86 +                    sources, // sources location
    1.87 +                    mainFile, // main file
    1.88 +                    project.getName(), // executable file
    1.89 +                    displayTitle, // display name
    1.90 +                    project.getEvaluator().getProperty(AdaOptions.PKG_SPEC_POSTFIX),
    1.91 +                    project.getEvaluator().getProperty(AdaOptions.PKG_BODY_POSTFIX),
    1.92 +                    project.getEvaluator().getProperty(AdaOptions.SEPARATE_POSTFIX),
    1.93 +                    project.getEvaluator().getProperty(AdaOptions.PKG_SPEC_EXT),
    1.94 +                    project.getEvaluator().getProperty(AdaOptions.PKG_BODY_EXT),
    1.95 +                    project.getEvaluator().getProperty(AdaOptions.SEPARATE_EXT));
    1.96 +        } else if (project.getEvaluator().getProperty(AdaProjectProperties.OUTPUT_BUILD_FORMAT).equalsIgnoreCase(AdaProjectProperties.JVM_FORMAT)) {
    1.97 +            compiler = new JGnatCompiler(
    1.98 +                    platform,
    1.99 +                    project.getName(), // project name
   1.100 +                    FileUtil.toFile(project.getProjectDirectory()).getAbsolutePath(), // project location
   1.101 +                    sources, // sources location
   1.102 +                    mainFile, // main file
   1.103 +                    project.getName(), // executable file
   1.104 +                    displayTitle, // display name
   1.105 +                    project.getEvaluator().getProperty(AdaOptions.PKG_SPEC_POSTFIX),
   1.106 +                    project.getEvaluator().getProperty(AdaOptions.PKG_BODY_POSTFIX),
   1.107 +                    project.getEvaluator().getProperty(AdaOptions.SEPARATE_POSTFIX),
   1.108 +                    project.getEvaluator().getProperty(AdaOptions.PKG_SPEC_EXT),
   1.109 +                    project.getEvaluator().getProperty(AdaOptions.PKG_BODY_EXT),
   1.110 +                    project.getEvaluator().getProperty(AdaOptions.SEPARATE_EXT));
   1.111 +        }
   1.112 +
   1.113 +        return compiler;
   1.114 +    }
   1.115 +}