Return-Path: X-Original-To: apmail-incubator-ace-commits-archive@minotaur.apache.org Delivered-To: apmail-incubator-ace-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id A417D88B3 for ; Tue, 13 Sep 2011 14:07:16 +0000 (UTC) Received: (qmail 92961 invoked by uid 500); 13 Sep 2011 14:07:16 -0000 Delivered-To: apmail-incubator-ace-commits-archive@incubator.apache.org Received: (qmail 92940 invoked by uid 500); 13 Sep 2011 14:07:16 -0000 Mailing-List: contact ace-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: ace-dev@incubator.apache.org Delivered-To: mailing list ace-commits@incubator.apache.org Received: (qmail 92932 invoked by uid 99); 13 Sep 2011 14:07:16 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 13 Sep 2011 14:07:16 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 13 Sep 2011 14:07:09 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id AFBF22388ACC; Tue, 13 Sep 2011 14:06:24 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1170188 [7/7] - in /incubator/ace/trunk: ./ ace-deployment-verifier-ui/ ace-deployment-verifier-ui/src/ ace-deployment-verifier-ui/src/main/ ace-deployment-verifier-ui/src/main/java/ ace-deployment-verifier-ui/src/main/java/org/ ace-deploy... Date: Tue, 13 Sep 2011 14:06:22 -0000 To: ace-commits@incubator.apache.org From: pauls@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20110913140624.AFBF22388ACC@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Added: incubator/ace/trunk/ace-deployment-verifier/src/main/java/org/apache/felix/framework/util/manifestparser/R4Library.java URL: http://svn.apache.org/viewvc/incubator/ace/trunk/ace-deployment-verifier/src/main/java/org/apache/felix/framework/util/manifestparser/R4Library.java?rev=1170188&view=auto ============================================================================== --- incubator/ace/trunk/ace-deployment-verifier/src/main/java/org/apache/felix/framework/util/manifestparser/R4Library.java (added) +++ incubator/ace/trunk/ace-deployment-verifier/src/main/java/org/apache/felix/framework/util/manifestparser/R4Library.java Tue Sep 13 14:06:20 2011 @@ -0,0 +1,183 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.felix.framework.util.manifestparser; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import org.osgi.framework.Constants; + +public class R4Library +{ + private String m_libraryFile; + private String[] m_osnames; + private String[] m_processors; + private String[] m_osversions; + private String[] m_languages; + private String m_selectionFilter; + + public R4Library( + String libraryFile, String[] osnames, String[] processors, String[] osversions, + String[] languages, String selectionFilter) throws Exception + { + m_libraryFile = libraryFile; + m_osnames = osnames; + m_processors = processors; + m_osversions = osversions; + m_languages = languages; + m_selectionFilter = selectionFilter; + } + + public String getEntryName() + { + return m_libraryFile; + } + + public String[] getOSNames() + { + return m_osnames; + } + + public String[] getProcessors() + { + return m_processors; + } + + public String[] getOSVersions() + { + return m_osversions; + } + + public String[] getLanguages() + { + return m_languages; + } + + public String getSelectionFilter() + { + return m_selectionFilter; + } + + /** + *

+ * Determines if the specified native library name matches this native + * library definition. + *

