Home | History | Annotate | Download | only in interpreter
      1 /*
      2  * Copyright (C) 2017 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0
      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.googlecode.android_scripting.interpreter;
     18 
     19 import android.content.Context;
     20 
     21 import java.io.File;
     22 import java.util.ArrayList;
     23 import java.util.HashMap;
     24 import java.util.List;
     25 import java.util.Map;
     26 
     27 /**
     28  * A description of the interpreters hosted by the SL4A project.
     29  *
     30  */
     31 public abstract class Sl4aHostedInterpreter implements InterpreterDescriptor {
     32 
     33   public static final String BASE_INSTALL_URL = "http://android-scripting.googlecode.com/files/";
     34   public static final String DALVIKVM = "/system/bin/dalvikvm";
     35 
     36   // TODO(damonkohler): Remove getVersion() and pull these three version methods up in to the base
     37   // class.
     38 
     39   public String getBaseInstallUrl() {
     40     return BASE_INSTALL_URL;
     41   }
     42 
     43   public int getInterpreterVersion() {
     44     return getVersion();
     45   }
     46 
     47   public int getExtrasVersion() {
     48     return getVersion();
     49   }
     50 
     51   public int getScriptsVersion() {
     52     return getVersion();
     53   }
     54 
     55   @Override
     56   public String getInterpreterArchiveName() {
     57     return String.format("%s_r%s.zip", getName(), getInterpreterVersion());
     58   }
     59 
     60   @Override
     61   public String getExtrasArchiveName() {
     62     return String.format("%s_extras_r%s.zip", getName(), getExtrasVersion());
     63   }
     64 
     65   @Override
     66   public String getScriptsArchiveName() {
     67     return String.format("%s_scripts_r%s.zip", getName(), getScriptsVersion());
     68   }
     69 
     70   @Override
     71   public String getInterpreterArchiveUrl() {
     72     return getBaseInstallUrl() + getInterpreterArchiveName();
     73   }
     74 
     75   @Override
     76   public String getExtrasArchiveUrl() {
     77     return getBaseInstallUrl() + getExtrasArchiveName();
     78   }
     79 
     80   @Override
     81   public String getScriptsArchiveUrl() {
     82     return getBaseInstallUrl() + getScriptsArchiveName();
     83   }
     84 
     85   @Override
     86   public String getInteractiveCommand(Context context) {
     87     return "";
     88   }
     89 
     90   @Override
     91   public boolean hasInteractiveMode() {
     92     return true;
     93   }
     94 
     95   @Override
     96   public String getScriptCommand(Context context) {
     97     return "%s";
     98   }
     99 
    100   @Override
    101   public List<String> getArguments(Context context) {
    102     return new ArrayList<String>();
    103   }
    104 
    105   @Override
    106   public Map<String, String> getEnvironmentVariables(Context context) {
    107     return new HashMap<String, String>();
    108   }
    109 
    110   // TODO(damonkohler): This shouldn't be public.
    111   public File getExtrasPath(Context context) {
    112     if (!hasInterpreterArchive() && hasExtrasArchive()) {
    113       return new File(InterpreterConstants.SDCARD_ROOT + this.getClass().getPackage().getName()
    114           + InterpreterConstants.INTERPRETER_EXTRAS_ROOT, getName());
    115     }
    116     return InterpreterUtils.getInterpreterRoot(context, getName());
    117   }
    118 }
    119