1 package org.apache.maven.toolchain.java;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.io.File;
23
24 import org.apache.maven.toolchain.MisconfiguredToolchainException;
25 import org.apache.maven.toolchain.RequirementMatcherFactory;
26 import org.apache.maven.toolchain.ToolchainFactory;
27 import org.apache.maven.toolchain.ToolchainPrivate;
28 import org.apache.maven.toolchain.model.ToolchainModel;
29 import org.codehaus.plexus.component.annotations.Component;
30 import org.codehaus.plexus.component.annotations.Requirement;
31 import org.codehaus.plexus.logging.Logger;
32 import org.codehaus.plexus.util.FileUtils;
33 import org.codehaus.plexus.util.xml.Xpp3Dom;
34
35
36
37
38
39 @Component( role = ToolchainFactory.class, hint = "jdk" )
40 public class DefaultJavaToolchainFactory
41 implements ToolchainFactory
42 {
43
44 @Requirement
45 private Logger logger;
46
47 public DefaultJavaToolchainFactory()
48 {
49 }
50
51 public ToolchainPrivate createToolchain( ToolchainModel model )
52 throws MisconfiguredToolchainException
53 {
54 if ( model == null )
55 {
56 return null;
57 }
58 DefaultJavaToolChain jtc = new DefaultJavaToolChain( model, logger );
59 Xpp3Dom dom = (Xpp3Dom) model.getConfiguration();
60 Xpp3Dom javahome = dom.getChild( DefaultJavaToolChain.KEY_JAVAHOME );
61 if ( javahome == null )
62 {
63 throw new MisconfiguredToolchainException( "Java toolchain without the "
64 + DefaultJavaToolChain.KEY_JAVAHOME + " configuration element." );
65 }
66 File normal = new File( FileUtils.normalize( javahome.getValue() ) );
67 if ( normal.exists() )
68 {
69 jtc.setJavaHome( FileUtils.normalize( javahome.getValue() ) );
70 }
71 else
72 {
73 throw new MisconfiguredToolchainException( "Non-existing JDK home configuration at "
74 + normal.getAbsolutePath() );
75 }
76
77
78
79 dom = (Xpp3Dom) model.getProvides();
80 Xpp3Dom[] provides = dom.getChildren();
81 for ( int i = 0; i < provides.length; i++ )
82 {
83 String key = provides[i].getName();
84 String value = provides[i].getValue();
85 if ( value == null )
86 {
87 throw new MisconfiguredToolchainException( "Provides token '" + key + "' doesn't have any value configured." );
88 }
89 if ( "version".equals( key ) )
90 {
91 jtc.addProvideToken( key,
92 RequirementMatcherFactory.createVersionMatcher( value ) );
93 }
94 else
95 {
96 jtc.addProvideToken( key,
97 RequirementMatcherFactory.createExactMatcher( value ) );
98 }
99 }
100 return jtc;
101 }
102
103 public ToolchainPrivate createDefaultToolchain()
104 {
105
106
107 return null;
108 }
109
110 protected Logger getLogger()
111 {
112 return logger;
113 }
114
115 }