Skip to content

Commit

Permalink
Added simple Gradle support (only .war)
Browse files Browse the repository at this point in the history
Added support for edoras one 1.6
Added support for SNAPSHOT versions
Creation of sample component test class
  • Loading branch information
rvillars committed Jun 28, 2017
1 parent 55ad06a commit 2fcf899
Show file tree
Hide file tree
Showing 11 changed files with 96 additions and 54 deletions.
15 changes: 9 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,20 @@ Still in early alpha state.
Using the generated code needs an edoras one license (see http://www.edorasware.com) and access to the appropriate repositories. Don't even try to get it running without.

Already working:
- Maven project stub creation based on edoras-one-starter 2.0.
- Maven project stub creation based on edoras-one-starter 1.6 or 2.0.
- Gradle project stub creation based on edoras-one-starter 1.6 or 2.0.
- Artifact coordinates are evaluated.
- First very unstable draft of addon support.
- Support for different Java versions
- .war and .executable .jar project generation
- Support for different Java versions.
- Maven .war and .executable .jar project generation
- Gradle .war project generation
- Support for additional "Short Name" property (used for config files, tenant, etc.)

Todo:
- Support for Version 1.0
- Support for Gradle Build
- Support for Gradle executable .jar Build
- Support for Groovy / Kotlin
- Metadata from Repository/Addon Marketplace
- IntelliJ integration
- IntelliJ Integration
- Config generation for addons
- Code cleanup
- Fixing a lot of bugs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@
import com.edorasware.one.initializr.InitializrException;
import com.edorasware.one.initializr.metadata.*;
import com.edorasware.one.initializr.metadata.InitializrConfiguration.Env.Maven.ParentPom;
import com.edorasware.one.initializr.util.TemplateRenderer;
import com.edorasware.one.initializr.util.Version;
import com.edorasware.one.initializr.util.VersionProperty;
import com.edorasware.one.initializr.util.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanWrapperImpl;
Expand Down Expand Up @@ -53,10 +51,6 @@ public class ProjectGenerator {

private static final Logger log = LoggerFactory.getLogger(ProjectGenerator.class);

private static final Version VERSION_1_6_5 = Version.parse("1.6.5");

private static final Version VERSION_2_0_0_M5 = Version.parse("2.0.0-M5");

@Autowired
private ApplicationEventPublisher eventPublisher;

Expand Down Expand Up @@ -173,6 +167,7 @@ protected File doGenerateProjectStructure(ProjectRequest request) {
// manually set some properties, seems not to be stable in javascript
request.setBaseDir(request.getArtifactId());
request.setPackageName(request.getGroupId().concat(".").concat(request.getShortName()));
request.setCreateSampleTest(true);

Map<String, Object> model = resolveModel(request);

Expand Down Expand Up @@ -219,7 +214,12 @@ protected File doGenerateProjectStructure(ProjectRequest request) {

if (request.isCreateSampleTest()) {
// setupTestModel(request, model);
write(new File(test, "SampleComponentTest." + language), "SampleComponentTest."+language+".tmpl", model);
if (isEdorasoneVersion10(request)) {
write(new File(test, "SampleComponentTest." + language), "SampleComponentTest16." + language + ".tmpl", model);
}
if (isEdorasoneVersion20(request)) {
write(new File(test, "SampleComponentTest." + language), "SampleComponentTest20." + language + ".tmpl", model);
}
}

// src/main/resources
Expand Down Expand Up @@ -431,6 +431,10 @@ protected Map<String, Object> resolveModel(ProjectRequest originalRequest) {
model.put("isJava7", isJavaVersion(request, "1.7"));
model.put("isJava8", isJavaVersion(request, "1.8"));

// edoras one versions
model.put("isEdorasOne10", isEdorasoneVersion10(request));
model.put("isEdorasOne20", isEdorasoneVersion20(request));

// Append the project request to the model
BeanWrapperImpl bean = new BeanWrapperImpl(request);
for (PropertyDescriptor descriptor : bean.getPropertyDescriptors()) {
Expand Down Expand Up @@ -522,6 +526,16 @@ private static boolean isJavaVersion(ProjectRequest request, String version) {
return request.getJavaVersion().equals(version);
}

private static boolean isEdorasoneVersion20(ProjectRequest request) {
VersionRange edorasone20 = VersionParser.DEFAULT.parseRange("[2.0.0-M0,3.0.0-M0)");
return edorasone20.match(Version.parse(request.getEdorasoneVersion()));
}

private static boolean isEdorasoneVersion10(ProjectRequest request) {
VersionRange edorasone10 = VersionParser.DEFAULT.parseRange("[1.0.0-M0,2.0.0-M0)");
return edorasone10.match(Version.parse(request.getEdorasoneVersion()));
}

private byte[] doGenerateMavenPom(Map<String, Object> model) {
return templateRenderer.process("starter-pom.xml", model).getBytes();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,9 @@ protected void initializeProperties(InitializrMetadata metadata) {
}
else {
buildProperties.getMaven().put("project.build.sourceEncoding", () -> "UTF-8");
buildProperties.getVersions().put(new VersionProperty("java.version"),
buildProperties.getVersions().put(new VersionProperty("maven.compiler.source"),
this::getJavaVersion);
buildProperties.getVersions().put(new VersionProperty("maven.compiler.target"),
this::getJavaVersion);
buildProperties.getVersions().put(new VersionProperty("com.edorasware.one.starter.version"),
this::getEdorasoneVersion);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public class VersionParser {
public static final VersionParser DEFAULT = new VersionParser(Collections.emptyList());

private static final Pattern VERSION_REGEX =
Pattern.compile("^(\\d+)\\.(\\d+|x)\\.(\\d+|x)(?:-([^0-9]+)(\\d+)?)?$");
Pattern.compile("^(\\d+)\\.(\\d+|x)\\.(\\d+|x)(?:-([^0-9]+)(\\d+)?(-SNAPSHOT)?)?$");

private static final Pattern RANGE_REGEX =
Pattern.compile("(\\(|\\[)(.*),(.*)(\\)|\\])");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,17 +82,17 @@ protected List<DefaultMetadataElement> fetchEdorasoneVersions() {

List<DefaultMetadataElement> edorasoneVersions = new ArrayList<>();

DefaultMetadataElement element1 = new DefaultMetadataElement();
element1.setId("1.6.5");
element1.setName("1.6.5");
element1.setDefault(false);
edorasoneVersions.add(element1);

DefaultMetadataElement element2 = new DefaultMetadataElement();
element2.setId("2.0.0-M5");
element2.setName("2.0.0-M5");
element2.setDefault(true);
edorasoneVersions.add(element2);
// DefaultMetadataElement element1 = new DefaultMetadataElement();
// element1.setId("1.6.5");
// element1.setName("1.6.5");
// element1.setDefault(false);
// edorasoneVersions.add(element1);
//
// DefaultMetadataElement element2 = new DefaultMetadataElement();
// element2.setId("2.0.0-M5");
// element2.setName("2.0.0-M5");
// element2.setDefault(true);
// edorasoneVersions.add(element2);

return edorasoneVersions;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public OfflineInitializrMetadataBuilder addDefaultTypes() {
return addType("maven-project", "Maven Project", true, "/starter.zip", "maven", "project")
// .addType("maven-build", "Maven Build", false, "/pom.xml", "maven", "build")
// .addType("gradle-build", "Gradle Build", false, "/build.gradle", "gradle", "build")
// .addType("gradle-project", "Gradle Project", false, "/starter.zip", "gradle", "project")
.addType("gradle-project", "Gradle Project", false, "/starter.zip", "gradle", "project")
;
}

Expand Down Expand Up @@ -185,8 +185,8 @@ public OfflineInitializrMetadataBuilder addLanguage(String id, String name, bool
}

public OfflineInitializrMetadataBuilder addDefaultEdorasoneVersions() {
return addEdorasoneVersion("2.0.0-M5", true)
// .addEdorasoneVersion("1.6.5", false)
return addEdorasoneVersion("2.0.0-M6-SNAPSHOT", true)
.addEdorasoneVersion("1.6.6", false)
;
}

Expand Down
35 changes: 35 additions & 0 deletions src/main/resources/templates/SampleComponentTest16.java.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package {{packageName}};

import com.edorasware.gear.core.task.Task;
import com.edorasware.gear.core.task.TaskId;
import com.edorasware.gear.core.task.TaskService;
import com.edorasware.one.document.viewer.DocumentViewerController;
import com.edorasware.one.micro.testing.AbstractComponentTest;
import com.edorasware.one.micro.testing.annotations.EdorasTestLogin;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;

import static org.junit.Assert.assertEquals;

/**
* Small test that just checks whether the context is successfully started
*/
@EdorasTestLogin(login = "{{shortName}}-admin")
public class SampleComponentTest extends AbstractComponentTest {

// You can inject beans from the root context (edoras one context)
@Autowired
private TaskService taskService;

// You can inject beans from rest service context (edoras one dispatcher servlet context)
@Autowired
private DocumentViewerController documentViewerController;

@Test
public void addCase() {
final String taskName = "taskName";
TaskId taskId = this.taskService.addTask(Task.builder().name(taskName).build(), "Add a task");
Task task = this.taskService.findTaskById(taskId);
assertEquals("The task name must be equal", taskName, task.getName());
}
}
28 changes: 5 additions & 23 deletions src/main/resources/templates/starter-build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,9 @@ buildscript {
}
repositories {
mavenCentral()
{{^isRelease}}
maven { url "https://repo.spring.io/snapshot" }
maven { url "https://repo.spring.io/milestone" }
{{/isRelease}}
mavenLocal()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
{{^bootOneThreeAvailable}}
classpath('io.spring.gradle:dependency-management-plugin:{{dependencyManagementPluginVersion}}')
{{/bootOneThreeAvailable}}
{{#kotlin}}
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:${kotlinVersion}")
classpath("org.jetbrains.kotlin:kotlin-allopen:${kotlinVersion}")
Expand All @@ -28,19 +21,6 @@ apply plugin: '{{language}}'
apply plugin: 'kotlin-spring'
{{/kotlin}}
{{#war}}
apply plugin: 'eclipse-wtp'
{{/war}}
{{^war}}
apply plugin: 'eclipse'
{{/war}}
apply plugin: '{{springBootPluginName}}'
{{^bootOneThreeAvailable}}
apply plugin: 'io.spring.dependency-management'
{{/bootOneThreeAvailable}}
{{#bootTwoZeroAvailable}}
apply plugin: 'io.spring.dependency-management'
{{/bootTwoZeroAvailable}}
{{#war}}
apply plugin: 'war'
{{/war}}

Expand All @@ -55,6 +35,7 @@ compileTestKotlin {

repositories {
mavenCentral()
mavenLocal()
{{#repositoryValues}}
maven { url "{{value.url}}" }
{{/repositoryValues}}
Expand All @@ -75,6 +56,7 @@ ext {

{{/buildPropertiesVersions.empty}}
dependencies {
compile("com.edorasware.one:edoras-one-starter:${edorasoneVersion}")
{{#compileDependencies}}
compile('{{groupId}}:{{artifactId}}{{#version}}:{{version}}{{/version}}{{#type}}@{{type}}{{/type}}')
{{/compileDependencies}}
Expand Down Expand Up @@ -102,9 +84,9 @@ dependencies {
{{#providedDependencies}}
providedRuntime('{{groupId}}:{{artifactId}}{{#version}}:{{version}}{{/version}}{{#type}}@{{type}}{{/type}}')
{{/providedDependencies}}
testCompile('org.springframework.boot:spring-boot-starter-test')
testCompile("com.edorasware.one:edoras-one-starter-test:${edorasoneVersion}")
{{#testDependencies}}
testCompile('{{groupId}}:{{artifactId}}{{#version}}:{{version}}{{/version}}{{#type}}@{{type}}{{/type}}')
testCompile("{{groupId}}:{{artifactId}}{{#version}}:{{version}}{{/version}}{{#type}}@{{type}}{{/type}}")
{{/testDependencies}}
}
{{#hasBoms}}
Expand Down
6 changes: 6 additions & 0 deletions src/main/resources/templates/starter-pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,14 @@
{{^war}}
<exclusions>
<exclusion>
{{#isEdorasOne10}}
<groupId>org.eclipse.jetty.orbit</groupId>
<artifactId>javax.servlet</artifactId>
{{/isEdorasOne10}}
{{#isEdorasOne20}}
<groupId>de.odysseus.juel</groupId>
<artifactId>juel-api</artifactId>
{{/isEdorasOne20}}
</exclusion>
</exclusions>
{{/war}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public InitializrMetadataTestBuilder addLanguage(String id, boolean defaultValue
}

public InitializrMetadataTestBuilder addDefaultEdorasoneVersions() {
return addEdorasoneVersion("1.6.5", false)
return addEdorasoneVersion("1.6.6", false)
.addEdorasoneVersion("2.0.0-M5", true);
}

Expand Down

0 comments on commit 2fcf899

Please sign in to comment.