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 org.apache.sling.maven.projectsupport.bundlelist.v1_0_0.Bundle;
   20   import org.codehaus.plexus.util.StringUtils;
   21   
   22   /**
   23    * The definition of an artifact.
   24    */
   25   public class ArtifactDefinition {
   26   
   27       /** The artifactId */
   28       private String artifactId;
   29   
   30       /** The classifier */
   31       private String classifier;
   32   
   33       /** The groupId */
   34       private String groupId;
   35   
   36       /** The start level at which this artifact should be started */
   37       private int startLevel;
   38   
   39       /** The artifact type */
   40       private String type;
   41   
   42       /** The artifact version */
   43       private String version;
   44   
   45       public ArtifactDefinition() {
   46       }
   47   
   48       public ArtifactDefinition(Bundle bundle, int startLevel) {
   49   		this.groupId = bundle.getGroupId();
   50   		this.artifactId = bundle.getArtifactId();
   51   		this.type = bundle.getType();
   52   		this.version = bundle.getVersion();
   53   		this.classifier = bundle.getClassifier();
   54   		this.startLevel = startLevel;
   55   	}
   56   
   57   	public String getArtifactId() {
   58           return artifactId;
   59       }
   60   
   61       public String getClassifier() {
   62           return classifier;
   63       }
   64   
   65       public String getGroupId() {
   66           return groupId;
   67       }
   68   
   69       public int getStartLevel() {
   70           return startLevel;
   71       }
   72   
   73       public String getType() {
   74           return type;
   75       }
   76   
   77       public String getVersion() {
   78           return version;
   79       }
   80   
   81       public void setArtifactId(String artifactId) {
   82           this.artifactId = artifactId;
   83       }
   84   
   85       public void setClassifier(String classifier) {
   86           this.classifier = classifier;
   87       }
   88   
   89       public void setGroupId(String groupId) {
   90           this.groupId = groupId;
   91       }
   92   
   93       public void setStartLevel(int startLevel) {
   94           this.startLevel = startLevel;
   95       }
   96   
   97       public void setType(String type) {
   98           this.type = type;
   99       }
  100   
  101       public void setVersion(String version) {
  102           this.version = version;
  103       }
  104   
  105       @Override
  106       public String toString() {
  107           return "AdditionalBundle [artifactId=" + artifactId + ", classifier="
  108                   + classifier + ", groupId=" + groupId + ", startLevel="
  109                   + startLevel + ", type=" + type + ", version=" + version + "]";
  110       }
  111   
  112       /**
  113        * Initialize this ArtifactDefinition with a set of default values from a
  114        * comma-delimited string. This string must have 6 items in it:
  115        * [groupId],[artifactId],[version],[type],[classifier],[startLevel]
  116        *
  117        * The only required parameter is the last one, which must be parseable as
  118        * an integer.
  119        *
  120        * @param commaDelimitedList
  121        *            the comma-delimited list
  122        */
  123       public void initDefaults(String commaDelimitedList) {
  124           String[] values = commaDelimitedList.split(",");
  125           if (values.length != 6) {
  126               throw new IllegalArgumentException(
  127                       String
  128                               .format(
  129                                       "The string %s does not have the correct number of items (6).",
  130                                       commaDelimitedList));
  131           }
  132           initDefaults(values[0], values[1], values[2], values[3], values[4],
  133                   Integer.valueOf(values[5]));
  134       }
  135   
  136       /**
  137        * Initialize this ArtifactDefinition with a set of default values. If the
  138        * corresponding field in this object is null (or 0 in the case of start
  139        * level) and the parameter is non-null, the parameter value will be used.
  140        *
  141        * @param groupId
  142        *            the groupId
  143        * @param artifactId
  144        *            the artifactId
  145        * @param version
  146        *            the version
  147        * @param type
  148        *            the artifact type
  149        * @param classifier
  150        *            the artifact classified
  151        * @param startLevel
  152        *            the start level
  153        */
  154       public void initDefaults(String groupId, String artifactId, String version,
  155               String type, String classifier, int startLevel) {
  156           if (this.groupId == null && StringUtils.isNotEmpty(groupId)) {
  157               this.groupId = groupId;
  158           }
  159           if (this.artifactId == null && StringUtils.isNotEmpty(artifactId)) {
  160               this.artifactId = artifactId;
  161           }
  162           if (this.version == null && StringUtils.isNotEmpty(version)) {
  163               this.version = version;
  164           }
  165           if (this.type == null && StringUtils.isNotEmpty(groupId)) {
  166               this.type = type;
  167           }
  168           if (this.classifier == null && StringUtils.isNotEmpty(classifier)) {
  169               this.classifier = classifier;
  170           }
  171           if (this.startLevel == 0) {
  172               this.startLevel = startLevel;
  173           }
  174       }
  175   
  176       public Bundle toBundle() {
  177           Bundle bnd = new Bundle();
  178           bnd.setArtifactId(artifactId);
  179           bnd.setGroupId(groupId);
  180           bnd.setVersion(version);
  181           if (type != null) {
  182               bnd.setType(type);
  183           }
  184           bnd.setClassifier(classifier);
  185           bnd.setStartLevel(startLevel);
  186           return bnd;
  187       }
  188   
  189   }

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