eclipse plugin: Refactor part of the addNode method...
...into its own method. Also add some todos and comments
This commit is contained in:
parent
95ec2fd1ad
commit
6de5e6c1e1
3 changed files with 78 additions and 53 deletions
|
@ -11,6 +11,7 @@ package org.wesnoth.builder;
|
|||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
|
@ -54,10 +55,12 @@ public class DependencyTreeBuilder implements Serializable
|
|||
private ProjectDependencyNode previous_;
|
||||
|
||||
protected Map< String, ProjectDependencyNode > tree_;
|
||||
protected List< String > directories_;
|
||||
|
||||
public DependencyTreeBuilder( IProject project )
|
||||
{
|
||||
tree_ = new HashMap<String, ProjectDependencyNode>();
|
||||
directories_ = new ArrayList<String>();
|
||||
|
||||
parent_ = previous_ = null;
|
||||
|
||||
|
@ -74,8 +77,8 @@ public class DependencyTreeBuilder implements Serializable
|
|||
public void createDependencyTree( boolean force )
|
||||
{
|
||||
if ( isCreated_ && !force ) {
|
||||
Logger.getInstance( ).log( "Depedency tree for project " +
|
||||
project_.getName( ) + " already built. Skipping it." );
|
||||
Logger.getInstance( ).log( " Skipping depedency tree for project " +
|
||||
project_.getName( ) );
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -100,57 +103,7 @@ public class DependencyTreeBuilder implements Serializable
|
|||
// add main.cfg to tree
|
||||
internal_addNode( (IFile) main_cfg );
|
||||
|
||||
WMLRoot root = ResourceUtils.getWMLRoot( ( IFile ) main_cfg );
|
||||
// nothing to do
|
||||
if ( root == null )
|
||||
continue;
|
||||
|
||||
EList<WMLMacroCall> macroCalls = new BasicEList<WMLMacroCall>( );
|
||||
|
||||
// iterate to find macro calls
|
||||
TreeIterator<EObject> treeItor = root.eAllContents( );
|
||||
|
||||
while ( treeItor.hasNext( ) ) {
|
||||
EObject object = treeItor.next( );
|
||||
if ( object instanceof WMLMacroCall ){
|
||||
macroCalls.add( (WMLMacroCall) object );
|
||||
}
|
||||
}
|
||||
|
||||
// now check what macros are really an inclusion macro
|
||||
Set<String> containersToAdd = new LinkedHashSet<String>( );
|
||||
|
||||
for ( WMLMacroCall macro : macroCalls ) {
|
||||
String name = macro.getName( );
|
||||
|
||||
/**
|
||||
* To include a folder the macro should be the following
|
||||
* forms:
|
||||
* - {campaigns/... }
|
||||
* - {~add-ons/... }
|
||||
*
|
||||
*/
|
||||
//TODO: check for including a specific config file?
|
||||
|
||||
if ( ( name.equals( "campaigns" ) || //$NON-NLS-1$
|
||||
name.equals( "add-ons" ) ) && //$NON-NLS-1$
|
||||
// the call should contain just string values
|
||||
macro.getExtraMacros( ).isEmpty( ) &&
|
||||
macro.getParams( ).size( ) > 1 &&
|
||||
macro.getParams( ).get( 0 ).equals( "/" ) ) //$NON-NLS-1$
|
||||
{
|
||||
// check if the macro includes directories local
|
||||
// to this project
|
||||
String projectPath = project_.getLocation( ).toOSString( );
|
||||
|
||||
if ( projectPath.contains( macro.getParams( ).get( 1 ) ) ) {
|
||||
containersToAdd.add(
|
||||
ListUtils.concatenateList(
|
||||
macro.getParams( ).subList( 2, macro.getParams( ).size( ) ), "" ) ); //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Set<String> containersToAdd = getContainers( (IFile) main_cfg );
|
||||
// push the containers in the queue
|
||||
for ( String containerPath : containersToAdd ) {
|
||||
containers.offer( project_.getFolder( containerPath ) );
|
||||
|
@ -193,6 +146,63 @@ public class DependencyTreeBuilder implements Serializable
|
|||
System.out.println( toString( ) );
|
||||
}
|
||||
|
||||
public static Set<String> getContainers( IFile file )
|
||||
{
|
||||
IProject project = file.getProject( );
|
||||
WMLRoot root = ResourceUtils.getWMLRoot( file );
|
||||
// nothing to do
|
||||
if ( root == null )
|
||||
return new LinkedHashSet<String> ( 0 );
|
||||
|
||||
EList<WMLMacroCall> macroCalls = new BasicEList<WMLMacroCall>( );
|
||||
|
||||
// iterate to find macro calls
|
||||
TreeIterator<EObject> treeItor = root.eAllContents( );
|
||||
|
||||
while ( treeItor.hasNext( ) ) {
|
||||
EObject object = treeItor.next( );
|
||||
if ( object instanceof WMLMacroCall ){
|
||||
macroCalls.add( (WMLMacroCall) object );
|
||||
}
|
||||
}
|
||||
|
||||
// now check what macros are really an inclusion macro
|
||||
Set<String> containersToAdd = new LinkedHashSet<String>( );
|
||||
|
||||
for ( WMLMacroCall macro : macroCalls ) {
|
||||
String name = macro.getName( );
|
||||
|
||||
/**
|
||||
* To include a folder the macro should be the following
|
||||
* forms:
|
||||
* - {campaigns/... }
|
||||
* - {~add-ons/... }
|
||||
*
|
||||
*/
|
||||
//TODO: check for including a specific config file?
|
||||
|
||||
if ( ( name.equals( "campaigns" ) || //$NON-NLS-1$
|
||||
name.equals( "add-ons" ) ) && //$NON-NLS-1$
|
||||
// the call should contain just string values
|
||||
macro.getExtraMacros( ).isEmpty( ) &&
|
||||
macro.getParams( ).size( ) > 1 &&
|
||||
macro.getParams( ).get( 0 ).equals( "/" ) ) //$NON-NLS-1$
|
||||
{
|
||||
// check if the macro includes directories local
|
||||
// to this project
|
||||
String projectPath = project.getLocation( ).toOSString( );
|
||||
|
||||
if ( projectPath.contains( macro.getParams( ).get( 1 ) ) ) {
|
||||
containersToAdd.add(
|
||||
ListUtils.concatenateList(
|
||||
macro.getParams( ).subList( 2, macro.getParams( ).size( ) ), "" ) ); //$NON-NLS-1$
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return containersToAdd;
|
||||
}
|
||||
|
||||
public ProjectDependencyNode addNode( IFile file )
|
||||
{
|
||||
// save current nodes
|
||||
|
|
|
@ -9,6 +9,8 @@
|
|||
package org.wesnoth.builder;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
|
@ -47,6 +49,7 @@ public class ProjectDependencyNode implements Serializable
|
|||
|
||||
protected transient IFile file_;
|
||||
protected String fileName_;
|
||||
protected List<String> includes_;
|
||||
|
||||
private int index_;
|
||||
|
||||
|
@ -54,6 +57,8 @@ public class ProjectDependencyNode implements Serializable
|
|||
{
|
||||
previous_ = next_ = parent_ = son_ = null;
|
||||
|
||||
includes_ = new ArrayList<String>();
|
||||
|
||||
file_ = file;
|
||||
fileName_ = file.getProjectRelativePath( ).toString( );
|
||||
setIndex( index );
|
||||
|
|
|
@ -44,6 +44,16 @@ import org.wesnoth.utils.WMLTools;
|
|||
import org.wesnoth.utils.WorkspaceUtils;
|
||||
import org.wesnoth.wml.core.ConfigFile;
|
||||
|
||||
/**
|
||||
* The builder does the following steps in order to create and ensure
|
||||
* a correct PDT (Project Dependency Tree)
|
||||
*
|
||||
* 1) remove REMOVED files from the PDT
|
||||
* 2) parse ADDED or CHANGED files, to check if new directory/file includes
|
||||
* happened
|
||||
* 3) add new dependencies to the tree
|
||||
*/
|
||||
//TODO: what happens if a file changes the order of the includes?
|
||||
public class WesnothProjectBuilder extends IncrementalProjectBuilder
|
||||
{
|
||||
private ProjectCache projectCache_;
|
||||
|
|
Loading…
Add table
Reference in a new issue