KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > maven > tools > plugin > util > PluginUtils


1 package org.apache.maven.tools.plugin.util;
2
3 /*
4  * Copyright 2001-2004 The Apache Software Foundation.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18
19 import org.apache.maven.model.Dependency;
20 import org.apache.maven.plugin.descriptor.PluginDescriptor;
21 import org.codehaus.plexus.component.repository.ComponentDependency;
22 import org.codehaus.plexus.util.DirectoryScanner;
23 import org.codehaus.plexus.util.StringUtils;
24 import org.codehaus.plexus.util.xml.XMLWriter;
25
26 import java.util.Iterator JavaDoc;
27 import java.util.LinkedList JavaDoc;
28 import java.util.List JavaDoc;
29
30 /**
31  * @author jdcasey
32  */

33 public final class PluginUtils
34 {
35
36     private PluginUtils()
37     {
38     }
39
40     public static String JavaDoc[] findSources( String JavaDoc basedir, String JavaDoc include )
41     {
42         return PluginUtils.findSources( basedir, include, null );
43     }
44
45     public static String JavaDoc[] findSources( String JavaDoc basedir, String JavaDoc include, String JavaDoc exclude )
46     {
47         DirectoryScanner scanner = new DirectoryScanner();
48         scanner.setBasedir( basedir );
49         scanner.setIncludes( new String JavaDoc[]{include} );
50         if ( !StringUtils.isEmpty( exclude ) )
51         {
52             // TODO: need default excludes in scanner
53
scanner.setExcludes( new String JavaDoc[]{exclude, "**/.svn/**"} );
54         }
55         else
56         {
57             scanner.setExcludes( new String JavaDoc[]{"**/.svn/**"} );
58         }
59
60         scanner.scan();
61
62         return scanner.getIncludedFiles();
63     }
64
65     public static void writeDependencies( XMLWriter w, PluginDescriptor pluginDescriptor )
66     {
67
68         w.startElement( "dependencies" );
69
70         for ( Iterator JavaDoc it = pluginDescriptor.getDependencies().iterator(); it.hasNext(); )
71         {
72             ComponentDependency dep = (ComponentDependency) it.next();
73             
74             w.startElement( "dependency" );
75
76             PluginUtils.element( w, "groupId", dep.getGroupId() );
77
78             PluginUtils.element( w, "artifactId", dep.getArtifactId() );
79
80             PluginUtils.element( w, "type", dep.getType() );
81
82             PluginUtils.element( w, "version", dep.getVersion() );
83
84             w.endElement();
85         }
86
87         w.endElement();
88     }
89     
90     public static List JavaDoc toComponentDependencies(List JavaDoc dependencies)
91     {
92         List JavaDoc componentDeps = new LinkedList JavaDoc();
93
94         for ( Iterator JavaDoc it = dependencies.iterator(); it.hasNext(); )
95         {
96             Dependency dependency = (Dependency) it.next();
97             
98             ComponentDependency cd = new ComponentDependency();
99
100             cd.setArtifactId( dependency.getArtifactId() );
101             cd.setGroupId( dependency.getGroupId() );
102             cd.setVersion( dependency.getVersion() );
103             cd.setType( dependency.getType() );
104
105             componentDeps.add( cd );
106         }
107         
108         return componentDeps;
109     }
110
111     private static void element( XMLWriter w, String JavaDoc name, String JavaDoc value )
112     {
113         w.startElement( name );
114
115         if ( value == null )
116         {
117             value = "";
118         }
119
120         w.writeText( value );
121
122         w.endElement();
123     }
124
125 }
126
Popular Tags