Lines 17-26
Link Here
|
17 |
import java.util.*; |
17 |
import java.util.*; |
18 |
import javax.xml.parsers.*; |
18 |
import javax.xml.parsers.*; |
19 |
import org.eclipse.ant.core.*; |
19 |
import org.eclipse.ant.core.*; |
20 |
import org.eclipse.core.resources.IFile; |
20 |
import org.eclipse.core.resources.*; |
21 |
import org.eclipse.core.runtime.*; |
21 |
import org.eclipse.core.runtime.*; |
22 |
import org.eclipse.core.runtime.jobs.Job; |
22 |
import org.eclipse.core.runtime.jobs.Job; |
23 |
import org.eclipse.jdt.core.JavaCore; |
23 |
import org.eclipse.jdt.core.*; |
24 |
import org.eclipse.jdt.launching.JavaRuntime; |
24 |
import org.eclipse.jdt.launching.JavaRuntime; |
25 |
import org.eclipse.jdt.launching.environments.IExecutionEnvironment; |
25 |
import org.eclipse.jdt.launching.environments.IExecutionEnvironment; |
26 |
import org.eclipse.jdt.launching.environments.IExecutionEnvironmentsManager; |
26 |
import org.eclipse.jdt.launching.environments.IExecutionEnvironmentsManager; |
Lines 33-38
Link Here
|
33 |
import org.eclipse.pde.internal.build.site.QualifierReplacer; |
33 |
import org.eclipse.pde.internal.build.site.QualifierReplacer; |
34 |
import org.eclipse.pde.internal.core.*; |
34 |
import org.eclipse.pde.internal.core.*; |
35 |
import org.eclipse.pde.internal.core.build.WorkspaceBuildModel; |
35 |
import org.eclipse.pde.internal.core.build.WorkspaceBuildModel; |
|
|
36 |
import org.eclipse.pde.internal.core.builders.PDEMarkerFactory; |
36 |
import org.eclipse.pde.internal.core.feature.FeatureChild; |
37 |
import org.eclipse.pde.internal.core.feature.FeatureChild; |
37 |
import org.eclipse.pde.internal.core.ifeature.*; |
38 |
import org.eclipse.pde.internal.core.ifeature.*; |
38 |
import org.eclipse.pde.internal.core.util.CoreUtility; |
39 |
import org.eclipse.pde.internal.core.util.CoreUtility; |
Lines 47-52
Link Here
|
47 |
private String fDevProperties; |
48 |
private String fDevProperties; |
48 |
private static boolean fHasErrors; |
49 |
private static boolean fHasErrors; |
49 |
protected HashMap fAntBuildProperties; |
50 |
protected HashMap fAntBuildProperties; |
|
|
51 |
protected IProject[] fWorkspaceProjects; |
50 |
|
52 |
|
51 |
protected State fStateCopy; |
53 |
protected State fStateCopy; |
52 |
|
54 |
|
Lines 76-82
Link Here
|
76 |
if (configurations == null) |
78 |
if (configurations == null) |
77 |
configurations = new String[][] {null}; |
79 |
configurations = new String[][] {null}; |
78 |
|
80 |
|
79 |
monitor.beginTask("", configurations.length * fInfo.items.length * 11); //$NON-NLS-1$ |
81 |
monitor.beginTask("", (configurations.length * fInfo.items.length * 11) + 1); //$NON-NLS-1$ |
|
|
82 |
testBuildWorkspaceBeforeExport(new SubProgressMonitor(monitor, 1)); |
83 |
// TODO Proper progress for the build! |
80 |
for (int i = 0; i < configurations.length; i++) { |
84 |
for (int i = 0; i < configurations.length; i++) { |
81 |
for (int j = 0; j < fInfo.items.length; j++) { |
85 |
for (int j = 0; j < fInfo.items.length; j++) { |
82 |
if (monitor.isCanceled()) |
86 |
if (monitor.isCanceled()) |
Lines 95-100
Link Here
|
95 |
} |
99 |
} |
96 |
} catch (InvocationTargetException e) { |
100 |
} catch (InvocationTargetException e) { |
97 |
return new Status(IStatus.ERROR, PDECore.PLUGIN_ID, PDECoreMessages.FeatureBasedExportOperation_ProblemDuringExport, e.getCause() != null ? e.getCause() : e); |
101 |
return new Status(IStatus.ERROR, PDECore.PLUGIN_ID, PDECoreMessages.FeatureBasedExportOperation_ProblemDuringExport, e.getCause() != null ? e.getCause() : e); |
|
|
102 |
} catch (CoreException e) { |
103 |
return new Status(IStatus.ERROR, PDECore.PLUGIN_ID, PDECoreMessages.FeatureBasedExportOperation_ProblemDuringExport, e.getCause() != null ? e.getCause() : e); |
98 |
} finally { |
104 |
} finally { |
99 |
monitor.done(); |
105 |
monitor.done(); |
100 |
} |
106 |
} |
Lines 205-212
Link Here
|
205 |
|
211 |
|
206 |
protected void doExport(String featureID, String version, String featureLocation, String os, String ws, String arch, IProgressMonitor monitor) throws CoreException, InvocationTargetException { |
212 |
protected void doExport(String featureID, String version, String featureLocation, String os, String ws, String arch, IProgressMonitor monitor) throws CoreException, InvocationTargetException { |
207 |
fHasErrors = false; |
213 |
fHasErrors = false; |
208 |
monitor.beginTask("", 9); //$NON-NLS-1$ |
214 |
monitor.beginTask("", 10); //$NON-NLS-1$ |
209 |
monitor.setTaskName(PDECoreMessages.FeatureExportJob_taskName); |
215 |
monitor.setTaskName(PDECoreMessages.FeatureExportJob_taskName); |
|
|
216 |
|
210 |
try { |
217 |
try { |
211 |
HashMap properties = createAntBuildProperties(os, ws, arch); |
218 |
HashMap properties = createAntBuildProperties(os, ws, arch); |
212 |
BuildScriptGenerator generator = new BuildScriptGenerator(); |
219 |
BuildScriptGenerator generator = new BuildScriptGenerator(); |
Lines 505-511
Link Here
|
505 |
generator.setArchivesFormat(format); |
512 |
generator.setArchivesFormat(format); |
506 |
generator.setPDEState(getState(os, ws, arch)); |
513 |
generator.setPDEState(getState(os, ws, arch)); |
507 |
generator.setNextId(TargetPlatformHelper.getPDEState().getNextId()); |
514 |
generator.setNextId(TargetPlatformHelper.getPDEState().getNextId()); |
508 |
generator.setStateExtraData(TargetPlatformHelper.getBundleClasspaths(TargetPlatformHelper.getPDEState()), TargetPlatformHelper.getPatchMap(TargetPlatformHelper.getPDEState())); |
515 |
|
|
|
516 |
if (fInfo.useWorkspaceCompiledClasses) { |
517 |
generator.setUseWorkspaceBinaries(true); |
518 |
generator.setStateExtraData(TargetPlatformHelper.getBundleClasspaths(TargetPlatformHelper.getPDEState()), TargetPlatformHelper.getPatchMap(TargetPlatformHelper.getPDEState()), getWorkspacePluginOutputFolders()); |
519 |
} else { |
520 |
generator.setStateExtraData(TargetPlatformHelper.getBundleClasspaths(TargetPlatformHelper.getPDEState()), TargetPlatformHelper.getPatchMap(TargetPlatformHelper.getPDEState())); |
521 |
} |
522 |
|
509 |
AbstractScriptGenerator.setForceUpdateJar(false); |
523 |
AbstractScriptGenerator.setForceUpdateJar(false); |
510 |
AbstractScriptGenerator.setEmbeddedSource(fInfo.exportSource); |
524 |
AbstractScriptGenerator.setEmbeddedSource(fInfo.exportSource); |
511 |
|
525 |
|
Lines 732-735
Link Here
|
732 |
} |
746 |
} |
733 |
return false; |
747 |
return false; |
734 |
} |
748 |
} |
|
|
749 |
|
750 |
protected void testBuildWorkspaceBeforeExport(IProgressMonitor monitor) throws CoreException { |
751 |
try { |
752 |
monitor.beginTask("Compiling classes in workspace before export", 1); |
753 |
if (fInfo.useWorkspaceCompiledClasses) { |
754 |
IProject[] projects = getExportedWorkspaceProjects(); |
755 |
for (int i = 0; i < projects.length; i++) { |
756 |
projects[i].build(IncrementalProjectBuilder.INCREMENTAL_BUILD, monitor); |
757 |
} |
758 |
|
759 |
List errors = new ArrayList(); |
760 |
for (int i = 0; i < projects.length; i++) { |
761 |
IMarker[] markers = projects[i].findMarkers(IMarker.PROBLEM, true, IResource.DEPTH_INFINITE); |
762 |
if (markers.length > 0) { |
763 |
for (int j = 0; j < markers.length; j++) { |
764 |
Integer severity = (Integer) (markers[j].getAttribute(IMarker.SEVERITY)); |
765 |
if (severity != null && severity.intValue() >= IMarker.SEVERITY_ERROR) { |
766 |
if (markers[j].getType().equals(IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER) || markers[j].getType().equals(PDEMarkerFactory.MARKER_ID)) { |
767 |
errors.add(projects[i]); |
768 |
} |
769 |
} |
770 |
} |
771 |
} |
772 |
} |
773 |
|
774 |
if (!errors.isEmpty()) { |
775 |
// TODO Inform user of errors? |
776 |
PDECore.log(new Status(IStatus.ERROR, PDECore.PLUGIN_ID, "Build problems present in projects being exported.")); |
777 |
} |
778 |
} |
779 |
} finally { |
780 |
monitor.done(); |
781 |
} |
782 |
} |
783 |
|
784 |
/** |
785 |
* Returns an array of projects in their suggested build order |
786 |
* containing all of the projects specified by <code>baseProjects</code> |
787 |
* and all of their referenced projects. |
788 |
* |
789 |
* @param baseProjects a collection of projects |
790 |
* @return an array of projects in their suggested build order |
791 |
* containing all of the projects specified by <code>baseProjects</code> |
792 |
* @throws CoreException if an error occurs while computing referenced |
793 |
* projects |
794 |
*/ |
795 |
protected IProject[] computeReferencedBuildOrder(IProject[] baseProjects) throws CoreException { |
796 |
HashSet unorderedProjects = new HashSet(); |
797 |
for (int i = 0; i < baseProjects.length; i++) { |
798 |
unorderedProjects.add(baseProjects[i]); |
799 |
addReferencedProjects(baseProjects[i], unorderedProjects); |
800 |
} |
801 |
IProject[] projectSet = (IProject[]) unorderedProjects.toArray(new IProject[unorderedProjects.size()]); |
802 |
return computeBuildOrder(projectSet); |
803 |
} |
804 |
|
805 |
/** |
806 |
* Adds all projects referenced by <code>project</code> to the given |
807 |
* set. |
808 |
* |
809 |
* @param project project |
810 |
* @param references set to which referenced projects are added |
811 |
* @throws CoreException if an error occurs while computing referenced |
812 |
* projects |
813 |
*/ |
814 |
protected void addReferencedProjects(IProject project, Set references) throws CoreException { |
815 |
if (project.isOpen()) { |
816 |
IProject[] projects = project.getReferencedProjects(); |
817 |
for (int i = 0; i < projects.length; i++) { |
818 |
IProject refProject = projects[i]; |
819 |
if (refProject.exists() && !references.contains(refProject)) { |
820 |
references.add(refProject); |
821 |
addReferencedProjects(refProject, references); |
822 |
} |
823 |
} |
824 |
} |
825 |
} |
826 |
|
827 |
/** |
828 |
* Returns a list of projects in their suggested build order from the |
829 |
* given unordered list of projects. |
830 |
* |
831 |
* @param projects the list of projects to sort into build order |
832 |
* @return a new array containing all projects from <code>projects</code> sorted |
833 |
* according to their build order. |
834 |
*/ |
835 |
private IProject[] computeBuildOrder(IProject[] projects) { |
836 |
String[] orderedNames = ResourcesPlugin.getWorkspace().getDescription().getBuildOrder(); |
837 |
if (orderedNames != null) { |
838 |
List orderedProjects = new ArrayList(projects.length); |
839 |
//Projects may not be in the build order but should be built if selected |
840 |
List unorderedProjects = new ArrayList(projects.length); |
841 |
for (int i = 0; i < projects.length; ++i) { |
842 |
unorderedProjects.add(projects[i]); |
843 |
} |
844 |
|
845 |
for (int i = 0; i < orderedNames.length; i++) { |
846 |
String projectName = orderedNames[i]; |
847 |
for (Iterator iterator = unorderedProjects.iterator(); iterator.hasNext();) { |
848 |
IProject project = (IProject) iterator.next(); |
849 |
if (project.getName().equals(projectName)) { |
850 |
orderedProjects.add(project); |
851 |
iterator.remove(); |
852 |
break; |
853 |
} |
854 |
} |
855 |
} |
856 |
//Add anything not specified before we return |
857 |
orderedProjects.addAll(unorderedProjects); |
858 |
return (IProject[]) orderedProjects.toArray(new IProject[orderedProjects.size()]); |
859 |
} |
860 |
|
861 |
// Computing build order returned null, try the project prerequisite order |
862 |
IWorkspace.ProjectOrder po = ResourcesPlugin.getWorkspace().computeProjectOrder(projects); |
863 |
return po.projects; |
864 |
} |
865 |
|
866 |
/** |
867 |
* Returns a map containing information associating libraries to the output locations the |
868 |
* workspace compiles them to. Uses information in the build.properties and the classpath. |
869 |
* The map will be of the following form: |
870 |
* String symbolic name > lib output map |
871 |
* The lib output map will be of the following form: |
872 |
* String lib name > Set of IPath output folders |
873 |
* |
874 |
* @return a map of library output folders for each plugin in the workspace |
875 |
*/ |
876 |
protected Map getWorkspacePluginOutputFolders() throws CoreException { |
877 |
IProject[] projects = getExportedWorkspaceProjects(); |
878 |
Map result = new HashMap(projects.length); |
879 |
for (int i = 0; i < projects.length; i++) { |
880 |
IFile buildFile = projects[i].getFile("build.properties"); //$NON-NLS-1$ |
881 |
if (buildFile.exists()) { |
882 |
IBuildModel buildModel = new WorkspaceBuildModel(buildFile); |
883 |
buildModel.load(); |
884 |
IJavaProject javaProject = JavaCore.create(projects[i]); |
885 |
if (javaProject.exists()) { |
886 |
Map modelOutput = getPluginOutputFolders(buildModel, javaProject); |
887 |
if (!modelOutput.isEmpty()) { |
888 |
IPluginModelBase model = PDECore.getDefault().getModelManager().findModel(projects[i]); |
889 |
if (model != null) { |
890 |
result.put(model.getBundleDescription().getSymbolicName(), modelOutput); |
891 |
} |
892 |
} |
893 |
} |
894 |
} |
895 |
} |
896 |
return result; |
897 |
} |
898 |
|
899 |
private Map getPluginOutputFolders(IBuildModel buildModel, IJavaProject javaProject) throws JavaModelException { |
900 |
Map outputEntries = new HashMap(); |
901 |
|
902 |
IBuildEntry[] buildEntries = buildModel.getBuild().getBuildEntries(); |
903 |
for (int i = 0; i < buildEntries.length; i++) { |
904 |
String name = buildEntries[i].getName(); |
905 |
if (name.startsWith(IBuildPropertiesConstants.PROPERTY_SOURCE_PREFIX)) { |
906 |
Set outputPaths = new HashSet(); |
907 |
|
908 |
String[] sourceFolders = buildEntries[i].getTokens(); |
909 |
for (int j = 0; j < sourceFolders.length; j++) { |
910 |
|
911 |
IClasspathEntry[] classpathEntries = javaProject.getRawClasspath(); |
912 |
for (int k = 0; k < classpathEntries.length; k++) { |
913 |
if (classpathEntries[k].getEntryKind() == IClasspathEntry.CPE_SOURCE) { |
914 |
IPath sourcePath = classpathEntries[k].getPath().removeFirstSegments(1); // Entries include project as first segment |
915 |
if (sourcePath.equals(new Path(sourceFolders[j]))) { |
916 |
IPath outputPath = classpathEntries[k].getOutputLocation(); |
917 |
if (outputPath == null) { |
918 |
outputPath = javaProject.getOutputLocation(); |
919 |
} |
920 |
outputPaths.add(outputPath.removeFirstSegments(1)); // Entries include project as first segment |
921 |
} |
922 |
} |
923 |
} |
924 |
} |
925 |
if (!outputPaths.isEmpty()) { |
926 |
outputEntries.put(name.substring(IBuildPropertiesConstants.PROPERTY_SOURCE_PREFIX.length()), outputPaths); |
927 |
} |
928 |
} |
929 |
} |
930 |
return outputEntries; |
931 |
} |
932 |
|
933 |
protected IProject[] getExportedWorkspaceProjects() throws CoreException { |
934 |
if (fWorkspaceProjects == null) { |
935 |
// TODO This won't work for nested features either |
936 |
Set projects = new HashSet(); |
937 |
for (int i = 0; i < fInfo.items.length; i++) { |
938 |
if (fInfo.items[i] instanceof IPluginModelBase) { |
939 |
IPath installLocation = new Path(((IPluginModelBase) fInfo.items[i]).getInstallLocation()); |
940 |
IProject project = PDECore.getWorkspace().getRoot().getProject(installLocation.lastSegment()); |
941 |
if (project.exists()) { |
942 |
projects.add(project); |
943 |
} |
944 |
} else if (fInfo.items[i] instanceof IFeatureModel) { |
945 |
IFeatureModel feature = (IFeatureModel) fInfo.items[i]; |
946 |
IFeaturePlugin[] plugins = feature.getFeature().getPlugins(); |
947 |
for (int j = 0; j < plugins.length; j++) { |
948 |
IPluginModelBase plugin = PDECore.getDefault().getModelManager().findModel(plugins[i].getId()); |
949 |
IPath installLocation = new Path(plugin.getInstallLocation()); |
950 |
IProject project = PDECore.getWorkspace().getRoot().getProject(installLocation.lastSegment()); |
951 |
if (project.exists()) { |
952 |
projects.add(project); |
953 |
} |
954 |
} |
955 |
|
956 |
} |
957 |
} |
958 |
fWorkspaceProjects = computeReferencedBuildOrder((IProject[]) projects.toArray(new IProject[projects.size()])); |
959 |
} |
960 |
return fWorkspaceProjects; |
961 |
} |
962 |
|
735 |
} |
963 |
} |