+ * Applies the java plugin by default. + *
+ * Makes the os, ws and arch variables available for the project (via project.ext) for building against platform-dependent + * dependencies; for example
compile "eclipse:org.eclipse.swt.${project.ext.ws}.${project.ext.os}.${project.ext.arch}:+"+ *
+ * To make the compilation work, the compileJava task depends on the establishment of the target platform. + *
+ * To construct the output jar just like Eclipse PDE the plugin loads the contents of the build.properties
+ * file and brings it in sync with the jar's content.
+ *
+ * The
+ * A feature project can specify its feature.xml with a very simple build script:
+ *
+ * Only thing this plugin does is basic validation if the feature.xml file and the build.properties file exists and
+ * It add everything to the plugin jar what is defined in the build.properties (just line in {@link EclipsePlugin#syncJarContentWithBuildProperties(Project)})
+ */
+class FeaturePlugin implements Plugin
+ * An example for a valid DSL:
+ *
+ * The main tasks contributed by this plugin are responsible to generate an Eclipse Update site. They are attached to
+ * the 'assemble' task. When executed, all project dependency jars are copied to the build folder, signed and published
+ * to the buildDir/repository folder.
+ */
+class UpdateSitePlugin implements Plugin
+ * This class is automatically instantiated by the Eclipse runtime and wired through the
+ * Bundle-Activator entry in the META-INF/MANIFEST.MF file. The registered
+ * instance can be obtained during runtime through the {@link CorePlugin#getInstance()} method.
+ *
+ * Moreover, this is the entry point for accessing associated services:
+ *
+ * The {@link #start(BundleContext)} and {@link #stop(BundleContext)} methods' responsibility is to
+ * assign and free the managed services along the plugin runtime lifecycle.
+ */
+@SuppressWarnings({ "unchecked", "rawtypes" })
+public final class CorePlugin extends Plugin {
+
+ public static final String PLUGIN_ID = "com.gradleware.tooling.eclipse.core";
+
+ private static CorePlugin plugin;
+
+ // do not use generics-aware signature since this causes compilation troubles (JDK, Spock)
+ // search the web for -target jsr14 to find out more about this obscurity
+ private ServiceRegistration loggerService;
+ private ServiceRegistration publishedGradleVersionsService;
+ private ServiceRegistration modelRepositoryProviderService;
+ private ServiceRegistration workspaceOperationsService;
+ private ServiceRegistration projectConfigurationManagerService;
+ private ServiceRegistration processStreamsProviderService;
+ private ServiceRegistration gradleLaunchConfigurationService;
+ private ServiceRegistration workbenchOperationsService;
+
+ // service tracker for each service to allow to register other service implementations of the
+ // same type but with higher prioritization, useful for testing
+ private ServiceTracker loggerServiceTracker;
+ private ServiceTracker publishedGradleVersionsServiceTracker;
+ private ServiceTracker modelRepositoryProviderServiceTracker;
+ private ServiceTracker workspaceOperationsServiceTracker;
+ private ServiceTracker projectConfigurationManagerServiceTracker;
+ private ServiceTracker processStreamsProviderServiceTracker;
+ private ServiceTracker gradleLaunchConfigurationServiceTracker;
+ private ServiceTracker workbenchOperationsServiceTracker;
+
+ @Override
+ public void start(BundleContext bundleContext) throws Exception {
+ super.start(bundleContext);
+ registerServices(bundleContext);
+ plugin = this;
+ }
+
+ @Override
+ public void stop(BundleContext context) throws Exception {
+ plugin = null;
+ unregisterServices();
+ super.stop(context);
+ }
+
+ private void registerServices(BundleContext context) {
+ // store services with low ranking such that they can be overridden
+ // during testing or the like
+ Dictionary
+ * By using this interface, we can log like this:
+ *
+ *
+ */
+public interface Logger {
+
+ /**
+ * Logs an entry with {@link org.eclipse.core.runtime.IStatus#INFO} severity in Eclipse's log.
+ *
+ * @param message the information to log
+ */
+ void info(String message);
+
+ /**
+ * Logs an entry with {@link org.eclipse.core.runtime.IStatus#WARNING} severity in Eclipse's log.
+ *
+ * @param message the warning to log
+ */
+ void warn(String message);
+
+ /**
+ * Logs an entry with {@link org.eclipse.core.runtime.IStatus#ERROR} severity in Eclipse's log.
+ *
+ * @param message the warning to log
+ */
+ void error(String message);
+
+ /**
+ * Logs an entry with {@link org.eclipse.core.runtime.IStatus#ERROR} severity in Eclipse's log.
+ *
+ * @param message the error to log
+ * @param t the underlying cause
+ */
+ void error(String message, Throwable t);
+
+}
diff --git a/com.gradleware.tooling.eclipse.core/src/main/java/com/gradleware/tooling/eclipse/core/configuration/ProjectConfiguration.java b/com.gradleware.tooling.eclipse.core/src/main/java/com/gradleware/tooling/eclipse/core/configuration/ProjectConfiguration.java
new file mode 100644
index 000000000..b1969ae21
--- /dev/null
+++ b/com.gradleware.tooling.eclipse.core/src/main/java/com/gradleware/tooling/eclipse/core/configuration/ProjectConfiguration.java
@@ -0,0 +1,106 @@
+/*
+ * Copyright (c) 2015 the original author or authors.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Etienne Studer & Donát Csikós (Gradle Inc.) - initial API and implementation and initial documentation
+ */
+
+package com.gradleware.tooling.eclipse.core.configuration;
+
+import java.io.File;
+
+import com.google.common.base.Objects;
+import com.google.common.base.Preconditions;
+import com.gradleware.tooling.toolingmodel.OmniEclipseProject;
+import com.gradleware.tooling.toolingmodel.Path;
+import com.gradleware.tooling.toolingmodel.repository.FixedRequestAttributes;
+
+/**
+ * Describes the Gradle-specific configuration of an Eclipse project.
+ */
+public final class ProjectConfiguration {
+
+ private final FixedRequestAttributes requestAttributes;
+ private final Path projectPath;
+ private final File projectDir;
+
+ private ProjectConfiguration(FixedRequestAttributes requestAttributes, Path projectPath, File projectDir) {
+ this.requestAttributes = Preconditions.checkNotNull(requestAttributes);
+ this.projectPath = Preconditions.checkNotNull(projectPath);
+ this.projectDir = Preconditions.checkNotNull(projectDir);
+ }
+
+ /**
+ * Returns the request attributes that are used to connect to the Gradle project.
+ *
+ * @return the request attributes used to connect to the Gradle project, never null
+ */
+ public FixedRequestAttributes getRequestAttributes() {
+ return this.requestAttributes;
+ }
+
+ /**
+ * Returns the path of the Gradle project.
+ *
+ * @return the path of the Gradle project, never null
+ */
+ public Path getProjectPath() {
+ return this.projectPath;
+ }
+
+ /**
+ * Returns the location of the Gradle project.
+ *
+ * @return the location of the Gradle project, never null
+ */
+ public File getProjectDir() {
+ return this.projectDir;
+ }
+
+ @Override
+ public boolean equals(Object other) {
+ if (this == other) {
+ return true;
+ }
+ if (other == null || getClass() != other.getClass()) {
+ return false;
+ }
+
+ ProjectConfiguration that = (ProjectConfiguration) other;
+ return Objects.equal(this.requestAttributes, that.requestAttributes) && Objects.equal(this.projectDir, that.projectDir)
+ && Objects.equal(this.projectPath, that.projectPath);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hashCode(this.requestAttributes, this.projectDir, this.projectPath);
+ }
+
+ /**
+ * Creates a new instance.
+ *
+ * @param requestAttributes the connection aspects of the configuration
+ * @param project the project aspects of the configuration
+ * @return the new instance
+ */
+ public static ProjectConfiguration from(FixedRequestAttributes requestAttributes, OmniEclipseProject project) {
+ return from(requestAttributes, project.getPath(), project.getProjectDirectory());
+ }
+
+ /**
+ * Creates a new instance.
+ *
+ * @param requestAttributes the connection aspects of the configuration
+ * @param projectPath the path of the Gradle project
+ * @param projectDir the location of the Gradle project
+ * @return the new instance
+ */
+ public static ProjectConfiguration from(FixedRequestAttributes requestAttributes, Path projectPath, File projectDir) {
+ return new ProjectConfiguration(requestAttributes, projectPath, projectDir);
+ }
+
+}
diff --git a/com.gradleware.tooling.eclipse.core/src/main/java/com/gradleware/tooling/eclipse/core/configuration/ProjectConfigurationManager.java b/com.gradleware.tooling.eclipse.core/src/main/java/com/gradleware/tooling/eclipse/core/configuration/ProjectConfigurationManager.java
new file mode 100644
index 000000000..8ba258dc4
--- /dev/null
+++ b/com.gradleware.tooling.eclipse.core/src/main/java/com/gradleware/tooling/eclipse/core/configuration/ProjectConfigurationManager.java
@@ -0,0 +1,54 @@
+/*
+ * Copyright (c) 2015 the original author or authors.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Etienne Studer & Donát Csikós (Gradle Inc.) - initial API and implementation and initial documentation
+ */
+
+package com.gradleware.tooling.eclipse.core.configuration;
+
+import org.eclipse.core.resources.IProject;
+
+import com.google.common.collect.ImmutableSet;
+
+/**
+ * Manages the persisted configuration of Gradle projects in the Eclipse workspace.
+ */
+public interface ProjectConfigurationManager {
+
+ /**
+ * Returns the unique set of {@link ProjectConfiguration} roots found in the workspace.
+ *
+ * @return the unique set of {@code ProjectConfiguration} roots
+ */
+ ImmutableSetbundled
scope, and copies
+ * them (including transitives) into the lib folder and modifies the bundle manifest to export all packages from the libraries.
+ */
+class BundlePlugin implements Plugingradle tasks
.
+ */
+ static String getGradleTaskGroupName() {
+ return "Eclipse Plugin Build"
+ }
+
+ /**
+ * Eclipse runtime abbreviation of the operating system.
+ * http://help.eclipse.org/indigo/topic/org.eclipse.platform.doc.isv/reference/misc/runtime-options.html
+ *
+ * @return The operating system: 'linux', 'win32' or 'macosx'
+ */
+ static String getOs() {
+ OperatingSystem os = OperatingSystem.current()
+ os.isLinux() ? 'linux' : os.isWindows() ? 'win32' : os.isMacOsX() ? 'macosx': null
+ }
+
+ /**
+ * Eclipse runtime abbreviation of the windowing system.
+ * http://help.eclipse.org/indigo/topic/org.eclipse.platform.doc.isv/reference/misc/runtime-options.html
+ *
+ * @return The windowing system: 'gtk', 'win32' or 'cocoa'
+ */
+ static String getWs() {
+ OperatingSystem os = OperatingSystem.current()
+ os.isLinux() ? 'gtk' : os.isWindows() ? 'win32' : os.isMacOsX() ? 'cocoa' : null
+ }
+
+ /**
+ * Eclipse runtime abbreviation of the architecture.
+ * http://help.eclipse.org/indigo/topic/org.eclipse.platform.doc.isv/reference/misc/runtime-options.html
+ *
+ * @return The architecture: x86, x86_64 or ppc
+ */
+ static String getArch() {
+ System.getProperty("os.arch").contains("64") ? "x86_64" : "x86"
+ }
+
+ /**
+ * @return The list of Eclipse versions supported by this Eclipse build. Possible values: '37', '42', '43' or '44',
+ */
+ static List
+ apply plugin: eclipsebuild.Feature
+
+ feature {
+ featureXml = file('feature.xml')
+ }
+
+ *
+ * apply plugin: eclipsebuild.UpdateSite
+ *
+ * updateSite {
+ * siteDescriptor = file("category.xml")
+ * }
+ *
+ * Where the category.xml file exists in the project.
+ *
+ *
+ * org.eclipse.core.resources.natures
+ * extension point in the plugin.xml.
+ */
+public final class GradleNature implements IProjectNature {
+
+ // the nature ID has to be in the following format: ${PLUGIN_ID}.${NATURE_ID}
+ // the nature id is defined in the external (xml) file specified in the plugin.xml
+ public static final String ID = CorePlugin.PLUGIN_ID + ".nature";
+
+ private IProject project;
+
+ @Override
+ public void configure() {
+ }
+
+ @Override
+ public void deconfigure() {
+ }
+
+ @Override
+ public IProject getProject() {
+ return this.project;
+ }
+
+ @Override
+ public void setProject(IProject project) {
+ this.project = project;
+ }
+
+ /**
+ * Determines if the specified project has the Gradle nature applied.
+ *
+ * @param project the project to verify
+ * @return {@code true} iff the specified project has the Gradle nature applied
+ */
+ public static boolean isPresentOn(IProject project) {
+ // abort if the project is closed since we cannot investigate closed projects
+ if (!project.isOpen()) {
+ String message = String.format("Cannot investigate Gradle nature on closed project %s.", project);
+ CorePlugin.logger().error(message);
+ throw new GradlePluginsRuntimeException(message);
+ }
+
+ // check if the Gradle nature is applied
+ try {
+ return project.hasNature(ID);
+ } catch (CoreException e) {
+ String message = String.format("Cannot check for Gradle nature on project %s.", project);
+ CorePlugin.logger().error(message, e);
+ throw new GradlePluginsRuntimeException(message, e);
+ }
+ }
+
+}
diff --git a/com.gradleware.tooling.eclipse.core/src/main/java/com/gradleware/tooling/eclipse/core/GradlePluginsRuntimeException.java b/com.gradleware.tooling.eclipse.core/src/main/java/com/gradleware/tooling/eclipse/core/GradlePluginsRuntimeException.java
new file mode 100644
index 000000000..1ce0fc0e7
--- /dev/null
+++ b/com.gradleware.tooling.eclipse.core/src/main/java/com/gradleware/tooling/eclipse/core/GradlePluginsRuntimeException.java
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2015 the original author or authors.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Etienne Studer & Donát Csikós (Gradle Inc.) - initial API and implementation and initial documentation
+ */
+
+package com.gradleware.tooling.eclipse.core;
+
+/**
+ * Base class for all custom unchecked exception types thrown by the Gradle integration plugins.
+ */
+public class GradlePluginsRuntimeException extends RuntimeException {
+
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * Creates a new instance.
+ *
+ * @param message the detail message
+ */
+ public GradlePluginsRuntimeException(String message) {
+ super(message);
+ }
+
+ /**
+ * Creates a new instance.
+ *
+ * @param message the detail message
+ * @param cause the cause
+ */
+ public GradlePluginsRuntimeException(String message, Exception cause) {
+ super(message, cause);
+ }
+
+ /**
+ * Creates a new instance.
+ *
+ * @param cause the cause
+ */
+ public GradlePluginsRuntimeException(Exception cause) {
+ super(cause);
+ }
+
+}
diff --git a/com.gradleware.tooling.eclipse.core/src/main/java/com/gradleware/tooling/eclipse/core/Logger.java b/com.gradleware.tooling.eclipse.core/src/main/java/com/gradleware/tooling/eclipse/core/Logger.java
new file mode 100644
index 000000000..19d1ad6d8
--- /dev/null
+++ b/com.gradleware.tooling.eclipse.core/src/main/java/com/gradleware/tooling/eclipse/core/Logger.java
@@ -0,0 +1,69 @@
+/*
+ * Copyright (c) 2015 the original author or authors.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Etienne Studer & Donát Csikós (Gradle Inc.) - initial API and implementation and initial documentation
+ */
+
+package com.gradleware.tooling.eclipse.core;
+
+/**
+ * Simplifying abstraction over Eclipse's logging ({@link org.eclipse.core.runtime.ILog}) interface.
+ *
+ * try {
+ * ...
+ * } catch (Exception e) {
+ * CorePlugin.logger().error(e);
+ * }o
+ *
+ *
+ * Instead of doing this:
+ *
+ *
+ * try {
+ * ...
+ * } catch (Exception e) {
+ * CorePlugin.getInstance().getLog().log(new Status(IStatus.ERROR, CorePlugin.PLUGIN_ID, "Error occurred", e));
+ * }
+ *
+ *