You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by ri...@apache.org on 2010/07/15 15:25:31 UTC
svn commit: r964419 -
/felix/sandbox/rickhall/resolver/src/main/java/org/apache/felix/resolver/proto3/Proto3Resolver.java
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<String, Long> m_invokeCounts = new HashMap<String, Long>();
@@ -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<Capability> candidates = state.getCandidates(module, req, true);
for (Iterator<Capability> 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<Requirement, Set<Capability>> entry = candidateMap.entrySet().iterator().next();
Requirement dynReq = entry.getKey();
Set<Capability> 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<Capability, Set<Requirement>> capDepSet,
- Map<Requirement, Set<Capability>> 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<Module> invalidated = new HashSet();
-
- for (Requirement req : invalid.getRequirements())
- {
- candidateMap.remove(req);
- }
-
- boolean wasRequired = false;
-
- for (Capability cap : invalid.getCapabilities())
- {
- Set<Requirement> reqs = capDepSet.remove(cap);
- if (reqs == null)
- {
- continue;
- }
- wasRequired = true;
- for (Requirement req : reqs)
- {
- Set<Capability> 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<Module, Packages> modulePkgMap)
{
@@ -1544,11 +1504,17 @@ System.out.println("+++ PACKAGE SPACES E
return wireMap;
}
- private static void dumpCandidateMap(
- ResolverState state, Map<Requirement, Set<Capability>> candidateMap)
+ private static void dumpCandidateMap(Map<Requirement, Set<Capability>> candidateMap)
{
+ // Create set of all modules from requirements.
+ Set<Module> modules = new HashSet();
+ for (Entry<Requirement, Set<Capability>> 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<Capability> 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())