-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: configure Maven wrapper usage if available
Signed-off-by: Fred Bricon <[email protected]>
- Loading branch information
Showing
2 changed files
with
63 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
src/main/java/com/redhat/devtools/intellij/quarkus/buildtool/maven/MavenWrapperUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. | ||
package com.redhat.devtools.intellij.quarkus.buildtool.maven; | ||
|
||
import com.intellij.openapi.vfs.VirtualFile; | ||
import org.jetbrains.annotations.Nullable; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.io.ByteArrayInputStream; | ||
import java.io.IOException; | ||
import java.util.Properties; | ||
|
||
/** | ||
* Port of <a href="https://github.com/JetBrains/intellij-community/blob/fa32fd18b2ea30ef9994f9737304df918ba12055/plugins/maven/src/main/java/org/jetbrains/idea/maven/server/MavenWrapperSupport.kt#L177-L187">MavenWrapperSupport.getWrapperDistributionUrl</a> to Java | ||
*/ | ||
public class MavenWrapperUtils { | ||
private static final Logger LOGGER = LoggerFactory.getLogger(MavenWrapperUtils.class); | ||
private static final String DISTRIBUTION_URL_PROPERTY = "distributionUrl"; | ||
private MavenWrapperUtils(){} | ||
|
||
public static String getWrapperDistributionUrl(VirtualFile baseDir) { | ||
VirtualFile wrapperPropertiesFile = getWrapperProperties(baseDir); | ||
if (wrapperPropertiesFile == null) { | ||
return null; | ||
} | ||
|
||
try (ByteArrayInputStream stream = new ByteArrayInputStream(wrapperPropertiesFile.contentsToByteArray(true))) { | ||
Properties properties = new Properties(); | ||
properties.load(stream); | ||
return properties.getProperty(DISTRIBUTION_URL_PROPERTY); | ||
} catch (IOException e) { | ||
LOGGER.warn("Failed to read Maven Wrapper from "+baseDir, e); | ||
} | ||
return null; | ||
} | ||
|
||
public static @Nullable VirtualFile getWrapperProperties(VirtualFile baseDir) { | ||
if (baseDir != null) { | ||
VirtualFile mvnDir = baseDir.findChild(".mvn"); | ||
if (mvnDir != null) { | ||
VirtualFile wrapperDir = mvnDir.findChild("wrapper"); | ||
if (wrapperDir != null) { | ||
return wrapperDir.findChild("maven-wrapper.properties"); | ||
} | ||
} | ||
} | ||
return null; | ||
} | ||
} |