Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

incubator-kie-issues#1614: Fix UserTasks Codegen issue in windows #3773

Merged
merged 4 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -18,7 +18,6 @@
*/
package org.kie.kogito.codegen.usertask;

import java.io.File;
import java.io.IOException;
import java.io.Reader;
import java.nio.file.Path;
Expand Down Expand Up @@ -167,17 +166,17 @@ public GeneratedFile generateRestEndpiont() {
compilationUnit.findAll(MethodDeclaration.class).stream().filter(MethodDeclaration::isPublic).forEach(context().getDependencyInjectionAnnotator()::withTransactional);
}
String className = compilationUnit.findFirst(ClassOrInterfaceDeclaration.class).get().getNameAsString();
String urlBase = packageName.replaceAll("\\.", File.separator);
return new GeneratedFile(GeneratedFileType.REST, Path.of(urlBase).resolve(className + ".java"), compilationUnit.toString());
Path basePath = UserTaskCodegenHelper.path(packageName);
return new GeneratedFile(GeneratedFileType.REST, basePath.resolve(className + ".java"), compilationUnit.toString());
}

public GeneratedFile generateProducer() {
String packageName = context().getPackageName();
CompilationUnit compilationUnit = producerTemplateGenerator.compilationUnitOrThrow("No producer template found for user tasks");
compilationUnit.setPackageDeclaration(packageName);
String className = compilationUnit.findFirst(ClassOrInterfaceDeclaration.class).get().getNameAsString();
String urlBase = packageName.replaceAll("\\.", File.separator);
return new GeneratedFile(GeneratedFileType.SOURCE, Path.of(urlBase).resolve(className + ".java"), compilationUnit.toString());
Path basePath = UserTaskCodegenHelper.path(packageName);
return new GeneratedFile(GeneratedFileType.SOURCE, basePath.resolve(className + ".java"), compilationUnit.toString());
}

public List<GeneratedFile> generateUserTask() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@

package org.kie.kogito.codegen.usertask;

import java.io.File;
import java.nio.file.Path;
import java.util.Arrays;

import org.jbpm.process.core.Work;
import org.kie.kogito.internal.utils.ConversionUtils;
Expand All @@ -44,7 +44,17 @@ public static String packageName(Work descriptor) {
}

public static Path path(Work descriptor) {
return Path.of(((String) descriptor.getParameter("PackageName")).replaceAll("\\.", File.separator));
return path(packageName(descriptor));
}

public static Path path(String packageName) {
String[] pathFragments = packageName.split("\\.");

if (pathFragments.length == 1) {
return Path.of(pathFragments[0]);
}
String[] children = Arrays.copyOfRange(pathFragments, 1, pathFragments.length);
return Path.of(pathFragments[0], children);
}

public static String fqnClassName(Work descriptor) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
*/
package org.kie.kogito.codegen.usertask;

import java.io.File;
import java.nio.file.Path;
import java.util.List;

Expand Down Expand Up @@ -58,8 +57,9 @@ public GeneratedFile generate() {

ConstructorDeclaration declaration = clazzDeclaration.findFirst(ConstructorDeclaration.class).get();
declaration.setName(configClassName());
Path basePath = UserTaskCodegenHelper.path(packageName);

return new GeneratedFile(GeneratedFileType.SOURCE, Path.of(packageName.replaceAll("\\.", File.separator), configClassName() + ".java"), unit.toString());
return new GeneratedFile(GeneratedFileType.SOURCE, basePath.resolve(configClassName() + ".java"), unit.toString());
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); 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 org.kie.kogito.codegen.usertask;

import org.assertj.core.api.Assertions;
import org.jbpm.process.core.Work;
import org.jbpm.process.core.impl.WorkImpl;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.*;

class UserTaskCodegenHelperTest {
static final String PROCESS_ID = "approvals";
static final String TASK_ID = "taskId";
static final String PACKAGE = "org.kie.kogito.usertask";
static final String PACKAGE_PATH = "org/kie/kogito/usertask";

private Work work;

@BeforeEach
void setUp() {
work = new WorkImpl();
work.setParameter("ProcessId", PROCESS_ID);
work.setParameter(Work.PARAMETER_UNIQUE_TASK_ID, TASK_ID);
work.setParameter("PackageName", PACKAGE);
}

@Test
void testGetWorkProcessId() {
Assertions.assertThat(UserTaskCodegenHelper.processId(work)).isEqualTo("Approvals");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For uniformity I suggest using a static import for assertThat

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you @pibizza

}

@Test
void testGetWorkClassName() {
Assertions.assertThat(UserTaskCodegenHelper.className(work)).isEqualTo("Approvals_TaskId");
}

@Test
void testGetWorkPackagePath() {
Assertions.assertThat(UserTaskCodegenHelper.path(work))
.isNotNull()
.asString()
.isEqualTo(PACKAGE_PATH);

}

@Test
void testGetPath() {
Assertions.assertThat(UserTaskCodegenHelper.path(PACKAGE))
.isNotNull()
.asString()
.isEqualTo(PACKAGE_PATH);

Assertions.assertThat(UserTaskCodegenHelper.path("test"))
.isNotNull()
.asString()
.isEqualTo("test");
}
}
Loading