+ * @param name the native library name to try to match. + * @return true if this native library name matches this native + * library definition; false otherwise. + **/ + public boolean match(Map configMap, String name) + { + // First, check for an exact match. + boolean matched = false; + if (m_libraryFile.equals(name) || m_libraryFile.endsWith("/" + name)) + { + matched = true; + } + + // Then check the mapped name. + String libname = System.mapLibraryName(name); + // As well as any additional library file extensions. + List exts = ManifestParser.parseDelimitedString( + (String) configMap.get(Constants.FRAMEWORK_LIBRARY_EXTENSIONS), ","); + if (exts == null) + { + exts = new ArrayList(); + } + // For Mac OSX, try dylib too. + if (libname.endsWith(".jnilib") && m_libraryFile.endsWith(".dylib")) + { + exts.add("dylib"); + } + // Loop until we find a match or not. + int extIdx = -1; + while (!matched && (extIdx < exts.size())) + { + // Check if the current name matches. + if (m_libraryFile.equals(libname) || m_libraryFile.endsWith("/" + libname)) + { + matched = true; + } + + // Increment extension index. + extIdx++; + + // If we have other native library extensions to try, then + // calculate the new native library name. + if (!matched && (extIdx < exts.size())) + { + int idx = libname.lastIndexOf("."); + libname = (idx < 0) + ? libname + "." + exts.get(extIdx) + : libname.substring(0, idx + 1) + exts.get(extIdx); + } + } + + return matched; + } + + public String toString() + { + if (m_libraryFile != null) + { + StringBuffer sb = new StringBuffer(); + sb.append(m_libraryFile); + for (int i = 0; (m_osnames != null) && (i < m_osnames.length); i++) + { + sb.append(';'); + sb.append(Constants.BUNDLE_NATIVECODE_OSNAME); + sb.append('='); + sb.append(m_osnames[i]); + } + for (int i = 0; (m_processors != null) && (i < m_processors.length); i++) + { + sb.append(';'); + sb.append(Constants.BUNDLE_NATIVECODE_PROCESSOR); + sb.append('='); + sb.append(m_processors[i]); + } + for (int i = 0; (m_osversions != null) && (i < m_osversions.length); i++) + { + sb.append(';'); + sb.append(Constants.BUNDLE_NATIVECODE_OSVERSION); + sb.append('='); + sb.append(m_osversions[i]); + } + for (int i = 0; (m_languages != null) && (i < m_languages.length); i++) + { + sb.append(';'); + sb.append(Constants.BUNDLE_NATIVECODE_LANGUAGE); + sb.append('='); + sb.append(m_languages[i]); + } + if (m_selectionFilter != null) + { + sb.append(';'); + sb.append(Constants.SELECTION_FILTER_ATTRIBUTE); + sb.append('='); + sb.append('\''); + sb.append(m_selectionFilter); + } + + return sb.toString(); + } + return "*"; + } +} \ No newline at end of file Added: incubator/ace/trunk/ace-deployment-verifier/src/main/java/org/apache/felix/framework/util/manifestparser/R4LibraryClause.java URL: http://svn.apache.org/viewvc/incubator/ace/trunk/ace-deployment-verifier/src/main/java/org/apache/felix/framework/util/manifestparser/R4LibraryClause.java?rev=1170188&view=auto ============================================================================== --- incubator/ace/trunk/ace-deployment-verifier/src/main/java/org/apache/felix/framework/util/manifestparser/R4LibraryClause.java (added) +++ incubator/ace/trunk/ace-deployment-verifier/src/main/java/org/apache/felix/framework/util/manifestparser/R4LibraryClause.java Tue Sep 13 14:06:20 2011 @@ -0,0 +1,523 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.felix.framework.util.manifestparser; + +import java.util.*; + +import org.apache.felix.framework.Logger; +import org.apache.felix.framework.util.FelixConstants; +import org.apache.felix.framework.util.VersionRange; +import org.osgi.framework.*; + +public class R4LibraryClause +{ + private final String[] m_libraryEntries; + private final String[] m_osnames; + private final String[] m_processors; + private final String[] m_osversions; + private final String[] m_languages; + private final String m_selectionFilter; + + public R4LibraryClause(String[] libraryEntries, String[] osnames, + String[] processors, String[] osversions, String[] languages, + String selectionFilter) + { + m_libraryEntries = libraryEntries; + m_osnames = osnames; + m_processors = processors; + m_osversions = osversions; + m_languages = languages; + m_selectionFilter = selectionFilter; + } + + public R4LibraryClause(R4LibraryClause library) + { + m_libraryEntries = library.m_libraryEntries; + m_osnames = library.m_osnames; + m_osversions = library.m_osversions; + m_processors = library.m_processors; + m_languages = library.m_languages; + m_selectionFilter = library.m_selectionFilter; + } + + public String[] getLibraryEntries() + { + return m_libraryEntries; + } + + public String[] getOSNames() + { + return m_osnames; + } + + public String[] getProcessors() + { + return m_processors; + } + + public String[] getOSVersions() + { + return m_osversions; + } + + public String[] getLanguages() + { + return m_languages; + } + + public String getSelectionFilter() + { + return m_selectionFilter; + } + + public boolean match(Map configMap) throws BundleException + { + String normal_osname = normalizeOSName((String) configMap.get(Constants.FRAMEWORK_OS_NAME)); + String normal_processor = normalizeProcessor((String) configMap.get(Constants.FRAMEWORK_PROCESSOR)); + String normal_osversion = normalizeOSVersion((String) configMap.get(Constants.FRAMEWORK_OS_VERSION)); + String normal_language = (String) configMap.get(Constants.FRAMEWORK_LANGUAGE); + + // Check library's osname. + if (!checkOSNames(normal_osname, getOSNames())) + { + return false; + } + + // Check library's processor. + if (!checkProcessors(normal_processor, getProcessors())) + { + return false; + } + + // Check library's osversion if specified. + if ((getOSVersions() != null) && + (getOSVersions().length > 0) && + !checkOSVersions(normal_osversion, getOSVersions())) + { + return false; + } + + // Check library's language if specified. + if ((getLanguages() != null) && + (getLanguages().length > 0) && + !checkLanguages(normal_language, getLanguages())) + { + return false; + } + + // Check library's selection-filter if specified. + if ((getSelectionFilter() != null) && + (getSelectionFilter().length() >= 0) && + !checkSelectionFilter(configMap, getSelectionFilter())) + { + return false; + } + + return true; + } + + private boolean checkOSNames(String currentOSName, String[] osnames) + { + boolean win32 = currentOSName.startsWith("win") && + (currentOSName.equals("windows95") + || currentOSName.equals("windows98") + || currentOSName.equals("windowsnt") + || currentOSName.equals("windows2000") + || currentOSName.equals("windows2003") + || currentOSName.equals("windowsxp") + || currentOSName.equals("windowsce") + || currentOSName.equals("windowsvista") + || currentOSName.equals("windows7")); + + for (int i = 0; (osnames != null) && (i < osnames.length); i++) + { + if (osnames[i].equals(currentOSName) || + ("win32".equals(osnames[i]) && win32)) + { + return true; + } + } + return false; + } + + private boolean checkProcessors(String currentProcessor, String[] processors) + { + for (int i = 0; (processors != null) && (i < processors.length); i++) + { + if (processors[i].equals(currentProcessor)) + { + return true; + } + } + return false; + } + + private boolean checkOSVersions(String currentOSVersion, String[] osversions) + throws BundleException + { + for (int i = 0; (osversions != null) && (i < osversions.length); i++) + { + try + { + VersionRange range = VersionRange.parse(osversions[i]); + if (range.isInRange(new Version(currentOSVersion))) + { + return true; + } + } + catch (Exception ex) + { + throw new BundleException( + "Error evaluating osversion: " + osversions[i], ex); + } + } + return false; + } + + private boolean checkLanguages(String currentLanguage, String[] languages) + { + for (int i = 0; (languages != null) && (i < languages.length); i++) + { + if (languages[i].equals(currentLanguage)) + { + return true; + } + } + return false; + } + + private boolean checkSelectionFilter(Map configMap, String expr) + throws BundleException + { + // Get all framework properties + Dictionary dict = new Hashtable(); + for (Iterator i = configMap.keySet().iterator(); i.hasNext(); ) + { + Object key = i.next(); + dict.put(key, configMap.get(key)); + } + // Compute expression + try + { + Filter filter = FrameworkUtil.createFilter(expr); + return filter.match(dict); + } + catch (Exception ex) + { + throw new BundleException( + "Error evaluating filter expression: " + expr, ex); + } + } + + public static R4LibraryClause parse(Logger logger, String s) + { + try + { + if ((s == null) || (s.length() == 0)) + { + return null; + } + + if (s.equals(FelixConstants.BUNDLE_NATIVECODE_OPTIONAL)) + { + return new R4LibraryClause(null, null, null, null, null, null); + } + + // The tokens are separated by semicolons and may include + // any number of libraries along with one set of associated + // properties. + StringTokenizer st = new StringTokenizer(s, ";"); + String[] libEntries = new String[st.countTokens()]; + List osNameList = new ArrayList(); + List osVersionList = new ArrayList(); + List processorList = new ArrayList(); + List languageList = new ArrayList(); + String selectionFilter = null; + int libCount = 0; + while (st.hasMoreTokens()) + { + String token = st.nextToken().trim(); + if (token.indexOf('=') < 0) + { + // Remove the slash, if necessary. + libEntries[libCount] = (token.charAt(0) == '/') + ? token.substring(1) + : token; + libCount++; + } + else + { + // Check for valid native library properties; defined as + // a property name, an equal sign, and a value. + // NOTE: StringTokenizer can not be used here because + // a value can contain one or more "=" too, e.g., + // selection-filter="(org.osgi.framework.windowing.system=gtk)" + String property = null; + String value = null; + if (!(token.indexOf("=") > 1)) + { + throw new IllegalArgumentException( + "Bundle manifest native library entry malformed: " + token); + } + else + { + property = (token.substring(0, token.indexOf("="))) + .trim().toLowerCase(); + value = (token.substring(token.indexOf("=") + 1, token + .length())).trim(); + } + + // Values may be quoted, so remove quotes if present. + if (value.charAt(0) == '"') + { + // This should always be true, otherwise the + // value wouldn't be properly quoted, but we + // will check for safety. + if (value.charAt(value.length() - 1) == '"') + { + value = value.substring(1, value.length() - 1); + } + else + { + value = value.substring(1); + } + } + // Add the value to its corresponding property list. + if (property.equals(Constants.BUNDLE_NATIVECODE_OSNAME)) + { + osNameList.add(normalizeOSName(value)); + } + else if (property.equals(Constants.BUNDLE_NATIVECODE_OSVERSION)) + { + osVersionList.add(normalizeOSVersion(value)); + } + else if (property.equals(Constants.BUNDLE_NATIVECODE_PROCESSOR)) + { + processorList.add(normalizeProcessor(value)); + } + else if (property.equals(Constants.BUNDLE_NATIVECODE_LANGUAGE)) + { + languageList.add(value); + } + else if (property.equals(Constants.SELECTION_FILTER_ATTRIBUTE)) + { +// TODO: NATIVE - I believe we can have multiple selection filters too. + selectionFilter = value; + } + } + } + + if (libCount == 0) + { + return null; + } + + // Shrink lib file array. + String[] actualLibEntries = new String[libCount]; + System.arraycopy(libEntries, 0, actualLibEntries, 0, libCount); + return new R4LibraryClause( + actualLibEntries, + (String[]) osNameList.toArray(new String[osNameList.size()]), + (String[]) processorList.toArray(new String[processorList.size()]), + (String[]) osVersionList.toArray(new String[osVersionList.size()]), + (String[]) languageList.toArray(new String[languageList.size()]), + selectionFilter); + } + catch (RuntimeException ex) + { + logger.log(Logger.LOG_ERROR, + "Error parsing native library header.", ex); + throw ex; + } + } + + public static String normalizeOSName(String value) + { + value = value.toLowerCase(); + + if (value.startsWith("win")) + { + String os = "win"; + if (value.indexOf("32") >= 0 || value.indexOf("*") >= 0) + { + os = "win32"; + } + else if (value.indexOf("95") >= 0) + { + os = "windows95"; + } + else if (value.indexOf("98") >= 0) + { + os = "windows98"; + } + else if (value.indexOf("nt") >= 0) + { + os = "windowsnt"; + } + else if (value.indexOf("2000") >= 0) + { + os = "windows2000"; + } + else if (value.indexOf("2003") >= 0) + { + os = "windows2003"; + } + else if (value.indexOf("xp") >= 0) + { + os = "windowsxp"; + } + else if (value.indexOf("ce") >= 0) + { + os = "windowsce"; + } + else if (value.indexOf("vista") >= 0) + { + os = "windowsvista"; + } + // will need better test here if any future Windows version has a 7 in it! + else if (value.indexOf("7") >= 0) + { + os = "windows7"; + } + return os; + } + else if (value.startsWith("linux")) + { + return "linux"; + } + else if (value.startsWith("aix")) + { + return "aix"; + } + else if (value.startsWith("digitalunix")) + { + return "digitalunix"; + } + else if (value.startsWith("hpux")) + { + return "hpux"; + } + else if (value.startsWith("irix")) + { + return "irix"; + } + else if (value.startsWith("macos") || value.startsWith("mac os")) + { + return "macos"; + } + else if (value.startsWith("netware")) + { + return "netware"; + } + else if (value.startsWith("openbsd")) + { + return "openbsd"; + } + else if (value.startsWith("netbsd")) + { + return "netbsd"; + } + else if (value.startsWith("os2") || value.startsWith("os/2")) + { + return "os2"; + } + else if (value.startsWith("qnx") || value.startsWith("procnto")) + { + return "qnx"; + } + else if (value.startsWith("solaris")) + { + return "solaris"; + } + else if (value.startsWith("sunos")) + { + return "sunos"; + } + else if (value.startsWith("vxworks")) + { + return "vxworks"; + } + return value; + } + + public static String normalizeProcessor(String value) + { + value = value.toLowerCase(); + + if (value.startsWith("x86-64") || value.startsWith("amd64") || + value.startsWith("em64") || value.startsWith("x86_64")) + { + return "x86-64"; + } + else if (value.startsWith("x86") || value.startsWith("pentium") + || value.startsWith("i386") || value.startsWith("i486") + || value.startsWith("i586") || value.startsWith("i686")) + { + return "x86"; + } + else if (value.startsWith("68k")) + { + return "68k"; + } + else if (value.startsWith("arm")) + { + return "arm"; + } + else if (value.startsWith("alpha")) + { + return "alpha"; + } + else if (value.startsWith("ignite") || value.startsWith("psc1k")) + { + return "ignite"; + } + else if (value.startsWith("mips")) + { + return "mips"; + } + else if (value.startsWith("parisc")) + { + return "parisc"; + } + else if (value.startsWith("powerpc") || value.startsWith("power") + || value.startsWith("ppc")) + { + return "powerpc"; + } + else if (value.startsWith("sparc")) + { + return "sparc"; + } + return value; + } + + public static String normalizeOSVersion(String value) + { + // Header: 'Bundle-NativeCode', Parameter: 'osversion' + // Standardized 'osversion': major.minor.micro, only digits + try + { + return VersionRange.parse(value).toString(); + } + catch (Exception ex) + { + return Version.emptyVersion.toString(); + } + } +} \ No newline at end of file Added: incubator/ace/trunk/ace-deployment-verifier/src/main/java/org/apache/felix/framework/wiring/BundleCapabilityImpl.java URL: http://svn.apache.org/viewvc/incubator/ace/trunk/ace-deployment-verifier/src/main/java/org/apache/felix/framework/wiring/BundleCapabilityImpl.java?rev=1170188&view=auto ============================================================================== --- incubator/ace/trunk/ace-deployment-verifier/src/main/java/org/apache/felix/framework/wiring/BundleCapabilityImpl.java (added) +++ incubator/ace/trunk/ace-deployment-verifier/src/main/java/org/apache/felix/framework/wiring/BundleCapabilityImpl.java Tue Sep 13 14:06:20 2011 @@ -0,0 +1,200 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.felix.framework.wiring; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.Collections; +import java.util.Set; +import java.util.Map; +import java.util.List; +import java.util.StringTokenizer; +import org.apache.felix.framework.capabilityset.SimpleFilter; +import org.apache.felix.framework.util.Util; +import org.apache.felix.framework.util.manifestparser.ManifestParser; +import org.osgi.framework.Constants; +import org.osgi.framework.wiring.BundleCapability; +import org.osgi.framework.wiring.BundleRevision; + +public class BundleCapabilityImpl implements BundleCapability +{ + public static final String SINGLETON_NAMESPACE = "singleton"; + + public static final String VERSION_ATTR = "version"; + + private final BundleRevision m_revision; + private final String m_namespace; + private final Map m_dirs; + private final Map m_attrs; + private final List m_uses; + private final List> m_includeFilter; + private final List> m_excludeFilter; + private final Set m_mandatory; + + public BundleCapabilityImpl(BundleRevision revision, String namespace, + Map dirs, Map attrs) + { + m_namespace = namespace; + m_revision = revision; + m_dirs = Collections.unmodifiableMap(dirs); + m_attrs = Collections.unmodifiableMap(attrs); + + // Find all export directives: uses, mandatory, include, and exclude. + + List uses = Collections.EMPTY_LIST; + String value = m_dirs.get(Constants.USES_DIRECTIVE); + if (value != null) + { + // Parse these uses directive. + StringTokenizer tok = new StringTokenizer(value, ","); + uses = new ArrayList(tok.countTokens()); + while (tok.hasMoreTokens()) + { + uses.add(tok.nextToken().trim()); + } + } + m_uses = uses; + + value = m_dirs.get(Constants.INCLUDE_DIRECTIVE); + if (value != null) + { + List filters = ManifestParser.parseDelimitedString(value, ","); + m_includeFilter = new ArrayList>(filters.size()); + for (int filterIdx = 0; filterIdx < filters.size(); filterIdx++) + { + List substrings = SimpleFilter.parseSubstring(filters.get(filterIdx)); + m_includeFilter.add(substrings); + } + } + else + { + m_includeFilter = null; + } + + value = m_dirs.get(Constants.EXCLUDE_DIRECTIVE); + if (value != null) + { + List filters = ManifestParser.parseDelimitedString(value, ","); + m_excludeFilter = new ArrayList>(filters.size()); + for (int filterIdx = 0; filterIdx < filters.size(); filterIdx++) + { + List substrings = SimpleFilter.parseSubstring(filters.get(filterIdx)); + m_excludeFilter.add(substrings); + } + } + else + { + m_excludeFilter = null; + } + + Set mandatory = Collections.EMPTY_SET; + value = m_dirs.get(Constants.MANDATORY_DIRECTIVE); + if (value != null) + { + List names = ManifestParser.parseDelimitedString(value, ","); + mandatory = new HashSet(names.size()); + for (String name : names) + { + // If attribute exists, then record it as mandatory. + if (m_attrs.containsKey(name)) + { + mandatory.add(name); + } + // Otherwise, report an error. + else + { + throw new IllegalArgumentException( + "Mandatory attribute '" + name + "' does not exist."); + } + } + } + m_mandatory = mandatory; + } + + public BundleRevision getRevision() + { + return m_revision; + } + + public String getNamespace() + { + return m_namespace; + } + + public Map getDirectives() + { + return m_dirs; + } + + public Map getAttributes() + { + return m_attrs; + } + + public boolean isAttributeMandatory(String name) + { + return !m_mandatory.isEmpty() && m_mandatory.contains(name); + } + + public List getUses() + { + return m_uses; + } + + public boolean isIncluded(String name) + { + if ((m_includeFilter == null) && (m_excludeFilter == null)) + { + return true; + } + + // Get the class name portion of the target class. + String className = Util.getClassName(name); + + // If there are no include filters then all classes are included + // by default, otherwise try to find one match. + boolean included = (m_includeFilter == null); + for (int i = 0; + (!included) && (m_includeFilter != null) && (i < m_includeFilter.size()); + i++) + { + included = SimpleFilter.compareSubstring(m_includeFilter.get(i), className); + } + + // If there are no exclude filters then no classes are excluded + // by default, otherwise try to find one match. + boolean excluded = false; + for (int i = 0; + (!excluded) && (m_excludeFilter != null) && (i < m_excludeFilter.size()); + i++) + { + excluded = SimpleFilter.compareSubstring(m_excludeFilter.get(i), className); + } + return included && !excluded; + } + + public String toString() + { + if (m_revision == null) + { + return m_attrs.toString(); + } + return "[" + m_revision + "] " + m_namespace + "; " + m_attrs; + } +} \ No newline at end of file Added: incubator/ace/trunk/ace-deployment-verifier/src/main/java/org/apache/felix/framework/wiring/BundleRequirementImpl.java URL: http://svn.apache.org/viewvc/incubator/ace/trunk/ace-deployment-verifier/src/main/java/org/apache/felix/framework/wiring/BundleRequirementImpl.java?rev=1170188&view=auto ============================================================================== --- incubator/ace/trunk/ace-deployment-verifier/src/main/java/org/apache/felix/framework/wiring/BundleRequirementImpl.java (added) +++ incubator/ace/trunk/ace-deployment-verifier/src/main/java/org/apache/felix/framework/wiring/BundleRequirementImpl.java Tue Sep 13 14:06:20 2011 @@ -0,0 +1,109 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.felix.framework.wiring; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import org.apache.felix.framework.capabilityset.CapabilitySet; +import org.apache.felix.framework.capabilityset.SimpleFilter; +import org.apache.felix.framework.util.VersionRange; +import org.osgi.framework.Constants; +import org.osgi.framework.wiring.BundleCapability; +import org.osgi.framework.wiring.BundleRequirement; +import org.osgi.framework.wiring.BundleRevision; + +public class BundleRequirementImpl implements BundleRequirement +{ + private final BundleRevision m_revision; + private final String m_namespace; + private final SimpleFilter m_filter; + private final boolean m_optional; + private final Map m_dirs; + private final Map m_attrs; + + public BundleRequirementImpl( + BundleRevision revision, String namespace, + Map dirs, Map attrs, SimpleFilter filter) + { + m_revision = revision; + m_namespace = namespace; + m_dirs = Collections.unmodifiableMap(dirs); + m_attrs = Collections.unmodifiableMap(attrs); + m_filter = filter; + + // Find resolution import directives. + boolean optional = false; + if (m_dirs.containsKey(Constants.RESOLUTION_DIRECTIVE) + && m_dirs.get(Constants.RESOLUTION_DIRECTIVE).equals(Constants.RESOLUTION_OPTIONAL)) + { + optional = true; + } + m_optional = optional; + } + + public BundleRequirementImpl( + BundleRevision revision, String namespace, + Map dirs, Map attrs) + { + this(revision, namespace, dirs, Collections.EMPTY_MAP, SimpleFilter.convert(attrs)); + } + + public String getNamespace() + { + return m_namespace; + } + + public Map getDirectives() + { + return m_dirs; + } + + public Map getAttributes() + { + return m_attrs; + } + + public BundleRevision getRevision() + { + return m_revision; + } + + public boolean matches(BundleCapability cap) + { + return CapabilitySet.matches((BundleCapabilityImpl) cap, getFilter()); + } + + public boolean isOptional() + { + return m_optional; + } + + public SimpleFilter getFilter() + { + return m_filter; + } + + public String toString() + { + return "[" + m_revision + "] " + m_namespace + "; " + getFilter().toString(); + } +} \ No newline at end of file Added: incubator/ace/trunk/ace-deployment-verifier/src/main/java/org/apache/felix/framework/wiring/BundleWireImpl.java URL: http://svn.apache.org/viewvc/incubator/ace/trunk/ace-deployment-verifier/src/main/java/org/apache/felix/framework/wiring/BundleWireImpl.java?rev=1170188&view=auto ============================================================================== --- incubator/ace/trunk/ace-deployment-verifier/src/main/java/org/apache/felix/framework/wiring/BundleWireImpl.java (added) +++ incubator/ace/trunk/ace-deployment-verifier/src/main/java/org/apache/felix/framework/wiring/BundleWireImpl.java Tue Sep 13 14:06:20 2011 @@ -0,0 +1,79 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.felix.framework.wiring; + +import org.osgi.framework.wiring.BundleCapability; +import org.osgi.framework.wiring.BundleRequirement; +import org.osgi.framework.wiring.BundleRevision; +import org.osgi.framework.wiring.BundleWire; +import org.osgi.framework.wiring.BundleWiring; + +public class BundleWireImpl implements BundleWire +{ + private final BundleRevision m_requirer; + private final BundleRequirement m_req; + private final BundleRevision m_provider; + private final BundleCapability m_cap; + + public BundleWireImpl(BundleRevision requirer, BundleRequirement req, + BundleRevision provider, BundleCapability cap) + { + m_requirer = requirer; + m_req = req; + m_provider = provider; + m_cap = cap; + } + + public BundleRevision getRequirer() + { + return m_requirer; + } + + public BundleWiring getRequirerWiring() + { + return m_requirer.getWiring(); + } + + public BundleRequirement getRequirement() + { + return m_req; + } + + public BundleRevision getProvider() + { + return m_provider; + } + + public BundleWiring getProviderWiring() + { + return m_provider.getWiring(); + } + + public BundleCapability getCapability() + { + return m_cap; + } + + public String toString() + { + return m_req + + " -> " + + "[" + m_provider + "]"; + } +} \ No newline at end of file Added: incubator/ace/trunk/ace-deployment-verifier/src/test/java/org/apache/ace/deployment/verifier/impl/VerifierTest.java URL: http://svn.apache.org/viewvc/incubator/ace/trunk/ace-deployment-verifier/src/test/java/org/apache/ace/deployment/verifier/impl/VerifierTest.java?rev=1170188&view=auto ============================================================================== --- incubator/ace/trunk/ace-deployment-verifier/src/test/java/org/apache/ace/deployment/verifier/impl/VerifierTest.java (added) +++ incubator/ace/trunk/ace-deployment-verifier/src/test/java/org/apache/ace/deployment/verifier/impl/VerifierTest.java Tue Sep 13 14:06:20 2011 @@ -0,0 +1,132 @@ +package org.apache.ace.deployment.verifier.impl; + +import static junit.framework.Assert.assertTrue; +import static org.junit.Assert.*; + +import java.util.HashMap; +import java.util.HashSet; +import java.util.Set; + +import junit.framework.AssertionFailedError; + +import org.apache.ace.deployment.verifier.VerifierService; +import org.apache.ace.deployment.verifier.VerifierService.VerifyEnvironment; +import org.apache.ace.deployment.verifier.VerifierService.VerifyReporter; +import org.apache.felix.framework.util.FelixConstants; +import org.junit.Test; +import org.osgi.framework.BundleException; +import org.osgi.framework.Constants; +import org.osgi.framework.wiring.BundleCapability; +import org.osgi.framework.wiring.BundleRequirement; +import org.osgi.framework.wiring.BundleRevision; +import org.osgi.service.log.LogEntry; + +public class VerifierTest { + @Test + public void testResolve() throws BundleException { + VerifierService verifier = new VerifierServiceImpl(); + VerifyEnvironment env = verifier.createEnvironment(new HashMap() { + { + put(Constants.FRAMEWORK_EXECUTIONENVIRONMENT, VerifierService.EE_1_6); + put(Constants.FRAMEWORK_OS_NAME, "macosx"); + put(Constants.FRAMEWORK_OS_VERSION, "10.5"); + } + }, new VerifyReporter() { + + public void reportWire(BundleRevision importer, + BundleRequirement reqirement, BundleRevision exporter, + BundleCapability capability) { + System.out.println("WIRE: " + importer + " - " + reqirement + " - " + capability + " -> " + exporter); + } + + public void reportLog(LogEntry logEntry) { + System.out.println("Log(" + logEntry.getTime() + "): " + logEntry.getLevel() + " " + logEntry.getMessage()); + if (logEntry.getException() != null) { + logEntry.getException().printStackTrace(); + } + } + + public void reportException(Exception ex) { + ex.printStackTrace(); + } + }); + Set bundles = new HashSet(); + bundles.add(env.addBundle(0, new HashMap(){ + { + put(Constants.BUNDLE_MANIFESTVERSION, "2"); + put(Constants.BUNDLE_SYMBOLICNAME, FelixConstants.SYSTEM_BUNDLE_SYMBOLICNAME); + put(Constants.EXPORT_PACKAGE, VerifierService.SYSTEM_PACKAGES + "," + VerifierService.JRE_1_6_PACKAGES); + } + })); + bundles.add(env.addBundle(1, new HashMap() { + { + put(Constants.BUNDLE_MANIFESTVERSION, "2"); + put(Constants.BUNDLE_SYMBOLICNAME, "org.test.foo"); + put(Constants.IMPORT_PACKAGE, "org.foo, org.osgi.framework"); + } + })); + bundles.add(env.addBundle(2, new HashMap() { + { + put(Constants.BUNDLE_MANIFESTVERSION, "2"); + put(Constants.BUNDLE_SYMBOLICNAME, "org.test.foo2"); + put(Constants.EXPORT_PACKAGE, "org.foo" + + ""); + } + })); + assertTrue(" Unable to resolve resolvable state.", env.verifyResolve(bundles, null, null)); + } + + @Test + public void testResolveFail() throws BundleException { + VerifierService verifier = new VerifierServiceImpl(); + VerifyEnvironment env = verifier.createEnvironment(new HashMap(){ + { + put(Constants.FRAMEWORK_EXECUTIONENVIRONMENT, VerifierService.EE_1_6); + put(Constants.FRAMEWORK_OS_NAME, "macosx"); + put(Constants.FRAMEWORK_OS_VERSION, "10.5"); + } + }, new VerifyReporter() { + + public void reportWire(BundleRevision importer, + BundleRequirement reqirement, BundleRevision exporter, + BundleCapability capability) { + System.out.println("WIRE: " + importer + " - " + reqirement + " - " + capability + " -> " + exporter); + } + + public void reportLog(LogEntry logEntry) { + System.out.println("Log(" + logEntry.getTime() + "): " + logEntry.getLevel() + " " + logEntry.getMessage()); + if (logEntry.getException() != null) { + logEntry.getException().printStackTrace(); + } + } + + public void reportException(Exception ex) { + ex.printStackTrace(); + } + }); + Set bundles = new HashSet(); + bundles.add(env.addBundle(0, new HashMap(){ + { + put(Constants.BUNDLE_MANIFESTVERSION, "2"); + put(Constants.BUNDLE_SYMBOLICNAME, FelixConstants.SYSTEM_BUNDLE_SYMBOLICNAME); + put(Constants.EXPORT_PACKAGE, VerifierService.SYSTEM_PACKAGES + "," + VerifierService.JRE_1_6_PACKAGES); + } + })); + bundles.add(env.addBundle(1, new HashMap() { + { + put(Constants.BUNDLE_MANIFESTVERSION, "2"); + put(Constants.BUNDLE_SYMBOLICNAME, "org.test.foo"); + put(Constants.IMPORT_PACKAGE, "org.foo"); + } + })); + bundles.add(env.addBundle(2, new HashMap() { + { + put(Constants.BUNDLE_MANIFESTVERSION, "2"); + put(Constants.BUNDLE_SYMBOLICNAME, "org.test.foo2"); + put(Constants.EXPORT_PACKAGE, "org.foo2" + + ""); + } + })); + assertFalse("Resolving unresolvable", env.verifyResolve(bundles, null, null)); + } +} Modified: incubator/ace/trunk/ace-target-devserver/pom.xml URL: http://svn.apache.org/viewvc/incubator/ace/trunk/ace-target-devserver/pom.xml?rev=1170188&r1=1170187&r2=1170188&view=diff ============================================================================== --- incubator/ace/trunk/ace-target-devserver/pom.xml (original) +++ incubator/ace/trunk/ace-target-devserver/pom.xml Tue Sep 13 14:06:20 2011 @@ -229,6 +229,16 @@ org.apache.ace.deployment.streamgenerator runtime + + org.apache.ace + org.apache.ace.deployment.verifier + runtime + + + org.apache.ace + org.apache.ace.deployment.verifier.ui + runtime + org.apache.ace org.apache.ace.discovery.api Modified: incubator/ace/trunk/pom.xml URL: http://svn.apache.org/viewvc/incubator/ace/trunk/pom.xml?rev=1170188&r1=1170187&r2=1170188&view=diff ============================================================================== --- incubator/ace/trunk/pom.xml (original) +++ incubator/ace/trunk/pom.xml Tue Sep 13 14:06:20 2011 @@ -77,7 +77,8 @@ ace-deployment-api ace-deployment-deploymentadmin ace-deployment-task - + ace-deployment-verifier + ace-deployment-verifier-ui ace-httplistener ace-server-log-store Modified: incubator/ace/trunk/pom/pom.xml URL: http://svn.apache.org/viewvc/incubator/ace/trunk/pom/pom.xml?rev=1170188&r1=1170187&r2=1170188&view=diff ============================================================================== --- incubator/ace/trunk/pom/pom.xml (original) +++ incubator/ace/trunk/pom/pom.xml Tue Sep 13 14:06:20 2011 @@ -147,7 +147,7 @@ 4.2.0 4.2.0 1.2.3 - 1.5.0 + 1.7.5 1.2.0 0.7.2 2.4 @@ -430,6 +430,16 @@ org.apache.ace + org.apache.ace.deployment.verifier + ${project.version} + + + org.apache.ace + org.apache.ace.deployment.verifier.ui + ${project.version} + + + org.apache.ace org.apache.ace.discovery.api ${project.version}