All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.apache.sling.maven.projectsupport.ArtifactDefinition Maven / Gradle / Ivy

/*
 * 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
 *
 * 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.sling.maven.projectsupport;

import static org.apache.sling.maven.projectsupport.BundleListUtils.nodeValue;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import org.apache.maven.model.Dependency;
import org.apache.sling.maven.projectsupport.bundlelist.v1_0_0.Bundle;
import org.codehaus.plexus.util.StringUtils;
import org.codehaus.plexus.util.xml.Xpp3Dom;

/**
 * The definition of an artifact.
 */
public class ArtifactDefinition {

    /** The artifactId */
    private String artifactId;

    /** The classifier */
    private String classifier;

    /** The groupId */
    private String groupId;

    /** The start level at which this artifact should be started */
    private int startLevel;

    /** The artifact type */
    private String type;

    /** The artifact version */
    private String version;

    /** The artifact run modes */
    private String runModes;

    private ArtifactDefinition[] bundles;

    public ArtifactDefinition() {
    }

    public ArtifactDefinition(Bundle bundle, int startLevel) {
        this.groupId = bundle.getGroupId();
        this.artifactId = bundle.getArtifactId();
        this.type = bundle.getType();
        this.version = bundle.getVersion();
        this.classifier = bundle.getClassifier();
        this.startLevel = startLevel;
        this.runModes = bundle.getRunModes();
    }

    public ArtifactDefinition(final Xpp3Dom config) {
        if ( config.getChild("bundles") != null ) {
            final Xpp3Dom[] children = config.getChild("bundles").getChildren("bundle");
            this.bundles = new ArtifactDefinition[children.length];
            for(int i=0; i toBundleList() {
        ArrayList bundleList = new ArrayList();

        if (bundles == null) {
            Bundle bnd = new Bundle();
            bnd.setArtifactId(artifactId);
            bnd.setGroupId(groupId);
            bnd.setVersion(version);
            if (type != null) {
                bnd.setType(type);
            }
            bnd.setClassifier(classifier);
            bnd.setStartLevel(startLevel);
            bundleList.add(bnd);
        } else {
            for (ArtifactDefinition bundle : bundles) {
                bundleList.addAll(bundle.toBundleList());
            }
        }

        return bundleList;
    }

    public List toDependencyList(String scope) {
        ArrayList depList = new ArrayList();

        if (bundles == null) {
            Dependency dep = new Dependency();
            dep.setArtifactId(artifactId);
            dep.setGroupId(groupId);
            dep.setVersion(version);
            if (type != null) {
                dep.setType(type);
            }
            dep.setClassifier(classifier);
            dep.setScope(scope);
            depList.add(dep);
        } else {
            for (ArtifactDefinition bundle : bundles) {
                depList.addAll(bundle.toDependencyList(scope));
            }
        }

        return depList;
    }

    public static List toDependencyList(Bundle bundle, String scope) {
        return new ArtifactDefinition(bundle, 0).toDependencyList(scope);
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy