Home | History | Annotate | Download | only in internal
      1 /*
      2  * Copyright (C) 2010, 2011 The Android Open Source Project
      3  *
      4  * Licensed under the Eclipse Public License, Version 1.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.eclipse.org/org/documents/epl-v10.php
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package com.android.ide.eclipse.ndk.internal;
     18 
     19 import org.eclipse.cdt.core.templateengine.TemplateCore;
     20 import org.eclipse.cdt.core.templateengine.TemplateEngine;
     21 import org.eclipse.core.resources.IProject;
     22 import org.eclipse.core.resources.IResource;
     23 import org.eclipse.core.runtime.CoreException;
     24 import org.eclipse.core.runtime.IProgressMonitor;
     25 import org.eclipse.core.runtime.SubProgressMonitor;
     26 
     27 import java.io.File;
     28 import java.util.Map;
     29 
     30 public class NdkManager {
     31 
     32     public static final String NDK_LOCATION = "ndkLocation"; //$NON-NLS-1$
     33 
     34     public static final String LIBRARY_NAME = "libraryName"; //$NON-NLS-1$
     35 
     36     public static String getNdkLocation() {
     37         return Activator.getDefault().getPreferenceStore().getString(NDK_LOCATION);
     38     }
     39 
     40     public static boolean isNdkLocationValid() {
     41         String location = getNdkLocation();
     42         if (location.length() == 0)
     43             return false;
     44 
     45         return isValidNdkLocation(location);
     46     }
     47 
     48     public static boolean isValidNdkLocation(String location) {
     49         File dir = new File(location);
     50         if (!dir.isDirectory())
     51             return false;
     52 
     53         // Must contain the ndk-build script which we call to build
     54         if (!new File(dir, "ndk-build").isFile()) //$NON-NLS-1$
     55             return false;
     56 
     57         return true;
     58     }
     59 
     60     public static void addNativeSupport(final IProject project, Map<String, String> templateArgs,
     61             IProgressMonitor monitor)
     62             throws CoreException {
     63         // Launch our template to set up the project contents
     64         TemplateCore template = TemplateEngine.getDefault().getTemplateById("AddNdkSupport"); //$NON-NLS-1$
     65         Map<String, String> valueStore = template.getValueStore();
     66         valueStore.put("projectName", project.getName()); //$NON-NLS-1$
     67         valueStore.putAll(templateArgs);
     68         template.executeTemplateProcesses(monitor, false);
     69 
     70         // refresh project resources
     71         project.refreshLocal(IResource.DEPTH_INFINITE, new SubProgressMonitor(monitor, 10));
     72     }
     73 
     74 }
     75