diff --git a/conformance/org.universaal.tools.conformancePlugin/.classpath b/conformance/org.universaal.tools.conformancePlugin/.classpath new file mode 100644 index 0000000000000000000000000000000000000000..8a8f1668cdcc5c73a6921162616f01cb556ae7c1 --- /dev/null +++ b/conformance/org.universaal.tools.conformancePlugin/.classpath @@ -0,0 +1,7 @@ +<?xml version="1.0" encoding="UTF-8"?> +<classpath> + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/> + <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> + <classpathentry kind="src" path="src"/> + <classpathentry kind="output" path="bin"/> +</classpath> diff --git a/conformance/org.universaal.tools.conformancePlugin/.project b/conformance/org.universaal.tools.conformancePlugin/.project new file mode 100644 index 0000000000000000000000000000000000000000..b03c6fb3fb2e3dc4507ad525b16f44109b6beb57 --- /dev/null +++ b/conformance/org.universaal.tools.conformancePlugin/.project @@ -0,0 +1,28 @@ +<?xml version="1.0" encoding="UTF-8"?> +<projectDescription> + <name>org.universaal.tools.conformancePlugin</name> + <comment></comment> + <projects> + </projects> + <buildSpec> + <buildCommand> + <name>org.eclipse.jdt.core.javabuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.pde.ManifestBuilder</name> + <arguments> + </arguments> + </buildCommand> + <buildCommand> + <name>org.eclipse.pde.SchemaBuilder</name> + <arguments> + </arguments> + </buildCommand> + </buildSpec> + <natures> + <nature>org.eclipse.pde.PluginNature</nature> + <nature>org.eclipse.jdt.core.javanature</nature> + </natures> +</projectDescription> diff --git a/conformance/org.universaal.tools.conformancePlugin/.settings/org.eclipse.jdt.core.prefs b/conformance/org.universaal.tools.conformancePlugin/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000000000000000000000000000000000000..10b0c599cda1589ea13d8b2b2060c13f7a5cf3ab --- /dev/null +++ b/conformance/org.universaal.tools.conformancePlugin/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,8 @@ +#Thu Nov 18 14:53:50 EET 2010 +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 +org.eclipse.jdt.core.compiler.compliance=1.6 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.6 diff --git a/conformance/org.universaal.tools.conformancePlugin/META-INF/MANIFEST.MF b/conformance/org.universaal.tools.conformancePlugin/META-INF/MANIFEST.MF new file mode 100644 index 0000000000000000000000000000000000000000..f639adfcb978720076fd36a4af15f2b359d9fe79 --- /dev/null +++ b/conformance/org.universaal.tools.conformancePlugin/META-INF/MANIFEST.MF @@ -0,0 +1,28 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: BuildServiceApplication +Bundle-SymbolicName: org.universaal.tools.conformancePlugin;singleton:=true +Bundle-Version: 0.3.0 +Bundle-Activator: org.universaal.tools.conformance.Activator +Bundle-Vendor: CERTH-ITI +Require-Bundle: org.eclipse.ui;bundle-version="3.7.0", + org.eclipse.core.runtime;bundle-version="3.7.0", + org.eclipse.debug.core;bundle-version="3.7.0", + org.eclipse.debug.ui;bundle-version="3.7.0", + org.eclipse.jdt.launching;bundle-version="3.6.0", + org.eclipse.pde.core;bundle-version="3.7.0", + org.eclipse.pde.ui;bundle-version="3.6.100", + org.eclipse.equinox.launcher;bundle-version="1.2.0", + org.eclipse.core.runtime.compatibility;bundle-version="3.2.100", + org.eclipse.jdt.core;bundle-version="3.7.0", + org.sonar.ide.eclipse.ui;bundle-version="1.0.0", + org.eclipse.m2e.maven.runtime;bundle-version="1.0.0", + org.eclipse.jdt.ui;bundle-version="3.7.0" +Bundle-RequiredExecutionEnvironment: JavaSE-1.6 +Import-Package: org.eclipse.core.internal.resources, + org.eclipse.pde.core.plugin, + org.eclipse.pde.internal.core.iproduct, + org.eclipse.pde.internal.core.util, + org.eclipse.pde.internal.ui.editor +Bundle-ActivationPolicy: lazy +Plugin-Class: org.universaal.tools.conformance.Activator diff --git a/conformance/org.universaal.tools.conformancePlugin/bin/org/universaal/tools/conformance/Activator.class b/conformance/org.universaal.tools.conformancePlugin/bin/org/universaal/tools/conformance/Activator.class new file mode 100644 index 0000000000000000000000000000000000000000..7d8fb686c18a5ab742772982123a62ba997660ae Binary files /dev/null and b/conformance/org.universaal.tools.conformancePlugin/bin/org/universaal/tools/conformance/Activator.class differ diff --git a/conformance/org.universaal.tools.conformancePlugin/bin/org/universaal/tools/conformance/actions/ConformanceAction$1.class b/conformance/org.universaal.tools.conformancePlugin/bin/org/universaal/tools/conformance/actions/ConformanceAction$1.class new file mode 100644 index 0000000000000000000000000000000000000000..ab9d230efe32f300027e2a6d0c09591c8792a47d Binary files /dev/null and b/conformance/org.universaal.tools.conformancePlugin/bin/org/universaal/tools/conformance/actions/ConformanceAction$1.class differ diff --git a/conformance/org.universaal.tools.conformancePlugin/bin/org/universaal/tools/conformance/actions/ConformanceAction$2.class b/conformance/org.universaal.tools.conformancePlugin/bin/org/universaal/tools/conformance/actions/ConformanceAction$2.class new file mode 100644 index 0000000000000000000000000000000000000000..da247b6e79eb1b66b9c61f945c4d40bae481231b Binary files /dev/null and b/conformance/org.universaal.tools.conformancePlugin/bin/org/universaal/tools/conformance/actions/ConformanceAction$2.class differ diff --git a/conformance/org.universaal.tools.conformancePlugin/bin/org/universaal/tools/conformance/actions/ConformanceAction$3.class b/conformance/org.universaal.tools.conformancePlugin/bin/org/universaal/tools/conformance/actions/ConformanceAction$3.class new file mode 100644 index 0000000000000000000000000000000000000000..5bee9ed1eaba3f6583c57c1b8b19e7d1c33beb69 Binary files /dev/null and b/conformance/org.universaal.tools.conformancePlugin/bin/org/universaal/tools/conformance/actions/ConformanceAction$3.class differ diff --git a/conformance/org.universaal.tools.conformancePlugin/bin/org/universaal/tools/conformance/actions/ConformanceAction$4.class b/conformance/org.universaal.tools.conformancePlugin/bin/org/universaal/tools/conformance/actions/ConformanceAction$4.class new file mode 100644 index 0000000000000000000000000000000000000000..fbe03f7a2b911d71a6c6eeed25d02a0d7b527c17 Binary files /dev/null and b/conformance/org.universaal.tools.conformancePlugin/bin/org/universaal/tools/conformance/actions/ConformanceAction$4.class differ diff --git a/conformance/org.universaal.tools.conformancePlugin/bin/org/universaal/tools/conformance/actions/ConformanceAction$5$1.class b/conformance/org.universaal.tools.conformancePlugin/bin/org/universaal/tools/conformance/actions/ConformanceAction$5$1.class new file mode 100644 index 0000000000000000000000000000000000000000..2b6578e8dc1424f3a2a5421643eb6ede6c90c09a Binary files /dev/null and b/conformance/org.universaal.tools.conformancePlugin/bin/org/universaal/tools/conformance/actions/ConformanceAction$5$1.class differ diff --git a/conformance/org.universaal.tools.conformancePlugin/bin/org/universaal/tools/conformance/actions/ConformanceAction$5.class b/conformance/org.universaal.tools.conformancePlugin/bin/org/universaal/tools/conformance/actions/ConformanceAction$5.class new file mode 100644 index 0000000000000000000000000000000000000000..3c70aca93465756ff0d5fdef63d3894f80bcde7a Binary files /dev/null and b/conformance/org.universaal.tools.conformancePlugin/bin/org/universaal/tools/conformance/actions/ConformanceAction$5.class differ diff --git a/conformance/org.universaal.tools.conformancePlugin/bin/org/universaal/tools/conformance/actions/ConformanceAction$6.class b/conformance/org.universaal.tools.conformancePlugin/bin/org/universaal/tools/conformance/actions/ConformanceAction$6.class new file mode 100644 index 0000000000000000000000000000000000000000..6de4a80ad25335ee07c2ff59f9f2db2ec0e3380e Binary files /dev/null and b/conformance/org.universaal.tools.conformancePlugin/bin/org/universaal/tools/conformance/actions/ConformanceAction$6.class differ diff --git a/conformance/org.universaal.tools.conformancePlugin/bin/org/universaal/tools/conformance/actions/ConformanceAction.class b/conformance/org.universaal.tools.conformancePlugin/bin/org/universaal/tools/conformance/actions/ConformanceAction.class new file mode 100644 index 0000000000000000000000000000000000000000..5c4248bb3d05a33ade29c1eb044218cefacd99fd Binary files /dev/null and b/conformance/org.universaal.tools.conformancePlugin/bin/org/universaal/tools/conformance/actions/ConformanceAction.class differ diff --git a/conformance/org.universaal.tools.conformancePlugin/build.properties b/conformance/org.universaal.tools.conformancePlugin/build.properties new file mode 100644 index 0000000000000000000000000000000000000000..3f603342b39095ecaf8d4add31baf18a6d75fe53 --- /dev/null +++ b/conformance/org.universaal.tools.conformancePlugin/build.properties @@ -0,0 +1,7 @@ +source.. = src/ +output.. = bin/ +bin.includes = plugin.xml,\ + META-INF/,\ + .,\ + icons/,\ + diff --git a/conformance/org.universaal.tools.conformancePlugin/icons/Thumbs.db b/conformance/org.universaal.tools.conformancePlugin/icons/Thumbs.db new file mode 100644 index 0000000000000000000000000000000000000000..3c5603d36daa6f6b9298162859554bc55cf60646 Binary files /dev/null and b/conformance/org.universaal.tools.conformancePlugin/icons/Thumbs.db differ diff --git a/conformance/org.universaal.tools.conformancePlugin/icons/compile.png b/conformance/org.universaal.tools.conformancePlugin/icons/compile.png new file mode 100644 index 0000000000000000000000000000000000000000..191e495f2f957b56eb4d8d20af3096ed67986686 Binary files /dev/null and b/conformance/org.universaal.tools.conformancePlugin/icons/compile.png differ diff --git a/conformance/org.universaal.tools.conformancePlugin/icons/logo_32x32.png b/conformance/org.universaal.tools.conformancePlugin/icons/logo_32x32.png new file mode 100644 index 0000000000000000000000000000000000000000..0aa000ef9afd6ae48487acccf58c53424cf1aaba Binary files /dev/null and b/conformance/org.universaal.tools.conformancePlugin/icons/logo_32x32.png differ diff --git a/conformance/org.universaal.tools.conformancePlugin/plugin.xml b/conformance/org.universaal.tools.conformancePlugin/plugin.xml new file mode 100644 index 0000000000000000000000000000000000000000..84f4e987111805c75195c967edca17619547d6ac --- /dev/null +++ b/conformance/org.universaal.tools.conformancePlugin/plugin.xml @@ -0,0 +1,26 @@ +<?xml version="1.0" encoding="UTF-8"?> +<?eclipse version="3.4"?> +<plugin> + + <extension + point="org.eclipse.ui.actionSets"> + <actionSet + label="Sample Action Set" + visible="true" + id="org.universaal.tools.conformance.actionSet"> + <action + label="&Test for conformance" + icon="icons/compile.png" + class="org.universaal.tools.conformance.actions.ConformanceAction" + tooltip="Test for conformance" + menubarPath="org.universaal.tools.AALStudio.menu/build" + toolbarPath="uAALGroup" + id="org.universaal.tools.conformance.actions.ConformanceAction"> + </action> + + </actionSet> + + </extension> + +</plugin> + \ No newline at end of file diff --git a/conformance/org.universaal.tools.conformancePlugin/src/org/universaal/tools/conformance/Activator.java b/conformance/org.universaal.tools.conformancePlugin/src/org/universaal/tools/conformance/Activator.java new file mode 100644 index 0000000000000000000000000000000000000000..cd6ec574d78780743352abf632f7cd75319c5e23 --- /dev/null +++ b/conformance/org.universaal.tools.conformancePlugin/src/org/universaal/tools/conformance/Activator.java @@ -0,0 +1,61 @@ +package org.universaal.tools.conformance; + +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.ui.plugin.AbstractUIPlugin; +import org.osgi.framework.BundleContext; + +/** + * The activator class controls the plug-in life cycle + */ +public class Activator extends AbstractUIPlugin { + + // The plug-in ID + public static final String PLUGIN_ID = "org.universaal.tools.buildServiceApplication"; //$NON-NLS-1$ + + // The shared instance + private static Activator plugin; + + /** + * The constructor + */ + public Activator() { + } + + /* + * (non-Javadoc) + * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext) + */ + public void start(BundleContext context) throws Exception { + super.start(context); + plugin = this; + } + + /* + * (non-Javadoc) + * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext) + */ + public void stop(BundleContext context) throws Exception { + plugin = null; + super.stop(context); + } + + /** + * Returns the shared instance + * + * @return the shared instance + */ + public static Activator getDefault() { + return plugin; + } + + /** + * Returns an image descriptor for the image file at the given + * plug-in relative path + * + * @param path the path + * @return the image descriptor + */ + public static ImageDescriptor getImageDescriptor(String path) { + return imageDescriptorFromPlugin(PLUGIN_ID, path); + } +} diff --git a/conformance/org.universaal.tools.conformancePlugin/src/org/universaal/tools/conformance/actions/ConformanceAction.java b/conformance/org.universaal.tools.conformancePlugin/src/org/universaal/tools/conformance/actions/ConformanceAction.java new file mode 100644 index 0000000000000000000000000000000000000000..1454de7cbca6e99895ecdd3dae75a33634b805e5 --- /dev/null +++ b/conformance/org.universaal.tools.conformancePlugin/src/org/universaal/tools/conformance/actions/ConformanceAction.java @@ -0,0 +1,528 @@ +package org.universaal.tools.conformance.actions; + +import java.io.File; +import java.net.URL; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Iterator; +import java.util.List; + +import org.apache.maven.Maven; +import org.apache.maven.artifact.metadata.ArtifactMetadata; +import org.apache.maven.cli.MavenCli; +import org.apache.maven.execution.DefaultMavenExecutionRequest; +import org.apache.maven.execution.MavenExecutionRequest; +import org.apache.maven.execution.MavenExecutionRequestPopulator; +import org.apache.maven.execution.MavenExecutionResult; +import org.apache.maven.settings.building.DefaultSettingsBuildingRequest; +import org.apache.maven.settings.building.SettingsBuilder; +import org.apache.maven.settings.building.SettingsBuildingRequest; +import org.codehaus.plexus.DefaultPlexusContainer; +import org.eclipse.core.internal.resources.Folder; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.IAdaptable; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Platform; +import org.eclipse.core.runtime.Status; +import org.eclipse.core.runtime.jobs.IJobChangeEvent; +import org.eclipse.core.runtime.jobs.Job; +import org.eclipse.core.runtime.jobs.JobChangeAdapter; +import org.eclipse.debug.core.DebugPlugin; +import org.eclipse.jdt.core.IJavaProject; +import org.eclipse.jdt.internal.core.CompilationUnit; +import org.eclipse.jdt.internal.core.JavaProject; +import org.eclipse.jdt.internal.core.PackageFragment; +import org.eclipse.jdt.internal.core.PackageFragmentRoot; +import org.eclipse.jface.action.Action; +import org.eclipse.jface.action.IAction; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.TreePath; +import org.eclipse.jface.viewers.TreeSelection; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.Text; +import org.eclipse.ui.IPageLayout; +import org.eclipse.ui.IViewPart; +import org.eclipse.ui.IViewReference; +import org.eclipse.ui.IWorkbench; +import org.eclipse.ui.IWorkbenchPage; +import org.eclipse.ui.IWorkbenchPart; +import org.eclipse.ui.IWorkbenchWindow; +import org.eclipse.ui.IWorkbenchWindowActionDelegate; +import org.eclipse.ui.PartInitException; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.progress.IProgressConstants; +import org.sonar.ide.eclipse.internal.ui.wizards.ConfigureProjectsWizard; +import org.sonar.ide.eclipse.internal.ui.wizards.ConfigureProjectsWizard.ConfigureProjectsPage.AssociateProjects; + + +/** + * Our sample action implements workbench action delegate. The action proxy will + * be created by the workbench and shown in the UI. When the user tries to use + * the action, this delegate will be created and execution will be delegated to + * it. + * + * @see IWorkbenchWindowActionDelegate + */ +public class ConformanceAction implements IWorkbenchWindowActionDelegate { + public static IWorkbenchWindow window; + public static MavenExecutionRequestPopulator populator; + public static DefaultPlexusContainer container; + public static Maven maven; + static public List<String> buildedProjects = new ArrayList<String>(); + static public SettingsBuilder settingsBuilder; + static public String artifactFileName = ""; + static public Collection<ArtifactMetadata> artifactMetadata = null; + private MavenExecutionResult installResult = null; + private static Shell activeShell = null; + private String selectedProjectName = ""; + private String selectedProjectPath = ""; + private static IProject iproject = null; + + /** + * The constructor. + */ + public ConformanceAction() { + } + + static IResource extractSelection(ISelection sel) { + if (!(sel instanceof IStructuredSelection)) + return null; + IStructuredSelection ss = (IStructuredSelection) sel; + if (ss.getFirstElement() instanceof IProject) { + IProject element = (IProject) ss.getFirstElement(); + if (element instanceof IResource) + return (IResource) element; + if (!(element instanceof IAdaptable)) + return null; + IAdaptable adaptable = (IAdaptable) element; + Object adapter = adaptable.getAdapter(IResource.class); + return (IResource) adapter; + } else if (ss.getFirstElement() instanceof JavaProject) { + JavaProject element = (JavaProject) ss.getFirstElement(); + if (element instanceof IResource) + return (IResource) element; + if (!(element instanceof IAdaptable)) + return null; + IAdaptable adaptable = (IAdaptable) element; + Object adapter = adaptable.getAdapter(IResource.class); + return (IResource) adapter; + } else if (ss.getFirstElement() instanceof PackageFragmentRoot) { + PackageFragmentRoot root = (PackageFragmentRoot) ss + .getFirstElement(); + IJavaProject element = root.getJavaProject(); + if (element instanceof IResource) + return (IResource) element; + if (!(element instanceof IAdaptable)) + return null; + IAdaptable adaptable = (IAdaptable) element; + Object adapter = adaptable.getAdapter(IResource.class); + return (IResource) adapter; + } else if (ss.getFirstElement() instanceof CompilationUnit) { + CompilationUnit root = (CompilationUnit) ss.getFirstElement(); + IJavaProject element = root.getJavaProject(); + if (element instanceof IResource) + return (IResource) element; + if (!(element instanceof IAdaptable)) + return null; + IAdaptable adaptable = (IAdaptable) element; + Object adapter = adaptable.getAdapter(IResource.class); + return (IResource) adapter; + } else if (ss.getFirstElement() instanceof org.eclipse.core.internal.resources.File) { + org.eclipse.core.internal.resources.File root = (org.eclipse.core.internal.resources.File) ss + .getFirstElement(); + IProject element = root.getProject(); + if (element instanceof IResource) + return (IResource) element; + if (!(element instanceof IAdaptable)) + return null; + IAdaptable adaptable = (IAdaptable) element; + Object adapter = adaptable.getAdapter(IResource.class); + return (IResource) adapter; + } else if (ss.getFirstElement() instanceof org.eclipse.jdt.internal.ui.packageview.ClassPathContainer) { + org.eclipse.jdt.internal.ui.packageview.ClassPathContainer root = (org.eclipse.jdt.internal.ui.packageview.ClassPathContainer) ss + .getFirstElement(); + IJavaProject element = root.getJavaProject(); + if (element instanceof IResource) + return (IResource) element; + if (!(element instanceof IAdaptable)) + return null; + IAdaptable adaptable = (IAdaptable) element; + Object adapter = adaptable.getAdapter(IResource.class); + return (IResource) adapter; + } else if (ss.getFirstElement() instanceof PackageFragment) { + PackageFragment root = (PackageFragment) ss.getFirstElement(); + IJavaProject element = root.getJavaProject(); + if (element instanceof IResource) + return (IResource) element; + if (!(element instanceof IAdaptable)) + return null; + IAdaptable adaptable = (IAdaptable) element; + Object adapter = adaptable.getAdapter(IResource.class); + return (IResource) adapter; + } else if (ss.getFirstElement() instanceof Folder) { + Folder root = (Folder) ss.getFirstElement(); + IProject element = root.getProject(); + if (element instanceof IResource) + return (IResource) element; + if (!(element instanceof IAdaptable)) + return null; + IAdaptable adaptable = (IAdaptable) element; + Object adapter = adaptable.getAdapter(IResource.class); + return (IResource) adapter; + } + try { + JavaProject element = (JavaProject) ss.getFirstElement(); + } catch (Exception ex) { + ex.printStackTrace(); + } + return null; + } + + public static boolean isActiveView(final IWorkbenchPage activePage, + final IViewPart view) { // obtain active page from WorkbenchWindow + final IWorkbenchPart activeView = activePage.getActivePart(); + return activeView == null ? false : activeView.equals(view); + } + + /** + * Returns the root path of the selected project within eclipse workspace. + */ + static public String getSelectedProjectPath() { + try { + + PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() { + public void run() { + activeShell = PlatformUI.getWorkbench() + .getActiveWorkbenchWindow().getShell(); + + IWorkbenchPage page = window.getActivePage(); + ISelection selection = null; + boolean packageExplorerActive = false; + boolean projectExplorerActive = false; + page.getViewReferences(); + for (int i = 0; i < page.getViewReferences().length; i++) { + IViewReference ref = page.getViewReferences()[i]; + if (ref.getPartName().equals("Package Explorer")) { + IViewPart view = ref.getView(false); + packageExplorerActive = isActiveView(page, view); + } else if (ref.getPartName().equals("Project Explorer")) { + IViewPart view = ref.getView(false); + projectExplorerActive = isActiveView(page, view); + } + } + if (projectExplorerActive && !packageExplorerActive) { + selection = page + .getSelection(IPageLayout.ID_PROJECT_EXPLORER); + } + if (!projectExplorerActive && packageExplorerActive + || selection == null + || ((IStructuredSelection) selection).isEmpty()) { + selection = page + .getSelection("org.eclipse.jdt.ui.PackageExplorer"); + } + if (selection == null + || ((IStructuredSelection) selection).isEmpty()) { + selection = page + .getSelection(IPageLayout.ID_PROJECT_EXPLORER); + } + IResource res = extractSelection(selection); + iproject = res.getProject(); + + } + }); + return iproject.getLocation().toOSString(); + } catch (Exception ex) { + ex.printStackTrace(); + return ""; + } + } + + static public String getSelectedProjectName() { + try { + PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() { + public void run() { + IWorkbenchPage page = window.getActivePage(); + ISelection selection = null; + boolean packageExplorerActive = false; + boolean projectExplorerActive = false; + page.getViewReferences(); + for (int i = 0; i < page.getViewReferences().length; i++) { + IViewReference ref = page.getViewReferences()[i]; + if (ref.getPartName().equals("Package Explorer")) { + IViewPart view = ref.getView(false); + packageExplorerActive = isActiveView(page, view); + } else if (ref.getPartName().equals("Project Explorer")) { + IViewPart view = ref.getView(false); + projectExplorerActive = isActiveView(page, view); + } + } + if (projectExplorerActive && !packageExplorerActive) { + selection = page + .getSelection(IPageLayout.ID_PROJECT_EXPLORER); + } + if (!projectExplorerActive && packageExplorerActive + || selection == null + || ((IStructuredSelection) selection).isEmpty()) { + selection = page + .getSelection("org.eclipse.jdt.ui.PackageExplorer"); + } + if (selection == null + || ((IStructuredSelection) selection).isEmpty()) { + selection = page + .getSelection(IPageLayout.ID_PROJECT_EXPLORER); + } + IResource res = extractSelection(selection); + iproject = res.getProject(); + + } + }); + return iproject.getName(); + } catch (Exception ex) { + // ex.printStackTrace(); + return ""; + } + } + + + + + + + /** + * The action has been activated. The argument of the method represents the + * 'real' action sitting in the workbench UI. + * + * @see IWorkbenchWindowActionDelegate#run + */ + public void run(IAction action) { + try { + final String selectedProject = getSelectedProjectPath(); + if (!selectedProject.equals("")) { + selectedProjectName = getSelectedProjectName(); + selectedProjectPath = getSelectedProjectPath(); + PlatformUI.getWorkbench().getDisplay().syncExec(new Runnable() { + public void run() { + activeShell = PlatformUI.getWorkbench() + .getActiveWorkbenchWindow().getShell(); + + } + }); + + Job job = new Job("AAL Studio") { + protected IStatus run(IProgressMonitor monitor) { + try { + monitor.beginTask("Testing conformance of application \"" + + selectedProjectName + "\"...", 50); + setProperty(IProgressConstants.KEEP_PROPERTY, + Boolean.FALSE); + URL url = Platform.getBundle( + "org.universaal.tools.buildPlugin") + .getEntry("icons/compile.png"); + setProperty(IProgressConstants.ICON_PROPERTY, + ImageDescriptor.createFromURL(url)); + setUpMavenBuild(); + monitor.worked(15); + installResult = runSonarGoal(selectedProjectPath); + + monitor.worked(50); + if (installResult.hasExceptions()) { + return Status.CANCEL_STATUS; + } else { + return Status.OK_STATUS; + } + } catch (Exception ex) { + ex.printStackTrace(); + return Status.CANCEL_STATUS; + } + } + }; + job.setUser(true); + job.schedule(); + job.addJobChangeListener(new JobChangeAdapter() { + public void done(final IJobChangeEvent event) { + Display.getDefault().syncExec(new Runnable() { + public void run() { + if (event.getResult().isOK()) { + MessageDialog.openInformation(activeShell, + "Test conformance", + "Testing conformance of application \"" + + selectedProjectName + + "\" succeeded."); + buildedProjects.add(selectedProject); + } else { + try { + String exceptions = "Errors found:\n"; + for (int i = 0; i < installResult + .getExceptions().size(); i++) { + exceptions = exceptions + + installResult + .getExceptions() + .get(i) + .getMessage() + + "\n\n"; + } + MessageDialog.openInformation( + activeShell, + "Test conformance", + "Testing conformance of project \"" + + selectedProjectName + + "\" failed.\n\n" + + exceptions); + } catch (Exception ex) { + MessageDialog.openInformation( + activeShell, + "Test conformance", + "Testing conformance of project \"" + + selectedProjectName + + "\" failed."); + } + } + } + }); + + } + }); + + } else { + MessageDialog + .openInformation(null, "Test conformance", + "Please select a project in the Project/Package Explorer tab."); + } + } catch (Exception ex) { + ex.printStackTrace(); + MessageDialog.openInformation(window.getShell(), + "Test conformance", + "Testing conformance of conformance failed"); + } + } + + + + + + + + + + protected Action getSonarWebView() { + return new Action("Open Sonar web view") { + public void run() { + try { + PlatformUI.getWorkbench().getActiveWorkbenchWindow() + .getActivePage().showView( + "org.sonar.ide.eclipse.ui.views.WebView"); + } catch (PartInitException e) { + + e.printStackTrace(); + } + // IWorkbenchWindow dw = + // PlatformUI.getWorkbench().getActiveWorkbenchWindow(); + // IWorkbenchPage page = dw.getActivePage(); + // try{ + // page.showView("WebView.ID"); + // }catch (Exception e){ + // e.printStackTrace(); + // } + + } + }; + } + + /** + * Sets up Maven embedder for execution. + */ + protected void setUpMavenBuild() { + try { + container = new DefaultPlexusContainer(); + maven = container.lookup(Maven.class); + populator = container.lookup(MavenExecutionRequestPopulator.class); + settingsBuilder = container.lookup(SettingsBuilder.class); + } catch (Exception ex) { + ex.printStackTrace(); + } + } + + /** + * Maven Excecution request. + */ + public MavenExecutionRequest createExecutionRequest() throws Exception { + SettingsBuildingRequest settingsRequest = new DefaultSettingsBuildingRequest(); + settingsRequest + .setUserSettingsFile(MavenCli.DEFAULT_USER_SETTINGS_FILE); + settingsRequest + .setGlobalSettingsFile(MavenCli.DEFAULT_GLOBAL_SETTINGS_FILE); + MavenExecutionRequest request = new DefaultMavenExecutionRequest(); + request.setUserSettingsFile(settingsRequest.getUserSettingsFile()); + request.setGlobalSettingsFile(settingsRequest.getGlobalSettingsFile()); + request.setSystemProperties(System.getProperties()); + populator.populateFromSettings(request, + settingsBuilder.build(settingsRequest).getEffectiveSettings()); + return request; + } + + /** + * Runs maven -clean/install command which builds the project and installs + * artifact to the local repository + */ + protected MavenExecutionResult runSonarGoal(String path) throws Exception { + File basedir = new File(selectedProjectPath); + MavenExecutionRequest request = createExecutionRequest(); + request.setPom(new File(basedir, "pom.xml")); + request.setGoals(Arrays.asList("sonar:sonar")); + populator.populateDefaults(request); + MavenExecutionResult result = maven.execute(request); + return result; + + } + + + /** + * Selection in the workbench has been changed. We can change the state of + * the 'real' action here if we want, but this can only happen after the + * delegate has been created. + * + * @see IWorkbenchWindowActionDelegate#selectionChanged + */ + public void selectionChanged(IAction action, ISelection selection) { + } + + /** + * We can use this method to dispose of any system resources we previously + * allocated. + * + * @see IWorkbenchWindowActionDelegate#dispose + */ + public void dispose() { + } + + /** + * We will cache window object in order to be able to provide parent shell + * for the message dialog. + * + * @see IWorkbenchWindowActionDelegate#init + */ + public void init(IWorkbenchWindow window) { + this.window = window; + } + + static public MavenExecutionRequestPopulator getMavenPopulator() { + return populator; + } + + static public DefaultPlexusContainer getMavenPlexusContainer() { + return container; + } + + static public Maven getMaven() { + return maven; + } + +} \ No newline at end of file