001: /*
002: * The contents of this file are subject to the terms of the Common Development
003: * and Distribution License (the License). You may not use this file except in
004: * compliance with the License.
005: *
006: * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
007: * or http://www.netbeans.org/cddl.txt.
008: *
009: * When distributing Covered Code, include this CDDL Header Notice in each file
010: * and include the License file at http://www.netbeans.org/cddl.txt.
011: * If applicable, add the following below the CDDL Header, with the fields
012: * enclosed by brackets [] replaced by your own identifying information:
013: * "Portions Copyrighted [year] [name of copyright owner]"
014: *
015: * The Original Software is NetBeans. The Initial Developer of the Original
016: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
017: * Microsystems, Inc. All Rights Reserved.
018: */
019: package org.netbeans.modules.bpel.project;
020:
021: import java.io.File;
022: import java.io.IOException;
023: import java.util.ArrayList;
024: import java.util.List;
025: import java.util.Properties;
026: import org.apache.tools.ant.module.api.support.ActionUtils;
027: import org.netbeans.api.project.Project;
028: import org.netbeans.api.project.ProjectManager;
029: import org.netbeans.spi.project.support.ProjectOperations;
030: import org.netbeans.spi.project.ActionProvider;
031: import org.netbeans.spi.project.DeleteOperationImplementation;
032: import org.netbeans.spi.project.CopyOperationImplementation;
033: import org.netbeans.spi.project.MoveOperationImplementation;
034: import org.netbeans.spi.project.support.ant.AntProjectHelper;
035: import org.netbeans.spi.project.support.ant.EditableProperties;
036: import org.netbeans.spi.project.support.ant.GeneratedFilesHelper;
037: import org.netbeans.spi.project.support.ant.PropertyEvaluator;
038: import org.netbeans.spi.project.support.ant.PropertyUtils;
039: import org.openide.filesystems.FileObject;
040: import org.openide.filesystems.FileUtil;
041: import org.openide.util.Lookup;
042: import org.openide.util.lookup.Lookups;
043: import org.netbeans.modules.compapp.projects.base.ui.customizer.IcanproProjectProperties;
044:
045: public class BpelProjectOperations implements
046: DeleteOperationImplementation, CopyOperationImplementation,
047: MoveOperationImplementation {
048: private BpelproProject project;
049:
050: /** Creates a new instance of JbiProjectOperations */
051: public BpelProjectOperations(BpelproProject project) {
052: this .project = project;
053: }
054:
055: public List/*<FileObject>*/getDataFiles() {
056: List/*<FileObject>*/files = new ArrayList();
057:
058: files.add(project.getSourceDirectory());
059:
060: PropertyEvaluator evaluator = project.evaluator();
061: String prop = evaluator
062: .getProperty(IcanproProjectProperties.SOURCE_ROOT);
063: if (prop != null) {
064: FileObject projectDirectory = project.getProjectDirectory();
065: FileObject srcDir = project.getAntProjectHelper()
066: .resolveFileObject(prop);
067: if (projectDirectory != srcDir && !files.contains(srcDir))
068: files.add(srcDir);
069: }
070:
071: return files;
072: }
073:
074: private static void addFile(FileObject projectDirectory,
075: String fileName, List/*<FileObject>*/result) {
076: FileObject file = projectDirectory.getFileObject(fileName);
077:
078: if (file != null) {
079: result.add(file);
080: }
081: }
082:
083: public List/*<FileObject>*/getMetadataFiles() {
084: FileObject projectDirectory = project.getProjectDirectory();
085: List/*<FileObject>*/files = new ArrayList();
086:
087: addFile(projectDirectory, "nbproject", files); // NOI18N
088: addFile(projectDirectory, "build.xml", files); // NOI18N
089: addFile(projectDirectory, "catalog.xml", files); //NOI18N
090: addFile(projectDirectory, projectDirectory.getName(), files); //NOI18N
091: addFile(
092: projectDirectory,
093: org.netbeans.modules.xml.retriever.XMLCatalogProvider.TYPE_RETRIEVED,
094: files); //NOI18N
095:
096: return files;
097: }
098:
099: public void notifyDeleting() throws IOException {
100: BpelproActionProvider ap = (BpelproActionProvider) project
101: .getLookup().lookup(BpelproActionProvider.class);
102: assert ap != null;
103:
104: Lookup context = Lookups.fixed(new Object[0]);
105: Properties p = new Properties();
106: String[] targetNames = ap.getTargetNames(
107: ActionProvider.COMMAND_CLEAN, context, p);
108: FileObject buildXML = project.getProjectDirectory()
109: .getFileObject(GeneratedFilesHelper.BUILD_XML_PATH);
110:
111: assert targetNames != null;
112: assert targetNames.length > 0;
113:
114: ActionUtils.runTarget(buildXML, targetNames, p).waitFinished();
115: }
116:
117: public void notifyDeleted() throws IOException {
118:
119: project.getAntProjectHelper().notifyDeleted();
120: }
121:
122: public void notifyCopied(Project original, File originalPath,
123: final String newName) {
124: if (original == null) {
125: // do nothing for the original project.
126: return;
127: }
128:
129: project.getReferenceHelper().fixReferences(originalPath);
130:
131: String oldName = project.getName();
132: project.setName(newName);
133: }
134:
135: public void notifyCopying() {
136: // do nothing.
137: // This does copy the old distribution file over though, which is
138: // probably OK because "ant clean" will clean it up.
139: }
140:
141: public void notifyMoved(Project original, File originalPath,
142: final String newName) {
143: if (original == null) {
144: project.getAntProjectHelper().notifyDeleted();
145: return;
146: }
147: String oldName = project.getName();
148: project.setName(newName);
149: project.getReferenceHelper().fixReferences(originalPath);
150: }
151:
152: public void notifyMoving() throws IOException {
153: notifyDeleting();
154: }
155: }
|