make the artifact type handlers configurable

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@191079 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Brett Leslie Porter 2005-06-17 03:55:50 +00:00
parent 3c6c0c7a2c
commit 7fc8dfba9d
22 changed files with 151 additions and 499 deletions

View File

@ -139,43 +139,58 @@
<component>
<role>org.apache.maven.artifact.handler.ArtifactHandler</role>
<role-hint>ejb</role-hint>
<implementation>org.apache.maven.artifact.handler.EjbHandler</implementation>
</component>
<component>
<role>org.apache.maven.artifact.handler.ArtifactHandler</role>
<role-hint>plexus-service</role-hint>
<implementation>org.apache.maven.artifact.handler.PlexusServiceHandler</implementation>
<implementation>org.apache.maven.artifact.handler.DefaultArtifactHandler</implementation>
<configuration>
<type>ejb</type>
<extension>jar</extension>
</configuration>
</component>
<component>
<role>org.apache.maven.artifact.handler.ArtifactHandler</role>
<role-hint>jar</role-hint>
<implementation>org.apache.maven.artifact.handler.JarHandler</implementation>
<implementation>org.apache.maven.artifact.handler.DefaultArtifactHandler</implementation>
<configuration>
<type>jar</type>
</configuration>
</component>
<component>
<role>org.apache.maven.artifact.handler.ArtifactHandler</role>
<role-hint>maven-plugin</role-hint>
<implementation>org.apache.maven.artifact.handler.PluginHandler</implementation>
<implementation>org.apache.maven.artifact.handler.DefaultArtifactHandler</implementation>
<configuration>
<type>maven-plugin</type>
<extension>jar</extension>
</configuration>
</component>
<component>
<role>org.apache.maven.artifact.handler.ArtifactHandler</role>
<role-hint>pom</role-hint>
<implementation>org.apache.maven.artifact.handler.PomHandler</implementation>
<implementation>org.apache.maven.artifact.handler.DefaultArtifactHandler</implementation>
<configuration>
<type>pom</type>
</configuration>
</component>
<component>
<role>org.apache.maven.artifact.handler.ArtifactHandler</role>
<role-hint>source</role-hint>
<implementation>org.apache.maven.artifact.handler.SourceHandler</implementation>
<role-hint>java-source</role-hint>
<implementation>org.apache.maven.artifact.handler.DefaultArtifactHandler</implementation>
<configuration>
<type>java-source</type>
<extension>jar</extension>
</configuration>
</component>
<component>
<role>org.apache.maven.artifact.handler.ArtifactHandler</role>
<role-hint>war</role-hint>
<implementation>org.apache.maven.artifact.handler.WarHandler</implementation>
<implementation>org.apache.maven.artifact.handler.DefaultArtifactHandler</implementation>
<configuration>
<type>war</type>
</configuration>
</component>
<!--

View File

@ -52,7 +52,7 @@ public class DefaultArtifactDeployer
try
{
String extension = artifactHandlerManager.getArtifactHandler( artifact.getType() ).extension();
String extension = artifactHandlerManager.getArtifactHandler( artifact.getType() ).getExtension();
source = new File( basedir, finalName + "." + extension );
}
catch ( ArtifactHandlerNotFoundException e )

View File

@ -1,38 +0,0 @@
package org.apache.maven.artifact.handler;
/*
* Copyright 2001-2005 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.
*/
/**
* @todo these should be configurable
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
* @version $Id$
*/
public abstract class AbstractArtifactHandler
implements ArtifactHandler
{
public String extension()
{
return "jar";
}
public String directory()
{
return "jars";
}
}

View File

@ -24,7 +24,11 @@ public interface ArtifactHandler
{
static String ROLE = ArtifactHandler.class.getName();
String extension();
String getExtension();
String directory();
String getDirectory();
String getClassifier();
String getPackaging();
}

View File

@ -0,0 +1,81 @@
package org.apache.maven.artifact.handler;
/*
* Copyright 2001-2005 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.
*/
/**
* @author <a href="mailto:brett@apach.org">Brett Porter</a>
* @version $Id: AbstractArtifactHandler.java 189871 2005-06-10 00:57:19Z brett $
*/
public class DefaultArtifactHandler
implements ArtifactHandler
{
private String extension;
private String type;
private String classifier;
private String directory;
private String packaging;
public DefaultArtifactHandler()
{
}
public DefaultArtifactHandler( String type )
{
this.type = type;
}
public String getExtension()
{
if ( extension == null )
{
extension = type;
}
return extension;
}
public String getType()
{
return type;
}
public String getClassifier()
{
return classifier;
}
public String getDirectory()
{
if ( directory == null )
{
directory = type + "s";
}
return directory;
}
public String getPackaging()
{
if ( packaging == null )
{
packaging = type;
}
return packaging;
}
}

View File

@ -1,30 +0,0 @@
package org.apache.maven.artifact.handler;
/*
* Copyright 2001-2005 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.
*/
/**
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
* @version $Id$
*/
public class EjbHandler
extends JarHandler
{
public String directory()
{
return "ejbs";
}
}

