View Javadoc

1   package org.apache.maven;
2   
3   /* ====================================================================
4    *   Licensed to the Apache Software Foundation (ASF) under one or more
5    *   contributor license agreements.  See the NOTICE file distributed with
6    *   this work for additional information regarding copyright ownership.
7    *   The ASF licenses this file to You under the Apache License, Version 2.0
8    *   (the "License"); you may not use this file except in compliance with
9    *   the License.  You may obtain a copy of the License at
10   *
11   *       http://www.apache.org/licenses/LICENSE-2.0
12   *
13   *   Unless required by applicable law or agreed to in writing, software
14   *   distributed under the License is distributed on an "AS IS" BASIS,
15   *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   *   See the License for the specific language governing permissions and
17   *   limitations under the License.
18   * ====================================================================
19   */
20  
21  import org.apache.commons.jelly.tags.ant.AntTagLibrary;
22  import org.apache.commons.jelly.tags.ant.GrantProject;
23  import org.apache.commons.jelly.tags.ant.JellyPropsHandler;
24  import org.apache.maven.jelly.JellyBuildListener;
25  import org.apache.maven.jelly.MavenJellyContext;
26  import org.apache.maven.project.Project;
27  import org.apache.tools.ant.types.Path;
28  
29  /**
30   * A class to help create Ant projects
31   */
32  public class AntProjectBuilder
33  {
34      /**
35       * Initialize Ant.
36       * @param project a Maven project
37       * @param context the maven context whose properties will be available to the Ant Project
38       * @return an Ant project
39       */
40      public static GrantProject build( final Project project, final MavenJellyContext context )
41      {
42          // Create the build listener.
43          JellyBuildListener buildListener = new JellyBuildListener( context.getXMLOutput() );
44          buildListener.setDebug( context.getDebugOn().booleanValue() );
45          buildListener.setEmacsMode( context.getEmacsModeOn().booleanValue() );
46  
47          // Create our ant project.
48          GrantProject antProject = new GrantProject();
49          antProject.setPropsHandler( new JellyPropsHandler( context ) );
50          antProject.init();
51          antProject.setBaseDir( project.getFile().getParentFile().getAbsoluteFile() );
52          antProject.addBuildListener( buildListener );
53  
54          context.setAntProject( antProject );
55          AntTagLibrary.setProject( context, antProject );
56  
57          Path p = new Path( antProject );
58          p.setPath( project.getDependencyClasspath() );
59          antProject.addReference( MavenConstants.DEPENDENCY_CLASSPATH, p );
60  
61          return antProject;
62      }
63  }