Commit ce774ded authored by Benedikt Engeser's avatar Benedikt Engeser
Browse files

Automatischer Antbuilder

parent 2f50ba33
......@@ -21,7 +21,8 @@ Require-Bundle: org.eclipse.ui,
org.eclipse.jdt;bundle-version="3.10.0",
org.eclipse.jdt.debug;bundle-version="3.8.101",
org.eclipse.jdt.core;bundle-version="3.10.0",
org.eclipse.jdt.ui;bundle-version="3.10.1"
org.eclipse.jdt.ui;bundle-version="3.10.1",
org.eclipse.ant.core;bundle-version="3.3.0"
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Bundle-ActivationPolicy: lazy
Bundle-ClassPath: .
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: CupPlugin
Bundle-SymbolicName: de.tum.in.www2.CupPlugin;singleton:=true
Bundle-Version: 1.0
Bundle-Activator: de.tum.in.www2.cupplugin.Activator
Bundle-Vendor: de.tum.in.www2
Require-Bundle: org.eclipse.ui,
org.eclipse.core.runtime,
org.eclipse.jface.text,
org.eclipse.core.resources,
org.eclipse.ui.editors,
org.eclipse.ui.ide,
org.eclipse.zest.core;bundle-version="1.5.100",
org.eclipse.zest.layouts;bundle-version="1.1.100",
CupReferencedLibraries;bundle-version="1.0.0",
org.eclipse.ui.views;bundle-version="3.7.0",
org.eclipse.core.expressions;bundle-version="3.4.600",
org.eclipse.debug.core;bundle-version="3.9.1",
org.eclipse.debug.ui;bundle-version="3.10.1",
org.eclipse.jdt.core;bundle-version="3.10.0",
org.eclipse.jdt.ui;bundle-version="3.10.1"
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Bundle-ActivationPolicy: lazy
Bundle-ClassPath: .
package de.tum.in.www2.cupplugin.wizards;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.eclipse.core.resources.ICommand;
import org.eclipse.core.resources.IContainer;
......@@ -43,10 +46,12 @@ public class CupJavaProjectWizard extends Wizard implements INewWizard {
private CupProjectWizardPage thirdPage;
private static final String WIZARD_TITLE = "Create new CUP project";
private static final String WIZARD_DESCRIPTION1 = "CUP projects are based on Java projects. " +
"Please configure your project.";
private static final String WIZARD_DESCRIPTION1 = "CUP projects are based on Java projects. "
+ "Please configure your project.";
private static final String WIZARD_DESCRIPTION2 = "Configure your CUP project here.";
private static final String launchConfigFile = ".cupAntBuilder.launch";
public CupJavaProjectWizard() {
super();
workbenchWindow = null;
......@@ -63,13 +68,13 @@ public class CupJavaProjectWizard extends Wizard implements INewWizard {
secondPage.setTitle(WIZARD_TITLE);
secondPage.setDescription(WIZARD_DESCRIPTION1);
addPage(secondPage);
thirdPage = new CupProjectWizardPage();
thirdPage.setTitle(WIZARD_TITLE);
thirdPage.setDescription(WIZARD_DESCRIPTION2);
addPage(thirdPage);
}
@Override
public boolean canFinish() {
return secondPage.getJavaProject() != null;
......@@ -142,7 +147,9 @@ public class CupJavaProjectWizard extends Wizard implements INewWizard {
}
private boolean setBuilder(IProject project) {
String builderName = "org.eclipse.ant.AntBuilderLaunchConfigurationType";
String builderName = "org.eclipse.ui.externaltools.ExternalToolBuilder";
// builderName = ExternalToolBuilder.ID;
IProjectDescription desc = null;
try {
desc = project.getDescription();
......@@ -151,8 +158,10 @@ public class CupJavaProjectWizard extends Wizard implements INewWizard {
return false;
}
createLaunchConfiguration(project, launchConfigFile);
ICommand[] commands = desc.getBuildSpec();
for (int i = 0; i < commands.length; ++i)
for (int i = 0; i < commands.length; i++)
if (commands[i].getBuilderName().equals(builderName))
return true;
ICommand command = desc.newCommand();
......@@ -168,58 +177,37 @@ public class CupJavaProjectWizard extends Wizard implements INewWizard {
*/
/*
MyAntBuilder.launch
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<launchConfiguration type="org.eclipse.ant.AntBuilderLaunchConfigurationType">
<booleanAttribute key="org.eclipse.ant.ui.ATTR_TARGETS_UPDATED" value="true"/>
<booleanAttribute key="org.eclipse.ant.ui.DEFAULT_VM_INSTALL" value="false"/>
<booleanAttribute key="org.eclipse.debug.ui.ATTR_LAUNCH_IN_BACKGROUND" value="false"/>
<stringAttribute key="org.eclipse.jdt.launching.CLASSPATH_PROVIDER" value="org.eclipse.ant.ui.AntClasspathProvider"/>
<booleanAttribute key="org.eclipse.jdt.launching.DEFAULT_CLASSPATH" value="true"/>
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="ijwdjpqwd"/>
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_LOCATION" value="${workspace_loc:/ijwdjpqwd/build.xml}"/>
<stringAttribute key="org.eclipse.ui.externaltools.ATTR_RUN_BUILD_KINDS" value="full,incremental,"/>
<booleanAttribute key="org.eclipse.ui.externaltools.ATTR_TRIGGERS_CONFIGURED" value="true"/>
</launchConfiguration>
.project:
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>ijwdjpqwd</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.ui.externaltools.ExternalToolBuilder</name>
<triggers>full,incremental,</triggers>
<arguments>
<dictionary>
<key>LaunchConfigHandle</key>
<value>&lt;project&gt;/.externalToolBuilders/MyAntBuilder.launch</value>
</dictionary>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
*/
*
* MyAntBuilder.launch
*
* <?xml version="1.0" encoding="UTF-8" standalone="no"?>
* <launchConfiguration
* type="org.eclipse.ant.AntBuilderLaunchConfigurationType">
* <booleanAttribute key="org.eclipse.ant.ui.ATTR_TARGETS_UPDATED"
* value="true"/> <booleanAttribute
* key="org.eclipse.ant.ui.DEFAULT_VM_INSTALL" value="false"/>
* <booleanAttribute
* key="org.eclipse.debug.ui.ATTR_LAUNCH_IN_BACKGROUND" value="false"/>
* <stringAttribute key="org.eclipse.jdt.launching.CLASSPATH_PROVIDER"
* value="org.eclipse.ant.ui.AntClasspathProvider"/> <booleanAttribute
* key="org.eclipse.jdt.launching.DEFAULT_CLASSPATH" value="true"/>
* <stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR"
* value="ijwdjpqwd"/> <stringAttribute
* key="org.eclipse.ui.externaltools.ATTR_LOCATION"
* value="${workspace_loc:/ijwdjpqwd/build.xml}"/> <stringAttribute
* key="org.eclipse.ui.externaltools.ATTR_RUN_BUILD_KINDS"
* value="full,incremental,"/> <booleanAttribute
* key="org.eclipse.ui.externaltools.ATTR_TRIGGERS_CONFIGURED"
* value="true"/> </launchConfiguration>
*/
ICommand[] nc = new ICommand[commands.length + 1];
System.arraycopy(commands, 0, nc, 1, commands.length);
Map<String, String> arguments = command.getArguments();
arguments.put("LaunchConfigHandle", "<project>/" + launchConfigFile);
command.setArguments(arguments);
nc[0] = command;
desc.setBuildSpec(nc);
try {
......@@ -232,7 +220,7 @@ public class CupJavaProjectWizard extends Wizard implements INewWizard {
}
private void doFinish(IProject project, IProgressMonitor monitor) {
monitor.beginTask("Creating project ...", 2);
try {
......@@ -241,7 +229,7 @@ public class CupJavaProjectWizard extends Wizard implements INewWizard {
// TODO Auto-generated catch block
e1.printStackTrace();
}
/*
* IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
* IResource resource = root.findMember(new Path(containerName)); if
......@@ -262,9 +250,9 @@ public class CupJavaProjectWizard extends Wizard implements INewWizard {
IFolder folder = createDirectory(project, monitor, "tools");
createFile(folder, monitor, "JFlex.jar", getTemplate("JFlex.jar"));
createFile(folder, monitor, "java-cup-11b-runtime.jar",
createFile(folder, monitor, "java-cup-11b-runtime.jar",
getTemplate("java-cup-11b-runtime.jar"));
createFile(folder, monitor, "java-cup-11b.jar",
createFile(folder, monitor, "java-cup-11b.jar",
getTemplate("java-cup-11b.jar"));
setBuilder(project);
......@@ -285,51 +273,85 @@ public class CupJavaProjectWizard extends Wizard implements INewWizard {
selectAndReveal(parserFile);
monitor.worked(1);
}
// copied from the net: https://svn.jmodelica.org/tags/1.6/EclipseIDE/org.jmodelica.ide/java/org/jmodelica/ide/ui/NewProjectWizard.java
private void selectAndReveal (IResource resource) {
if (workbenchWindow == null)
return;
IWorkbenchPage page = workbenchWindow.getActivePage();
if (page == null)
// copied from the net:
// https://svn.jmodelica.org/tags/1.6/EclipseIDE/org.jmodelica.ide/java/org/jmodelica/ide/ui/NewProjectWizard.java
private void selectAndReveal(IResource resource) {
if (workbenchWindow == null)
return;
IWorkbenchPage page = workbenchWindow.getActivePage();
if (page == null)
return;
List<IWorkbenchPart> parts = new ArrayList<IWorkbenchPart>();
IWorkbenchPartReference refs[] = page.getViewReferences();
for (int i = 0; i < refs.length; i++) {
IWorkbenchPart part = refs[i].getPart(false);
if (part != null)
List<IWorkbenchPart> parts = new ArrayList<IWorkbenchPart>();
IWorkbenchPartReference refs[] = page.getViewReferences();
for (int i = 0; i < refs.length; i++) {
IWorkbenchPart part = refs[i].getPart(false);
if (part != null)
parts.add(part);
}
refs = page.getEditorReferences();
for (int i = 0; i < refs.length; i++) {
if (refs[i].getPart(false) != null)
}
refs = page.getEditorReferences();
for (int i = 0; i < refs.length; i++) {
if (refs[i].getPart(false) != null)
parts.add(refs[i].getPart(false));
}
final ISelection selection = new StructuredSelection(resource);
Iterator<IWorkbenchPart> itr = parts.iterator();
while (itr.hasNext()) {
IWorkbenchPart part = (IWorkbenchPart) itr.next();
ISetSelectionTarget target = null;
if (part instanceof ISetSelectionTarget)
}
final ISelection selection = new StructuredSelection(resource);
Iterator<IWorkbenchPart> itr = parts.iterator();
while (itr.hasNext()) {
IWorkbenchPart part = (IWorkbenchPart) itr.next();
ISetSelectionTarget target = null;
if (part instanceof ISetSelectionTarget)
target = (ISetSelectionTarget) part;
else
target = (ISetSelectionTarget) part
.getAdapter(ISetSelectionTarget.class);
if (target != null) {
final ISetSelectionTarget finalTarget = target;
workbenchWindow.getShell().getDisplay().asyncExec(new Runnable() {
public void run() {
finalTarget.selectReveal(selection);
}
});
}
}
}
@Override
.getAdapter(ISetSelectionTarget.class);
if (target != null) {
final ISetSelectionTarget finalTarget = target;
workbenchWindow.getShell().getDisplay()
.asyncExec(new Runnable() {
public void run() {
finalTarget.selectReveal(selection);
}
});
}
}
}
@Override
public void init(IWorkbench workbench, IStructuredSelection selection) {
this.workbenchWindow = workbench.getActiveWorkbenchWindow();
this.workbenchWindow = workbench.getActiveWorkbenchWindow();
}
private boolean createLaunchConfiguration(IProject project, String filename) {
String FileContents = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n"
+ "<launchConfiguration type=\"org.eclipse.ant.AntBuilderLaunchConfigurationType\">\n"
+ "<booleanAttribute key=\"org.eclipse.ant.ui.ATTR_TARGETS_UPDATED\" value=\"true\"/>\n"
+ "<booleanAttribute key=\"org.eclipse.ant.ui.DEFAULT_VM_INSTALL\" value=\"false\"/>\n"
+ "<booleanAttribute key=\"org.eclipse.debug.ui.ATTR_LAUNCH_IN_BACKGROUND\" value=\"false\"/>\n"
+ "<stringAttribute key=\"org.eclipse.jdt.launching.CLASSPATH_PROVIDER\" value=\"org.eclipse.ant.ui.AntClasspathProvider\"/>\n"
+ "<booleanAttribute key=\"org.eclipse.jdt.launching.DEFAULT_CLASSPATH\" value=\"true\"/>\n"
+ "<stringAttribute key=\"org.eclipse.jdt.launching.PROJECT_ATTR\" value=\""
+ project.getName()
+ "\"/>\n"
+ "<stringAttribute key=\"org.eclipse.ui.externaltools.ATTR_LOCATION\" value=\"${workspace_loc:/"
+ project.getName()
+ "/build.xml}\"/>\n"
+ "<stringAttribute key=\"org.eclipse.ui.externaltools.ATTR_RUN_BUILD_KINDS\" value=\"full,incremental,\"/>\n"
+ "<booleanAttribute key=\"org.eclipse.ui.externaltools.ATTR_TRIGGERS_CONFIGURED\" value=\"true\"/>\n</launchConfiguration>";
IFile file = project.getFile(filename);
if (!file.exists()) {
byte[] bytes = FileContents.getBytes();
InputStream source = new ByteArrayInputStream(bytes);
try {
file.create(source, IResource.NONE, null);
} catch (CoreException e) {
return false;
}
return true;
}
return false;
}
}
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment