📄 flowexportwizard.java
字号:
/*
* Copyright (c) 2003-2004, Alexander Greif
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the name of the Flow4J-Eclipse project nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
package net.orthanc.flow4j.designer.ui.wizards;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.lang.reflect.InvocationTargetException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import net.orthanc.flow4j.designer.core.Flow4JPlugin;
import org.eclipse.ant.core.AntRunner;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.ILibrary;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Plugin;
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.IPackageFragment;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.wizard.Wizard;
import org.eclipse.ui.IExportWizard;
import org.eclipse.ui.IWorkbench;
/**
* Wizard for flow documentation creation.
* @author greifa
*/
public class FlowExportWizard extends Wizard implements IExportWizard {
private FlowExportWizardPage mainPage;
private IStructuredSelection selection;
/**
* Constructor of this wizard.
* Sets the title.
*/
public FlowExportWizard() {
super();
setNeedsProgressMonitor(true);
setWindowTitle(Flow4JPlugin.getResourceString("Wizard_FlowDoc.windowTitle")); //$NON-NLS-1$
}
/**
* @see org.eclipse.ui.IWorkbenchWizard#init(org.eclipse.ui.IWorkbench, org.eclipse.jface.viewers.IStructuredSelection)
*/
public void init(IWorkbench workbench, IStructuredSelection selection) {
this.selection = selection;
}
/**
* Adds the wizard pages.
* @see org.eclipse.jface.wizard.IWizard#addPages()
*/
public void addPages() {
mainPage = new FlowExportWizardPage("flowExportWizardPage", Flow4JPlugin.getResourceString("Wizard_FlowDoc.pageTitle"), null); //$NON-NLS-1$ //$NON-NLS-2$
IProject[] projects =
(IProject[]) selection.toList().toArray(new IProject[0]);
mainPage.setSelectedProjects(projects);
addPage(mainPage);
}
/**
* @see org.eclipse.jface.wizard.IWizard#performFinish()
*/
public boolean performFinish() {
try {
getContainer().run(false, false, new IRunnableWithProgress() {
public void run(IProgressMonitor monitor)
throws InvocationTargetException {
doPerformFinish(monitor);
}
});
} catch (InterruptedException e) {
return true;
} catch (InvocationTargetException e) {
String message = e.getTargetException().getMessage();
if (message != null && message.length() > 0) {
MessageDialog.openError(
getShell(),
getWindowTitle(),
e.getTargetException().getMessage());
}
return false;
}
return true;
}
/**
* Does the actual export.
* Creates and runs the ant build flowFile for the docu generation.
* The build script is created in the plugin's temporary folder.
*/
private void doPerformFinish(IProgressMonitor monitor) {
String buildFileLocation = Flow4JPlugin.getDefault().getStateLocation().append("flowdoc_build.xml").toOSString(); //$NON-NLS-1$
File buildFile = new File(buildFileLocation);
try {
List flowFiles = getFlowFiles(mainPage.getSelectedProjects());
monitor.beginTask("Export flow documentation", 100);//flowFiles.size());
createBuildFile(buildFile, flowFiles, mainPage.getDestFolder());
AntRunner runner = new AntRunner();
//runner.addUserProperties(properties);
runner.setBuildFileLocation(buildFileLocation);
//runner.setMessageOutputLevel(Project.MSG_VERBOSE);
StringBuffer projectClasspathBuf = new StringBuffer();
List xdocletClasspathFiles = getXdocletClasspathFiles();
for (Iterator iter = xdocletClasspathFiles.iterator();
iter.hasNext();
) {
File file = (File) iter.next();
projectClasspathBuf.append(file.getAbsolutePath());
projectClasspathBuf.append(System.getProperty("path.separator"));
}
runner.setArguments("-Dxdoclet.class.path=" + projectClasspathBuf.toString());
Map props = new HashMap();
// props.put("xdoclet.class.path", xdocletClasspathBuf.toString());
// runner.addUserProperties(props);
List projectClasspathURLs = getProjectClasspathURLs(mainPage.getSelectedProjects());
runner.setCustomClasspath((URL[])projectClasspathURLs.toArray(new URL[projectClasspathURLs.size()]));
runner.run(monitor);
} catch (IOException e) {
e.printStackTrace();
} catch (CoreException e) {
Flow4JPlugin.message(e.getMessage());
} catch (Exception e) {
e.printStackTrace();
} finally {
monitor.done();
}
}
private List getXdocletClasspathFiles() throws IOException {
List xdocletClasspathFiles = new ArrayList();
Plugin plugin = Platform.getPlugin("net.orthanc.flow4j.flowdoc");
IPath pluginInstallFolderPath = Flow4JPlugin.getPluginInstallFolderPath("net.orthanc.flow4j.flowdoc");
ILibrary[] libs = plugin.getDescriptor().getRuntimeLibraries();
for (int i = 0; i < libs.length; i++) {
ILibrary lib = libs[i];
if (lib.getPath().toString().indexOf("xdoclet") != -1)
xdocletClasspathFiles.add(pluginInstallFolderPath.append(lib.getPath()).toFile());
}
return xdocletClasspathFiles;
}
/**
* Collects the Files which are necessary to create the flowdoc
* of the selected projects and returns a list of <code>java.net.URL</code> Objects.
* Includes all runtime libs from the plugins
* <ul>
* <li>net.orthanc.flow4j</li>
* <li>net.orthanc.flow4j.flowdoc</li>
* <li>org.apache.ant</li>
* </ul>
* @return
* @throws IOException
* @throws MalformedURLException
*/
private static List getProjectClasspathURLs(IProject[] projects) throws IOException, MalformedURLException {
List classpathURLs = new ArrayList();
Plugin plugin = Platform.getPlugin("net.orthanc.flow4j");
IPath pluginInstallFolderPath = Flow4JPlugin.getPluginInstallFolderPath("net.orthanc.flow4j");
ILibrary[] libs = plugin.getDescriptor().getRuntimeLibraries();
for (int i = 0; i < libs.length; i++) {
ILibrary lib = libs[i];
classpathURLs.add(pluginInstallFolderPath.append(lib.getPath()).toFile().toURL());
}
plugin = Platform.getPlugin("net.orthanc.flow4j.flowdoc");
pluginInstallFolderPath = Flow4JPlugin.getPluginInstallFolderPath("net.orthanc.flow4j.flowdoc");
libs = plugin.getDescriptor().getRuntimeLibraries();
for (int i = 0; i < libs.length; i++) {
ILibrary lib = libs[i];
classpathURLs.add(pluginInstallFolderPath.append(lib.getPath()).toFile().toURL());
}
plugin = Platform.getPlugin("org.apache.ant");
pluginInstallFolderPath = Flow4JPlugin.getPluginInstallFolderPath("org.apache.ant");
libs = plugin.getDescriptor().getRuntimeLibraries();
for (int i = 0; i < libs.length; i++) {
ILibrary lib = libs[i];
classpathURLs.add(pluginInstallFolderPath.append(lib.getPath()).toFile().toURL());
}
// selected projects
for (int i = 0; i < projects.length; i++) {
IJavaProject javaProject = Flow4JPlugin.getJavaProject(projects[i]);
List classpathPaths = new ArrayList();
Flow4JPlugin.getResolvedClasspath(Flow4JPlugin.getProject(javaProject), classpathPaths);
classpathURLs.addAll(Flow4JPlugin.convertPaths2URLs(classpathPaths));
/* for (Iterator iter = classpathPaths.iterator(); iter.hasNext();) {
IPath path = (IPath) iter.next();
classpathURLs.add(path.toFile().toURL());
}
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -