Skip to content

Commit

Permalink
added integration test for project creation + sonar cleanup
Browse files Browse the repository at this point in the history
Signed-off-by: Lars Heinemann <lhein.smx@gmail.com>
  • Loading branch information
lhein committed Dec 20, 2017
1 parent ea4ee8f commit c640046
Show file tree
Hide file tree
Showing 21 changed files with 746 additions and 44 deletions.
37 changes: 17 additions & 20 deletions core/tests/org.fusesource.ide.camel.tests.util/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,28 @@ Bundle-Name: %Bundle-Name
Bundle-SymbolicName: org.fusesource.ide.camel.tests.util
Bundle-Version: 10.2.0.qualifier
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Require-Bundle: org.fusesource.ide.branding,
org.junit;bundle-version="4.12.0",
org.eclipse.core.runtime;bundle-version="3.11.1",
Require-Bundle: org.junit;bundle-version="4.12.0",
org.eclipse.core.databinding,
org.eclipse.core.runtime,
org.eclipse.core.resources,
org.eclipse.m2e.maven.runtime;bundle-version="1.7.1",
org.eclipse.m2e.core;bundle-version="1.7.1",
org.fusesource.ide.camel.model.service.core;bundle-version="10.0.0",
org.fusesource.ide.camel.model.service.impl;bundle-version="10.0.0",
org.fusesource.ide.camel.model.service.core.tests.integration,
org.fusesource.ide.branding,
org.eclipse.core.databinding;bundle-version="1.5.0",
org.eclipse.ui.ide,
org.eclipse.emf.common;bundle-version="2.11.0",
org.eclipse.emf.transaction;bundle-version="1.8.0",
org.eclipse.equinox.security;bundle-version="1.2.200",
org.eclipse.graphiti,
org.eclipse.graphiti.ui,
org.eclipse.jdt.ui,
org.eclipse.jface,
org.eclipse.m2e.maven.runtime;bundle-version="1.7.1",
org.eclipse.m2e.core;bundle-version="1.7.1",
org.eclipse.pde.core,
org.eclipse.graphiti,
org.eclipse.graphiti.ui,
org.eclipse.emf.common;bundle-version="2.11.0",
org.eclipse.emf.transaction;bundle-version="1.8.0",
org.eclipse.ui.workbench;bundle-version="3.108.1",
org.fusesource.ide.camel.model.service.core.tests.integration,
org.fusesource.ide.camel.editor;bundle-version="10.0.0",
org.eclipse.ui.ide;bundle-version="3.12.0",
org.eclipse.ui,
org.eclipse.ui.ide,
org.eclipse.ui.workbench,
org.fusesource.ide.branding,
org.fusesource.ide.camel.editor,
org.eclipse.equinox.security;bundle-version="1.2.200"
org.fusesource.ide.camel.model.service.core.tests.integration,
org.fusesource.ide.camel.model.service.core,
org.fusesource.ide.camel.model.service.impl
Export-Package: org.fusesource.ide.camel.test.util.editor,
org.fusesource.ide.camel.tests.util
Bundle-Vendor: %Bundle-Vendor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.eclipse.swt.SWTException;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IEditorReference;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.PlatformUI;
Expand Down Expand Up @@ -123,6 +124,14 @@ public static IEditorPart getCurrentActiveEditor() {
return null;
}

public static IEditorReference[] getCurrentOpenEditors() {
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
if (page != null) {
return page.getEditorReferences();
}
return new IEditorReference[0];
}

