Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,16 @@

public class Be5CachesImpl implements Be5Caches, Configurable<Be5CachesImpl.Config>
{
private Config config = new Config();
private Config config;

class Config
public static class Config
{
Map<String, Integer> cacheSizes = new HashMap<>();

public Config(Map<String, Integer> cacheSizes)
{
this.cacheSizes = cacheSizes;
}
}

private Map<String, Cache> caches = new ConcurrentHashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import java.io.IOException;
import java.io.InputStream;
import java.util.logging.Handler;
import java.util.logging.LogManager;
import java.util.logging.Logger;

Expand Down Expand Up @@ -34,15 +33,7 @@ public LogConfigurator()

String parentLevel = log.getParent().getLevel() != null ? log.getParent().getLevel().getName() : "null";

StringBuilder sb = new StringBuilder();
sb.append("Log root level: ").append(parentLevel);

for (Handler handler : log.getParent().getHandlers())
{
sb.append("\n - ").append(handler.getClass().getName()).append(" ").append(handler.getLevel());
}

log.info(sb.toString());
log.info("Log root level: " + parentLevel);
}

}
2 changes: 1 addition & 1 deletion database-model/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

<dependency>
<groupId>com.developmentontheedge.be5</groupId>
<artifactId>be5-test</artifactId>
<artifactId>be5-test-base</artifactId>
<version>0.0.3-SNAPSHOT</version>
<scope>test</scope>
</dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public abstract class DatabaseModelProjectDbTest extends BaseTestUtils
@Inject protected DatabaseModel database;

private static final Injector injector = initInjector(
Modules.override(new BaseModule()).with(new TestProjectProviderModule())
Modules.override(new BaseModule()).with(new BaseDbTestModule())
);

