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.xslt.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.spi.project.ActionProvider;
029: import org.netbeans.spi.project.CopyOperationImplementation;
030: import org.netbeans.spi.project.DeleteOperationImplementation;
031: import org.netbeans.spi.project.MoveOperationImplementation;
032: import org.netbeans.spi.project.support.ant.GeneratedFilesHelper;
033: import org.netbeans.spi.project.support.ant.PropertyEvaluator;
034: import org.openide.filesystems.FileObject;
035: import org.openide.util.Lookup;
036: import org.openide.util.lookup.Lookups;
037: import org.netbeans.modules.compapp.projects.base.ui.customizer.IcanproProjectProperties;
038:
039: /**
040: *
041: * @author Vitaly Bychkov
042: * @version 1.0
043: */
044: public class XsltProjectOperations implements
045: DeleteOperationImplementation, CopyOperationImplementation,
046: MoveOperationImplementation {
047:
048: private XsltproProject project;
049:
050: public XsltProjectOperations(XsltproProject project) {
051: this .project = project;
052: }
053:
054: public List<FileObject> getMetadataFiles() {
055: FileObject projectDirectory = project.getProjectDirectory();
056: List<FileObject> files = new ArrayList<FileObject>();
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(
063: projectDirectory,
064: org.netbeans.modules.xml.retriever.XMLCatalogProvider.TYPE_RETRIEVED,
065: files); //NOI18N
066:
067: return files;
068: }
069:
070: public List<FileObject> getDataFiles() {
071: List<FileObject> files = new ArrayList<FileObject>();
072:
073: files.add(project.getSourceDirectory());
074:
075: PropertyEvaluator evaluator = project.evaluator();
076: String prop = evaluator
077: .getProperty(IcanproProjectProperties.SOURCE_ROOT);
078: if (prop != null) {
079: FileObject projectDirectory = project.getProjectDirectory();
080: FileObject srcDir = project.getAntProjectHelper()
081: .resolveFileObject(prop);
082: if (projectDirectory != srcDir && !files.contains(srcDir)) {
083: files.add(srcDir);
084: }
085: }
086:
087: return files;
088: }
089:
090: public void notifyDeleting() throws IOException {
091: XsltproActionProvider ap = project.getLookup().lookup(
092: XsltproActionProvider.class);
093: assert ap != null;
094:
095: Lookup context = Lookups.fixed(new Object[0]);
096: Properties p = new Properties();
097: String[] targetNames = ap.getTargetNames(
098: ActionProvider.COMMAND_CLEAN, context, p);
099: FileObject buildXML = project.getProjectDirectory()
100: .getFileObject(GeneratedFilesHelper.BUILD_XML_PATH);
101:
102: assert targetNames != null;
103: assert targetNames.length > 0;
104:
105: ActionUtils.runTarget(buildXML, targetNames, p).waitFinished();
106: }
107:
108: public void notifyDeleted() throws IOException {
109:
110: project.getAntProjectHelper().notifyDeleted();
111: }
112:
113: public void notifyCopying() throws IOException {
114: // do nothing.
115: // This does copy the old distribution file over though, which is
116: // probably OK because "ant clean" will clean it up.
117: }
118:
119: public void notifyCopied(Project original, File originalPath,
120: String newName) throws IOException {
121: if (original == null) {
122: // do nothing for the original project.
123: return;
124: }
125:
126: project.getReferenceHelper().fixReferences(originalPath);
127:
128: String oldName = project.getName();
129: project.setName(newName);
130: }
131:
132: public void notifyMoving() throws IOException {
133: notifyDeleting();
134: }
135:
136: public void notifyMoved(Project original, File originalPath,
137: String newName) throws IOException {
138: if (original == null) {
139: project.getAntProjectHelper().notifyDeleted();
140: return;
141: }
142: String oldName = project.getName();
143: project.setName(newName);
144: project.getReferenceHelper().fixReferences(originalPath);
145: }
146:
147: private static void addFile(FileObject projectDirectory,
148: String fileName, List<FileObject> result) {
149: FileObject file = projectDirectory.getFileObject(fileName);
150:
151: if (file != null) {
152: result.add(file);
153: }
154: }
155: }
|