[ 
https://issues.apache.org/jira/browse/MSHARED-763?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16645826#comment-16645826
 ] 

ASF GitHub Bot commented on MSHARED-763:
----------------------------------------

olamy commented on a change in pull request #1: [MSHARED-763] - Include a 
dependency change detection.
URL: 
https://github.com/apache/maven-shared-incremental/pull/1#discussion_r224291307
 
 

 ##########
 File path: 
src/main/java/org/apache/maven/shared/incremental/IncrementalBuildHelper.java
 ##########
 @@ -359,6 +378,143 @@ public void afterRebuildExecution( 
IncrementalBuildHelperRequest incrementalBuil
         }
 
     }
+    /**
+     * Detect whether the dependencies has changed since the last build.
+     *
+     * @param incrementalBuildHelperRequest
+     * @return <code>true</code> if the set of dependencies got changed since 
the last build.
+     * @throws MojoExecutionException
+     */
+    public boolean dependencyTreeChanged( IncrementalBuildHelperRequest 
incrementalBuildHelperRequest )
+            throws MojoExecutionException
+    {
+        File mojoConfigBase = getMojoStatusDirectory();
+        File mojoConfigFile = new File ( mojoConfigBase, 
DEPENDENCY_INFO_FILENAME );
+
+        classpathElements.clear();
+        dependencyInfo.clear();
+
+        final List<String> classpathElementsNew = 
incrementalBuildHelperRequest.getClasspathElements();
+
+        for ( String  classPathElement : classpathElementsNew )
+        {
+            File artifactPath = new File ( classPathElement );
+            if ( artifactPath.isFile() )
+            {
+                dependencyInfo.put( artifactPath, artifactPath.lastModified() 
);
+                classpathElements.add( artifactPath );
+            }
+        }
+        if ( dependencyInfo == null )
+        {
+            return false;
+        }
+        if ( !mojoConfigFile.exists() )
+        {
+            //no file, assume rebuild
+            return true;
+        }
+
+        Map<File, Long> origDependencyInfo;
+        List<File> origClasspathElements;
+        try
+        {
+            ObjectInputStream ois = new ObjectInputStream ( new 
FileInputStream( mojoConfigFile ) );
+            origClasspathElements = ( List<File> ) ois.readObject();
+            origDependencyInfo = ( Map<File, Long> ) ois.readObject();
+            ois.close();
+        }
+        catch ( FileNotFoundException e )
+        {
+            //no file, assume rebuild
+            return true;
+        }
+        catch ( IOException e )
+        {
+            //assume rebuild
+            return true;
+        }
+        catch ( ClassNotFoundException e )
+        {
+            //unexpected exception, assume rebuild
+            return true;
+        }
+        // Check newly added dependencies
+
+        Set<File> newDependencies = new HashSet<File>( dependencyInfo.keySet() 
);
+        newDependencies.removeAll( origDependencyInfo.keySet() );
+        if ( !newDependencies.isEmpty() )
+        {
+            // new dependencies are detected
+            return true;
+        }
+
+
+        // Check removed dependencies
+
+        Set<File> removedDependencies = new HashSet<File>( 
origDependencyInfo.keySet() );
+        removedDependencies.removeAll( dependencyInfo.keySet() );
+        if ( !removedDependencies.isEmpty() )
+        {
+            //removed dependencies are detected
+            return true;
+        }
+
+
+        // Here keys of both dependencyInfo and origDependencyInfo are equal.
+        // Let's check the values.
+        for ( Map.Entry<File, Long> di : dependencyInfo.entrySet() )
+        {
+            final Long originalTimestamp = origDependencyInfo.get( di.getKey() 
);
+            final Long timestamp = di.getValue();
+            if ( !originalTimestamp.equals( timestamp ) )
+            {
+                //modified AR is detected
+                return true;
+            }
+        }
+
+        if ( !origClasspathElements.equals( classpathElements ) )
+        {
+            //order of JARs in classpath is changed
+            return true;
+        }
+
+        // obviously there was no new file detected.
+        return false;
+
+    }
+
+    public void keepDependencyInfo() throws MojoExecutionException
+    {
+        File mojoConfigBase = getMojoStatusDirectory();
+        File mojoConfigFile = new File( mojoConfigBase, 
DEPENDENCY_INFO_FILENAME );
+
+        if ( dependencyInfo == null )
+        {
+            mojoConfigFile.delete();
+            return;
+        }
+
+        try
+        {
+            ObjectOutputStream oos = new ObjectOutputStream( new 
FileOutputStream( mojoConfigFile ) );
 
 Review comment:
   use try resources

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


> Include a dependency change detection.
> --------------------------------------
>
>                 Key: MSHARED-763
>                 URL: https://issues.apache.org/jira/browse/MSHARED-763
>             Project: Maven Shared Components
>          Issue Type: Improvement
>          Components: maven-shared-incremental
>            Reporter: Liwae Lamaa
>            Priority: Major
>
> Currently, maven incremental compilation does not detect dependency change.
> Sample scenario:
>  * Project A depends on Project B.
>  * Project B is recompiled.
>  * Project A should detect this change and recompile. (which is not the case 
> currently)
>  * If B recompilation includes changing an interface, we expect A to 
> recompile and fail accordingly. 
> A fix was already performed on *maven-compiler-plugin*, but it was never 
> merged. 
> https://issues.apache.org/jira/browse/MCOMPILER-278 
> After recent discussion with [~rfscholte], he decided that the fix should 
> rather be in *maven-shared-incremental.* I have performed the implementation 
> for the fix in maven-shared-incremental, and I will be forking the project 
> for that.
> PS: The change include minor change in the *maven-compiler-plugin* for it to 
> take effect. Jira issue in maven-compiler-plugin: 
> https://issues.apache.org/jira/browse/MCOMPILER-363



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to