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   
   21   import org.apache.sling.maven.projectsupport.bundlelist.v1_0_0.Bundle;
   22   import org.apache.sling.maven.projectsupport.bundlelist.v1_0_0.BundleList;
   23   import org.apache.sling.maven.projectsupport.bundlelist.v1_0_0.StartLevel;
   24   
   25   public abstract class BaseBundleList {
   26   
   27       public abstract List<StartLevel> getStartLevels();
   28   
   29       public Bundle get(Bundle bundle, boolean compareVersions) {
   30           for (StartLevel sl : getStartLevels()) {
   31               Bundle foundBundle = sl.getBundle(bundle, compareVersions);
   32               if (foundBundle != null) {
   33                   return foundBundle;
   34               }
   35           }
   36           return null;
   37       }
   38   
   39       public boolean remove(Bundle bundle, boolean compareVersions) {
   40           for (StartLevel sl : getStartLevels()) {
   41               if (sl.removeBundle(bundle, compareVersions)) {
   42                   return true;
   43               }
   44           }
   45           return false;
   46       }
   47   
   48   
   49       /**
   50        * Merge the current bundle list with an additional list.
   51        * @see add(Bundle)
   52        *
   53        * @param bundleList the new bundle list
   54        */
   55       public void merge(BundleList bundleList) {
   56           for (StartLevel sl : bundleList.getStartLevels()) {
   57               for (Bundle bnd : sl.getBundles()) {
   58                   add(sl, bnd);
   59               }
   60           }
   61       }
   62   
   63       /**
   64        * Add an artifact definition. If it already exists, update the version, but
   65        * do not change the start level.
   66        *
   67        * @param newBnd the bundle to add
   68        */
   69       public void add(Bundle newBnd) {
   70          add(null, newBnd);
   71       }
   72   
   73       /**
   74        * Merge bundle into a start level using the supplied level if present.
   75        * @param mergeStartLevel
   76        * @param newBnd
   77        */
   78       private void add(StartLevel mergeStartLevel, Bundle newBnd) {
   79           Bundle current = get(newBnd, false);
   80           if (current != null) {
   81   
   82           } else {
   83               StartLevel startLevel = null;
   84               if ( mergeStartLevel == null || newBnd.getStartLevel() > 0) {
   85                   startLevel = getOrCreateStartLevel(newBnd.getStartLevel());
   86               } else {
   87                   startLevel = getOrCreateStartLevel(mergeStartLevel.getLevel());
   88               }
   89               startLevel.getBundles().add(newBnd);
   90           }
   91   
   92       }
   93   
   94       private StartLevel getOrCreateStartLevel(int startLevel) {
   95           for (StartLevel sl : getStartLevels()) {
   96               if (sl.getLevel() == startLevel) {
   97                   return sl;
   98               }
   99           }
  100   
  101           StartLevel sl = new StartLevel();
  102           getStartLevels().add(sl);
  103           sl.setLevel(startLevel);
  104           return sl;
  105       }
  106   
  107   }

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