package org.apache.maven.repository;
/* ====================================================================
* Copyright 2001-2004 The Apache Software Foundation.
*
* Licensed 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 org.apache.maven.jelly.MavenJellyContext;
import org.apache.maven.project.Dependency;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* ArtifactTypeHandlerFactory
* Creates ArtifactTypeHandlers to create Artifacts and
* handle the different types of dependencies.
*
* This allows for different types to be specified.
* Add the following to your properties files to set the settings:
*
* maven.type.handler.<Type Name>=org.maven....ArtifactTypeHandler
*
* Uses the MavenJellyContext.
*
* @author Daniel Marchant
* @version 1.0 5:08:06 PM
*
*/
public class ArtifactTypeHandlerFactory {
private static Log log = LogFactory.getLog(ArtifactTypeHandlerFactory.class);
public static ArtifactTypeHandler getHandler(Dependency dependency, MavenJellyContext context) {
String type = dependency.getType();
String name = "maven.type.handler." + type;
String instanceName = name + ".instance";
ArtifactTypeHandler handler = (ArtifactTypeHandler)context.getVariable(instanceName);
if(handler != null) return handler;
String className =(String)context.getVariable(name);
if(className != null) {
try {
handler = (ArtifactTypeHandler)Class.forName(className).newInstance();
context.setVariable(instanceName, handler);
} catch(InstantiationException ie) {
log.warn(" Problem instantiating the handler: " + className,ie);
} catch(IllegalAccessException iae) {
log.warn(" Cannot Access the handler: " + className,iae);
} catch(ClassNotFoundException cnfe) {
log.warn(" ClassNot found for the handler: " + className,cnfe);
}
}
if(handler == null) {
handler = new DefaultArtifactTypeHandler();
context.setVariable(instanceName, handler);
}
return handler;
}
}