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