/*
* Copyright 2008 Google Inc.
*
* Licensed under the Apache 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.apache.org/licenses/LICENSE-2.0
*
* 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 com.google.devtools.depan.filesystem.eclipse;
import com.google.devtools.depan.eclipse.editors.GraphDocument;
import com.google.devtools.depan.eclipse.utils.Resources;
import com.google.devtools.depan.eclipse.wizards.AbstractAnalysisWizard;
import com.google.devtools.depan.filesystem.FileSystemResources;
import com.google.devtools.depan.model.GraphModel;
import com.google.devtools.depan.model.builder.DependenciesListener;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import java.io.IOException;
/**
* Wizard for converting a file system tree into a DepAn analysis graph.
*
* @author <a href="leeca@google.com">Lee Carver</a>
*/
public class NewFileSystemWizard extends AbstractAnalysisWizard {
/**
* Eclipse extension identifier for this wizard.
*/
public static final String ANALYSIS_WIZARD_ID =
"com.google.devtools.depan.filesystem.eclipse.NewFileSystemWizard";
public NewFileSystemPage page;
/**
* Constructor for FileSystem wizard.
*/
public NewFileSystemWizard() {
super();
setNeedsProgressMonitor(true);
}
/**
* Adding the page to the wizard.
*/
@Override
public void addPages() {
page = new NewFileSystemPage(getSelection());
addPage(page);
}
@Override
protected String getOutputFileName() {
return page.getOutputFileName();
}
@Override
protected IFile getOutputFile() throws CoreException {
return page.getOutputFile();
}
@Override
protected int countAnalysisWork() {
return 2;
}
/**
* Create an analysis graph by traversing the file system tree from
* the named starting point.
*
* Note that this generates two (2) monitor.worked() calls.
*/
@Override
protected GraphDocument generateAnalysisDocument(IProgressMonitor monitor)
throws IOException {
// Step 1) Create the GraphModel to hold the analysis results
// TODO(leeca): Add filters, etc.
// TODO(leeca): Extend UI to allow lists of directories.
GraphModel result = new GraphModel();
DependenciesListener builder =
new FileSystemDependencyDispatcher(result.getBuilder());
monitor.worked(1);
// Step 2) Read through the file system to build the analysis graph
monitor.setTaskName("Loading file tree...");
TreeLoader loader = new TreeLoader(builder, page.getTreePrefix());
loader.analyzeTree(page.getPathText());
monitor.worked(1);
// Done
return createGraphDocument(result,
FileSystemResources.PLUGIN_ID, Resources.PLUGIN_ID);
}
}