|
What this is
Other links
The source code
/*****************************************************************************
* 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 the CVS Client Library.
* The Initial Developer of the Original Code is Robert Greig.
* Portions created by Robert Greig are Copyright (C) 2000.
* All Rights Reserved.
*
* Contributor(s): Robert Greig.
*****************************************************************************/
package org.netbeans.lib.cvsclient.command.commit;
import java.io.*;
import java.util.*;
import org.netbeans.lib.cvsclient.*;
import org.netbeans.lib.cvsclient.admin.*;
import org.netbeans.lib.cvsclient.command.*;
import org.netbeans.lib.cvsclient.connection.*;
import org.netbeans.lib.cvsclient.event.*;
import org.netbeans.lib.cvsclient.request.*;
/**
* The command to commit any changes that have been made.
* @author Robert Greig
*/
public class CommitCommand extends BasicCommand {
/**
* The argument requests that must be added at the end.
* These argument requests indicate the files to be committed
*/
private final List argumentRequests = new LinkedList();
/**
* The log message used for the commit.
*/
private String message;
/**
* Forces the commit of the file(s) even if no changes were done.
* the standard behaviour is NOT-TO-BE recursive in this case.
*/
private boolean forceCommit;
/**
* The filename for the file that defines the message.
*/
private String logMessageFromFile;
/**
* Determines that no module program should run on the server.
*/
private boolean noModuleProgram;
/** Holds value of property toRevisionOrBranch. */
private String toRevisionOrBranch;
/**
* Construct a CommitCommand.
*/
public CommitCommand() {
resetCVSCommand();
}
/**
* Returns the commit message.
*/
public String getMessage() {
return message;
}
/**
* Sets the commit message.
*/
public void setMessage(String message) {
this.message = message;
}
/**
* Indicates whether the commit should be forced even if there are no
* changes.
*/
public boolean isForceCommit() {
return forceCommit;
}
/**
* Sets whether the commit should be forced even if there are no changes.
*/
public void setForceCommit(boolean forceCommit) {
this.forceCommit = forceCommit;
}
/**
* Adds the appropriate requests for a given directory.
* Sends a directory request followed by as many Entry and Modified requests
* as required.
* @param directory the directory to send requests for
* @throws IOException if an error occurs constructing the requests
*/
protected void addRequestsForDirectory(File directory)
throws IOException {
if (!directory.exists()) {
return;
}
// remove localPath prefix from directory. If left with
// nothing, use dot (".") in the directory request. Also remove the
// trailing slash
String dir = getRelativeToLocalPathInUnixStyle(directory);
try {
String repository = clientServices.getRepositoryForDirectory(
directory.getAbsolutePath());
requests.add(new DirectoryRequest(dir, repository));
String tag = clientServices.getStickyTagForDirectory(directory);
if (tag != null) {
requests.add(new StickyRequest(tag));
}
}
catch (IOException ex) {
System.err.println("An error occurred reading the respository " +
"for the directory " + dir + ": " + ex);
ex.printStackTrace();
}
// Obtain a set of all files known to CVS. We union
// this set with the set of files in the actual filesystem directory
// to obtain a set of files to commit (or at least attempt to commit).
Set set = clientServices.getAllFiles(directory);
// We must add the local files (and directories) because the above
// command does *not* return cvs controlled directories
final File[] files = directory.listFiles();
// get the union of the files in the directory and the files retrieved
// from the Entries file.
set.addAll(Arrays.asList(files));
List subdirectories = null;
if (isRecursive()) {
subdirectories = new LinkedList();
}
for (Iterator it = set.iterator(); it.hasNext();) {
File file = (File)it.next();
if (file.getName().equals("CVS")) { //NOI18N
continue;
}
try {
final Entry entry = clientServices.getEntry(file);
// a non-null entry means the file does exist in the
// Entries file for this directory
if (entry == null) {
continue;
}
// here file.isFile() is *not* used, because not existing
// files (removed ones) should also be sent
if (!file.isDirectory()) {
sendEntryAndModifiedRequests(entry, file);
}
else if (isRecursive() && file.isDirectory()) {
File cvsSubDir = new File(file, "CVS"); //NOI18N
if (cvsSubDir.exists()) {
subdirectories.add(file);
}
}
}
catch (IOException ex) {
System.err.println("An error occurred getting the " +
"Entry for file " + file + ": " + ex);
ex.printStackTrace();
}
}
if (isRecursive()) {
for (Iterator it = subdirectories.iterator(); it.hasNext();) {
File subdirectory = (File)it.next();
addRequestsForDirectory(subdirectory);
}
}
}
/**
* Add the appropriate requests for a single file.
* A directory request is sent, followed by an Entry and Modified request.
* @param file the file to send requests for
* @throws IOException if an error occurs constructing the requests
*/
protected void addRequestsForFile(File file)
throws IOException {
final File parentDirectory = file.getParentFile();
// remove localPath prefix from directory. If left with
// nothing, use dot (".") in the directory request
String dir = getRelativeToLocalPathInUnixStyle(parentDirectory);
try {
// send a argument request indicating the file to update
requests.add(new DirectoryRequest(dir, clientServices.
getRepositoryForDirectory(parentDirectory.
getAbsolutePath())));
String tag = clientServices.getStickyTagForDirectory(parentDirectory);
if (tag != null) {
requests.add(new StickyRequest(tag));
}
}
catch (IOException ex) {
System.err.println("An error occurred reading the respository " +
"for the directory " + dir + ": " + ex);
ex.printStackTrace();
}
try {
final Entry entry = clientServices.getEntry(file);
// a non-null entry means the file does exist in the
// Entries file for this directory
if (entry != null) {
sendEntryAndModifiedRequests(entry, file);
}
}
catch (IOException ex) {
System.err.println("An error occurred getting the Entry " +
"for file " + file + ": " + ex);
ex.printStackTrace();
}
}
/**
* Should return true if unchanged files should not be sent to server.
* If false is returned, all files will be sent to server
* This method is used by
|
| ... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.