Author: timotei
Date: Sat Aug 20 08:39:32 2011
New Revision: 50862

URL: http://svn.gna.org/viewcvs/wesnoth?rev=50862&view=rev
Log:
eclipse plugin: Add file includes in the
Dependency List as well.

Modified:
    
trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/builder/DependencyListBuilder.java
    
trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/builder/DependencyListNode.java
    
trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/builder/WesnothProjectBuilder.java
    trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/utils/ResourceUtils.java

Modified: 
trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/builder/DependencyListBuilder.java
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/builder/DependencyListBuilder.java?rev=50862&r1=50861&r2=50862&view=diff
==============================================================================
--- 
trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/builder/DependencyListBuilder.java
 (original)
+++ 
trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/builder/DependencyListBuilder.java
 Sat Aug 20 08:39:32 2011
@@ -51,10 +51,13 @@
 
     /**
      * Holds a list of directories that are parsed in the WML order
-     * (that is, they don't have a _main.cfg in them) and
-     * the value is the first node in that directory existing in the list
+     * (that is, they don't have a _main.cfg in them).
      */
     private List< String >                    directories_;
+    /**
+     * This list contains the first node of each directory in the
+     * {@link #directories_} list
+     */
     private List< ListDirectoryEntry >        directoriesEntries_;
 
     /**
@@ -67,8 +70,8 @@
     public DependencyListBuilder( IProject project )
     {
         list_ = new HashMap< String, DependencyListNode >( );
+
         directories_ = new ArrayList< String >( );
-
         directoriesEntries_ = new ArrayList< ListDirectoryEntry >( );
 
         previous_ = null;
@@ -89,7 +92,7 @@
     {
         if( isCreated_ && ! force ) {
             Logger.getInstance( )
-                .log( "Skipping depedency list for project "
+                .log( "Skipping dependency list for project "
                     + project_.getName( ) );
             return;
         }
@@ -173,7 +176,6 @@
                 }
             }
             else {
-
                 // previous_ should be the first non-null node in previous
                 // directories.
 
@@ -186,13 +188,13 @@
                 newNode = internal_addNode( file );
             }
 
-            // now, parse the file to check if we should include other dirs
-            internal_addContainers( newNode.getIncludes( true ) );
+            // now, parse the file to check if we should include other
+            // dirs/files
+            internal_addIncludes( newNode.getMacroIncludes( true ) );
         }
         else {
             // didn't found any place to put it. where shall we?
-            // the place should be dictated by other cfg,
-            // by getting the included directory
+            // the place should be dictated by other cfg via a macro include
         }
 
         // restore old previous
@@ -202,15 +204,21 @@
     }
 
     /**
-     * Adds the containers and their contents to the list
+     * Adds the includes to the list
      * 
      * @param containerList
      *        The list of container paths
      */
