Debian Codegraph @

pmaven-cli/src/main/java/org/apache/maven/cli/PolyglotMavenCli.java

raw symbols SCIP
1 /*
2 * Copyright (C) 2009 the original author or authors.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 package org.apache.maven.cli;
18
19 import org.apache.maven.model.building.ModelProcessor;
20 import org.codehaus.plexus.PlexusContainer;
21 import org.codehaus.plexus.classworlds.ClassWorld;
22 import org.codehaus.plexus.component.composition.CycleDetectedInComponentGraphException;
23 import org.codehaus.plexus.component.repository.ComponentDescriptor;
24 import org.codehaus.plexus.component.repository.ComponentRequirement;
25
26 /**
27 * Polgyglot-aware Maven CLI.
28 *
29 * @author <a href="mailto:[email protected]">Jason Dillon</a>
30 * @since 0.7
31 */
32 public class PolyglotMavenCli
33 extends MavenCli
34 {
35 @Override
36 protected void customizeContainer( final PlexusContainer container )
37 {
38 assert container != null;
39
40 // HACK: Wedge our processor in as the default
41 final ComponentDescriptor<?> source =
42 container.getComponentDescriptor( ModelProcessor.class.getName(), "polyglot" );
43 final ComponentDescriptor<?> target =
44 container.getComponentDescriptor( ModelProcessor.class.getName(), "default" );
45 target.setImplementation( source.getImplementation() );
46
47 // delete the old requirements and replace them with the new
48 // with size == 0 is getRequirements is an emptyList which is unmutable
49 if ( target.getRequirements().size() > 0 )
50 {
51 target.getRequirements().clear();
52 }
53 for ( final ComponentRequirement requirement : source.getRequirements() )
54 {
55 target.addRequirement( requirement );
56 }
57
58 // TODO this should not be needed
59 final ComponentRequirement manager = new ComponentRequirement();
60 manager.setFieldName( "manager" );
61 manager.setRole( "org.sonatype.maven.polyglot.PolyglotModelManager" );
62 manager.setRoleHint( "default" );
63 target.addRequirement( manager );
64
65 try
66 {
67 container.addComponentDescriptor( target );
68 }
69 catch ( final CycleDetectedInComponentGraphException e )
70 {
71 throw new RuntimeException( e );
72 }
73 }
74
75 public static void main( final String[] args )
76 {
77 final int result = main( args, null );
78 System.exit( result );
79 }
80
81 public static int main( final String[] args, final ClassWorld classWorld )
82 {
83 assert classWorld != null;
84 final PolyglotMavenCli cli = new PolyglotMavenCli();
85 return cli.doMain( new CliRequest( args, classWorld ) );
86 }
87 }