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;
19 import org.eclipse.core.resources.IContainer;
20 import org.eclipse.core.resources.IFile;
21 import org.eclipse.core.resources.IResource;
22 import org.eclipse.core.resources.IResourceProxy;
23 import org.eclipse.core.resources.IResourceProxyVisitor;
24 import org.eclipse.core.runtime.CoreException;
25 import org.eclipse.core.runtime.IPath;
27 public class BatchImageBuilder extends AbstractImageBuilder {
29 protected BatchImageBuilder(PHPBuilder javaBuilder) {
31 this.nameEnvironment.isIncrementalBuild = false;
36 System.out.println("FULL build"); //$NON-NLS-1$
39 // notifier.subTask(Util.bind("build.cleaningOutput")); //$NON-NLS-1$
40 // JavaModelManager.getJavaModelManager().deltaProcessor.addForRefresh(javaBuilder.javaProject);
41 // PHPBuilder.removeProblemsAndTasksFor(javaBuilder.currentProject);
42 // cleanOutputFolders();
43 notifier.updateProgressDelta(0.1f);
45 notifier.subTask(Util.bind("build.analyzingSources")); //$NON-NLS-1$
46 ArrayList sourceFiles = new ArrayList(33);
47 addAllSourceFiles(sourceFiles);
48 notifier.updateProgressDelta(0.15f);
50 if (sourceFiles.size() > 0) {
51 SourceFile[] allSourceFiles = new SourceFile[sourceFiles.size()];
52 sourceFiles.toArray(allSourceFiles);
54 notifier.setProgressPerCompilationUnit(0.75f / allSourceFiles.length);
55 workQueue.addAll(allSourceFiles);
56 compile(allSourceFiles);
59 if (javaBuilder.javaProject.hasCycleMarker())
60 javaBuilder.mustPropagateStructuralChanges();
61 } catch (CoreException e) {
62 throw internalException(e);
68 protected void addAllSourceFiles(final ArrayList sourceFiles) throws CoreException {
69 for (int i = 0, l = sourceLocations.length; i < l; i++) {
70 final ClasspathMultiDirectory sourceLocation = sourceLocations[i];
71 final char[][] exclusionPatterns = sourceLocation.exclusionPatterns;
72 final boolean isAlsoProject = sourceLocation.sourceFolder.equals(javaBuilder.currentProject);
73 sourceLocation.sourceFolder.accept(
74 new IResourceProxyVisitor() {
75 public boolean visit(IResourceProxy proxy) throws CoreException {
76 IResource resource = null;
77 if (exclusionPatterns != null) {
78 resource = proxy.requestResource();
79 if (Util.isExcluded(resource, exclusionPatterns)) return false;
81 switch(proxy.getType()) {
83 if (Util.isJavaFileName(proxy.getName())) {
85 resource = proxy.requestResource();
86 sourceFiles.add(new SourceFile((IFile) resource, sourceLocation, encoding));
89 case IResource.FOLDER :
90 if (isAlsoProject && isExcludedFromProject(proxy.requestFullPath())) return false;
97 notifier.checkCancel();
101 protected void cleanOutputFolders() throws CoreException {
102 boolean deleteAll = PHPCore.CLEAN.equals(
103 javaBuilder.javaProject.getOption(PHPCore.CORE_JAVA_BUILD_CLEAN_OUTPUT_FOLDER, true));
105 ArrayList visited = new ArrayList(sourceLocations.length);
106 for (int i = 0, l = sourceLocations.length; i < l; i++) {
107 notifier.subTask(Util.bind("build.cleaningOutput")); //$NON-NLS-1$
108 ClasspathMultiDirectory sourceLocation = sourceLocations[i];
109 if (sourceLocation.hasIndependentOutputFolder) {
110 IContainer outputFolder = sourceLocation.binaryFolder;
111 if (!visited.contains(outputFolder)) {
112 visited.add(outputFolder);
113 IResource[] members = outputFolder.members();
114 for (int j = 0, m = members.length; j < m; j++)
115 members[j].delete(IResource.FORCE, null);
117 notifier.checkCancel();
118 copyExtraResourcesBack(sourceLocation, deleteAll);
120 boolean isOutputFolder = sourceLocation.sourceFolder.equals(sourceLocation.binaryFolder);
121 final char[][] exclusionPatterns =
123 ? sourceLocation.exclusionPatterns
124 : null; // ignore exclusionPatterns if output folder == another source folder... not this one
125 sourceLocation.binaryFolder.accept(
126 new IResourceProxyVisitor() {
127 public boolean visit(IResourceProxy proxy) throws CoreException {
128 IResource resource = null;
129 if (exclusionPatterns != null) {
130 resource = proxy.requestResource();
131 if (Util.isExcluded(resource, exclusionPatterns)) return false;
133 if (proxy.getType() == IResource.FILE) {
134 // if (Util.isClassFileName(proxy.getName())) {
135 // if (resource == null)
136 // resource = proxy.requestResource();
137 // resource.delete(IResource.FORCE, null);
141 notifier.checkCancel();
147 if (!isOutputFolder) {
148 notifier.checkCancel();
149 copyPackages(sourceLocation);
152 notifier.checkCancel();
155 for (int i = 0, l = sourceLocations.length; i < l; i++) {
156 ClasspathMultiDirectory sourceLocation = sourceLocations[i];
157 if (sourceLocation.hasIndependentOutputFolder)
158 copyExtraResourcesBack(sourceLocation, deleteAll);
159 else if (!sourceLocation.sourceFolder.equals(sourceLocation.binaryFolder))
160 copyPackages(sourceLocation); // output folder is different from source folder
161 notifier.checkCancel();
166 protected void copyExtraResourcesBack(ClasspathMultiDirectory sourceLocation, final boolean deletedAll) throws CoreException {
167 // When, if ever, does a builder need to copy resources files (not .java or .class) into the output folder?
168 // If we wipe the output folder at the beginning of the build then all 'extra' resources must be copied to the output folder.
170 notifier.subTask(Util.bind("build.copyingResources")); //$NON-NLS-1$
171 final int segmentCount = sourceLocation.sourceFolder.getFullPath().segmentCount();
172 final char[][] exclusionPatterns = sourceLocation.exclusionPatterns;
173 final IContainer outputFolder = sourceLocation.binaryFolder;
174 final boolean isAlsoProject = sourceLocation.sourceFolder.equals(javaBuilder.currentProject);
175 sourceLocation.sourceFolder.accept(
176 new IResourceProxyVisitor() {
177 public boolean visit(IResourceProxy proxy) throws CoreException {
178 IResource resource = null;
179 switch(proxy.getType()) {
180 case IResource.FILE :
181 if (Util.isJavaFileName(proxy.getName())) return false;// || Util.isClassFileName(proxy.getName())) return false;
183 resource = proxy.requestResource();
184 if (javaBuilder.filterExtraResource(resource)) return false;
185 if (exclusionPatterns != null && Util.isExcluded(resource, exclusionPatterns))
188 IPath partialPath = resource.getFullPath().removeFirstSegments(segmentCount);
189 IResource copiedResource = outputFolder.getFile(partialPath);
190 if (copiedResource.exists()) {
192 createErrorFor(resource, Util.bind("build.duplicateResource")); //$NON-NLS-1$
195 copiedResource.delete(IResource.FORCE, null); // last one wins
197 resource.copy(copiedResource.getFullPath(), IResource.FORCE, null);
198 copiedResource.setDerived(true);
200 case IResource.FOLDER :
201 resource = proxy.requestResource();
202 if (javaBuilder.filterExtraResource(resource)) return false;
203 if (exclusionPatterns != null && Util.isExcluded(resource, exclusionPatterns))
206 IPath folderPath = resource.getFullPath();
207 if (isAlsoProject && isExcludedFromProject(folderPath)) return false; // the sourceFolder == project
208 createFolder(folderPath.removeFirstSegments(segmentCount), outputFolder);
217 protected void copyPackages(ClasspathMultiDirectory sourceLocation) throws CoreException {
218 final int segmentCount = sourceLocation.sourceFolder.getFullPath().segmentCount();
219 final char[][] exclusionPatterns = sourceLocation.exclusionPatterns;
220 final IContainer outputFolder = sourceLocation.binaryFolder;
221 final boolean isAlsoProject = sourceLocation.sourceFolder.equals(javaBuilder.currentProject);
222 sourceLocation.sourceFolder.accept(
223 new IResourceProxyVisitor() {
224 public boolean visit(IResourceProxy proxy) throws CoreException {
225 switch(proxy.getType()) {
226 case IResource.FILE :
228 case IResource.FOLDER :
229 IResource resource = proxy.requestResource();
230 if (javaBuilder.filterExtraResource(resource)) return false;
231 if (exclusionPatterns != null && Util.isExcluded(resource, exclusionPatterns))
234 IPath folderPath = resource.getFullPath();
235 if (isAlsoProject && isExcludedFromProject(folderPath)) return false; // the sourceFolder == project
236 createFolder(folderPath.removeFirstSegments(segmentCount), outputFolder);
245 public String toString() {
246 return "batch image builder for:\n\tnew state: " + newState; //$NON-NLS-1$