Index: projects/projectuiapi/src/org/netbeans/spi/project/ui/support/CommonProjectActions.java =================================================================== RCS file: /cvs/projects/projectuiapi/src/org/netbeans/spi/project/ui/support/CommonProjectActions.java,v retrieving revision 1.12 diff -u -r1.12 CommonProjectActions.java --- projects/projectuiapi/src/org/netbeans/spi/project/ui/support/CommonProjectActions.java 14 Jul 2005 20:32:53 -0000 1.12 +++ projects/projectuiapi/src/org/netbeans/spi/project/ui/support/CommonProjectActions.java 29 Jul 2005 14:57:31 -0000 @@ -113,6 +113,48 @@ } /** + * Create an action "Copy Project". + * It should be invoked with an action context containing + * one or more {@link org.netbeans.api.project.Project}s. + *

+ * You might include this in the context menu of a logical view. + *

+ * @since 1.10 + * @return an action + */ + public static Action copyProjectAction() { + return Utilities.getActionsFactory().copyProjectAction(); + } + + /** + * Create an action "Move Project". + * It should be invoked with an action context containing + * one or more {@link org.netbeans.api.project.Project}s. + *

+ * You might include this in the context menu of a logical view. + *

+ * @since 1.10 + * @return an action + */ + public static Action moveProjectAction() { + return Utilities.getActionsFactory().moveProjectAction(); + } + + /** + * Create an action "Rename Project". + * It should be invoked with an action context containing + * one or more {@link org.netbeans.api.project.Project}s. + *

+ * You might include this in the context menu of a logical view. + *

+ * @since 1.10 + * @return an action + */ + public static Action renameProjectAction() { + return Utilities.getActionsFactory().renameProjectAction(); + } + + /** * Creates action that invokes New Project wizard. * *

{@link #EXISTING_SOURCES_FOLDER} keyed action Index: projects/projectuiapi/src/org/netbeans/spi/project/ui/support/DefaultProjectOperations.java =================================================================== RCS file: projects/projectuiapi/src/org/netbeans/spi/project/ui/support/DefaultProjectOperations.java diff -N projects/projectuiapi/src/org/netbeans/spi/project/ui/support/DefaultProjectOperations.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ projects/projectuiapi/src/org/netbeans/spi/project/ui/support/DefaultProjectOperations.java 29 Jul 2005 14:57:31 -0000 @@ -0,0 +1,130 @@ +/* + * Sun Public License Notice + * + * The contents of this file are subject to the Sun Public License + * Version 1.0 (the "License"). You may not use this file except in + * compliance with the License. A copy of the License is available at + * http://www.sun.com/ + * + * The Original Code is NetBeans. The Initial Developer of the Original + * Code is Sun Microsystems, Inc. Portions Copyright 1997-2005 Sun + * Microsystems, Inc. All Rights Reserved. + */ +package org.netbeans.spi.project.ui.support; + +import org.netbeans.api.project.Project; +import org.netbeans.spi.project.support.ProjectOperations; +import org.netbeans.modules.project.uiapi.DefaultProjectOperationsImplementation; + +/**Support class to allow the project type implementors to perform {@link ProjectOperations} + * by simply calling a method in this class. Each method in this class provides a default + * confirmation dialog and default behavior. + * + * If the project type requires a different behavior of an operation, it is required to provide its + * own implementation of the operation. + * + * @since 1.10 + * @author Jan Lahoda + */ +public final class DefaultProjectOperations { + + /** + * Creates a new instance of DefaultProjectOperations + */ + private DefaultProjectOperations() { + } + + /**Perform default delete operation. Gathers all necessary data, shows a confirmation + * dialog and deletes the project (if confirmed by the user). + * + * @since 1.10 + * + * @param p project to delete + * @throws IllegalArgumentException if + * p == null or + * if {@link org.netbeans.api.projects.ProjectOperations.isDeleteOperationSupported} + * returns false for this project. + */ + public static void performDefaultDeleteOperation(Project p) throws IllegalArgumentException { + if (p == null) { + throw new IllegalArgumentException("Project is null"); + } + + if (!ProjectOperations.isDeleteOperationSupported(p)) { + throw new IllegalStateException("Attempt to delete project that does not support deletion."); + } + + DefaultProjectOperationsImplementation.deleteProject(p); + } + + /**Perform default copy operation. Gathers all necessary data, shows a confirmation + * dialog and copies the project (if confirmed by the user). + * + * @since 1.10 + * + * @param p project to copy + * @throws IllegalArgumentException if + * p == null or + * {@link org.netbeans.api.projects.ProjectOperations.isCopyOperationSupported} + * returns false for this project. + */ + public static void performDefaultCopyOperation(Project p) throws IllegalArgumentException { + if (p == null) { + throw new IllegalArgumentException("Project is null"); + } + + if (!ProjectOperations.isCopyOperationSupported(p)) { + throw new IllegalStateException("Attempt to delete project that does not support copy."); + } + + DefaultProjectOperationsImplementation.copyProject(p); + } + + /**Perform default move operation. Gathers all necessary data, shows a confirmation + * dialog and moves the project (if confirmed by the user). + * + * @since 1.10 + * + * @param p project to move + * @throws IllegalArgumentException if + * p == null or + * {@link org.netbeans.api.projects.ProjectOperations.ismoveOperationSupported} + * returns false for this project. + */ + public static void performDefaultMoveOperation(Project p) throws IllegalArgumentException { + if (p == null) { + throw new IllegalArgumentException("Project is null"); + } + + if (!ProjectOperations.isMoveOperationSupported(p)) { + throw new IllegalStateException("Attempt to delete project that does not support move."); + } + + DefaultProjectOperationsImplementation.moveProject(p); + } + + /**Perform default rename operation. Gathers all necessary data, shows a confirmation + * dialog and renames the project (if confirmed by the user). + * + * @since 1.10 + * + * @param p project to move + * @param newName new project's name or null + * @throws IllegalArgumentException if + * p == null or + * {@link org.netbeans.api.projects.ProjectOperations.ismoveOperationSupported} + * returns false for this project. + */ + public static void performDefaultRenameOperation(Project p, String newName) throws IllegalStateException { + if (p == null) { + throw new IllegalArgumentException("Project is null"); + } + + if (!ProjectOperations.isMoveOperationSupported(p)) { + throw new IllegalStateException("Attempt to delete project that does not support move."); + } + + DefaultProjectOperationsImplementation.renameProject(p, newName); + } + +} Index: ant/project/src/org/netbeans/spi/project/support/ant/AntProjectHelper.java =================================================================== RCS file: /cvs/ant/project/src/org/netbeans/spi/project/support/ant/AntProjectHelper.java,v retrieving revision 1.31 diff -u -r1.31 AntProjectHelper.java --- ant/project/src/org/netbeans/spi/project/support/ant/AntProjectHelper.java 11 Jul 2005 12:18:05 -0000 1.31 +++ ant/project/src/org/netbeans/spi/project/support/ant/AntProjectHelper.java 29 Jul 2005 14:57:31 -0000 @@ -29,7 +29,6 @@ import org.netbeans.api.project.ProjectManager; import org.netbeans.api.project.ant.AntArtifact; import org.netbeans.modules.project.ant.AntBasedProjectFactorySingleton; -import org.netbeans.modules.project.ant.DefaultAntProjectOperations; import org.netbeans.modules.project.ant.FileChangeSupport; import org.netbeans.modules.project.ant.FileChangeSupportEvent; import org.netbeans.modules.project.ant.FileChangeSupportListener; @@ -38,7 +37,7 @@ import org.netbeans.spi.project.AuxiliaryConfiguration; import org.netbeans.spi.project.CacheDirectoryProvider; import org.netbeans.spi.project.ProjectState; -import org.netbeans.api.project.ProjectOperations; +import org.netbeans.spi.project.support.ProjectOperations; import org.netbeans.spi.queries.FileBuiltQueryImplementation; import org.netbeans.spi.queries.SharabilityQueryImplementation; import org.openide.ErrorManager; @@ -482,26 +481,6 @@ state.notifyDeleted(); } - /**Perform default delete operation. Gathers all necessary data, shows a confirmation - * dialog and deletes the project (if confirmed by the user). - * - * @since 1.8 - * - * @throws IllegalStateException if - * {@link org.netbeans.api.projects.ProjectOperations.getDefault().isDeleteOperationSupported} - * returns false for this project. - */ - public void performDefaultDeleteOperation() throws IllegalStateException { - Project p = AntBasedProjectFactorySingleton.getProjectFor(this); - - assert p != null; - - if (!ProjectOperations.getDefault().isDeleteOperationSupported(p)) { - throw new IllegalStateException("Attempt to delete project that does not support deletion."); - } - - DefaultAntProjectOperations.deleteProject(p); - } /** * Mark this project as being modified without actually changing anything in it. Index: ant/project/src/org/netbeans/spi/project/support/ant/ReferenceHelper.java =================================================================== RCS file: /cvs/ant/project/src/org/netbeans/spi/project/support/ant/ReferenceHelper.java,v retrieving revision 1.26 diff -u -r1.26 ReferenceHelper.java --- ant/project/src/org/netbeans/spi/project/support/ant/ReferenceHelper.java 3 Apr 2005 01:29:16 -0000 1.26 +++ ant/project/src/org/netbeans/spi/project/support/ant/ReferenceHelper.java 29 Jul 2005 14:57:32 -0000 @@ -19,7 +19,9 @@ import java.net.URISyntaxException; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collection; import java.util.Collections; +import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.List; @@ -1229,6 +1231,91 @@ */ AntProjectHelper getAntProjectHelper() { return h; + } + + /**Tries to fix references after copy/rename/move operation on the project. + * Handles relative/absolute paths. + * + * @param originalPath the project folder of the original project + * @see org.netbeans.spi.project.CopyOperationImplementation + * @see org.netbeans.spi.project.MoveOperationImplementation + * @since 1.9 + */ + public void fixReferences(File originalPath) { + String[] prefixesToFix = new String[] {"file.reference.", "project."}; + EditableProperties pub = h.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH); + EditableProperties priv = h.getProperties(AntProjectHelper.PRIVATE_PROPERTIES_PATH); + + File projectDir = FileUtil.toFile(h.getProjectDirectory()); + + List pubRemove = new ArrayList(); + List privRemove = new ArrayList(); + Map pubAdd = new HashMap(); + Map privAdd = new HashMap(); + + for (Iterator i = pub.entrySet().iterator(); i.hasNext(); ) { + Map.Entry e = (Map.Entry) i.next(); + String key = (String) e.getKey(); + boolean cont = false; + + for (int cntr = 0; cntr < prefixesToFix.length; cntr++) { + if (key.startsWith(prefixesToFix[cntr])) { + cont = true; + break; + } + } + if (!cont) + continue; + + String value = (String) e.getValue(); + + File absolutePath = FileUtil.normalizeFile(PropertyUtils.resolveFile(originalPath, value)); + + //TODO: extra base dir relativization: + if (!CollocationQuery.areCollocated(absolutePath, projectDir)) { + pubRemove.add(key); + privAdd.put(key, absolutePath.getAbsolutePath()); + } + } + + for (Iterator i = priv.entrySet().iterator(); i.hasNext(); ) { + Map.Entry e = (Map.Entry) i.next(); + String key = (String) e.getKey(); + boolean cont = false; + + for (int cntr = 0; cntr < prefixesToFix.length; cntr++) { + if (key.startsWith(prefixesToFix[cntr])) { + cont = true; + break; + } + } + if (!cont) + continue; + + String value = (String) e.getValue(); + + File absolutePath = FileUtil.normalizeFile(PropertyUtils.resolveFile(originalPath, value)); + + //TODO: extra base dir relativization: + if (CollocationQuery.areCollocated(absolutePath, projectDir)) { + privRemove.add(key); + pubAdd.put(key, PropertyUtils.relativizeFile(projectDir, absolutePath)); + } + } + + for (Iterator i = pubRemove.iterator(); i.hasNext(); ) { + pub.remove(i.next()); + } + + for (Iterator i = privRemove.iterator(); i.hasNext(); ) { + priv.remove(i.next()); + } + + pub.putAll(pubAdd); + priv.putAll(privAdd); + + h.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, pub); + h.putProperties(AntProjectHelper.PRIVATE_PROPERTIES_PATH, priv); } /** Index: ant/project/apichanges.xml =================================================================== RCS file: /cvs/ant/project/apichanges.xml,v retrieving revision 1.7 diff -u -r1.7 apichanges.xml --- ant/project/apichanges.xml 11 Jul 2005 12:18:02 -0000 1.7 +++ ant/project/apichanges.xml 29 Jul 2005 14:57:33 -0000 @@ -78,14 +78,13 @@ -

Basic Support SPI for Project Delete - + Basic Support SPI for Project Delete/Copy/Rename/Move + - AntProjectHelper.notifyDeleted() and AntProjectHelper.performDefaultDeleteOperation() - added. + Added AntProjectHelper.notifyDeleted(). Added ReferenceHelper.fixReferences. Index: ant/project/manifest.mf =================================================================== RCS file: /cvs/ant/project/manifest.mf,v retrieving revision 1.11 diff -u -r1.11 manifest.mf --- ant/project/manifest.mf 11 Jul 2005 12:18:02 -0000 1.11 +++ ant/project/manifest.mf 29 Jul 2005 14:57:33 -0000 @@ -1,5 +1,5 @@ Manifest-Version: 1.0 OpenIDE-Module: org.netbeans.modules.project.ant/1 -OpenIDE-Module-Specification-Version: 1.8 +OpenIDE-Module-Specification-Version: 1.9 OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/project/ant/Bundle.properties Index: projects/projectapi/apichanges.xml =================================================================== RCS file: /cvs/projects/projectapi/apichanges.xml,v retrieving revision 1.4 diff -u -r1.4 apichanges.xml --- projects/projectapi/apichanges.xml 11 Jul 2005 12:18:06 -0000 1.4 +++ projects/projectapi/apichanges.xml 29 Jul 2005 14:57:33 -0000 @@ -76,31 +76,32 @@ - + - Support for project delete - - + Added support for project delete/copy/rename/move + + - -

- As only the ProjectManager is allowed to implement ProjectState interface, - this change should not directly affect any clients. -

+

- The notifyDeleted action is added to the ProjectState, - allowing the project implmentation to let the ProjectManager - know that the project has been deleted. ProjectManager.isValid(Project) added - to detect deleted projects. -

-

- ProjectOperations and ProjectOperationsImplementation added to support - project delete operation. + Introduced: +

    +
  • + New method notifyDeleted added to ProjectState. +
  • +
  • + Interfaces DataFilesProviderImplementation, DeleteOperationImplementation, CopyOperationImplementation, MoveOperationImplementation has + been added to support project delete/copy/rename/move. +
  • +
  • + Support class ProjectOperations has been added to simplify operations on compound projects. +
  • +

- +
Index: projects/projectapi/manifest.mf =================================================================== RCS file: /cvs/projects/projectapi/manifest.mf,v retrieving revision 1.9 diff -u -r1.9 manifest.mf --- projects/projectapi/manifest.mf 11 Jul 2005 12:18:06 -0000 1.9 +++ projects/projectapi/manifest.mf 29 Jul 2005 14:57:33 -0000 @@ -1,5 +1,5 @@ Manifest-Version: 1.0 OpenIDE-Module: org.netbeans.modules.projectapi/1 -OpenIDE-Module-Specification-Version: 1.6 +OpenIDE-Module-Specification-Version: 1.7 OpenIDE-Module-Localizing-Bundle: org/netbeans/modules/projectapi/Bundle.properties Index: projects/projectapi/src/org/netbeans/api/project/ProjectOperations.java =================================================================== RCS file: projects/projectapi/src/org/netbeans/api/project/ProjectOperations.java diff -N projects/projectapi/src/org/netbeans/api/project/ProjectOperations.java --- projects/projectapi/src/org/netbeans/api/project/ProjectOperations.java 11 Jul 2005 12:18:07 -0000 1.1 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,134 +0,0 @@ -/* - * Sun Public License Notice - * - * The contents of this file are subject to the Sun Public License - * Version 1.0 (the "License"). You may not use this file except in - * compliance with the License. A copy of the License is available at - * http://www.sun.com/ - * - * The Original Code is NetBeans. The Initial Developer of the Original - * Code is Sun Microsystems, Inc. Portions Copyright 1997-2005 Sun - * Microsystems, Inc. All Rights Reserved. - */ - -package org.netbeans.api.project; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Iterator; -import java.util.List; -import org.netbeans.spi.project.ProjectOperationsImplementation.DataFilesProviderImplementation; -import org.netbeans.spi.project.ProjectOperationsImplementation.DeleteOperationImplementation; -import org.openide.util.Lookup; - -/**Allows gathering information for vaious project operations (currently only project delete, but will - * be extended in the future). - * - *

Project Delete Operation - * - * Consists of {@link #getMetadataFiles(Project) getMetadataFiles}, - * {@link #getDataFiles(Project) getDataFiles}, {@link #performClean(Project) performClean} - * and {@link #notifyDeleted(Project) notifyDeleted}. - * - * The delete operation should run in two phases: preparation, when - * {@link #getMetadataFiles(Project) getMetadataFiles} and {@link #getDataFiles(Project) getDataFiles} - * (any number of times, - * in any order) are called and performing, when {@link #performClean(Project) performClean} should be called, - * then the files previously returned should be deleted (as required by the user) - * and finally {@link #notifyDeleted(Project) notifyDeleted} should be called. - * - * @since 1.6 - * @author Jan Lahoda - */ -public final class ProjectOperations { - - private static ProjectOperations INSTANCE = null; - - public static synchronized ProjectOperations getDefault() { - if (INSTANCE == null) { - INSTANCE = new ProjectOperations(); - } - - return INSTANCE; - } - - private ProjectOperations() { - } - - /**Return list of files that are considered metadata files and folders for the given project. - * Returns meaningfull values only if some of the is*Supported methods - * return true. - * - * @param prj project to test - * @return list of metadata files/folders - */ - public List/**/ getMetadataFiles(Project prj) { - List/**/ result = new ArrayList(); - - for (Iterator i = getProjectsOperationsImplementation(prj).iterator(); i.hasNext(); ) { - result.addAll(((DataFilesProviderImplementation) i.next()).getMetadataFiles()); - } - - return result; - } - - /**Return list of files that are considered source files and folders for the given project. - * Returns meaningfull values only if some of the is*Supported methods - * return true. - * - * @param prj project to test - * @return list of data files/folders - */ - public List/**/ getDataFiles(Project prj) { - List/**/ result = new ArrayList(); - - for (Iterator i = getProjectsOperationsImplementation(prj).iterator(); i.hasNext(); ) { - result.addAll(((DataFilesProviderImplementation) i.next()).getDataFiles()); - } - - return result; - } - - /**Test whether the delete operation is supported on the given project. - * - * - * @param prj project to test - * @return true if the project supports delete operation, - * false otherwise - */ - public boolean isDeleteOperationSupported(Project prj) { - return !getDeleteOperationImplementation(prj).isEmpty(); - } - - /**Performs pre-delete clean of the project. Should be called immediatelly before - * the project is deleted. - * - * @param prj project to clean - */ - public void performClean(Project prj) throws IOException { - for (Iterator i = getDeleteOperationImplementation(prj).iterator(); i.hasNext(); ) { - ((DeleteOperationImplementation) i.next()).performClean(); - } - } - - /**Post-delete notification that the project has been deleted.. Should be called immediatelly after - * the project is deleted. - * - * @param prj deleted project - */ - public void notifyDeleted(Project prj) throws IOException { - for (Iterator i = getDeleteOperationImplementation(prj).iterator(); i.hasNext(); ) { - ((DeleteOperationImplementation) i.next()).notifyDeleted(); - } - } - - private Collection/**/ getDeleteOperationImplementation(Project prj) { - return prj.getLookup().lookup(new Lookup.Template(DeleteOperationImplementation.class)).allInstances(); - } - - private Collection/**/ getProjectsOperationsImplementation(Project prj) { - return prj.getLookup().lookup(new Lookup.Template(DataFilesProviderImplementation.class)).allInstances(); - } - -} Index: projects/projectapi/src/org/netbeans/spi/project/ActionProvider.java =================================================================== RCS file: /cvs/projects/projectapi/src/org/netbeans/spi/project/ActionProvider.java,v retrieving revision 1.7 diff -u -r1.7 ActionProvider.java --- projects/projectapi/src/org/netbeans/spi/project/ActionProvider.java 11 Jul 2005 12:18:08 -0000 1.7 +++ projects/projectapi/src/org/netbeans/spi/project/ActionProvider.java 29 Jul 2005 14:57:33 -0000 @@ -94,6 +94,27 @@ String COMMAND_DELETE = "delete"; // NOI18N /** + * Standard command for deleting the project. + * + * @since 1.7 + */ + String COMMAND_COPY = "copy"; // NOI18N + + /** + * Standard command for deleting the project. + * + * @since 1.7 + */ + String COMMAND_MOVE = "move"; // NOI18N + + /** + * Standard command for deleting the project. + * + * @since 1.7 + */ + String COMMAND_RENAME = "rename"; // NOI18N + + /** * Get a list of all commands which this project supports. * @return a list of command names suitable for {@link #invokeAction} * @see #COMMAND_BUILD Index: projects/projectapi/src/org/netbeans/spi/project/CopyOperationImplementation.java =================================================================== RCS file: projects/projectapi/src/org/netbeans/spi/project/CopyOperationImplementation.java diff -N projects/projectapi/src/org/netbeans/spi/project/CopyOperationImplementation.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ projects/projectapi/src/org/netbeans/spi/project/CopyOperationImplementation.java 29 Jul 2005 14:57:33 -0000 @@ -0,0 +1,64 @@ +/* + * Sun Public License Notice + * + * The contents of this file are subject to the Sun Public License + * Version 1.0 (the "License"). You may not use this file except in + * compliance with the License. A copy of the License is available at + * http://www.sun.com/ + * + * The Original Code is NetBeans. The Initial Developer of the Original + * Code is Sun Microsystems, Inc. Portions Copyright 1997-2005 Sun + * Microsystems, Inc. All Rights Reserved. + */ +package org.netbeans.spi.project; + +import java.io.File; +import java.io.IOException; +import org.netbeans.api.project.Project; + +/** + * Project Copy Operation. Allows to gather information necessary for project + * copy and also provides callbacks to the project type to handle special + * checkpoints during the copy process. + * + * An implementation of this interface may be registered in the project's lookup to support + * copy operation in the following cases: + *

    + *
  • The project type wants to use the {@link org.netbeans.spi.project.ui.support DefaultProjectOperationsImplementation} + * to perform the copy operation. + *
  • + *
  • If this project may be part of of a compound project (like EJB project is a part of a J2EE project), + * and the compound project wants to copy all the sub-projects. + *
  • + *
+ * + * The project type is not required to put an implementation of this interface into the project's + * lookup if the above two cases should not be supported. + * + * @author Jan Lahoda + * @since 1.7 + */ +public interface CopyOperationImplementation extends DataFilesProviderImplementation { + + /**Pre-copy notification. The exact meaning is left on the project implementors, but + * typically this means to undeloy the application and remove all artifacts + * created by the build project. + * + * @throws IOException if an I/O operation fails. + */ + public void notifyCopying() throws IOException; + + /**Notification that the copy operation has finished. Is supposed to fix the + * newly created (copied) project into the correct state (including changing its display name + * to nueName). Should be called on both original and newly created project (in this order). + * + * @param original the original project + * @param originalPath the project folder of the original project (for consistency + * with MoveOperationImplementation.notifyMoved) + * @param nueName new name for the newly created project. + * + * @throws IOException if an I/O operation fails. + */ + public void notifyCopied(Project original, File originalPath, String nueName) throws IOException; + +} Index: projects/projectapi/src/org/netbeans/spi/project/DataFilesProviderImplementation.java =================================================================== RCS file: projects/projectapi/src/org/netbeans/spi/project/DataFilesProviderImplementation.java diff -N projects/projectapi/src/org/netbeans/spi/project/DataFilesProviderImplementation.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ projects/projectapi/src/org/netbeans/spi/project/DataFilesProviderImplementation.java 29 Jul 2005 14:57:33 -0000 @@ -0,0 +1,45 @@ +/* + * Sun Public License Notice + * + * The contents of this file are subject to the Sun Public License + * Version 1.0 (the "License"). You may not use this file except in + * compliance with the License. A copy of the License is available at + * http://www.sun.com/ + * + * The Original Code is NetBeans. The Initial Developer of the Original + * Code is Sun Microsystems, Inc. Portions Copyright 1997-2005 Sun + * Microsystems, Inc. All Rights Reserved. + */ +package org.netbeans.spi.project; + +import java.util.List; +import org.openide.filesystems.FileObject; + +/** + * Base for various Project Operations, allows to gather metadata and data files + * for a project. + * + * @author Jan Lahoda + * @since 1.7 + */ +public interface DataFilesProviderImplementation { + + /** + * Returns list of {@link FileObject}s the are considered to be metadata files + * and folders belonging into this project. + * See {@link ProjectOperations#getMetadataFiles()} for more information. + * + * @return list of {@link FileObject}s that are considered metadata files and folders. + */ + public List/**/ getMetadataFiles(); + + /** + * Returns list of {@link FileObject}s the are considered to be data files and folders + * belonging into this project. + * See {@link ProjectOperations#getDataFiles()} for more information. + * + * @return list of {@link FileObject}s that are considered data files and folders. + */ + public List/**/ getDataFiles(); + +} Index: projects/projectapi/src/org/netbeans/spi/project/DeleteOperationImplementation.java =================================================================== RCS file: projects/projectapi/src/org/netbeans/spi/project/DeleteOperationImplementation.java diff -N projects/projectapi/src/org/netbeans/spi/project/DeleteOperationImplementation.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ projects/projectapi/src/org/netbeans/spi/project/DeleteOperationImplementation.java 29 Jul 2005 14:57:33 -0000 @@ -0,0 +1,56 @@ +/* + * Sun Public License Notice + * + * The contents of this file are subject to the Sun Public License + * Version 1.0 (the "License"). You may not use this file except in + * compliance with the License. A copy of the License is available at + * http://www.sun.com/ + * + * The Original Code is NetBeans. The Initial Developer of the Original + * Code is Sun Microsystems, Inc. Portions Copyright 1997-2005 Sun + * Microsystems, Inc. All Rights Reserved. + */ +package org.netbeans.spi.project; + +import java.io.IOException; + +/** + * Project Delete Operation. Allows to gather information necessary for project + * delete and also provides callbacks to the project type to handle special + * checkpoints during the delete. + * + * An implementation of this interface may be registered in the project's lookup to support + * delete operation in the following cases: + *
    + *
  • The project type wants to use the {@link org.netbeans.spi.project.ui.support.DefaultProjectOperationsImplementation} + * to perform the delete operation. + *
  • + *
  • If this project may be part of of a compound project (like EJB project is a part of a J2EE project), + * and the compound project wants to delete all the sub-projects. + *
  • + *
+ * + * The project type is not required to put an implementation of this interface into the project's + * lookup if the above two cases should not be supported. + * + * @author Jan Lahoda + * @since 1.7 + */ +public interface DeleteOperationImplementation extends DataFilesProviderImplementation { + + /**Pre-delete notification. The exact meaning is left on the project implementors, but + * typically this means to undeloy the application and remove all artifacts + * created by the build project. + * + * @throws IOException if an I/O operation fails. + */ + public void notifyDeleting() throws IOException; + + /**Notification that the delete operation has finished. Is supposed to perform + * final cleanup and to call {@link ProjectState#notifyDeleted}. + * + * @throws IOException if an I/O operation fails. + */ + public void notifyDeleted() throws IOException; + +} Index: projects/projectapi/src/org/netbeans/spi/project/MoveOperationImplementation.java =================================================================== RCS file: projects/projectapi/src/org/netbeans/spi/project/MoveOperationImplementation.java diff -N projects/projectapi/src/org/netbeans/spi/project/MoveOperationImplementation.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ projects/projectapi/src/org/netbeans/spi/project/MoveOperationImplementation.java 29 Jul 2005 14:57:33 -0000 @@ -0,0 +1,64 @@ +/* + * Sun Public License Notice + * + * The contents of this file are subject to the Sun Public License + * Version 1.0 (the "License"). You may not use this file except in + * compliance with the License. A copy of the License is available at + * http://www.sun.com/ + * + * The Original Code is NetBeans. The Initial Developer of the Original + * Code is Sun Microsystems, Inc. Portions Copyright 1997-2005 Sun + * Microsystems, Inc. All Rights Reserved. + */ +package org.netbeans.spi.project; + +import java.io.File; +import java.io.IOException; +import org.netbeans.api.project.Project; + +/** + * Project Rename/Move Operation. Allows to gather information necessary for project + * move and also provides callbacks to the project type to handle special + * checkpoints during the delete. + * + * An implementation of this interface may be registered in the project's lookup to support + * move operation in the following cases: + *
    + *
  • The project type wants to use the {@link org.netbeans.spi.project.ui.support.DefaultProjectOperationsImplementation} + * to perform the rename/move operation. + *
  • + *
  • If this project may be part of of a compound project (like EJB project is a part of a J2EE project), + * and the compound project wants to rename/move all the sub-projects. + *
  • + *
+ * + * The project type is not required to put an implementation of this interface into the project's + * lookup if the above two cases should not be supported. + * + * @author Jan Lahoda + * @since 1.7 + */ +public interface MoveOperationImplementation extends DataFilesProviderImplementation { + + /**Pre-move notification. The exact meaning is left on the project implementors, but + * typically this means to undeloy the application and remove all artifacts + * created by the build project. + * + * @throws IOException if an I/O operation fails. + */ + public void notifyMoving() throws IOException; + + /**Notification that the move operation has finished. Is supposed to fix the + * newly created (moved) project into the correct state (including changing its display name + * to nueName) and call {@link ProjectState#notifyDeleted} on the original project. + * Should be called on both original and newly created project (in this order). + * + * @param original the original project + * @param originalPath the project folder of the original project + * @param nueName new name for the newly created project. + * + * @throws IOException if an I/O operation fails. + */ + public void notifyMoved(Project original, File originalPath, String nueName) throws IOException; + +} Index: projects/projectapi/src/org/netbeans/spi/project/ProjectOperationsImplementation.java =================================================================== RCS file: projects/projectapi/src/org/netbeans/spi/project/ProjectOperationsImplementation.java diff -N projects/projectapi/src/org/netbeans/spi/project/ProjectOperationsImplementation.java --- projects/projectapi/src/org/netbeans/spi/project/ProjectOperationsImplementation.java 11 Jul 2005 12:18:08 -0000 1.1 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,84 +0,0 @@ -/* - * Sun Public License Notice - * - * The contents of this file are subject to the Sun Public License - * Version 1.0 (the "License"). You may not use this file except in - * compliance with the License. A copy of the License is available at - * http://www.sun.com/ - * - * The Original Code is NetBeans. The Initial Developer of the Original - * Code is Sun Microsystems, Inc. Portions Copyright 1997-2005 Sun - * Microsystems, Inc. All Rights Reserved. - */ - -package org.netbeans.spi.project; - -import java.io.IOException; -import java.util.List; -import org.netbeans.api.project.ProjectOperations; - -/**This is only a scope class that holds several project operation interfaces. - * See particular interface for more information: - *
  • - *
      {@link DeleteOperationImplementation DeleteOperationImplementation}
    - *
  • - * - * @since 1.6 - * @author Jan Lahoda - */ -public final class ProjectOperationsImplementation { - - /** - * Base for various Project Operations, allows to gather metadata and data files - * for a project. - */ - public interface DataFilesProviderImplementation { - - /** - * Returns list of {@link FileObject}s the are considered to be metadata files - * and folders belonging into this project. - * See {@link ProjectOperations#getMetadataFiles()} for more information. - * - * @return list of {@link FileObject}s that are considered metadata files and folders. - */ - public List/**/ getMetadataFiles(); - - /** - * Returns list of {@link FileObject}s the are considered to be data files and folders - * belonging into this project. - * See {@link ProjectOperations#getDataFiles()} for more information. - * - * @return list of {@link FileObject}s that are considered data files and folders. - */ - public List/**/ getDataFiles(); - - } - - /** - * Project Delete Operation. Allows to gather information necessary for project - * delete and also provides callbacks to the project type to handle special - * checkpoints during the delete. - * - * An implementation of this interface should be registered in the project to support - * delete operation. - */ - public interface DeleteOperationImplementation extends DataFilesProviderImplementation { - - /**Pre-delete clean. The exact meaning is left on the project implementors, but - * typically this means to undeloy the application and remove all artifacts - * created by the build project. - * - * @throws IOException if an I/O operation fails. - */ - public void performClean() throws IOException; - - /**Notification that the delete operation has finished. Is supposed to perform - * final cleanup and to call {@link ProjectState#notifyDeleted}. - * - * @throws IOException if an I/O operation fails. - */ - public void notifyDeleted() throws IOException; - - } - -} Index: projects/projectapi/src/org/netbeans/spi/project/support/ProjectOperations.java =================================================================== RCS file: projects/projectapi/src/org/netbeans/spi/project/support/ProjectOperations.java diff -N projects/projectapi/src/org/netbeans/spi/project/support/ProjectOperations.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ projects/projectapi/src/org/netbeans/spi/project/support/ProjectOperations.java 29 Jul 2005 14:57:33 -0000 @@ -0,0 +1,220 @@ +/* + * Sun Public License Notice + * + * The contents of this file are subject to the Sun Public License + * Version 1.0 (the "License"). You may not use this file except in + * compliance with the License. A copy of the License is available at + * http://www.sun.com/ + * + * The Original Code is NetBeans. The Initial Developer of the Original + * Code is Sun Microsystems, Inc. Portions Copyright 1997-2005 Sun + * Microsystems, Inc. All Rights Reserved. + */ + +package org.netbeans.spi.project.support; + +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Iterator; +import java.util.List; +import org.netbeans.api.project.Project; +import org.netbeans.spi.project.CopyOperationImplementation; +import org.netbeans.spi.project.DataFilesProviderImplementation; +import org.netbeans.spi.project.DeleteOperationImplementation; +import org.netbeans.spi.project.MoveOperationImplementation; +import org.openide.util.Lookup; + +/** + * Allows gathering information for various project operations. + * + * @author Jan Lahoda + * @since 1.7 + */ +public final class ProjectOperations { + + private ProjectOperations() { + } + + /**Return list of files that are considered metadata files and folders for the given project. + * Returns meaningfull values only if some of the is*Supported methods + * return true. + * + * @param prj project to test + * @return list of metadata files/folders + */ + public static List/**/ getMetadataFiles(Project prj) { + List/**/ result = new ArrayList(); + + for (Iterator i = getProjectsOperationsImplementation(prj).iterator(); i.hasNext(); ) { + result.addAll(((DataFilesProviderImplementation) i.next()).getMetadataFiles()); + } + + return result; + } + + /**Return list of files that are considered source files and folders for the given project. + * Returns meaningfull values only if some of the is*Supported methods + * return true. + * + * @param prj project to test + * @return list of data files/folders + */ + public static List/**/ getDataFiles(Project prj) { + List/**/ result = new ArrayList(); + + for (Iterator i = getProjectsOperationsImplementation(prj).iterator(); i.hasNext(); ) { + result.addAll(((DataFilesProviderImplementation) i.next()).getDataFiles()); + } + + return result; + } + + /**Test whether the delete operation is supported on the given project. + * + * @param prj project to test + * @return true if the project supports delete operation, + * false otherwise + */ + public static boolean isDeleteOperationSupported(Project prj) { + return !getDeleteOperationImplementation(prj).isEmpty(); + } + + /**Notification that the project is about to be deleted. + * Should be called immediatelly before the project is deleted. + * + * The project is supposed to do all required cleanup to allow the project to be deleted. + * + * @param prj project to notify + * @throws IOException is some error occurs + */ + public static void notifyDeleting(Project prj) throws IOException { + for (Iterator i = getDeleteOperationImplementation(prj).iterator(); i.hasNext(); ) { + ((DeleteOperationImplementation) i.next()).notifyDeleting(); + } + } + + /**Notification that the project has been deleted. + * Should be called immediatelly after the project is deleted. + * + * @param prj project to notify + * @throws IOException is some error occurs + */ + public static void notifyDeleted(Project prj) throws IOException { + for (Iterator i = getDeleteOperationImplementation(prj).iterator(); i.hasNext(); ) { + ((DeleteOperationImplementation) i.next()).notifyDeleted(); + } + } + + /**Test whether the copy operation is supported on the given project. + * + * @param prj project to test + * @return true if the project supports the copy operation, + * false otherwise + */ + public static boolean isCopyOperationSupported(Project prj) { + return !getCopyOperationImplementation(prj).isEmpty(); + } + + /**Notification that the project is about to be copyied. + * Should be called immediatelly before the project is copied. + * + * The project is supposed to do all required cleanup to allow the project to be copied. + * + * @param prj project to notify + * @throws IOException is some error occurs + */ + public static void notifyCopying(Project prj) throws IOException { + for (Iterator i = getCopyOperationImplementation(prj).iterator(); i.hasNext(); ) { + ((CopyOperationImplementation) i.next()).notifyCopying(); + } + } + + /**Notification that the project has been copied. + * Should be called immediatelly after the project is copied. + * + * The project is supposed to do all necessary fixes to the project's structure to + * form a valid project. + * + * Both original and newly created project (copy) are notified, in this order. + * + * @param original original project + * @param nue new project (copy) + * @param originalPath the project folder of the original project (for consistency with notifyMoved) + * @param name new name of the project + * @throws IOException is some error occurs + */ + public static void notifyCopied(Project original, Project nue, File originalPath, String name) throws IOException { + for (Iterator i = getCopyOperationImplementation(original).iterator(); i.hasNext(); ) { + ((CopyOperationImplementation) i.next()).notifyCopied(original, originalPath, name); + } + for (Iterator i = getCopyOperationImplementation(nue).iterator(); i.hasNext(); ) { + ((CopyOperationImplementation) i.next()).notifyCopied(original, originalPath, name); + } + } + + /**Notification that the project is about to be moved. + * Should be called immediatelly before the project is moved. + * + * The project is supposed to do all required cleanup to allow the project to be moved. + * + * @param prj project to notify + * @throws IOException is some error occurs + */ + public static void notifyMoving(Project prj) throws IOException { + for (Iterator i = getMoveOperationImplementation(prj).iterator(); i.hasNext(); ) { + ((MoveOperationImplementation) i.next()).notifyMoving(); + } + } + + /**Notification that the project has been moved. + * Should be called immediatelly after the project is moved. + * + * The project is supposed to do all necessary fixes to the project's structure to + * form a valid project. + * + * Both original and moved project are notified, in this order. + * + * @param original original project + * @param nue moved project + * @param originalPath the project folder of the original project + * @param name new name of the project + * @throws IOException is some error occurs + */ + public static void notifyMoved(Project original, Project nue, File originalPath, String name) throws IOException { + for (Iterator i = getMoveOperationImplementation(original).iterator(); i.hasNext(); ) { + ((MoveOperationImplementation) i.next()).notifyMoved(original, originalPath, name); + } + for (Iterator i = getMoveOperationImplementation(nue).iterator(); i.hasNext(); ) { + ((MoveOperationImplementation) i.next()).notifyMoved(original, originalPath, name); + } + } + + /**Test whether the move operation is supported on the given project. + * + * @param prj project to test + * @return true if the project supports the move operation, + * false otherwise + */ + public static boolean isMoveOperationSupported(Project prj) { + return true; + } + + private static Collection/**/ getDeleteOperationImplementation(Project prj) { + return prj.getLookup().lookup(new Lookup.Template(DeleteOperationImplementation.class)).allInstances(); + } + + private static Collection/**/ getProjectsOperationsImplementation(Project prj) { + return prj.getLookup().lookup(new Lookup.Template(DataFilesProviderImplementation.class)).allInstances(); + } + + private static Collection/**/ getCopyOperationImplementation(Project prj) { + return prj.getLookup().lookup(new Lookup.Template(CopyOperationImplementation.class)).allInstances(); + } + + private static Collection/**/ getMoveOperationImplementation(Project prj) { + return prj.getLookup().lookup(new Lookup.Template(MoveOperationImplementation.class)).allInstances(); + } + +}