Skip to content

Commit

Permalink
Extract migration logic into separate class and use in inside maven p…
Browse files Browse the repository at this point in the history
…lugin and main class (#6152)

* Make new module and copy initial code there.

* Extract mojo functionality to external class and use it from main Java
class

* Move migration logic to the standalone module

* Transfer code from pending PR and add javadocs

* Adapt the code for the latest master branch state.

* Review fixes.

* Add check for faulty migration folder.

* Merge branch 'master' into 6095-migration-stand-alone

# Conflicts:
#	flow-migration/src/test/java/com/vaadin/flow/migration/CopyResourcesStepTest.java

* Fix sonar issues

* Add happy-path test for Migration.migration

* Don't use clone.

* Remove clone

* Clone File arrays to keep them separate from given configuration.

* null check

* No actuall install.

Check executions to be expected command chains
  • Loading branch information
Denis authored and Johannes Eriksson committed Aug 13, 2019
1 parent 03bb687 commit 413a4b7
Show file tree
Hide file tree
Showing 46 changed files with 2,224 additions and 504 deletions.
37 changes: 3 additions & 34 deletions flow-maven-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,22 +45,13 @@
<artifactId>frontend-plugin-core</artifactId>
<version>1.6</version>
</dependency>
<dependency>
<groupId>org.reflections</groupId>
<artifactId>reflections</artifactId>
<version>0.9.11</version>
</dependency>

<dependency>
<groupId>com.vaadin</groupId>
<artifactId>flow-server</artifactId>
<artifactId>flow-migration</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>

<dependency>
<groupId>org.apache.maven.plugin-tools</groupId>
<artifactId>maven-plugin-annotations</artifactId>
Expand Down Expand Up @@ -115,28 +106,6 @@
</plugin>
</plugins>
</pluginManagement>

<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<id>add-resource</id>
<phase>generate-resources</phase>
<goals>
<goal>add-test-resource</goal>
</goals>
<configuration>
<resources>
<resource>
<directory>src/test/java</directory>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>

</build>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.util.stream.Collectors;
import java.util.stream.Stream;

import com.vaadin.flow.migration.ClassPathIntrospector;
import com.vaadin.flow.server.frontend.scanner.ClassFinder;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,88 +17,21 @@
package com.vaadin.flow.plugin.common;

import java.io.File;
import java.lang.annotation.Annotation;
import java.lang.annotation.Repeatable;
import java.lang.reflect.AnnotatedElement;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.apache.maven.artifact.DependencyResolutionRequiredException;
import org.apache.maven.project.MavenProject;
import org.reflections.Reflections;
import org.reflections.util.ConfigurationBuilder;

import com.vaadin.flow.server.frontend.scanner.ClassFinder;
import com.vaadin.flow.server.scanner.ReflectionsClassFinder;
import com.vaadin.flow.utils.FlowFileUtils;

/**
* Utility methods used by all goals.
*/
public class FlowPluginFrontendUtils {

/**
* A class finder using org.reflections.
*/
public static class ReflectionsClassFinder implements ClassFinder {
private final transient ClassLoader classLoader;

private final transient Reflections reflections;

/**
* Constructor.
*
* @param urls
* the list of urls for finding classes.
*/
public ReflectionsClassFinder(URL... urls) {
classLoader = new URLClassLoader(urls, null); // NOSONAR
reflections = new Reflections(
new ConfigurationBuilder().addClassLoader(classLoader)
.setExpandSuperTypes(false).addUrls(urls));
}

@Override
public Set<Class<?>> getAnnotatedClasses(
Class<? extends Annotation> clazz) {
Set<Class<?>> classes = new HashSet<>();
classes.addAll(reflections.getTypesAnnotatedWith(clazz, true));
classes.addAll(getAnnotatedByRepeatedAnnotation(clazz));
return classes;

}

private Set<Class<?>> getAnnotatedByRepeatedAnnotation(
AnnotatedElement annotationClass) {
Repeatable repeatableAnnotation = annotationClass
.getAnnotation(Repeatable.class);
if (repeatableAnnotation != null) {
return reflections.getTypesAnnotatedWith(
repeatableAnnotation.value(), true);
}
return Collections.emptySet();
}

@Override
public URL getResource(String name) {
return classLoader.getResource(name);
}

@SuppressWarnings("unchecked")
@Override
public <T> Class<T> loadClass(String name)
throws ClassNotFoundException {
return (Class<T>) classLoader.loadClass(name);
}

@Override
public <T> Set<Class<? extends T>> getSubTypesOf(Class<T> type) {
return reflections.getSubTypesOf(type);
}
}

private FlowPluginFrontendUtils() {
}

Expand All @@ -120,7 +53,7 @@ public static ClassFinder getClassFinder(MavenProject project) {
project), e);
}
URL[] urls = runtimeClasspathElements.stream().map(File::new)
.map(FlowPluginFileUtils::convertToUrl).toArray(URL[]::new);
.map(FlowFileUtils::convertToUrl).toArray(URL[]::new);

return new ReflectionsClassFinder(urls);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import com.vaadin.flow.component.dependency.HtmlImport;
import com.vaadin.flow.component.dependency.JavaScript;
import com.vaadin.flow.component.dependency.StyleSheet;
import com.vaadin.flow.migration.ClassPathIntrospector;
import com.vaadin.flow.server.Constants;
import com.vaadin.flow.shared.ApplicationConstants;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.vaadin.flow.utils.FlowFileUtils;

/**
* Entity to operate frontend tools to transpile files.
* <p>
Expand Down Expand Up @@ -85,7 +87,7 @@ public FrontendToolsManager(File workingDirectory,
String es5OutputDirectoryName, String es6OutputDirectoryName,
FrontendDataProvider frontendDataProvider,
RunnerManager runnerManager) {
FlowPluginFileUtils
FlowFileUtils
.forceMkdir(Objects.requireNonNull(workingDirectory));
this.runnerManager = Objects.requireNonNull(runnerManager);
this.workingDirectory = workingDirectory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.slf4j.LoggerFactory;

import com.vaadin.flow.internal.ReflectTools;
import com.vaadin.flow.migration.ClassPathIntrospector;
import com.vaadin.flow.theme.AbstractTheme;
import com.vaadin.flow.theme.Theme;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.util.stream.Collectors;

import com.vaadin.flow.component.WebComponentExporter;
import com.vaadin.flow.migration.ClassPathIntrospector;
import com.vaadin.flow.server.webcomponent.WebComponentModulesWriter;

/**
Expand All @@ -29,7 +30,7 @@
* Uses {@link com.vaadin.flow.server.webcomponent.WebComponentModulesWriter} to
* generate web component modules files from
* {@link com.vaadin.flow.component.WebComponentExporter} implementations found
* by {@link com.vaadin.flow.plugin.common.ClassPathIntrospector}.
* by {@link com.vaadin.flow.migration.ClassPathIntrospector}.
*
* @author Vaadin Ltd.
*/
Expand All @@ -43,7 +44,7 @@ public class WebComponentModulesGenerator extends ClassPathIntrospector {
* {@link com.vaadin.flow.component.WebComponentExporter} classes.
*
* @param introspector
* {@link com.vaadin.flow.plugin.common.ClassPathIntrospector}
* {@link com.vaadin.flow.migration.ClassPathIntrospector}
* implementation to use as a base.
*/
public WebComponentModulesGenerator(ClassPathIntrospector introspector) {
Expand Down
Loading

0 comments on commit 413a4b7

Please sign in to comment.