diff --git a/jsonschema2pojo-ant/src/main/java/org/jsonschema2pojo/ant/Jsonschema2PojoTask.java b/jsonschema2pojo-ant/src/main/java/org/jsonschema2pojo/ant/Jsonschema2PojoTask.java index 67328f90a..e0cf8af41 100644 --- a/jsonschema2pojo-ant/src/main/java/org/jsonschema2pojo/ant/Jsonschema2PojoTask.java +++ b/jsonschema2pojo-ant/src/main/java/org/jsonschema2pojo/ant/Jsonschema2PojoTask.java @@ -41,8 +41,10 @@ import org.jsonschema2pojo.GenerationConfig; import org.jsonschema2pojo.Jsonschema2Pojo; import org.jsonschema2pojo.NoopAnnotator; +import org.jsonschema2pojo.URLProtocol; import org.jsonschema2pojo.SourceType; import org.jsonschema2pojo.rules.RuleFactory; +import org.jsonschema2pojo.util.URLUtil; /** * When invoked, this task reads one or more getSource() { - return Collections.singleton(source).iterator(); + public Iterator getSource() { + return Collections.singleton(URLUtil.parseURL(source)).iterator(); } @Override diff --git a/jsonschema2pojo-cli/src/main/java/org/jsonschema2pojo/cli/Arguments.java b/jsonschema2pojo-cli/src/main/java/org/jsonschema2pojo/cli/Arguments.java index be3697300..f2547dc08 100644 --- a/jsonschema2pojo-cli/src/main/java/org/jsonschema2pojo/cli/Arguments.java +++ b/jsonschema2pojo-cli/src/main/java/org/jsonschema2pojo/cli/Arguments.java @@ -20,6 +20,7 @@ import java.io.File; import java.io.FileFilter; +import java.net.URL; import java.util.Iterator; import java.util.List; @@ -34,7 +35,6 @@ import com.beust.jcommander.JCommander; import com.beust.jcommander.Parameter; import com.beust.jcommander.ParameterException; -import com.beust.jcommander.converters.FileConverter; /** * Describes and parses the command line arguments supported by the @@ -51,8 +51,8 @@ public class Arguments implements GenerationConfig { @Parameter(names = { "-t", "--target" }, description = "The target directory into which generated types will be written", required = true) private File targetDirectory; - @Parameter(names = { "-s", "--source" }, description = "The source file(s) or directory(ies) from which JSON Schema will be read", required = true, converter = FileConverter.class) - private List sourcePaths; + @Parameter(names = { "-s", "--source" }, description = "The source file(s) or directory(ies) from which JSON Schema will be read", required = true, converter = UrlConverter.class) + private List sourcePaths; @Parameter(names = { "-b", "--generate-builders" }, description = "Generate builder-style methods as well as setters") private boolean generateBuilderMethods = false; @@ -158,7 +158,7 @@ public Arguments parse(String[] args) { } @Override - public Iterator getSource() { + public Iterator getSource() { return sourcePaths.iterator(); } diff --git a/jsonschema2pojo-cli/src/main/java/org/jsonschema2pojo/cli/Jsonschema2PojoCLI.java b/jsonschema2pojo-cli/src/main/java/org/jsonschema2pojo/cli/Jsonschema2PojoCLI.java index 1bfe326a0..c3dfa4bf5 100644 --- a/jsonschema2pojo-cli/src/main/java/org/jsonschema2pojo/cli/Jsonschema2PojoCLI.java +++ b/jsonschema2pojo-cli/src/main/java/org/jsonschema2pojo/cli/Jsonschema2PojoCLI.java @@ -41,7 +41,7 @@ private Jsonschema2PojoCLI() { * if the application is unable to read data from the paths * specified */ - public static void main(String[] args) throws FileNotFoundException, IOException { + public static void main(String[] args) throws IOException { Arguments arguments = new Arguments().parse(args); diff --git a/jsonschema2pojo-cli/src/main/java/org/jsonschema2pojo/cli/UrlConverter.java b/jsonschema2pojo-cli/src/main/java/org/jsonschema2pojo/cli/UrlConverter.java new file mode 100644 index 000000000..3fcc70bbd --- /dev/null +++ b/jsonschema2pojo-cli/src/main/java/org/jsonschema2pojo/cli/UrlConverter.java @@ -0,0 +1,51 @@ +/** + * Copyright ¬© 2010-2014 Nokia + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jsonschema2pojo.cli; + +import com.beust.jcommander.ParameterException; +import com.beust.jcommander.converters.BaseConverter; +import org.jsonschema2pojo.util.URLUtil; + +import java.net.URL; + +import static org.apache.commons.lang3.StringUtils.isBlank; + + +/** + * Convert a string into a url. + * + * @author jvasiljevich + */ +public class UrlConverter extends BaseConverter { + + public UrlConverter(String optionName) { + super(optionName); + } + + public URL convert(String value) { + if (isBlank(value)) { + throw new ParameterException(getErrorString("a blank value", "a valid URL")); + } + + try { + return URLUtil.parseURL(value); + } catch (IllegalArgumentException e) { + throw new ParameterException(getErrorString(value, "a valid URL")); + } + + } +} diff --git a/jsonschema2pojo-cli/src/test/java/org/jsonschema2pojo/cli/ArgumentsTest.java b/jsonschema2pojo-cli/src/test/java/org/jsonschema2pojo/cli/ArgumentsTest.java index 46ce6ab38..725d66502 100644 --- a/jsonschema2pojo-cli/src/test/java/org/jsonschema2pojo/cli/ArgumentsTest.java +++ b/jsonschema2pojo-cli/src/test/java/org/jsonschema2pojo/cli/ArgumentsTest.java @@ -23,7 +23,10 @@ import java.io.File; import java.io.IOException; import java.io.PrintStream; +import java.net.MalformedURLException; +import java.net.URL; +import org.jsonschema2pojo.util.URLUtil; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -55,7 +58,7 @@ public void parseRecognisesValidArguments() { }); assertThat(args.didExit(), is(false)); - assertThat(args.getSource().next(), is(theFile("/home/source"))); + assertThat(args.getSource().next().getFile(), is("/home/source")); assertThat(args.getTargetDirectory(), is(theFile("/home/target"))); assertThat(args.getTargetPackage(), is("mypackage")); assertThat(args.isGenerateBuilders(), is(true)); @@ -71,7 +74,7 @@ public void parseRecognisesShorthandArguments() { }); assertThat(args.didExit(), is(false)); - assertThat(args.getSource().next(), is(theFile("/home/source"))); + assertThat(args.getSource().next().getFile(), is("/home/source")); assertThat(args.getTargetDirectory(), is(theFile("/home/target"))); assertThat(args.getTargetPackage(), is("mypackage")); assertThat(args.isGenerateBuilders(), is(true)); @@ -96,7 +99,7 @@ public void allOptionalArgsCanBeOmittedAndDefaultsPrevail() { }); assertThat(args.didExit(), is(false)); - assertThat(args.getSource().next(), is(theFile("/home/source"))); + assertThat(args.getSource().next().getFile(), is("/home/source")); assertThat(args.getTargetDirectory(), is(theFile("/home/target"))); assertThat(args.getTargetPackage(), is(nullValue())); assertThat(args.isGenerateBuilders(), is(false)); diff --git a/jsonschema2pojo-cli/src/test/java/org/jsonschema2pojo/cli/UrlConverterTest.java b/jsonschema2pojo-cli/src/test/java/org/jsonschema2pojo/cli/UrlConverterTest.java new file mode 100644 index 000000000..221efe0e6 --- /dev/null +++ b/jsonschema2pojo-cli/src/test/java/org/jsonschema2pojo/cli/UrlConverterTest.java @@ -0,0 +1,57 @@ +/** + * Copyright © 2010-2014 Nokia + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jsonschema2pojo.cli; + +import static org.hamcrest.Matchers.*; +import static org.junit.Assert.*; + +import org.junit.Test; + +import com.beust.jcommander.ParameterException; +import org.jsonschema2pojo.Annotator; + +import java.net.URL; + +public class UrlConverterTest { + + private UrlConverter converter = new UrlConverter("--source"); + + @Test + public void urlIsCreatedFromFilePath() { + URL url = converter.convert("/path/to/something"); + + assertThat(url.getPath(), is("/path/to/something")); + } + + @Test + public void urlIsCreatedFromFileUrl() { + URL url = converter.convert("file:/path/to/something"); + + assertThat(url.toString(), is("file:/path/to/something")); + } + + @Test(expected = ParameterException.class) + public void invalidUrlThrowsParameterException() { + converter.convert("http:total nonsense"); + } + + @Test(expected = ParameterException.class) + public void nullValueThrowsParameterException() { + converter.convert(null); + } + +} diff --git a/jsonschema2pojo-core/pom.xml b/jsonschema2pojo-core/pom.xml index 2b1eaf3be..bd3c80ed8 100644 --- a/jsonschema2pojo-core/pom.xml +++ b/jsonschema2pojo-core/pom.xml @@ -33,6 +33,10 @@ commons-lang commons-lang + + commons-io + commons-io + javax.validation validation-api diff --git a/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/DefaultGenerationConfig.java b/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/DefaultGenerationConfig.java index 74b2af55d..ec51863eb 100644 --- a/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/DefaultGenerationConfig.java +++ b/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/DefaultGenerationConfig.java @@ -20,6 +20,7 @@ import java.io.File; import java.io.FileFilter; +import java.net.URL; import java.util.Iterator; /** @@ -47,7 +48,7 @@ public boolean isUsePrimitives() { * Unsupported since no default source is possible. */ @Override - public Iterator getSource() { + public Iterator getSource() { throw new UnsupportedOperationException("No default source available"); } diff --git a/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/GenerationConfig.java b/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/GenerationConfig.java index 5380f5312..02a48d9ac 100644 --- a/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/GenerationConfig.java +++ b/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/GenerationConfig.java @@ -18,6 +18,7 @@ import java.io.File; import java.io.FileFilter; +import java.net.URL; import java.util.Iterator; import org.jsonschema2pojo.rules.RuleFactory; @@ -55,7 +56,7 @@ public interface GenerationConfig { * @return The source file(s) or directory(ies) from which JSON Schema will * be read. */ - Iterator getSource(); + Iterator getSource(); /** * Gets the 'targetDirectory' configuration option. diff --git a/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/Jsonschema2Pojo.java b/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/Jsonschema2Pojo.java index c4c58efb5..75ca4d217 100644 --- a/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/Jsonschema2Pojo.java +++ b/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/Jsonschema2Pojo.java @@ -18,10 +18,12 @@ import com.sun.codemodel.CodeWriter; import com.sun.codemodel.JCodeModel; -import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; +import java.io.UnsupportedEncodingException; +import java.net.URL; +import java.net.URLDecoder; import java.util.Arrays; import java.util.Collections; import java.util.Iterator; @@ -29,9 +31,10 @@ import static org.apache.commons.lang3.StringUtils.defaultString; import static org.apache.commons.lang3.StringUtils.substringBeforeLast; -import org.jsonschema2pojo.FileCodeWriterWithEncoding; +import org.apache.commons.io.FilenameUtils; import org.jsonschema2pojo.exception.GenerationException; import org.jsonschema2pojo.rules.RuleFactory; +import org.jsonschema2pojo.util.URLUtil; public class Jsonschema2Pojo { /** @@ -46,7 +49,7 @@ public class Jsonschema2Pojo { * @throws IOException * if the application is unable to read data from the source */ - public static void generate(GenerationConfig config) throws FileNotFoundException, IOException { + public static void generate(GenerationConfig config) throws IOException { Annotator annotator = getAnnotator(config); RuleFactory ruleFactory = createRuleFactory(config); @@ -61,13 +64,19 @@ public static void generate(GenerationConfig config) throws FileNotFoundExceptio removeOldOutput(config.getTargetDirectory()); } - for (Iterator sources = config.getSource(); sources.hasNext();) { - File source = sources.next(); - - if (source.isDirectory()) { - generateRecursive(config, mapper, codeModel, defaultString(config.getTargetPackage()), Arrays.asList(source.listFiles(config.getFileFilter()))); + for (Iterator sources = config.getSource(); sources.hasNext();) { + URL source = sources.next(); + + if (URLUtil.parseProtocol(source.toString()) == URLProtocol.FILE && URLUtil.getFileFromURL(source).isDirectory()) { + generateRecursive( + config, + mapper, + codeModel, + defaultString(config.getTargetPackage()), + Arrays.asList(URLUtil.getFileFromURL(source).listFiles(config.getFileFilter())) + ); } else { - mapper.generate(codeModel, getNodeName(source), defaultString(config.getTargetPackage()), source.toURI().toURL()); + mapper.generate(codeModel, getNodeName(source), defaultString(config.getTargetPackage()), source); } } @@ -96,12 +105,12 @@ private static RuleFactory createRuleFactory(GenerationConfig config) { } } - private static void generateRecursive(GenerationConfig config, SchemaMapper mapper, JCodeModel codeModel, String packageName, List schemaFiles) throws FileNotFoundException, IOException { + private static void generateRecursive(GenerationConfig config, SchemaMapper mapper, JCodeModel codeModel, String packageName, List schemaFiles) throws IOException { Collections.sort(schemaFiles); for (File child : schemaFiles) { if (child.isFile()) { - mapper.generate(codeModel, getNodeName(child), defaultString(packageName), child.toURI().toURL()); + mapper.generate(codeModel, getNodeName(child.toURI().toURL()), defaultString(packageName), child.toURI().toURL()); } else { generateRecursive(config, mapper, codeModel, packageName + "." + child.getName(), Arrays.asList(child.listFiles(config.getFileFilter()))); } @@ -133,7 +142,12 @@ private static Annotator getAnnotator(GenerationConfig config) { factory.getAnnotator(config.getCustomAnnotator())); } - private static String getNodeName(File file) { - return substringBeforeLast(file.getName(), "."); + private static String getNodeName(URL file) { + try { + return substringBeforeLast(FilenameUtils.getBaseName(URLDecoder.decode(file.toString(), "UTF-8")), "."); + } catch (UnsupportedEncodingException e) { + throw new IllegalArgumentException(String.format("Unable to generate node name from URL: %s", file.toString()), e); + } + } } diff --git a/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/URLProtocol.java b/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/URLProtocol.java new file mode 100644 index 000000000..57beccac0 --- /dev/null +++ b/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/URLProtocol.java @@ -0,0 +1,47 @@ +/** + * Copyright ¬© 2010-2014 Nokia + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jsonschema2pojo; + +public enum URLProtocol { + FILE("file"), + RESOURCE("resource"), + JAVA("java"), + CLASSPATH("classpath"), + HTTP("http"), + HTTPS("https"), + NO_PROTOCOL(""); + + private String protocol; + + URLProtocol(final String protocol) { + this.protocol = protocol; + } + + public String getProtocol() { + return protocol; + } + + public static URLProtocol fromString(final String input) { + for (URLProtocol protocol : URLProtocol.values()) { + if (protocol.getProtocol().equalsIgnoreCase(input)) { + return protocol; + } + } + // default to file + return NO_PROTOCOL; + } +} diff --git a/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/util/URLUtil.java b/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/util/URLUtil.java new file mode 100644 index 000000000..9d12ee57d --- /dev/null +++ b/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/util/URLUtil.java @@ -0,0 +1,54 @@ +/** + * Copyright ¬© 2010-2014 Nokia + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jsonschema2pojo.util; + +import org.apache.commons.lang.StringUtils; +import org.jsonschema2pojo.URLProtocol; + +import java.io.File; +import java.net.MalformedURLException; +import java.net.URI; +import java.net.URISyntaxException; +import java.net.URL; + +public class URLUtil { + + public static URLProtocol parseProtocol(String input) { + return URLProtocol.fromString(StringUtils.substringBefore(input, ":")); + } + + public static URL parseURL(String input) { + try { + switch (parseProtocol(input)) { + case NO_PROTOCOL: + return new File(input).toURI().toURL(); + default: + return URI.create(input).toURL(); + } + } catch (MalformedURLException e) { + throw new IllegalArgumentException(String.format("Unable to parse source: %s", input), e); + } + } + + public static File getFileFromURL(URL url) { + try { + return new File(url.toURI()); + } catch (URISyntaxException e) { + throw new IllegalArgumentException(String.format("URL contains an invalid URI syntax: %s", url), e); + } + } +} diff --git a/jsonschema2pojo-gradle-plugin/src/main/groovy/org/jsonschema2pojo/gradle/JsonSchemaExtension.groovy b/jsonschema2pojo-gradle-plugin/src/main/groovy/org/jsonschema2pojo/gradle/JsonSchemaExtension.groovy index 3a5f37f94..e3e86cd91 100644 --- a/jsonschema2pojo-gradle-plugin/src/main/groovy/org/jsonschema2pojo/gradle/JsonSchemaExtension.groovy +++ b/jsonschema2pojo-gradle-plugin/src/main/groovy/org/jsonschema2pojo/gradle/JsonSchemaExtension.groovy @@ -15,7 +15,6 @@ */ package org.jsonschema2pojo.gradle -import java.util.Map import org.jsonschema2pojo.AnnotationStyle import org.jsonschema2pojo.Annotator import org.jsonschema2pojo.AllFileFilter @@ -85,8 +84,12 @@ public class JsonSchemaExtension implements GenerationConfig { } @Override - public Iterator getSource() { - sourceFiles.iterator() + public Iterator getSource() { + def urlList = [] + for (source in sourceFiles) { + urlList.add(source.toURI().toURL()) + } + urlList.iterator() } public void setSource(Iterable files) { diff --git a/jsonschema2pojo-integration-tests/src/test/java/org/jsonschema2pojo/integration/RegressionIT.java b/jsonschema2pojo-integration-tests/src/test/java/org/jsonschema2pojo/integration/RegressionIT.java index 363e92565..8ea39deaa 100644 --- a/jsonschema2pojo-integration-tests/src/test/java/org/jsonschema2pojo/integration/RegressionIT.java +++ b/jsonschema2pojo-integration-tests/src/test/java/org/jsonschema2pojo/integration/RegressionIT.java @@ -20,9 +20,8 @@ import static org.jsonschema2pojo.integration.util.CodeGenerationHelper.*; import static org.junit.Assert.*; -import java.io.File; import java.net.MalformedURLException; -import java.util.HashMap; +import java.util.Collections; import org.junit.Test; @@ -32,10 +31,7 @@ public class RegressionIT { @SuppressWarnings("rawtypes") public void pathWithSpacesInTheNameDoesNotFail() throws ClassNotFoundException, MalformedURLException { - File file = new File("src/test/resources/schema/regression/spaces in path.json"); - - File sourcesDirectory = generate(file.toURI().toURL(), "com.example", new HashMap()); - ClassLoader resultsClassLoader = compile(sourcesDirectory); + ClassLoader resultsClassLoader = generateAndCompile("/schema/regression/spaces in path.json", "com.example", Collections.emptyMap()); Class generatedType = resultsClassLoader.loadClass("com.example.SpacesInPath"); assertThat(generatedType, is(notNullValue())); diff --git a/jsonschema2pojo-integration-tests/src/test/java/org/jsonschema2pojo/integration/util/CodeGenerationHelper.java b/jsonschema2pojo-integration-tests/src/test/java/org/jsonschema2pojo/integration/util/CodeGenerationHelper.java index 031620d1d..995ff6c72 100644 --- a/jsonschema2pojo-integration-tests/src/test/java/org/jsonschema2pojo/integration/util/CodeGenerationHelper.java +++ b/jsonschema2pojo-integration-tests/src/test/java/org/jsonschema2pojo/integration/util/CodeGenerationHelper.java @@ -39,6 +39,7 @@ import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.project.MavenProject; import org.jsonschema2pojo.maven.Jsonschema2PojoMojo; +import org.jsonschema2pojo.util.URLUtil; public class CodeGenerationHelper { @@ -85,7 +86,7 @@ public static void generate(final URL schema, final String targetPackage, final @SuppressWarnings("serial") Jsonschema2PojoMojo pluginMojo = new TestableJsonschema2PojoMojo().configure(new HashMap() { { - put("sourceDirectory", new File(schema.toURI())); + put("sourceDirectory", URLUtil.getFileFromURL(schema).getPath()); put("outputDirectory", outputDirectory); put("project", getMockProject()); put("targetPackage", targetPackage); @@ -94,8 +95,6 @@ public static void generate(final URL schema, final String targetPackage, final }); pluginMojo.execute(); - } catch (URISyntaxException e) { - throw new RuntimeException(e); } catch (MojoExecutionException e) { throw new RuntimeException(e); } catch (DependencyResolutionRequiredException e) { diff --git a/jsonschema2pojo-maven-plugin/src/main/java/org/jsonschema2pojo/maven/Jsonschema2PojoMojo.java b/jsonschema2pojo-maven-plugin/src/main/java/org/jsonschema2pojo/maven/Jsonschema2PojoMojo.java index af2a96c85..84cf80a69 100644 --- a/jsonschema2pojo-maven-plugin/src/main/java/org/jsonschema2pojo/maven/Jsonschema2PojoMojo.java +++ b/jsonschema2pojo-maven-plugin/src/main/java/org/jsonschema2pojo/maven/Jsonschema2PojoMojo.java @@ -21,9 +21,14 @@ import java.io.File; import java.io.FileFilter; import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URI; +import java.net.URL; +import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.Iterator; +import java.util.List; import org.apache.maven.artifact.DependencyResolutionRequiredException; import org.apache.maven.plugin.AbstractMojo; @@ -38,6 +43,7 @@ import org.jsonschema2pojo.NoopAnnotator; import org.jsonschema2pojo.SourceType; import org.jsonschema2pojo.rules.RuleFactory; +import org.jsonschema2pojo.util.URLUtil; /** * When invoked, this goal reads one or more getSource() { + public Iterator getSource() { if (null != sourceDirectory) { - return Collections.singleton(sourceDirectory).iterator(); + return Collections.singleton(URLUtil.parseURL(sourceDirectory)).iterator(); + } + List sourceURLs = new ArrayList(); + for (String source : sourcePaths) { + sourceURLs.add(URLUtil.parseURL(source)); } - return Arrays.asList(sourcePaths).iterator(); + return sourceURLs.iterator(); } @Override @@ -590,11 +617,12 @@ boolean filteringEnabled() { FileFilter createFileFilter() throws MojoExecutionException { try { + URL urlSource = URLUtil.parseURL(sourceDirectory); return new MatchPatternsFileFilter.Builder() .addIncludes(includes) .addExcludes(excludes) .addDefaultExcludes() - .withSourceDirectory(sourceDirectory.getCanonicalPath()) + .withSourceDirectory(URLUtil.getFileFromURL(urlSource).getCanonicalPath()) .withCaseSensitive(false) .build(); } catch (IOException e) { diff --git a/jsonschema2pojo-maven-plugin/src/test/java/org/jsonschema2pojo/maven/MatchPatternsFileFilterTest.java b/jsonschema2pojo-maven-plugin/src/test/java/org/jsonschema2pojo/maven/MatchPatternsFileFilterTest.java index 74dc6b5cb..cd7901285 100644 --- a/jsonschema2pojo-maven-plugin/src/test/java/org/jsonschema2pojo/maven/MatchPatternsFileFilterTest.java +++ b/jsonschema2pojo-maven-plugin/src/test/java/org/jsonschema2pojo/maven/MatchPatternsFileFilterTest.java @@ -16,16 +16,16 @@ package org.jsonschema2pojo.maven; -import static org.hamcrest.MatcherAssert.*; -import static org.hamcrest.CoreMatchers.*; +import org.jsonschema2pojo.maven.MatchPatternsFileFilter; +import org.junit.Before; +import org.junit.Test; import java.io.File; import java.io.IOException; -import org.junit.Before; -import org.junit.Test; - import static java.util.Arrays.asList; +import static org.hamcrest.CoreMatchers.*; +import static org.hamcrest.MatcherAssert.assertThat; public class MatchPatternsFileFilterTest { diff --git a/pom.xml b/pom.xml index 1f08db905..568daee7b 100644 --- a/pom.xml +++ b/pom.xml @@ -303,7 +303,6 @@ commons-io commons-io 2.4 - test commons-lang