Return-Path: Delivered-To: apmail-felix-commits-archive@www.apache.org Received: (qmail 1115 invoked from network); 15 Jul 2010 13:27:01 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 15 Jul 2010 13:27:01 -0000 Received: (qmail 44565 invoked by uid 500); 15 Jul 2010 13:27:01 -0000 Delivered-To: apmail-felix-commits-archive@felix.apache.org Received: (qmail 44480 invoked by uid 500); 15 Jul 2010 13:26:59 -0000 Mailing-List: contact commits-help@felix.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@felix.apache.org Delivered-To: mailing list commits@felix.apache.org Received: (qmail 44473 invoked by uid 99); 15 Jul 2010 13:26:58 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 15 Jul 2010 13:26:58 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.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; Thu, 15 Jul 2010 13:26:54 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 75BF02388903; Thu, 15 Jul 2010 13:25:31 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r964419 - /felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/proto3/Proto3Resolver.java Date: Thu, 15 Jul 2010 13:25:31 -0000 To: commits@felix.apache.org From: rickhall@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20100715132531.75BF02388903@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: rickhall Date: Thu Jul 15 13:25:31 2010 New Revision: 964419 URL: http://svn.apache.org/viewvc?rev=964419&view=rev Log: Align sandbox resolver with trunk. Modified: felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/proto3/Proto3Resolver.java Modified: felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/proto3/Proto3Resolver.java URL: http://svn.apache.org/viewvc/felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/proto3/Proto3Resolver.java?rev=964419&r1=964418&r2=964419&view=diff ============================================================================== --- felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/proto3/Proto3Resolver.java (original) +++ felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/proto3/Proto3Resolver.java Thu Jul 15 13:25:31 2010 @@ -1,20 +1,20 @@ /* - * 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. + * 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.resolver.proto3; @@ -46,9 +46,6 @@ import org.apache.felix.resolver.cs.Requ import org.apache.felix.resolver.manifestparser.Constants; import org.apache.felix.resolver.manifestparser.Util; -// 1. Treat hard pkg constraints separately from implied package constraints -// 2. Map pkg constraints to a set of capabilities, not a single capability. -// 3. Uses constraints cannot conflict with other uses constraints, only with hard constraints. public class Proto3Resolver implements Resolver { private static final Map m_invokeCounts = new HashMap(); @@ -116,7 +113,7 @@ System.out.println("+++ PROTO3 RESOLVER" candidateMap = (m_usesPermutations.size() > 0) ? m_usesPermutations.remove(0) : m_importPermutations.remove(0); -dumpCandidateMap(state, candidateMap); +dumpCandidateMap(candidateMap); calculatePackageSpaces( module, candidateMap, modulePkgMap, @@ -455,6 +452,7 @@ System.out.println("+++ PACKAGE SPACES E Requirement req = remainingReqs.remove(0); // Get satisfying candidates and populate their candidates if necessary. + ResolveException rethrow = null; Set candidates = state.getCandidates(module, req, true); for (Iterator itCandCap = candidates.iterator(); itCandCap.hasNext(); ) { @@ -468,6 +466,10 @@ System.out.println("+++ PACKAGE SPACES E } catch (ResolveException ex) { + if (rethrow == null) + { + rethrow = ex; + } // Remove the candidate since we weren't able to // populate its candidates. itCandCap.remove(); @@ -480,12 +482,15 @@ System.out.println("+++ PACKAGE SPACES E // a resolve exception. if ((candidates.size() == 0) && !req.isOptional()) { - ResolveException ex = - new ResolveException("Unable to resolve " + module - + ": missing requirement " + req, module, req); - resultCache.put(module, ex); - System.out.println("No viable candidates: " + ex); - throw ex; + if (rethrow == null) + { + rethrow = + new ResolveException("Unable to resolve " + module + + ": missing requirement " + req, module, req); + } + resultCache.put(module, rethrow); + System.out.println("No viable candidates: " + rethrow); + throw rethrow; } // If we actually have candidates for the requirement, then // add them to the local candidate map. @@ -494,7 +499,6 @@ System.out.println("+++ PACKAGE SPACES E localCandidateMap.put(req, candidates); } } - // If we are exiting from a cycle then decrement // cycle counter, otherwise record the result. if (cycleCount.intValue() > 0) @@ -529,6 +533,7 @@ System.out.println("+++ PACKAGE SPACES E // There should be one entry in the candidate map, which are the // the candidates for the matching dynamic requirement. Get the // matching candidates and populate their candidates if necessary. + ResolveException rethrow = null; Entry> entry = candidateMap.entrySet().iterator().next(); Requirement dynReq = entry.getKey(); Set candidates = entry.getValue(); @@ -544,6 +549,10 @@ System.out.println("+++ PACKAGE SPACES E } catch (ResolveException ex) { + if (rethrow == null) + { + rethrow = ex; + } itCandCap.remove(); } } @@ -552,7 +561,11 @@ System.out.println("+++ PACKAGE SPACES E if (candidates.size() == 0) { candidateMap.remove(dynReq); - throw new ResolveException("Dynamic import failed.", module, dynReq); + if (rethrow == null) + { + rethrow = new ResolveException("Dynamic import failed.", module, dynReq); + } + throw rethrow; } } @@ -1181,59 +1194,6 @@ System.out.println("+++ PACKAGE SPACES E } } - private void removeInvalidateCandidate( - Module invalid, Map> capDepSet, - Map> candidateMap) - { - if (m_isInvokeCount) - { - String methodName = new Exception().fillInStackTrace().getStackTrace()[0].getMethodName(); - Long count = m_invokeCounts.get(methodName); - count = (count == null) ? new Long(1) : new Long(count.longValue() + 1); - m_invokeCounts.put(methodName, count); - } - - Set invalidated = new HashSet(); - - for (Requirement req : invalid.getRequirements()) - { - candidateMap.remove(req); - } - - boolean wasRequired = false; - - for (Capability cap : invalid.getCapabilities()) - { - Set reqs = capDepSet.remove(cap); - if (reqs == null) - { - continue; - } - wasRequired = true; - for (Requirement req : reqs) - { - Set candidates = candidateMap.get(req); - candidates.remove(cap); - if (candidates.size() == 0) - { - candidateMap.remove(req); - invalidated.add(req.getModule()); - } - } - } - - if (!wasRequired) - { - throw new ResolveException( - "Unable to resolve module", invalid, null); - } - - for (Module m : invalidated) - { - removeInvalidateCandidate(m, capDepSet, candidateMap); - } - } - private static void calculateExportedPackages( Module module, Map modulePkgMap) { @@ -1544,11 +1504,17 @@ System.out.println("+++ PACKAGE SPACES E return wireMap; } - private static void dumpCandidateMap( - ResolverState state, Map> candidateMap) + private static void dumpCandidateMap(Map> candidateMap) { + // Create set of all modules from requirements. + Set modules = new HashSet(); + for (Entry> entry : candidateMap.entrySet()) + { + modules.add(entry.getKey().getModule()); + } + // Now dump the modules. System.out.println("=== BEGIN CANDIDATE MAP ==="); - for (Module module : ((ResolverStateImpl) state).getModules()) + for (Module module : modules) { System.out.println(" " + module + " (" + (module.isResolved() ? "RESOLVED)" : "UNRESOLVED)")); @@ -1557,7 +1523,7 @@ System.out.println("+++ PACKAGE SPACES E Set candidates = candidateMap.get(req); if ((candidates != null) && (candidates.size() > 0)) { - System.out.println(" " + req + ": " + candidates); + System.out.println(" " + req + ": " + candidates); } } for (Requirement req : module.getDynamicRequirements())