Skip to content

Commit

Permalink
feat(element-template): create the element-template unique generator (#…
Browse files Browse the repository at this point in the history
…3008)

* feat(element-template): create the element-template unique generator

* feat(element-template): create the element-template unique generator 2

* feat(element-template): create the element-template unique generator 3

* feat(element-template): create the element-template unique generator 4

* feat(uniquet): change file formatting

* feat(uniquet): add AssertFalse to the test function

* feat(uniquet): there is no need to keep the hybrid ET as they are not part of the web modeler

* Update element-template-generator/uniquet/README.md

Co-authored-by: Pavel Kotelevsky <[email protected]>

* refactor(uniquet): created a subpackage to prevent conflicts

---------

Co-authored-by: Pavel Kotelevsky <[email protected]>
  • Loading branch information
mathias-vandaele and chillleader authored Aug 12, 2024
1 parent dcf5754 commit 627c6d0
Show file tree
Hide file tree
Showing 14 changed files with 618 additions and 0 deletions.
37 changes: 37 additions & 0 deletions element-template-generator/uniquet/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Uniquet

`uniquet` goes through a github repository checking for all different versions of all elements-template and provides a single file containing references to all versions

## Installation

Currently, the only way to install `uniquet` is to build it from source.

### Local build

To build `uniquet` locally, check out the repository and build the project with Maven:

```shell
mvn install -pl element-template-generator/uniquet -am
```

This will build the `uniquet` module and all its dependencies.

Navigate to the `element-template-generator/uniquet/target/appassembler` directory.
The executable `uniquet` script is located in the `bin` directory. The compiled Java code required for
running `uniquet` is located in the `repo` directory. Make sure to copy both directories to your application installation directory.

Executables for Windows and Unix systems are provided (`.bat` and Shell scripts, respectively).

## Usage

`uniquet` has to be run at root of a git repository, It will crawl through every files inside `element-templates` directories for every commit and compile latest version of each of them in a single file

### Examples

`--branch` or `-b` is the branch one wants to start from. not required, default `main`
`--destination` or `-d` is the location where the file will be generated.
`--git-repository` or `-g` is the location of the git repository.

```shell
uniquet --destination ~/Desktop/singlefile.json --branch main
```
104 changes: 104 additions & 0 deletions element-template-generator/uniquet/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>io.camunda.connector</groupId>
<artifactId>connector-parent</artifactId>
<relativePath>../../parent/pom.xml</relativePath>
<version>8.6.0-SNAPSHOT</version>
</parent>

<name>Uniquet</name>
<description>Generate a single ET file</description>
<artifactId>uniquet</artifactId>
<packaging>jar</packaging>

<properties>
<maven.compiler.source>21</maven.compiler.source>
<maven.compiler.target>21</maven.compiler.target>
<version.picocli>4.7.6</version.picocli>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
<dependency>
<groupId>info.picocli</groupId>
<artifactId>picocli</artifactId>
<version>${version.picocli}</version>
</dependency>

<dependency>
<groupId>io.camunda.connector</groupId>
<artifactId>jackson-datatype-feel</artifactId>
</dependency>

<dependency>
<groupId>org.eclipse.jgit</groupId>
<artifactId>org.eclipse.jgit</artifactId>
<version>6.10.0.202406032230-r</version>
</dependency>

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-nop</artifactId>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<scope>test</scope>
</dependency>

</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<!-- annotationProcessorPaths requires maven-compiler-plugin version 3.5 or higher -->
<configuration>
<annotationProcessorPaths>
<path>
<groupId>info.picocli</groupId>
<artifactId>picocli-codegen</artifactId>
<version>4.7.6</version>
</path>
</annotationProcessorPaths>
<compilerArgs>
<arg>-Aproject=${project.groupId}/${project.artifactId}</arg>
</compilerArgs>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>appassembler-maven-plugin</artifactId>
<version>2.1.0</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>assemble</goal>
</goals>
</execution>
</executions>
<configuration>
<programs>
<program>
<mainClass>io.camunda.connector.uniquet.Main</mainClass>
<id>uniquet</id>
</program>
</programs>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH
* under one or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information regarding copyright
* ownership. Camunda licenses this file to you under the Apache License,
* Version 2.0; you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.camunda.connector.uniquet;

import io.camunda.connector.uniquet.command.UniquetCommand;
import picocli.CommandLine;

