Skip to content

Commit

Permalink
Fix Eclipse plugin build
Browse files Browse the repository at this point in the history
Updates the Eclipse plugin build logic. The logic is now completely separate from the main google java format build. Instead of relying on the build artifacts of the core build, the needed google-java-format and guava build artifacts used for the build are now pulled from maven.

Updates google-java-format version used for the build to '1.9', the build JDK to 11, and removes old dependencies which are no longer used.

Updates tycho version to 1.7.0 in order to build with JDK > 8.

Updates the build guide in the README.

Fixes #465

COPYBARA_INTEGRATE_REVIEW=#465 from tobous:fix-eclipse-build e80a72b
PiperOrigin-RevId: 387615841
  • Loading branch information
tobous authored and google-java-format Team committed Jul 29, 2021
1 parent cc8b96f commit 93ee8fe
Show file tree
Hide file tree
Showing 6 changed files with 109 additions and 93 deletions.
45 changes: 0 additions & 45 deletions core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -156,51 +156,6 @@
</archive>
</configuration>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.1</version>
<executions>
<execution>
<id>copy-resources</id>
<phase>package</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>../eclipse_plugin/lib</outputDirectory>
<resources>
<resource>
<directory>target</directory>
<include>${project.artifactId}-${project.version}.jar</include>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.10</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>../eclipse_plugin/lib</outputDirectory>
<overWriteReleases>true</overWriteReleases>
<overWriteSnapshots>true</overWriteSnapshots>
<excludeTransitive>true</excludeTransitive>
<excludeArtifactIds>org.eclipse.jdt.core</excludeArtifactIds>
<excludeScope>compile</excludeScope>
<excludeScope>provided</excludeScope>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.google.code.maven-replacer-plugin</groupId>
<artifactId>replacer</artifactId>
Expand Down
10 changes: 5 additions & 5 deletions eclipse_plugin/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: google-java-format
Bundle-SymbolicName: google-java-format-eclipse-plugin;singleton:=true
Bundle-Version: 1.6.0
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Bundle-Vendor: Google
Bundle-Version: 1.9.0
Bundle-RequiredExecutionEnvironment: JavaSE-11
Require-Bundle: org.eclipse.jdt.core;bundle-version="3.10.0",
org.eclipse.jface,
org.eclipse.text,
org.eclipse.ui,
org.eclipse.equinox.common
Bundle-ClassPath: .,
lib/guava-22.0.jar,
lib/javac-shaded-9+181-r4173-1.jar,
lib/google-java-format-1.6.jar
lib/guava-28.1-jre.jar,
lib/google-java-format-1.9.jar
61 changes: 42 additions & 19 deletions eclipse_plugin/README.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,49 @@
# google-java-format Eclipse Plugin
# Google Java Format Eclipse Plugin

## Enabling

See https://github.com/google/google-java-format#eclipse

## Development

1) Uncomment `<module>eclipse_plugin</module>` in the parent `pom.xml`

2) Run `mvn install`, which will copy the dependences of the plugin to
`eclipse_plugin/lib`.

2) If you are using Java 9, add

```
-vm
/Library/Java/JavaVirtualMachines/jdk1.8.0_91.jdk/Contents/Home/bin/java
```

to `/Applications/Eclipse.app/Contents/Eclipse/eclipse.ini`.

3) Open the `eclipse_plugin` project in a recent Eclipse SDK build.

4) From `File > Export` select `Plugin-in Development > Deployable plugin-ins
and fragments` and follow the wizard to export a plugin jar.
### Prerequisites

Make sure that the `build.properties` and `META-INF/MANIFEST.MF` contain all
necessary dependencies for the build. Furthermore, make sure that the
dependencies declared in the `pom.xml` match the entries in `build.properties`
and `META-INF/MANIFEST.MF`.

If the used google java format core version is a 'SNAPSHOT' release, the version
for the Eclipse plugin in the `pom.xml` must end in '-SNAPSHOT' as well and the
bundle version specified in `META-INF/MANIFEST.MF` must end in '.qualifier'.

### Building the Plugin

