mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-03 14:25:37 +02:00
[188863] fix job conflict problems for save jobs, ignore bad profiles on restore
This commit is contained in:
parent
ea000cc737
commit
9edbe8448a
6 changed files with 140 additions and 10 deletions
|
@ -19,7 +19,10 @@ import org.eclipse.core.runtime.IPath;
|
|||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.core.runtime.IStatus;
|
||||
import org.eclipse.core.runtime.Status;
|
||||
import org.eclipse.core.runtime.jobs.Job;
|
||||
import org.eclipse.rse.core.RSECorePlugin;
|
||||
import org.eclipse.rse.persistence.IRSEPersistenceProvider;
|
||||
import org.eclipse.rse.persistence.dom.RSEDOM;
|
||||
|
||||
class PFMetadataAnchor implements PFPersistenceAnchor {
|
||||
|
||||
|
@ -55,7 +58,15 @@ class PFMetadataAnchor implements PFPersistenceAnchor {
|
|||
names.toArray(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.eclipse.rse.internal.persistence.PFPersistenceAnchor#makeSaveJob(org.eclipse.rse.persistence.dom.RSEDOM, org.eclipse.rse.persistence.IRSEPersistenceProvider)
|
||||
*/
|
||||
public Job makeSaveJob(RSEDOM dom, IRSEPersistenceProvider provider) {
|
||||
return new PFMetatdataJob(dom, provider);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the folder that acts as the parent for profile folders.
|
||||
*/
|
||||
|
@ -106,4 +117,5 @@ class PFMetadataAnchor implements PFPersistenceAnchor {
|
|||
}
|
||||
resource.delete();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,78 @@
|
|||
/********************************************************************************
|
||||
* Copyright (c) 2006, 2007 IBM 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
|
||||
*
|
||||
* Initial Contributors:
|
||||
* The following IBM employees contributed to the Remote System Explorer
|
||||
* component that contains this file: David McKnight, Kushal Munir,
|
||||
* Michael Berger, David Dykstal, Phil Coulthard, Don Yantzi, Eric Simpson,
|
||||
* Emily Bruner, Mazen Faraj, Adrian Storisteanu, Li Ding, and Kent Hawley.
|
||||
*
|
||||
* Contributors:
|
||||
* Martin Oberhuber (Wind River) - [184095] Replace systemTypeName by IRSESystemType
|
||||
* David Dykstal (IBM) - [188863] created out of SaveRSEDOMJob
|
||||
********************************************************************************/
|
||||
|
||||
package org.eclipse.rse.internal.persistence;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.core.runtime.IStatus;
|
||||
import org.eclipse.core.runtime.Status;
|
||||
import org.eclipse.core.runtime.jobs.ISchedulingRule;
|
||||
import org.eclipse.core.runtime.jobs.Job;
|
||||
import org.eclipse.rse.core.RSECorePlugin;
|
||||
import org.eclipse.rse.internal.core.RSECoreMessages;
|
||||
import org.eclipse.rse.persistence.IRSEPersistenceProvider;
|
||||
import org.eclipse.rse.persistence.dom.RSEDOM;
|
||||
|
||||
/**
|
||||
* The PFMetadataJob is a Job that belongs to the family
|
||||
* {@link RSECorePlugin#getThePersistenceManager()}. It is used to
|
||||
* save a DOM to the workspace metadata area. A DOM corresponds to a profile.
|
||||
*/
|
||||
public class PFMetatdataJob extends Job {
|
||||
|
||||
private RSEDOM _dom;
|
||||
private IRSEPersistenceProvider _provider;
|
||||
|
||||
private class SerializingRule implements ISchedulingRule {
|
||||
public boolean contains(ISchedulingRule rule) {
|
||||
return this == rule;
|
||||
}
|
||||
public boolean isConflicting(ISchedulingRule rule) {
|
||||
return (rule instanceof SerializingRule);
|
||||
}
|
||||
}
|
||||
|
||||
public PFMetatdataJob(RSEDOM dom, IRSEPersistenceProvider provider) {
|
||||
super("Saving Profile"); //$NON-NLS-1$
|
||||
String title = MessageFormat.format(RSECoreMessages.SaveRSEDOMJob_SavingProfileJobName, new Object[] { dom.getName() });
|
||||
setName(title);
|
||||
setRule(new SerializingRule());
|
||||
_dom = dom;
|
||||
_provider = provider;
|
||||
}
|
||||
|
||||
public IStatus run(IProgressMonitor monitor) {
|
||||
IStatus result = Status.OK_STATUS;
|
||||
boolean saved = _provider.saveRSEDOM(_dom, monitor);
|
||||
if (!saved) {
|
||||
result = Status.CANCEL_STATUS;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public boolean belongsTo(Object family) {
|
||||
Object[] families = new Object[] {RSECorePlugin.getThePersistenceManager()};
|
||||
for (int i = 0; i < families.length; i++) {
|
||||
Object object = families[i];
|
||||
if (family == object) return true;
|
||||
}
|
||||
return super.belongsTo(family);
|
||||
}
|
||||
|
||||
}
|
|
@ -13,6 +13,9 @@ package org.eclipse.rse.internal.persistence;
|
|||
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.core.runtime.IStatus;
|
||||
import org.eclipse.core.runtime.jobs.Job;
|
||||
import org.eclipse.rse.persistence.IRSEPersistenceProvider;
|
||||
import org.eclipse.rse.persistence.dom.RSEDOM;
|
||||
|
||||
interface PFPersistenceAnchor {
|
||||
|
||||
|
@ -34,5 +37,15 @@ interface PFPersistenceAnchor {
|
|||
* @return the location of the profile
|
||||
*/
|
||||
PFPersistenceLocation getProfileLocation(String profileName);
|
||||
|
||||
/**
|
||||
* Factory method to return a new Job instance to save an RSE DOM
|
||||
* to the persistence location managed by this anchor.
|
||||
* @param dom the RSEDOM (Profile) to save.
|
||||
* @param provider the Persistence Provider asking for save.
|
||||
* @return a Job to perform the save operation with proper
|
||||
* scheduling rules.
|
||||
*/
|
||||
Job makeSaveJob(RSEDOM dom, IRSEPersistenceProvider provider);
|
||||
|
||||
}
|
||||
|
|
|
@ -24,9 +24,12 @@ import org.eclipse.core.runtime.IProgressMonitor;
|
|||
import org.eclipse.core.runtime.IStatus;
|
||||
import org.eclipse.core.runtime.Path;
|
||||
import org.eclipse.core.runtime.Status;
|
||||
import org.eclipse.core.runtime.jobs.Job;
|
||||
import org.eclipse.rse.core.RSECorePlugin;
|
||||
import org.eclipse.rse.core.SystemResourceManager;
|
||||
import org.eclipse.rse.internal.core.RSECoreMessages;
|
||||
import org.eclipse.rse.persistence.IRSEPersistenceProvider;
|
||||
import org.eclipse.rse.persistence.dom.RSEDOM;
|
||||
|
||||
class PFWorkspaceAnchor implements PFPersistenceAnchor {
|
||||
|
||||
|
@ -70,7 +73,11 @@ class PFWorkspaceAnchor implements PFPersistenceAnchor {
|
|||
PFPersistenceLocation result = new PFWorkspaceLocation(profileFolder);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
public Job makeSaveJob(RSEDOM dom, IRSEPersistenceProvider provider) {
|
||||
return new PFWorkspaceJob(dom, provider);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the IFolder in which a profile is stored.
|
||||
* @return The folder that was created or found.
|
||||
|
@ -119,4 +126,5 @@ class PFWorkspaceAnchor implements PFPersistenceAnchor {
|
|||
private void logException(Exception e) {
|
||||
RSECorePlugin.getDefault().getLogger().logError("unexpected exception", e); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -12,12 +12,14 @@
|
|||
*
|
||||
* Contributors:
|
||||
* Martin Oberhuber (Wind River) - [184095] Replace systemTypeName by IRSESystemType
|
||||
* David Dykstal (IBM) - [188863] created out of SaveRSEDOMJob
|
||||
********************************************************************************/
|
||||
|
||||
package org.eclipse.rse.internal.persistence;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
|
||||
import org.eclipse.core.resources.ResourcesPlugin;
|
||||
import org.eclipse.core.resources.WorkspaceJob;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.core.runtime.IStatus;
|
||||
|
@ -28,19 +30,20 @@ import org.eclipse.rse.persistence.IRSEPersistenceProvider;
|
|||
import org.eclipse.rse.persistence.dom.RSEDOM;
|
||||
|
||||
/**
|
||||
* The SaveRSEDOMJob is a workspace job that belongs to the family
|
||||
* The PFWorkspaceJob is a workspace job that belongs to the family
|
||||
* {@link RSECorePlugin#getThePersistenceManager()}. It is used to
|
||||
* save a DOM to the workspace. A DOM corresponds to a profile.
|
||||
*/
|
||||
public class SaveRSEDOMJob extends WorkspaceJob {
|
||||
public class PFWorkspaceJob extends WorkspaceJob {
|
||||
|
||||
private RSEDOM _dom;
|
||||
private IRSEPersistenceProvider _provider;
|
||||
|
||||
public SaveRSEDOMJob(RSEDOM dom, IRSEPersistenceProvider provider) {
|
||||
|
||||
public PFWorkspaceJob(RSEDOM dom, IRSEPersistenceProvider provider) {
|
||||
super("Saving Profile"); //$NON-NLS-1$
|
||||
String title = MessageFormat.format(RSECoreMessages.SaveRSEDOMJob_SavingProfileJobName, new Object[] { dom.getName() });
|
||||
setName(title);
|
||||
setRule(ResourcesPlugin.getWorkspace().getRoot());
|
||||
_dom = dom;
|
||||
_provider = provider;
|
||||
}
|
||||
|
@ -63,4 +66,4 @@ public class SaveRSEDOMJob extends WorkspaceJob {
|
|||
return super.belongsTo(family);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -12,6 +12,7 @@
|
|||
* David Dykstal (IBM) - removed printlns, printStackTrace and added logging.
|
||||
* David Dykstal (IBM) - [177882] fixed escapeValue for garbling of CJK characters
|
||||
* Martin Oberhuber (Wind River) - [184095] Replace systemTypeName by IRSESystemType
|
||||
* David Dykstal (IBM) - [188863] fix job conflict problems for save jobs, ignore bad profiles on restore
|
||||
********************************************************************************/
|
||||
package org.eclipse.rse.internal.persistence;
|
||||
|
||||
|
@ -20,10 +21,12 @@ import java.io.ByteArrayOutputStream;
|
|||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.Set;
|
||||
|
@ -76,12 +79,16 @@ public class PropertyFileProvider implements IRSEPersistenceProvider {
|
|||
*/
|
||||
public String[] getSavedProfileNames() {
|
||||
String[] locationNames = getAnchor().getProfileLocationNames();
|
||||
String[] result = new String[locationNames.length];
|
||||
List names = new ArrayList(locationNames.length);
|
||||
for (int i = 0; i < locationNames.length; i++) {
|
||||
String locationName = locationNames[i];
|
||||
String profileName = getNodeName(locationName);
|
||||
result[i] = profileName;
|
||||
if (isValidName(profileName)) {
|
||||
names.add(profileName);
|
||||
}
|
||||
}
|
||||
String[] result = new String[names.size()];
|
||||
names.toArray(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -141,7 +148,7 @@ public class PropertyFileProvider implements IRSEPersistenceProvider {
|
|||
public Job getSaveJob(RSEDOM dom) {
|
||||
Job saveJob = (Job) saveJobs.get(dom);
|
||||
if (saveJob == null) {
|
||||
saveJob = new SaveRSEDOMJob(dom, this);
|
||||
saveJob = anchor.makeSaveJob(dom, this);
|
||||
saveJobs.put(dom, saveJob);
|
||||
}
|
||||
return saveJob;
|
||||
|
@ -164,6 +171,15 @@ public class PropertyFileProvider implements IRSEPersistenceProvider {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks a profile name for validity. Currently all names are valid except for completely blank names.
|
||||
* @param profileName the name to check
|
||||
* @return true if the name is valid.
|
||||
*/
|
||||
private boolean isValidName(String profileName) {
|
||||
return (profileName.trim().length() > 0);
|
||||
}
|
||||
|
||||
private PFPersistenceAnchor getAnchor() {
|
||||
if (anchor == null) {
|
||||
String location = properties.getProperty(P_LOCATION);
|
||||
|
|
Loading…
Add table
Reference in a new issue