renamed DefaultJavaToolchainFactory to JavaToolchainFactory to ease understanding: there is no JavaToolchainFactory Plexus component
Project: http://git-wip-us.apache.org/repos/asf/maven/repo Commit: http://git-wip-us.apache.org/repos/asf/maven/commit/aef3b36c Tree: http://git-wip-us.apache.org/repos/asf/maven/tree/aef3b36c Diff: http://git-wip-us.apache.org/repos/asf/maven/diff/aef3b36c Branch: refs/heads/master Commit: aef3b36c0e56bf9515259ecf492881f59113b97c Parents: eddfef3 Author: Hervé Boutemy <hbout...@apache.org> Authored: Wed Nov 5 01:32:21 2014 +0100 Committer: Hervé Boutemy <hbout...@apache.org> Committed: Wed Nov 5 01:32:21 2014 +0100 ---------------------------------------------------------------------- .../java/DefaultJavaToolchainFactory.java | 118 ------------------ .../toolchain/java/JavaToolchainFactory.java | 120 +++++++++++++++++++ maven-core/src/site/apt/index.apt | 6 +- 3 files changed, 123 insertions(+), 121 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/maven/blob/aef3b36c/maven-core/src/main/java/org/apache/maven/toolchain/java/DefaultJavaToolchainFactory.java ---------------------------------------------------------------------- diff --git a/maven-core/src/main/java/org/apache/maven/toolchain/java/DefaultJavaToolchainFactory.java b/maven-core/src/main/java/org/apache/maven/toolchain/java/DefaultJavaToolchainFactory.java deleted file mode 100644 index d95f2fe..0000000 --- a/maven-core/src/main/java/org/apache/maven/toolchain/java/DefaultJavaToolchainFactory.java +++ /dev/null @@ -1,118 +0,0 @@ -package org.apache.maven.toolchain.java; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import java.io.File; -import java.util.Map.Entry; -import java.util.Properties; - -import org.apache.maven.toolchain.MisconfiguredToolchainException; -import org.apache.maven.toolchain.RequirementMatcherFactory; -import org.apache.maven.toolchain.ToolchainFactory; -import org.apache.maven.toolchain.ToolchainPrivate; -import org.apache.maven.toolchain.model.ToolchainModel; -import org.codehaus.plexus.component.annotations.Component; -import org.codehaus.plexus.component.annotations.Requirement; -import org.codehaus.plexus.logging.Logger; -import org.codehaus.plexus.util.FileUtils; -import org.codehaus.plexus.util.xml.Xpp3Dom; - -/** - * JDK toolchain factory. - * - * @author mkleint - * @since 2.0.9 - */ -@Component( role = ToolchainFactory.class, hint = "jdk" ) -public class DefaultJavaToolchainFactory - implements ToolchainFactory -{ - - @Requirement - private Logger logger; - - public ToolchainPrivate createToolchain( ToolchainModel model ) - throws MisconfiguredToolchainException - { - if ( model == null ) - { - return null; - } - - DefaultJavaToolchain jtc = new DefaultJavaToolchain( model, logger ); - - // populate the provides section - Properties provides = model.getProvides(); - for ( Entry<Object, Object> provide : provides.entrySet() ) - { - String key = (String) provide.getKey(); - String value = (String) provide.getValue(); - - if ( value == null ) - { - throw new MisconfiguredToolchainException( - "Provides token '" + key + "' doesn't have any value configured." ); - } - - if ( "version".equals( key ) ) - { - jtc.addProvideToken( key, RequirementMatcherFactory.createVersionMatcher( value ) ); - } - else - { - jtc.addProvideToken( key, RequirementMatcherFactory.createExactMatcher( value ) ); - } - } - - // populate the configuration section - Xpp3Dom dom = (Xpp3Dom) model.getConfiguration(); - Xpp3Dom javahome = dom.getChild( DefaultJavaToolchain.KEY_JAVAHOME ); - if ( javahome == null ) - { - throw new MisconfiguredToolchainException( "Java toolchain without the " - + DefaultJavaToolchain.KEY_JAVAHOME + " configuration element." ); - } - File normal = new File( FileUtils.normalize( javahome.getValue() ) ); - if ( normal.exists() ) - { - jtc.setJavaHome( FileUtils.normalize( javahome.getValue() ) ); - } - else - { - throw new MisconfiguredToolchainException( "Non-existing JDK home configuration at " - + normal.getAbsolutePath() ); - } - - return jtc; - } - - public ToolchainPrivate createDefaultToolchain() - { - //not sure it's necessary to provide a default toolchain here. - //only version can be eventually supplied, and - return null; - } - - protected Logger getLogger() - { - return logger; - } - -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/maven/blob/aef3b36c/maven-core/src/main/java/org/apache/maven/toolchain/java/JavaToolchainFactory.java ---------------------------------------------------------------------- diff --git a/maven-core/src/main/java/org/apache/maven/toolchain/java/JavaToolchainFactory.java b/maven-core/src/main/java/org/apache/maven/toolchain/java/JavaToolchainFactory.java new file mode 100644 index 0000000..f47a3d0 --- /dev/null +++ b/maven-core/src/main/java/org/apache/maven/toolchain/java/JavaToolchainFactory.java @@ -0,0 +1,120 @@ +package org.apache.maven.toolchain.java; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import java.io.File; +import java.util.Map.Entry; +import java.util.Properties; + +import org.apache.maven.toolchain.MisconfiguredToolchainException; +import org.apache.maven.toolchain.RequirementMatcherFactory; +import org.apache.maven.toolchain.ToolchainFactory; +import org.apache.maven.toolchain.ToolchainPrivate; +import org.apache.maven.toolchain.model.ToolchainModel; +import org.codehaus.plexus.component.annotations.Component; +import org.codehaus.plexus.component.annotations.Requirement; +import org.codehaus.plexus.logging.Logger; +import org.codehaus.plexus.util.FileUtils; +import org.codehaus.plexus.util.xml.Xpp3Dom; + +/** + * JDK toolchain factory. + * This is a <code>ToolchainFactory</code> Plexus component registered with + * <code>jdk</code> hint. + * + * @author mkleint + * @since 2.0.9, renamed from <code>DefaultJavaToolchainFactory</code> in 3.2.4 + */ +@Component( role = ToolchainFactory.class, hint = "jdk" ) +public class JavaToolchainFactory + implements ToolchainFactory +{ + + @Requirement + private Logger logger; + + public ToolchainPrivate createToolchain( ToolchainModel model ) + throws MisconfiguredToolchainException + { + if ( model == null ) + { + return null; + } + + DefaultJavaToolchain jtc = new DefaultJavaToolchain( model, logger ); + + // populate the provides section + Properties provides = model.getProvides(); + for ( Entry<Object, Object> provide : provides.entrySet() ) + { + String key = (String) provide.getKey(); + String value = (String) provide.getValue(); + + if ( value == null ) + { + throw new MisconfiguredToolchainException( + "Provides token '" + key + "' doesn't have any value configured." ); + } + + if ( "version".equals( key ) ) + { + jtc.addProvideToken( key, RequirementMatcherFactory.createVersionMatcher( value ) ); + } + else + { + jtc.addProvideToken( key, RequirementMatcherFactory.createExactMatcher( value ) ); + } + } + + // populate the configuration section + Xpp3Dom dom = (Xpp3Dom) model.getConfiguration(); + Xpp3Dom javahome = dom.getChild( DefaultJavaToolchain.KEY_JAVAHOME ); + if ( javahome == null ) + { + throw new MisconfiguredToolchainException( "Java toolchain without the " + + DefaultJavaToolchain.KEY_JAVAHOME + " configuration element." ); + } + File normal = new File( FileUtils.normalize( javahome.getValue() ) ); + if ( normal.exists() ) + { + jtc.setJavaHome( FileUtils.normalize( javahome.getValue() ) ); + } + else + { + throw new MisconfiguredToolchainException( "Non-existing JDK home configuration at " + + normal.getAbsolutePath() ); + } + + return jtc; + } + + public ToolchainPrivate createDefaultToolchain() + { + //not sure it's necessary to provide a default toolchain here. + //only version can be eventually supplied, and + return null; + } + + protected Logger getLogger() + { + return logger; + } + +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/maven/blob/aef3b36c/maven-core/src/site/apt/index.apt ---------------------------------------------------------------------- diff --git a/maven-core/src/site/apt/index.apt b/maven-core/src/site/apt/index.apt index f44c756..d847b0d 100644 --- a/maven-core/src/site/apt/index.apt +++ b/maven-core/src/site/apt/index.apt @@ -69,7 +69,7 @@ Maven Core with its <<<DefaultToolchainManagerPrivate>>> implementation ({{{./xref/org/apache/maven/toolchain/DefaultToolchainManagerPrivate.html}source}}), to manage toolchain selection, - * <<<JavaToolchain>>> component ({{{./apidocs/org/apache/maven/toolchain/java/JavaToolchain.html}javadoc}}), + * <<<JavaToolchain>>> interface ({{{./apidocs/org/apache/maven/toolchain/java/JavaToolchain.html}javadoc}}), with its <<<DefaultJavaToolchain>>> implementation - ({{{./xref/org/apache/maven/toolchain/java/DefaultJavaToolchain.html}source}}) and <<<DefaultJavaToolchainFactory>>> - factory ({{{./xref/org/apache/maven/toolchain/java/DefaultJavaToolchainFactory.html}source}}). + ({{{./xref/org/apache/maven/toolchain/java/DefaultJavaToolchain.html}source}}) and <<<JavaToolchainFactory>>> + factory ({{{./xref/org/apache/maven/toolchain/java/JavaToolchainFactory.html}source}}).