Search in sources :

Example 6 with GenericWsdlOption

use of org.apache.cxf.maven_plugin.GenericWsdlOption in project cxf by apache.

the class WSDL2JavaMojo method mergeOptions.

/**
 * Merge WsdlOptions that point to the same file by adding the extraargs to the first option and deleting
 * the second from the options list
 *
 * @param effectiveWsdlOptions
 */
protected void mergeOptions(List<GenericWsdlOption> effectiveWsdlOptions) {
    File outputDirFile = getGeneratedTestRoot() == null ? getGeneratedSourceRoot() : getGeneratedTestRoot();
    List<GenericWsdlOption> newList = new ArrayList<>();
    for (GenericWsdlOption go : effectiveWsdlOptions) {
        WsdlOption o = (WsdlOption) go;
        if (defaultOptions != null) {
            o.merge(defaultOptions);
        }
        /*
             * If not output dir at all, go for tests, and failing that, source.
             */
        if (o.getOutputDir() == null) {
            o.setOutputDir(outputDirFile);
        }
        File file = o.getWsdlFile(project.getBasedir());
        if (file != null && file.exists()) {
            file = file.getAbsoluteFile();
            boolean duplicate = false;
            for (GenericWsdlOption o2w : newList) {
                WsdlOption o2 = (WsdlOption) o2w;
                File file2 = o2.getWsdlFile(project.getBasedir());
                if (file2 != null && file2.exists() && file2.getAbsoluteFile().equals(file)) {
                    o2.getExtraargs().addAll(0, o.getExtraargs());
                    duplicate = true;
                    break;
                }
            }
            if (!duplicate) {
                newList.add(o);
            }
        } else {
            newList.add(o);
        }
    }
    effectiveWsdlOptions.clear();
    effectiveWsdlOptions.addAll(newList);
}
Also used : GenericWsdlOption(org.apache.cxf.maven_plugin.GenericWsdlOption) GenericWsdlOption(org.apache.cxf.maven_plugin.GenericWsdlOption) ArrayList(java.util.ArrayList) File(java.io.File)

Example 7 with GenericWsdlOption

use of org.apache.cxf.maven_plugin.GenericWsdlOption in project cxf by apache.

the class WsdlOptionLoader method loadWsdlOptionsFromDependencies.

public static List<GenericWsdlOption> loadWsdlOptionsFromDependencies(MavenProject project, File outputDir) {
    List<GenericWsdlOption> options = new ArrayList<>();
    Set<Artifact> dependencies = CastUtils.cast(project.getDependencyArtifacts());
    for (Artifact artifact : dependencies) {
        WsdlOption option = generateWsdlOptionFromArtifact(artifact, outputDir);
        if (option != null) {
            options.add(option);
        }
    }
    return options;
}
Also used : GenericWsdlOption(org.apache.cxf.maven_plugin.GenericWsdlOption) GenericWsdlOption(org.apache.cxf.maven_plugin.GenericWsdlOption) ArrayList(java.util.ArrayList) Artifact(org.apache.maven.artifact.Artifact)

Example 8 with GenericWsdlOption

use of org.apache.cxf.maven_plugin.GenericWsdlOption in project cxf by apache.

the class WSDL2JavaScriptMojo method shouldRun.

@Override
protected boolean shouldRun(GenericWsdlOption genericWsdlOption, File doneFile, URI wsdlURI) {
    WsdlOption wsdlOption = (WsdlOption) genericWsdlOption;
    long timestamp = 0;
    if ("file".equals(wsdlURI.getScheme())) {
        timestamp = new File(wsdlURI).lastModified();
    } else {
        try {
            timestamp = wsdlURI.toURL().openConnection().getDate();
        } catch (Exception e) {
        // ignore
        }
    }
    boolean doWork = false;
    if (!doneFile.exists()) {
        doWork = true;
    } else if (timestamp > doneFile.lastModified()) {
        doWork = true;
    } else {
        File[] files = wsdlOption.getDependencies();
        if (files != null) {
            for (int z = 0; z < files.length; ++z) {
                if (files[z].lastModified() > doneFile.lastModified()) {
                    doWork = true;
                }
            }
        }
    }
    return doWork;
}
Also used : GenericWsdlOption(org.apache.cxf.maven_plugin.GenericWsdlOption) File(java.io.File) URISyntaxException(java.net.URISyntaxException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException)

