-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#2459 store and restore IDE state: opened files, opened part and thei…
- Loading branch information
Evgen Vidolob
committed
Oct 27, 2016
1 parent
d55fbe9
commit 9f96c77
Showing
61 changed files
with
1,875 additions
and
336 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
119 changes: 119 additions & 0 deletions
119
ide/che-core-dyna-provider-generator-maven-plugin/pom.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
Copyright (c) 2012-2016 Codenvy, S.A. | ||
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: | ||
Codenvy, S.A. - initial API and implementation | ||
--> | ||
<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/maven-v4_0_0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<artifactId>che-core-ide-parent</artifactId> | ||
<groupId>org.eclipse.che.core</groupId> | ||
<version>5.0.0-M6-SNAPSHOT</version> | ||
</parent> | ||
<artifactId>che-core-dyna-provider-generator-maven-plugin</artifactId> | ||
<packaging>maven-plugin</packaging> | ||
<name>che-core-dyna-provider-generator-maven-plugin Maven Mojo</name> | ||
<url>http://maven.apache.org</url> | ||
<dependencies> | ||
<dependency> | ||
<groupId>com.google.guava</groupId> | ||
<artifactId>guava</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.antlr</groupId> | ||
<artifactId>ST4</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.eclipse.che.core</groupId> | ||
<artifactId>che-core-commons-gwt</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.reflections</groupId> | ||
<artifactId>reflections</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.maven</groupId> | ||
<artifactId>maven-artifact</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.maven</groupId> | ||
<artifactId>maven-model</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.maven</groupId> | ||
<artifactId>maven-plugin-api</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.maven.plugin-tools</groupId> | ||
<artifactId>maven-plugin-annotations</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.eclipse.sisu</groupId> | ||
<artifactId>org.eclipse.sisu.plexus</artifactId> | ||
<scope>provided</scope> | ||
<exclusions> | ||
<exclusion> | ||
<artifactId>jsr250-api</artifactId> | ||
<groupId>javax.annotation</groupId> | ||
</exclusion> | ||
</exclusions> | ||
</dependency> | ||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.maven</groupId> | ||
<artifactId>maven-compat</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.maven.plugin-testing</groupId> | ||
<artifactId>maven-plugin-testing-harness</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.codehaus.plexus</groupId> | ||
<artifactId>plexus-utils</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.mockito</groupId> | ||
<artifactId>mockito-all</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-plugin-plugin</artifactId> | ||
<executions> | ||
<execution> | ||
<id>mojo-descriptor</id> | ||
<goals> | ||
<goal>descriptor</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
<configuration> | ||
<skipErrorNoDescriptorsFound>true</skipErrorNoDescriptorsFound> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
37 changes: 37 additions & 0 deletions
37
...a-provider-generator-maven-plugin/src/main/java/org/eclipse/che/providers/ClassModel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2012-2016 Codenvy, S.A. | ||
* 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: | ||
* Codenvy, S.A. - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.che.providers; | ||
|
||
/** | ||
* Data class for generator. | ||
* Holds class name and variable name for class. | ||
* | ||
* @author Evgen Vidolob | ||
*/ | ||
public class ClassModel { | ||
|
||
private String name; | ||
|
||
private String varName; | ||
|
||
public ClassModel(Class<?> clazz) { | ||
name = clazz.getName(); | ||
varName = clazz.getName().replaceAll("\\.", "_"); | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public String getVarName() { | ||
return varName; | ||
} | ||
} |
115 changes: 115 additions & 0 deletions
115
...generator-maven-plugin/src/main/java/org/eclipse/che/providers/DynaProviderGenerator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2012-2016 Codenvy, S.A. | ||
* 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: | ||
* Codenvy, S.A. - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.che.providers; | ||
|
||
import com.google.common.io.Resources; | ||
|
||
import org.reflections.Reflections; | ||
import org.reflections.scanners.SubTypesScanner; | ||
import org.reflections.scanners.TypeAnnotationsScanner; | ||
import org.reflections.util.ClasspathHelper; | ||
import org.reflections.util.ConfigurationBuilder; | ||
import org.stringtemplate.v4.ST; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.net.URL; | ||
import java.net.URLClassLoader; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Set; | ||
|
||
import static java.nio.charset.StandardCharsets.UTF_8; | ||
|
||
/** | ||
* Generate implementation for {@link DynaProvider}. | ||
* Find all types annotated with {@link DynaObject} and add {@link com.google.inject.Provider} for them to {@link DynaProvider} implementation. | ||
* | ||
* @author Evgen Vidolob | ||
*/ | ||
public class DynaProviderGenerator { | ||
|
||
private static final String TEMPLATE_PATH = | ||
"/".concat(DynaProviderGenerator.class.getPackage().getName().replace(".", "/")).concat("/DynaProvider.st"); | ||
|
||
/** | ||
* String template instance used | ||
*/ | ||
private ST st; | ||
|
||
private final String packageName; | ||
private final String className; | ||
private final List<String> classpath; | ||
private List<ClassModel> dynaClasses; | ||
|
||
|
||
public DynaProviderGenerator(String packageName, String className, List<String> classpath) { | ||
this.packageName = packageName; | ||
this.className = className; | ||
this.classpath = classpath; | ||
} | ||
|
||
public String generate() throws IOException { | ||
dynaClasses = new ArrayList<>(); | ||
findDynaObjects(); | ||
|
||
ST st = getTemplate(); | ||
st.add("packageName", packageName); | ||
st.add("className", className); | ||
st.add("classes", dynaClasses); | ||
return st.render(); | ||
} | ||
|
||
private void findDynaObjects() throws IOException { | ||
ConfigurationBuilder configuration = new ConfigurationBuilder(); | ||
|
||
List<URL> urls = new ArrayList<>(); | ||
for (String element : classpath) { | ||
urls.add(new File(element).toURI().toURL()); | ||
} | ||
|
||
ClassLoader contextClassLoader = URLClassLoader.newInstance( | ||
urls.toArray(new URL[urls.size()]), | ||
Thread.currentThread().getContextClassLoader()); | ||
Thread.currentThread().setContextClassLoader(contextClassLoader); | ||
configuration.setUrls(ClasspathHelper.forClassLoader(contextClassLoader)); | ||
configuration.setScanners(new SubTypesScanner(), | ||
new TypeAnnotationsScanner()); | ||
Reflections reflection = new Reflections(configuration); | ||
|
||
Set<Class<?>> classes = reflection.getTypesAnnotatedWith(DynaObject.class); | ||
for (Class clazz : classes) { | ||
//accept only classes | ||
if (clazz.isEnum() || clazz.isInterface() || clazz.isAnnotation()) { | ||
continue; | ||
} | ||
dynaClasses.add(new ClassModel(clazz)); | ||
System.out.println(String.format("New Dyna Object Found: %s", clazz.getCanonicalName())); | ||
} | ||
System.out.println(String.format("Found: %d Dyna Objects", dynaClasses.size())); | ||
} | ||
|
||
/** | ||
* Get the template for provider | ||
* @return the String Template | ||
*/ | ||
protected ST getTemplate() { | ||
if (st == null) { | ||
URL url = Resources.getResource(DynaProviderGenerator.class, TEMPLATE_PATH); | ||
try { | ||
st = new ST(Resources.toString(url, UTF_8)); | ||
} catch (IOException e) { | ||
throw new IllegalArgumentException("Unable to read template", e); | ||
} | ||
} | ||
return st; | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
...ider-generator-maven-plugin/src/main/java/org/eclipse/che/providers/DynaProviderMojo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2012-2016 Codenvy, S.A. | ||
* 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: | ||
* Codenvy, S.A. - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.che.providers; | ||
|
||
import org.apache.maven.plugin.AbstractMojo; | ||
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 java.io.BufferedWriter; | ||
import java.io.File; | ||
import java.io.FileWriter; | ||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.util.List; | ||
|
||
/** | ||
* Mojo for generation implementation of DynaProvider interface. | ||
* | ||
* @author Evgen Vidolob | ||
*/ | ||
@Mojo(name = "generate", requiresDependencyResolution = ResolutionScope.COMPILE) | ||
public class DynaProviderMojo extends AbstractMojo { | ||
@Parameter(property = "outputDir", required = true) | ||
private String outputDirectory; | ||
|
||
@Parameter(property = "typeName", defaultValue = "org.eclipse.che.providers.DynaProviderImpl") | ||
private String typeName; | ||
|
||
@Parameter(property = "project.compileClasspathElements", required = true, readonly = true) | ||
private List<String> classpath; | ||
|
||
@Override | ||
public void execute() throws MojoExecutionException, MojoFailureException { | ||
File outFile = new File(outputDirectory, typeName.replace('.', File.separatorChar) + ".java"); | ||
String packageName = typeName.substring(0, typeName.lastIndexOf('.')); | ||
String className = typeName.substring(typeName.lastIndexOf('.') + 1, typeName.length()); | ||
|
||
DynaProviderGenerator generator = new DynaProviderGenerator(packageName, className, classpath); | ||
|
||
|
||
try { | ||
Files.createDirectories(outFile.toPath().getParent()); | ||
} catch (IOException e) { | ||
throw new MojoExecutionException("Can't create packages folders", e); | ||
} | ||
try (BufferedWriter writer = new BufferedWriter(new FileWriter(outFile))) { | ||
writer.write(generator.generate()); | ||
} catch (IOException e) { | ||
throw new MojoExecutionException("Can't write file content", e); | ||
} | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
...vider-generator-maven-plugin/src/main/resources/org/eclipse/che/providers/DynaProvider.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2012-2016 Codenvy, S.A. | ||
* 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: | ||
* Codenvy, S.A. - initial API and implementation | ||
*******************************************************************************/ | ||
package <packageName>; | ||
|
||
import com.google.inject.Provider; | ||
import com.google.inject.Inject; | ||
import com.google.inject.Singleton; | ||
import java.util.Map; | ||
import java.util.HashMap; | ||
|
||
// File has been generated automatically by Eclipse Che Dyna provider generator plugin | ||
@Singleton | ||
@SuppressWarnings("unchecked") | ||
public class <className> implements org.eclipse.che.providers.DynaProvider { | ||
|
||
private final Map\<String, Provider\<?>> providers = new HashMap\<>(); | ||
|
||
@Override | ||
public \<T> Provider\<T> getProvider(String className) { | ||
return (Provider\<T>)providers.get(className); | ||
} | ||
|
||
@Inject | ||
public <className>(<if(!classes.empty)> | ||
<classes: {clazz | Provider\<<clazz.name>> <clazz.varName>}; separator=",\n"><endif>) { | ||
|
||
<classes : {clazz | providers.put("<clazz.name>", <clazz.varName>);}; separator="\n"> | ||
} | ||
|
||
} |
Oops, something went wrong.