carbidev/com.nokia.tools.variant.confml.core_2.0.0.v20090225_01-11/src/com/nokia/tools/variant/confml/internal/core/project/GenericBuilder.java
changeset 0 30eb2d538f02
child 1 fe41c66bacc7
equal deleted inserted replaced
-1:000000000000 0:30eb2d538f02
       
     1 /*
       
     2  * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). 
       
     3  * All rights reserved.
       
     4  * This component and the accompanying materials are made available
       
     5  * under the terms of the License "Symbian Foundation License v1.0"
       
     6  * which accompanies this distribution, and is available
       
     7  * at the URL "http://www.symbianfoundation.org/legal/sfl-v10.html".
       
     8  * 
       
     9  * Initial Contributors:
       
    10  * Nokia Corporation - Initial contribution
       
    11  * 
       
    12  * Contributors:
       
    13  * 
       
    14  * Description: This file is part of com.nokia.tools.variant.confml.core component.
       
    15  */
       
    16 
       
    17 package com.nokia.tools.variant.confml.internal.core.project;
       
    18 
       
    19 import java.util.Map;
       
    20 
       
    21 import org.eclipse.core.resources.IProject;
       
    22 import org.eclipse.core.resources.IResource;
       
    23 import org.eclipse.core.resources.IResourceDelta;
       
    24 import org.eclipse.core.resources.IResourceDeltaVisitor;
       
    25 import org.eclipse.core.resources.IResourceVisitor;
       
    26 import org.eclipse.core.resources.IncrementalProjectBuilder;
       
    27 import org.eclipse.core.runtime.CoreException;
       
    28 import org.eclipse.core.runtime.IProgressMonitor;
       
    29 
       
    30 import com.nokia.tools.variant.confml.core.ConfMLCore;
       
    31 
       
    32 public class GenericBuilder extends IncrementalProjectBuilder {
       
    33 
       
    34 	class SimpleDeltaVisitor implements IResourceDeltaVisitor {
       
    35 		
       
    36 		IProgressMonitor monitor;
       
    37 		
       
    38 		public SimpleDeltaVisitor(IProgressMonitor monitor) {
       
    39 			this.monitor = monitor;
       
    40 		}
       
    41 		
       
    42 		/*
       
    43 		 * @see IResourceDeltaVisitor#visit(IResourceDelta)
       
    44 		 */
       
    45 		public boolean visit(IResourceDelta delta) throws CoreException {
       
    46 			IResource resource = delta.getResource();
       
    47 			if (this.monitor != null) {
       
    48 				this.monitor.subTask("Building" + resource.getProjectRelativePath());
       
    49 			}
       
    50 			
       
    51 			switch (delta.getKind()) {
       
    52 			case IResourceDelta.ADDED:
       
    53 				// handle added resource
       
    54 				buildResource(resource);
       
    55 				break;
       
    56 			case IResourceDelta.REMOVED:
       
    57 				// handle removed resource
       
    58 				break;
       
    59 			case IResourceDelta.CHANGED:
       
    60 				// handle changed resource
       
    61 				buildResource(resource);
       
    62 				break;
       
    63 			}
       
    64 			// return true to continue visiting children.
       
    65 			return true;
       
    66 		}
       
    67 	}
       
    68 
       
    69 	class SimpleResourceVisitor implements IResourceVisitor {
       
    70 		IProgressMonitor monitor;
       
    71 		
       
    72 		public SimpleResourceVisitor(IProgressMonitor monitor) {
       
    73 			this.monitor = monitor;
       
    74 		}
       
    75 
       
    76 		/*
       
    77 		 * @see IResourceVisitor#visit(IResource)
       
    78 		 */
       
    79 		public boolean visit(IResource resource) {
       
    80 			if (monitor != null) {
       
    81 				monitor.subTask("Building "+resource.getProjectRelativePath());
       
    82 			}
       
    83 			
       
    84 			try {
       
    85 				buildResource(resource);
       
    86 			} catch (CoreException e) {
       
    87 				ConfMLCore.getDefault().getLog().log(e.getStatus());
       
    88 				return false;
       
    89 			}
       
    90 			// return true to continue visiting children.
       
    91 			return true;
       
    92 		}
       
    93 	}
       
    94 
       
    95 	/*
       
    96 	 * @see org.eclipse.core.internal.events.InternalBuilder#build(int, Map,
       
    97 	 * IProgressMonitor)
       
    98 	 */
       
    99 	@SuppressWarnings("unchecked")
       
   100 	protected IProject[] build(int kind, Map args, IProgressMonitor monitor)
       
   101 			throws CoreException {
       
   102 		if (kind == FULL_BUILD) {
       
   103 			fullBuild(monitor);
       
   104 		} else {
       
   105 			IResourceDelta delta = getDelta(getProject());
       
   106 			if (delta == null) {
       
   107 				fullBuild(monitor);
       
   108 			} else {
       
   109 				incrementalBuild(delta, monitor);
       
   110 			}
       
   111 		}
       
   112 		return null;
       
   113 	}
       
   114 
       
   115 	protected void buildResource(IResource resource) throws CoreException {
       
   116 		deleteMarkers(resource);
       
   117 	}
       
   118 
       
   119 	protected void deleteMarkers(IResource resource) throws CoreException{
       
   120 	}
       
   121 
       
   122 	protected void fullBuild(final IProgressMonitor monitor)
       
   123 			throws CoreException {
       
   124 		monitor.beginTask("Full Build", 100);
       
   125 		getProject().accept(new SimpleResourceVisitor(monitor));
       
   126 		monitor.done();
       
   127 	}
       
   128 
       
   129 	protected void incrementalBuild(IResourceDelta delta,
       
   130 			IProgressMonitor monitor) throws CoreException {
       
   131 		monitor.beginTask("Incremental Build", 100);
       
   132 		delta.accept(new SimpleDeltaVisitor(monitor));
       
   133 		monitor.done();
       
   134 	}
       
   135 }