jvanzyl 02/04/22 13:21:57
Added: src/java/org/apache/maven ProjectVerifier.java
Log:
Renaming to a noun and javadoc'ing. This will now take the place of
update-jars to ensure that the needed resources are present before attempting
to build the projects. To start we are just looking for the missing
dependencies. We will only connect to the remote repository if something
is missing. If something is missing that requires manual intervention
then the user is notified and the build is stopped.
Revision Changes Path
1.1
jakarta-turbine-maven/src/java/org/apache/maven/ProjectVerifier.java
Index: ProjectVerifier.java
===================================================================
package org.apache.maven;
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2002 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 Maven" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* "Apache Maven", 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/>.
*/
import java.io.File;
import java.io.BufferedReader;
import java.io.FileReader;
import java.net.URL;
import java.util.Iterator;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.commons.lang.Strings;
import org.apache.maven.executor.ProjectExecutor;
import org.apache.maven.project.Dependency;
import org.apache.maven.util.HttpUtils;
/**
* Make sure that everything that is required for the project to build
* successfully is present. We will start by looking at the dependencies
* and make sure they are all here before trying to compile.
*
* @author <a href="[EMAIL PROTECTED]">Jason van Zyl</a>
* @version $Id: ProjectVerifier.java,v 1.1 2002/04/22 20:21:57 jvanzyl Exp $
* @task Create a list of all things that could go wrong and then protect
* against them.
* @task Merge the XML POM validation mechanism in here.
*/
public class ProjectVerifier
extends ProjectExecutor
{
/**
* Maven local repo
*/
private String mavenLocalRepo;
/**
* Maven remote repo
*/
private String mavenRemoteRepo;
/**
* Verbosity during downloading of missing resources.
*/
private boolean verbose = false;
/**
* Control the use of timestamp comparison when downloading
* missing resources.
*/
private boolean useTimestamp = true;
/**
* Control continuation upon errors during the
* downloading of missing resources.
*/
private boolean ignoreErrors = true;
/**
* Container for storing warnings about JARs that cannot be
* distributed by Maven.
*/
private StringBuffer warnings = new StringBuffer();
/**
* List of failed deps.
*/
private List failedDependencies;
/**
* Name of the file in the maven.remoteRepo that enumerates the
* JARs that cannot be distributed by Maven.
*/
private static final String NON_DIST_JAR_LIST = "non-distributable-jars.list";
/**
* Default ctor.
*/
public ProjectVerifier()
{
failedDependencies = new ArrayList();
}
/**
* Sets the proxyHost attribute.
*/
public void setProxyHost(String proxyHost)
{
System.getProperties().put("proxySet", "true");
System.getProperties().put("proxyHost", proxyHost);
}
/**
* Sets the mavenLocalRepo attribute of the Get object
*/
public void setMavenLocalRepo(String mavenLocalRepo)
{
this.mavenLocalRepo = mavenLocalRepo;
}
/**
* Get the maven local repo.
*/
public String getMavenLocalRepo()
{
return mavenLocalRepo;
}
/**
* Sets the mavenRemoteRepo attribute of the Get object
*/
public void setMavenRemoteRepo(String mavenRemoteRepo)
{
this.mavenRemoteRepo = mavenRemoteRepo;
}
/**
* Get the maven remote repo.
*/
public String getMavenRemoteRepo()
{
return mavenRemoteRepo;
}
/**
* Execute the task.
*
* @throws BuildException
*/
public void doExecute()
throws Exception
{
verifyDependencies();
}
/**
* Check to see that all dependencies are present and if they are
* not then download them.
*/
private void verifyDependencies()
throws Exception
{
for (Iterator i = getMavenProject().getDependencies().iterator();
i.hasNext();)
{
Dependency dependency = (Dependency)i.next();
String jar = (String) dependency.getJar();
File jarFile = new File(getMavenLocalRepo(), jar);
if (jarFile.exists() == false)
{
// We are missing a dependency. Either the user didn't
// run update-jars or something else has gone wrong. So
// We'll add the jar to our list of failed dependencies
// and get them when we're done checking all the JARs.
failedDependencies.add(jar);
}
}
// If we have any failed dependencies then we will download
// them for the user.
if (failedDependencies.size() > 0)
{
File f = new File(getMavenLocalRepo(), NON_DIST_JAR_LIST);
HttpUtils.getFile(new URL(getMavenRemoteRepo() + NON_DIST_JAR_LIST),
f, NON_DIST_JAR_LIST,verbose,
ignoreErrors,useTimestamp,"","");
Map nonDistMap = getNonDistMap(f);
for (Iterator i = failedDependencies.iterator(); i.hasNext();)
{
String dependency = (String) i.next();
log("Retrieving missing dependency: " + dependency);
URL url = new URL(mavenRemoteRepo + dependency);
File destinationFile = new File(getMavenLocalRepo(),dependency);
if (nonDistMap.containsKey(dependency))
{
if (!destinationFile.exists())
{
String[] entry =
Strings.split((String)nonDistMap.get(dependency),"$");
String downloadLocation = entry[0];
String additionalNotes = entry[1];
warnings.append("-------------------------------------------------\n");
warnings.append("W A R N I N G\n");
warnings.append("------------------------------------------------\n");
warnings.append("The following JAR must be downloaded
manually:\n");
warnings.append(dependency + "\n");
warnings.append("\n");
warnings.append("You can find the JAR here:\n");
warnings.append(downloadLocation + "\n");
warnings.append("\n\n");
warnings.append("NOTE: " + additionalNotes + "\n");
continue;
}
continue;
}
HttpUtils.getFile(url, destinationFile, dependency, verbose,
ignoreErrors, useTimestamp,"","");
}
}
if (warnings.length() > 1)
{
log("\n" + warnings.toString());
// We have warnings so that means there are non-dist jars
// that the user has to retrieve so the build can't
// continue.
getProject().setProperty("verificationFailed","true");
}
}
/**
* Get a list of JARs that cannon be distributed by Maven.
*/
private Map getNonDistMap(File f)
{
Map nonDistMap = new HashMap();
String line;
try
{
BufferedReader in = new BufferedReader(new FileReader(f));
while ((line=in.readLine()) != null)
{
line = line.trim();
// Allow comments to be placed in the payload
// descriptor.
if (line.startsWith("#") || line.startsWith("--") || line.length() <
1)
{
continue;
}
String[] entry = Strings.split(line,"|");
// The name of the non-dist JAR is the key, and the value is the
// location where the user can find it.
nonDistMap.put(entry[0], entry[1]);
}
}
catch (Exception e)
{
}
return nonDistMap;
}
}