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
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
Expand All @@ -32,6 +33,7 @@
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;

import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.versioning.ArtifactVersion;
import org.apache.maven.artifact.versioning.OverConstrainedVersionException;
Expand All @@ -44,6 +46,7 @@
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.util.Os;
import org.codehaus.plexus.util.cli.Arg;
import org.codehaus.plexus.util.cli.CommandLineException;
import org.codehaus.plexus.util.cli.CommandLineUtils;
import org.codehaus.plexus.util.cli.Commandline;
Expand All @@ -59,7 +62,6 @@
import org.eclipse.aether.util.graph.visitor.PreorderNodeListGenerator;

/**
*
* @author dantran <[email protected]>
* @version $Id: AbstractJaxwsMojo.java 3240 2007-02-04 07:13:21Z dantran $ *
*/
Expand Down Expand Up @@ -246,7 +248,7 @@ protected List<String> getCommonArgs() throws MojoExecutionException {
commonArgs.add("-extension");
}

if(getXnocompile()){
if (getXnocompile()) {
commonArgs.add("-Xnocompile");
}

Expand Down Expand Up @@ -319,7 +321,7 @@ protected void exec(List<String> args) throws MojoExecutionException {
if (executable != null) {
if (executable.isFile() && executable.canExecute()) {
cmd.setExecutable(executable.getAbsolutePath());
if (getExtraClasspath() != null) {
if (getExtraClasspath() != null) {
cmd.createArg().setLine("-cp");
cmd.createArg().setValue(getExtraClasspath());
}
Expand All @@ -343,7 +345,13 @@ protected void exec(List<String> args) throws MojoExecutionException {
String cp = extraCp != null ? extraCp + File.pathSeparator : "";
cp += classpath[0];
try {
File pathFile = createPathFile(cp);
Map<String, String> cpMap = new HashMap<>();
cpMap.put("cp", cp);
cpMap.put("wsgen.classpath", classpath[0]);
if (extraCp != null) {
cpMap.put("wsgen.extra.classpath", extraCp);
}
File pathFile = createPathFile(cpMap);
cmd.createArg().setLine("-pathfile " + pathFile.getAbsolutePath());
} catch (IOException ioe) {
//creation of temporary file can fail, in such case just put everything on cp
Expand Down Expand Up @@ -445,7 +453,7 @@ private String getJavaExec() {
return isWindows() ? "java.exe" : "java";
}

private File createPathFile(String cp) throws IOException {
private File createPathFile(Map<String, String> cpMap) throws IOException {
File f = File.createTempFile("jax-ws-mvn-plugin-cp", ".txt");
if (f.exists() && f.isFile()) {
if (!f.delete()) {
Expand All @@ -454,8 +462,14 @@ private File createPathFile(String cp) throws IOException {
}
}
Properties p = new Properties();
p.put("cp", cp.replace(File.separatorChar, '/'));
getLog().debug("stored classpath: " + cp.replace(File.separatorChar, '/'));
cpMap.forEach((key, value) -> {
p.put(key, value.replace(File.separatorChar, '/'));
getLog().debug(String.format(
"stored classpath: %s - %s\n",
key,
value.replace(File.separatorChar, '/')
));
});
FileOutputStream fos = null;
try {
fos = new FileOutputStream(f);
Expand Down Expand Up @@ -497,7 +511,7 @@ private void sortArtifacts(DependencyResult result, Map<String, org.eclipse.aeth
}

private boolean containsTools(Set<String> cp) {
return cp.contains("com.sun.xml.ws:jaxws-tools")
return cp.contains("com.sun.xml.ws:jaxws-tools")
|| cp.contains("org.glassfish.metro:webservices-tools")
|| cp.contains("com.oracle.weblogic:weblogic-server-pom");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,16 @@ public final class Invoker {
public static void main(String... args) throws Exception {
int idx = 1;
String c = args[2];
String wsgenClasspath = null;
String wsgenExtraClasspath = null;
if ("-pathfile".equals(args[1])) {
Properties p = new Properties();
File pathFile = new File(args[2]);
pathFile.deleteOnExit();
p.load(new FileInputStream(pathFile));
c = p.getProperty("cp");
wsgenClasspath = p.getProperty("wsgen.classpath");
wsgenExtraClasspath = p.getProperty("wsgen.extra.classpath");
idx = 3;
}
List<URL> cp = new ArrayList<URL>();
Expand All @@ -66,6 +70,10 @@ public static void main(String... args) throws Exception {
String origJcp = System.getProperty("java.class.path");
Thread.currentThread().setContextClassLoader(cl);
System.setProperty("java.class.path", c);
System.setProperty("wsgen.classpath", wsgenClasspath);
if (wsgenExtraClasspath != null) {
System.setProperty("wsgen.extra.classpath", wsgenExtraClasspath);
}
try {
Class<?> compileTool = cl.loadClass(args[0]);
Constructor<?> ctor = compileTool.getConstructor(OutputStream.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ public class Options {

public String classpath = System.getProperty("java.class.path");

public String wsgenExtraClasspath = System.getProperty("wsgen.extra.classpath");

public String wsgenClasspath = System.getProperty("wsgen.classpath");

/**
* -javacOptions
*
Expand All @@ -102,6 +106,17 @@ public class Options {
*/
public boolean disableXmlSecurity;

/**
* -Xno-modules
* If it is true, java compiler will not use modules during the compilation. All dependencies will be put to the classpath.
*/
public boolean noModules;

/**
* -modulepath
*/
public String modulepath;

public enum Target {

V2_0("2.0"), V2_1("2.1"), V2_2("2.2"), V2_3("2.3"), V3_0("3.0");
Expand Down Expand Up @@ -368,6 +383,12 @@ protected int parseArguments(String[] args, int i) throws BadCommandLineExceptio
}
javacOptions.add(args[i].substring(2));
return 1;
} else if (args[i].equals("-Xno-modules")) {
noModules = true;
return 1;
} else if (args[i].equals("-modulepath")) {
modulepath = requireArgument("-modulepath", args, ++i);
return 2;
}
return 0;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@
import javax.xml.namespace.QName;
import javax.xml.transform.Result;
import javax.xml.transform.stream.StreamResult;

import jakarta.xml.ws.Holder;

import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
Expand All @@ -50,14 +52,21 @@
import java.io.PrintStream;
import java.net.URLClassLoader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.ServiceLoader;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import javax.tools.Diagnostic;
import javax.tools.DiagnosticListener;

import org.xml.sax.ext.Locator2Impl;

/**
Expand All @@ -70,6 +79,13 @@
public class WsgenTool {
private final PrintStream out;
private final WsgenOptions options = new WsgenOptions();
private static final String RELEASE_MARK = "releaseMark";
private static final String JAVA_VERSION_MARK = "javaVersion";
private static final Pattern RELEASE_VERSION_PATTERN =
Pattern.compile("(?<" + RELEASE_MARK + ">--release=)(?<" + JAVA_VERSION_MARK + ">[0-9]+)");
private static final int JAVA_MODULE_VERSION = 9;
private static final String CLASSPATH_KEY = "--class-path";
private static final String MODULEPATH_KEY = "--module-path";


public WsgenTool(OutputStream out, Container container) {
Expand Down Expand Up @@ -124,7 +140,6 @@ public boolean run(String[] args) {
private final Container container;

/**
*
* @param endpoint
* @param listener
* @return
Expand All @@ -139,8 +154,24 @@ public boolean buildModel(String endpoint, Listener listener) throws BadCommandL

args.add("-d");
args.add(options.destDir.getAbsolutePath());
args.add("-classpath");
args.add(options.classpath);

int javaVersion = 0;
if (options.javacOptions != null) {
for (String option : options.javacOptions) {
final Matcher matcher = RELEASE_VERSION_PATTERN.matcher(option);
if (matcher.find()) {
javaVersion = Integer.parseInt(matcher.group(JAVA_VERSION_MARK));
break;
}
}
}
if (javaVersion < JAVA_MODULE_VERSION || options.noModules) {
args.add("-classpath");
args.add(options.classpath);
} else {
args.addAll(generatePathArgs(args));
}

args.add("-s");
args.add(options.sourceDir.getAbsolutePath());
if (options.nocompile) {
Expand Down Expand Up @@ -313,6 +344,87 @@ public Result getSchemaOutput(String namespace, Holder<String> filename) {
return true;
}

private List<String> generatePathArgs(List<String> args) {
List<String> result = new ArrayList<>();
Map<String, String> separatedDependencies = new HashMap<>();
Map<String, String> separatedWsgenClasspath = splitWsgenClasspath();
separatedWsgenClasspath.computeIfPresent(CLASSPATH_KEY, separatedDependencies::put);
separatedWsgenClasspath.computeIfPresent(MODULEPATH_KEY, separatedDependencies::put);
if (options.modulepath != null) {
Map<String, String> separatedExtraClasspath = splitExtraClasspath();
separatedExtraClasspath.computeIfPresent(CLASSPATH_KEY, (key, value) ->
separatedDependencies.merge(
CLASSPATH_KEY, value,
(oldValue, newValue) -> oldValue + File.pathSeparator + value
));
separatedExtraClasspath.computeIfPresent(MODULEPATH_KEY, (key, value) ->
separatedDependencies.merge(
MODULEPATH_KEY, value,
(oldValue, newValue) -> oldValue + File.pathSeparator + value
));
}
if (separatedDependencies.containsKey(CLASSPATH_KEY)) {
result.add(CLASSPATH_KEY);
result.add(separatedDependencies.get(CLASSPATH_KEY));
}
if (separatedDependencies.containsKey(MODULEPATH_KEY)) {
result.add(MODULEPATH_KEY);
result.add(separatedDependencies.get(MODULEPATH_KEY));
}
return result;
}

private Map<String, String> splitExtraClasspath() {
Map<String, String> result = new HashMap<>();
String cp = options.wsgenExtraClasspath;
String mp = options.modulepath;
if (cp == null || cp.isEmpty()) {
if (mp == null || mp.isEmpty()){
return result;
}
result.put(MODULEPATH_KEY, mp);
return result;
}
if (mp == null || mp.isEmpty()){
result.put(CLASSPATH_KEY, mp);
return result;
}
Set<String> splitCP = new HashSet(Arrays.asList(cp.split(File.pathSeparator)));
Set<String> splitMP = new HashSet(Arrays.asList(mp.split(File.pathSeparator)));
Set<String> onlyCP = new HashSet<>(splitCP);
onlyCP.removeAll(splitMP);
if (!onlyCP.isEmpty()) {
result.put(CLASSPATH_KEY, String.join(File.pathSeparator, onlyCP));
}
if (!splitMP.isEmpty()) {
result.put(MODULEPATH_KEY, mp);
}
return result;
}

private Map<String, String> splitWsgenClasspath() {
Map<String, String> result = new HashMap<>();
String mp = options.wsgenClasspath;
if (mp == null || mp.isEmpty()) {
return result;
}
List<String> classpathJarNames = Arrays.asList("ha-api");
Set<String> splitMP = new HashSet(Arrays.asList(mp.split(File.pathSeparator)));
Set<String> onlyMP = new HashSet<>(splitMP);
Set<String> onlyCP = onlyMP.stream()
.filter(name -> classpathJarNames.stream().anyMatch(name::contains))
.collect(Collectors.toSet());
onlyMP.removeAll(onlyCP);
if (!onlyMP.isEmpty()) {
result.put(MODULEPATH_KEY, String.join(File.pathSeparator, onlyMP));
}
if (!onlyCP.isEmpty()) {

result.put(CLASSPATH_KEY, String.join(File.pathSeparator, onlyCP));
}
return result;
}

private String property(String key) {
try {
String property = System.getProperty(key);
Expand Down Expand Up @@ -422,8 +534,8 @@ protected void usage(Options options) {
options = this.options;
if (options instanceof WsgenOptions) {
System.out.println(WscompileMessages.WSGEN_HELP("WSGEN",
((WsgenOptions)options).protocols,
((WsgenOptions)options).nonstdProtocols.keySet()));
((WsgenOptions) options).protocols,
((WsgenOptions) options).nonstdProtocols.keySet()));
System.out.println(WscompileMessages.WSGEN_USAGE_EXTENSIONS());
System.out.println(WscompileMessages.WSGEN_USAGE_EXAMPLES());
}
Expand Down