copy maven-toolchains project into components trunk.

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@632585 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Milos Kleint 2008-03-01 12:59:47 +00:00
parent a5f49900f2
commit 5377165201
17 changed files with 1254 additions and 0 deletions

86
maven-toolchain/pom.xml Normal file
View File

@ -0,0 +1,86 @@
<?xml version="1.0" encoding="UTF-8"?>
<project>
<parent>
<groupId>org.apache.maven</groupId>
<artifactId>maven</artifactId>
<version>2.0.6</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>maven-toolchain</artifactId>
<name>Maven Toolchains</name>
<version>1.0-SNAPSHOT</version>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-core</artifactId>
<version>2.0.6</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-artifact</artifactId>
<version>2.0.6</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.modello</groupId>
<artifactId>modello-maven-plugin</artifactId>
<version>1.0-alpha-14</version>
<executions>
<execution>
<goals>
<goal>java</goal>
<goal>xsd</goal>
<goal>xpp3-reader</goal>
</goals>
</execution>
</executions>
<configuration>
<version>1.0.0</version>
<packageWithVersion>false</packageWithVersion>
<model>src/main/mdo/toolchains.xml</model>
</configuration>
</plugin>
<plugin>
<artifactId>maven-shade-plugin</artifactId>
<groupId>org.apache.maven.plugins</groupId>
<version>1.0-alpha-15</version>
<executions>
<execution>
<id>shading</id>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<artifactSet>
<includes>
<include>${project.groupId}:${project.artifactId}</include>
</includes>
</artifactSet>
<relocations>
<relocation>
<pattern>org.codehaus.plexus.util</pattern>
<excludes>
<exclude>org.codehaus.plexus.util.xml.Xpp3Dom</exclude>
<exclude>org.codehaus.plexus.util.xml.pull.*</exclude>
</excludes>
</relocation>
</relocations>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,102 @@
/*
* 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.
*/
package org.apache.maven.toolchain;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import org.apache.maven.toolchain.model.ToolchainModel;
import org.codehaus.plexus.logging.Logger;
/**
*
* @author mkleint
*/
public abstract class DefaultToolchain
implements Toolchain, ToolchainPrivate
{
private String type;
private Map provides = new HashMap /*<String,RequirementMatcher>*/ ( );
public static final String KEY_TYPE = "type"; //NOI18N
private ToolchainModel model;
private Logger logger;
protected DefaultToolchain( ToolchainModel model, Logger logger )
{
this.model = model;
this.logger = logger;
}
protected DefaultToolchain( ToolchainModel model, String type, Logger logger )
{
this( model, logger );
this.type = type;
}
public final String getType( )
{
return type;
}
public final ToolchainModel getModel( )
{
return model;
}
public final void addProvideToken( String type,
RequirementMatcher matcher )
{
provides.put( type, matcher );
}
public boolean matchesRequirements(Map requirements) {
Iterator it = requirements.keySet().iterator();
while ( it.hasNext() )
{
String key = (String) it.next();
RequirementMatcher matcher = (RequirementMatcher) provides.get(key);
if ( matcher == null )
{
getLog().debug( "Toolchain " + this + " is missing required property: " + key );
return false;
}
if ( !matcher.matches( (String) requirements.get(key) ) )
{
getLog().debug( "Toolchain " + this + " doesn't match required property: " + key );
return false;
}
}
return true;
}
protected Logger getLog() {
return logger;
}
}

View File