static {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public abstract class DatabaseModelSqlMockProjectTest extends BaseTestUtils
@Inject protected DatabaseModel database;

private static final Injector injector = initInjector(
Modules.override(new BaseModule()).with(new SqlMockModule())
Modules.override(new BaseModule()).with(new BaseDbMockTestModule())
);

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,70 +1,78 @@
package com.developmentontheedge.be5.maven.gdsl;

import com.developmentontheedge.be5.maven.Be5Mojo;
import com.developmentontheedge.be5.metadata.exception.ProjectLoadException;
import com.developmentontheedge.be5.metadata.model.Entity;
import com.developmentontheedge.be5.metadata.model.Project;
import com.developmentontheedge.be5.metadata.serialization.ModuleLoader2;
import freemarker.template.Configuration;
import freemarker.template.Template;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;

import java.io.File;
import java.io.IOException;
import java.nio.file.Paths;
import java.util.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Logger;


public class GdslGenerator
@Mojo( name = "generate-groovy-dsl")
public class GroovyDSLGenerator extends Be5Mojo<GroovyDSLGenerator>
{
private static final Logger log = Logger.getLogger(GdslGenerator.class.getName());
private static final Logger log = Logger.getLogger(GroovyDSLGenerator.class.getName());

private int entityCount = 0;

public static void main(String[] args) throws IOException
@Parameter(property = "FILE_NAME")
protected String fileName;

@Override
public void execute() throws MojoFailureException
{
String generatedSourcesPath = args[0];
String packageName = args[1];
if(packageName == null){
packageName = "";
}else{
if(!packageName.endsWith("."))packageName += ".";
try
{
generate(fileName.replace(".", "/") + "GroovyDSL");
}
catch (IOException e)
{
throw new RuntimeException(e);
}

String serviceClassName = args[2] + "DatabaseModel";

new GdslGenerator(generatedSourcesPath, packageName, serviceClassName);
}

public GdslGenerator(String generatedSourcesPath, String packageName, String serviceClassName) throws IOException
public void generate(String fileName) throws IOException
{
Configuration cfg = new Configuration();
cfg.setClassForTemplateLoading(GdslGenerator.class, "/gdsl");
cfg.setClassForTemplateLoading(GroovyDSLGenerator.class, "/gdsl");
cfg.setDefaultEncoding("UTF-8");

File file = Paths.get(generatedSourcesPath + packageName.replace(".", "/") + serviceClassName + ".gdsl").toFile();
File file = Paths.get(fileName + ".gdsl").toFile();

if(file.exists() && !file.isDirectory())
{
log.info("Generate skipped, file exists: " + packageName + "." + serviceClassName);
log.info("Generate skipped, file exists: " + fileName);
return;
}

log.info("File '"+file.toString()+"' not found, generate...");

try
{
createService(generatedSourcesPath, packageName, serviceClassName, cfg);
createDSL(fileName, cfg);
}
catch (ProjectLoadException e)
{
e.printStackTrace();
}

log.info("Generate successful: " + entityCount + " entities added.\n" + packageName + serviceClassName);
log.info("Generate successful: " + entityCount + " entities added.\n" + file.getAbsolutePath());
}

private void createService(String generatedSourcesPath, String packageName,
String serviceClassName, Configuration cfg) throws IOException, ProjectLoadException
private void createDSL(String fileName, Configuration cfg) throws IOException, ProjectLoadException
{
Template serviceTpl = cfg.getTemplate("/entities.ftl");

Expand All @@ -84,8 +92,10 @@ private void createService(String generatedSourcesPath, String packageName,
entityNames.add(entity.getName());
}
input.put("entityNames", entityNames);
Utils.createFile(generatedSourcesPath, packageName, serviceClassName+ ".gdsl", serviceTpl, input);
Utils.createFile(fileName + ".gdsl", serviceTpl, input);
}


@Override protected GroovyDSLGenerator me() {
return this;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

### GdslGenegator
### GroovyDSLGenerator
Генерирует GroovyDSL для таблиц в проекте
GroovyDSL - добавляет поддержку мета классов для groovy:
```groovy
Expand All @@ -16,36 +16,27 @@ contribute(context(ctype: "com.developmentontheedge.be5.databasemodel.EntityMode
```

Добавление в проект:
```xml
<dependency>
<groupId>com.developmentontheedge.be5</groupId>
<artifactId>be5-maven-plugin</artifactId>
<version>0.1.1-SNAPSHOT</version>
</dependency>
```
```xml
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.6.0</version>
<executions>
<execution>
<id>GdslGenegator</id>
<goals>
<goal>java</goal>
</goals>
<phase>compile</phase>
<configuration>
<mainClass>com.developmentontheedge.be5.maven.gdsl.GdslGenegator</mainClass>
<arguments>
<argument>${project.build.directory}/generated-sources/java/</argument>
<argument/>
<argument>${project.artifactId}</argument>
</arguments>
</configuration>
</execution>
</executions>
<groupId>com.developmentontheedge.be5</groupId>
<artifactId>be5-maven-plugin</artifactId>
<version>0.1.1-SNAPSHOT</version>
<configuration>
<projectPath>./</projectPath>
</configuration>
<executions>
<execution>
<id>generate-groovy-dsl</id>
<phase>compile</phase>
<goals>
<goal>generate-groovy-dsl</goal>
</goals>
<configuration>
<fileName>${project.build.directory}/generated-sources/java/${project.artifactId}</fileName>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,22 @@

public class Utils
{
public static void createFile(String generatedSourcesPath, String packageName, String fileName,
Template template, Map<String, Object> input)
public static void createFile(String fileName, Template template, Map<String, Object> input)
{
try
{
Paths.get(generatedSourcesPath + packageName.replace(".", "/")).toFile().mkdirs();
Writer fileWriter = new FileWriter(new File(generatedSourcesPath + packageName.replace(".", "/") + "/" + fileName));
Paths.get(fileName.substring(0, fileName.lastIndexOf("/"))).toFile().mkdirs();
Writer fileWriter = new FileWriter(new File(fileName));

try
{
template.process(input, fileWriter);
} catch (TemplateException e)
}
catch (TemplateException e)
{
e.printStackTrace();
} finally
}
finally
{
fileWriter.close();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.developmentontheedge.be5.maven.TestUtils;
import com.google.common.base.Charsets;
import com.google.common.io.Resources;
import org.apache.maven.plugin.MojoFailureException;
import org.junit.Test;

import java.io.IOException;
Expand All @@ -14,15 +15,16 @@
import static org.junit.Assert.assertEquals;


public class GdslGeneratorTest extends TestUtils
public class GroovyDSLGeneratorTest extends TestUtils
{
@Test
public void test() throws IOException
public void test() throws IOException, MojoFailureException
{
GdslGenerator.main(new String[]{tpmProjectPath.toAbsolutePath().toString() + "/",
"", ""});
GroovyDSLGenerator groovyDSLGenerator = new GroovyDSLGenerator();
groovyDSLGenerator.fileName = tpmProjectPath.toAbsolutePath().toString() + "/";
groovyDSLGenerator.execute();

String result = readFile(tpmProjectPath.toAbsolutePath().toString() + "/DatabaseModel.gdsl", Charsets.UTF_8);
String result = readFile(tpmProjectPath.toAbsolutePath().toString() + "/GroovyDSL.gdsl", Charsets.UTF_8);

URL url = Resources.getResource("gdsl/test.txt");
String test = Resources.toString(url, Charsets.UTF_8);
Expand Down
40 changes: 14 additions & 26 deletions modules/core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,31 +31,19 @@
</properties>

<dependencies>
<dependency>
<groupId>com.developmentontheedge.be5</groupId>
<artifactId>be5-server</artifactId>
<version>0.1.2-SNAPSHOT</version>
</dependency>

<dependency>
<groupId>com.developmentontheedge.be5.modules</groupId>
<artifactId>be5-modules-system</artifactId>
<version>0.1.0-SNAPSHOT</version>
</dependency>

<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>1.4.193</version>
<groupId>com.developmentontheedge.be5</groupId>
<artifactId>be5-test</artifactId>
<version>0.0.3-SNAPSHOT</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand All @@ -77,20 +65,20 @@
</resources>

<plugins>
<plugin>
<groupId>org.codehaus.gmavenplus</groupId>
<artifactId>gmavenplus-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<goals>
<plugin>
<groupId>org.codehaus.gmavenplus</groupId>
<artifactId>gmavenplus-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<goals>
<goal>addTestSources</goal>
<goal>compileTests</goal>
<goal>removeTestStubs</goal>
</goals>
</execution>
</executions>
</plugin>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import static org.junit.Assert.assertEquals
import static org.junit.Assert.assertNotNull


class LoadTest extends CoreBe5ProjectTest
class LoadTest extends CoreBe5ProjectDbMockTest
{
@Inject ProjectProvider projectProvider

Expand Down
Loading