Return-Path: X-Original-To: apmail-karaf-commits-archive@minotaur.apache.org Delivered-To: apmail-karaf-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 144AE10E38 for ; Mon, 28 Apr 2014 23:34:04 +0000 (UTC) Received: (qmail 91321 invoked by uid 500); 28 Apr 2014 23:33:59 -0000 Delivered-To: apmail-karaf-commits-archive@karaf.apache.org Received: (qmail 91226 invoked by uid 500); 28 Apr 2014 23:33:58 -0000 Mailing-List: contact commits-help@karaf.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@karaf.apache.org Delivered-To: mailing list commits@karaf.apache.org Received: (qmail 91190 invoked by uid 99); 28 Apr 2014 23:33:57 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 28 Apr 2014 23:33:57 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 22F0699429D; Mon, 28 Apr 2014 23:33:57 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: gnodet@apache.org To: commits@karaf.apache.org Date: Mon, 28 Apr 2014 23:33:59 -0000 Message-Id: In-Reply-To: <98bd083e0e2842d7babf9da952dc424a@git.apache.org> References: <98bd083e0e2842d7babf9da952dc424a@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [3/7] Code formatting and other checkstyle issues http://git-wip-us.apache.org/repos/asf/karaf/blob/b6c5a173/features/core/src/main/java/org/apache/karaf/features/internal/model/Requirement.java ---------------------------------------------------------------------- diff --git a/features/core/src/main/java/org/apache/karaf/features/internal/model/Requirement.java b/features/core/src/main/java/org/apache/karaf/features/internal/model/Requirement.java index f7b5775..6771e3d 100644 --- a/features/core/src/main/java/org/apache/karaf/features/internal/model/Requirement.java +++ b/features/core/src/main/java/org/apache/karaf/features/internal/model/Requirement.java @@ -1,23 +1,19 @@ /* - * 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 + * 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 + * 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. + * 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.karaf.features.internal.model; import javax.xml.bind.annotation.XmlAccessType; @@ -27,14 +23,13 @@ import javax.xml.bind.annotation.XmlValue; /** - * * Additional requirement for a feature. - * - * + *

+ *

*

Java class for bundle complex type. - * + *

*

The following schema fragment specifies the expected content contained within this class. - * + *

*

  * <complexType name="capability">
  *   <simpleContent>
@@ -43,13 +38,9 @@ import javax.xml.bind.annotation.XmlValue;
  *   </simpleContent>
  * </complexType>
  * 
