refactoring: reduced try/catch scope
authorHervé Boutemy <hboutemy@apache.org>
Thu, 27 Dec 2018 16:25:27 +0000 (17:25 +0100)
committerHervé Boutemy <hboutemy@apache.org>
Mon, 14 Jan 2019 12:52:03 +0000 (13:52 +0100)
maven-core/src/main/java/org/apache/maven/project/DefaultProjectBuilder.java

index a44e932..218119d 100644 (file)
@@ -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;