@ -0,0 +1,239 @@
/*
* 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.
*/
package org.apache.maven.toolchain;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.plugin.descriptor.PluginDescriptor;
import org.apache.maven.project.MavenProject;
import org.apache.maven.toolchain.model.PersistedToolchains;
import org.apache.maven.toolchain.model.ToolchainModel;
import org.apache.maven.toolchain.model.io.xpp3.MavenToolchainsXpp3Reader;
import org.codehaus.plexus.PlexusConstants;
import org.codehaus.plexus.PlexusContainer;
import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
import org.codehaus.plexus.context.Context;
import org.codehaus.plexus.context.ContextException;
import org.codehaus.plexus.logging.AbstractLogEnabled;
import org.codehaus.plexus.personality.plexus.lifecycle.phase.Contextualizable;
/**
*
* @author mkleint
*/
public class DefaultToolchainManager extends AbstractLogEnabled
implements ToolchainManager,
ToolchainManagerPrivate,
Contextualizable
{
/**
* @component
*/
private PlexusContainer container;
public DefaultToolchainManager( )
{
}
public void contextualize( Context context )
throws ContextException
{
container = (PlexusContainer) context.get(PlexusConstants.PLEXUS_KEY);
}
public ToolchainPrivate[] getToolchainsForType( String type )
throws MisconfiguredToolchainException
{
try
{
PersistedToolchains pers = readToolchainSettings ();
Map factories = container.lookupMap( ToolchainFactory.ROLE );
List toRet = new ArrayList( );
if ( pers != null )
{
List lst = pers.getToolchains();
if ( lst != null )
{
Iterator it = lst.iterator();
while ( it.hasNext() )
{
ToolchainModel toolchainModel = (ToolchainModel) it.next();
ToolchainFactory fact = (ToolchainFactory) factories.get( toolchainModel.getType() );
if ( fact != null )
{
toRet.add( fact.createToolchain( toolchainModel ) );
}
else
{
getLogger().error("Missing toolchain factory for type:" + toolchainModel.getType() + ". Possibly caused by misconfigured project.");
}
}
}
}
Iterator it = factories.values().iterator();
while ( it.hasNext() )
{
ToolchainFactory fact = (ToolchainFactory) it.next();
ToolchainPrivate tool = fact.createDefaultToolchain();
if ( tool != null )
{
toRet.add( tool );
}
}
ToolchainPrivate[] tc = new ToolchainPrivate[ toRet.size() ];
return (ToolchainPrivate[]) toRet.toArray(tc);
}
catch ( ComponentLookupException ex )
{
getLogger().fatalError("Error in component lookup", ex);
}
return new ToolchainPrivate[0];
}
public Toolchain getToolchainFromBuildContext( String type,
MavenSession session )
{
Map context = retrieveContext(session);
if ( "javac".equals( type ))
{
//HACK to make compiler plugin happy
type = "jdk";
}
Object obj = context.get( getStorageKey( type ) );
ToolchainModel model = (ToolchainModel)obj;
if ( model != null )
{
try
{
ToolchainFactory fact = (ToolchainFactory) container.lookup(ToolchainFactory.ROLE, type);
return fact.createToolchain( model );
}
catch ( ComponentLookupException ex )
{
getLogger().fatalError("Error in component lookup", ex);
}
catch ( MisconfiguredToolchainException ex )
{
getLogger().error("Misconfigured toolchain.", ex);
}
}
return null;
}
private MavenProject getCurrentProject(MavenSession session) {
//use reflection since MavenSession.getCurrentProject() is not part of 3.0.8
try
{
Method meth = session.getClass().getMethod("getCurrentProject", new Class[0]);
return (MavenProject) meth.invoke(session, null);
} catch (Exception ex)
{
//just ignore, we're running in pre- 3.0.9
}
return null;
}
private Map retrieveContext( MavenSession session )
{
if (session == null)
{
return new HashMap();
}
PluginDescriptor desc = new PluginDescriptor();
desc.setGroupId( PluginDescriptor.getDefaultPluginGroupId() );
desc.setArtifactId( PluginDescriptor.getDefaultPluginArtifactId ("toolchains") );
MavenProject current = getCurrentProject(session);
if ( current != null )
{
return session.getPluginContext( desc, current );
}
return new HashMap();
}
public void storeToolchainToBuildContext( ToolchainPrivate toolchain,
MavenSession session )
{
Map context = retrieveContext( session );
context.put( getStorageKey( toolchain.getType() ), toolchain.getModel () );
}
public static final String getStorageKey( String type )
{
return "toolchain-" + type; //NOI18N
}
private PersistedToolchains readToolchainSettings( )
throws MisconfiguredToolchainException
{
//TODO how to point to the local path?
File tch = new File( System.getProperty( "user.home" ),
".m2/toolchains.xml" );
if ( tch.exists() )
{
MavenToolchainsXpp3Reader reader = new MavenToolchainsXpp3Reader();
InputStreamReader in = null;
try
{
in = new InputStreamReader( new BufferedInputStream( new FileInputStream( tch ) ) );
return reader.read( in );
}
catch ( Exception ex )
{
throw new MisconfiguredToolchainException( "Cannot read toolchains file at " + tch.getAbsolutePath( ),
ex );
}
finally
{
if (in != null)
{
try
{
in.close();
}
catch (IOException ex)
{ }
}
// IOUtil.close( in );
}
}
else
{
//TODO log the fact that no toolchains file was found.
}
return null;
}
}

