Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

### Version 3.13.0-SNAPSHOT - TBD ([javadoc](http://diffplug.github.io/goomph/javadoc/snapshot/), [snapshot](https://oss.sonatype.org/content/repositories/snapshots/com/diffplug/gradle/goomph/))

- Added support for translating eclipse releases to maven central coordinates. [(#61)](https://github.com/diffplug/goomph/pull/61)

### Version 3.12.0 - February 26th 2018 ([javadoc](http://diffplug.github.io/goomph/javadoc/3.12.0/), [jcenter](https://bintray.com/diffplug/opensource/goomph/3.12.0/view))

- Added support for `includeLaunchers` property from product files [(#58)](https://github.com/diffplug/goomph/pull/58)
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,9 @@ Below is an index of Goomph's capabilities, along with links to the javadoc wher
* [`bndmanifest`](https://diffplug.github.io/goomph/javadoc/3.12.0/com/diffplug/gradle/osgi/BndManifestPlugin.html) generates a manifest using purely bnd, and outputs it for IDE consumption.
* [`OsgiExecable`](https://diffplug.github.io/goomph/javadoc/3.12.0/com/diffplug/gradle/osgi/OsgiExecable.html) makes it easy to run a chunk of code within an OSGi container, and get the result from outside the container.

**`com.diffplug.gradle.eclipse` Plugins for creating and manipulating eclipse project files.**
**`com.diffplug.gradle.eclipse` Plugins for handling eclipse' maven central artifacts and creating and manipulating eclipse project files.**

* [`mavencentral`](https://diffplug.github.io/goomph/javadoc/3.12.0/com/diffplug/gradle/eclipse/MavenCentralPlugin.html) makes it easy to add dependency jars from an eclipse release.
* [`buildproperties`](https://diffplug.github.io/goomph/javadoc/3.12.0/com/diffplug/gradle/eclipse/BuildPropertiesPlugin.html) uses [`build.properties`](http://help.eclipse.org/mars/index.jsp?topic=%2Forg.eclipse.pde.doc.user%2Fguide%2Ftools%2Feditors%2Fmanifest_editor%2Fbuild.htm) to control a gradle build, and fixes eclipse project classpath to include binary assets specified in `build.properties`.
* [`excludebuildfolder`](https://diffplug.github.io/goomph/javadoc/3.12.0/com/diffplug/gradle/eclipse/ExcludeBuildFolderPlugin.html) excludes the gradle `build` folder from Eclipse's resource indexing.
* [`projectdeps`](https://diffplug.github.io/goomph/javadoc/3.12.0/com/diffplug/gradle/eclipse/ProjectDepsPlugin.html) fixes an intermittent problem where dependencies on other projects within the workspace aren't always resolved correctly within Eclipse.
Expand Down
9 changes: 8 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ dependencies {
compileOnly 'p2:org.eclipse.jdt.launching:3.8.0.v20150527-0946'
compileOnly 'p2:org.eclipse.emf.ecore:2.11.2.v20160208-0816'
// testing
testCompile "junit:junit:${VER_JUNIT}"
testCompile "junit:junit:4.12"
testCompile "org.assertj:assertj-core:3.9.0"
}

test {
Expand Down Expand Up @@ -313,6 +314,12 @@ pluginBundle {
description = "Excludes the gradle build folder from Eclipse's resource indexing."
tags = ['eclipse']
}
eclipseMavenCentralPlugin {
id = 'com.diffplug.gradle.eclipse.mavencentral'
displayName = 'Goomph eclipse.mavencentral'
description = 'Maps eclipse releases and bundle ids to their MavenCentral coordinates.'
tags = ['eclipse', 'mavenCentral']
}
eclipseProjectDepsPlugin {
id = 'com.diffplug.gradle.eclipse.projectdeps'
displayName = 'Goomph eclipse.projectdeps'
Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ VER_SPOTLESS_LIB=1.5.1
# OSGi
VER_BNDLIB=3.5.0

# Testing
VER_JUNIT=4.12
# OSGi in Mars.1, latest uploaded to MavenCentral so far
VER_ECLIPSE_OSGI=3.10.101.v20150820-1432
14 changes: 14 additions & 0 deletions src/main/java/com/diffplug/gradle/GoomphCacheLocations.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,20 @@ public static void initFromProject(Project project) {
}
}

/**
* {@link MavenCentralMap} needs to look at p2 metadata
* to know what the version numbers are for the specific
* bundles of a given eclipse release are.
*
* Rather than downloading this metadata over and over, we only
* download it once, and cache the results here.
*/
public static File eclipseReleaseMetadata() {
return defOverride(ROOT + "/eclipse-release-metadata", override_eclipseReleaseMetadata);
}

public static File override_eclipseReleaseMetadata = null;

/**
* When Goomph creates an IDE for you, it must
* also create an eclipse workspace. Unfortunately,
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/com/diffplug/gradle/ZipMisc.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.charset.StandardCharsets;
import java.util.Enumeration;
import java.util.Map;
import java.util.function.Function;
import java.util.function.Predicate;
Expand Down Expand Up @@ -56,6 +57,17 @@ public static void read(File input, String toRead, Throwing.Specific.Consumer<In
ZipFile file = new ZipFile(input);
InputStream stream = file.getInputStream(file.getEntry(toRead));) {
reader.accept(stream);
} catch (NullPointerException e) {
if (e.getMessage().equals("entry")) {
System.err.println("No such entry: " + toRead);
try (ZipFile file = new ZipFile(input)) {
Enumeration<? extends ZipEntry> entries = file.entries();
while (entries.hasMoreElements()) {
ZipEntry entry = entries.nextElement();
System.err.println(" available: " + entry.getName());
}
}
}
}
}

Expand Down
116 changes: 116 additions & 0 deletions src/main/java/com/diffplug/gradle/eclipse/MavenCentralExtension.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
/*
* Copyright 2016 DiffPlug
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.diffplug.gradle.eclipse;

import java.io.IOException;
import java.util.Map;
import java.util.Objects;

import org.gradle.api.Action;
import org.gradle.api.Project;
import org.gradle.api.plugins.JavaPlugin;

import com.diffplug.common.swt.os.SwtPlatform;
import com.diffplug.gradle.pde.EclipseRelease;

public class MavenCentralExtension {
public static final String NAME = "eclipseMavenCentral";

private final Project project;

public MavenCentralExtension(Project project) {
this.project = Objects.requireNonNull(project);
}

public void release(String version, Action<ReleaseConfigurer> configurer) throws IOException {
release(EclipseRelease.official(version), configurer);
}

public void release(EclipseRelease release, Action<ReleaseConfigurer> configurer) throws IOException {
configurer.execute(new ReleaseConfigurer(release));
}

public class ReleaseConfigurer {
final EclipseRelease release;
final Map<String, String> bundleToVersion;

public ReleaseConfigurer(EclipseRelease release) throws IOException {
this.release = release;
this.bundleToVersion = MavenCentralMapping.bundleToVersion(release);
}

public void compileOnly(String bundleId) {
dep(JavaPlugin.COMPILE_ONLY_CONFIGURATION_NAME, bundleId);
}

public void testCompileOnly(String bundleId) {
dep(JavaPlugin.TEST_COMPILE_ONLY_CONFIGURATION_NAME, bundleId);
}

public void compile(String bundleId) {
dep(JavaPlugin.COMPILE_CONFIGURATION_NAME, bundleId);
}

public void testCompile(String bundleId) {
dep(JavaPlugin.TEST_COMPILE_CONFIGURATION_NAME, bundleId);
}

public void runtime(String bundleId) {
dep(JavaPlugin.RUNTIME_CONFIGURATION_NAME, bundleId);
}

public void testRuntime(String bundleId) {
dep(JavaPlugin.TEST_RUNTIME_CONFIGURATION_NAME, bundleId);
}

public void dep(String configName, String bundleId) {
String groupIdArtifactId = MavenCentralMapping.groupIdArtifactId(bundleId);
project.getDependencies().add(configName, groupIdArtifactId + ":" + bundleToVersion.get(bundleId));
}

/////////////
// natives //
/////////////
public void compileOnlyNative(String bundleId) {
nativeDep(JavaPlugin.COMPILE_ONLY_CONFIGURATION_NAME, bundleId);
}

public void testCompileOnlyNative(String bundleId) {
nativeDep(JavaPlugin.TEST_COMPILE_ONLY_CONFIGURATION_NAME, bundleId);
}

public void compileNative(String bundleId) {
nativeDep(JavaPlugin.COMPILE_CONFIGURATION_NAME, bundleId);
}

public void testCompileNative(String bundleId) {
nativeDep(JavaPlugin.TEST_COMPILE_CONFIGURATION_NAME, bundleId);
}

public void runtimeNative(String bundleId) {
nativeDep(JavaPlugin.RUNTIME_CONFIGURATION_NAME, bundleId);
}

public void testRuntimeNative(String bundleId) {
nativeDep(JavaPlugin.TEST_RUNTIME_CONFIGURATION_NAME, bundleId);
}

public void nativeDep(String configName, String bundleId) {
SwtPlatform platform = SwtPlatform.getRunning();
dep(configName, bundleId + "." + platform);
}
}
}
116 changes: 116 additions & 0 deletions src/main/java/com/diffplug/gradle/eclipse/MavenCentralMapping.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
/*
* Copyright 2016 DiffPlug
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.diffplug.gradle.eclipse;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

import org.osgi.framework.Version;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.xml.sax.SAXException;

import com.diffplug.common.base.Box;
import com.diffplug.common.base.Errors;
import com.diffplug.common.io.Files;
import com.diffplug.common.io.Resources;
import com.diffplug.gradle.FileMisc;
import com.diffplug.gradle.GoomphCacheLocations;
import com.diffplug.gradle.ZipMisc;
import com.diffplug.gradle.pde.EclipseRelease;

/** Maps eclipse jars to their mavenCentral artifact ids and versions based on their official release. */
public class MavenCentralMapping {
private static final EclipseRelease FIRST_ON_CENTRAL = EclipseRelease.official("4.6.2");

private static final String PLATFORM = "org.eclipse.platform";
private static final String JDT = "org.eclipse.jdt";
private static final String PDE = "org.eclipse.pde";

/** Returns the MavenCentral groupId:artifactId appropriate for the given bundleId. */
public static String groupIdArtifactId(String bundleId) {
if (bundleId.startsWith(JDT)) {
return JDT + ":" + bundleId;
} else if (bundleId.startsWith(PDE)) {
return PDE + ":" + bundleId;
} else {
return PLATFORM + ":" + bundleId;
}
}

/** Creates a map from bundle-id to its corresponding 3-part version. */
static Map<String, String> parse(InputStream inputStream) throws ParserConfigurationException, SAXException, IOException {
Map<String, String> map = new HashMap<>();
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse(inputStream);
Node artifacts = doc.getDocumentElement().getElementsByTagName("artifacts").item(0);
for (int i = 0; i < artifacts.getChildNodes().getLength(); ++i) {
Node artifact = artifacts.getChildNodes().item(i);
if ("artifact".equals(artifact.getNodeName())) {
String id = artifact.getAttributes().getNamedItem("id").getNodeValue();
String version = artifact.getAttributes().getNamedItem("version").getNodeValue();
Version parsed = Version.parseVersion(version);
map.put(id, parsed.getMajor() + "." + parsed.getMinor() + "." + parsed.getMicro());
}
}
return map;
}

private static final String ARTIFACTS_JAR = "artifacts.jar";

/** Returns a map from every bundle-id to its corresponding 3-part version (the qualifier is dropped). */
public static Map<String, String> bundleToVersion(EclipseRelease release) {
// warn if the user is asking for a too-old version of eclipse, but go ahead and try anyway just in case
if (release.version().compareTo(FIRST_ON_CENTRAL.version()) < 0) {
System.err.println(FIRST_ON_CENTRAL.version() + " was the first eclipse release that was published on MavenCentral.");
}
File versionFolder = new File(GoomphCacheLocations.eclipseReleaseMetadata(), release.version().toString());
FileMisc.mkdirs(versionFolder);
File artifactsJar = new File(versionFolder, ARTIFACTS_JAR);
if (artifactsJar.exists() && artifactsJar.length() > 0) {
try {
return parseFromFile(artifactsJar);
} catch (Exception e) {
e.printStackTrace();
System.err.println("Retrying download...");
FileMisc.forceDelete(artifactsJar);
}
}
return Errors.rethrow().get(() -> {
byte[] content = Resources.toByteArray(new URL(release.updateSite() + "artifacts.jar"));
Files.write(content, artifactsJar);
return parseFromFile(artifactsJar);
});
}

private static Map<String, String> parseFromFile(File artifactsJar) throws IOException {
Box.Nullable<Map<String, String>> value = Box.Nullable.ofNull();
ZipMisc.read(artifactsJar, "artifacts.xml", input -> {
value.set(Errors.rethrow().get(() -> parse(input)));
});
return Objects.requireNonNull(value.get());
}
}
Loading