Skip to content

Commit

Permalink
maven daemon support.
Browse files Browse the repository at this point in the history
  • Loading branch information
mbien committed Oct 4, 2021
1 parent f154606 commit fdbd5dc
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
package org.netbeans.modules.maven.execute.cmd;

import java.io.File;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import org.netbeans.api.annotations.common.NonNull;
Expand All @@ -39,24 +41,28 @@ public ShellConstructor(@NonNull File mavenHome) {

@Override
public List<String> construct() {

// use mvnd if its the home of a daemon
String ex = Files.exists(Path.of(mavenHome.getPath(), "bin", "mvnd")) ? "mvnd" : "mvn"; //NOI18N

//#164234
//if maven.bat file is in space containing path, we need to quote with simple quotes.
String quote = "\"";
List<String> toRet = new ArrayList<String>();
String ex = "mvn"; //NOI18N
List<String> toRet = new ArrayList<>();

if (Utilities.isWindows()) {
String version = MavenSettings.getCommandLineMavenVersion(mavenHome);
if (null == version) {
ex = "mvn.bat"; // NOI18N
ex += ".bat"; // NOI18N
} else {
String[] v = version.split("\\."); // NOI18N
int major = Integer.parseInt(v[0]);
int minor = Integer.parseInt(v[1]);
// starting with 3.3.0 maven stop using .bat file
if ((major < 3) || (major == 3 && minor < 3)) {
ex = "mvn.bat"; //NOI18N
ex += ".bat"; //NOI18N
} else {
ex = "mvn.cmd"; //NOI18N
ex += ".cmd"; //NOI18N
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.io.File;
import java.io.FilenameFilter;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.nio.file.Path;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
Expand All @@ -35,6 +36,7 @@
import java.util.logging.Logger;
import java.util.prefs.BackingStoreException;
import java.util.prefs.Preferences;
import java.util.stream.Collectors;
import org.apache.maven.execution.MavenExecutionRequest;
import org.codehaus.plexus.util.cli.CommandLineUtils;
import org.netbeans.api.annotations.common.CheckForNull;
Expand Down Expand Up @@ -457,32 +459,32 @@ public void setBinaryDownloadStrategy(DownloadStrategy ds) {
}

public static @CheckForNull String getCommandLineMavenVersion(File mavenHome) {
File[] jars = new File(mavenHome, "lib").listFiles(new FilenameFilter() { // NOI18N
public @Override boolean accept(File dir, String name) {
return name.endsWith(".jar"); // NOI18N

Path lib = Path.of(mavenHome.getPath(), "lib"); // mvn layout // NOI18N
if (!Files.exists(lib)) {
lib = Path.of(mavenHome.getPath(), "mvn", "lib"); // mvnd layout // NOI18N
if (!Files.exists(lib)) {
return null;
}
});
if (jars == null) {
return null;
}
for (File jar : jars) {
try {

try {
List<Path> jars = Files.list(lib).filter((file) -> file.toString().endsWith(".jar")).collect(Collectors.toList()); // NOI18N

for (Path jar : jars) {
// Prefer to use this rather than raw ZipFile since URLMapper since ArchiveURLMapper will cache JARs:
FileObject entry = URLMapper.findFileObject(new URL(FileUtil.urlForArchiveOrDir(jar), "META-INF/maven/org.apache.maven/maven-core/pom.properties")); // NOI18N
FileObject entry = URLMapper.findFileObject(
new URL(FileUtil.urlForArchiveOrDir(jar.toFile()), "META-INF/maven/org.apache.maven/maven-core/pom.properties")); // NOI18N
if (entry != null) {
InputStream is = entry.getInputStream();
try {
try (InputStream is = entry.getInputStream()) {
Properties properties = new Properties();
properties.load(is);
return properties.getProperty("version"); // NOI18N
} finally {
is.close();
}
}
} catch (IOException x) {
// ignore for now
}
}
} catch (IOException ignored) {}

return null;
}

Expand Down

0 comments on commit fdbd5dc

Please sign in to comment.