View File

@ -0,0 +1,40 @@
/*
* 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.
*/
package org.apache.maven.toolchain;
/**
*
* @author mkleint
*/
public class MisconfiguredToolchainException
extends Exception
{
public MisconfiguredToolchainException( String message )
{
super( message );
}
public MisconfiguredToolchainException( String message,
Throwable orig )
{
super( message, orig );
}
}

View File

@ -0,0 +1,30 @@
/*
* 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.
*/
package org.apache.maven.toolchain;
/**
*
* @author mkleint
*/
public interface RequirementMatcher
{
boolean matches( String requirement );
}

View File

@ -0,0 +1,94 @@
/*
* 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.
*/
package org.apache.maven.toolchain;
import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
import org.apache.maven.artifact.versioning.InvalidVersionSpecificationException;
import org.apache.maven.artifact.versioning.VersionRange;
/**
*
* @author mkleint
*/
public final class RequirementMatcherFactory
{
private RequirementMatcherFactory( )
{
}
public static RequirementMatcher createExactMatcher( String provideValue )
{
return new ExactMatcher( provideValue );
}
public static RequirementMatcher createVersionMatcher( String provideValue )
{
return new VersionMatcher( provideValue );
}
private static final class ExactMatcher
implements RequirementMatcher
{
private String provides;
private ExactMatcher( String provides )
{
this.provides = provides;
}
public boolean matches( String requirement )
{
return provides.equalsIgnoreCase( requirement );
}
}
private static final class VersionMatcher
implements RequirementMatcher
{
DefaultArtifactVersion version;
private VersionMatcher( String version )
{
this.version = new DefaultArtifactVersion(version);
}
public boolean matches( String requirement )
{
try
{
VersionRange range = VersionRange.createFromVersionSpec(requirement);
if (range.hasRestrictions()) {
return range.containsVersion(version);
} else {
return range.getRecommendedVersion().compareTo(version) == 0;
}
}
catch (InvalidVersionSpecificationException ex)
{
//TODO error reporting
ex.printStackTrace();
return false;
}
}
}
}

View File

@ -0,0 +1,39 @@
/*
* 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.
*/
package org.apache.maven.toolchain;
/**
* @author Milos Kleint
* @author Jason van Zyl
*/
public interface Toolchain
{
String getType( );
/**
* Gets the platform tool executable.
*
* @param toolName the tool platform independent tool name.
* @return file representing the tool executable, or null if the tool can not be found
*/
String findTool( String toolName );
}

View File

@ -0,0 +1,45 @@
/*
* 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.
*/
package org.apache.maven.toolchain;
import org.apache.maven.toolchain.model.ToolchainModel;
/**
*
* @author mkleint
*/
public interface ToolchainFactory
{
String ROLE = ToolchainFactory.class.getName();
/**
* Create instance of toolchain.
**/
ToolchainPrivate createToolchain( ToolchainModel model )
throws MisconfiguredToolchainException;
/**
* Returns the default instance of the particular type of toolchain, can return null
* if not applicable.
* TODO keep around??
**/
ToolchainPrivate createDefaultToolchain( );
}

View File

@ -0,0 +1,41 @@
/*
* 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.
*/
package org.apache.maven.toolchain;
import org.apache.maven.execution.MavenSession;
/**
*
* @author mkleint
*/
public interface ToolchainManager
{
String ROLE = ToolchainManager.class.getName();
/**
* to be used from plugins capable of working with toolchains.
*/
Toolchain getToolchainFromBuildContext( String type,
MavenSession context );
}

View File

@ -0,0 +1,46 @@
/*
* 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.
*/
package org.apache.maven.toolchain;
import org.apache.maven.execution.MavenSession;
/**
* Component for use by the maven-toolchains-plugin only.
* @author mkleint
*/
public interface ToolchainManagerPrivate
{
String ROLE = ToolchainManagerPrivate.class.getName();
/**
* Retrieves the toolchains of given type from the user settings.
*/
ToolchainPrivate[] getToolchainsForType( String type )
throws MisconfiguredToolchainException;
/**
* Stores the toolchain into build context.
*/
void storeToolchainToBuildContext( ToolchainPrivate toolchain,
MavenSession context );
}