1) Run `mvn clean package` in the `eclipse_plugin` directory. This will first copy the dependencies
of the plugin to `eclipse_plugin/lib/` and then triggers the tycho build that uses these
dependencies (as declared in `build.properties`) for the actual Eclipse plugin build.<br><br>
If you also want to add the build artifact to the local maven repository, you can use
`mvn clean install -Dtycho.localArtifacts=ignore` instead. Note, however, that you then must use
this build command for every build with that specific version number until you clear the build
artifact (or the
[p2-local-metadata.properties](https://wiki.eclipse.org/Tycho/Target_Platform#Locally_built_artifacts))
from your local repository. Otherwise, you might run into issues caused by the build using an
outdated build artifact created by a previous build instead of re-building the plugin. More
information on this issue is given
[in this thread](https://www.eclipse.org/lists/tycho-user/msg00952.html) and
[this bug tracker entry](https://bugs.eclipse.org/bugs/show_bug.cgi?id=355367).

2) You can find the built plugin in
`eclipse_plugin/target/google-java-format-eclipse-plugin-<version>.jar`

#### Building against a local (snapshot) release of the core

With the current build setup, the Eclipse plugin build pulls the needed build
artifacts of the google java format core specified in the property
`google-java-format.version` and copies it into the `eclipse_plugin/lib/`
directory.

If you instead want to build against a local (snapshot) build of the core which
is not available in a maven repository (local or otherwise), you will have to
place the appropriate version into the `eclipse_plugin/lib/` directory yourself
before the build.
5 changes: 2 additions & 3 deletions eclipse_plugin/build.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,5 @@ output.. = target/classes
bin.includes = META-INF/,\
.,\
plugin.xml,\
lib/javac-shaded-9+181-r4173-1.jar,\
lib/guava-22.0.jar,\
lib/google-java-format-1.6.jar
lib/guava-28.1-jre.jar,\
lib/google-java-format-1.9.jar
3 changes: 2 additions & 1 deletion eclipse_plugin/plugin.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>

<!--
Copyright 2020 Google Inc.
Expand All @@ -14,7 +16,6 @@
limitations under the License.
-->

<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>
<extension point="org.eclipse.jdt.core.javaFormatter">
Expand Down
78 changes: 58 additions & 20 deletions eclipse_plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,47 @@
~ limitations under the License.
-->

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.google.googlejavaformat</groupId>
<artifactId>google-java-format-parent</artifactId>
<version>1.6</version>
</parent>

<groupId>com.google.googlejavaformat</groupId>
<artifactId>google-java-format-eclipse-plugin</artifactId>
<version>1.6.0</version>
<packaging>eclipse-plugin</packaging>
<name>google-java-format Plugin for Eclipse 4.5+</name>
<version>1.9.0</version>

<name>Google Java Format Plugin for Eclipse 4.5+</name>

<description>
A Java source code formatter that follows Google Java Style.
A Java source code formatter plugin for Eclipse that follows Google Java Style.
</description>

<properties>
<tycho-version>0.26.0</tycho-version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

<tycho-version>1.7.0</tycho-version>

<!-- specific library versions; must match declarations in build.properties and META-INF/MANIFEST.MF -->
<google-java-format.version>1.9</google-java-format.version>
<guava.version>28.1-jre</guava.version>
</properties>

<dependencies>
<dependency>
<groupId>com.google.googlejavaformat</groupId>
<artifactId>google-java-format</artifactId>
<version>${google-java-format.version}</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>${guava.version}</version>
<type>jar</type>
</dependency>
</dependencies>

<repositories>
<repository>
<id>mars</id>
Expand All @@ -44,24 +63,35 @@
</repository>
</repositories>

<dependencies>
<dependency>
<groupId>com.google.googlejavaformat</groupId>
<artifactId>google-java-format</artifactId>
<version>1.6</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.1.2</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>initialize</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
</execution>
</executions>
<configuration>
<outputDirectory>lib</outputDirectory>
<includeScope>runtime</includeScope>
<excludeTransitive>true</excludeTransitive>
<overWriteSnapshots>true</overWriteSnapshots>
</configuration>
</plugin>

<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-maven-plugin</artifactId>
<version>${tycho-version}</version>
<extensions>true</extensions>
</plugin>

<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>target-platform-configuration</artifactId>
Expand Down Expand Up @@ -97,7 +127,15 @@
</configuration>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<source>11</source>
<target>11</target>
</configuration>
</plugin>
</plugins>
</build>

</project>

0 comments on commit 93ee8fe

Please sign in to comment.