You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by hb...@apache.org on 2019/01/14 13:02:48 UTC

[maven] 02/05: refactoring: reduced try/catch scope

This is an automated email from the ASF dual-hosted git repository.

hboutemy pushed a commit to branch MNG-6533-2
in repository https://gitbox.apache.org/repos/asf/maven.git

commit 049b7a7ba8857fdbca94acca4d104af6f3532ee9
Author: Hervé Boutemy <hb...@apache.org>
AuthorDate: Thu Dec 27 17:25:27 2018 +0100

    refactoring: reduced try/catch scope
---
 .../maven/project/DefaultProjectBuilder.java       | 143 +++++++++++----------
 1 file changed, 72 insertions(+), 71 deletions(-)

diff --git a/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java b/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java
index a44e932..218119d 100644
--- a/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java
+++ b/maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java
@@ -438,106 +438,107 @@ public class DefaultProjectBuilder
             new DefaultModelBuildingListener( project, projectBuildingHelper, config.request );
         request.setModelBuildingListener( listener );
 
+        ModelBuildingResult result;
         try
         {
-            ModelBuildingResult result = modelBuilder.build( request );
+            result = modelBuilder.build( request );
+        }
+        catch ( ModelBuildingException e )
+        {
+            results.add( new DefaultProjectBuildingResult( e.getModelId(), pomFile, e.getProblems() ) );
 
-            Model model = result.getEffectiveModel();
+            return false;
+        }
 
-            projectIndex.put( result.getModelIds().get( 0 ), project );
+        Model model = result.getEffectiveModel();
 
-            InterimResult interimResult = new InterimResult( pomFile, request, result, listener, isRoot );
-            interimResults.add( interimResult );
+        projectIndex.put( result.getModelIds().get( 0 ), project );
 
-            if ( recursive && !model.getModules().isEmpty() )
-            {
-                File basedir = pomFile.getParentFile();
+        InterimResult interimResult = new InterimResult( pomFile, request, result, listener, isRoot );
+        interimResults.add( interimResult );
+
+        if ( recursive && !model.getModules().isEmpty() )
+        {
+            File basedir = pomFile.getParentFile();
 
-                List<File> moduleFiles = new ArrayList<>();
+            List<File> moduleFiles = new ArrayList<>();
 
-                for ( String module : model.getModules() )
+            for ( String module : model.getModules() )
+            {
+                if ( StringUtils.isEmpty( module ) )
                 {
-                    if ( StringUtils.isEmpty( module ) )
-                    {
-                        continue;
-                    }
+                    continue;
+                }
 
-                    module = module.replace( '\\', File.separatorChar ).replace( '/', File.separatorChar );
+                module = module.replace( '\\', File.separatorChar ).replace( '/', File.separatorChar );
 
-                    File moduleFile = new File( basedir, module );
+                File moduleFile = new File( basedir, module );
 
-                    if ( moduleFile.isDirectory() )
-                    {
-                        moduleFile = modelProcessor.locatePom( moduleFile );
-                    }
+                if ( moduleFile.isDirectory() )
+                {
+                    moduleFile = modelProcessor.locatePom( moduleFile );
+                }
 
-                    if ( !moduleFile.isFile() )
-                    {
-                        ModelProblem problem =
-                            new DefaultModelProblem( "Child module " + moduleFile + " of " + pomFile
-                                + " does not exist", ModelProblem.Severity.ERROR, ModelProblem.Version.BASE, model, -1,
-                                                     -1, null );
-                        result.getProblems().add( problem );
+                if ( !moduleFile.isFile() )
+                {
+                    ModelProblem problem =
+                        new DefaultModelProblem( "Child module " + moduleFile + " of " + pomFile
+                            + " does not exist", ModelProblem.Severity.ERROR, ModelProblem.Version.BASE, model, -1,
+                                                 -1, null );
+                    result.getProblems().add( problem );
 
-                        noErrors = false;
+                    noErrors = false;
 
-                        continue;
-                    }
+                    continue;
+                }
 
-                    if ( Os.isFamily( Os.FAMILY_WINDOWS ) )
+                if ( Os.isFamily( Os.FAMILY_WINDOWS ) )
+                {
+                    // we don't canonicalize on unix to avoid interfering with symlinks
+                    try
                     {
-                        // we don't canonicalize on unix to avoid interfering with symlinks
-                        try
-                        {
-                            moduleFile = moduleFile.getCanonicalFile();
-                        }
-                        catch ( IOException e )
-                        {
-                            moduleFile = moduleFile.getAbsoluteFile();
-                        }
+                        moduleFile = moduleFile.getCanonicalFile();
                     }
-                    else
+                    catch ( IOException e )
                     {
-                        moduleFile = new File( moduleFile.toURI().normalize() );
+                        moduleFile = moduleFile.getAbsoluteFile();
                     }
+                }
+                else
+                {
+                    moduleFile = new File( moduleFile.toURI().normalize() );
+                }
 
-                    if ( aggregatorFiles.contains( moduleFile ) )
+                if ( aggregatorFiles.contains( moduleFile ) )
+                {
+                    StringBuilder buffer = new StringBuilder( 256 );
+                    for ( File aggregatorFile : aggregatorFiles )
                     {
-                        StringBuilder buffer = new StringBuilder( 256 );
-                        for ( File aggregatorFile : aggregatorFiles )
-                        {
-                            buffer.append( aggregatorFile ).append( " -> " );
-                        }
-                        buffer.append( moduleFile );
-
-                        ModelProblem problem =
-                            new DefaultModelProblem( "Child module " + moduleFile + " of " + pomFile
-                                + " forms aggregation cycle " + buffer, ModelProblem.Severity.ERROR,
-                                                     ModelProblem.Version.BASE, model, -1, -1, null );
-                        result.getProblems().add( problem );
-
-                        noErrors = false;
-
-                        continue;
+                        buffer.append( aggregatorFile ).append( " -> " );
                     }
+                    buffer.append( moduleFile );
 
-                    moduleFiles.add( moduleFile );
-                }
-
-                interimResult.modules = new ArrayList<>();
+                    ModelProblem problem =
+                        new DefaultModelProblem( "Child module " + moduleFile + " of " + pomFile
+                            + " forms aggregation cycle " + buffer, ModelProblem.Severity.ERROR,
+                                                 ModelProblem.Version.BASE, model, -1, -1, null );
+                    result.getProblems().add( problem );
 
-                if ( !build( results, interimResult.modules, projectIndex, moduleFiles, aggregatorFiles, false,
-                             recursive, config ) )
-                {
                     noErrors = false;
+
+                    continue;
                 }
+
+                moduleFiles.add( moduleFile );
             }
-        }
-        catch ( ModelBuildingException e )
-        {
-            results.add( new DefaultProjectBuildingResult( e.getModelId(), pomFile, e.getProblems() ) );
 
-            noErrors = false;
+            interimResult.modules = new ArrayList<>();
+
+            if ( !build( results, interimResult.modules, projectIndex, moduleFiles, aggregatorFiles, false,
+                         recursive, config ) )
+            {
+                noErrors = false;
+            }
         }
 
         return noErrors;