SaveProjectAsTemplateAction: handling packages

This commit is contained in:
Dmitry Avdeev
2013-02-07 14:30:37 +04:00
parent 3beb0e1d95
commit 5b335d6033
4 changed files with 24 additions and 15 deletions
@@ -171,11 +171,10 @@ public class TemplateModuleBuilder extends ModuleBuilder {
}
}
private String getBasePackage() {
List<WizardInputField> fields = getAdditionalFields();
for (WizardInputField field : fields) {
private WizardInputField getBasePackageField() {
for (WizardInputField field : getAdditionalFields()) {
if (WizardInputField.IJ_BASE_PACKAGE.equals(field.getId())) {
return field.getValue();
return field;
}
}
return null;
@@ -184,18 +183,18 @@ public class TemplateModuleBuilder extends ModuleBuilder {
private void unzip(String path, final boolean moduleMode) {
File dir = new File(path);
ZipInputStream zipInputStream = null;
final String basePackage = getBasePackage();
final WizardInputField basePackage = getBasePackageField();
try {
zipInputStream = myTemplate.getStream();
NullableFunction<String, String> pathConvertor = new NullableFunction<String, String>() {
@Nullable
@Override
public String fun(String s) {
if (moduleMode && s.contains(".idea")) return null;
if (basePackage != null && s.startsWith(SRC)) {
return SRC + basePackage.replace('.', '/') + s.substring(SRC.length() - 1);
public String fun(String path) {
if (moduleMode && path.contains(".idea")) return null;
if (basePackage != null) {
return path.replace(getPathFragment(basePackage.getDefaultValue()), getPathFragment(basePackage.getValue()));
}
return s;
return path;
}
};
ZipUtil.unzip(ProgressManager.getInstance().getProgressIndicator(), dir, zipInputStream, pathConvertor, new ZipUtil.ContentProcessor() {
@@ -232,6 +231,10 @@ public class TemplateModuleBuilder extends ModuleBuilder {
}
}
private static String getPathFragment(String value) {
return "/" + value.replace('.', '/') + "/";
}
private byte[] processTemplates(String s) throws IOException {
Properties properties = FileTemplateManager.getInstance().getDefaultProperties();
for (WizardInputField field : myAdditionalFields) {
@@ -52,11 +52,11 @@ public class BasePackageParameterFactory extends ProjectTemplateParameterFactory
}
@Override
public WizardInputField createField(final String initialValue) {
public WizardInputField createField(final String defaultValue) {
return new WizardInputField<JTextField>(WizardInputField.IJ_BASE_PACKAGE) {
return new WizardInputField<JTextField>(WizardInputField.IJ_BASE_PACKAGE, defaultValue) {
private final JTextField myField = new JTextField(initialValue);
private final JTextField myField = new JTextField(defaultValue);
@Override
public String getLabel() {
@@ -30,7 +30,7 @@ public abstract class ProjectTemplateParameterFactory {
public abstract String getParameterId();
@Nullable
public abstract WizardInputField createField(String initialValue);
public abstract WizardInputField createField(String defaultValue);
@Nullable
public abstract String detectParameterValue(Project project);
@@ -30,15 +30,21 @@ public abstract class WizardInputField<T extends JComponent> {
public static final String IJ_BASE_PACKAGE = "IJ_BASE_PACKAGE";
private final String myId;
private final String myDefaultValue;
protected WizardInputField(String id) {
protected WizardInputField(String id, String defaultValue) {
myId = id;
myDefaultValue = defaultValue;
}
public String getId() {
return myId;
}
public String getDefaultValue() {
return myDefaultValue;
}
public abstract String getLabel();
public abstract T getComponent();