View File

@ -0,0 +1,43 @@
/*
* 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.
*/
package org.apache.maven.toolchain;
import java.util.Map;
import org.apache.maven.toolchain.model.ToolchainModel;
/**
* a private contract between the toolchains plugin and the components.
* @author mkleint
*/
public interface ToolchainPrivate
extends Toolchain
{
/**
* Let the toolchain decide if it matches requirements defined
* in the toolchain plugin configuration.
* @param requirements Map<String, String> key value pair
* @return
*/
boolean matchesRequirements( Map requirements);
ToolchainModel getModel( );
}

View File

@ -0,0 +1,87 @@
/*
* 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.
*/
package org.apache.maven.toolchain.java;
import java.io.File;
import org.apache.maven.toolchain.DefaultToolchain;
import org.apache.maven.toolchain.model.ToolchainModel;
import org.codehaus.plexus.logging.Logger;
import org.codehaus.plexus.util.FileUtils;
import org.codehaus.plexus.util.Os;
/**
* @author Milos Kleint
*/
public class DefaultJavaToolChain
extends DefaultToolchain
implements JavaToolChain
{
private String javaHome;
public static final String KEY_JAVAHOME = "jdkHome"; //NOI18N
public DefaultJavaToolChain( ToolchainModel model, Logger logger )
{
super( model, "jdk", logger );
}
public String getJavaHome( )
{
return javaHome;
}
public void setJavaHome( String javaHome )
{
this.javaHome = javaHome;
}
public String toString( )
{
return "JDK[" + getJavaHome( ) + "]";
}
public String findTool( String toolName )
{
File toRet = findTool( toolName,
new File( FileUtils.normalize( getJavaHome( ) ) ) );
if ( toRet != null )
{
return toRet.getAbsolutePath( );
}
return null;
}
private static File findTool( String toolName, File installFolder )
{
File bin = new File( installFolder, "bin" ); //NOI18N
if ( bin.exists( ) )
{
File tool = new File( bin,
toolName + (Os.isFamily( "windows" ) ? ".exe" : "") ); //NOI18N
if ( tool.exists( ) )
{
return tool;
}
}
return null;
}
}

View File

@ -0,0 +1,113 @@
/*
* 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.
*/
package org.apache.maven.toolchain.java;
import java.io.File;
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.logging.LogEnabled;
import org.codehaus.plexus.logging.Logger;
import org.codehaus.plexus.util.FileUtils;
import org.codehaus.plexus.util.xml.Xpp3Dom;
/**
*
* @author mkleint
*/
public class DefaultJavaToolchainFactory
implements ToolchainFactory, LogEnabled
{
private Logger logger;
public DefaultJavaToolchainFactory( )
{
}
public ToolchainPrivate createToolchain( ToolchainModel model )
throws MisconfiguredToolchainException
{
if (model == null) {
return null;
}
DefaultJavaToolChain jtc = new DefaultJavaToolChain( model , logger);
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( ) );
}
//now populate the provides section.
//TODO possibly move at least parts to a utility method or abstract implementation.
dom = (Xpp3Dom) model.getProvides();
Xpp3Dom[] provides = dom.getChildren();
for ( int i = 0; i < provides.length; i++ )
{
String key = provides[i].getName();
String value = provides[i].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 ) );
}
}
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;
}
public void enableLogging( Logger logger )
{
this.logger = logger;
}
}

View File

@ -0,0 +1,65 @@
/*
* 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.
*/
package org.apache.maven.toolchain.java;
import org.apache.maven.toolchain.Toolchain;
/**
* @author Jason van Zyl
* @author Milos Kleint
*/
public interface JavaToolChain
extends Toolchain
{
// /**
// * Returns a list of {@link java.io.File}s which represents the bootstrap libraries for the
// * runtime environment. The Bootstrap libraries include libraries in JRE's
// * extension directory, if there are any.
// *
// * @return List
// */
// List getBootstrapLibraries();
//
// /**
// * Returns a list of {@link java.io.File}s which represent the libraries recognized by
// * default by the platform. Usually it corresponds to contents of CLASSPATH
// * environment variable.
// *
// * @return List
// */
// List getStandardLibraries();
//
// /**
// * Returns a {@link java.io.File}s which represent the locations of the source of the JDK,
// * or an empty collection when the location is not set or is invalid.
// *
// * @return List
// */
// List getSourceDirectories();
//
// /**
// * Returns a {@link java.io.File}s which represent the locations of the Javadoc for this platform,
// * or empty collection if the location is not set or invalid
// *
// * @return List
// */
// List getJavadocFolders();
}

