Skip to content

Commit

Permalink
Revert "16: moved pde tp utils to common testutils"
Browse files Browse the repository at this point in the history
This reverts commit 1d229c0.
  • Loading branch information
LorenzoBettini committed Oct 25, 2017
1 parent 1d229c0 commit 4ac90d9
Show file tree
Hide file tree
Showing 9 changed files with 111 additions and 17 deletions.
Expand Up @@ -16,8 +16,7 @@ Require-Bundle: org.junit;bundle-version="4.7.0",
org.eclipse.xtext.testing,
org.eclipse.xtext.xbase.testing,
org.eclipse.xtext.ui.testing,
org.eclipse.xtext.xbase.ui.testing,
edelta.testutils
org.eclipse.xtext.xbase.ui.testing
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Import-Package: org.hamcrest.core,
org.junit;version="4.5.0",
Expand Down
Expand Up @@ -17,8 +17,6 @@
import org.junit.BeforeClass;
import org.junit.Test;

import edelta.testutils.PDETargetPlatformUtils;

/**
* Utility class that runs Eclipse, import the projects that we want to
* compile and compile it with the Edelta compiler, so that java._trace files
Expand Down
@@ -1,4 +1,4 @@
package edelta.testutils;
package edelta.library.compilation;

import java.io.File;
import java.util.ArrayList;
Expand Down Expand Up @@ -28,7 +28,6 @@
*
* @author Lorenzo Bettini - some adaptations
*/
@SuppressWarnings("restriction")
public class PDETargetPlatformUtils {

private static boolean targetPlatformAlreadySet = false;
Expand Down
5 changes: 1 addition & 4 deletions edelta.parent/edelta.testutils/META-INF/MANIFEST.MF
Expand Up @@ -6,7 +6,4 @@ Bundle-Version: 0.2.0.qualifier
Bundle-Vendor: Lorenzo Bettini
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Export-Package: edelta.testutils
Require-Bundle: org.junit;bundle-version="4.12.0",
org.eclipse.core.runtime,
org.eclipse.pde.core,
org.eclipse.core.resources
Require-Bundle: org.junit;bundle-version="4.12.0"
3 changes: 1 addition & 2 deletions edelta.parent/edelta.ui.tests/META-INF/MANIFEST.MF
Expand Up @@ -18,8 +18,7 @@ Require-Bundle: edelta.ui,
org.eclipse.xtext.testing,
org.eclipse.xtext.xbase.testing,
org.eclipse.xtext.ui.testing,
org.eclipse.xtext.xbase.ui.testing,
edelta.testutils
org.eclipse.xtext.xbase.ui.testing
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Export-Package: edelta.ui.tests;x-internal=true
Import-Package: org.hamcrest.core,
Expand Down
@@ -1,8 +1,8 @@
package edelta.ui.tests

import edelta.testutils.PDETargetPlatformUtils
import edelta.ui.internal.EdeltaActivator
import edelta.ui.tests.utils.EdeltaPluginProjectHelper
import edelta.ui.tests.utils.PDETargetPlatformUtils
import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
Expand Down
Expand Up @@ -2,16 +2,16 @@ package edelta.ui.tests

import com.google.inject.Inject
import com.google.inject.Provider
import edelta.testutils.PDETargetPlatformUtils
import edelta.ui.tests.utils.EdeltaTestableNewProjectWizard
import edelta.ui.tests.utils.PDETargetPlatformUtils
import edelta.ui.tests.utils.PluginProjectHelper
import org.eclipse.jface.viewers.StructuredSelection
import org.eclipse.jface.wizard.Wizard
import org.eclipse.jface.wizard.WizardDialog
import org.eclipse.ui.PlatformUI
import org.eclipse.xtext.ui.testing.AbstractWorkbenchTest
import org.eclipse.xtext.testing.InjectWith
import org.eclipse.xtext.testing.XtextRunner
import org.eclipse.xtext.ui.testing.AbstractWorkbenchTest
import org.junit.BeforeClass
import org.junit.Test
import org.junit.runner.RunWith
Expand Down
@@ -1,13 +1,13 @@
package edelta.ui.tests

import com.google.inject.Inject
import edelta.testutils.PDETargetPlatformUtils
import edelta.ui.tests.utils.EdeltaPluginProjectHelper
import edelta.ui.tests.utils.PDETargetPlatformUtils
import edelta.ui.tests.utils.PluginProjectHelper
import org.eclipse.core.resources.IProject
import org.eclipse.xtext.ui.testing.AbstractWorkbenchTest
import org.eclipse.xtext.testing.InjectWith
import org.eclipse.xtext.testing.XtextRunner
import org.eclipse.xtext.ui.testing.AbstractWorkbenchTest
import org.junit.Before
import org.junit.BeforeClass
import org.junit.Test
Expand Down
@@ -0,0 +1,102 @@
package edelta.ui.tests.utils;

import java.io.File;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.osgi.internal.framework.EquinoxBundle;
import org.eclipse.osgi.storage.BundleInfo.Generation;
import org.eclipse.pde.core.target.ITargetDefinition;
import org.eclipse.pde.core.target.ITargetLocation;
import org.eclipse.pde.core.target.ITargetPlatformService;
import org.eclipse.pde.core.target.LoadTargetDefinitionJob;
import org.eclipse.pde.internal.core.target.TargetPlatformService;
import org.osgi.framework.Bundle;
import org.osgi.framework.FrameworkUtil;

/**
* Implements workaround suggested here:
* https://bugs.eclipse.org/bugs/show_bug.cgi?id=343156
* This is required when running SwtBot tests in Tycho
* that requires the PDE, for example, for testing that the
* imported projects compile fine, or if they use the DSL, which
* requires PDE projects dependencies.
*
* @author Lorenzo Bettini - some adaptations
*/
public class PDETargetPlatformUtils {

private static boolean targetPlatformAlreadySet = false;

/**
* Sets a target platform in the test platform to get workspace builds OK
* with PDE.
*
* @throws Exception
*/
public static void setTargetPlatform() throws Exception {
if (System.getProperty("buildingWithTycho") != null) {
if (targetPlatformAlreadySet) {
System.out.println("Target platform already set");
return;
}
targetPlatformAlreadySet = true;
System.out.println("Generating a target platform");
} else {
System.out.println("Using the Workbench's target platform");
return;
}
ITargetPlatformService tpService = TargetPlatformService.getDefault();
ITargetDefinition targetDef = tpService.newTarget();
Bundle currentBundle = FrameworkUtil.getBundle(PDETargetPlatformUtils.class);
System.out.println("Current bundle: " + currentBundle);
targetDef.setName("Tycho platform");
Bundle[] bundles = Platform.getBundle("org.eclipse.core.runtime").getBundleContext().getBundles();
List<ITargetLocation> bundleContainers = new ArrayList<ITargetLocation>();
Set<File> dirs = new HashSet<File>();
System.out.println("Bundles for the target platform:");
for (Bundle bundle : bundles) {
if (bundle.equals(currentBundle)) {
// we skip the current bundle, otherwise the folder for the target platform
// will include the absolute directory of the maven parent project
// since the projects are nested in the parent project the result
// would be that Java packages of our project will be available twice
// and Java won't be able to find our classes leading in compilation
// errors during our tests.
System.err.println("*** Skipping current bundle: " + currentBundle);
continue;
}
// AbstractBundle bundleImpl = (AbstractBundle) bundle;
// BaseData bundleData = (BaseData) bundleImpl.getBundleData();
EquinoxBundle bundleImpl = (EquinoxBundle) bundle;
Generation generation = (Generation) bundleImpl.getModule().getCurrentRevision().getRevisionInfo();
File file = generation.getBundleFile().getBaseFile();
File folder = file.getParentFile();
if (!dirs.contains(folder)) {
dirs.add(folder);
String absolutePath = folder.getAbsolutePath();
System.out.println(bundle + " - " + absolutePath);
bundleContainers.add(tpService.newDirectoryLocation(absolutePath));
}
}
System.out.println("");
System.out.println("Bundles added the target platform.");
targetDef.setTargetLocations(bundleContainers.toArray(new ITargetLocation[bundleContainers.size()]));
targetDef.setArch(Platform.getOSArch());
targetDef.setOS(Platform.getOS());
targetDef.setWS(Platform.getWS());
targetDef.setNL(Platform.getNL());
// targetDef.setJREContainer()
tpService.saveTargetDefinition(targetDef);

System.out.print("Loading target platform... ");
Job job = new LoadTargetDefinitionJob(targetDef);
job.schedule();
job.join();
System.out.println("DONE.");
}
}

0 comments on commit 4ac90d9

Please sign in to comment.