1 /*******************************************************************************
2 * Copyright (c) 2000, 2003 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Common Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/cpl-v10.html
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
11 package net.sourceforge.phpdt.internal.core.builder;
13 import java.util.ArrayList;
15 import net.sourceforge.phpdt.internal.core.JavaModelManager;
16 import net.sourceforge.phpdt.internal.core.Util;
17 import net.sourceforge.phpeclipse.PHPCore;
18 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
19 import net.sourceforge.phpeclipse.builder.IdentifierIndexManager;
21 import org.eclipse.core.resources.IContainer;
22 import org.eclipse.core.resources.IFile;
23 import org.eclipse.core.resources.IResource;
24 import org.eclipse.core.resources.IResourceProxy;
25 import org.eclipse.core.resources.IResourceProxyVisitor;
26 import org.eclipse.core.runtime.CoreException;
27 import org.eclipse.core.runtime.IPath;
29 public class BatchImageBuilder extends AbstractImageBuilder {
31 protected BatchImageBuilder(PHPBuilder javaBuilder) {
33 this.nameEnvironment.isIncrementalBuild = false;
38 System.out.println("FULL build"); //$NON-NLS-1$
41 notifier.subTask(Util.bind("build.cleaningOutput")); //$NON-NLS-1$
42 JavaModelManager.getJavaModelManager().deltaProcessor.addForRefresh(javaBuilder.javaProject);
43 PHPBuilder.removeProblemsAndTasksFor(javaBuilder.currentProject);
44 // cleanOutputFolders();
45 notifier.updateProgressDelta(0.1f);
47 notifier.subTask(Util.bind("build.analyzingSources")); //$NON-NLS-1$
48 ArrayList sourceFiles = new ArrayList(33);
49 addAllSourceFiles(sourceFiles);
50 notifier.updateProgressDelta(0.15f);
52 if (sourceFiles.size() > 0) {
53 SourceFile[] allSourceFiles = new SourceFile[sourceFiles.size()];
54 sourceFiles.toArray(allSourceFiles);
56 notifier.setProgressPerCompilationUnit(0.75f / allSourceFiles.length);
57 workQueue.addAll(allSourceFiles);
58 compile(allSourceFiles);
61 if (javaBuilder.javaProject.hasCycleMarker())
62 javaBuilder.mustPropagateStructuralChanges();
63 } catch (CoreException e) {
64 throw internalException(e);
70 protected void addAllSourceFiles(final ArrayList sourceFiles) throws CoreException {
72 for (int i = 0, l = sourceLocations.length; i < l; i++) {
73 final ClasspathMultiDirectory sourceLocation = sourceLocations[i];
74 final char[][] exclusionPatterns = sourceLocation.exclusionPatterns;
75 final boolean isAlsoProject = sourceLocation.sourceFolder.equals(javaBuilder.currentProject);
76 sourceLocation.sourceFolder.accept(
77 new IResourceProxyVisitor() {
78 public boolean visit(IResourceProxy proxy) throws CoreException {
79 IResource resource = null;
80 if (exclusionPatterns != null) {
81 resource = proxy.requestResource();
82 if (Util.isExcluded(resource, exclusionPatterns)) return false;
84 switch(proxy.getType()) {
86 if (Util.isJavaFileName(proxy.getName())) {
88 resource = proxy.requestResource();
89 sourceFiles.add(new SourceFile((IFile) resource, sourceLocation, encoding));
92 case IResource.FOLDER :
93 if (isAlsoProject && isExcludedFromProject(proxy.requestFullPath())) return false;
100 notifier.checkCancel();
104 protected void cleanOutputFolders() throws CoreException {
105 boolean deleteAll = PHPCore.CLEAN.equals(
106 javaBuilder.javaProject.getOption(PHPCore.CORE_JAVA_BUILD_CLEAN_OUTPUT_FOLDER, true));
108 ArrayList visited = new ArrayList(sourceLocations.length);
109 for (int i = 0, l = sourceLocations.length; i < l; i++) {
110 notifier.subTask(Util.bind("build.cleaningOutput")); //$NON-NLS-1$
111 ClasspathMultiDirectory sourceLocation = sourceLocations[i];
112 if (sourceLocation.hasIndependentOutputFolder) {
113 IContainer outputFolder = sourceLocation.binaryFolder;
114 if (!visited.contains(outputFolder)) {
115 visited.add(outputFolder);
116 IResource[] members = outputFolder.members();
117 for (int j = 0, m = members.length; j < m; j++)
118 members[j].delete(IResource.FORCE, null);
120 notifier.checkCancel();
121 copyExtraResourcesBack(sourceLocation, deleteAll);
123 boolean isOutputFolder = sourceLocation.sourceFolder.equals(sourceLocation.binaryFolder);
124 final char[][] exclusionPatterns =
126 ? sourceLocation.exclusionPatterns
127 : null; // ignore exclusionPatterns if output folder == another source folder... not this one
128 sourceLocation.binaryFolder.accept(
129 new IResourceProxyVisitor() {
130 public boolean visit(IResourceProxy proxy) throws CoreException {
131 IResource resource = null;
132 if (exclusionPatterns != null) {
133 resource = proxy.requestResource();
134 if (Util.isExcluded(resource, exclusionPatterns)) return false;
136 if (proxy.getType() == IResource.FILE) {
137 // if (Util.isClassFileName(proxy.getName())) {
138 // if (resource == null)
139 // resource = proxy.requestResource();
140 // resource.delete(IResource.FORCE, null);
144 notifier.checkCancel();
150 if (!isOutputFolder) {
151 notifier.checkCancel();
152 copyPackages(sourceLocation);
155 notifier.checkCancel();
158 for (int i = 0, l = sourceLocations.length; i < l; i++) {
159 ClasspathMultiDirectory sourceLocation = sourceLocations[i];
160 if (sourceLocation.hasIndependentOutputFolder)
161 copyExtraResourcesBack(sourceLocation, deleteAll);
162 else if (!sourceLocation.sourceFolder.equals(sourceLocation.binaryFolder))
163 copyPackages(sourceLocation); // output folder is different from source folder
164 notifier.checkCancel();
169 protected void copyExtraResourcesBack(ClasspathMultiDirectory sourceLocation, final boolean deletedAll) throws CoreException {
170 // When, if ever, does a builder need to copy resources files (not .java or .class) into the output folder?
171 // If we wipe the output folder at the beginning of the build then all 'extra' resources must be copied to the output folder.
173 notifier.subTask(Util.bind("build.copyingResources")); //$NON-NLS-1$
174 final int segmentCount = sourceLocation.sourceFolder.getFullPath().segmentCount();
175 final char[][] exclusionPatterns = sourceLocation.exclusionPatterns;
176 final IContainer outputFolder = sourceLocation.binaryFolder;
177 final boolean isAlsoProject = sourceLocation.sourceFolder.equals(javaBuilder.currentProject);
178 sourceLocation.sourceFolder.accept(
179 new IResourceProxyVisitor() {
180 public boolean visit(IResourceProxy proxy) throws CoreException {
181 IResource resource = null;
182 switch(proxy.getType()) {
183 case IResource.FILE :
184 if (Util.isJavaFileName(proxy.getName())) return false;// || Util.isClassFileName(proxy.getName())) return false;
186 resource = proxy.requestResource();
187 if (javaBuilder.filterExtraResource(resource)) return false;
188 if (exclusionPatterns != null && Util.isExcluded(resource, exclusionPatterns))
191 IPath partialPath = resource.getFullPath().removeFirstSegments(segmentCount);
192 IResource copiedResource = outputFolder.getFile(partialPath);
193 if (copiedResource.exists()) {
195 createErrorFor(resource, Util.bind("build.duplicateResource")); //$NON-NLS-1$
198 copiedResource.delete(IResource.FORCE, null); // last one wins
200 resource.copy(copiedResource.getFullPath(), IResource.FORCE, null);
201 copiedResource.setDerived(true);
203 case IResource.FOLDER :
204 resource = proxy.requestResource();
205 if (javaBuilder.filterExtraResource(resource)) return false;
206 if (exclusionPatterns != null && Util.isExcluded(resource, exclusionPatterns))
209 IPath folderPath = resource.getFullPath();
210 if (isAlsoProject && isExcludedFromProject(folderPath)) return false; // the sourceFolder == project
211 createFolder(folderPath.removeFirstSegments(segmentCount), outputFolder);
220 protected void copyPackages(ClasspathMultiDirectory sourceLocation) throws CoreException {
221 final int segmentCount = sourceLocation.sourceFolder.getFullPath().segmentCount();
222 final char[][] exclusionPatterns = sourceLocation.exclusionPatterns;
223 final IContainer outputFolder = sourceLocation.binaryFolder;
224 final boolean isAlsoProject = sourceLocation.sourceFolder.equals(javaBuilder.currentProject);
225 sourceLocation.sourceFolder.accept(
226 new IResourceProxyVisitor() {
227 public boolean visit(IResourceProxy proxy) throws CoreException {
228 switch(proxy.getType()) {
229 case IResource.FILE :
231 case IResource.FOLDER :
232 IResource resource = proxy.requestResource();
233 if (javaBuilder.filterExtraResource(resource)) return false;
234 if (exclusionPatterns != null && Util.isExcluded(resource, exclusionPatterns))
237 IPath folderPath = resource.getFullPath();
238 if (isAlsoProject && isExcludedFromProject(folderPath)) return false; // the sourceFolder == project
239 createFolder(folderPath.removeFirstSegments(segmentCount), outputFolder);
248 public String toString() {
249 return "batch image builder for:\n\tnew state: " + newState; //$NON-NLS-1$