Skip to content

Commit

Permalink
Use gradle-one-jar plugin; create main() skeleton
Browse files Browse the repository at this point in the history
Unfortunately, it appears that one-jar cannot be made _completely_ silent :/

Signed-off-by: Francis Galiegue <[email protected]>
  • Loading branch information
fge committed Apr 9, 2014
1 parent f60fd3f commit 90d7a2f
Show file tree
Hide file tree
Showing 3 changed files with 135 additions and 15 deletions.
34 changes: 19 additions & 15 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,21 @@
*
* https://github.com/spring-projects/gradle-plugins/tree/master/propdeps-plugin
*/
//buildscript {
// repositories {
// mavenCentral();
buildscript {
repositories {
mavenCentral();
// maven {
// url "http://repo.springsource.org/plugins-release";
// }
// }
// dependencies {
// classpath(group: "eu.appsatori", name: "gradle-fatjar-plugin",
// version: "0.2-rc2");
}
dependencies {
classpath(group: "com.github.rholder", name: "gradle-one-jar",
version: "1.0.4");
// classpath(group: "org.springframework.build.gradle",
// name: "propdeps-plugin", version: "0.0.5");
// }
//};
//
}
};

//configure(allprojects) {
// apply(plugin: "propdeps");
// apply(plugin: "propdeps-maven");
Expand All @@ -59,9 +59,9 @@ apply(plugin: "java");
apply(plugin: "maven");
apply(plugin: "signing");
apply(plugin: "osgi");
//apply(plugin: "fatjar");
apply(plugin: "idea");
apply(plugin: "eclipse");
apply(plugin: "gradle-one-jar");

apply(from: "project.gradle");

Expand Down Expand Up @@ -121,15 +121,19 @@ task javadocJar(type: Jar, dependsOn: copyDocFiles) {
from javadoc.destinationDir;
}

//fatJar {
// classifier = "full";
//}
task fullJar(type: OneJar) {
mainClass = "com.github.fge.jsonschema.main.Main";
mergeManifestFromJar = true;
archiveName = "jsonschema.jar";
manifest {
attributes 'One-Jar-Silent': true;
}
}

artifacts {
archives jar;
archives sourcesJar;
archives javadocJar;
// bad idea: archives fatJar;
}

task wrapper(type: Wrapper) {
Expand Down
1 change: 1 addition & 0 deletions project.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ dependencies {
version: "5.9");
compile(group: "com.google.code.findbugs", name: "jsr305",
version: "2.0.1");
compile(group: "net.sf.jopt-simple", name: "jopt-simple", version: "4.6");
testCompile(group: "org.testng", name: "testng", version: "6.8.7") {
exclude(group: "junit", module: "junit");
exclude(group: "org.beanshell", module: "bsh");
Expand Down
115 changes: 115 additions & 0 deletions src/main/java/com/github/fge/jsonschema/main/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
/*
* Copyright (c) 2014, Francis Galiegue ([email protected])
*
* This software is dual-licensed under:
*
* - the Lesser General Public License (LGPL) version 3.0 or, at your option, any
* later version;
* - the Apache Software License (ASL) version 2.0.
*
* The text of both licenses is available under the src/resources/ directory of
* this project (under the names LGPL-3.0.txt and ASL-2.0.txt respectively).
*
* Direct link to the sources:
*
* - LGPL 3.0: https://www.gnu.org/licenses/lgpl-3.0.txt
* - ASL 2.0: http://www.apache.org/licenses/LICENSE-2.0.txt
*/

package com.github.fge.jsonschema.main;

import com.fasterxml.jackson.databind.JsonNode;
import com.github.fge.jackson.JsonLoader;
import com.github.fge.jsonschema.core.report.ProcessingReport;
import com.github.fge.jsonschema.processors.syntax.SyntaxValidator;
import com.google.common.base.Joiner;
import com.google.common.collect.Lists;
import joptsimple.HelpFormatter;
import joptsimple.OptionDescriptor;
import joptsimple.OptionException;
import joptsimple.OptionParser;
import joptsimple.OptionSet;

import java.io.IOException;
import java.util.Collection;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

public final class Main
{
private static final String LINE_SEPARATOR
= System.getProperty("line.separator", "\n");
private static final Joiner JOINER = Joiner.on(LINE_SEPARATOR);
private static final Joiner OPTIONS_JOINER = Joiner.on(", ");
private static final String HELP_PREAMBLE
= "Syntax: java -jar json-schema-validator-full.jar [options] " +
"file [file...]";

private static final HelpFormatter HELP = new HelpFormatter()
{
private final List<String> lines = Lists.newArrayList();

@Override
public String format(
final Map<String, ? extends OptionDescriptor> options)
{
final Set<OptionDescriptor> opts
= new LinkedHashSet<OptionDescriptor>(options.values());

lines.add(HELP_PREAMBLE);
lines.add("Options: ");

StringBuilder sb;

for (final OptionDescriptor descriptor: opts) {
if (descriptor.representsNonOptions())
continue;
sb = new StringBuilder(optionsToString(descriptor.options()))
.append(": ").append(descriptor.description());
lines.add(sb.toString());
}
return JOINER.join(lines) + LINE_SEPARATOR;
}

private String optionsToString(final Collection<String> names)
{
final List<String> list = Lists.newArrayList();
for (final String name: names)
list.add("--" + name);
return OPTIONS_JOINER.join(list);
}
};

public static void main(final String... args)
throws IOException
{
final OptionParser parser = new OptionParser();
parser.accepts("syntax",
"check the syntax of schema(s) given as argument(s)");
parser.formatHelpWith(HELP);
try {
final OptionSet optionSet = parser.parse(args);
if (optionSet.nonOptionArguments().isEmpty()) {
System.err.println("missing arguments");
parser.printHelpOn(System.err);
System.exit(2);
}
} catch (OptionException e) {
System.err.println(
"unrecognized option: " + e.options().iterator().next());
parser.printHelpOn(System.err);
System.exit(2);
}
final String input = "{" +
"\"$schema\": \"http://json-schema.org/draft-04/hyper-schema#\"," +
"\"links\":null" +
"}";
final JsonNode node = JsonLoader.fromString(input);
final JsonSchemaFactory factory = JsonSchemaFactory.byDefault();
final SyntaxValidator validator = factory.getSyntaxValidator();
final ProcessingReport report = validator.validateSchema(node);
System.out.println(report);
}
}

0 comments on commit 90d7a2f

Please sign in to comment.