Save This Page
Home » maven-launchpad-plugin-2.0.6-source-release » org.apache.sling.maven.projectsupport.bundlelist » [javadoc | source]
    1   /*
    2    * Licensed to the Apache Software Foundation (ASF) under one or more
    3    * contributor license agreements. See the NOTICE file distributed with this
    4    * work for additional information regarding copyright ownership. The ASF
    5    * licenses this file to You under the Apache License, Version 2.0 (the
    6    * "License"); you may not use this file except in compliance with the License.
    7    * You may obtain a copy of the License at
    8    *
    9    * http://www.apache.org/licenses/LICENSE-2.0
   10    *
   11    * Unless required by applicable law or agreed to in writing, software
   12    * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
   13    * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
   14    * License for the specific language governing permissions and limitations under
   15    * the License.
   16    */
   17   package org.apache.sling.maven.projectsupport.bundlelist;
   18   
   19   import java.util.List;
   20   import java.util.ListIterator;
   21   
   22   import org.apache.sling.maven.projectsupport.bundlelist.v1_0_0.Bundle;
   23   
   24   public abstract class BaseStartLevel {
   25   
   26       public abstract List<Bundle> getBundles();
   27   
   28       public boolean removeBundle(Bundle bundle, boolean compareVersions) {
   29           for (ListIterator<Bundle> it = getBundles().listIterator(); it.hasNext();) {
   30               if (isSameArtifact(bundle, it.next(), compareVersions)) {
   31                   it.remove();
   32                   return true;
   33               }
   34           }
   35           return false;
   36       }
   37   
   38       public boolean containsBundle(Bundle bundle, boolean compareVersions) {
   39           for (Bundle compare : getBundles()) {
   40               return isSameArtifact(bundle, compare, compareVersions);
   41           }
   42           return false;
   43       }
   44   
   45       public Bundle getBundle(Bundle bundle, boolean compareVersions) {
   46           for (Bundle compare : getBundles()) {
   47               if (isSameArtifact(bundle, compare, compareVersions)) {
   48                   return compare;
   49               }
   50           }
   51           return null;
   52       }
   53   
   54       private boolean isSameArtifact(Bundle bundle1, Bundle bundle2, boolean compareVersions) {
   55           boolean result = compareVersions ? bundle1.getVersion().equals(bundle2) : true;
   56           return result && bundle1.getArtifactId().equals(bundle2.getArtifactId())
   57                   && bundle1.getGroupId().equals(bundle2.getGroupId()) && bundle1.getType().equals(bundle2.getType());
   58       }
   59   
   60   }

Save This Page
Home » maven-launchpad-plugin-2.0.6-source-release » org.apache.sling.maven.projectsupport.bundlelist » [javadoc | source]