Save This Page
Home » maven-launchpad-plugin-2.0.6-source-release » org.apache.sling.maven.projectsupport » [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
    4    * this work for additional information regarding copyright ownership.
    5    * The ASF licenses this file to You under the Apache License, Version 2.0
    6    * (the "License"); you may not use this file except in compliance with
    7    * the License.  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,
   13    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   14    * See the License for the specific language governing permissions and
   15    * limitations under the License.
   16    */
   17   package org.apache.sling.maven.projectsupport;
   18   
   19   import java.util.ArrayList;
   20   import java.util.List;
   21   
   22   import org.apache.maven.plugin.MojoExecutionException;
   23   import org.apache.maven.plugin.MojoFailureException;
   24   import org.apache.sling.maven.projectsupport.bundlelist.v1_0_0.Bundle;
   25   import org.apache.sling.maven.projectsupport.bundlelist.v1_0_0.BundleList;
   26   import org.apache.sling.maven.projectsupport.bundlelist.v1_0_0.StartLevel;
   27   
   28   /**
   29    * Validate that the bundle list file (if it exists) does not contain references
   30    * to SNAPSHOT versions.
   31    *
   32    * @goal check-bundle-list-for-snapshots
   33    *
   34    */
   35   public class CheckBundleListForSnapshotsMojo extends AbstractBundleListMojo {
   36   
   37       /**
   38        * True if the build should be failed if a snapshot is found.
   39        *
   40        * @parameter default-value="true"
   41        */
   42       private boolean failOnSnapshot;
   43   
   44       @Override
   45       protected void executeWithArtifacts() throws MojoExecutionException, MojoFailureException {
   46           List<Bundle> snapshots = new ArrayList<Bundle>();
   47           BundleList bundleList = getBundleList();
   48           for (StartLevel level : bundleList.getStartLevels()) {
   49               for (Bundle bundle : level.getBundles()) {
   50                   if (isSnapshot(bundle)) {
   51                       snapshots.add(bundle);
   52                   }
   53               }
   54           }
   55           if (!snapshots.isEmpty()) {
   56               getLog().error("The following entries in the bundle list file are SNAPSHOTs:");
   57               for (Bundle bundle : snapshots) {
   58                   getLog().error(
   59                           String
   60                                   .format("     %s:%s:%s", bundle.getGroupId(), bundle.getArtifactId(), bundle
   61                                           .getVersion()));
   62               }
   63               if (failOnSnapshot) {
   64                   throw new MojoFailureException("SNAPSHOTs were found in the bundle list. See log.");
   65               }
   66           }
   67       }
   68   
   69       private boolean isSnapshot(Bundle bundle) {
   70           return bundle.getVersion().endsWith("SNAPSHOT");
   71       }
   72   
   73   }

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