001: package org.netbeans.modules.etl.project;
002:
003: import java.io.File;
004: import java.io.IOException;
005: import java.util.ArrayList;
006: import java.util.List;
007: import java.util.Properties;
008: import org.apache.tools.ant.module.api.support.ActionUtils;
009: import org.netbeans.api.project.Project;
010: import org.netbeans.spi.project.ActionProvider;
011: import org.netbeans.spi.project.DeleteOperationImplementation;
012: import org.netbeans.spi.project.CopyOperationImplementation;
013: import org.netbeans.spi.project.MoveOperationImplementation;
014: import org.netbeans.spi.project.support.ant.GeneratedFilesHelper;
015: import org.netbeans.spi.project.support.ant.PropertyEvaluator;
016: import org.openide.filesystems.FileObject;
017: import org.openide.util.Lookup;
018: import org.openide.util.lookup.Lookups;
019: import org.netbeans.modules.compapp.projects.base.ui.customizer.IcanproProjectProperties;
020:
021: public class EtlProjectOperations implements
022: DeleteOperationImplementation, CopyOperationImplementation,
023: MoveOperationImplementation {
024: private EtlproProject project;
025:
026: public EtlProjectOperations(EtlproProject project) {
027: this .project = project;
028: }
029:
030: public List getDataFiles() {
031: List files = new ArrayList();
032: files.add(project.getSourceDirectory());
033: PropertyEvaluator evaluator = project.evaluator();
034: String prop = evaluator
035: .getProperty(IcanproProjectProperties.SOURCE_ROOT);
036: if (prop != null) {
037: FileObject projectDirectory = project.getProjectDirectory();
038: FileObject srcDir = project.getAntProjectHelper()
039: .resolveFileObject(prop);
040: if (projectDirectory != srcDir && !files.contains(srcDir))
041: files.add(srcDir);
042: }
043: return files;
044: }
045:
046: private static void addFile(FileObject projectDirectory,
047: String fileName, List result) {
048: FileObject file = projectDirectory.getFileObject(fileName);
049: if (file != null) {
050: result.add(file);
051: }
052: }
053:
054: public List getMetadataFiles() {
055: FileObject projectDirectory = project.getProjectDirectory();
056: List files = new ArrayList();
057:
058: addFile(projectDirectory, "nbproject", files); // NOI18N
059: addFile(projectDirectory, "build.xml", files); // NOI18N
060: addFile(projectDirectory, "catalog.xml", files); //NOI18N
061: addFile(projectDirectory, projectDirectory.getName(), files); //NOI18N
062: //addFile(projectDirectory, org.netbeans.modules.xml.retriever.XMLCatalogProvider.TYPE_RETRIEVED , files); //NOI18N
063:
064: return files;
065: }
066:
067: public void notifyDeleting() throws IOException {
068: EtlproActionProvider ap = (EtlproActionProvider) project
069: .getLookup().lookup(EtlproActionProvider.class);
070: assert ap != null;
071:
072: Lookup context = Lookups.fixed(new Object[0]);
073: Properties p = new Properties();
074: String[] targetNames = ap.getTargetNames(
075: ActionProvider.COMMAND_CLEAN, context, p);
076: FileObject buildXML = project.getProjectDirectory()
077: .getFileObject(GeneratedFilesHelper.BUILD_XML_PATH);
078:
079: assert targetNames != null;
080: assert targetNames.length > 0;
081:
082: ActionUtils.runTarget(buildXML, targetNames, p).waitFinished();
083: }
084:
085: public void notifyDeleted() throws IOException {
086:
087: project.getAntProjectHelper().notifyDeleted();
088: }
089:
090: public void notifyCopied(Project original, File originalPath,
091: final String newName) {
092: if (original == null) {
093: return;
094: }
095:
096: project.getReferenceHelper().fixReferences(originalPath);
097:
098: String oldName = project.getName();
099: project.setName(newName);
100: }
101:
102: public void notifyCopying() {
103: }
104:
105: public void notifyMoved(Project original, File originalPath,
106: final String newName) {
107: if (original == null) {
108: project.getAntProjectHelper().notifyDeleted();
109: return;
110: }
111: String oldName = project.getName();
112: project.setName(newName);
113: project.getReferenceHelper().fixReferences(originalPath);
114: }
115:
116: public void notifyMoving() throws IOException {
117: notifyDeleting();
118: }
119: }
|