[ 
http://jira.codehaus.org/browse/MNG-4815?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Benjamin Bentmann closed MNG-4815.
----------------------------------

       Resolution: Fixed
    Fix Version/s: 3.0
         Assignee: Benjamin Bentmann

Improved in 
[r1000091|http://svn.apache.org/viewvc?view=revision&revision=1000091].

> (3.0-RC1) Maven Java API does not give nice error messages when improperly 
> configured
> -------------------------------------------------------------------------------------
>
>                 Key: MNG-4815
>                 URL: http://jira.codehaus.org/browse/MNG-4815
>             Project: Maven 2 & 3
>          Issue Type: Improvement
>          Components: Errors
>    Affects Versions: 3.0-beta-3
>         Environment: Maven 3.0-RC1
>            Reporter: Lincoln Baxter, III
>            Assignee: Benjamin Bentmann
>             Fix For: 3.0
>
>
> I get nullpointers all over the place if I do not set up the configuration 
> options exactly as maven requires them. This is fine, but not a very friendly 
> experience for developers trying to figure out how to use the API.
> This is a correct/simple bootstrap (see below,) but if any or many of the 
> methods are not called "just so" a nullpointer will result. Better error 
> messages should be provided, such as:
> "No LocalRepositoryManager was configured in the RespositorySession - this 
> may not be null."
> Etc...
> {noformat}
> /*
>  * JBoss, Home of Professional Open Source
>  * Copyright 2010, Red Hat, Inc., and individual contributors
>  * by the @authors tag. See the copyright.txt in the distribution for a
>  * full listing of individual contributors.
>  *
>  * This is free software; you can redistribute it and/or modify it
>  * under the terms of the GNU Lesser General Public License as
>  * published by the Free Software Foundation; either version 2.1 of
>  * the License, or (at your option) any later version.
>  *
>  * This software is distributed in the hope that it will be useful,
>  * but WITHOUT ANY WARRANTY; without even the implied warranty of
>  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
>  * Lesser General Public License for more details.
>  *
>  * You should have received a copy of the GNU Lesser General Public
>  * License along with this software; if not, write to the Free
>  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
>  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
>  */
> package org.jboss.arqmvn;
> import java.io.File;
> import java.util.ArrayList;
> import org.apache.maven.artifact.repository.ArtifactRepository;
> import org.apache.maven.artifact.repository.ArtifactRepositoryPolicy;
> import org.apache.maven.artifact.repository.MavenArtifactRepository;
> import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
> import org.apache.maven.project.DefaultProjectBuildingRequest;
> import org.apache.maven.project.ProjectBuilder;
> import org.apache.maven.project.ProjectBuildingException;
> import org.apache.maven.project.ProjectBuildingRequest;
> import org.apache.maven.project.ProjectBuildingResult;
> import org.codehaus.plexus.DefaultPlexusContainer;
> import org.codehaus.plexus.logging.console.ConsoleLoggerManager;
> import org.sonatype.aether.impl.internal.SimpleLocalRepositoryManager;
> import org.sonatype.aether.util.DefaultRepositorySystemSession;
> /**
>  * @author <a href="mailto:lincolnbax...@gmail.com";>Lincoln Baxter, III</a>
>  */
> public class MavenFacet
> {
>    private final ProjectBuildingRequest request = new 
> DefaultProjectBuildingRequest();
>    private DefaultPlexusContainer container = null;
>    private ProjectBuilder builder = null;
>    private void bootstrapMaven()
>    {
>       if (!initialized())
>       {
>          try
>          {
>             container = new DefaultPlexusContainer();
>             ConsoleLoggerManager loggerManager = new ConsoleLoggerManager();
>             loggerManager.setThreshold("ERROR");
>             container.setLoggerManager(loggerManager);
>             builder = container.lookup(ProjectBuilder.class);
>             // TODO this needs to be configurable via the project/.sidekick 
> file.
>             String localRepository = getUserHomeDir().getAbsolutePath() + 
> "/.m2/repository";
>             request.setLocalRepository(new MavenArtifactRepository(
>                      "local", new 
> File(localRepository).toURI().toURL().toString(),
>                      container.lookup(ArtifactRepositoryLayout.class),
>                      new ArtifactRepositoryPolicy(true, 
> ArtifactRepositoryPolicy.UPDATE_POLICY_NEVER,
>                               ArtifactRepositoryPolicy.CHECKSUM_POLICY_WARN),
>                      new ArtifactRepositoryPolicy(true, 
> ArtifactRepositoryPolicy.UPDATE_POLICY_NEVER,
>                               
> ArtifactRepositoryPolicy.CHECKSUM_POLICY_WARN)));
>             request.setRemoteRepositories(new 
> ArrayList<ArtifactRepository>());
>             DefaultRepositorySystemSession repositorySession = new 
> DefaultRepositorySystemSession();
>             repositorySession.setLocalRepositoryManager(new 
> SimpleLocalRepositoryManager(localRepository));
>             repositorySession.setOffline(true);
>             request.setRepositorySession(repositorySession);
>             request.setProcessPlugins(true);
>             request.setResolveDependencies(true);
>             // request.setOffline(true);
>          }
>          catch (Exception e)
>          {
>             throw new RuntimeException(e);
>          }
>       }
>    }
>    private boolean initialized()
>    {
>       return request == null;
>    }
>    /*
>     * POM manipulation methods
>     */
>    public ProjectBuildingResult getProjectBuildingResult()
>    {
>       bootstrapMaven();
>       try
>       {
>          ProjectBuildingResult buildingResult = builder.build(getPOMFile(), 
> request);
>          return buildingResult;
>       }
>       catch (ProjectBuildingException e)
>       {
>          throw new RuntimeException(e);
>       }
>    }
>    private File getPOMFile()
>    {
>       File file = new File("pom.xml");
>       return file;
>    }
>    private File getUserHomeDir()
>    {
>       return new File(System.getProperty("user.home")).getAbsoluteFile();
>    }
> }
> {noformat}

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: 
http://jira.codehaus.org/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

Reply via email to