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

org.eclipse.jetty.maven.plugin.OverlayConfig Maven / Gradle / Ivy

//
//  ========================================================================
//  Copyright (c) 1995-2016 Mort Bay Consulting Pty. Ltd.
//  ------------------------------------------------------------------------
//  All rights reserved. This program and the accompanying materials
//  are made available under the terms of the Eclipse Public License v1.0
//  and Apache License v2.0 which accompanies this distribution.
//
//      The Eclipse Public License is available at
//      http://www.eclipse.org/legal/epl-v10.html
//
//      The Apache License v2.0 is available at
//      http://www.opensource.org/licenses/apache2.0.php
//
//  You may elect to redistribute this code under either of these licenses.
//  ========================================================================
//


package org.eclipse.jetty.maven.plugin;

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

import org.codehaus.plexus.util.xml.Xpp3Dom;
import org.eclipse.jetty.util.StringUtil;

/**
 * OverlayConfig
 */
public class OverlayConfig
{
    private String targetPath;
    private String groupId;
    private String artifactId;
    private String classifier;
    private List includes;
    private List excludes;
    private boolean skip;
    private boolean filtered;
    
    public OverlayConfig() {}
    
    public OverlayConfig(String fmt, List defaultIncludes, List defaultExcludes)
    {
        if (fmt == null)
            return;
        String[] atoms = StringUtil.csvSplit(fmt);
        for (int i=0;i 0)
                        includes = Arrays.asList(incs);
                    break;
                }
                case 7:
                { 
                    if ("".equals(s))
                        break;
                    String[] exs = s.split(";");
                    if (exs.length > 0)
                        excludes = Arrays.asList(exs);
                    break;
                }
            }
        }
    }

    public OverlayConfig(Xpp3Dom root, List defaultIncludes, List defaultExcludes)
    {
        Xpp3Dom node = root.getChild("groupId");
        setGroupId(node==null?null:node.getValue());
        
        node = root.getChild("artifactId");
        setArtifactId(node==null?null:node.getValue());   
        
        node = root.getChild("classifier");
        setClassifier(node==null?null:node.getValue());
       
        node = root.getChild("targetPath");
        setTargetPath(node==null?null:node.getValue());
        
        node = root.getChild("skip");
        setSkip(node==null?false:Boolean.valueOf(node.getValue()));

        node = root.getChild("filtered");
        setFiltered(node==null?false:Boolean.valueOf(node.getValue()));

        node = root.getChild("includes");
        List includes = null;
        if (node != null && node.getChildCount() > 0)
        {
            Xpp3Dom[] list = node.getChildren("include");
            for (int j=0; list != null && j < list.length;j++)
            {
                if (includes == null)
                    includes = new ArrayList();
                includes.add(list[j].getValue());
            }
        }
        if (includes == null && defaultIncludes != null)
        {
            includes = new ArrayList();
            includes.addAll(defaultIncludes);
        }
        setIncludes(includes);
        
       
        node = root.getChild("excludes");
        List excludes = null;
        if (node != null && node.getChildCount() > 0)
        {
            Xpp3Dom[] list = node.getChildren("exclude");
            for (int j=0; list != null && j < list.length;j++)
            {
                if (excludes == null)
                    excludes = new ArrayList();
                excludes.add(list[j].getValue());
            }
        }
        if (excludes == null && defaultExcludes != null)
        {
            excludes = new ArrayList();
            excludes.addAll(defaultExcludes);
        }
        setExcludes(excludes);
    }
    
    public String getTargetPath()
    {
        return targetPath;
    }

    public void setTargetPath(String targetPath)
    {
        this.targetPath = targetPath;
    }

    public String getGroupId()
    {
        return groupId;
    }

    public void setGroupId(String groupId)
    {
        this.groupId = groupId;
    }

    public String getArtifactId()
    {
        return artifactId;
    }

    public void setArtifactId(String artifactId)
    {
        this.artifactId = artifactId;
    }

    public String getClassifier()
    {
        return classifier;
    }

    public void setClassifier(String classifier)
    {
        this.classifier = classifier;
    }

    public List getIncludes()
    {
        return includes;
    }

    public void setIncludes(List includes)
    {
        this.includes = includes;
    }

    public List getExcludes()
    {
        return excludes;
    }

    public void setExcludes(List excludes)
    {
        this.excludes = excludes;
    }

    public boolean isSkip()
    {
        return skip;
    }

    public void setSkip(boolean skip)
    {
        this.skip = skip;
    }

    public boolean isFiltered()
    {
        return filtered;
    }

    public void setFiltered(boolean filtered)
    {
        this.filtered = filtered;
    }
    
    public boolean isCurrentProject()
    {
        if (this.groupId == null && this.artifactId == null)
            return true;
        return false;
    }
    

    /**
     * Check if this overlay configuration matches an Artifact's info
     * 
     * @param gid Artifact groupId
     * @param aid Artifact artifactId
     * @param cls Artifact classifier
     * @return true if matched
     */
    public boolean matchesArtifact (String gid, String aid, String cls)
    {
        if (((getGroupId() == null && gid == null) || (getGroupId() != null && getGroupId().equals(gid)))
           &&((getArtifactId() == null && aid == null) || (getArtifactId() != null && getArtifactId().equals(aid)))
           &&((getClassifier() == null) || (getClassifier().equals(cls))))
            return true;

        return false;
    }
    
    /**
     * Check if this overlay configuration matches an Artifact's info
     * 
     * @param gid the group id
     * @param aid the artifact id
     * @return true if matched
     */
    public boolean matchesArtifact (String gid, String aid)
    {
        if (((getGroupId() == null && gid == null) || (getGroupId() != null && getGroupId().equals(gid)))
           &&((getArtifactId() == null && aid == null) || (getArtifactId() != null && getArtifactId().equals(aid))))
            return true;

        return false;
    }
    
    public String toString()
    {
        StringBuffer strbuff = new StringBuffer();
        strbuff.append((groupId != null ? groupId : "")+",");
        strbuff.append((artifactId != null ? artifactId : "")+",");
        strbuff.append((classifier != null ? classifier : "")+",");
        strbuff.append((targetPath != null ? targetPath : "")+",");
        strbuff.append(""+skip+",");
        strbuff.append(""+filtered+",");
     
        if (includes != null)
        {
            Iterator itor = includes.iterator();
            while (itor.hasNext())
            {
                strbuff.append(itor.next());
                if (itor.hasNext())
                    strbuff.append(";");
            }
        }
        
        strbuff.append(", ");

        if (excludes != null)
        {
            Iterator itor = excludes.iterator();
            while (itor.hasNext())
            {
                strbuff.append(itor.next());
                if (itor.hasNext())
                    strbuff.append(";");
            }
        }
  
        return strbuff.toString();
    }
}





© 2015 - 2025 Weber Informatics LLC | Privacy Policy