View File

@ -1,42 +0,0 @@
package org.apache.maven.artifact.handler;
/*
* Copyright 2001-2005 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.
*/
/**
* @author Andreas Hoheneder (ahoh/at/inode.at)
* @version $Id$
*/
public class GenericHandler
extends AbstractArtifactHandler
{
private String type;
public GenericHandler( String atype )
{
type = atype;
}
public String extension()
{
return type;
}
public String directory()
{
return type + "s";
}
}

View File

@ -1,26 +0,0 @@
package org.apache.maven.artifact.handler;
/*
* Copyright 2001-2005 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.
*/
/**
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
* @version $Id$
*/
public class JarHandler
extends AbstractArtifactHandler
{
}

View File

@ -1,36 +0,0 @@
package org.apache.maven.artifact.handler;
/*
* Copyright 2001-2005 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.
*/
/**
* @author <a href="mailto:carlos@apache.org">Carlos Sanchez </a>
* @version $Id$
*/
public class JavadocHandler
extends AbstractArtifactHandler
{
public String extension()
{
return "jar";
}
public String directory()
{
return "javadocs";
}
}

View File

@ -1,26 +0,0 @@
package org.apache.maven.artifact.handler;
/*
* Copyright 2001-2005 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.
*/
/**
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
* @version $Id$
*/
public class PlexusApplicationHandler
extends JarHandler
{
}

View File

@ -1,26 +0,0 @@
package org.apache.maven.artifact.handler;
/*
* Copyright 2001-2005 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.
*/
/**
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
* @version $Id$
*/
public class PlexusServiceHandler
extends JarHandler
{
}

View File

@ -1,33 +0,0 @@
package org.apache.maven.artifact.handler;
/*
* Copyright 2001-2005 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.
*/
/**
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
* @version $Id$
*/
public class PluginHandler
extends AbstractArtifactHandler
{
public static final String PLUGIN_TYPE = "maven-plugin";
public String directory()
{
return "maven-plugins";
}
}

View File

@ -1,35 +0,0 @@
package org.apache.maven.artifact.handler;
/*
* Copyright 2001-2005 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.
*/
/**
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
* @version $Id$
*/
public class PomHandler
extends AbstractArtifactHandler
{
public String extension()
{
return "pom";
}
public String directory()
{
return "poms";
}
}

View File

@ -1,36 +0,0 @@
package org.apache.maven.artifact.handler;
/*
* Copyright 2001-2005 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.
*/
/**
* @author <a href="mailto:trygvis@inamo.no">Trygve Laugst&oslash;l</a>
* @version $Id$
*/
public class SourceHandler
extends AbstractArtifactHandler
{
public String extension()
{
return "jar";
}
public String directory()
{
return "sources";
}
}

View File

@ -1,35 +0,0 @@
package org.apache.maven.artifact.handler;
/*
* Copyright 2001-2005 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.
*/
/**
* @author <a href="mailto:carlos@apache.org">Carlos Sanchez</a>
* @version $Id$
*/
public class WarHandler
extends AbstractArtifactHandler
{
public String extension()
{
return "war";
}
public String directory()
{
return "wars";
}
}

View File

@ -1,31 +0,0 @@
package org.apache.maven.artifact.handler.manager;
/*
* Copyright 2001-2005 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.artifact.handler.ArtifactHandler;
/**
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
* @version $Id$
*/
public interface ArtifactHandlerManager
{
String ROLE = ArtifactHandlerManager.class.getName();
ArtifactHandler getArtifactHandler( String type )
throws ArtifactHandlerNotFoundException;
}

View File

@ -1,62 +0,0 @@
package org.apache.maven.artifact.handler.manager;
/*
* Copyright 2001-2005 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.artifact.handler.ArtifactHandler;
import org.apache.maven.artifact.handler.GenericHandler;
import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
import java.util.Map;
import java.util.Set;
/**
* @author <a href="mailto:jason@maven.org">Jason van Zyl </a>
* @version $Id: DefaultArtifactHandlerManager.java,v 1.1.1.1 2004/08/09
* 18:37:32 jvanzyl Exp $
*/
public class DefaultArtifactHandlerManager
implements ArtifactHandlerManager
{
private Map artifactHandlers;
private ArtifactRepositoryLayout artifactRepositoryLayout;
public ArtifactHandler getArtifactHandler( String type )
throws ArtifactHandlerNotFoundException
{
ArtifactHandler handler = (ArtifactHandler) artifactHandlers.get( type );
if ( handler == null )
{
handler = new GenericHandler( type );
}
// this should only happen if GenericHandler decides that the given type is unworthy to be handled
// TODO: can probably remove this
if ( handler == null )
{
throw new ArtifactHandlerNotFoundException( "Artifact handler for type '" + type + "' cannot be found." );
}
return handler;
}
public Set getHandlerTypes()
{
return artifactHandlers.keySet();
}
}

View File