public class Main {
public static void main(String[] args) {
int exitCode =
new CommandLine(new UniquetCommand())
.setUnmatchedOptionsArePositionalParams(true)
.execute(args);
System.exit(exitCode);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH
* under one or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information regarding copyright
* ownership. Camunda licenses this file to you under the Apache License,
* Version 2.0; you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.camunda.connector.uniquet.command;

import io.camunda.connector.uniquet.core.GitCrawler;
import java.util.concurrent.Callable;
import picocli.CommandLine;

public class UniquetCommand implements Callable<Integer> {

@CommandLine.Option(
names = {"-b", "--branch"},
defaultValue = "main")
private String branch;

@CommandLine.Option(
names = {"-d", "--destination"},
required = true)
private String pathDestination;

@CommandLine.Option(
names = {"-g", "--git-directory"},
defaultValue = "")
private String gitDirectory;

@Override
public Integer call() {
try {
GitCrawler gitCrawler = GitCrawler.create(gitDirectory);
gitCrawler.crawl(branch).persist(pathDestination).close();
} catch (RuntimeException e) {
System.err.println(e.getMessage());
return 1;
}
return 0;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
/*
* Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH
* under one or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information regarding copyright
* ownership. Camunda licenses this file to you under the Apache License,
* Version 2.0; you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.camunda.connector.uniquet.core;

import com.fasterxml.jackson.databind.ObjectMapper;
import io.camunda.connector.uniquet.dto.ElementTemplate;
import io.camunda.connector.uniquet.dto.ElementTemplateFile;
import java.io.IOException;
import java.util.Iterator;
import java.util.Objects;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.ObjectLoader;
import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.treewalk.TreeWalk;
import org.eclipse.jgit.treewalk.filter.PathFilter;

public class ElementTemplateIterator implements Iterator<ElementTemplateFile> {

private final RevCommit commit;
private final ObjectMapper objectMapper;
private final Repository repository;
private final TreeWalk initialWalk;
private ElementTemplateFile elementTemplate;
private TreeWalk currentWalk;
private String currentFolderBeingAnalyzed;

public ElementTemplateIterator(Repository repository, RevCommit commit) {
this.commit = commit;
this.repository = repository;
this.objectMapper = new ObjectMapper();
try {
TreeWalk treeWalk = new TreeWalk(repository);
treeWalk.addTree(this.commit.getTree());
treeWalk.setRecursive(false);
treeWalk.setFilter(PathFilter.create("connectors"));
this.initialWalk = treeWalk;
this.initialWalk.next();
} catch (IOException e) {
throw new RuntimeException(e);
}
this.elementTemplate = this.prepareNext();
}

@Override
public boolean hasNext() {
return this.elementTemplate != null;
}

@Override
public ElementTemplateFile next() {
ElementTemplateFile elementTemplate = this.elementTemplate;
this.elementTemplate = this.prepareNext();
return elementTemplate;
}

private ElementTemplateFile prepareNext() {
try {
do {
if (this.initialWalk.isSubtree()
&& !this.initialWalk.getPathString().endsWith("element-templates")) {
this.initialWalk.enterSubtree();
} else if (this.initialWalk.getPathString().endsWith("element-templates")) {
if (!Objects.equals(this.currentFolderBeingAnalyzed, this.initialWalk.getPathString())) {
this.currentFolderBeingAnalyzed = this.initialWalk.getPathString();
this.currentWalk = new TreeWalk(repository);
this.currentWalk.addTree(this.commit.getTree());
this.currentWalk.setRecursive(true);
this.currentWalk.setFilter(PathFilter.create(this.currentFolderBeingAnalyzed));
}
while (this.currentWalk.next()) {
if (!this.currentWalk.getPathString().endsWith(".json")) continue;
if (this.currentWalk.getPathString().contains("/hybrid/")) continue;
ObjectId objectId = this.currentWalk.getObjectId(0);
ObjectLoader loader = this.repository.open(objectId);
byte[] bytes = loader.getBytes();
try {
return new ElementTemplateFile(
objectMapper.readValue(bytes, ElementTemplate.class),
this.currentWalk.getPathString());
} catch (IOException e) {
System.err.println(
"Error while reading element-template: "
+ this.currentWalk.getPathString()
+ ". Commit is: "
+ commit.getName());
}
}
}
} while (this.initialWalk.next());
} catch (Exception e) {
throw new RuntimeException(e);
}
return null;
}
}
Loading

0 comments on commit 627c6d0

Please sign in to comment.