Example 9 with GenericWsdlOption

use of org.apache.cxf.maven_plugin.GenericWsdlOption in project cxf by apache.

the class WSDL2JavaScriptMojo method loadWsdlOptionsFromDependencies.

public static List<GenericWsdlOption> loadWsdlOptionsFromDependencies(MavenProject project, Option defaultOptions, File outputDir) {
    List<GenericWsdlOption> options = new ArrayList<>();
    Set<Artifact> dependencies = CastUtils.cast(project.getDependencyArtifacts());
    for (Artifact artifact : dependencies) {
        WsdlOption option = new WsdlOption();
        if (WsdlUtilities.fillWsdlOptionFromArtifact(option, artifact, outputDir)) {
            if (defaultOptions != null) {
                option.merge(defaultOptions);
            }
            options.add(option);
        }
    }
    return options;
}
Also used : GenericWsdlOption(org.apache.cxf.maven_plugin.GenericWsdlOption) GenericWsdlOption(org.apache.cxf.maven_plugin.GenericWsdlOption) ArrayList(java.util.ArrayList) Artifact(org.apache.maven.artifact.Artifact)

Example 10 with GenericWsdlOption

use of org.apache.cxf.maven_plugin.GenericWsdlOption in project cxf by apache.

the class WSDL2JavaScriptMojo method loadWsdlOptionsFromFiles.

private List<GenericWsdlOption> loadWsdlOptionsFromFiles(File wsdlBasedir, File defaultOutputDir) throws MojoExecutionException {
    if (wsdlBasedir == null) {
        return Collections.emptyList();
    }
    if (!wsdlBasedir.exists()) {
        throw new MojoExecutionException(wsdlBasedir + " does not exist");
    }
    List<File> wsdlFiles = WsdlUtilities.getWsdlFiles(wsdlBasedir, includes, excludes);
    List<GenericWsdlOption> options = new ArrayList<>();
    for (File wsdl : wsdlFiles) {
        WsdlOption wsdlOption = new WsdlOption();
        wsdlOption.setOutputDir(defaultOutputDir);
        wsdlOption.setUri(wsdl.toURI().toString());
        options.add(wsdlOption);
    }
    return options;
}
Also used : GenericWsdlOption(org.apache.cxf.maven_plugin.GenericWsdlOption) GenericWsdlOption(org.apache.cxf.maven_plugin.GenericWsdlOption) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ArrayList(java.util.ArrayList) File(java.io.File)

Aggregations

GenericWsdlOption (org.apache.cxf.maven_plugin.GenericWsdlOption)12 ArrayList (java.util.ArrayList)8 File (java.io.File)7 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)6 Artifact (org.apache.maven.artifact.Artifact)4 URI (java.net.URI)3 URISyntaxException (java.net.URISyntaxException)3 IOException (java.io.IOException)2 LinkedHashSet (java.util.LinkedHashSet)2 ToolContext (org.apache.cxf.tools.common.ToolContext)2 DataInputStream (java.io.DataInputStream)1 DataOutputStream (java.io.DataOutputStream)1 OutputStream (java.io.OutputStream)1 OutputStreamCreator (org.apache.cxf.tools.util.OutputStreamCreator)1 WSDLToJava (org.apache.cxf.tools.wsdlto.WSDLToJava)1 WSDLToJavaScript (org.apache.cxf.tools.wsdlto.javascript.WSDLToJavaScript)1