/** * Given a library file, find the configuration element that matches the current platform and * target * * @param lib * @return the configuration that matches the current platform and target */ private Configuration getTargetConfiguration(Library lib) { String matchedConfigName = null; // check whether platform and target match what we support ArrayList<Platform> platforms = lib.getPlatforms(); if (platforms != null) { for (Platform p : platforms) { if (p.getValue().equals(_platform)) { ArrayList<Target> targets = p.getTargets(); if (targets != null) { for (Target t : targets) { if (t.getVersion().equals(_targetVersion)) { matchedConfigName = t.getConfigName(); } } } } } } // make sure the config is defined if (matchedConfigName != null) { ArrayList<Configuration> configurations = lib.getConfigurations(); for (Configuration config : configurations) { if (config.getName().equals(matchedConfigName)) { return config; } } } return null; }
/** * Parse a given a library.xml to find out the features it offers and store the proper set of * source file paths for the current platform and target * * @param libraryXML library.xml file, cannot be null * @param allowBackwardCompatibility true if it's parsing library.xml from an extension JAR * @return hashtable that contains feature id's and the paths for the source files, or null if (1) * library.xml is malformed, (2) if allowBackwardCompatibility is false, and <target>, * <configuration>, <platform> or <src> is not specified correctly * @throws Exception */ private Hashtable<String, ExtensionInfo> parseFeaturesInLibraryXML( File libraryXML, boolean allowBackwardCompatibility) throws Exception { Library lib = parseLibraryXML(libraryXML); if (lib == null) { return null; } ArrayList<WidgetFeature> features = lib.getFeatures(); HashSet<String> javaPaths = new HashSet<String>(); HashSet<String> jsPaths = new HashSet<String>(); Hashtable<String, ExtensionInfo> availableFeatures = new Hashtable<String, ExtensionInfo>(); if (allowBackwardCompatibility) { // have to work for library.xml that doesn't contain configuration and platform elements File[] files = _temporaryDirectory.listFiles(); for (File f : files) { javaPaths.add(f.getAbsolutePath()); } } else { ExtensionInfo info = new ExtensionInfo(lib, javaPaths, jsPaths); boolean extensionIdFound = false; if (lib.getExtension() != null) { Extension extension = lib.getExtension(); String id = extension.getId(); if (id != null && !id.isEmpty()) { if (_extensionLookupTable.contains(id)) { // more than one library.xml contain the same extension id Logger.logMessage( LogType.WARNING, "VALIDATION_EXTENSION_DEFINED_MORE_THAN_ONCE", new String[] {id}); } _extensionLookupTable.put(id, info); info.setExtensionFolder(libraryXML.getParentFile()); extensionIdFound = true; } } if (!extensionIdFound) { // not considered an error, this extension might not be used // by the app being compiled Logger.logMessage( LogType.WARNING, "VALIDATION_LIBRARYXML_EXTENSION_ID_NOT_DEFINED", new String[] {libraryXML.getAbsolutePath()}); } Configuration config = getTargetConfiguration(lib); if (config == null) { Logger.logMessage( LogType.WARNING, "VALIDATION_LIBRARYXML_NO_CONFIG", new String[] {libraryXML.getAbsolutePath()}); return null; } ArrayList<Src> src = config.getSrc(); if (src == null || src.isEmpty()) { Logger.logMessage( LogType.WARNING, "VALIDATION_LIBRARYXML_NO_SRC", new String[] {libraryXML.getAbsolutePath()}); return null; } File extensionDir = libraryXML.getParentFile(); for (Src s : src) { String path = s.getPath(); if (s.getType().equalsIgnoreCase("text/java")) { javaPaths.add(extensionDir.getAbsolutePath() + File.separator + path); } else if (s.getType().equalsIgnoreCase("text/javascript")) { jsPaths.add(extensionDir.getAbsolutePath() + File.separator + path); } } } ExtensionInfo info = new ExtensionInfo(lib, javaPaths, jsPaths); for (WidgetFeature feature : features) { availableFeatures.put(feature.getID(), info); } if (lib.getCompiledJARDependencies() != null) { for (Jar j : lib.getCompiledJARDependencies()) { String path = j.getPath(); File temp = new File(path); if (temp.isAbsolute()) { info.addCompiledJARPath(path); } else { info.addCompiledJARPath( libraryXML.getParentFile().getAbsolutePath() + File.separator + path); } } } return availableFeatures; }