View File

@ -0,0 +1,79 @@
<?xml version="1.0"?>
<!--
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.
-->
<model>
<id>maven-toolchains</id>
<name>MavenToolchains</name>
<description><![CDATA[
]]></description>
<defaults>
<default>
<key>package</key>
<value>org.apache.maven.toolchain.model</value>
</default>
</defaults>
<classes>
<class rootElement="true" xml.tagName="toolchains" xsd.compositor="sequence">
<name>PersistedToolchains</name>
<description><![CDATA[
The <code>&lt;project&gt;</code> element is the root of the descriptor.
The following table lists all of the possible child elements.
]]></description>
<version>1.0.0+</version>
<fields>
<field xml.listStyle="flat">
<name>toolchains</name>
<version>1.0.0+</version>
<description><![CDATA[The toolchain definition.]]></description>
<association>
<type>ToolchainModel</type>
<multiplicity>*</multiplicity>
</association>
</field>
</fields>
</class>
<class>
<name>ToolchainModel</name>
<version>1.0.0+</version>
<fields>
<field>
<name>type</name>
<version>1.0.0+</version>
<description>
<![CDATA[Type of toolchain]]></description>
<type>String</type>
</field>
<field>
<name>provides</name>
<version>1.0.0+</version>
<type>DOM</type>
</field>
<field>
<name>configuration</name>
<version>1.0.0+</version>
<type>DOM</type>
</field>
</fields>
</class>
</classes>
</model>

View File

@ -0,0 +1,44 @@
<!--
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.
-->
<component-set>
<components>
<component>
<role>org.apache.maven.toolchain.ToolchainManager</role>
<implementation>org.apache.maven.toolchain.DefaultToolchainManager</implementation>
</component>
<!--- TODO do I really need to define 2 components? I'd rather have 1 istance shared for both lookups. -->
<component>
<role>org.apache.maven.toolchain.ToolchainManagerPrivate</role>
<implementation>org.apache.maven.toolchain.DefaultToolchainManager</implementation>
</component>
<component>
<role>org.apache.maven.toolchain.ToolchainFactory</role>
<role-hint>jdk</role-hint>
<implementation>org.apache.maven.toolchain.java.DefaultJavaToolchainFactory</implementation>
</component>
<!-- make sure the compiler-plugin gets the jdk toolchain -->
<component>
<role>org.apache.maven.toolchain.ToolchainFactory</role>
<role-hint>javac</role-hint>
<implementation>org.apache.maven.toolchain.java.DefaultJavaToolchainFactory</implementation>
</component>
</components>
</component-set>

View File

@ -0,0 +1,61 @@
/*
* 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.
*/
package org.apache.maven.toolchain;
import junit.framework.TestCase;
/**
*
* @author mkleint
*/
public class RequirementMatcherFactoryTest extends TestCase {
public RequirementMatcherFactoryTest(String testName) {
super(testName);
}
/**
* Test of createExactMatcher method, of class RequirementMatcherFactory.
*/
public void testCreateExactMatcher() {
RequirementMatcher matcher;
matcher = RequirementMatcherFactory.createExactMatcher("foo");
assertFalse(matcher.matches("bar"));
assertFalse(matcher.matches("foobar"));
assertFalse(matcher.matches("foob"));
assertTrue(matcher.matches("foo"));
}
/**
* Test of createVersionMatcher method, of class RequirementMatcherFactory.
*/
public void testCreateVersionMatcher() {
RequirementMatcher matcher;
matcher = RequirementMatcherFactory.createVersionMatcher("1.5.2");
assertFalse(matcher.matches("1.5"));
assertTrue(matcher.matches("1.5.2"));
assertFalse(matcher.matches("[1.4,1.5)"));
assertFalse(matcher.matches("[1.5,1.5.2)"));
assertFalse(matcher.matches("(1.5.2,1.6)"));
assertTrue(matcher.matches("(1.4,1.5.2]"));
assertTrue(matcher.matches("(1.5,)"));
}
}