Home | History | Annotate | Download | only in setup
      1 /*******************************************************************************
      2  * Copyright 2011 See AUTHORS file.
      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.badlogic.gdx.setup;
     18 
     19 import java.util.List;
     20 import java.util.Map;
     21 
     22 public class ExternalExtension {
     23 
     24 	private String name;
     25 	private String[] gwtInherits;
     26 	private String description;
     27 	private String version;
     28 
     29 	private Map<String, List<ExternalExtensionDependency>> dependencies;
     30 
     31 	public ExternalExtension (String name, String[] gwtInherits, String description, String version) {
     32 		this.name = name;
     33 		this.gwtInherits = gwtInherits;
     34 		this.description = description;
     35 		this.version = version;
     36 	}
     37 
     38 	public void setDependencies (Map<String, List<ExternalExtensionDependency>> dependencies) {
     39 		this.dependencies = dependencies;
     40 	}
     41 
     42 	public Dependency generateDependency () {
     43 		Dependency dep = new Dependency(name, gwtInherits, getPlatformDependencies("core"), getPlatformDependencies("desktop"),
     44 			getPlatformDependencies("android"), getPlatformDependencies("ios"), getPlatformDependencies("html"));
     45 
     46 		return dep;
     47 	}
     48 
     49 	private String[] getPlatformDependencies (String platformName) {
     50 		if (dependencies.get(platformName) == null) {
     51 			return null;
     52 		} else if (dependencies.get(platformName) != null && dependencies.get(platformName).size() == 0) {
     53 			return new String[] {};
     54 		} else {
     55 			String[] arr = new String[dependencies.get(platformName).size()];
     56 			for (int i = 0; i < dependencies.get(platformName).size(); i++) {
     57 				ExternalExtensionDependency dependency = dependencies.get(platformName).get(i);
     58 				if (dependency.external) {
     59 					arr[i] = dependency.text;
     60 				} else {
     61 					String[] split = dependency.text.split(":");
     62 					if (split.length == 3) {
     63 						arr[i] = split[0] + ":" + split[1] + ":" + version + ":" + split[2];
     64 					} else {
     65 						arr[i] = dependency.text + ":" + version;
     66 					}
     67 				}
     68 			}
     69 			return arr;
     70 		}
     71 	}
     72 
     73 	public String getName () {
     74 		return name;
     75 	}
     76 }
     77