mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-98157 Generated web xml has wrong version for servlet 3 0
This commit is contained in:
@@ -40,6 +40,7 @@ import com.intellij.openapi.roots.ModuleRootManager;
|
||||
import com.intellij.openapi.roots.ProjectRootManager;
|
||||
import com.intellij.openapi.ui.Messages;
|
||||
import com.intellij.openapi.util.JDOMUtil;
|
||||
import com.intellij.openapi.util.ThrowableComputable;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.util.io.StreamUtil;
|
||||
import com.intellij.openapi.vfs.VfsUtil;
|
||||
@@ -176,7 +177,12 @@ public class SaveProjectAsTemplateAction extends AnAction {
|
||||
@Override
|
||||
public InputStream getContent(final File file) throws IOException {
|
||||
if (virtualFile.getFileType().isBinary() || PROJECT_TEMPLATE_XML.equals(virtualFile.getName())) return STANDARD.getContent(file);
|
||||
String result = getEncodedContent(virtualFile, project, parameters);
|
||||
String result = ApplicationManager.getApplication().runReadAction(new ThrowableComputable<String, IOException>() {
|
||||
@Override
|
||||
public String compute() throws IOException {
|
||||
return getEncodedContent(virtualFile, project, parameters);
|
||||
}
|
||||
});
|
||||
return new ByteArrayInputStream(result.getBytes(TemplateModuleBuilder.UTF_8));
|
||||
}
|
||||
});
|
||||
|
||||
@@ -214,9 +214,9 @@ public class TemplateModuleBuilder extends ModuleBuilder {
|
||||
};
|
||||
ZipUtil.unzip(ProgressManager.getInstance().getProgressIndicator(), dir, zipInputStream, pathConvertor, new ZipUtil.ContentProcessor() {
|
||||
@Override
|
||||
public byte[] processContent(byte[] content, String fileName) throws IOException {
|
||||
FileType fileType = FileTypeManager.getInstance().getFileTypeByExtension(FileUtilRt.getExtension(fileName));
|
||||
return fileType.isBinary() ? content : processTemplates(projectName, new String(content));
|
||||
public byte[] processContent(byte[] content, File file) throws IOException {
|
||||
FileType fileType = FileTypeManager.getInstance().getFileTypeByExtension(FileUtilRt.getExtension(file.getName()));
|
||||
return fileType.isBinary() ? content : processTemplates(projectName, new String(content), file);
|
||||
}
|
||||
});
|
||||
String iml = ContainerUtil.find(dir.list(), new Condition<String>() {
|
||||
@@ -250,7 +250,14 @@ public class TemplateModuleBuilder extends ModuleBuilder {
|
||||
return "/" + value.replace('.', '/') + "/";
|
||||
}
|
||||
|
||||
private byte[] processTemplates(@Nullable String projectName, String s) throws IOException {
|
||||
@SuppressWarnings("UseOfPropertiesAsHashtable")
|
||||
@Nullable
|
||||
private byte[] processTemplates(@Nullable String projectName, String content, File file) throws IOException {
|
||||
for (WizardInputField field : myAdditionalFields) {
|
||||
if (!field.acceptFile(file)) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Properties properties = FileTemplateManager.getInstance().getDefaultProperties();
|
||||
for (WizardInputField field : myAdditionalFields) {
|
||||
properties.putAll(field.getValues());
|
||||
@@ -258,7 +265,7 @@ public class TemplateModuleBuilder extends ModuleBuilder {
|
||||
if (projectName != null) {
|
||||
properties.put(ProjectTemplateParameterFactory.IJ_PROJECT_NAME, projectName);
|
||||
}
|
||||
String merged = FileTemplateUtil.mergeTemplate(properties, s, true);
|
||||
String merged = FileTemplateUtil.mergeTemplate(properties, content, true);
|
||||
return merged.replace("\\$", "$").replace("\\#", "#").getBytes(UTF_8);
|
||||
}
|
||||
|
||||
|
||||
@@ -16,8 +16,10 @@
|
||||
package com.intellij.ide.util.projectWizard;
|
||||
|
||||
import com.intellij.openapi.options.ConfigurationException;
|
||||
import org.jetbrains.annotations.TestOnly;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.io.File;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -69,4 +71,13 @@ public abstract class WizardInputField<T extends JComponent> {
|
||||
public void addToSettings(SettingsStep settingsStep) {
|
||||
settingsStep.addSettingsField(getLabel(), getComponent());
|
||||
}
|
||||
|
||||
public boolean acceptFile(File file) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@TestOnly
|
||||
public void setValue(String value) {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
|
||||
+4
@@ -42,4 +42,8 @@ public abstract class ProjectTemplateFileProcessor {
|
||||
}
|
||||
return content;
|
||||
}
|
||||
|
||||
protected static String wrap(String param) {
|
||||
return "${" + param + "}";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,12 +22,15 @@ import java.util.zip.ZipInputStream;
|
||||
/**
|
||||
* @author Sergey Simonchik
|
||||
*/
|
||||
@SuppressWarnings("IOResourceOpenedButNotSafelyClosed")
|
||||
public class ZipUtil {
|
||||
|
||||
private static final Logger LOG = Logger.getInstance(ZipUtil.class);
|
||||
|
||||
public interface ContentProcessor {
|
||||
byte[] processContent(byte[] content, String fileName) throws IOException;
|
||||
/** Return null to skip the file */
|
||||
@Nullable
|
||||
byte[] processContent(byte[] content, File file) throws IOException;
|
||||
}
|
||||
|
||||
public static void unzipWithProgressSynchronously(
|
||||
@@ -109,17 +112,23 @@ public class ZipUtil {
|
||||
if (progress != null) {
|
||||
progress.setText("Extracting " + relativeExtractPath + " ...");
|
||||
}
|
||||
FileOutputStream fileOutputStream = new FileOutputStream(child);
|
||||
FileOutputStream fileOutputStream = null;
|
||||
try {
|
||||
if (contentProcessor == null) {
|
||||
fileOutputStream = new FileOutputStream(child);
|
||||
FileUtil.copy(stream, fileOutputStream);
|
||||
}
|
||||
else {
|
||||
byte[] content = contentProcessor.processContent(FileUtil.loadBytes(stream), child.getName());
|
||||
fileOutputStream.write(content);
|
||||
byte[] content = contentProcessor.processContent(FileUtil.loadBytes(stream), child);
|
||||
if (content != null) {
|
||||
fileOutputStream = new FileOutputStream(child);
|
||||
fileOutputStream.write(content);
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
fileOutputStream.close();
|
||||
if (fileOutputStream != null) {
|
||||
fileOutputStream.close();
|
||||
}
|
||||
}
|
||||
LOG.info("Extract: " + relativeExtractPath);
|
||||
}
|
||||
|
||||
+2
-2
@@ -51,11 +51,11 @@ public class MavenTemplateFileProcessor extends ProjectTemplateFileProcessor {
|
||||
String text = psiFile.getText();
|
||||
XmlElement element = model.getName().getXmlElement();
|
||||
if (element instanceof XmlTag) {
|
||||
text = ((XmlTag)element).getValue().getTextRange().replace(text, "${" + ProjectTemplateParameterFactory.IJ_PROJECT_NAME + "}");
|
||||
text = ((XmlTag)element).getValue().getTextRange().replace(text, wrap(ProjectTemplateParameterFactory.IJ_PROJECT_NAME));
|
||||
}
|
||||
element = model.getArtifactId().getXmlElement();
|
||||
if (element instanceof XmlTag) {
|
||||
text = ((XmlTag)element).getValue().getTextRange().replace(text, "${" + ProjectTemplateParameterFactory.IJ_PROJECT_NAME + "}");
|
||||
text = ((XmlTag)element).getValue().getTextRange().replace(text, wrap(ProjectTemplateParameterFactory.IJ_PROJECT_NAME));
|
||||
}
|
||||
return text;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user