-    private void internal_addContainers( Collection< String > containerList )
-    {
-        for( String container: containerList ) {
-            internal_addContainer( container );
+    private void internal_addIncludes( Collection< String > includesList )
+    {
+        for( String include: includesList ) {
+            IFile file = project_.getFile( include );
+            if( file.exists( ) ) {
+                internal_addNode( file );
+            }
+            else {
+                internal_addContainer( include );
+            }
         }
     }
 
@@ -241,8 +249,8 @@
             // add main.cfg to list
             DependencyListNode newNode = internal_addNode( ( IFile ) main_cfg 
);
 
-            // add any included containers
-            internal_addContainers( newNode.getIncludes( true ) );
+            // add any included files/folders
+            internal_addIncludes( newNode.getMacroIncludes( true ) );
         }
         else {
             // no main.cfg, just follow WML reading rules
@@ -338,6 +346,11 @@
      */
     private DependencyListNode internal_addNode( IFile file )
     {
+        // don't add a file more than 1 time
+        if( list_.containsKey( file.getProjectRelativePath( ).toString( ) ) ) {
+            return getNode( file );
+        }
+
         DependencyListNode newNode = new DependencyListNode( file, - 1 );
 
         if( previous_ != null ) {
@@ -423,10 +436,9 @@
             node.getNext( ).setPrevious( node.getPrevious( ) );
         }
 
-        String fileParentProjectPath = node.getFile( ).getParent( )
-            .getProjectRelativePath( ).toString( );
-
-        list_.remove( node.getFile( ).getProjectRelativePath( ).toString( ) );
+        IFile file = node.getFile( );
+
+        list_.remove( file.getProjectRelativePath( ).toString( ) );
 
         // if we're at last node, decrease currentIndex_ to make economy on
         // indexes
@@ -437,13 +449,14 @@
             }
         }
 
-        // removing a _main.cfg, add the parent container
+        // if removing a _main.cfg, we need to add the parent container
         // back to the list along with it's directories_ entry
-        if( node.getFile( ).getName( ).equals( "_main.cfg" ) ) {
+        if( file.getName( ).equals( "_main.cfg" ) ) {
             DependencyListNode backupPrevious = previous_;
 
             previous_ = node.getPrevious( );
-            internal_addContainer( fileParentProjectPath );
+            internal_addContainer( file.getParent( ).getProjectRelativePath( )
+                .toString( ) );
 
             previous_ = backupPrevious;
         }
@@ -498,10 +511,10 @@
     public void updateNode( DependencyListNode node )
     {
         // check the includes, to see if they changed
-        List< String > previousIncludes = node.getIncludes( false );
+        List< String > previousIncludes = node.getMacroIncludes( false );
         int prevLength = previousIncludes.size( );
 
-        List< String > newIncludes = node.getIncludes( true );
+        List< String > newIncludes = node.getMacroIncludes( true );
         int newLength = newIncludes.size( );
 
         List< String > processedIncludes = new ArrayList< String >( );
@@ -642,7 +655,7 @@
     /**
      * Returns the node specified by the key. The keys are
      * usually project-relative paths for project's files, or
-     * the {@link #ROOT_NODE_KEY}
+     * the {@link #ROOT_NODE_KEY} for the first list node
      * 
      * @param key
      *        The key to get the node by
@@ -658,7 +671,7 @@
      * 
      * @return A boolean value
      */
-    public boolean getIsCreated( )
+    public boolean isCreated( )
     {
         return isCreated_;
     }

Modified: 
trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/builder/DependencyListNode.java
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/builder/DependencyListNode.java?rev=50862&r1=50861&r2=50862&view=diff
==============================================================================
--- 
trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/builder/DependencyListNode.java 
(original)
+++ 
trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/builder/DependencyListNode.java 
Sat Aug 20 08:39:32 2011
@@ -94,11 +94,11 @@
      *        the newly parsed ones
      * @return A set with string paths for included directories
      */
-    public List< String > getIncludes( boolean refresh )
+    public List< String > getMacroIncludes( boolean refresh )
     {
         if( includes_ == null || refresh ) {
             includes_ = new ArrayList< String >(
-                ResourceUtils.getContainers( file_ ) );
+                ResourceUtils.getMacroIncludes( file_ ) );
         }
 
         return includes_;

Modified: 
trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/builder/WesnothProjectBuilder.java
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/builder/WesnothProjectBuilder.java?rev=50862&r1=50861&r2=50862&view=diff
==============================================================================
--- 
trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/builder/WesnothProjectBuilder.java
 (original)
+++ 
trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/builder/WesnothProjectBuilder.java
 Sat Aug 20 08:39:32 2011
@@ -105,10 +105,6 @@
         }
         monitor.worked( 5 );
 
-        monitor.subTask( "Creating the project list ..." );
-        projectCache_.getDependencyList( ).createDependencyList( false );
-        monitor.worked( 10 );
-
         // create the temporary directory used by the plugin if not created
         monitor.subTask( Messages.WesnothProjectBuilder_6 );
         WorkspaceUtils.getTemporaryFolder( );
@@ -167,7 +163,9 @@
         PreprocessorUtils.getInstance( ).clearTimestampsForPath(
             project_.getLocation( ).toOSString( ) );
 
+        // force creating the dependency list
         projectCache_.getDependencyList( ).createDependencyList( true );
+        System.out.println( projectCache_.getDependencyList( ) );
         boolean foundCfg = false;
 
         DependencyListNode node = null;
@@ -202,6 +200,10 @@
     protected boolean incrementalBuild( IResourceDelta delta,
         IProgressMonitor monitor ) throws CoreException
     {
+        // Create the dependency list only if it's not created.
+        projectCache_.getDependencyList( ).createDependencyList( false );
+        monitor.worked( 10 );
+
         boolean foundCfg = false;
 
         // TODO: unprocessed files should be reprocessed on each build
@@ -319,7 +321,7 @@
             monitor.subTask( Messages.WesnothProjectBuilder_8 );
             Map< String, String > properties = new HashMap< String, String >( 
);
             properties.put( "wesnoth.user.dir", paths.getUserDir( ) ); 
//$NON-NLS-1$
-            Logger.getInstance( ).log( "Ant result:" ); //$NON-NLS-1$
+            Logger.getInstance( ).logTool( "Ant result:" ); //$NON-NLS-1$
 
             String result = AntUtils.runAnt( buildXMLPath, properties, true );
             Logger.getInstance( ).logTool( result );

Modified: 
trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/utils/ResourceUtils.java
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/utils/ResourceUtils.java?rev=50862&r1=50861&r2=50862&view=diff
==============================================================================
--- trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/utils/ResourceUtils.java 
(original)
+++ trunk/utils/umc_dev/org.wesnoth/src/org/wesnoth/utils/ResourceUtils.java 
Sat Aug 20 08:39:32 2011
@@ -666,14 +666,13 @@
     }
 
     /**
-     * Gets the set of included containers in this file
-     * as a macro call
+     * Gets the set of included files or folders from this file
      * 
      * @param file
      *        The file to get the containers from
      * @return A set of containers represented by their Path as string
      */
-    public static Set< String > getContainers( IFile file )
+    public static Set< String > getMacroIncludes( IFile file )
     {
         IProject project = file.getProject( );
         WMLRoot root = WMLUtils.getWMLRoot( file );
@@ -695,18 +694,16 @@
         }
 
         // now check what macros are really an inclusion macro
-        Set< String > containersToAdd = new LinkedHashSet< String >( );
+        Set< String > includesToAdd = new LinkedHashSet< String >( );
 
         for( WMLMacroCall macro: macroCalls ) {
             String text = WMLUtils.toString( macro );
             /**
-             * To include a folder the macro should be the following
+             * To include a folder/file the macro should be the following
              * forms:
              * - {campaigns/... }
              * - {~add-ons/... }
-             * 
              */
-            // TODO: check for including a specific config file?
             if( ! ( text.startsWith( "{campaigns" ) ) && //$NON-NLS-1$
                 ! ( text.equals( "{~add-ons" ) ) ) {
                 continue;
@@ -722,12 +719,12 @@
                 String subString = text.replace( "}", "" )
                     .replaceFirst( "\\{campaigns/", "" )
                     .replaceFirst( "\\{~add-ons/", "" );
-                containersToAdd.add( subString.substring( subString
+                includesToAdd.add( subString.substring( subString
                     .indexOf( '/' ) ) );
             }
         }
 
-        return containersToAdd;
+        return includesToAdd;
     }
 
     /**


_______________________________________________
Wesnoth-commits mailing list
[email protected]
https://mail.gna.org/listinfo/wesnoth-commits

Reply via email to