/**
* process ui events
*
Expand All @@ -131,7 +140,7 @@ public static IEditorPart getCurrentActiveEditor() {
public static void readAndDispatch(int currentNumberOfTry) {
try{
while (Display.getDefault().readAndDispatch()) {

// wait
}
} catch(SWTException swtException){
//TODO: remove try catch when https://issues.jboss.org/browse/FUSETOOLS-1913 is done (CI with valid GUI)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@

import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.Set;

import org.apache.maven.model.Dependency;
import org.apache.maven.model.Model;
import org.apache.maven.model.Plugin;
import org.apache.maven.project.MavenProject;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
Expand Down Expand Up @@ -60,6 +63,7 @@ public class CamelProjectConfigurator extends AbstractProjectConfigurator {
public static final String WAR_PACKAGE = "WAR"; //$NON-NLS-1$
public static final String BUNDLE_PACKAGE = "BUNDLE"; //$NON-NLS-1$
public static final String JAR_PACKAGE = "JAR"; //$NON-NLS-1$

public static final IProjectFacet camelFacet = ProjectFacetsManager.getProjectFacet("jst.camel"); //$NON-NLS-1$
public static final IProjectFacet javaFacet = ProjectFacetsManager.getProjectFacet("java"); //$NON-NLS-1$
public static final IProjectFacet m2eFacet = ProjectFacetsManager.getProjectFacet("jboss.m2"); //$NON-NLS-1$
Expand All @@ -79,7 +83,7 @@ public void mavenProjectChanged(MavenProjectChangedEvent event, IProgressMonitor
IProject project = facade.getProject();
MavenProject mavenProject = facade.getMavenProject(monitor);
IFacetedProject fproj = ProjectFacetsManager.create(project);
if (fproj != null && checkCamelContextsExist(project, monitor)) {
if (fproj != null && checkCamelContextsExist(project, monitor) && isValidCamelFacetCandidate(project)) {
installDefaultFacets(project, mavenProject, fproj, monitor);
}
}
Expand All @@ -92,7 +96,7 @@ public void mavenProjectChanged(MavenProjectChangedEvent event, IProgressMonitor
*/
@Override
public void configure(ProjectConfigurationRequest request, IProgressMonitor monitor) throws CoreException {
if (checkCamelContextsExist(request.getProject(), monitor)) {
if (checkCamelContextsExist(request.getProject(), monitor) && isValidCamelFacetCandidate(request.getProject())) {
if (!isCamelFacetEnabled(request)) {
// if we have a camel context but no facade set we do set it
configureFacet(request.getMavenProject(), request.getProject(), monitor);
Expand Down Expand Up @@ -190,7 +194,7 @@ private void repairCamelFacet(ProjectConfigurationRequest request, IProgressMoni
IProjectFacetVersion oldfv = fproj.getInstalledVersion(camelFacet);
IFacetedProjectWorkingCopy fpwc = fproj.createWorkingCopy();
fproj.uninstallProjectFacet(oldfv, null, mon);
installCamelFacet(fproj, fpwc, DEFAULT_CAMEL_FACET_VERSION, mon);
installCamelFacet(fproj, fpwc, mon);
fpwc.commitChanges(mon);
}
}
Expand Down Expand Up @@ -276,14 +280,14 @@ private void installDefaultFacets(IProject project, MavenProject mavenProject, I
installFacet(fproj, fpwc, utilFacet, utilFacet.getLatestVersion());
}
}
installCamelFacet(fproj, fpwc, camelVersion, subMonitor.split(1));
installCamelFacet(fproj, fpwc, subMonitor.split(1));
fpwc.commitChanges(subMonitor.split(1));
configureNature(project, mavenProject, subMonitor.split(1));
updateMavenProject(project);
}
}

