You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@maven.apache.org by mi...@apache.org on 2003/05/25 11:44:23 UTC
cvs commit: maven-new/core/src/java/org/apache/maven/artifact/handlers DefaultArtifactHandlerManager.java ArtifactHandlerManager.java
michal 2003/05/25 02:44:23
Modified: core/src/java/org/apache/maven/artifact/processor
DefaultArtifactProcessor.java
Added: core/src/java/org/apache/maven/artifact/handlers
DefaultArtifactHandlerManager.java
ArtifactHandlerManager.java
Log:
Further decomposition so classes can be easly tested. ArtifactHandlerManger class added
Revision Changes Path
1.2 +32 -108 maven-new/core/src/java/org/apache/maven/artifact/processor/DefaultArtifactProcessor.java
Index: DefaultArtifactProcessor.java
===================================================================
RCS file: /home/cvs/maven-new/core/src/java/org/apache/maven/artifact/processor/DefaultArtifactProcessor.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- DefaultArtifactProcessor.java 20 May 2003 19:57:52 -0000 1.1
+++ DefaultArtifactProcessor.java 25 May 2003 09:44:23 -0000 1.2
@@ -55,51 +55,28 @@
*/
package org.apache.maven.artifact.processor;
-import org.apache.avalon.framework.activity.Initializable;
+import java.util.Iterator;
+import java.util.List;
+
import org.apache.avalon.framework.service.ServiceException;
import org.apache.avalon.framework.service.ServiceManager;
import org.apache.avalon.framework.service.Serviceable;
-import org.apache.maven.MavenConstants;
-import org.apache.maven.MavenException;
+import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.factory.ArtifactFactory;
-import org.apache.maven.artifact.verify.ArtifactVerifier;
import org.apache.maven.artifact.handlers.ArtifactHandler;
-import org.apache.maven.artifact.processor.ArtifactProcessor;
+import org.apache.maven.artifact.handlers.ArtifactHandlerManager;
import org.apache.maven.artifact.satisfy.DependencySatisfier;
-import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.verify.ArtifactVerifier;
import org.apache.maven.project.Project;
-import java.io.File;
-import java.io.InputStream;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Properties;
-
/**
* Default implementation of ArtifactProcessor
*
* @author <a href="mailto:michal.maczka@dimatics.com">Michal Maczka</a>
* @version $Id$
*/
-public class DefaultArtifactProcessor
- implements Initializable, Serviceable, ArtifactProcessor
-{
-
- /**
- * Maps type to its handler Object
- */
- private Map cachedGlobalHandlers = new HashMap();
-
- /**
- * Configuraation file.
- * We will lazy load handlers. Once we need one
- * for given type we will instattiate it
- * and put to cachedGlobalHandlers map
- */
- private Properties globalHandlers = null;
-
+public class DefaultArtifactProcessor implements Serviceable, ArtifactProcessor
+{
/** */
private ArtifactFactory artifactFactory = null;
@@ -108,110 +85,57 @@
/** */
private ArtifactVerifier artifactVerifier = null;
-
- // ----------------------------------------------------------------------
- // Lifecycle Management
- // ----------------------------------------------------------------------
-
- /**
- * Reads artifact-handler.properties file
- *
- * @throws java.lang.Exception if any error occures
- */
- public void initialize() throws Exception
- {
- InputStream inputStream = null;
- File configFile = null;
- try
- {
- Class clazz = DefaultArtifactProcessor.class;
- inputStream =
- clazz.getResourceAsStream(
- MavenConstants.ARTIFACT_HANDLER_PROPERTIES );
- globalHandlers = new Properties();
- globalHandlers.load( inputStream );
- }
- catch ( Exception e )
- {
- String message = "Cannot read global layout.properties file";
- throw new MavenException( message, e );
- }
- finally
- {
- if ( inputStream != null )
- {
- try
- {
- inputStream.close();
- }
- catch ( Exception e )
- {
- }
- }
- }
- }
+
+ /** */
+ private ArtifactHandlerManager handlerManager = null;
/**
* @see org.apache.maven.artifact.ArtifactListProcessor#processArtifacts(org.apache.maven.project.Project)
*/
- public void processArtifacts( Project project ) throws Exception
+ public void processArtifacts(Project project) throws Exception
{
//1.
- artifactFactory.createArtifacts( project );
+ artifactFactory.createArtifacts(project);
//2. download all missing artifacts
- dependencySatisfier.satisfyDependencies( project );
+ dependencySatisfier.satisfyDependencies(project);
//3. verify artifacts
- artifactVerifier.verify( project );
+ artifactVerifier.verify(project);
//4. applay artifact's handlers
List artifacts = project.getArtifacts();
- for ( Iterator iter = artifacts.iterator(); iter.hasNext(); )
+ for (Iterator iter = artifacts.iterator(); iter.hasNext();)
{
Artifact artifact = (Artifact) iter.next();
String type = artifact.getType();
- ArtifactHandler artifactHandler = getHandler( type );
- if ( artifactHandler != null )
- {
- artifactHandler.process( artifact, project );
- }
- }
- }
+ ArtifactHandler artifactHandler = handlerManager.getHandler( artifact );
+ artifactHandler.process(artifact, project);
- /**
- * @param type
- * @return
- */
- private ArtifactHandler getHandler( String type ) throws Exception
- {
- if ( cachedGlobalHandlers.containsKey( type ) )
- {
- return (ArtifactHandler) cachedGlobalHandlers.get( type );
- }
- String handlerClassname = globalHandlers.getProperty( type );
- if ( handlerClassname == null )
- {
- return null;
}
- Class clazz = Class.forName( handlerClassname );
- ArtifactHandler artifactHandler = (ArtifactHandler) clazz.newInstance();
- cachedGlobalHandlers.put( type, artifactHandler );
- return artifactHandler;
}
+ // ----------------------------------------------------------------------
+ // Lifecycle Management
+ // ----------------------------------------------------------------------
+
/**
* @see org.apache.avalon.framework.service.Serviceable#service(org.apache.avalon.framework.service.ServiceManager)
*/
- public void service( ServiceManager serviceManager ) throws ServiceException
+ public void service(ServiceManager serviceManager) throws ServiceException
{
+
artifactFactory =
- (ArtifactFactory) serviceManager.lookup( ArtifactFactory.ROLE );
+ (ArtifactFactory) serviceManager.lookup(ArtifactFactory.ROLE);
dependencySatisfier =
- (DependencySatisfier) serviceManager.lookup( DependencySatisfier.ROLE );
+ (DependencySatisfier) serviceManager.lookup(
+ DependencySatisfier.ROLE);
artifactVerifier =
- (ArtifactVerifier) serviceManager.lookup( ArtifactVerifier.ROLE );
+ (ArtifactVerifier) serviceManager.lookup(ArtifactVerifier.ROLE);
+ handlerManager =
+ (ArtifactHandlerManager) serviceManager.lookup(
+ ArtifactHandlerManager.ROLE);
}
}
1.1 maven-new/core/src/java/org/apache/maven/artifact/handlers/DefaultArtifactHandlerManager.java
Index: DefaultArtifactHandlerManager.java
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2001 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache MavenSession" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* "Apache MavenSession", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* ====================================================================
*/
package org.apache.maven.artifact.handlers;
import java.io.File;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import org.apache.avalon.framework.activity.Initializable;
import org.apache.maven.MavenConstants;
import org.apache.maven.MavenException;
import org.apache.maven.artifact.Artifact;
/**
* @author <a href="michal.maczka@dimatics.com">Michal Maczka</a>
* @version $Id: DefaultArtifactHandlerManager.java,v 1.1 2003/05/25 09:44:23 michal Exp $
*/
public class DefaultArtifactHandlerManager
implements ArtifactHandlerManager, Initializable
{
private ArtifactHandler defaultHandler = new NOPHandler();
/**
* Maps type to its handler Object
*/
private Map cachedHandlers = new HashMap();
/**
* Configuration file.
* We will lazy load handlers. Once we need one
* for given type we will instattiate it
* and put to cachedHandlers map
*/
private Properties handlers = null;
/**
* @param type
* @return
*/
public ArtifactHandler getHandler(Artifact artifact) throws Exception
{
String type = artifact.getType();
if (cachedHandlers.containsKey(type))
{
return (ArtifactHandler) cachedHandlers.get(type);
}
String handlerClassname = handlers.getProperty(type);
if (handlerClassname == null)
{
return defaultHandler;
}
Class clazz = Class.forName(handlerClassname);
ArtifactHandler artifactHandler = (ArtifactHandler) clazz.newInstance();
cachedHandlers.put(type, artifactHandler);
return artifactHandler;
}
// ----------------------------------------------------------------------
// Lifecycle Management
// ----------------------------------------------------------------------
/**
* Reads artifact-handler.properties file
*
* @throws java.lang.Exception if any error occures
*/
public void initialize() throws Exception
{
InputStream inputStream = null;
File configFile = null;
try
{
Class clazz = DefaultArtifactHandlerManager.class;
inputStream =
clazz.getResourceAsStream(
MavenConstants.ARTIFACT_HANDLER_PROPERTIES);
handlers = new Properties();
handlers.load(inputStream);
}
catch (Exception e)
{
String message = "Cannot read global layout.properties file";
throw new MavenException(message, e);
}
finally
{
if (inputStream != null)
{
try
{
inputStream.close();
}
catch (Exception e)
{
}
}
}
}
}
1.1 maven-new/core/src/java/org/apache/maven/artifact/handlers/ArtifactHandlerManager.java
Index: ArtifactHandlerManager.java
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2001 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache MavenSession" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* "Apache MavenSession", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* ====================================================================
*/
package org.apache.maven.artifact.handlers;
import org.apache.maven.artifact.Artifact;
/**
* @author <a href="michal.maczka@dimatics.com">Michal Maczka</a>
* @version $Id: ArtifactHandlerManager.java,v 1.1 2003/05/25 09:44:23 michal Exp $
*/
public interface ArtifactHandlerManager
{
/** Component role name */
public static final String ROLE = ArtifactHandlerManager.class.getName();
/**
*
* @param artifact
* @return
*/
public ArtifactHandler getHandler( Artifact artifact ) throws Exception;
}
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
For additional commands, e-mail: dev-help@maven.apache.org