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

Add windows ci build pipeline #472

Closed
wants to merge 5 commits into from
Closed
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
50 changes: 50 additions & 0 deletions build/windows/Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
pipeline {
agent {
label 'windows'
}

tools {
jdk 'temurin-jdk-21.0.3.9'
maven '3.9'
}

options {
buildDiscarder(logRotator(numToKeepStr: '30', artifactNumToKeepStr: '10'))
}

triggers {
cron '@midnight'
}

parameters {
string(name: 'engineListUrl',
description: 'Engine to use for build',
defaultValue: 'https://product.ivyteam.io')
}

stages {
stage('build') {
steps {
script {
maven cmd: "clean verify " +
"-Divy.engine.list.url=${params.engineListUrl} " +
"-Dmaven.test.failure.ignore=true"
}
collectBuildArtifacts()
}
}
}
}

def collectBuildArtifacts() {
archiveArtifacts 'target/*.jar'
archiveArtifacts 'target/its/**/build.log'
junit testDataPublishers: [[$class: 'AttachmentPublisher'], [$class: 'StabilityTestDataPublisher']], testResults: '**/target/surefire-reports/**/*.xml'
recordIssues tools: [mavenConsole()], qualityGates: [[threshold: 1, type: 'TOTAL']], filters: [
excludeType('site-maven-plugin:site'),
excludeType('maven-surefire-plugin:test'),
// printed to console by test. was since ever the case but they are now real maven warnings
excludeMessage('.*Uncaught exception in thread Thread.*'),
]
recordIssues tools: [java()], qualityGates: [[threshold: 1, type: 'TOTAL']]
}
9 changes: 4 additions & 5 deletions src/main/java/ch/ivyteam/ivy/maven/InstallEngineMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.SystemUtils;
import org.apache.maven.artifact.versioning.ArtifactVersion;
Expand All @@ -42,6 +41,7 @@
import ch.ivyteam.ivy.maven.engine.download.EngineDownloader;
import ch.ivyteam.ivy.maven.engine.download.MavenEngineDownloader;
import ch.ivyteam.ivy.maven.engine.download.URLEngineDownloader;
import ch.ivyteam.ivy.maven.util.PathUtils;
import net.lingala.zip4j.ZipFile;

