Skip to content

Commit

Permalink
Merge branch 'release/v1.1.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
yasuflatland-lf committed Nov 12, 2019
2 parents 99ba3ba + 1d9c620 commit 05e69ed
Show file tree
Hide file tree
Showing 182 changed files with 18,405 additions and 104 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ The list of what Damascus automatically generate is as follows
### Required environment
* Liferay 7.0 CE GA4 and Liferay DXP SP3 or higher versions.
* Liferay 7.1 CE GA1 and higher.
* Liferay 7.2 CE GA1 and higher.
* Java 1.8 or above
* gradle 3.0 or above need to be installed
* jpm needs to be installed. (instruction to install is as follows)
Expand All @@ -48,7 +49,7 @@ curl https://raw.githubusercontent.com/yasuflatland-lf/damascus/master/installer
### Getting started
Let's make a Todo app with damascus
1. Create a Liferay workspace with Blade cli or Liferay IDE / Liferay Developer Studio. For more details, please see [this document](https://dev.liferay.com/de/develop/tutorials/-/knowledge_base/7-1/blade-cli).
2. After creating Liferay workspace, navigate to under ```modules``` folder and run ```damascus init Todo -p com.liferay.sb.test -v 7.1```
2. After creating Liferay workspace, navigate to under ```modules``` folder and run ```damascus init -c Todo -p com.liferay.sb.test -v 7.2```
3. Navigate to ```todo``` folder. You'll see ```base.json``` file is created. For detailed configuration, please see [the official documentation](https://yasuflatland-lf.github.io/damascus-doc/). Just for demonstration now, we'll create a scaffolding as it is.
4. Type ```damascus create``` and damascus will create a scaffolding service and portlet according to the base.json file.
5. Start up your Liferay server and in the ```Todo``` folder, type ```blade deploy```. Blade will run properly and service and portlet will be deployed.
Expand Down
20 changes: 10 additions & 10 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ buildscript {
}

plugins {
id 'io.franzbecker.gradle-lombok' version '1.14'
id 'io.franzbecker.gradle-lombok' version '3.2.0'
id 'java'
id 'groovy'
id 'eclipse'
Expand All @@ -21,7 +21,7 @@ plugins {
apply plugin: 'com.github.kt3k.coveralls'

lombok { // optional: values below are the defaults
version = "1.18.6"
version = "1.18.10"
sha256 = ""
}

Expand Down Expand Up @@ -58,7 +58,7 @@ jar {
manifest {
attributes(
"Bundle-SymbolicName": "com.liferay.damascus.cli",
"Bundle-Version": "1.0.23",
"Bundle-Version": "1.1.0",
"Bundle-Description": "Liferay extension tool for scaffolding service builder portlet",
"Main-Class": "com.liferay.damascus.cli.Damascus",
"JPM-Command": "damascus"
Expand All @@ -71,24 +71,24 @@ jar {

dependencies {
compile 'com.beust:jcommander:1.72'
compile 'com.google.guava:guava:27.0.1-jre'
compile 'com.google.guava:guava:28.1-jre'
compile 'commons-io:commons-io:2.6'
compile 'org.apache.commons:commons-lang3:3.7'
compile 'org.apache.commons:commons-configuration2:2.1.+'
compile 'commons-beanutils:commons-beanutils:1.9.3'
compile 'org.apache.commons:commons-configuration2:2.6'
compile 'commons-beanutils:commons-beanutils:1.9.+'
compile 'com.jayway.jsonpath:json-path:2.4.+'

compile 'org.freemarker:freemarker:2.3.28'
compile 'com.liferay:com.liferay.project.templates:latest.integration'
compile 'com.liferay:com.liferay.project.templates:5.0.2'
compile 'org.slf4j:slf4j-api:1.7.25'
compile 'org.slf4j:slf4j-log4j12:1.7.25'
compile 'com.fasterxml.jackson.core:jackson-core:2.9.+'
compile 'com.fasterxml.jackson.core:jackson-databind:2.9.+'
compile 'com.fasterxml.jackson.core:jackson-annotations:2.9.+'
compile 'com.fasterxml.jackson.datatype:jackson-datatype-joda:2.9.+'
compile 'joda-time:joda-time:2.9.+'
compile 'org.gradle:gradle-tooling-api:4.0.+'
compile 'org.codehaus.groovy:groovy-all:2.4.16'
compile 'org.gradle:gradle-tooling-api:4.3'
compile 'org.codehaus.groovy:groovy-all:2.5.8'

compile group: 'org.antlr', name: 'antlr4', version: '4.7.2'
compile group: 'org.antlr', name: 'antlr4-runtime', version: '4.7.2'
Expand All @@ -110,7 +110,7 @@ dependencies {
testCompile group: 'org.powermock', name: 'powermock-module-junit4-rule', version:'1.6.6'
testCompile group: 'org.powermock', name: 'powermock-api-mockito', version: '1.6.6'
testCompile group: 'org.powermock', name: 'powermock-api-mockito-common', version: '1.6.6'
testCompile('org.spockframework:spock-core:1.2-groovy-2.4') {
testCompile('org.spockframework:spock-core:1.3-groovy-2.5') {
exclude module: 'groovy-all'
}
}
Expand Down
Binary file modified latest/damascus.jar
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ static public DamascusBase addReplacementToDamascusBase(File baseJsonPath) throw
* @param application Application object
* @return
*/
static private Map<String, String> initializeReplacement(DamascusBase dmsb, Application application) {
Map<String, String> replacement = new LinkedHashMap<>();
static private LinkedHashMap<String, String> initializeReplacement(DamascusBase dmsb, Application application) {
LinkedHashMap<String, String> replacement = new LinkedHashMap<>();

// The order of replacements below is important.
// When you add default replacements,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
Expand Down Expand Up @@ -72,18 +73,18 @@ public void process()
}

// Scan the template file and fetch contents to replace
String templateName = sourceTemplateContext.getRootAttribute(DamascusProps.ATTR_TEMPLATE_NAME);
File templateFullPath = new File(templateDirPath + templateName);
String templateName = sourceTemplateContext.getRootAttribute(DamascusProps.ATTR_TEMPLATE_NAME);
File templateFullPath = new File(templateDirPath + templateName);

TemplateContext targetTemplateContext = null;
if (templateFullPath.exists()) {

targetTemplateContext
= TemplateScanner
.builder()
.contentsFile(templateFullPath)
.build()
.getTargetTemplateContext();
.builder()
.contentsFile(templateFullPath)
.build()
.getTargetTemplateContext();
}

// Rescan the source file and replace contents if the template file has already exist.
Expand All @@ -95,6 +96,16 @@ public void process()
.build()
.process();

// If insertPathTag is defined, replace the tag to the target full path.
if(null != insertPathTag) {
LinkedHashMap<String, String> pathReplacement = new LinkedHashMap<>();
pathReplacement.put(insertPathTag, target.getAbsolutePath());
processedContents =
CommonUtil.replaceKeywords(
processedContents,
pathReplacement);
}

// Replace keywords
processedContents =
CommonUtil.replaceKeywords(
Expand Down Expand Up @@ -176,7 +187,7 @@ private boolean validateSourceContext(TemplateContext sourceTemplateContext, Fil
* Replacement keywords map from base.json
*/
@Builder.Default
private Map<String, String> replacements = new ConcurrentHashMap<>();
private Map<String, String> replacements = new LinkedHashMap<>();

/**
* Pick up flag
Expand All @@ -186,4 +197,13 @@ private boolean validateSourceContext(TemplateContext sourceTemplateContext, Fil
*/
@Builder.Default
private boolean pickup = false;

/**
* Target path replacement TAG definition
* <p>
* For the initial template generation, creating the target path for all templates is tedious. This option defines the tag to be replaced to the target path (the original source's full path)
* OPTIONAL
*/
@Builder.Default
private String insertPathTag = null;
}
4 changes: 2 additions & 2 deletions src/main/java/com/liferay/damascus/cli/BaseArgs.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public boolean isHelp() {
@Parameter(description = "Get help on a specific command.", help = true, names = "--help")
private boolean _help;

@Parameter(names = "-v", description = "Target Liferay Version. (e.g. 7.1)", validateWith = VersionValidator.class)
private String liferayVersion = DamascusProps.VERSION_71;
@Parameter(names = "-v", description = "Target Liferay Version. (e.g. 7.2)", validateWith = VersionValidator.class)
private String liferayVersion = DamascusProps.VERSION_72;

}
5 changes: 3 additions & 2 deletions src/main/java/com/liferay/damascus/cli/Damascus.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.beust.jcommander.Parameters;
import lombok.extern.slf4j.Slf4j;

import java.time.LocalDateTime;
import java.util.*;

/**
Expand All @@ -18,7 +19,7 @@
@Slf4j
public class Damascus {

public final static String VERSION = "1.0.23"; //"20190708" + "_" + LocalDateTime.now().toString();
public final static String VERSION = "1.1.0";// + "_" + LocalDateTime.now().toString();

/**
* Main
Expand All @@ -30,7 +31,7 @@ public static void main(String[] args) {
try {
damascus.run(args);
} catch (Exception e) {
System.err.println("Unexpected error occured.");
System.err.println("Unexpected error occurred.");
e.printStackTrace();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.liferay.damascus.cli.common.DamascusProps;
import com.liferay.project.templates.ProjectTemplates;
import com.liferay.project.templates.ProjectTemplatesArgs;
import com.liferay.project.templates.extensions.ProjectTemplatesArgs;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
Expand All @@ -22,18 +22,14 @@
@Builder
public class ProjectTemplatesBuilder {
private String className;
private String contributorType;
private File destinationDir;
private boolean force;
@Builder.Default private boolean gradle = true;
private boolean help;
private String hostBundleSymbolicName;
private String hostBundleVersion;
private boolean list;
@Builder.Default private boolean maven = false;
private String name;
private String packageName;
private String service;
@Builder.Default private String template = DamascusProps.MVC_PORTLET_CMD;
@NonNull
private String liferayVersion;
Expand All @@ -47,13 +43,9 @@ public void create() throws Exception {
ProjectTemplatesArgs projectTemplatesArgs = new ProjectTemplatesArgs();

projectTemplatesArgs.setClassName(getClassName());
projectTemplatesArgs.setContributorType(getContributorType());
projectTemplatesArgs.setDestinationDir(getDestinationDir());
projectTemplatesArgs.setHostBundleSymbolicName(getHostBundleSymbolicName());
projectTemplatesArgs.setHostBundleVersion(getHostBundleVersion());
projectTemplatesArgs.setName(getName());
projectTemplatesArgs.setPackageName(getPackageName());
projectTemplatesArgs.setService(getService());
projectTemplatesArgs.setTemplate(getTemplate());
projectTemplatesArgs.setLiferayVersion(getLiferayVersion());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,18 @@ public void setSourceRootPath(String sourceRootPath) {
this.sourceRootPath = sourceRootPath;
}

public String getInsertPathTag() {
return insertPathTag;
}

public void setInsertPathTag(String insertPathTag) {
this.insertPathTag = insertPathTag;
}

@Parameter(names = "-model", description = "Model to convert. -model (target model name, \"SampleSB\" e.g.) ", validateWith = ProjectNameValidator.class)
private String model = "";

@Parameter(names = "-pickup", description = "Only processing pickup flag is on. Default is false.")
@Parameter(names = "-pickup", description = "Remove pick up flags from dmsc tags at template generation if this is true. Default is false.")
private boolean pickup = false;

/**
Expand All @@ -77,4 +85,12 @@ public void setSourceRootPath(String sourceRootPath) {
@Parameter(names = "-sourcerootdir", description = "The base directory where base.json exists. The default directory will be used if this value is not configured. Default is current directory.")
private String sourceRootPath = DamascusProps.CURRENT_DIR;

/**
* Target path replacement TAG definition
* <p>
* For the initial template generation, creating the target path for all templates is tedious. This option defines the tag to be replaced to the target path (the original source's full path)
* OPTIONAL
*/
@Parameter(names = "-insertpathtag", description = "Template target path tag for initial template generation. Define the tag name here that you want to replace to the Template target path in your templates.")
private String insertPathTag = null;
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

import java.io.File;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
Expand Down Expand Up @@ -70,7 +71,7 @@ public void execute() throws Exception {
PropertyContext propertyContext = PropertyContextFactory.createPropertyContext();
String checkPattern = propertyContext.getString(DamascusProps.PROP_EXT_WHITE_LIST);
List<String> extensionPatterns = getWhiteExtentionPatterns(checkPattern);
Map<String, String> replacementPattern = getReplacementPatternByModel(dmsb, args.getModel());
LinkedHashMap<String, String> replacementPattern = getReplacementPatternByModel(dmsb, args.getModel());

if (replacementPattern.isEmpty()) {
System.out.println("Model name has not been found. Model name <" + args.getModel() + ">");
Expand All @@ -83,14 +84,17 @@ public void execute() throws Exception {
processedSourceRootPath
)
.templateDirPath(
processedTemplateDir + args.getLiferayVersion()
processedTemplateDir
)
.replacements(
replacementPattern
)
.extentionPatterns(
extensionPatterns
)
.insertPathTag (
args.getInsertPathTag()
)
.build()
.process();

Expand Down Expand Up @@ -135,7 +139,7 @@ protected List<String> getWhiteExtentionPatterns(String extPattern) {
* @param modelName
* @return
*/
protected Map<String, String> getReplacementPatternByModel(DamascusBase dmsb, String modelName) {
protected LinkedHashMap<String, String> getReplacementPatternByModel(DamascusBase dmsb, String modelName) {

List<Application> applications = dmsb.getApplications();
for (Application application : applications) {
Expand All @@ -145,7 +149,7 @@ protected Map<String, String> getReplacementPatternByModel(DamascusBase dmsb, St
}
}

return new ConcurrentHashMap<>();
return new LinkedHashMap<>();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,16 @@ static public void runGradle(String projectPath, String task) throws IOException
.newConnector()
.forProjectDirectory(filePath)
.connect();
connection.newBuild().forTasks(task).run();
connection
.newBuild()
.forTasks(task)
.setStandardOutput(System.out)
.run();
} finally {
if (null != connection) {
connection.close();
} else {
System.out.println("Fail to run task <" + task + ">");
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,14 @@ public class DamascusProps {

public static final String PROPERTY_FILE_PATH = CACHE_DIR_PATH + DS + PROPERTY_FILE_NAME;

public static final String TEMPLATE_FILE_PATH = CACHE_DIR_PATH + DS + TEMPLATE_FOLDER_NAME;
public static final String TEMPLATE_FILE_PATH = CACHE_DIR_PATH + DS + TEMPLATE_FOLDER_NAME;

/**
* Liferay Version
*/
public static final String VERSION_70 = "7.0";
public static final String VERSION_71 = "7.1";
public static final String VERSION_72 = "7.2";

/**
* Service Builder command
Expand Down Expand Up @@ -166,7 +167,7 @@ public class DamascusProps {
/**
* Attribute keys for dmsc tags (dmsc:root, dmsc:sync)
*/
static public final String ATTR_ID = "id";
static public final String ATTR_TEMPLATE_NAME = "templateName";
static public final String ATTR_PICKUP = "pickup";
public static final String ATTR_ID = "id";
public static final String ATTR_TEMPLATE_NAME = "templateName";
public static final String ATTR_PICKUP = "pickup";
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ObjectWriter;
import com.fasterxml.jackson.datatype.joda.JodaModule;
import com.liferay.project.templates.internal.util.Validator;
import com.liferay.project.templates.extensions.util.Validator;
import org.apache.commons.io.FileUtils;

import java.io.File;
Expand Down
Loading

0 comments on commit 05e69ed

Please sign in to comment.