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 import java.util.Map.Entry;
24 import java.util.Properties;
25
26 import org.apache.maven.toolchain.MisconfiguredToolchainException;
27 import org.apache.maven.toolchain.RequirementMatcher;
28 import org.apache.maven.toolchain.RequirementMatcherFactory;
29 import org.apache.maven.toolchain.ToolchainFactory;
30 import org.apache.maven.toolchain.ToolchainPrivate;
31 import org.apache.maven.toolchain.model.ToolchainModel;
32 import org.codehaus.plexus.component.annotations.Component;
33 import org.codehaus.plexus.component.annotations.Requirement;
34 import org.codehaus.plexus.logging.Logger;
35 import org.codehaus.plexus.util.FileUtils;
36 import org.codehaus.plexus.util.xml.Xpp3Dom;
37
38
39
40
41
42
43
44
45
46 @Component( role = ToolchainFactory.class, hint = "jdk" )
47 public class JavaToolchainFactory
48 implements ToolchainFactory
49 {
50
51 @Requirement
52 private Logger logger;
53
54 public ToolchainPrivate createToolchain( ToolchainModel model )
55 throws MisconfiguredToolchainException
56 {
57 if ( model == null )
58 {
59 return null;
60 }
61
62
63
64 @SuppressWarnings( "deprecation" )
65 JavaToolchainImpl jtc = new DefaultJavaToolChain( model, logger );
66
67
68 Properties provides = model.getProvides();
69 for ( Entry<Object, Object> provide : provides.entrySet() )
70 {
71 String key = (String) provide.getKey();
72 String value = (String) provide.getValue();
73
74 if ( value == null )
75 {
76 throw new MisconfiguredToolchainException(
77 "Provides token '" + key + "' doesn't have any value configured." );
78 }
79
80 RequirementMatcher matcher;
81 if ( "version".equals( key ) )
82 {
83 matcher = RequirementMatcherFactory.createVersionMatcher( value );
84 }
85 else
86 {
87 matcher = RequirementMatcherFactory.createExactMatcher( value );
88 }
89
90 jtc.addProvideToken( key, matcher );
91 }
92
93
94 Xpp3Dom dom = (Xpp3Dom) model.getConfiguration();
95 Xpp3Dom javahome = dom.getChild( JavaToolchainImpl.KEY_JAVAHOME );
96 if ( javahome == null )
97 {
98 throw new MisconfiguredToolchainException( "Java toolchain without the "
99 + JavaToolchainImpl.KEY_JAVAHOME + " configuration element." );
100 }
101 File normal = new File( FileUtils.normalize( javahome.getValue() ) );
102 if ( normal.exists() )
103 {
104 jtc.setJavaHome( FileUtils.normalize( javahome.getValue() ) );
105 }
106 else
107 {
108 throw new MisconfiguredToolchainException( "Non-existing JDK home configuration at "
109 + normal.getAbsolutePath() );
110 }
111
112 return jtc;
113 }
114
115 public ToolchainPrivate createDefaultToolchain()
116 {
117
118
119 return null;
120 }
121
122 protected Logger getLogger()
123 {
124 return logger;
125 }
126
127 }