1 /* 2 * Copyright (C) 2012 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 package com.motorolamobility.preflighting.internal; 17 18 import java.util.ArrayList; 19 import java.util.Arrays; 20 import java.util.List; 21 22 import org.eclipse.core.runtime.IBundleGroup; 23 import org.eclipse.core.runtime.IBundleGroupProvider; 24 import org.eclipse.core.runtime.Platform; 25 import org.eclipse.core.runtime.Plugin; 26 import org.osgi.framework.Bundle; 27 import org.osgi.framework.BundleActivator; 28 import org.osgi.framework.BundleContext; 29 import org.osgi.framework.Version; 30 31 import com.motorolamobility.preflighting.core.PreflightingCorePlugin; 32 import com.motorolamobility.preflighting.core.logging.PreflightingLogger; 33 34 public class PreflightingPlugin extends Plugin implements BundleActivator 35 { 36 private static PreflightingPlugin instance; 37 38 private String appValidatorVersion = null; 39 40 private static final String COM_MOTOROLAMOBILITY_PREFLIGHTING_FEATURE = 41 "com.motorolamobility.preflighting.feature"; 42 43 public PreflightingPlugin() 44 { 45 instance = this; 46 } 47 48 @Override 49 public void start(BundleContext context) throws Exception 50 { 51 PreflightingLogger.debug(PreflightingPlugin.class, "Starting Preflighting Plugin..."); 52 53 super.start(context); 54 55 PreflightingLogger.debug(PreflightingPlugin.class, "Preflighting Plugin started..."); 56 } 57 58 public static PreflightingPlugin getInstance() 59 { 60 return instance; 61 } 62 63 private void readAppValidatorVersion() 64 { 65 IBundleGroupProvider[] providers = Platform.getBundleGroupProviders(); 66 List<IBundleGroup> groups = new ArrayList<IBundleGroup>(); 67 if (providers != null) 68 { 69 for (int i = 0; i < providers.length; ++i) 70 { 71 IBundleGroup[] bundleGroups = providers[i].getBundleGroups(); 72 groups.addAll(Arrays.asList(bundleGroups)); 73 } 74 } 75 for (IBundleGroup group : groups) 76 { 77 if (group.getIdentifier().equals(COM_MOTOROLAMOBILITY_PREFLIGHTING_FEATURE)) 78 { 79 appValidatorVersion = group.getVersion(); 80 break; 81 } 82 } 83 84 /* 85 * WORKAROUND for commandline product 86 */ 87 if (appValidatorVersion == null) 88 { 89 List<Bundle> appValidatorBundles = new ArrayList<Bundle>(); 90 appValidatorBundles.add(this.getBundle()); 91 appValidatorBundles.add(Platform 92 .getBundle("com.motorolamobility.preflighting.checkers")); 93 appValidatorBundles.add(PreflightingCorePlugin.getContext().getBundle()); 94 95 Version v = null; 96 for (Bundle b : appValidatorBundles) 97 { 98 if ((v == null) && (b != null)) 99 { 100 v = b.getVersion(); 101 } 102 if ((b != null) && (v != null) && (b.getVersion().compareTo(v) > 0)) 103 { 104 v = b.getVersion(); 105 } 106 } 107 108 appValidatorVersion = v.toString(); 109 } 110 111 /* 112 * End of WORKAROUND for commandline product 113 */ 114 } 115 116 public String getAppValidatorVersion() 117 { 118 if (appValidatorVersion == null) 119 { 120 readAppValidatorVersion(); 121 } 122 return appValidatorVersion; 123 } 124 125 } 126