mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
google app engine: added converter for facet configuration [rev by Dmitry A.]
This commit is contained in:
@@ -27,7 +27,7 @@ import java.util.Collection;
|
||||
* @author nik
|
||||
*/
|
||||
public class ProjectConversionUtil {
|
||||
@NonNls private static final String PROJECT_FILES_BACKUP = "projectFilesBackup";
|
||||
@NonNls public static final String PROJECT_FILES_BACKUP = "projectFilesBackup";
|
||||
@NonNls private static final String BACKUP_EXTENSION = "backup";
|
||||
|
||||
private ProjectConversionUtil() {
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
<frameworkSupport implementation="com.intellij.appengine.facet.AppEngineSupportProvider"/>
|
||||
<fileTemplateGroup implementation="com.intellij.appengine.facet.AppEngineTemplateGroupDescriptorFactory"/>
|
||||
<facetType implementation="com.intellij.appengine.facet.AppEngineFacetType"/>
|
||||
<project.converterProvider implementation="com.intellij.appengine.converter.AppEngineFacetConverterProvider"/>
|
||||
<framework.detector implementation="com.intellij.appengine.facet.AppEngineFrameworkDetector"/>
|
||||
<compiler implementation="com.intellij.appengine.enhancement.EnhancerCompiler"/>
|
||||
<compileServer.plugin classpath="google-app-engine-jps-plugin.jar;appEngine-runtime.jar"/>
|
||||
|
||||
+90
@@ -0,0 +1,90 @@
|
||||
/*
|
||||
* Copyright 2000-2013 JetBrains s.r.o.
|
||||
*
|
||||
* 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.intellij.appengine.converter;
|
||||
|
||||
import com.intellij.appengine.facet.AppEngineFacetType;
|
||||
import com.intellij.conversion.*;
|
||||
import com.intellij.openapi.util.JDOMUtil;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import org.jdom.Element;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jps.model.serialization.facet.JpsFacetSerializer;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author nik
|
||||
*/
|
||||
public class AppEngineFacetConverterProvider extends ConverterProvider {
|
||||
public AppEngineFacetConverterProvider() {
|
||||
super("google-app-engine-facet");
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public ProjectConverter createConverter(@NotNull ConversionContext context) {
|
||||
return new ProjectConverter() {
|
||||
@Nullable
|
||||
@Override
|
||||
public ConversionProcessor<ModuleSettings> createModuleFileConverter() {
|
||||
return new GoogleAppEngineFacetConversionProcessor();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getConversionDescription() {
|
||||
return "Google App Engine facets will be decoupled from Web facets";
|
||||
}
|
||||
|
||||
private static class GoogleAppEngineFacetConversionProcessor extends ConversionProcessor<ModuleSettings> {
|
||||
|
||||
@Override
|
||||
public boolean isConversionNeeded(ModuleSettings settings) {
|
||||
return !getAppEngineFacetTags(settings).isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void process(ModuleSettings settings) throws CannotConvertException {
|
||||
List<Element> facetTags = getAppEngineFacetTags(settings);
|
||||
for (Element tag : facetTags) {
|
||||
tag.detach();
|
||||
}
|
||||
Element facetTag = ContainerUtil.getFirstItem(facetTags);
|
||||
if (facetTag != null) {
|
||||
String facetName = facetTag.getAttributeValue(JpsFacetSerializer.NAME_ATTRIBUTE);
|
||||
Element configuration = facetTag.getChild(JpsFacetSerializer.CONFIGURATION_TAG);
|
||||
settings.addFacetElement(AppEngineFacetType.STRING_ID, facetName, (Element)configuration.clone());
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static List<Element> getAppEngineFacetTags(@NotNull ModuleSettings settings) {
|
||||
List<Element> appEngineFacetTags = new ArrayList<Element>();
|
||||
for (Element webFacetTag : settings.getFacetElements("web")) {
|
||||
for (Element childFacetTag : JDOMUtil.getChildren(webFacetTag, JpsFacetSerializer.FACET_TAG)) {
|
||||
if (AppEngineFacetType.STRING_ID.equals(childFacetTag.getAttributeValue(JpsFacetSerializer.TYPE_ATTRIBUTE))) {
|
||||
appEngineFacetTags.add(childFacetTag);
|
||||
}
|
||||
}
|
||||
}
|
||||
return appEngineFacetTags;
|
||||
}
|
||||
}
|
||||
}
|
||||
+3
-1
@@ -30,8 +30,10 @@ import javax.swing.*;
|
||||
* @author nik
|
||||
*/
|
||||
public class AppEngineFacetType extends FacetType<AppEngineFacet, AppEngineFacetConfiguration> {
|
||||
public static final String STRING_ID = "google-app-engine";
|
||||
|
||||
public AppEngineFacetType() {
|
||||
super(AppEngineFacet.ID, "google-app-engine", "Google App Engine");
|
||||
super(AppEngineFacet.ID, STRING_ID, "Google App Engine");
|
||||
}
|
||||
|
||||
public AppEngineFacetConfiguration createDefaultConfiguration() {
|
||||
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/appEngineGuestbook.iml" filepath="$PROJECT_DIR$/appEngineGuestbook.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
||||
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="FacetManager">
|
||||
<facet type="web" name="Web">
|
||||
<configuration>
|
||||
<descriptors>
|
||||
<deploymentDescriptor name="web.xml" url="file://$MODULE_DIR$/web/WEB-INF/web.xml" />
|
||||
</descriptors>
|
||||
<webroots>
|
||||
<root url="file://$MODULE_DIR$/web" relative="/" />
|
||||
</webroots>
|
||||
</configuration>
|
||||
</facet>
|
||||
<facet type="google-app-engine" name="Google App Engine">
|
||||
<configuration>
|
||||
<files-to-enhance>
|
||||
<file path="$MODULE_DIR$/src" />
|
||||
</files-to-enhance>
|
||||
<persistence-api>JPA</persistence-api>
|
||||
<run-enhancer-on-make>true</run-enhancer-on-make>
|
||||
<sdk-home-path>$USER_HOME$/applications/appengine-java-sdk-1.7.3</sdk-home-path>
|
||||
</configuration>
|
||||
</facet>
|
||||
</component>
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" name="AppEngine API" level="project" />
|
||||
<orderEntry type="library" name="AppEngine ORM" level="project" />
|
||||
<orderEntry type="library" name="Java EE 6" level="project" />
|
||||
</component>
|
||||
</module>
|
||||
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectModuleManager">
|
||||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/appEngineGuestbook.iml" filepath="$PROJECT_DIR$/appEngineGuestbook.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
||||
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="FacetManager">
|
||||
<facet type="web" name="Web">
|
||||
<configuration>
|
||||
<descriptors>
|
||||
<deploymentDescriptor name="web.xml" url="file://$MODULE_DIR$/web/WEB-INF/web.xml" />
|
||||
</descriptors>
|
||||
<webroots>
|
||||
<root url="file://$MODULE_DIR$/web" relative="/" />
|
||||
</webroots>
|
||||
</configuration>
|
||||
<facet type="google-app-engine" name="Google App Engine">
|
||||
<configuration>
|
||||
<files-to-enhance>
|
||||
<file path="$MODULE_DIR$/src" />
|
||||
</files-to-enhance>
|
||||
<persistence-api>JPA</persistence-api>
|
||||
<run-enhancer-on-make>true</run-enhancer-on-make>
|
||||
<sdk-home-path>$USER_HOME$/applications/appengine-java-sdk-1.7.3</sdk-home-path>
|
||||
</configuration>
|
||||
</facet>
|
||||
</facet>
|
||||
</component>
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
<orderEntry type="library" name="AppEngine API" level="project" />
|
||||
<orderEntry type="library" name="AppEngine ORM" level="project" />
|
||||
<orderEntry type="library" name="Java EE 6" level="project" />
|
||||
</component>
|
||||
</module>
|
||||
|
||||
+51
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Copyright 2000-2013 JetBrains s.r.o.
|
||||
*
|
||||
* 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.intellij.appengine.converter;
|
||||
|
||||
import com.intellij.conversion.ProjectConversionTestUtil;
|
||||
import com.intellij.conversion.impl.ProjectConversionUtil;
|
||||
import com.intellij.openapi.application.ex.PathManagerEx;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.vfs.LocalFileSystem;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.openapi.vfs.VirtualFileFilter;
|
||||
import com.intellij.testFramework.PlatformTestCase;
|
||||
import com.intellij.testFramework.PlatformTestUtil;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* @author nik
|
||||
*/
|
||||
public class AppEngineFacetConverterTest extends PlatformTestCase {
|
||||
public void testConvert() throws IOException {
|
||||
String testDataPath = "plugins/google-app-engine/testData/conversion/appEngineFacet/";
|
||||
File testData = PathManagerEx.findFileUnderProjectHome(testDataPath + "before", getClass());
|
||||
File tempDir = FileUtil.createTempDirectory("app-engine-project", null);
|
||||
FileUtil.copyDir(testData, tempDir);
|
||||
ProjectConversionTestUtil.convert(tempDir.getAbsolutePath());
|
||||
File expectedDataDir = PathManagerEx.findFileUnderProjectHome(testDataPath + "after", getClass());
|
||||
PlatformTestUtil.assertDirectoriesEqual(LocalFileSystem.getInstance().refreshAndFindFileByIoFile(expectedDataDir),
|
||||
LocalFileSystem.getInstance().refreshAndFindFileByIoFile(tempDir),
|
||||
new VirtualFileFilter() {
|
||||
@Override
|
||||
public boolean accept(VirtualFile file) {
|
||||
return !file.getName().startsWith(ProjectConversionUtil.PROJECT_FILES_BACKUP);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user