- * - * */ @XmlAccessorType(XmlAccessType.FIELD) -@XmlType(name = "requirement", propOrder = { - "value" -}) +@XmlType(name = "requirement", propOrder = {"value"}) public class Requirement implements org.apache.karaf.features.Requirement { @XmlValue @@ -69,13 +60,16 @@ public class Requirement implements org.apache.karaf.features.Requirement { @Override public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } Requirement bundle = (Requirement) o; - - if (value != null ? !value.equals(bundle.value) : bundle.value != null) return false; - + if (value != null ? !value.equals(bundle.value) : bundle.value != null) { + return false; + } return true; } http://git-wip-us.apache.org/repos/asf/karaf/blob/b6c5a173/features/core/src/main/java/org/apache/karaf/features/internal/model/ScopeFilter.java ---------------------------------------------------------------------- diff --git a/features/core/src/main/java/org/apache/karaf/features/internal/model/ScopeFilter.java b/features/core/src/main/java/org/apache/karaf/features/internal/model/ScopeFilter.java index 4b81fed..a1096ac 100644 --- a/features/core/src/main/java/org/apache/karaf/features/internal/model/ScopeFilter.java +++ b/features/core/src/main/java/org/apache/karaf/features/internal/model/ScopeFilter.java @@ -23,9 +23,7 @@ import javax.xml.bind.annotation.XmlType; import javax.xml.bind.annotation.XmlValue; @XmlAccessorType(XmlAccessType.FIELD) -@XmlType(name = "scopeFilter", propOrder = { - "value" -}) +@XmlType(name = "scopeFilter", propOrder = {"value"}) public class ScopeFilter implements org.apache.karaf.features.ScopeFilter { @XmlAttribute(required = true) http://git-wip-us.apache.org/repos/asf/karaf/blob/b6c5a173/features/core/src/main/java/org/apache/karaf/features/internal/model/Scoping.java ---------------------------------------------------------------------- diff --git a/features/core/src/main/java/org/apache/karaf/features/internal/model/Scoping.java b/features/core/src/main/java/org/apache/karaf/features/internal/model/Scoping.java index 6773995..85264b3 100644 --- a/features/core/src/main/java/org/apache/karaf/features/internal/model/Scoping.java +++ b/features/core/src/main/java/org/apache/karaf/features/internal/model/Scoping.java @@ -26,10 +26,7 @@ import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlType; @XmlAccessorType(XmlAccessType.FIELD) -@XmlType(name = "scoping", propOrder = { - "imports", - "exports" -}) +@XmlType(name = "scoping", propOrder = {"imports", "exports"}) public class Scoping implements org.apache.karaf.features.Scoping { @XmlAttribute @@ -41,14 +38,14 @@ public class Scoping implements org.apache.karaf.features.Scoping { public List getImport() { if (imports == null) { - imports = new ArrayList(); + imports = new ArrayList<>(); } return imports; } public List getExport() { if (exports == null) { - exports = new ArrayList(); + exports = new ArrayList<>(); } return exports; } http://git-wip-us.apache.org/repos/asf/karaf/blob/b6c5a173/features/core/src/main/java/org/apache/karaf/features/internal/model/package-info.java ---------------------------------------------------------------------- diff --git a/features/core/src/main/java/org/apache/karaf/features/internal/model/package-info.java b/features/core/src/main/java/org/apache/karaf/features/internal/model/package-info.java index c86a58c..b5506bc 100644 --- a/features/core/src/main/java/org/apache/karaf/features/internal/model/package-info.java +++ b/features/core/src/main/java/org/apache/karaf/features/internal/model/package-info.java @@ -1,21 +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 + * 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 + * 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. + * 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. */ - -@javax.xml.bind.annotation.XmlSchema(namespace = org.apache.karaf.features.FeaturesNamespaces.URI_CURRENT, elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED) +@javax.xml.bind.annotation.XmlSchema( + namespace = org.apache.karaf.features.FeaturesNamespaces.URI_CURRENT, + elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED) package org.apache.karaf.features.internal.model; http://git-wip-us.apache.org/repos/asf/karaf/blob/b6c5a173/features/core/src/main/java/org/apache/karaf/features/internal/osgi/Activator.java ---------------------------------------------------------------------- diff --git a/features/core/src/main/java/org/apache/karaf/features/internal/osgi/Activator.java b/features/core/src/main/java/org/apache/karaf/features/internal/osgi/Activator.java index 81fdf49..1be87fc 100644 --- a/features/core/src/main/java/org/apache/karaf/features/internal/osgi/Activator.java +++ b/features/core/src/main/java/org/apache/karaf/features/internal/osgi/Activator.java @@ -33,17 +33,17 @@ import org.apache.felix.resolver.ResolverImpl; import org.apache.felix.utils.properties.Properties; import org.apache.karaf.features.FeaturesListener; import org.apache.karaf.features.FeaturesService; +import org.apache.karaf.features.internal.management.FeaturesServiceMBeanImpl; import org.apache.karaf.features.internal.repository.AggregateRepository; import org.apache.karaf.features.internal.repository.JsonRepository; import org.apache.karaf.features.internal.repository.XmlRepository; import org.apache.karaf.features.internal.resolver.Slf4jResolverLog; +import org.apache.karaf.features.internal.service.BootFeaturesInstaller; import org.apache.karaf.features.internal.service.EventAdminListener; import org.apache.karaf.features.internal.service.FeatureConfigInstaller; import org.apache.karaf.features.internal.service.FeatureFinder; -import org.apache.karaf.features.internal.service.BootFeaturesInstaller; import org.apache.karaf.features.internal.service.FeaturesServiceImpl; import org.apache.karaf.features.internal.service.StateStorage; -import org.apache.karaf.features.internal.management.FeaturesServiceMBeanImpl; import org.apache.karaf.util.tracker.BaseActivator; import org.eclipse.equinox.internal.region.DigraphHelper; import org.eclipse.equinox.internal.region.StandardRegionDigraph; @@ -146,9 +146,15 @@ public class Activator extends BaseActivator { } Repository globalRepository; switch (repositories.size()) { - case 0: globalRepository = null; break; - case 1: globalRepository = repositories.get(0); break; - default: globalRepository = new AggregateRepository(repositories); break; + case 0: + globalRepository = null; + break; + case 1: + globalRepository = repositories.get(0); + break; + default: + globalRepository = new AggregateRepository(repositories); + break; } FeatureConfigInstaller configInstaller = new FeatureConfigInstaller(configurationAdmin); @@ -180,37 +186,41 @@ public class Activator extends BaseActivator { eventAdminListener = null; } featuresService = new FeaturesServiceImpl( - bundleContext.getBundle(), - bundleContext.getBundle(0).getBundleContext(), - stateStorage, - featureFinder, - eventAdminListener, - configInstaller, - digraph, - overrides, - featureResolutionRange, - bundleUpdateRange, - updateSnapshots, - globalRepository); + bundleContext.getBundle(), + bundleContext.getBundle(0).getBundleContext(), + stateStorage, + featureFinder, + eventAdminListener, + configInstaller, + digraph, + overrides, + featureResolutionRange, + bundleUpdateRange, + updateSnapshots, + globalRepository); register(FeaturesService.class, featuresService); featuresListenerTracker = new ServiceTracker<>( - bundleContext, FeaturesListener.class, new ServiceTrackerCustomizer() { - @Override - public FeaturesListener addingService(ServiceReference reference) { - FeaturesListener service = bundleContext.getService(reference); - featuresService.registerListener(service); - return service; - } - @Override - public void modifiedService(ServiceReference reference, FeaturesListener service) { - } - @Override - public void removedService(ServiceReference reference, FeaturesListener service) { - featuresService.unregisterListener(service); - bundleContext.ungetService(reference); - } - } + bundleContext, + FeaturesListener.class, + new ServiceTrackerCustomizer() { + @Override + public FeaturesListener addingService(ServiceReference reference) { + FeaturesListener service = bundleContext.getService(reference); + featuresService.registerListener(service); + return service; + } + + @Override + public void modifiedService(ServiceReference reference, FeaturesListener service) { + } + + @Override + public void removedService(ServiceReference reference, FeaturesListener service) { + featuresService.unregisterListener(service); + bundleContext.ungetService(reference); + } + } ); featuresListenerTracker.open(); http://git-wip-us.apache.org/repos/asf/karaf/blob/b6c5a173/features/core/src/main/java/org/apache/karaf/features/internal/region/AbstractRegionDigraphVisitor.java ---------------------------------------------------------------------- diff --git a/features/core/src/main/java/org/apache/karaf/features/internal/region/AbstractRegionDigraphVisitor.java b/features/core/src/main/java/org/apache/karaf/features/internal/region/AbstractRegionDigraphVisitor.java index 3ad2325..698db1b 100644 --- a/features/core/src/main/java/org/apache/karaf/features/internal/region/AbstractRegionDigraphVisitor.java +++ b/features/core/src/main/java/org/apache/karaf/features/internal/region/AbstractRegionDigraphVisitor.java @@ -80,8 +80,9 @@ public abstract class AbstractRegionDigraphVisitor implements RegionDigraphVi i.remove(); } } - if (candidates.isEmpty()) + if (candidates.isEmpty()) { return false; // this filter does not apply; avoid traversing this edge + } // push the filtered candidates for the next region filteredDeque.push(candidates); // push the allowed @@ -104,7 +105,7 @@ public abstract class AbstractRegionDigraphVisitor implements RegionDigraphVi /** * Determines whether the given region contains the given candidate. * - * @param region the {@link Region} + * @param region the {@link Region} * @param candidate the candidate * @return true if and only if the given region contains the given candidate */ @@ -114,7 +115,7 @@ public abstract class AbstractRegionDigraphVisitor implements RegionDigraphVi * Determines whether the given candidate is allowed by the given {@link RegionFilter}. * * @param candidate the candidate - * @param filter the filter + * @param filter the filter * @return true if and only if the given candidate is allowed by the given filter */ protected abstract boolean isAllowed(C candidate, RegionFilter filter); http://git-wip-us.apache.org/repos/asf/karaf/blob/b6c5a173/features/core/src/main/java/org/apache/karaf/features/internal/region/CandidateComparator.java ---------------------------------------------------------------------- diff --git a/features/core/src/main/java/org/apache/karaf/features/internal/region/CandidateComparator.java b/features/core/src/main/java/org/apache/karaf/features/internal/region/CandidateComparator.java index 74c014b..35d6043 100644 --- a/features/core/src/main/java/org/apache/karaf/features/internal/region/CandidateComparator.java +++ b/features/core/src/main/java/org/apache/karaf/features/internal/region/CandidateComparator.java @@ -25,10 +25,8 @@ import org.osgi.framework.namespace.PackageNamespace; import org.osgi.framework.wiring.BundleCapability; import org.osgi.resource.Capability; -public class CandidateComparator implements Comparator -{ - public int compare(Capability cap1, Capability cap2) - { +public class CandidateComparator implements Comparator { + public int compare(Capability cap1, Capability cap2) { int c = 0; // Always prefer system bundle if (cap1 instanceof BundleCapability && !(cap2 instanceof BundleCapability)) { @@ -37,12 +35,10 @@ public class CandidateComparator implements Comparator c = 1; } // Compare revision capabilities. - if ((c == 0) && cap1.getNamespace().equals(BundleNamespace.BUNDLE_NAMESPACE)) - { - c = ((Comparable) cap1.getAttributes().get(BundleNamespace.BUNDLE_NAMESPACE)) + if ((c == 0) && cap1.getNamespace().equals(BundleNamespace.BUNDLE_NAMESPACE)) { + c = ((Comparable) cap1.getAttributes().get(BundleNamespace.BUNDLE_NAMESPACE)) .compareTo(cap2.getAttributes().get(BundleNamespace.BUNDLE_NAMESPACE)); - if (c == 0) - { + if (c == 0) { Version v1 = (!cap1.getAttributes().containsKey(BundleNamespace.CAPABILITY_BUNDLE_VERSION_ATTRIBUTE)) ? Version.emptyVersion : (Version) cap1.getAttributes().get(BundleNamespace.CAPABILITY_BUNDLE_VERSION_ATTRIBUTE); @@ -53,14 +49,11 @@ public class CandidateComparator implements Comparator // highest version to have priority. c = compareVersions(v2, v1); } - } // Compare package capabilities. - else if ((c == 0) && cap1.getNamespace().equals(PackageNamespace.PACKAGE_NAMESPACE)) - { - c = ((Comparable) cap1.getAttributes().get(PackageNamespace.PACKAGE_NAMESPACE)) + } else if ((c == 0) && cap1.getNamespace().equals(PackageNamespace.PACKAGE_NAMESPACE)) { + c = ((Comparable) cap1.getAttributes().get(PackageNamespace.PACKAGE_NAMESPACE)) .compareTo(cap2.getAttributes().get(PackageNamespace.PACKAGE_NAMESPACE)); - if (c == 0) - { + if (c == 0) { Version v1 = (!cap1.getAttributes().containsKey(PackageNamespace.CAPABILITY_VERSION_ATTRIBUTE)) ? Version.emptyVersion : (Version) cap1.getAttributes().get(PackageNamespace.CAPABILITY_VERSION_ATTRIBUTE); @@ -71,8 +64,7 @@ public class CandidateComparator implements Comparator // highest version to have priority. c = compareVersions(v2, v1); // if same version, rather compare on the bundle version - if (c == 0) - { + if (c == 0) { v1 = (!cap1.getAttributes().containsKey(BundleNamespace.CAPABILITY_BUNDLE_VERSION_ATTRIBUTE)) ? Version.emptyVersion : (Version) cap1.getAttributes().get(BundleNamespace.CAPABILITY_BUNDLE_VERSION_ATTRIBUTE); @@ -84,14 +76,11 @@ public class CandidateComparator implements Comparator c = compareVersions(v2, v1); } } - } // Compare feature capabilities - else if ((c == 0) && cap1.getNamespace().equals(IdentityNamespace.IDENTITY_NAMESPACE)) - { - c = ((Comparable) cap1.getAttributes().get(IdentityNamespace.IDENTITY_NAMESPACE)) + } else if ((c == 0) && cap1.getNamespace().equals(IdentityNamespace.IDENTITY_NAMESPACE)) { + c = ((Comparable) cap1.getAttributes().get(IdentityNamespace.IDENTITY_NAMESPACE)) .compareTo(cap2.getAttributes().get(IdentityNamespace.IDENTITY_NAMESPACE)); - if (c == 0) - { + if (c == 0) { Version v1 = (!cap1.getAttributes().containsKey(IdentityNamespace.CAPABILITY_VERSION_ATTRIBUTE)) ? Version.emptyVersion : (Version) cap1.getAttributes().get(IdentityNamespace.CAPABILITY_VERSION_ATTRIBUTE); http://git-wip-us.apache.org/repos/asf/karaf/blob/b6c5a173/features/core/src/main/java/org/apache/karaf/features/internal/region/Subsystem.java ---------------------------------------------------------------------- diff --git a/features/core/src/main/java/org/apache/karaf/features/internal/region/Subsystem.java b/features/core/src/main/java/org/apache/karaf/features/internal/region/Subsystem.java index 8d6277a..d4e362f 100644 --- a/features/core/src/main/java/org/apache/karaf/features/internal/region/Subsystem.java +++ b/features/core/src/main/java/org/apache/karaf/features/internal/region/Subsystem.java @@ -188,7 +188,7 @@ public class Subsystem extends ResourceImpl { Capability identity = as.getCapabilities(IDENTITY_NAMESPACE).iterator().next(); Object bsn = identity.getAttributes().get(IDENTITY_NAMESPACE); Requirement requirement = new RequirementImpl(this, IDENTITY_NAMESPACE, - Collections.emptyMap(), + Collections.emptyMap(), Collections.singletonMap(IDENTITY_NAMESPACE, bsn)); addRequirement(requirement); // Add it to repo @@ -325,7 +325,7 @@ public class Subsystem extends ResourceImpl { for (DependencyInfo info : dependencies.values()) { installable.add(info.resource); addIdentityRequirement(info.resource, this, info.mandatory); - } + } } void addDependency(ResourceImpl resource, boolean mandatory, boolean start, int startLevel) { http://git-wip-us.apache.org/repos/asf/karaf/blob/b6c5a173/features/core/src/main/java/org/apache/karaf/features/internal/region/SubsystemResolver.java ---------------------------------------------------------------------- diff --git a/features/core/src/main/java/org/apache/karaf/features/internal/region/SubsystemResolver.java b/features/core/src/main/java/org/apache/karaf/features/internal/region/SubsystemResolver.java index 0478125..fbacb9c 100644 --- a/features/core/src/main/java/org/apache/karaf/features/internal/region/SubsystemResolver.java +++ b/features/core/src/main/java/org/apache/karaf/features/internal/region/SubsystemResolver.java @@ -105,7 +105,8 @@ public class SubsystemResolver { ss = getOrCreateChild(ss, parts[i]); } for (String feature : entry.getValue()) { - String name, range; + String name; + String range; int idx = feature.indexOf('/'); if (idx >= 0) { name = feature.substring(0, idx); @@ -257,7 +258,7 @@ public class SubsystemResolver { public Map getFeatures() { if (features == null) { SimpleFilter sf = createFilter(IDENTITY_NAMESPACE, "*", - CAPABILITY_TYPE_ATTRIBUTE, TYPE_FEATURE); + CAPABILITY_TYPE_ATTRIBUTE, TYPE_FEATURE); features = getResourceMapping(sf); } return features; @@ -268,7 +269,7 @@ public class SubsystemResolver { Map> wiring = getWiring(); Map resources = new HashMap<>(); SimpleFilter sf = createFilter(IDENTITY_NAMESPACE, "*", - CAPABILITY_TYPE_ATTRIBUTE, TYPE_SUBSYSTEM); + CAPABILITY_TYPE_ATTRIBUTE, TYPE_SUBSYSTEM); for (Resource resource : wiring.keySet()) { if (findMatchingCapability(resourceFilter, resource.getCapabilities(null)) != null) { // Find the subsystem where this feature is installed @@ -351,7 +352,7 @@ public class SubsystemResolver { private SimpleFilter createFilter(String... s) { Map attrs = new HashMap<>(); for (int i = 0; i < s.length - 1; i += 2) { - attrs.put(s[i], s[i+1]); + attrs.put(s[i], s[i + 1]); } return SimpleFilter.convert(attrs); @@ -391,9 +392,11 @@ public class SubsystemResolver { private RegionFilterBuilder createRegionFilterBuilder(RegionDigraph digraph, Map> sharingPolicy) throws InvalidSyntaxException { RegionFilterBuilder result = digraph.createRegionFilterBuilder(); - for (Map.Entry> entry : sharingPolicy.entrySet()) - for (String filter : entry.getValue()) + for (Map.Entry> entry : sharingPolicy.entrySet()) { + for (String filter : entry.getValue()) { result.allow(entry.getKey(), filter); + } + } return result; } http://git-wip-us.apache.org/repos/asf/karaf/blob/b6c5a173/features/core/src/main/java/org/apache/karaf/features/internal/repository/JsonRepository.java ---------------------------------------------------------------------- diff --git a/features/core/src/main/java/org/apache/karaf/features/internal/repository/JsonRepository.java b/features/core/src/main/java/org/apache/karaf/features/internal/repository/JsonRepository.java index f1f3c0b..270bcdf 100644 --- a/features/core/src/main/java/org/apache/karaf/features/internal/repository/JsonRepository.java +++ b/features/core/src/main/java/org/apache/karaf/features/internal/repository/JsonRepository.java @@ -102,11 +102,11 @@ public class JsonRepository extends BaseRepository { @SuppressWarnings("unchecked") private Map> verify(Object value) { - Map obj = Map.class.cast(value); - for (Map.Entry entry : obj.entrySet()) { + Map obj = Map.class.cast(value); + for (Map.Entry entry : obj.entrySet()) { String.class.cast(entry.getKey()); - Map child = Map.class.cast(entry.getValue()); - for (Map.Entry ce : child.entrySet()) { + Map child = Map.class.cast(entry.getValue()); + for (Map.Entry ce : child.entrySet()) { String.class.cast(ce.getKey()); String.class.cast(ce.getValue()); } http://git-wip-us.apache.org/repos/asf/karaf/blob/b6c5a173/features/core/src/main/java/org/apache/karaf/features/internal/repository/StaxParser.java ---------------------------------------------------------------------- diff --git a/features/core/src/main/java/org/apache/karaf/features/internal/repository/StaxParser.java b/features/core/src/main/java/org/apache/karaf/features/internal/repository/StaxParser.java index 9e13e8e..4b59b3d 100644 --- a/features/core/src/main/java/org/apache/karaf/features/internal/repository/StaxParser.java +++ b/features/core/src/main/java/org/apache/karaf/features/internal/repository/StaxParser.java @@ -1,20 +1,18 @@ /* - * 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 + * 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 + * 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. + * 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.karaf.features.internal.repository; @@ -42,7 +40,7 @@ import static javax.xml.stream.XMLStreamConstants.START_ELEMENT; /** * Repository XML xml based on StaX */ -public class StaxParser { +public final class StaxParser { public static final String REPOSITORY = "repository"; public static final String REPO_NAME = "name"; @@ -60,6 +58,11 @@ public class StaxParser { public static final String VALUE = "value"; public static final String TYPE = "type"; + static XMLInputFactory factory; + + private StaxParser() { + } + public static class Referral { String url; int depth = Integer.MAX_VALUE; @@ -68,8 +71,8 @@ public class StaxParser { public static class XmlRepository { String name; long increment; - List referrals = new ArrayList(); - List resources = new ArrayList(); + List referrals = new ArrayList<>(); + List resources = new ArrayList<>(); } public static XmlRepository parse(InputStream is) throws XMLStreamException { @@ -86,11 +89,14 @@ public class StaxParser { for (int i = 0, nb = reader.getAttributeCount(); i < nb; i++) { String attrName = reader.getAttributeLocalName(i); String attrValue = reader.getAttributeValue(i); - if (REPO_NAME.equals(attrName)) { + switch (attrName) { + case REPO_NAME: repo.name = attrName; - } else if (INCREMENT.equals(attrName)) { + break; + case INCREMENT: repo.increment = Integer.parseInt(attrValue); - } else { + break; + default: throw new IllegalStateException("Unexpected attribute '" + attrName + "'"); } } @@ -99,16 +105,20 @@ public class StaxParser { } while ((event = reader.nextTag()) == START_ELEMENT) { String element = reader.getLocalName(); - if (REFERRAL.equals(element)) { + switch (element) { + case REFERRAL: Referral referral = new Referral(); for (int i = 0, nb = reader.getAttributeCount(); i < nb; i++) { String attrName = reader.getAttributeLocalName(i); String attrValue = reader.getAttributeValue(i); - if (DEPTH.equals(attrName)) { + switch (attrName) { + case DEPTH: referral.depth = Integer.parseInt(attrValue); - } else if (URL.equals(attrName)) { + break; + case URL: referral.url = attrValue; - } else { + break; + default: throw new IllegalStateException("Unexpected attribute '" + attrName + "'"); } } @@ -117,9 +127,11 @@ public class StaxParser { } repo.referrals.add(referral); sanityCheckEndElement(reader, reader.nextTag(), REFERRAL); - } else if (RESOURCE.equals(element)) { + break; + case RESOURCE: repo.resources.add(parseResource(reader)); - } else { + break; + default: throw new IllegalStateException("Unsupported element '" + element + "'. Expected 'referral' or 'resource'"); } } @@ -143,19 +155,25 @@ public class StaxParser { int event; while ((event = reader.nextTag()) == START_ELEMENT) { String element = reader.getLocalName(); - if (CAPABILITY.equals(element)) { + switch (element) { + case CAPABILITY: resource.addCapability(parseCapability(reader, resource)); - } else if (REQUIREMENT.equals(element)) { + break; + case REQUIREMENT: resource.addRequirement(parseRequirement(reader, resource)); - } else { + break; + default: while ((event = reader.next()) != END_ELEMENT) { switch (event) { - case START_ELEMENT: - throw new IllegalStateException("Unexpected element '" + reader.getLocalName() + "' inside 'resource' element"); - case CHARACTERS: - throw new IllegalStateException("Unexpected text inside 'resource' element"); + case START_ELEMENT: + throw new IllegalStateException("Unexpected element '" + reader.getLocalName() + "' inside 'resource' element"); + case CHARACTERS: + throw new IllegalStateException("Unexpected text inside 'resource' element"); + default: + break; } } + break; } } // Sanity check @@ -173,8 +191,8 @@ public class StaxParser { private static CapabilityImpl parseCapability(XMLStreamReader reader, ResourceImpl resource) throws XMLStreamException { String[] namespace = new String[1]; - Map directives = new HashMap(); - Map attributes = new HashMap(); + Map directives = new HashMap<>(); + Map attributes = new HashMap<>(); parseClause(reader, namespace, directives, attributes); sanityCheckEndElement(reader, reader.getEventType(), CAPABILITY); return new CapabilityImpl(resource, namespace[0], directives, attributes); @@ -182,8 +200,8 @@ public class StaxParser { private static RequirementImpl parseRequirement(XMLStreamReader reader, ResourceImpl resource) throws XMLStreamException { String[] namespace = new String[1]; - Map directives = new HashMap(); - Map attributes = new HashMap(); + Map directives = new HashMap<>(); + Map attributes = new HashMap<>(); parseClause(reader, namespace, directives, attributes); sanityCheckEndElement(reader, reader.getEventType(), REQUIREMENT); return new RequirementImpl(resource, namespace[0], directives, attributes); @@ -205,17 +223,21 @@ public class StaxParser { } while (reader.nextTag() == START_ELEMENT) { String element = reader.getLocalName(); - if (DIRECTIVE.equals(element)) { + switch (element) { + case DIRECTIVE: { String name = null; String value = null; for (int i = 0, nb = reader.getAttributeCount(); i < nb; i++) { String attName = reader.getAttributeLocalName(i); String attValue = reader.getAttributeValue(i); - if (NAME.equals(attName)) { + switch (attName) { + case NAME: name = attValue; - } else if (VALUE.equals(attName)) { + break; + case VALUE: value = attValue; - } else { + break; + default: throw new IllegalStateException("Unexpected attribute: '" + attName + "'. Expected 'name', or 'value'."); } } @@ -224,20 +246,26 @@ public class StaxParser { } directives.put(name, value); sanityCheckEndElement(reader, reader.nextTag(), DIRECTIVE); - } else if (ATTRIBUTE.equals(element)) { + break; + } + case ATTRIBUTE: { String name = null; String value = null; String type = "String"; for (int i = 0, nb = reader.getAttributeCount(); i < nb; i++) { String attName = reader.getAttributeLocalName(i); String attValue = reader.getAttributeValue(i); - if (NAME.equals(attName)) { + switch (attName) { + case NAME: name = attValue; - } else if (VALUE.equals(attName)) { + break; + case VALUE: value = attValue; - } else if (TYPE.equals(attName)) { + break; + case TYPE: type = attValue; - } else { + break; + default: throw new IllegalStateException("Unexpected attribute: '" + attName + "'. Expected 'name', 'value' or 'type'."); } } @@ -246,7 +274,9 @@ public class StaxParser { } attributes.put(name, parseAttribute(value, type)); sanityCheckEndElement(reader, reader.nextTag(), ATTRIBUTE); - } else { + break; + } + default: throw new IllegalStateException("Unexpected element: '" + element + ". Expected 'directive' or 'attribute'"); } } @@ -263,7 +293,7 @@ public class StaxParser { return Double.parseDouble(value.trim()); } else if (type.startsWith("List<") && type.endsWith(">")) { type = type.substring("List<".length(), type.length() - 1); - List list = new ArrayList(); + List list = new ArrayList<>(); for (String s : value.split(",")) { list.add(parseAttribute(s.trim(), type)); } @@ -273,8 +303,6 @@ public class StaxParser { } } - static XMLInputFactory factory; - private static synchronized XMLInputFactory getFactory() { if (StaxParser.factory == null) { XMLInputFactory factory = XMLInputFactory.newInstance(); @@ -284,6 +312,4 @@ public class StaxParser { return StaxParser.factory; } - private StaxParser() { - } } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/karaf/blob/b6c5a173/features/core/src/main/java/org/apache/karaf/features/internal/repository/UrlLoader.java ---------------------------------------------------------------------- diff --git a/features/core/src/main/java/org/apache/karaf/features/internal/repository/UrlLoader.java b/features/core/src/main/java/org/apache/karaf/features/internal/repository/UrlLoader.java index 77db247..640837a 100644 --- a/features/core/src/main/java/org/apache/karaf/features/internal/repository/UrlLoader.java +++ b/features/core/src/main/java/org/apache/karaf/features/internal/repository/UrlLoader.java @@ -62,7 +62,7 @@ public abstract class UrlLoader { return false; } try ( - BufferedInputStream bis = new BufferedInputStream(connection.getInputStream()) + BufferedInputStream bis = new BufferedInputStream(connection.getInputStream()) ) { // Auto-detect gzipped streams InputStream is = bis; http://git-wip-us.apache.org/repos/asf/karaf/blob/b6c5a173/features/core/src/main/java/org/apache/karaf/features/internal/resolver/CapabilityImpl.java ---------------------------------------------------------------------- diff --git a/features/core/src/main/java/org/apache/karaf/features/internal/resolver/CapabilityImpl.java b/features/core/src/main/java/org/apache/karaf/features/internal/resolver/CapabilityImpl.java index bfe9b40..ba6bfd7 100644 --- a/features/core/src/main/java/org/apache/karaf/features/internal/resolver/CapabilityImpl.java +++ b/features/core/src/main/java/org/apache/karaf/features/internal/resolver/CapabilityImpl.java @@ -16,13 +16,11 @@ */ package org.apache.karaf.features.internal.resolver; -import java.util.ArrayList; import java.util.Collections; import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; -import java.util.StringTokenizer; import org.osgi.framework.Constants; import org.osgi.resource.Capability; @@ -30,136 +28,56 @@ import org.osgi.resource.Resource; public class CapabilityImpl extends BaseClause implements Capability { - private final Resource m_resource; - 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 CapabilityImpl(Capability capability) { - this(null, capability.getNamespace(), capability.getDirectives(), capability.getAttributes()); - } + private final Resource resource; + private final String namespace; + private final Map dirs; + private final Map attrs; + private final Set mandatory; public CapabilityImpl(Resource resource, String namespace, Map dirs, Map attrs) { - m_namespace = namespace; - m_resource = resource; - m_dirs = dirs; - m_attrs = attrs; - - // Find all export directives: uses, mandatory, include, and exclude. - - List uses = Collections.emptyList(); - 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 = ResourceBuilder.parseDelimitedString(value, ","); - m_includeFilter = new ArrayList>(filters.size()); - for (String filter : filters) { - List substrings = SimpleFilter.parseSubstring(filter); - m_includeFilter.add(substrings); - } - } else { - m_includeFilter = null; - } - - value = m_dirs.get(Constants.EXCLUDE_DIRECTIVE); - if (value != null) { - List filters = ResourceBuilder.parseDelimitedString(value, ","); - m_excludeFilter = new ArrayList>(filters.size()); - for (String filter : filters) { - List substrings = SimpleFilter.parseSubstring(filter); - m_excludeFilter.add(substrings); - } - } else { - m_excludeFilter = null; - } + this.namespace = namespace; + this.resource = resource; + this.dirs = dirs; + this.attrs = attrs; + // Handle mandatory directive Set mandatory = Collections.emptySet(); - value = m_dirs.get(Constants.MANDATORY_DIRECTIVE); + String value = this.dirs.get(Constants.MANDATORY_DIRECTIVE); if (value != null) { List names = ResourceBuilder.parseDelimitedString(value, ","); - mandatory = new HashSet(names.size()); + mandatory = new HashSet<>(names.size()); for (String name : names) { // If attribute exists, then record it as mandatory. - if (m_attrs.containsKey(name)) { + if (this.attrs.containsKey(name)) { mandatory.add(name); - } // Otherwise, report an error. - else { + } else { throw new IllegalArgumentException("Mandatory attribute '" + name + "' does not exist."); } } } - m_mandatory = mandatory; + this.mandatory = mandatory; } public Resource getResource() { - return m_resource; + return resource; } public String getNamespace() { - return m_namespace; + return namespace; } public Map getDirectives() { - return m_dirs; + return dirs; } public Map getAttributes() { - return m_attrs; + return 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 = 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; - } - - private static String getClassName(String className) { - if (className == null) { - className = ""; - } - return (className.lastIndexOf('.') < 0) ? "" : className.substring(className.lastIndexOf('.') + 1); + return !mandatory.isEmpty() && mandatory.contains(name); } } http://git-wip-us.apache.org/repos/asf/karaf/blob/b6c5a173/features/core/src/main/java/org/apache/karaf/features/internal/resolver/CapabilitySet.java ---------------------------------------------------------------------- diff --git a/features/core/src/main/java/org/apache/karaf/features/internal/resolver/CapabilitySet.java b/features/core/src/main/java/org/apache/karaf/features/internal/resolver/CapabilitySet.java index 4c5656d..46fd571 100644 --- a/features/core/src/main/java/org/apache/karaf/features/internal/resolver/CapabilitySet.java +++ b/features/core/src/main/java/org/apache/karaf/features/internal/resolver/CapabilitySet.java @@ -32,74 +32,60 @@ import java.util.TreeMap; import org.osgi.framework.Constants; import org.osgi.resource.Capability; -public class CapabilitySet -{ - private final Map>> m_indices; - private final Set m_capSet = new HashSet(); - -public void dump() -{ - for (Entry>> entry : m_indices.entrySet()) - { - boolean header1 = false; - for (Entry> entry2 : entry.getValue().entrySet()) - { - boolean header2 = false; - for (Capability cap : entry2.getValue()) - { - if (!header1) - { - System.out.println(entry.getKey() + ":"); - header1 = true; - } - if (!header2) - { - System.out.println(" " + entry2.getKey()); - header2 = true; - } - System.out.println(" " + cap); - } +public class CapabilitySet { + + private static final Class[] STRING_CLASS = new Class[] {String.class}; + + private final Map>> indices; + private final Set capSet = new HashSet<>(); + + public CapabilitySet(List indexProps) { + indices = new TreeMap<>(); + for (int i = 0; (indexProps != null) && (i < indexProps.size()); i++) { + indices.put( + indexProps.get(i), new HashMap>()); } } -} - public CapabilitySet(List indexProps) - { - m_indices = new TreeMap>>(); - for (int i = 0; (indexProps != null) && (i < indexProps.size()); i++) - { - m_indices.put( - indexProps.get(i), new HashMap>()); + public void dump() { + for (Entry>> entry : indices.entrySet()) { + boolean header1 = false; + for (Entry> entry2 : entry.getValue().entrySet()) { + boolean header2 = false; + for (Capability cap : entry2.getValue()) { + if (!header1) { + System.out.println(entry.getKey() + ":"); + header1 = true; + } + if (!header2) { + System.out.println(" " + entry2.getKey()); + header2 = true; + } + System.out.println(" " + cap); + } + } } } - public void addCapability(Capability cap) - { - m_capSet.add(cap); + public void addCapability(Capability cap) { + capSet.add(cap); // Index capability. - for (Entry>> entry : m_indices.entrySet()) - { + for (Entry>> entry : indices.entrySet()) { Object value = cap.getAttributes().get(entry.getKey()); - if (value != null) - { - if (value.getClass().isArray()) - { + if (value != null) { + if (value.getClass().isArray()) { value = convertArrayToList(value); } Map> index = entry.getValue(); - if (value instanceof Collection) - { + if (value instanceof Collection) { Collection c = (Collection) value; - for (Object o : c) - { + for (Object o : c) { indexCapability(index, cap, o); } - } - else - { + } else { indexCapability(index, cap, value); } } @@ -107,43 +93,32 @@ public void dump() } private void indexCapability( - Map> index, Capability cap, Object capValue) - { + Map> index, Capability cap, Object capValue) { Set caps = index.get(capValue); - if (caps == null) - { - caps = new HashSet(); + if (caps == null) { + caps = new HashSet<>(); index.put(capValue, caps); } caps.add(cap); } - public void removeCapability(Capability cap) - { - if (m_capSet.remove(cap)) - { - for (Entry>> entry : m_indices.entrySet()) - { + public void removeCapability(Capability cap) { + if (capSet.remove(cap)) { + for (Entry>> entry : indices.entrySet()) { Object value = cap.getAttributes().get(entry.getKey()); - if (value != null) - { - if (value.getClass().isArray()) - { + if (value != null) { + if (value.getClass().isArray()) { value = convertArrayToList(value); } Map> index = entry.getValue(); - if (value instanceof Collection) - { + if (value instanceof Collection) { Collection c = (Collection) value; - for (Object o : c) - { + for (Object o : c) { deindexCapability(index, cap, o); } - } - else - { + } else { deindexCapability(index, cap, value); } } @@ -152,91 +127,67 @@ public void dump() } private void deindexCapability( - Map> index, Capability cap, Object value) - { + Map> index, Capability cap, Object value) { Set caps = index.get(value); - if (caps != null) - { + if (caps != null) { caps.remove(cap); - if (caps.isEmpty()) - { + if (caps.isEmpty()) { index.remove(value); } } } - public Set match(SimpleFilter sf, boolean obeyMandatory) - { - Set matches = match(m_capSet, sf); - return (obeyMandatory) - ? matchMandatory(matches, sf) - : matches; + public Set match(SimpleFilter sf, boolean obeyMandatory) { + Set matches = match(capSet, sf); + return obeyMandatory + ? matchMandatory(matches, sf) + : matches; } - private Set match(Set caps, SimpleFilter sf) - { - Set matches = new HashSet(); + @SuppressWarnings("unchecked") + private Set match(Set caps, SimpleFilter sf) { + Set matches = new HashSet<>(); - if (sf.getOperation() == SimpleFilter.MATCH_ALL) - { + if (sf.getOperation() == SimpleFilter.MATCH_ALL) { matches.addAll(caps); - } - else if (sf.getOperation() == SimpleFilter.AND) - { + } else if (sf.getOperation() == SimpleFilter.AND) { // Evaluate each subfilter against the remaining capabilities. // For AND we calculate the intersection of each subfilter. // We can short-circuit the AND operation if there are no // remaining capabilities. List sfs = (List) sf.getValue(); - for (int i = 0; (caps.size() > 0) && (i < sfs.size()); i++) - { + for (int i = 0; (caps.size() > 0) && (i < sfs.size()); i++) { matches = match(caps, sfs.get(i)); caps = matches; } - } - else if (sf.getOperation() == SimpleFilter.OR) - { + } else if (sf.getOperation() == SimpleFilter.OR) { // Evaluate each subfilter against the remaining capabilities. // For OR we calculate the union of each subfilter. List sfs = (List) sf.getValue(); - for (int i = 0; i < sfs.size(); i++) - { - matches.addAll(match(caps, sfs.get(i))); + for (SimpleFilter sf1 : sfs) { + matches.addAll(match(caps, sf1)); } - } - else if (sf.getOperation() == SimpleFilter.NOT) - { + } else if (sf.getOperation() == SimpleFilter.NOT) { // Evaluate each subfilter against the remaining capabilities. // For OR we calculate the union of each subfilter. matches.addAll(caps); List sfs = (List) sf.getValue(); - for (int i = 0; i < sfs.size(); i++) - { - matches.removeAll(match(caps, sfs.get(i))); + for (SimpleFilter sf1 : sfs) { + matches.removeAll(match(caps, sf1)); } - } - else - { - Map> index = m_indices.get(sf.getName()); - if ((sf.getOperation() == SimpleFilter.EQ) && (index != null)) - { + } else { + Map> index = indices.get(sf.getName()); + if ((sf.getOperation() == SimpleFilter.EQ) && (index != null)) { Set existingCaps = index.get(sf.getValue()); - if (existingCaps != null) - { + if (existingCaps != null) { matches.addAll(existingCaps); matches.retainAll(caps); } - } - else - { - for (Iterator it = caps.iterator(); it.hasNext(); ) - { - Capability cap = it.next(); + } else { + for (Capability cap : caps) { Object lhs = cap.getAttributes().get(sf.getName()); - if (lhs != null) - { - if (compare(lhs, sf.getValue(), sf.getOperation())) - { + if (lhs != null) { + if (compare(lhs, sf.getValue(), sf.getOperation())) { matches.add(cap); } } @@ -247,58 +198,44 @@ public void dump() return matches; } - public static boolean matches(Capability cap, SimpleFilter sf) - { + public static boolean matches(Capability cap, SimpleFilter sf) { return matchesInternal(cap, sf) && matchMandatory(cap, sf); } - private static boolean matchesInternal(Capability cap, SimpleFilter sf) - { + @SuppressWarnings("unchecked") + private static boolean matchesInternal(Capability cap, SimpleFilter sf) { boolean matched = true; - if (sf.getOperation() == SimpleFilter.MATCH_ALL) - { + if (sf.getOperation() == SimpleFilter.MATCH_ALL) { matched = true; - } - else if (sf.getOperation() == SimpleFilter.AND) - { + } else if (sf.getOperation() == SimpleFilter.AND) { // Evaluate each subfilter against the remaining capabilities. // For AND we calculate the intersection of each subfilter. // We can short-circuit the AND operation if there are no // remaining capabilities. List sfs = (List) sf.getValue(); - for (int i = 0; matched && (i < sfs.size()); i++) - { + for (int i = 0; matched && (i < sfs.size()); i++) { matched = matchesInternal(cap, sfs.get(i)); } - } - else if (sf.getOperation() == SimpleFilter.OR) - { + } else if (sf.getOperation() == SimpleFilter.OR) { // Evaluate each subfilter against the remaining capabilities. // For OR we calculate the union of each subfilter. matched = false; List sfs = (List) sf.getValue(); - for (int i = 0; !matched && (i < sfs.size()); i++) - { + for (int i = 0; !matched && (i < sfs.size()); i++) { matched = matchesInternal(cap, sfs.get(i)); } - } - else if (sf.getOperation() == SimpleFilter.NOT) - { + } else if (sf.getOperation() == SimpleFilter.NOT) { // Evaluate each subfilter against the remaining capabilities. // For OR we calculate the union of each subfilter. List sfs = (List) sf.getValue(); - for (int i = 0; i < sfs.size(); i++) - { - matched = !(matchesInternal(cap, sfs.get(i))); + for (SimpleFilter sf1 : sfs) { + matched = !(matchesInternal(cap, sf1)); } - } - else - { + } else { matched = false; Object lhs = cap.getAttributes().get(sf.getName()); - if (lhs != null) - { + if (lhs != null) { matched = compare(lhs, sf.getValue(), sf.getOperation()); } } @@ -307,27 +244,21 @@ public void dump() } private static Set matchMandatory( - Set caps, SimpleFilter sf) - { - for (Iterator it = caps.iterator(); it.hasNext(); ) - { + Set caps, SimpleFilter sf) { + for (Iterator it = caps.iterator(); it.hasNext();) { Capability cap = it.next(); - if (!matchMandatory(cap, sf)) - { + if (!matchMandatory(cap, sf)) { it.remove(); } } return caps; } - private static boolean matchMandatory(Capability cap, SimpleFilter sf) - { + private static boolean matchMandatory(Capability cap, SimpleFilter sf) { if (cap instanceof CapabilityImpl) { - for (Entry entry : cap.getAttributes().entrySet()) - { + for (Entry entry : cap.getAttributes().entrySet()) { if (((CapabilityImpl) cap).isAttributeMandatory(entry.getKey()) - && !matchMandatoryAttribute(entry.getKey(), sf)) - { + && !matchMandatoryAttribute(entry.getKey(), sf)) { return false; } } @@ -335,11 +266,9 @@ public void dump() String value = cap.getDirectives().get(Constants.MANDATORY_DIRECTIVE); if (value != null) { List names = ResourceBuilder.parseDelimitedString(value, ","); - for (Entry entry : cap.getAttributes().entrySet()) - { + for (Entry entry : cap.getAttributes().entrySet()) { if (names.contains(entry.getKey()) - && !matchMandatoryAttribute(entry.getKey(), sf)) - { + && !matchMandatoryAttribute(entry.getKey(), sf)) { return false; } } @@ -349,21 +278,15 @@ public void dump() return true; } - private static boolean matchMandatoryAttribute(String attrName, SimpleFilter sf) - { - if ((sf.getName() != null) && sf.getName().equals(attrName)) - { + private static boolean matchMandatoryAttribute(String attrName, SimpleFilter sf) { + if ((sf.getName() != null) && sf.getName().equals(attrName)) { return true; - } - else if (sf.getOperation() == SimpleFilter.AND) - { + } else if (sf.getOperation() == SimpleFilter.AND) { List list = (List) sf.getValue(); - for (int i = 0; i < list.size(); i++) - { - SimpleFilter sf2 = (SimpleFilter) list.get(i); + for (Object aList : list) { + SimpleFilter sf2 = (SimpleFilter) aList; if ((sf2.getName() != null) - && sf2.getName().equals(attrName)) - { + && sf2.getName().equals(attrName)) { return true; } } @@ -371,129 +294,77 @@ public void dump() return false; } - private static final Class[] STRING_CLASS = new Class[] { String.class }; - - private static boolean compare(Object lhs, Object rhsUnknown, int op) - { - if (lhs == null) - { + @SuppressWarnings("unchecked") + private static boolean compare(Object lhs, Object rhsUnknown, int op) { + if (lhs == null) { return false; } // If this is a PRESENT operation, then just return true immediately // since we wouldn't be here if the attribute wasn't present. - if (op == SimpleFilter.PRESENT) - { + if (op == SimpleFilter.PRESENT) { return true; } // If the type is comparable, then we can just return the // result immediately. - if (lhs instanceof Comparable) - { + if (lhs instanceof Comparable) { // Spec says SUBSTRING is false for all types other than string. - if ((op == SimpleFilter.SUBSTRING) && !(lhs instanceof String)) - { + if ((op == SimpleFilter.SUBSTRING) && !(lhs instanceof String)) { return false; } Object rhs; - if (op == SimpleFilter.SUBSTRING) - { + if (op == SimpleFilter.SUBSTRING) { rhs = rhsUnknown; - } - else - { - try - { + } else { + try { rhs = coerceType(lhs, (String) rhsUnknown); - } - catch (Exception ex) - { + } catch (Exception ex) { return false; } } - switch (op) - { - case SimpleFilter.EQ : - try - { - return (((Comparable) lhs).compareTo(rhs) == 0); - } - catch (Exception ex) - { - return false; - } - case SimpleFilter.GTE : - try - { - return (((Comparable) lhs).compareTo(rhs) >= 0); - } - catch (Exception ex) - { - return false; - } - case SimpleFilter.LTE : - try - { - return (((Comparable) lhs).compareTo(rhs) <= 0); - } - catch (Exception ex) - { - return false; - } - case SimpleFilter.APPROX : - return compareApproximate(((Comparable) lhs), rhs); - case SimpleFilter.SUBSTRING : - return SimpleFilter.compareSubstring((List) rhs, (String) lhs); - default: - throw new RuntimeException( - "Unknown comparison operator: " + op); - } - } - // Booleans do not implement comparable, so special case them. - else if (lhs instanceof Boolean) - { - Object rhs; - try - { - rhs = coerceType(lhs, (String) rhsUnknown); - } - catch (Exception ex) - { - return false; - } - - switch (op) - { - case SimpleFilter.EQ : - case SimpleFilter.GTE : - case SimpleFilter.LTE : - case SimpleFilter.APPROX : - return (lhs.equals(rhs)); - default: - throw new RuntimeException( - "Unknown comparison operator: " + op); + switch (op) { + case SimpleFilter.EQ: + try { + return ((Comparable) lhs).compareTo(rhs) == 0; + } catch (Exception ex) { + return false; + } + case SimpleFilter.GTE: + try { + return ((Comparable) lhs).compareTo(rhs) >= 0; + } catch (Exception ex) { + return false; + } + case SimpleFilter.LTE: + try { + return ((Comparable) lhs).compareTo(rhs) <= 0; + } catch (Exception ex) { + return false; + } + case SimpleFilter.APPROX: + return compareApproximate(lhs, rhs); + case SimpleFilter.SUBSTRING: + return SimpleFilter.compareSubstring((List) rhs, (String) lhs); + default: + throw new RuntimeException("Unknown comparison operator: " + op); } } // If the LHS is not a comparable or boolean, check if it is an // array. If so, convert it to a list so we can treat it as a // collection. - if (lhs.getClass().isArray()) - { + if (lhs.getClass().isArray()) { lhs = convertArrayToList(lhs); } // If LHS is a collection, then call compare() on each element // of the collection until a match is found. - if (lhs instanceof Collection) - { - for (Iterator iter = ((Collection) lhs).iterator(); iter.hasNext(); ) - { - if (compare(iter.next(), rhsUnknown, op)) - { + if (lhs instanceof Collection) { + for (Object o : (Collection) lhs) { + if (compare(o, rhsUnknown, op)) { return true; } } @@ -502,90 +373,71 @@ public void dump() } // Spec says SUBSTRING is false for all types other than string. - if ((op == SimpleFilter.SUBSTRING) && !(lhs instanceof String)) - { + if (op == SimpleFilter.SUBSTRING) { return false; } // Since we cannot identify the LHS type, then we can only perform // equality comparison. - try - { + try { return lhs.equals(coerceType(lhs, (String) rhsUnknown)); - } - catch (Exception ex) - { + } catch (Exception ex) { return false; } } - private static boolean compareApproximate(Object lhs, Object rhs) - { - if (rhs instanceof String) - { + private static boolean compareApproximate(Object lhs, Object rhs) { + if (rhs instanceof String) { return removeWhitespace((String) lhs) - .equalsIgnoreCase(removeWhitespace((String) rhs)); - } - else if (rhs instanceof Character) - { - return Character.toLowerCase(((Character) lhs)) - == Character.toLowerCase(((Character) rhs)); + .equalsIgnoreCase(removeWhitespace((String) rhs)); + } else if (rhs instanceof Character) { + return Character.toLowerCase((Character) lhs) + == Character.toLowerCase((Character) rhs); } return lhs.equals(rhs); } - private static String removeWhitespace(String s) - { - StringBuffer sb = new StringBuffer(s.length()); - for (int i = 0; i < s.length(); i++) - { - if (!Character.isWhitespace(s.charAt(i))) - { + private static String removeWhitespace(String s) { + StringBuilder sb = new StringBuilder(s.length()); + for (int i = 0; i < s.length(); i++) { + if (!Character.isWhitespace(s.charAt(i))) { sb.append(s.charAt(i)); } } return sb.toString(); } - private static Object coerceType(Object lhs, String rhsString) throws Exception - { + private static Object coerceType(Object lhs, String rhsString) throws Exception { // If the LHS expects a string, then we can just return // the RHS since it is a string. - if (lhs.getClass() == rhsString.getClass()) - { + if (lhs.getClass() == rhsString.getClass()) { return rhsString; } // Try to convert the RHS type to the LHS type by using // the string constructor of the LHS class, if it has one. - Object rhs = null; - try - { + Object rhs; + try { // The Character class is a special case, since its constructor // does not take a string, so handle it separately. - if (lhs instanceof Character) - { - rhs = new Character(rhsString.charAt(0)); - } - else - { + if (lhs instanceof Character) { + rhs = rhsString.charAt(0); + } else { // Spec says we should trim number types. - if ((lhs instanceof Number) || (lhs instanceof Boolean)) - { + if ((lhs instanceof Number) || (lhs instanceof Boolean)) { rhsString = rhsString.trim(); } Constructor ctor = lhs.getClass().getConstructor(STRING_CLASS); ctor.setAccessible(true); - rhs = ctor.newInstance(new Object[] { rhsString }); + rhs = ctor.newInstance(rhsString); } - } - catch (Exception ex) - { + } catch (Exception ex) { throw new Exception( - "Could not instantiate class " - + lhs.getClass().getName() - + " from string constructor with argument '" - + rhsString + "' because " + ex); + "Could not instantiate class " + + lhs.getClass().getName() + + " from string constructor with argument '" + + rhsString + "' because " + ex + ); } return rhs; @@ -596,15 +448,14 @@ public void dump() * to an array of primitive wrapper objects. This method simplifies * processing LDAP filters since the special case of primitive arrays * can be ignored. + * * @param array An array of primitive types. * @return An corresponding array using pritive wrapper objects. - **/ - private static List convertArrayToList(Object array) - { + */ + private static List convertArrayToList(Object array) { int len = Array.getLength(array); - List list = new ArrayList(len); - for (int i = 0; i < len; i++) - { + List list = new ArrayList<>(len); + for (int i = 0; i < len; i++) { list.add(Array.get(array, i)); } return list; http://git-wip-us.apache.org/repos/asf/karaf/blob/b6c5a173/features/core/src/main/java/org/apache/karaf/features/internal/resolver/FeatureResource.java ---------------------------------------------------------------------- diff --git a/features/core/src/main/java/org/apache/karaf/features/internal/resolver/FeatureResource.java b/features/core/src/main/java/org/apache/karaf/features/internal/resolver/FeatureResource.java index 707a213..15cfcc1 100644 --- a/features/core/src/main/java/org/apache/karaf/features/internal/resolver/FeatureResource.java +++ b/features/core/src/main/java/org/apache/karaf/features/internal/resolver/FeatureResource.java @@ -33,11 +33,16 @@ import static org.apache.karaf.features.internal.resolver.ResourceUtils.TYPE_FEA import static org.apache.karaf.features.internal.resolver.ResourceUtils.addIdentityRequirement; /** -*/ -public class FeatureResource extends ResourceImpl { + */ +public final class FeatureResource extends ResourceImpl { private final Feature feature; + private FeatureResource(Feature feature) { + super(feature.getName(), TYPE_FEATURE, VersionTable.getVersion(feature.getVersion())); + this.feature = feature; + } + public static FeatureResource build(Feature feature, Conditional conditional, String featureRange, Map locToRes) throws BundleException { Feature fcond = conditional.asFeature(feature.getName(), feature.getVersion()); FeatureResource resource = build(fcond, featureRange, locToRes); @@ -97,11 +102,6 @@ public class FeatureResource extends ResourceImpl { addIdentityRequirement(resource, name, TYPE_FEATURE, version); } - public FeatureResource(Feature feature) { - super(feature.getName(), TYPE_FEATURE, VersionTable.getVersion(feature.getVersion())); - this.feature = feature; - } - public Feature getFeature() { return feature; } http://git-wip-us.apache.org/repos/asf/karaf/blob/b6c5a173/features/core/src/main/java/org/apache/karaf/features/internal/resolver/RequirementImpl.java ---------------------------------------------------------------------- diff --git a/features/core/src/main/java/org/apache/karaf/features/internal/resolver/RequirementImpl.java b/features/core/src/main/java/org/apache/karaf/features/internal/resolver/RequirementImpl.java index a4ef775..f03fbb3 100644 --- a/features/core/src/main/java/org/apache/karaf/features/internal/resolver/RequirementImpl.java +++ b/features/core/src/main/java/org/apache/karaf/features/internal/resolver/RequirementImpl.java @@ -24,23 +24,24 @@ import org.osgi.resource.Requirement; import org.osgi.resource.Resource; public class RequirementImpl extends BaseClause implements Requirement { - private final Resource m_resource; - 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; + + private final Resource resource; + private final String namespace; + private final SimpleFilter filter; + private final boolean optional; + private final Map dirs; + private final Map attrs; public RequirementImpl( Resource resource, String namespace, Map dirs, Map attrs, SimpleFilter filter) { - m_resource = resource; - m_namespace = namespace; - m_dirs = dirs; - m_attrs = attrs; - m_filter = filter; + this.resource = resource; + this.namespace = namespace; + this.dirs = dirs; + this.attrs = attrs; + this.filter = filter; // Find resolution import directives. - m_optional = Constants.RESOLUTION_OPTIONAL.equals(m_dirs.get(Constants.RESOLUTION_DIRECTIVE)); + optional = Constants.RESOLUTION_OPTIONAL.equals(this.dirs.get(Constants.RESOLUTION_DIRECTIVE)); } public RequirementImpl( @@ -50,19 +51,19 @@ public class RequirementImpl extends BaseClause implements Requirement { } public String getNamespace() { - return m_namespace; + return namespace; } public Map getDirectives() { - return m_dirs; + return dirs; } public Map getAttributes() { - return m_attrs; + return attrs; } public Resource getResource() { - return m_resource; + return resource; } public boolean matches(Capability cap) { @@ -70,11 +71,11 @@ public class RequirementImpl extends BaseClause implements Requirement { } public boolean isOptional() { - return m_optional; + return optional; } public SimpleFilter getFilter() { - return m_filter; + return filter; } }