Skip to content
Open
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
6 changes: 6 additions & 0 deletions distribution-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,12 @@
<file>${project.basedir}/../iidm/iidm-serde/src/main/resources/xsd/iidm_V1_0.xsd</file>
</files>
</copyToEtc>
<copyToPackageRoot>
<files>
<file>${project.basedir}/../LICENSE.txt</file>
<file>${project.basedir}/../THIRD-PARTY.txt</file>
</files>
</copyToPackageRoot>
</configuration>
</plugin>
</plugins>
Expand Down
10 changes: 8 additions & 2 deletions itools-packager/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ This Maven plugin can be used to generate an itools package with the following l
share
java
<jars of the project classpath>
<additional files to be placed at package root>
```

Here is how to configure itools package Maven plugin in your project
Expand Down Expand Up @@ -61,6 +62,11 @@ Here is how to configure itools package Maven plugin in your project
<file>...</file>
</files>
</copyToEtc>
<copyToPackageRoot>
<files>
<file>...</file>
</files>
</copyToPackageRoot>
</configuration>
</plugin>
</plugins>
Expand All @@ -71,5 +77,5 @@ Here is how to configure itools package Maven plugin in your project
- archiveName is optional, packageName is used as default value.
- packageType is optional, "zip" is the default value. It can be either zip or tgz.
- javaXmx, mpiTasks and mpiHosts are used to generate itools.conf, are all optional and default values are respectively 8G, 2 and localhost.
- additional binaries, libraries and configurations file can be added to the package using optional copyToBin, copyToLib and copyToEtc tags.
- all of the jars with compile and runtime scope will be included in the package
- additional binaries, libraries, configurations, package files can be added to the package using optional copyToBin, copyToLib, copyToEtc, copyToPackageRoot tags.
- all the jars with compile and runtime scope will be included in the package
4 changes: 2 additions & 2 deletions itools-packager/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import java.nio.file.attribute.PosixFilePermission;
import java.util.Arrays;
import java.util.EnumSet;
import java.util.List;
import java.util.Set;

/**
Expand Down Expand Up @@ -80,6 +79,9 @@ public void setFiles(File[] files) {
@Parameter
private CopyTo copyToEtc;

@Parameter
private CopyTo copyToPackageRoot;

private void zip(Path dir, Path baseDir, Path zipFilePath) throws IOException {
getLog().info("Zip package");
try (ZipArchiveOutputStream zos = new ZipArchiveOutputStream(Files.newOutputStream(zipFilePath))) {
Expand Down Expand Up @@ -169,32 +171,6 @@ private void writeItoolsConf(BufferedWriter writer) throws IOException {
writer.newLine();
}

private void addLicenseFiles(Path packageDir) {
// List of the license files to copy
List<String> licenseFiles = Arrays.asList("LICENSE.txt", "THIRD-PARTY.txt");

// Get the root directory of the project
File projectRoot = project.getBasedir();
if (project.getParent() != null) {
projectRoot = projectRoot.getParentFile();
}

// Copy each license file to the package directory
for (String licenseFile : licenseFiles) {
Path sourcePath = Paths.get(projectRoot.getPath(), licenseFile);
if (Files.exists(sourcePath)) {
try {
getLog().info("Copy license file " + sourcePath + " to " + packageDir);
Files.copy(sourcePath, packageDir.resolve(licenseFile), StandardCopyOption.REPLACE_EXISTING);
} catch (IOException e) {
getLog().warn("Failed to copy license file " + sourcePath + ": " + e.getMessage());
}
} else {
getLog().warn("License file " + sourcePath + " not found");
}
}
}

@Override
public void execute() {
try {
Expand Down Expand Up @@ -245,8 +221,8 @@ public void execute() {
Files.createDirectories(libDir);
copyFiles(copyToLib, libDir);

// Add licenses
addLicenseFiles(packageDir);
// Add misc files to package root (e.g. license, third party ...)
copyFiles(copyToPackageRoot, packageDir);

String archiveNameNotNull = archiveName != null ? archiveName : packageNameNotNull;
if (packageType.equalsIgnoreCase("zip")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,110 +7,97 @@
*/
package com.powsybl.itools;

import org.apache.commons.io.FileUtils;
import org.apache.maven.execution.DefaultMavenExecutionRequest;
import org.apache.maven.execution.MavenExecutionRequest;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.plugin.MojoExecution;
import org.apache.maven.plugin.testing.AbstractMojoTestCase;
import org.apache.maven.api.plugin.testing.Basedir;
import org.apache.maven.api.plugin.testing.InjectMojo;
import org.apache.maven.api.plugin.testing.MojoParameter;
import org.apache.maven.api.plugin.testing.MojoTest;
import org.apache.maven.model.Build;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.ProjectBuilder;
import org.apache.maven.project.ProjectBuildingRequest;
import org.codehaus.plexus.configuration.DefaultPlexusConfiguration;
import org.codehaus.plexus.configuration.PlexusConfiguration;
import org.eclipse.aether.DefaultRepositorySystemSession;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
import org.mockito.Mockito;

import javax.inject.Inject;
import java.io.File;
import java.nio.file.Path;
import java.util.UUID;

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

/**
* @author Damien Jeandemange {@literal <damien.jeandemange at artelys.com>}
*/
public class ItoolsPackagerMojoTest extends AbstractMojoTestCase {
@MojoTest
class ItoolsPackagerMojoTest {

private static final File BASEDIR = new File("src/test/resources/test-maven-project/");
private static final File POM_XML = new File(BASEDIR, "pom.xml");
private static final File TARGET = new File(BASEDIR, "target");
public static final String DEFAULT_PACKAGE_NAME = "itools-packager-test-project-1.0.0-SNAPSHOT";

ItoolsPackagerMojo mojo;
PlexusConfiguration configuration;

@Override
protected void setUp()
throws Exception {
// required
super.setUp();
MavenProject project = readMavenProject();
MavenSession session = newMavenSession(project);
MojoExecution execution = newMojoExecution("package-zip");
mojo = (ItoolsPackagerMojo) lookupConfiguredMojo(session, execution);
configuration = new DefaultPlexusConfiguration("configuration");
}

@Override
protected void tearDown()
throws Exception {
// required
super.tearDown();
FileUtils.deleteDirectory(TARGET); // cleanup
}
@Inject
MavenProject project;

protected MavenProject readMavenProject() throws Exception {
MavenExecutionRequest request = new DefaultMavenExecutionRequest();
request.setBaseDirectory(BASEDIR);
ProjectBuildingRequest projectBuildingRequest = request.getProjectBuildingRequest();
projectBuildingRequest.setRepositorySession(new DefaultRepositorySystemSession());
MavenProject project = lookup(ProjectBuilder.class).build(POM_XML, projectBuildingRequest).getProject();
assertNotNull(project);
return project;
}
@TempDir
Path tempDir;

protected MavenProject readMavenProject2() throws Exception {
MavenExecutionRequest request = new DefaultMavenExecutionRequest();
File basedir2 = new File("src/test/resources/test-maven-project-2/");
File pomXml2 = new File(basedir2, "pom.xml");
request.setBaseDirectory(basedir2);
ProjectBuildingRequest projectBuildingRequest = request.getProjectBuildingRequest();
projectBuildingRequest.setRepositorySession(new DefaultRepositorySystemSession());
MavenProject project = lookup(ProjectBuilder.class).build(pomXml2, projectBuildingRequest).getProject();
assertNotNull(project);
return project;
@BeforeEach
void setup() {
Build build = new Build();
build.setFinalName(DEFAULT_PACKAGE_NAME);
String target = tempDir.resolve(UUID.randomUUID().toString()).toString();
build.setDirectory(target);
Mockito.when(project.getBuild()).thenReturn(build);
}

public void testDefaultConfiguration() throws Exception {
super.configureMojo(mojo, configuration);
assertNotNull(mojo);
@Test
@Basedir("src/test/resources/test-maven-project/")
@InjectMojo(goal = "package-zip")
void testDefaultConfiguration(ItoolsPackagerMojo mojo) {
mojo.execute();
assertTrue(new File(TARGET, DEFAULT_PACKAGE_NAME + ".zip").exists());
String target = project.getBuild().getDirectory();
assertTrue(new File(target, DEFAULT_PACKAGE_NAME + ".zip").exists());
assertTrue(new File(target, DEFAULT_PACKAGE_NAME + "/LICENSE.txt").exists());
assertTrue(new File(target, DEFAULT_PACKAGE_NAME + "/bin/itools").exists());
assertTrue(new File(target, DEFAULT_PACKAGE_NAME + "/bin/itools.bat").exists());
assertTrue(new File(target, DEFAULT_PACKAGE_NAME + "/bin/powsyblsh").exists());
assertTrue(new File(target, DEFAULT_PACKAGE_NAME + "/etc/itools.conf").exists());
assertTrue(new File(target, DEFAULT_PACKAGE_NAME + "/etc/logback-itools.xml").exists());
assertTrue(new File(target, DEFAULT_PACKAGE_NAME + "/etc/logback-powsyblsh.xml").exists());
assertTrue(new File(target, DEFAULT_PACKAGE_NAME + "/lib").exists());
assertTrue(new File(target, DEFAULT_PACKAGE_NAME + "/lib").isDirectory());
assertTrue(new File(target, DEFAULT_PACKAGE_NAME + "/share/java").exists());
assertTrue(new File(target, DEFAULT_PACKAGE_NAME + "/share/java").isDirectory());
assertTrue(new File(target, DEFAULT_PACKAGE_NAME + "/THIRD-PARTY.txt").exists());
assertTrue(new File(target, DEFAULT_PACKAGE_NAME + "/file.txt").exists());
assertFalse(new File(target, DEFAULT_PACKAGE_NAME + "/not_exists.txt").exists());
}

public void testPackageTypeTgz() throws Exception {
configuration.addChild("packageType", "tgz");
super.configureMojo(mojo, configuration);
assertNotNull(mojo);
@Test
@Basedir("src/test/resources/test-maven-project/")
@InjectMojo(goal = "package-zip")
@MojoParameter(name = "packageType", value = "tgz")
void testTgzConfiguration(ItoolsPackagerMojo mojo) {
mojo.execute();
assertTrue(new File(TARGET, DEFAULT_PACKAGE_NAME + ".tgz").exists());
String target = project.getBuild().getDirectory();
assertTrue(new File(target, DEFAULT_PACKAGE_NAME + ".tgz").exists());
}

public void testLicenseFiles() throws Exception {
super.configureMojo(mojo, configuration);
assertNotNull(mojo);
mojo.execute();
assertTrue(new File(TARGET, DEFAULT_PACKAGE_NAME + "/LICENSE.txt").exists());
assertTrue(new File(TARGET, DEFAULT_PACKAGE_NAME + "/THIRD-PARTY.txt").exists());
@Test
@Basedir("src/test/resources/test-maven-project/")
@InjectMojo(goal = "package-zip")
@MojoParameter(name = "packageType", value = "someUnsupportedValue")
void testUnknownPackageType(ItoolsPackagerMojo mojo) {
IllegalArgumentException e = assertThrows(IllegalArgumentException.class, mojo::execute);
assertEquals("Unknown filetype 'someUnsupportedValue': should be either zip or tgz", e.getMessage());
}

public void testMissingLicenseFile() throws Exception {
MavenProject project = readMavenProject2();
MavenSession session = newMavenSession(project);
MojoExecution execution = newMojoExecution("package-zip");
mojo = (ItoolsPackagerMojo) lookupConfiguredMojo(session, execution);
super.configureMojo(mojo, configuration);
assertNotNull(mojo);
@Test
@Basedir("src/test/resources/test-maven-project/")
@InjectMojo(goal = "package-zip")
@MojoParameter(name = "packageName", value = "myOwnPackageName")
void testPackageNameConfiguration(ItoolsPackagerMojo mojo) {
mojo.execute();
File target2 = new File("src/test/resources/test-maven-project-2/target/");
assertTrue(new File(target2, DEFAULT_PACKAGE_NAME + "/LICENSE.txt").exists());
assertFalse(new File(target2, DEFAULT_PACKAGE_NAME + "/THIRD-PARTY.txt").exists());
FileUtils.deleteDirectory(target2); // cleanup
String target = project.getBuild().getDirectory();
assertTrue(new File(target, "myOwnPackageName" + ".zip").exists());
}

}

This file was deleted.

37 changes: 0 additions & 37 deletions itools-packager/src/test/resources/test-maven-project-2/pom.xml

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
hello itools packager!
10 changes: 10 additions & 0 deletions itools-packager/src/test/resources/test-maven-project/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,16 @@
</goals>
</execution>
</executions>
<configuration>
<copyToPackageRoot>
<files>
<file>${project.basedir}/LICENSE.txt</file>
<file>${project.basedir}/THIRD-PARTY.txt</file>
<file>${project.basedir}/path/to/some/file.txt</file>
<file>${project.basedir}/does/not_exists.txt</file>
</files>
</copyToPackageRoot>
</configuration>
</plugin>
</plugins>
</build>
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@
<maven.compat>3.9.9</maven.compat>
<maven.core.version>3.8.5</maven.core.version>
<maven.plugin.annotations.version>3.15.1</maven.plugin.annotations.version>
<maven.plugin.testing.harness.version>3.3.0</maven.plugin.testing.harness.version>
<maven.plugin.testing.harness.version>3.4.0</maven.plugin.testing.harness.version>
<mfl.version>0.5.15</mfl.version>
<mockito.version>5.18.0</mockito.version>
<nativelibloader.version>2.5.0</nativelibloader.version>
Expand Down