001package org.apache.maven.tools.plugin.util;
002
003/*
004 * Licensed to the Apache Software Foundation (ASF) under one
005 * or more contributor license agreements.  See the NOTICE file
006 * distributed with this work for additional information
007 * regarding copyright ownership.  The ASF licenses this file
008 * to you under the Apache License, Version 2.0 (the
009 * "License"); you may not use this file except in compliance
010 * with the License.  You may obtain a copy of the License at
011 *
012 *   http://www.apache.org/licenses/LICENSE-2.0
013 *
014 * Unless required by applicable law or agreed to in writing,
015 * software distributed under the License is distributed on an
016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017 * KIND, either express or implied.  See the License for the
018 * specific language governing permissions and limitations
019 * under the License.
020 */
021
022import org.apache.maven.plugin.descriptor.PluginDescriptor;
023import org.junit.Test;
024
025import static org.junit.Assert.assertEquals;
026
027/**
028 * @author jdcasey
029 */
030public class PluginUtilsTest
031{
032    @Test
033    public void testShouldTrimArtifactIdToFindPluginId()
034    {
035        assertEquals( "artifactId", PluginDescriptor.getGoalPrefixFromArtifactId( "maven-artifactId-plugin" ) );
036        assertEquals( "artifactId", PluginDescriptor.getGoalPrefixFromArtifactId( "maven-plugin-artifactId" ) );
037        assertEquals( "artifactId", PluginDescriptor.getGoalPrefixFromArtifactId( "artifactId-maven-plugin" ) );
038        assertEquals( "artifactId", PluginDescriptor.getGoalPrefixFromArtifactId( "artifactId" ) );
039        assertEquals( "artifactId", PluginDescriptor.getGoalPrefixFromArtifactId( "artifactId-plugin" ) );
040        assertEquals( "plugin", PluginDescriptor.getGoalPrefixFromArtifactId( "maven-plugin-plugin" ) );
041    }
042
043    @Test
044    public void testShouldFindTwoScriptsWhenNoExcludesAreGiven()
045    {
046        String testScript = "test.txt";
047
048        String basedir = TestUtils.dirname( testScript );
049
050        String includes = "**/*.txt";
051
052        String[] files = PluginUtils.findSources( basedir, includes );
053        assertEquals( 2, files.length );
054    }
055
056    @Test
057    public void testShouldFindOneScriptsWhenAnExcludeIsGiven()
058    {
059        String testScript = "test.txt";
060
061        String basedir = TestUtils.dirname( testScript );
062
063        String includes = "**/*.txt";
064        String excludes = "**/*Excludes.txt";
065
066        String[] files = PluginUtils.findSources( basedir, includes, excludes );
067        assertEquals( 1, files.length );
068    }
069
070}