You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@maven.apache.org by jv...@apache.org on 2004/04/05 19:23:57 UTC
cvs commit: maven-components/maven-project/src/main/java/org/apache/maven/artifact/satisfier ArtifactSatisfier.java DefaultArtifactSatisfier.java UnsatisfiedArtifactException.java DefaultDependencySatisfier.java DependencySatisfier.java UnsatisfiedDependencyException.java
jvanzyl 2004/04/05 10:23:57
Added: maven-project/src/main/java/org/apache/maven/artifact/satisfier
ArtifactSatisfier.java
DefaultArtifactSatisfier.java
UnsatisfiedArtifactException.java
Removed: maven-project/src/main/java/org/apache/maven/artifact/satisfier
DefaultDependencySatisfier.java
DependencySatisfier.java
UnsatisfiedDependencyException.java
Log:
Revision Changes Path
1.1 maven-components/maven-project/src/main/java/org/apache/maven/artifact/satisfier/ArtifactSatisfier.java
Index: ArtifactSatisfier.java
===================================================================
package org.apache.maven.artifact.satisfier;
/*
* 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.project.MavenProject;
/**
*
*
* @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
*
* @version $Id: ArtifactSatisfier.java,v 1.1 2004/04/05 17:23:56 jvanzyl Exp $
*/
public interface ArtifactSatisfier
{
static String ROLE = ArtifactSatisfier.class.getName();
public void verifyDependencies( MavenProject project )
throws UnsatisfiedArtifactException;
}
1.1 maven-components/maven-project/src/main/java/org/apache/maven/artifact/satisfier/DefaultArtifactSatisfier.java
Index: DefaultArtifactSatisfier.java
===================================================================
package org.apache.maven.artifact.satisfier;
/*
* 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.artifact.MavenArtifact;
import org.apache.maven.artifact.WagonArtifactAdapter;
import org.apache.maven.project.MavenProject;
import org.apache.maven.wagon.manager.WagonManager;
import org.codehaus.plexus.i18n.I18N;
import org.codehaus.plexus.logging.AbstractLogEnabled;
import org.codehaus.plexus.util.StringUtils;
import java.io.File;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
public class DefaultArtifactSatisfier
extends AbstractLogEnabled
implements ArtifactSatisfier
{
private boolean useTimestamp = true;
private boolean ignoreErrors = true;
private List failedDependencies;
private I18N i18n;
private WagonManager wagonManager;
public DefaultArtifactSatisfier()
{
failedDependencies = new ArrayList();
}
public void verifyDependencies( MavenProject project )
throws UnsatisfiedArtifactException
{
satisfyDependencies( project );
}
private void clearFailedDependencies()
{
for ( int i = 0; i < failedDependencies.size(); i++ )
{
failedDependencies.remove( i );
}
}
private void satisfyDependencies( MavenProject project )
throws UnsatisfiedArtifactException
{
// Is the remote repository enabled?
boolean remoteRepoEnabled = project.getBooleanProperty( "maven.repo.remote.enabled" );
// Is the user online?
boolean online = project.getBooleanProperty( "maven.mode.online" );
if ( !remoteRepoEnabled )
{
getLogger().warn( i18n.getString( "remote.repository.disabled.warning" ) );
}
clearFailedDependencies();
for ( Iterator i = project.getArtifacts().iterator(); i.hasNext(); )
{
MavenArtifact artifact = (MavenArtifact) i.next();
// The artifact plain doesn't exist so chalk it up as a failed dependency.
if ( !artifact.exists() )
{
failedDependencies.add( artifact );
}
else
{
// The artifact exists but we need to take into account the user
// being online and whether the artifact is a snapshot. If the user
// is online then snapshots are added to the list of failed dependencies
// so that a newer version can be retrieved if one exists. We make
// an exception when the user is working offline and let them
// take their chances with a strong warning that they could possibly
// be using an out-of-date artifact. We don't want to cripple users
// when working offline.
if ( online && artifact.isSnapshot() )
{
failedDependencies.add( artifact );
}
else if ( !online && artifact.isSnapshot() )
{
getLogger().warn( i18n.format( "offline.snapshot.warning", artifact.getName() ) );
}
}
}
// If we have any failed dependencies then we will attempt to download
// them for the user if the remote repository is enabled.
if ( !failedDependencies.isEmpty() && remoteRepoEnabled && online )
{
getDependencies( project );
}
// If we still have failed dependencies after we have tried to
// satisfy all dependencies then we have a problem. There might
// also be a problem if the use of the remote repository has
// been disabled and dependencies just aren't present. In any
// case we have a problem.
if ( !failedDependencies.isEmpty() )
{
throw new UnsatisfiedArtifactException( createUnsatisfiedDependenciesMessage() );
}
}
private String createUnsatisfiedDependenciesMessage()
{
StringBuffer message = new StringBuffer();
if ( failedDependencies.size() == 1 )
{
message.append( i18n.getString( "single.unsatisfied.dependency.error" ) );
}
else
{
message.append( i18n.getString( "multiple.unsatisfied.dependency.error" ) );
}
message.append( "\n\n" );
for ( Iterator i = failedDependencies.iterator(); i.hasNext(); )
{
MavenArtifact artifact = (MavenArtifact) i.next();
message.append( artifact.getName() );
String url = artifact.getDependency().getUrl();
if ( StringUtils.isNotEmpty( url ) )
{
// FIXME: internationalize
message.append( " (" )
.append( "try downloading from " )
.append( url )
.append( ")" );
}
else
{
// FIXME: internationalize
message.append( " (no download url specified)" );
}
message.append( "\n" );
}
return message.toString();
}
private void getDependencies( MavenProject project )
{
for ( Iterator i = failedDependencies.iterator(); i.hasNext(); )
{
MavenArtifact artifact = (MavenArtifact) i.next();
// The directory structure for the project this dependency belongs to
// may not exists so attempt to create the project directory structure
// before attempting to download the dependency.
File directory = artifact.getFile().getParentFile();
if ( !directory.exists() )
{
directory.mkdirs();
}
getLogger().info( i18n.format( "download.message", artifact.getName() ) );
if ( getRemoteArtifact( project, artifact ) )
{
// The dependency has been successfully downloaded so lets remove
// it from the failed dependency list.
i.remove();
}
else
{
if ( artifact.exists() )
{
// The snapshot jar locally exists and not in remote repository
// FIXME: localize this message
getLogger().debug( "Artifact " + artifact.getUrlPath() + " doesn't exists in remote repository, but it exists locally" );
i.remove();
}
else
{
String warning = i18n.format( "failed.download.warning", artifact.getName() );
getLogger().warn( warning );
}
}
}
}
private boolean getRemoteArtifact( MavenProject project, MavenArtifact artifact )
{
File localRepo = new File( project.getProperty( "maven.repo.localRepo" ) );
File destination = new File( localRepo, artifact.getPath() );
try
{
wagonManager.getWagon( "http" ).get( new WagonArtifactAdapter( artifact ), destination );
}
catch (Exception e )
{
return false;
}
return true;
}
public boolean isIgnoreErrors()
{
return ignoreErrors;
}
public void setIgnoreErrors( boolean ignoreErrors )
{
this.ignoreErrors = ignoreErrors;
}
}
1.1 maven-components/maven-project/src/main/java/org/apache/maven/artifact/satisfier/UnsatisfiedArtifactException.java
Index: UnsatisfiedArtifactException.java
===================================================================
package org.apache.maven.artifact.satisfier;
/*
* 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.
*/
public class UnsatisfiedArtifactException
extends Exception
{
public UnsatisfiedArtifactException( String message )
{
super( message );
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
For additional commands, e-mail: dev-help@maven.apache.org