private void updateMavenProject(final IProject project) throws CoreException {
private void updateMavenProject(final IProject project) {
// MANIFEST.MF is probably not built yet
if (project != null) {
// update the maven project so we start in a deployable state
Expand All @@ -293,17 +297,17 @@ private void updateMavenProject(final IProject project) throws CoreException {
}
}

private void installCamelFacet(IFacetedProject fproj, IFacetedProjectWorkingCopy fpwc, String camelVersionString,
private void installCamelFacet(IFacetedProject fproj, IFacetedProjectWorkingCopy fpwc,
IProgressMonitor monitor) throws CoreException {
IDataModel config = (IDataModel) new CamelFacetDataModelProvider().create();
config.setBooleanProperty(ICamelFacetDataModelProperties.UPDATE_PROJECT_STRUCTURE, false);
installFacet(fproj, fpwc, camelFacet, getCamelFacetVersion(DEFAULT_CAMEL_FACET_VERSION));
installFacet(fproj, fpwc, camelFacet, getCamelFacetVersion());
// we need to switch dependency versions
CamelFacetVersionChangeDelegate del = new CamelFacetVersionChangeDelegate();
del.execute(fproj.getProject(), getCamelFacetVersion(DEFAULT_CAMEL_FACET_VERSION), config, monitor);
del.execute(fproj.getProject(), getCamelFacetVersion(), config, monitor);
}

private IProjectFacetVersion getCamelFacetVersion(String camelVersionString) throws CoreException {
private IProjectFacetVersion getCamelFacetVersion() throws CoreException {
try {
IProjectFacetVersion facetVersion = camelFacet.getVersion(DEFAULT_CAMEL_FACET_VERSION);
if (facetVersion != null) {
Expand All @@ -314,20 +318,50 @@ private IProjectFacetVersion getCamelFacetVersion(String camelVersionString) thr
}
return camelFacet.getLatestVersion();
}

/**
* common feature of all our templates is the use of the camel-maven-plugin. if it is not defined in the
* pom.xml then we don't apply facet and nature on those projects.
*
* @param project
* @return
*/
private boolean isValidCamelFacetCandidate(IProject project) {
Model model = new CamelMavenUtils().getMavenModel(project);
if (model != null) {
return model.getBuild().getPluginManagement() != null && isCamelPluginDefined(model.getBuild().getPluginManagement().getPlugins()) ||
isCamelPluginDefined(model.getBuild().getPlugins());

}

return false;
}

private boolean isCamelPluginDefined(List<Plugin> plugins) {
if (plugins != null) {
for (Plugin p : plugins) {
if (GROUP_ID_ORG_APACHE_CAMEL.equalsIgnoreCase(p.getGroupId()) &&
"camel-maven-plugin".equalsIgnoreCase(p.getArtifactId()) ) {
return true;
}
}
}
return false;
}

/**
* checks whether the project contains any camel context xml file
*
* @param project
* @return
*/
private boolean checkCamelContextsExist(IProject project, IProgressMonitor monitor) throws CoreException {
private boolean checkCamelContextsExist(IProject project, IProgressMonitor monitor) {
return !new CamelFilesFinder().findFiles(project).isEmpty()
|| new JavaCamelFilesFinder().findJavaDSLRouteBuilderClass(project, monitor) != null;
}

private void installFacet(IFacetedProject fproj, IFacetedProjectWorkingCopy fpwc, IProjectFacet facet,
IProjectFacetVersion facetVersion) throws CoreException {
IProjectFacetVersion facetVersion) {
if (facet != null && !fproj.hasProjectFacet(facet)) {
fpwc.addProjectFacet(facetVersion);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,4 @@ Require-Bundle: org.junit,
org.fusesource.ide.camel.model.service.core.tests.integration;bundle-version="10.2.0"
Bundle-Vendor: %Bundle-Vendor
Bundle-Activator: org.fusesource.ide.projecttemplates.tests.integration.ProjectTemplatesIntegrationTestsActivator
Export-Package: org.fusesource.ide.projecttemplates.tests.integration.wizards;x-friends:="org.fusesource.ide.syndesis.extension.core.tests.integration"
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import org.junit.rules.TestWatcher;
import org.junit.runner.Description;

final class PrintThreadStackOnFailureRule extends TestWatcher {
public final class PrintThreadStackOnFailureRule extends TestWatcher {
@Override
protected void failed(Throwable e, Description description) {
super.failed(e, description);
Expand Down
2 changes: 2 additions & 0 deletions site/category.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
<bundle id="org.fusesource.ide.launcher.ui.tests.integration"><category name="AllTests"/></bundle>
<bundle id="org.fusesource.ide.project.tests.integration"><category name="AllTests"/></bundle>
<bundle id="org.fusesource.ide.projecttemplates.tests.integration"><category name="AllTests"/></bundle>
<bundle id="org.fusesource.ide.syndesis.extension.ui.tests.integration"><category name="AllTests"/></bundle>
<bundle id="org.jboss.tools.fuse.transformation.core.tests.integration"><category name="AllTests"/></bundle>
<bundle id="org.jboss.tools.fuse.transformation.editor.tests.integration"><category name="AllTests"/></bundle>

Expand Down Expand Up @@ -83,6 +84,7 @@
<bundle id="org.fusesource.ide.launcher.ui.tests.integration.source"><category name="AllTests"/></bundle>
<bundle id="org.fusesource.ide.project.tests.integration.source"><category name="AllTests"/></bundle>
<bundle id="org.fusesource.ide.projecttemplates.tests.integration.source"><category name="AllTests"/></bundle>
<bundle id="org.fusesource.ide.syndesis.extension.ui.tests.integration.source"><category name="AllTests"/></bundle>
<bundle id="org.jboss.tools.fuse.transformation.core.tests.integration.source"><category name="AllTests"/></bundle>
<bundle id="org.jboss.tools.fuse.transformation.editor.tests.integration.source"><category name="AllTests"/></bundle>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,5 @@ Require-Bundle: org.eclipse.core.runtime,
Bundle-Activator: org.fusesource.ide.syndesis.extensions.ui.internal.SyndesisExtensionsUIActivator
Bundle-ActivationPolicy: lazy
Bundle-ClassPath: .
Export-Package: org.fusesource.ide.syndesis.extensions.ui.wizards;x-friends:="org.fusesource.ide.syndesis.extension.core.tests.integration"

Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@
******************************************************************************/
package org.fusesource.ide.syndesis.extensions.ui.maven;

import org.apache.maven.project.MavenProject;
import java.util.List;

import org.apache.maven.model.Model;
import org.apache.maven.model.Plugin;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.SubMonitor;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.m2e.core.project.IMavenProjectFacade;
Expand All @@ -27,6 +29,8 @@
import org.eclipse.wst.common.project.facet.core.IProjectFacet;
import org.eclipse.wst.common.project.facet.core.IProjectFacetVersion;
import org.eclipse.wst.common.project.facet.core.ProjectFacetsManager;
import org.fusesource.ide.camel.model.service.core.util.CamelMavenUtils;
import org.fusesource.ide.project.RiderProjectNature;
import org.fusesource.ide.projecttemplates.maven.CamelProjectConfigurator;
import org.fusesource.ide.syndesis.extensions.ui.internal.Messages;

Expand All @@ -35,6 +39,9 @@
*/
public class SyndesisExtensionProjectConfigurator extends AbstractProjectConfigurator {

private static final String SYNDESIS_PLUGIN_GROUPID = "io.syndesis";
private static final String SYNDESIS_PLUGIN_ARTIFACTID = "syndesis-maven-plugin";

/* (non-Javadoc)
* @see org.eclipse.m2e.core.project.configurator.AbstractProjectConfigurator#mavenProjectChanged(org.eclipse.m2e.core.project.MavenProjectChangedEvent, org.eclipse.core.runtime.IProgressMonitor)
*/
Expand All @@ -43,21 +50,39 @@ public void mavenProjectChanged(MavenProjectChangedEvent event, IProgressMonitor
IMavenProjectFacade facade = event.getMavenProject();
if (event.getFlags() == MavenProjectChangedEvent.FLAG_DEPENDENCIES && facade != null) {
IProject project = facade.getProject();
MavenProject mavenProject = facade.getMavenProject(monitor);
IFacetedProject fproj = ProjectFacetsManager.create(project);
if (fproj != null && checkSyndesisExtensionsMetaDataExist(project)) {
installDefaultFacets(project, mavenProject, fproj, monitor);
if (fproj != null && isValidSyndesisProject(project)) {
installDefaultFacets(project, fproj, monitor);
// we add the camel nature because this enables the Camel Contexts virtual folder in the project
addNature(project, RiderProjectNature.NATURE_ID, monitor);
}
}
super.mavenProjectChanged(event, monitor);
}

private boolean checkSyndesisExtensionsMetaDataExist(IProject project) {
// check for file:
return project != null && project.findMember(new Path("src").append("main").append("resources").append("META-INF").append("syndesis").append("extension-definition.json")) != null;
private boolean isValidSyndesisProject(IProject project) {
Model model = new CamelMavenUtils().getMavenModel(project);
if (model != null) {
return model.getBuild().getPluginManagement() != null && isSyndesisPluginDefined(model.getBuild().getPluginManagement().getPlugins()) ||
isSyndesisPluginDefined(model.getBuild().getPlugins());

}
return false;
}

private boolean isSyndesisPluginDefined(List<Plugin> plugins) {
if (plugins != null) {
for (Plugin p : plugins) {
if (SYNDESIS_PLUGIN_GROUPID.equalsIgnoreCase(p.getGroupId()) &&
SYNDESIS_PLUGIN_ARTIFACTID.equalsIgnoreCase(p.getArtifactId()) ) {
return true;
}
}
}
return false;
}

private void installDefaultFacets(IProject project, MavenProject mavenProject, IFacetedProject fproj, IProgressMonitor monitor) throws CoreException {
private void installDefaultFacets(IProject project, IFacetedProject fproj, IProgressMonitor monitor) throws CoreException {
SubMonitor subMonitor = SubMonitor.convert(monitor, Messages.installingRequiredFacetsForSyndesisExtensionProject, 4);
subMonitor.setWorkRemaining(3);

Expand Down Expand Up @@ -99,6 +124,7 @@ private void installFacet(IFacetedProject fproj, IFacetedProjectWorkingCopy fpwc
*/
@Override
public void configure(ProjectConfigurationRequest request, IProgressMonitor monitor) throws CoreException {
// nothing to do
// we add the camel nature because this enables the Camel Contexts virtual folder in the project
addNature(request.getProject(), RiderProjectNature.NATURE_ID, monitor);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public SyndesisExtensionProjectCreatorRunnable(String projectName, IPath locatio
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
boolean oldValueForValidation = disableGlobalValidationDuringProjectCreation();
try {
SubMonitor subMonitor = SubMonitor.convert(monitor, Messages.syndesisExtensionProjectCreatorRunnableCreatingTheProjectMonitorMessage, 7);
SubMonitor subMonitor = SubMonitor.convert(monitor, Messages.syndesisExtensionProjectCreatorRunnableCreatingTheProjectMonitorMessage, 8);
CamelModelServiceCoreActivator.getProjectClasspathChangeListener().deactivate();

// first create the project skeleton
Expand Down Expand Up @@ -152,6 +152,8 @@ public void run(IProgressMonitor monitor) throws InvocationTargetException, Inte

// finally open the camel context file
openCamelContextFile(prj, subMonitor.split(1));
// and open the syndesis config file
openSyndesisConfiguration(prj, subMonitor.split(1));
new BuildAndRefreshJobWaiterUtil().waitJob(subMonitor.split(1));
} finally {
setbackValidationValueAfterProjectCreation(oldValueForValidation);
Expand Down Expand Up @@ -317,6 +319,23 @@ private boolean confirmPerspectiveSwitch(IWorkbenchWindow window, IPerspectiveDe
return result == IDialogConstants.YES_ID;
}

private void openSyndesisConfiguration(IProject project, IProgressMonitor monitor) {
if (project != null) {
final IFile holder = project.getFile("src/main/resources/META-INF/syndesis/extension-definition.json");
Display.getDefault().asyncExec( () -> {
try {
if (!holder.exists()) {
new BuildAndRefreshJobWaiterUtil().waitJob(monitor);
}
IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
IDE.openEditor(activePage, holder, OpenStrategy.activateOnOpen());
} catch (PartInitException e) {
SyndesisExtensionsUIActivator.pluginLog().logError("Cannot open syndesis configuration file in editor", e); //$NON-NLS-1$
}
});
}
}

/**
* Open the first detected camel context file in the editor
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src/main/java"/>
<classpathentry kind="src" path="src/main/resources"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="output" path="bin"/>
</classpath>
Loading

0 comments on commit c640046

Please sign in to comment.