Skip to content

Commit

Permalink
Fix deprecation warnings
Browse files Browse the repository at this point in the history
- Enable deprecation warnings in build
- Use Java Compiler recorder intead of ECJ
  • Loading branch information
alexsuter committed Jul 19, 2024
1 parent cd2898b commit 787e393
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 33 deletions.
2 changes: 1 addition & 1 deletion Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,5 @@ def collectBuildArtifacts() {
// 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: [eclipse()], qualityGates: [[threshold: 1, type: 'TOTAL']]
recordIssues tools: [java()], qualityGates: [[threshold: 1, type: 'TOTAL']]
}
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@
<version>3.13.0</version>
<configuration>
<release>${java.version}</release>
<showDeprecation>true</showDeprecation>
</configuration>
</plugin>
<plugin>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,10 @@ public EngineClassLoaderFactory(MavenContext mavenContext) {

public URLClassLoader createEngineClassLoader(File engineDirectory) throws IOException {
List<File> osgiClasspath = getOsgiBootstrapClasspath(engineDirectory);
addToClassPath(osgiClasspath, new File(engineDirectory, OsgiDir.PLUGINS),
new WildcardFileFilter("org.eclipse.osgi_*.jar"));
var filter = WildcardFileFilter.builder()
.setWildcards("org.eclipse.osgi_*.jar")
.get();
addToClassPath(osgiClasspath, new File(engineDirectory, OsgiDir.PLUGINS), filter);
osgiClasspath.addAll(0, getSlf4jJars());
if (maven.log.isDebugEnabled()) {
maven.log.debug("Configuring OSGi engine classpath:");
Expand Down Expand Up @@ -130,11 +132,11 @@ private void writeEngineClasspathJar(List<File> ivyEngineClassPathFiles) throws
}

private static URL[] toUrls(List<File> ivyEngineClassPathFiles) throws MalformedURLException {
List<URL> classPathUrls = new ArrayList<>();
var classPathUrls = new ArrayList<URL>();
for (File file : ivyEngineClassPathFiles) {
classPathUrls.add(new URL(file.toURI().toASCIIString()));
classPathUrls.add(file.toURI().toURL());
}
return classPathUrls.toArray(new URL[classPathUrls.size()]);
return classPathUrls.toArray(URL[]::new);
}

public static class MavenContext {
Expand Down
11 changes: 7 additions & 4 deletions src/main/java/ch/ivyteam/ivy/maven/engine/EngineControl.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,10 @@ public Executor start() throws Exception {

Executor executor = createEngineExecutor();
executor.setStreamHandler(createEngineLogStreamForwarder(logLine -> findStartEngineUrl(logLine)));
executor.setWatchdog(new ExecuteWatchdog(ExecuteWatchdog.INFINITE_TIMEOUT));
var watchdog = ExecuteWatchdog.builder()
.setTimeout(ExecuteWatchdog.INFINITE_TIMEOUT_DURATION)
.get();
executor.setWatchdog(watchdog);
executor.setProcessDestroyer(new ShutdownHookProcessDestroyer());
executor.execute(startCmd, asynchExecutionHandler());
waitForEngineStart(executor);
Expand Down Expand Up @@ -130,9 +133,9 @@ private CommandLine toEngineCommand(Command command) {
}

private Executor createEngineExecutor() {
DefaultExecutor executor = new DefaultExecutor();
executor.setWorkingDirectory(context.engineDirectory);
return executor;
return DefaultExecutor.builder()
.setWorkingDirectory(context.engineDirectory)
.get();
}

private PumpStreamHandler createEngineLogStreamForwarder(Consumer<String> logLineHandler)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package ch.ivyteam.ivy.maven.engine.download;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
Expand Down Expand Up @@ -66,7 +67,7 @@ private URL findEngineDownloadUrlFromListPage() throws MojoExecutionException {
} finally {
Files.deleteIfExists(index);
}
} catch (IOException ex) {
} catch (Exception ex) {
throw new MojoExecutionException("Failed to find engine download link in list page " + engineListPageUrl, ex);
}
}
Expand Down Expand Up @@ -128,7 +129,7 @@ public String getZipFileNameFromDownloadLocation() {
}

public URL findEngineDownloadUrl(InputStream htmlStream)
throws MojoExecutionException, MalformedURLException {
throws MojoExecutionException, MalformedURLException, URISyntaxException {
String engineFileNameRegex = "AxonIvyEngine[^.]+?\\.[^.]+?\\.+[^_]*?_" + osArchitecture + "\\.zip";
Pattern enginePattern = Pattern.compile("href=[\"|'][^\"']*?" + engineFileNameRegex + "[\"|']");
try (Scanner scanner = new Scanner(htmlStream)) {
Expand All @@ -152,12 +153,11 @@ public URL findEngineDownloadUrl(InputStream htmlStream)
}
}

private static URL toAbsoluteLink(URL baseUrl, String parsedEngineArchivLink) throws MalformedURLException {
private static URL toAbsoluteLink(URL baseUrl, String parsedEngineArchivLink) throws MalformedURLException, URISyntaxException {
boolean isAbsoluteLink = StringUtils.startsWithAny(parsedEngineArchivLink, "http://", "https://");
if (isAbsoluteLink) {
return new URL(parsedEngineArchivLink);
return URI.create(parsedEngineArchivLink).toURL();
}
return new URL(baseUrl, parsedEngineArchivLink);
return baseUrl.toURI().resolve(parsedEngineArchivLink).toURL();
}

}
10 changes: 3 additions & 7 deletions src/main/java/ch/ivyteam/ivy/maven/util/MavenDependencies.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,9 @@ private Optional<MavenProject> findReactorProject(Artifact artifact) {
if (session == null) {
return Optional.empty();
}
var projects = session.getProjectMap();
if (projects == null) {
return Optional.empty();
}
String artifactKey = artifact.getGroupId() + ":" + artifact.getArtifactId() + ":" + artifact.getVersion();
MavenProject reactorProject = projects.get(artifactKey);
return Optional.ofNullable(reactorProject);
return session.getAllProjects().stream()
.filter(p -> p.getArtifact().equals(artifact))
.findAny();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.net.URI;
import java.nio.file.Files;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.Calendar;
Expand Down Expand Up @@ -96,7 +96,7 @@ protected void before() throws Throwable {

String alternateEngineListPageUrl = System.getProperty(InstallEngineMojo.ENGINE_LIST_URL_PROPERTY);
if (alternateEngineListPageUrl != null) {
getMojo().engineListPageUrl = new URL(alternateEngineListPageUrl);
getMojo().engineListPageUrl = URI.create(alternateEngineListPageUrl).toURL();
}
getMojo().engineCacheDirectory = new File(CACHE_DIR);
getMojo().ivyVersion = ENGINE_VERSION_TO_TEST;
Expand Down
16 changes: 9 additions & 7 deletions src/test/java/ch/ivyteam/ivy/maven/TestInstallEngineMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import java.io.FileInputStream;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
Expand Down Expand Up @@ -75,7 +77,7 @@ public void stopHttp() {
}

private URL mockEngineZip() throws MalformedURLException {
return new URL(mockBaseUrl+"/fakeEngine.zip");
return URI.create(mockBaseUrl + "/fakeEngine.zip").toURL();
}

@Test
Expand All @@ -89,7 +91,7 @@ public void testEngineDownload_defaultBehaviour() throws Exception {
// test setup can not expand expression ${settings.localRepository}: so we
// setup an explicit temp dir!
mojo.engineCacheDirectory = Files.createTempDirectory("tmpRepo").toFile();
mojo.engineListPageUrl = new URL(mockBaseUrl + "/listPageUrl.html");
mojo.engineListPageUrl = URI.create(mockBaseUrl + "/listPageUrl.html").toURL();

File defaultEngineDir = new File(mojo.engineCacheDirectory, DEFAULT_VERSION);
assertThat(defaultEngineDir).doesNotExist();
Expand Down Expand Up @@ -149,7 +151,7 @@ public void testEngineDownload_alreadyInstalledVersionWithinRange() throws Excep

mojo.ivyVersion = "[7.0.0,800.0.0)";
mojo.autoInstallEngine = true;
mojo.engineDownloadUrl = new URL("http://localhost/fakeUri");
mojo.engineDownloadUrl = URI.create("http://localhost/fakeUri").toURL();

mojo.execute();
assertThat(mojo.engineDirectory.listFiles()).isNotEmpty();
Expand Down Expand Up @@ -231,7 +233,7 @@ public void testEngineDownload_overProxy() throws Exception {
mojo.autoInstallEngine = true;
mockServer.setMockHttpServerResponses(createFakeZipResponse(createFakeEngineZip(DEFAULT_VERSION)));

mojo.engineDownloadUrl = new URL("http://localhost:7123/fakeEngine.zip"); // not reachable: but proxy knows how :)
mojo.engineDownloadUrl = URI.create("http://localhost:7123/fakeEngine.zip").toURL(); // not reachable: but proxy knows how :)
var downloader = (URLEngineDownloader) mojo.getDownloader();
try {
downloader.downloadEngine();
Expand Down Expand Up @@ -307,7 +309,7 @@ public void testEngineLinkFinder_relative() throws Exception {
mojo.ivyVersion = "[7.0.0,7.1.0]";
mojo.restrictVersionToMinimalCompatible = false;
mojo.osArchitecture = "Windows_x86";
mojo.engineListPageUrl = new URL("http://localhost/");
mojo.engineListPageUrl = URI.create("http://localhost/").toURL();
assertThat(findLink("<a href=\"7.0.0/AxonIvyEngine7.0.0.46949_Windows_x86.zip\">the latest engine</a>"))
.isEqualTo("http://localhost/7.0.0/AxonIvyEngine7.0.0.46949_Windows_x86.zip");
}
Expand Down Expand Up @@ -354,15 +356,15 @@ public void testEngineLinkFinder_multipleLinks() throws Exception {
mojo.ivyVersion = "[7.0.0,7.1.0]";
mojo.restrictVersionToMinimalCompatible = false;
mojo.osArchitecture = "Linux_x86";
mojo.engineListPageUrl = new URL("http://localhost/");
mojo.engineListPageUrl = URI.create("http://localhost/").toURL();

assertThat(findLink(
"<a href=\"7.0.0/AxonIvyEngine7.0.0.46949_Windows_x86.zip\">the latest engine</a>" // windows
+ "<a href=\"7.0.0/AxonIvyEngine7.0.0.46949_Linux_x86.zip\">the latest engine</a>")) // linux
.isEqualTo("http://localhost/7.0.0/AxonIvyEngine7.0.0.46949_Linux_x86.zip");
}

private String findLink(String html) throws MojoExecutionException, MalformedURLException {
private String findLink(String html) throws MojoExecutionException, MalformedURLException, URISyntaxException {
return getUrlDownloader().findEngineDownloadUrl(IOUtils.toInputStream(html, StandardCharsets.UTF_8)).toExternalForm();
}

Expand Down

0 comments on commit 787e393

Please sign in to comment.