From ef689536269438ba30f6c0bc7b8484d45daaee40 Mon Sep 17 00:00:00 2001 From: James Blackburn Date: Thu, 19 Nov 2009 14:16:08 +0000 Subject: [PATCH] Bug 295588 Changing Artifact type should update export settings --- .../internal/core/Configuration.java | 108 +++++++++++------- .../ui/properties/ArtifactTab.java | 54 ++++----- 2 files changed, 91 insertions(+), 71 deletions(-) diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/Configuration.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/Configuration.java index 2522cb072cc..afe2079c5bd 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/Configuration.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/Configuration.java @@ -30,6 +30,7 @@ import org.eclipse.cdt.core.settings.model.CLibraryFileEntry; import org.eclipse.cdt.core.settings.model.CLibraryPathEntry; import org.eclipse.cdt.core.settings.model.CSourceEntry; import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; +import org.eclipse.cdt.core.settings.model.ICExternalSetting; import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry; import org.eclipse.cdt.core.settings.model.ICLibraryPathEntry; import org.eclipse.cdt.core.settings.model.ICOutputEntry; @@ -1449,6 +1450,23 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild public void setArtifactName(String name) { if (name == null && artifactName == null) return; if (artifactName == null || name == null || !artifactName.equals(name)) { + if (canExportedArtifactInfo()) { + // Remove existing exported library, if it exists + ICConfigurationDescription des = ManagedBuildManager.getDescriptionForConfiguration(this); + ICSettingEntry lib = CDataUtil.resolveEntries(new ICSettingEntry[] { + new CLibraryFileEntry(getArtifactName(), 0)}, des)[0]; + for (ICExternalSetting setting : des.getExternalSettings()) { + Set entries = new LinkedHashSet(Arrays.asList(setting.getEntries())); + if (entries.contains(lib)) { + entries.remove(lib); + des.removeExternalSetting(setting); + des.createExternalSetting(setting.getCompatibleLanguageIds(), setting.getCompatibleContentTypeIds(), + setting.getCompatibleExtensions(), entries.toArray(new ICSettingEntry[entries.size()])); + break; + } + } + } + artifactName = name; if(!isExtensionElement()){ ITool tool = calculateTargetTool(); @@ -1460,8 +1478,7 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild } // rebuildNeeded = true; isDirty = true; -// exportArtifactInfo(); - + exportArtifactInfo(); } } @@ -2649,7 +2666,26 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild public boolean buildsFileType(String srcExt) { return getRootFolderInfo().buildsFileType(srcExt); } - + + /** + * @return whether this Configuration exports settings to other referenced configurations + */ + private boolean canExportedArtifactInfo() { + if (isExtensionConfig) + return false; + + IBuildObjectProperties props = getBuildProperties(); + IBuildProperty prop = props.getProperty(ManagedBuildManager.BUILD_ARTEFACT_TYPE_PROPERTY_ID); + if (prop == null) + return false; + String valueId = prop.getValue().getId(); + if(!ManagedBuildManager.BUILD_ARTEFACT_TYPE_PROPERTY_SHAREDLIB.equals(valueId) + && !ManagedBuildManager.BUILD_ARTEFACT_TYPE_PROPERTY_STATICLIB.equals(valueId)) + return false; + ICConfigurationDescription des = ManagedBuildManager.getDescriptionForConfiguration(this); + return des != null && !des.isReadOnly(); + } + /** * Responsible for contributing 'external' settings back to the core for use * by referenced projects. @@ -2658,47 +2694,39 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild * to be used be references for linking the output of this library project */ public void exportArtifactInfo(){ - if(isExtensionConfig) + if (!canExportedArtifactInfo()) return; - - IBuildObjectProperties props = getBuildProperties(); - IBuildProperty prop = props.getProperty(ManagedBuildManager.BUILD_ARTEFACT_TYPE_PROPERTY_ID); - if(prop != null){ - String valueId = prop.getValue().getId(); - if(ManagedBuildManager.BUILD_ARTEFACT_TYPE_PROPERTY_SHAREDLIB.equals(valueId) - || ManagedBuildManager.BUILD_ARTEFACT_TYPE_PROPERTY_STATICLIB.equals(valueId)){ - ICConfigurationDescription des = ManagedBuildManager.getDescriptionForConfiguration(this); - if(des != null && !des.isReadOnly()){ - ICOutputEntry entries[] = getConfigurationData().getBuildData().getOutputDirectories(); - IPath path = getOwner().getFullPath(); - - List list = new ArrayList(entries.length + 1); - - // Add project level include path - list.add(new CIncludePathEntry(path.toString(), ICLanguageSettingEntry.VALUE_WORKSPACE_PATH)); - // Add Build output path as an exported library path - entries = CDataUtil.resolveEntries(entries, des); - for(int i = 0; i < entries.length; i++){ - ICOutputEntry out = entries[i]; - String value = out.getValue(); + ICConfigurationDescription des = ManagedBuildManager.getDescriptionForConfiguration(this); + if(des != null && !des.isReadOnly()){ + ICOutputEntry entries[] = getConfigurationData().getBuildData().getOutputDirectories(); + IPath path = getOwner().getFullPath(); - IPath p = new Path(value); - if(!p.isAbsolute()) - value = getOwner().getFullPath().append(value).toString(); - ICLibraryPathEntry lib = new CLibraryPathEntry(value, out.getFlags() & (~ICSettingEntry.RESOLVED)); - list.add(lib); - } + List list = new ArrayList(entries.length + 1); - // Add 'libs' artifact names themselves - ICSettingEntry[] libFile = new ICSettingEntry[] {new CLibraryFileEntry(getArtifactName(), 0)}; - libFile = CDataUtil.resolveEntries(libFile, des); - list.add(libFile[0]); + // Add project level include path + list.add(new CIncludePathEntry(path.toString(), ICLanguageSettingEntry.VALUE_WORKSPACE_PATH)); - // Contribute the settings back as 'exported' - des.createExternalSetting(null, null, null, list.toArray(new ICSettingEntry[list.size()])); - } + // Add Build output path as an exported library path + entries = CDataUtil.resolveEntries(entries, des); + for(int i = 0; i < entries.length; i++){ + ICOutputEntry out = entries[i]; + String value = out.getValue(); + + IPath p = new Path(value); + if(!p.isAbsolute()) + value = getOwner().getFullPath().append(value).toString(); + ICLibraryPathEntry lib = new CLibraryPathEntry(value, out.getFlags() & (~ICSettingEntry.RESOLVED)); + list.add(lib); } + + // Add 'libs' artifact names themselves + ICSettingEntry[] libFile = new ICSettingEntry[] {new CLibraryFileEntry(getArtifactName(), 0)}; + libFile = CDataUtil.resolveEntries(libFile, des); + list.add(libFile[0]); + + // Contribute the settings back as 'exported' + des.createExternalSetting(null, null, null, list.toArray(new ICSettingEntry[list.size()])); } } @@ -2948,8 +2976,10 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild } catch (CoreException e){ throw new BuildException(e.getLocalizedMessage()); } + // May need to update the exports paths & symbols after artifact type change + exportArtifactInfo(); } - + boolean isExcluded(IPath path){ // if(path.segmentCount() == 0) // return false; diff --git a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/properties/ArtifactTab.java b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/properties/ArtifactTab.java index f5e337f1c8c..8a8fd400ae1 100644 --- a/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/properties/ArtifactTab.java +++ b/build/org.eclipse.cdt.managedbuilder.ui/src/org/eclipse/cdt/managedbuilder/ui/properties/ArtifactTab.java @@ -1,12 +1,13 @@ /******************************************************************************* - * Copyright (c) 2007, 2008 Intel Corporation and others. + * Copyright (c) 2007, 2009 Intel Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Intel Corporation - Initial API and implementation + * Intel Corporation - Initial API and implementation + * James Blackburn (Broadcom Corp.) *******************************************************************************/ package org.eclipse.cdt.managedbuilder.ui.properties; @@ -16,14 +17,12 @@ import java.util.TreeSet; import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; import org.eclipse.cdt.core.settings.model.ICMultiItemsHolder; import org.eclipse.cdt.core.settings.model.ICResourceDescription; -import org.eclipse.cdt.managedbuilder.buildproperties.IBuildProperty; import org.eclipse.cdt.managedbuilder.buildproperties.IBuildPropertyValue; -import org.eclipse.cdt.managedbuilder.core.IBuildObjectProperties; +import org.eclipse.cdt.managedbuilder.core.BuildException; import org.eclipse.cdt.managedbuilder.core.IConfiguration; import org.eclipse.cdt.managedbuilder.core.IMultiConfiguration; import org.eclipse.cdt.managedbuilder.core.ITool; import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager; -import org.eclipse.core.runtime.CoreException; import org.eclipse.swt.SWT; import org.eclipse.swt.events.ModifyEvent; import org.eclipse.swt.events.ModifyListener; @@ -45,7 +44,6 @@ public class ArtifactTab extends AbstractCBuildPropertyTab { private Combo c1; private int savedPos = -1; // current project type private IConfiguration fCfg; - private IBuildObjectProperties fProperties; private IBuildPropertyValue[] values; private ITool tTool; private boolean canModify = true; @@ -55,7 +53,8 @@ public class ArtifactTab extends AbstractCBuildPropertyTab { private Set set2 = new TreeSet(); private Set set3 = new TreeSet(); private Set set4 = new TreeSet(); - + + @Override public void createControls(Composite parent) { super.createControls(parent); usercomp.setLayout(new GridLayout(2, false)); @@ -66,6 +65,7 @@ public class ArtifactTab extends AbstractCBuildPropertyTab { c1 = new Combo(usercomp, SWT.READ_ONLY | SWT.DROP_DOWN | SWT.BORDER); c1.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); c1.addSelectionListener(new SelectionAdapter() { + @Override public void widgetSelected(SelectionEvent e) { typeChanged(); }}); @@ -120,27 +120,20 @@ public class ArtifactTab extends AbstractCBuildPropertyTab { private void setProjectType(int n) { try { String s = values[n].getId(); - if (fCfg instanceof IMultiConfiguration) { - ((IMultiConfiguration)fCfg).setBuildProperty(PROPERTY, s); - } else { - if (fProperties == null) - return; - fProperties.setProperty(PROPERTY, s); - } - } catch (CoreException ex) { + fCfg.setBuildArtefactType(s); + } catch (BuildException ex) { ManagedBuilderUIPlugin.log(ex); } } + @Override public void updateData(ICResourceDescription cfgd) { if (cfgd == null) return; fCfg = getCfg(); if (page.isMultiCfg()) { - fProperties = null; values = ((IMultiConfiguration)fCfg).getSupportedValues(PROPERTY); } else { - fProperties = fCfg.getBuildProperties(); - values = fProperties.getSupportedValues(PROPERTY); + values = fCfg.getBuildProperties().getSupportedValues(PROPERTY); } c1.removeAll(); c1.setData(values); @@ -148,11 +141,9 @@ public class ArtifactTab extends AbstractCBuildPropertyTab { c1.add(values[i].getName()); } c1.setText(EMPTY_STR); - IBuildProperty pr = (page.isMultiCfg()) ? - ((IMultiConfiguration)fCfg).getBuildProperty(PROPERTY) : - fProperties.getProperty(PROPERTY); - if (pr != null) { - String s = pr.getValue().getId(); + IBuildPropertyValue pv = fCfg.getBuildArtefactType(); + if (pv != null) { + String s = pv.getId(); for (int i=0; i set) {