@ -47,7 +47,7 @@ public class DefaultArtifactInstaller
try
{
String extension = artifactHandlerManager.getArtifactHandler( artifact.getType() ).extension();
String extension = artifactHandlerManager.getArtifactHandler( artifact.getType() ).getExtension();
source = new File( basedir, finalName + "." + extension );
}
catch ( ArtifactHandlerNotFoundException e )

View File

@ -62,9 +62,9 @@ public class DefaultRepositoryLayout
path.append( '-' ).append( artifact.getClassifier() );
}
if ( artifactHandler.extension() != null && artifactHandler.extension().length() > 0 )
if ( artifactHandler.getExtension() != null && artifactHandler.getExtension().length() > 0 )
{
path.append( '.' ).append( artifactHandler.extension() );
path.append( '.' ).append( artifactHandler.getExtension() );
}
return path.toString();

View File

@ -49,7 +49,7 @@ public class LegacyRepositoryLayout
StringBuffer path = new StringBuffer();
path.append( artifact.getGroupId() ).append( '/' );
path.append( artifactHandler.directory() ).append( '/' );
path.append( artifactHandler.getDirectory() ).append( '/' );
path.append( artifact.getArtifactId() ).append( '-' ).append( artifact.getVersion() );
if ( artifact.hasClassifier() )
@ -57,9 +57,9 @@ public class LegacyRepositoryLayout
path.append( '-' ).append( artifact.getClassifier() );
}
if ( artifactHandler.extension() != null && artifactHandler.extension().length() > 0 )
if ( artifactHandler.getExtension() != null && artifactHandler.getExtension().length() > 0 )
{
path.append( '.' ).append( artifactHandler.extension() );
path.append( '.' ).append( artifactHandler.getExtension() );
}
return path.toString();

View File

@ -148,49 +148,58 @@
<component>
<role>org.apache.maven.artifact.handler.ArtifactHandler</role>
<role-hint>ejb</role-hint>
<implementation>org.apache.maven.artifact.handler.EjbHandler</implementation>
</component>
<component>
<role>org.apache.maven.artifact.handler.ArtifactHandler</role>
<role-hint>plexus-application</role-hint>
<implementation>org.apache.maven.artifact.handler.PlexusApplicationHandler</implementation>
</component>
<component>
<role>org.apache.maven.artifact.handler.ArtifactHandler</role>
<role-hint>plexus-service</role-hint>
<implementation>org.apache.maven.artifact.handler.PlexusServiceHandler</implementation>
<implementation>org.apache.maven.artifact.handler.DefaultArtifactHandler</implementation>
<configuration>
<type>ejb</type>
<extension>jar</extension>
</configuration>
</component>
<component>
<role>org.apache.maven.artifact.handler.ArtifactHandler</role>
<role-hint>jar</role-hint>
<implementation>org.apache.maven.artifact.handler.JarHandler</implementation>
<implementation>org.apache.maven.artifact.handler.DefaultArtifactHandler</implementation>
<configuration>
<type>jar</type>
</configuration>
</component>
<component>
<role>org.apache.maven.artifact.handler.ArtifactHandler</role>
<role-hint>maven-plugin</role-hint>
<implementation>org.apache.maven.artifact.handler.PluginHandler</implementation>
<implementation>org.apache.maven.artifact.handler.DefaultArtifactHandler</implementation>
<configuration>
<type>maven-plugin</type>
<extension>jar</extension>
</configuration>
</component>
<component>
<role>org.apache.maven.artifact.handler.ArtifactHandler</role>
<role-hint>pom</role-hint>
<implementation>org.apache.maven.artifact.handler.PomHandler</implementation>
<implementation>org.apache.maven.artifact.handler.DefaultArtifactHandler</implementation>
<configuration>
<type>pom</type>
</configuration>
</component>
<component>
<role>org.apache.maven.artifact.handler.ArtifactHandler</role>
<role-hint>source</role-hint>
<implementation>org.apache.maven.artifact.handler.SourceHandler</implementation>
<role-hint>java-source</role-hint>
<implementation>org.apache.maven.artifact.handler.DefaultArtifactHandler</implementation>
<configuration>
<type>java-source</type>
<extension>jar</extension>
</configuration>
</component>
<component>
<role>org.apache.maven.artifact.handler.ArtifactHandler</role>
<role-hint>war</role-hint>
<implementation>org.apache.maven.artifact.handler.WarHandler</implementation>
<implementation>org.apache.maven.artifact.handler.DefaultArtifactHandler</implementation>
<configuration>
<type>war</type>
</configuration>
</component>
<component>

View File

@ -2,7 +2,6 @@ package org.apache.maven.plugin.version;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.factory.ArtifactFactory;
import org.apache.maven.artifact.handler.PluginHandler;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
import org.apache.maven.artifact.resolver.ArtifactResolver;
@ -531,7 +530,7 @@ public class DefaultPluginVersionManager
throws PluginVersionResolutionException
{
Artifact releaseArtifact = artifactFactory.createArtifact( groupId, artifactId, "RELEASE",
Artifact.SCOPE_RUNTIME, PluginHandler.PLUGIN_TYPE );
Artifact.SCOPE_RUNTIME, "maven-plugin" );
try
{