Permalink
Browse files

cleanup

fixes related to #42 - no longer capturing duplicate divs for previously captured stuff
  • Loading branch information...
1 parent bd29b82 commit 089cb297340bf7c0bd2cb8d3f0c61a4cd286d05c @gregjan gregjan committed Jul 19, 2011
@@ -65,7 +65,7 @@ public boolean test(Object receiver, String property, Object[] args, Object expe
}
}
} else if(SIBLING_IRESOURCES.equals(property)) {
- System.out.println("checking siblings");
+ //System.out.println("checking siblings");
if (receiver instanceof ISelection) {
ISelection s = (ISelection) receiver;
if (s instanceof IStructuredSelection) {
@@ -49,8 +49,6 @@
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.emf.common.command.Command;
import org.eclipse.emf.edit.command.AddCommand;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import unc.lib.cdr.workbench.IResourceConstants;
import unc.lib.cdr.workbench.project.MetsProjectNature;
@@ -60,7 +58,6 @@
*
*/
public class CaptureJob extends Job {
- private static final Logger log = LoggerFactory.getLogger(CaptureJob.class);
private IProject project = null;
private List<IResource> items;
private DivType topDestination = null;
@@ -156,8 +153,8 @@ protected IStatus run(IProgressMonitor monitor) {
// params.put("audit", Boolean.TRUE);
// }
//log.debug("calling incremental build");
- //project.build(IncrementalProjectBuilder.FULL_BUILD, MetsProjectNature.STAGING_BUILDER_ID, params,
- // new NullProgressMonitor());
+ project.build(IncrementalProjectBuilder.INCREMENTAL_BUILD, MetsProjectNature.STAGING_BUILDER_ID, params,
+ new NullProgressMonitor());
monitor.done();
return Status.OK_STATUS;
} catch (CoreException e) {
@@ -176,7 +173,12 @@ private void captureSiblingList(List<IResource> list, DivType dest, DivType inse
}
Collections.sort(list, resourceComparator);
for (IResource r : list) {
- DivType d = capture(r, sharedParent, insert);
+ DivType d = findDiv(r);
+ if(d == null) {
+ d = capture(r, sharedParent, insert);
+ } else {
+ System.out.println("previously captured: "+d);
+ }
if(r instanceof IContainer) {
List<IResource> children = new ArrayList<IResource>();
IContainer c = (IContainer)r;
@@ -187,6 +189,15 @@ private void captureSiblingList(List<IResource> list, DivType dest, DivType inse
// TODO appended in alpha order, now sort the parent folder?
}
+ private DivType findDiv(IResource r) throws CoreException {
+ DivType result = null;
+ String divID = IResourceConstants.getCapturedDivID(r);
+ if (divID != null) {
+ result = METSUtils.findDiv(m, divID);
+ }
+ return result;
+ }
+
/**
* @param iResource
* @return
@@ -197,13 +208,10 @@ private DivType findOrCaptureParent(IResource me) throws CoreException {
return this.bag;
}
- DivType result = null;
- String divID = IResourceConstants.getCapturedDivID(me.getParent());
- if (divID != null) {
- result = METSUtils.findDiv(m, divID);
- if( result != null ) {
- return result;
- }
+ DivType result = findDiv(me.getParent());
+ if( result != null ) {
+ System.out.println("Found closest parent:"+result);
+ return result;
}
// need to create parent, but first we need it's parent
@@ -226,10 +234,15 @@ DivType capture(IResource me, DivType parent, DivType insertBefore) throws CoreE
command = AddCommand.create(mpn.getEditingDomain(), parent,
MetsPackage.eINSTANCE.getDivType_Div(), result);
}
+
+ // update resource to reflect capture
+ String ID = METSUtils.makeXMLUUID();
+ IResourceConstants.setCapturedState(me, ID);
+
if(me instanceof IContainer) {
- fillFolderDiv(result, (IContainer)me);
+ fillFolderDiv(result, (IContainer)me, ID);
} else if(me instanceof IFile){
- fillFileDiv(result, (IFile)me);
+ fillFileDiv(result, (IFile)me, ID);
}
mpn.getCommandStack().execute(command);
monitor.worked(1);
@@ -240,11 +253,10 @@ DivType capture(IResource me, DivType parent, DivType insertBefore) throws CoreE
* @param folderDiv
* @param c
*/
- private void fillFolderDiv(DivType folderDiv, IContainer c) throws CoreException {
+ private void fillFolderDiv(DivType folderDiv, IContainer c, String ID) throws CoreException {
List<String> contentIds = new ArrayList<String>();
contentIds.add(c.getLocationURI().toASCIIString());
folderDiv.setCONTENTIDS(contentIds);
- String ID = METSUtils.makeXMLUUID();
folderDiv.setID(ID);
folderDiv.setLABEL1(c.getName());
folderDiv.setTYPE(METSConstants.Div_Folder);
@@ -255,11 +267,10 @@ private void fillFolderDiv(DivType folderDiv, IContainer c) throws CoreException
* @param folderDiv
* @param c
*/
- private void fillFileDiv(DivType div, IFile c) throws CoreException {
+ private void fillFileDiv(DivType div, IFile c, String ID) throws CoreException {
List<String> contentIds = new ArrayList<String>();
contentIds.add(c.getLocationURI().toASCIIString());
div.setCONTENTIDS(contentIds);
- String ID = METSUtils.makeXMLUUID();
div.setID(ID);
div.setLABEL1(c.getName());
div.setTYPE(METSConstants.Div_File);
@@ -275,8 +286,6 @@ private void fillFileDiv(DivType div, IFile c) throws CoreException {
long size = sourceFileInfo.getLength();
// String md5 = StagingUtils.fetchMD5Digest(sourceFileStore, new NullProgressMonitor());
METSUtils.addDataFile(m, ID, c.getLocationURI(), size, null);
- // update resource to reflect capture
- IResourceConstants.setCapturedState(c, ID);
}
}
@@ -58,7 +58,7 @@ private void toggleStaging(IProject project) throws CoreException {
ICommand[] commands = desc.getBuildSpec();
for (int i = 0; i < commands.length; ++i) {
if (commands[i].getBuilderName().equals(MetsProjectNature.STAGING_BUILDER_ID)) {
- System.out.println("about to toggle:"+commands[i].isBuilding(IncrementalProjectBuilder.AUTO_BUILD));
+ //System.out.println("about to toggle:"+commands[i].isBuilding(IncrementalProjectBuilder.AUTO_BUILD));
if(commands[i].isBuilding(IncrementalProjectBuilder.AUTO_BUILD)) {
commands[i].setBuilding(IncrementalProjectBuilder.AUTO_BUILD, false);
} else {
@@ -30,27 +30,24 @@
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.jobs.Job;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
import unc.lib.cdr.workbench.IResourceConstants;
public class StageBuilder extends IncrementalProjectBuilder {
- private static final Logger log = LoggerFactory.getLogger(StageBuilder.class);
public StageBuilder() {
}
/*
* (non-Javadoc)
- *
+ *
* @see org.eclipse.core.resources.IncrementalProjectBuilder#build(int, java.util.Map,
* org.eclipse.core.runtime.IProgressMonitor)
- *
+ *
* audits and repairs previously staged files when arg["verify"] == Boolean.True
*/
@Override
- protected IProject[] build(int kind, Map args, IProgressMonitor monitor) throws CoreException {
+ protected IProject[] build(int kind, @SuppressWarnings("rawtypes") Map args, IProgressMonitor monitor) throws CoreException {
IProject[] result = null;
boolean audit = false;
if (args != null && Boolean.TRUE.equals(args.get("audit"))) {

0 comments on commit 089cb29

Please sign in to comment.