/**
Expand Down Expand Up @@ -263,11 +263,10 @@ private void removeOldEngineContent() throws MojoExecutionException {
var dir = getRawEngineDirectory();
try {
if (dir != null) {
FileUtils.cleanDirectory(dir.toFile());
PathUtils.clean(dir);
}
} catch (IOException ex) {
throw new MojoExecutionException(
"Failed to clean outdated ivy Engine directory '" + dir + "'.", ex);
} catch (Exception ex) {
throw new MojoExecutionException("Failed to clean outdated ivy Engine directory '" + dir + "'.", ex);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,23 @@

package ch.ivyteam.ivy.maven;

import java.io.IOException;

import org.apache.commons.io.FileUtils;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.project.MavenProject;

import ch.ivyteam.ivy.maven.util.PathUtils;

/**
* Delete copied maven dependencies in the lib/mvn-deps folder.
*
*
* @since 9.2.0
*/
@Mojo(name = MavenDependencyCleanupMojo.GOAL)
public class MavenDependencyCleanupMojo extends AbstractMojo {

public static final String GOAL = "maven-dependency-cleanup";

@Parameter(property = "project", required = true, readonly = true)
Expand All @@ -51,12 +51,11 @@ public void execute() throws MojoExecutionException, MojoFailureException {
return;
}
var mvnLibDir = project.getBasedir().toPath().resolve("lib").resolve("mvn-deps");
getLog().info("Deleting " + mvnLibDir.toString());
getLog().info("Deleting " + mvnLibDir);
try {
FileUtils.deleteDirectory(mvnLibDir.toFile());
} catch (IOException ex) {
getLog().warn("Couldn't delete: " + mvnLibDir.toString(), ex);
PathUtils.delete(mvnLibDir);
} catch (Exception ex) {
getLog().warn("Couldn't delete: " + mvnLibDir, ex);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,8 @@ public class ShareEngineCoreClasspathMojo extends AbstractEngineMojo {

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
List<File> ivyEngineClassPathFiles = EngineClassLoaderFactory
.getIvyEngineClassPathFiles(identifyAndGetEngineDirectory().toFile());
List<File> ivyEngineClassPathFiles = EngineClassLoaderFactory.getIvyEngineClassPathFiles(identifyAndGetEngineDirectory());
String propertyValue = StringUtils.join(ivyEngineClassPathFiles, ",");

MavenProperties properties = new MavenProperties(project, getLog());
properties.setMavenProperty(IVY_ENGINE_CORE_CLASSPATH_PROPERTY, propertyValue);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ protected MavenProjectBuilderProxy getMavenProjectBuilder() throws Exception {
getLog(),
timeoutEngineStartInSeconds);
}
classLoaderFactory.writeEngineClasspathJar(toFile(engineDir));
classLoaderFactory.writeEngineClasspathJar(engineDir);
// share engine directory as property for custom follow up plugins:
if (engineDir != null) {
project.getProperties().put(AbstractEngineMojo.ENGINE_DIRECTORY_PROPERTY, engineDir.toAbsolutePath().toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,12 @@

package ch.ivyteam.ivy.maven.deploy;

import java.io.File;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.ReadOnlyFileSystemException;

import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.plugin.MojoExecutionException;
Expand Down Expand Up @@ -244,12 +243,14 @@ protected final Path createDeployOptionsFile(DeploymentOptionsFileFactory option
return null;
}

protected static final void removeTemporaryDeploymentOptionsFile(Path deploymentOptionsFile) {
FileUtils.deleteQuietly(toFile(deploymentOptionsFile));
}

private static File toFile(Path file) {
return file == null ? null : file.toFile();
protected static void deleteFile(Path file) {
if (file != null && Files.exists(file)) {
try {
Files.delete(file);
} catch (IOException ex) {
throw new UncheckedIOException("Could not delete " + file, ex);
}
}
}

protected final void deployToDirectory(Path resolvedOptionsFile, Path deployDir)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public void execute() throws MojoExecutionException, MojoFailureException {
try {
deployWithOptions(resolvedOptionsFile);
} finally {
removeTemporaryDeploymentOptionsFile(resolvedOptionsFile);
deleteFile(resolvedOptionsFile);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ private void deployTestApp() throws MojoExecutionException {
var deployDir = getEngineDir(project).resolve(DeployToEngineMojo.DEPLOY_DEFAULT);
deployToDirectory(resolvedOptionsFile, deployDir);
} finally {
removeTemporaryDeploymentOptionsFile(resolvedOptionsFile);
deleteFile(resolvedOptionsFile);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,13 @@
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.function.Predicate;

import org.apache.commons.io.FileUtils;
import org.apache.commons.io.filefilter.IOFileFilter;
import org.apache.commons.io.filefilter.SuffixFileFilter;
import org.apache.commons.io.filefilter.WildcardFileFilter;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.plugin.logging.Log;
Expand Down Expand Up @@ -72,12 +71,10 @@ public EngineClassLoaderFactory(MavenContext mavenContext) {
this.maven = mavenContext;
}

public URLClassLoader createEngineClassLoader(File engineDirectory) throws IOException {
public URLClassLoader createEngineClassLoader(Path engineDirectory) throws IOException {
List<File> osgiClasspath = getOsgiBootstrapClasspath(engineDirectory);
var filter = WildcardFileFilter.builder()
.setWildcards("org.eclipse.osgi_*.jar")
.get();
addToClassPath(osgiClasspath, new File(engineDirectory, OsgiDir.PLUGINS), filter);
var pluginsDir = engineDirectory.resolve(OsgiDir.PLUGINS);
addToClassPath(osgiClasspath, pluginsDir, p -> p.getFileName().toString().startsWith("org.eclipse.osgi_") && p.getFileName().toString().endsWith(".jar"));
osgiClasspath.addAll(0, getSlf4jJars());
if (maven.log.isDebugEnabled()) {
maven.log.debug("Configuring OSGi engine classpath:");
Expand All @@ -93,35 +90,55 @@ public List<File> getSlf4jJars() {
maven.getJar("org.slf4j", "log4j-over-slf4j", SLF4J_VERSION));
}

public static List<File> getOsgiBootstrapClasspath(File engineDirectory) {
if (engineDirectory == null || !engineDirectory.isDirectory()) {
public static List<File> getOsgiBootstrapClasspath(Path engineDirectory) {
if (engineDirectory == null || !Files.isDirectory(engineDirectory)) {
throw new RuntimeException("The engineDirectory is missing: " + engineDirectory);
}
List<File> classPathFiles = new ArrayList<>();
addToClassPath(classPathFiles, new File(engineDirectory, OsgiDir.INSTALL_AREA + "/" + OsgiDir.LIB_BOOT),
new SuffixFileFilter(".jar"));
var libBoot = engineDirectory.resolve(OsgiDir.INSTALL_AREA).resolve(OsgiDir.LIB_BOOT);
addToClassPath(classPathFiles, libBoot, p -> p.getFileName().toString().endsWith(".jar"));
return classPathFiles;
}

private static void addToClassPath(List<File> classPathFiles, File dir, IOFileFilter fileFilter) {
if (dir.isDirectory()) {
classPathFiles.addAll(FileUtils.listFiles(dir, fileFilter, null));
private static void addToClassPath(List<File> classPathFiles, Path dir, Predicate<Path> filter) {
if (Files.isDirectory(dir)) {
try (var stream = Files.list(dir)) {
var files = stream
.filter(filter)
.map(p -> p.toFile())
.toList();
classPathFiles.addAll(files);
} catch (IOException ex) {
throw new RuntimeException(ex);
}
}
}

public static List<File> getIvyEngineClassPathFiles(File engineDirectory) {
List<File> classPathFiles = new ArrayList<>();
public static List<File> getIvyEngineClassPathFiles(Path engineDirectory) {
if (engineDirectory == null) {
return List.of();
}

var classPathFiles = new ArrayList<File>();
for (String libDirPath : ENGINE_LIB_DIRECTORIES) {
File jarDir = new File(engineDirectory, libDirPath + File.separator);
if (!jarDir.isDirectory()) {
var jarDir = engineDirectory.resolve(libDirPath);
if (!Files.isDirectory(jarDir)) {
continue;
}
classPathFiles.addAll(FileUtils.listFiles(jarDir, new String[] {"jar"}, true));
try (var walker = Files.walk(jarDir)) {
var jars = walker
.filter(p -> p.getFileName().toString().endsWith(".jar"))
.map(p -> p.toFile())
.toList();
classPathFiles.addAll(jars);
} catch (IOException ex) {
throw new RuntimeException(ex);
}
}
return classPathFiles;
}

public void writeEngineClasspathJar(File engineDirectory) throws IOException {
public void writeEngineClasspathJar(Path engineDirectory) throws IOException {
writeEngineClasspathJar(getIvyEngineClassPathFiles(engineDirectory));
}

Expand Down Expand Up @@ -163,5 +180,4 @@ public File getJar(String groupId, String artifactId, String version) {
return jar;
}
}

}
}
Loading
Loading