Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright 2011-2012 The Kuali Foundation Licensed under the Educational Community License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.opensource.org/licenses/ecl2.php Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
 
 package org.kuali.maven.plugins.externals;
 
 import java.io.File;
 import java.util.List;
 
This mojo examines oldDir for any files that are not also in newDir. If it finds any, it deletes them from Subversion.

Goal:
dirsync
 
 public class DirSyncMojo extends AbstractMojo {
 
 	SVNUtils svnUtils = SVNUtils.getInstance();

The Maven project object

Parameter:
expression="${project}"
Readonly:
 
 	private MavenProject project;

The message to associate with the commit

Parameter:
expression="${externals.commitMessage}" default-value="Sync directories"
 
 	private String commitMessage;

This is the new directory containing files that should be under version control.

Parameter:
expression="${externals.newDir}"
Required:
 
 	private File newDir;

This is the old directory containing files that were previously under version control.

Parameter:
expression="${externals.oldDir}"
Required:
 
 	private File oldDir;

Regex pattern for files in new dir that should be included

Parameter:
expression="${externals.include}" default-value="\*\*\/\*"
 
 	private String include;

Regex pattern for files in new dir that should be excluded

Parameter:
expression="${externals.exclude}"
 
 	private String exclude;
 
 	public void execute() throws MojoExecutionException {
 		try {
 			getLog().info("Syncing directories");
 			getLog().info("New Dir - " + .getCanonicalPath());
 			getLog().info("Old Dir - " + .getCanonicalPath());
 			getLog().info("Include - " + );
 			getLog().info("Exclude - " + );
 			List<FileoldFiles = getFiles();
 			List<FilenewFiles = getFiles();
 			List<Filedeletes = getDeletableFiles(newFilesoldFiles);
 			if (deletes.size() == 0) {
 				getLog().info("No files to delete.");
 				return;
 			}
 			getLog().info("Located - " + deletes.size() + " files to delete");
			for (File delete : deletes) {
				getLog().info("Deleting " + delete);
			}
			SVNCommitInfo info = .commit(nullnull);
			getLog().info("Committed revision " + info.getNewRevision() + ".");
catch (Exception e) {
			throw new MojoExecutionException("Unexpected error"e);
		}
	}
	protected List<StringgetRelativePaths(File dirList<Filefilesthrows IOException {
		String path = dir.getCanonicalPath();
		List<Stringpaths = new ArrayList<String>();
		for (File file : files) {
			String filePath = file.getCanonicalPath();
			String s = StringUtils.remove(filePathpath);
			paths.add(s);
		}
		return paths;
	}
	protected List<FilegetDeletableFiles(File newDirFile oldDirList<FilenewFilesList<FileoldFilesthrows IOException {
		List<StringnewPaths = getRelativePaths(newDirnewFiles);
		List<StringoldPaths = getRelativePaths(oldDiroldFiles);
		List<FiledeletableFiles = new ArrayList<File>();
		for (int i = 0; i < oldPaths.size(); i++) {
			String path = oldPaths.get(i);
			if (!newPaths.contains(path)) {
				deletableFiles.add(oldFiles.get(i));
			}
		}
		return deletableFiles;
	}
	protected List<FilegetFiles(File dirString includeString exclude) {
		SimpleScanner scanner = new SimpleScanner(dirincludeexclude);
		return scanner.getFiles();
	}
	}
	public void setCommitMessage(String commitMessage) {
		this. = commitMessage;
	}
	public File getOldDir() {
		return ;
	}
	public void setOldDir(File oldDir) {
		this. = oldDir;
	}
	public File getNewDir() {
		return ;
	}
	public void setNewDir(File newDir) {
		this. = newDir;
	}
	public String getInclude() {
		return ;
	}
	public void setInclude(String include) {
		this. = include;
	}
	public String getExclude() {
		return ;
	}
	public void setExclude(String exclude) {
		this. = exclude;
	}
		return ;
	}
New to GrepCode? Check out our FAQ X