Skip to content

Commit

Permalink
Add vaadin:upgrade8 which runs the migration tool (#90)
Browse files Browse the repository at this point in the history
  • Loading branch information
ahie authored Feb 17, 2017
1 parent 9b4b4cb commit dcba894
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 14 deletions.
20 changes: 6 additions & 14 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@
<vaadinVersion>${vaadin.version}</vaadinVersion>
<gwtVersion>${gwt.version}</gwtVersion>
<mavenVersion>3.0.5</mavenVersion>
<mavenPluginPluginVersion>3.2</mavenPluginPluginVersion>
<mavenPluginPluginVersion>3.5</mavenPluginPluginVersion>
<mojo.java.target>1.8</mojo.java.target>
<doxia-sitetoolsVersion>1.6</doxia-sitetoolsVersion>
<!-- to be able on powerfull ci machine to change it tru the cli :-) -->
Expand Down Expand Up @@ -150,19 +150,6 @@
<enabled>true</enabled>
</snapshots>
</repository>
<!-- Codehaus closed its services in 2015 -->
<!--
<repository>
<id>codehaus-snapshots</id>
<url>http://nexus.codehaus.org/snapshots</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
<releases>
<enabled>false</enabled>
</releases>
</repository>
-->
<repository>
<id>google-snapshots</id>
<url>https://oss.sonatype.org/content/repositories/google-snapshots/</url>
Expand Down Expand Up @@ -410,6 +397,11 @@
<artifactId>plexus-compiler-javac</artifactId>
<version>2.3</version>
</dependency>
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>framework8-migration-tool</artifactId>
<version>8.0-SNAPSHOT</version>
</dependency>
</dependencies>
<profiles>

Expand Down
60 changes: 60 additions & 0 deletions src/main/java/com/vaadin/integration/maven/Vaadin8UpgradeMojo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package com.vaadin.integration.maven;

import org.apache.maven.artifact.Artifact;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.plugins.annotations.ResolutionScope;
import org.codehaus.mojo.gwt.AbstractGwtMojo;

import com.vaadin.framework8.migrate.Migrate;

/**
* Updates Vaadin 7 class imports to their corresponding compatibility imports
* in a Vaadin 8 project. Additionally updates declarative files to use the correct
* versions of components.
*/
@Mojo(name = "upgrade8", requiresDependencyResolution = ResolutionScope.COMPILE)
public class Vaadin8UpgradeMojo extends AbstractGwtMojo {
/**
* The vaadin version to use for upgrading.
*/
@Parameter(property = "vaadin.version")
private String vaadinVersion;

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
if (vaadinVersion == null) {
vaadinVersion = getVaadinVersion();
}
if (vaadinVersion == null) {
throw new MojoExecutionException(
"Unable to determine the Vaadin version for the project. Use -Dvaadin.version=<version>");
}

if (!vaadinVersion.startsWith("8.")) {
throw new MojoExecutionException("Unexpected Vaadin version ("
+ vaadinVersion
+ "). Upgrade the project to Vaadin 8 or use -Dvaadin.version=<version> with a version starting with 8");
}
try {
Migrate.main(new String[] { "-version=" + vaadinVersion });
} catch (Exception e) {
throw new MojoFailureException("Problem migrating the project", e);
}
}

protected String getVaadinVersion() {
// find "vaadin-shared" and check its version
for (Artifact artifact : getProjectArtifacts()) {
if (VAADIN_GROUP_ID.equals(artifact.getGroupId())
&& "vaadin-shared".equals(artifact.getArtifactId())) {
return artifact.getVersion();
}
}

return null;
}

}

0 comments on commit dcba894

Please sign in to comment.