Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Rule Logger #1040

Merged
merged 32 commits into from
Nov 19, 2019
Merged
Show file tree
Hide file tree
Changes from 31 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
ed63237
#113 Create RuleLogger interface and implementations.
ddcruver Nov 5, 2019
b92a9ab
#113 Create RuleLogger implementation for each factory and assign the…
ddcruver Nov 5, 2019
c4ffa94
#113 Move some test dependencies out of the compile scope.
ddcruver Nov 5, 2019
8365804
#113 Fix an issue where script/jar/lib were assumed to be all togethe…
ddcruver Nov 5, 2019
71c4632
#113 Add RuleLogger mocking to some tests.
ddcruver Nov 5, 2019
e8f542c
#113 Add SLF4J binding for gradle plugin tests.
ddcruver Nov 5, 2019
82c04fd
#1040 Remove explicit scope in test dependencies that are already set…
ddcruver Nov 6, 2019
fc3e4da
#1040 Use slf4j instead of gradle logger
ddcruver Nov 6, 2019
ab83f5c
#1040 Use slf4j instead of gradle logger - fix log statement
ddcruver Nov 6, 2019
1cb089f
#1040 Move simplelogger.properties to classpath.
ddcruver Nov 6, 2019
5867a0e
#1040 Try to get CI Build working.
ddcruver Nov 6, 2019
c272508
#1040 Try to get CI Build working. Upgrade Groovy version.
ddcruver Nov 6, 2019
34a6888
#1040 Remove pushd/popd to not mess with current working directory. …
ddcruver Nov 6, 2019
1772deb
#1040 Try deleting gradle-2.3-bin to fix org.gradle.tooling.GradleCon…
ddcruver Nov 6, 2019
bd6c9a0
#1040 Fix outdated references and spelling errors.
ddcruver Nov 6, 2019
2faea92
#1040 Try to get CI Build working.
ddcruver Nov 6, 2019
f70d0cf
#1040 Try to get CI Build working. Using eclipse plugin.
ddcruver Nov 6, 2019
2ad7943
#1040 Try to get CI Build working. Force it to use https.
ddcruver Nov 6, 2019
268ff15
#1040 Switch back to using Gradle framework logger.
ddcruver Nov 6, 2019
4e8933c
#1040 Try build without to maven builds.
ddcruver Nov 6, 2019
1605a54
#1040 Remove switch in AntRuleLogger to address PR comment.
ddcruver Nov 6, 2019
6328cdb
#1040 Revert changes to jars classpath and scripts to avoid breaking …
ddcruver Nov 6, 2019
eb612ac
#1040 Remove SLFJ from CLI module.
ddcruver Nov 7, 2019
a6174e1
#1040 Add is enable checks to RuleLogger interface to mimic what SLFJ…
ddcruver Nov 7, 2019
154b3db
#1040 Fix some instances of hardcoded "UTF-8"
ddcruver Nov 7, 2019
156f35e
#1040 Cleanup Travis CI integration since we resolve the Gradle downl…
ddcruver Nov 7, 2019
d363ccc
#1040 Convert bat file back to Windows line endings.
ddcruver Nov 7, 2019
a069661
#1040 Add note in description that if print-log-levels option is choo…
ddcruver Nov 7, 2019
63a1a70
#1040 Add Batch files to .gitattributes so it is always treated as CRLF.
ddcruver Nov 7, 2019
44472e8
#1040 Remove simplelogger.properties because we are just going to use…
ddcruver Nov 7, 2019
222d2fb
#1040 Renormalize jsonschema2pojo.bat
ddcruver Nov 7, 2019
646d9f8
#1040 Remove .gitattributes and revert jsonschema2pojo.bat.
ddcruver Nov 15, 2019
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
6 changes: 6 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

# Batch Scripts should always be using Windows line endings.
*.bat text eol=crlf

# Shell Scripts should always be using Linux line endings.
*.sh text eol=lf
17 changes: 14 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
language: java
script: "mvn verify"
jdk:
- openjdk8
os: linux

jdk: openjdk8

before_cache:
- rm -f $HOME/.gradle/caches/modules-2/modules-2.lock
- rm -fr $HOME/.gradle/caches/*/plugin-resolution/
- rm -fr $HOME/.gradle/caches/*/scripts/

cache:
directories:
- "$HOME/.m2"
- "$HOME/.gradle/caches/"
- "$HOME/.gradle/wrapper/"

script:
- mvn verify
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the reason for install then verify?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was trying to resolve the build issues and found this commit (81adfe7) and it mentioned that CI tests might be broken unless do a build then do a test build.

@ben-manes Is this unnecessary now?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might be necessary with the eclipse-groovy-compiler. I will try removing it.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That commit comment wrt CI failure was a one-time breakage and no longer relevant. Just required a clean if I recall correctly.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@joelittlejohn I have already removed the extra build and haven't notice any problems.
@ben-manes Thanks for your input.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I think all the changes in this file can be reverted, is that right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have removed the hacky gradle bin and double building stuff from Travis CI configuration but left in the caching.

Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/*
* Copyright © 2010-2017 Nokia
* <p>
* 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
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* 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.ant;

import org.apache.tools.ant.Project;
import org.jsonschema2pojo.AbstractRuleLogger;

public class AntRuleLogger extends AbstractRuleLogger {

private static final String LEVEL_PREFIX = "[";
private static final String LEVEL_SUFFIX = "] ";
private static final String DEBUG_LEVEL_PREFIX = LEVEL_PREFIX + "DEBUG" + LEVEL_SUFFIX;
private static final String ERROR_LEVEL_PREFIX = LEVEL_PREFIX + "ERROR" + LEVEL_SUFFIX;
private static final String INFO_LEVEL_PREFIX = LEVEL_PREFIX + "INFO" + LEVEL_SUFFIX;
private static final String TRACE_LEVEL_PREFIX = LEVEL_PREFIX + "TRACE" + LEVEL_SUFFIX;
private static final String WARN_LEVEL_PREFIX = LEVEL_PREFIX + "WARN" + LEVEL_SUFFIX;

private final Jsonschema2PojoTask task;

public AntRuleLogger(Jsonschema2PojoTask jsonschema2PojoTask) {
this.task = jsonschema2PojoTask;
}

@Override
public boolean isDebugEnabled() {
return true;
}

@Override
public boolean isErrorEnabled() {
return true;
}

@Override
public boolean isInfoEnabled() {
return true;
}

@Override
public boolean isTraceEnabled() {
return true;
}

@Override
public boolean isWarnEnabled() {
return true;
}

protected void doDebug(String msg) {
log(msg, Project.MSG_DEBUG, DEBUG_LEVEL_PREFIX);
}

protected void doError(String msg) {
log(msg, Project.MSG_ERR, ERROR_LEVEL_PREFIX);
}

protected void doInfo(String msg) {
log(msg, Project.MSG_INFO, INFO_LEVEL_PREFIX);
}

protected void doTrace(String msg) {
log(msg, Project.MSG_VERBOSE, TRACE_LEVEL_PREFIX);
}

protected void doWarn(String msg) {
log(msg, Project.MSG_WARN, WARN_LEVEL_PREFIX);
}

private void log(String msg, int level, String levelPrefix) {
if (task != null && task.getProject() != null) {
task.getProject().log(msg, level);
} else {
System.err.println(levelPrefix + msg);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import org.jsonschema2pojo.Jsonschema2Pojo;
import org.jsonschema2pojo.Language;
import org.jsonschema2pojo.NoopAnnotator;
import org.jsonschema2pojo.RuleLogger;
import org.jsonschema2pojo.SourceSortOrder;
import org.jsonschema2pojo.SourceType;
import org.jsonschema2pojo.URLProtocol;
Expand Down Expand Up @@ -242,8 +243,10 @@ public void execute() throws BuildException {
ClassLoader extendedClassloader = buildExtendedClassloader();
Thread.currentThread().setContextClassLoader(extendedClassloader);

RuleLogger ruleLogger = new AntRuleLogger(this);

try {
Jsonschema2Pojo.generate(this);
Jsonschema2Pojo.generate(this, ruleLogger);
} catch (IOException e) {
throw new BuildException("Error generating classes from JSON Schema file(s) " + source, e);
}
Expand Down
10 changes: 5 additions & 5 deletions jsonschema2pojo-cli/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@
<configuration>
<archive>
<manifest>
<classpathPrefix>./</classpathPrefix>
<addClasspath>true</addClasspath>
<classpathPrefix>./</classpathPrefix>
<mainClass>org.jsonschema2pojo.cli.Jsonschema2PojoCLI</mainClass>
</manifest>
</archive>
Expand All @@ -61,9 +61,6 @@
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.1.1</version>
<configuration>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
</configuration>
<executions>
<execution>
<phase>package</phase>
Expand All @@ -72,6 +69,7 @@
</goals>
<configuration>
<includeScope>runtime</includeScope>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
ddcruver marked this conversation as resolved.
Show resolved Hide resolved
</configuration>
</execution>
</executions>
Expand Down Expand Up @@ -111,14 +109,17 @@
<artifactId>jsonschema2pojo-core</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>com.beust</groupId>
<artifactId>jcommander</artifactId>
</dependency>

<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
Expand All @@ -132,5 +133,4 @@
<artifactId>mockito-all</artifactId>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
import org.jsonschema2pojo.NoopAnnotator;
import org.jsonschema2pojo.SourceSortOrder;
import org.jsonschema2pojo.SourceType;
import org.jsonschema2pojo.cli.CommandLineLogger.LogLevel;
import org.jsonschema2pojo.cli.CommandLineLogger.LogLevelValidator;
import org.jsonschema2pojo.rules.RuleFactory;

import com.beust.jcommander.JCommander;
Expand Down Expand Up @@ -239,11 +241,16 @@ public class Arguments implements GenerationConfig {

@Parameter(names = { "-ftm", "--format-type-mapping" }, description = "Mapping from format identifier to type: <format>:<fully.qualified.Type>.", variableArity = true)
private List<String> formatTypeMapping = new ArrayList<>();


@Parameter(names = { "-log" }, description = "Configure log level. Defaults to info. Available options are: off, error, warn, info, debug, trace", validateWith = LogLevelValidator.class )
private String logLevel = CommandLineLogger.DEFAULT_LOG_LEVEL;

@Parameter(names = {"--print-log-levels"}, description = "Prints available log levels and exit.")
private boolean printLogLevels = false;

private static final int EXIT_OKAY = 0;
private static final int EXIT_ERROR = 1;


/**
* Parses command line arguments and populates this command line instance.
* <p>
Expand Down Expand Up @@ -302,6 +309,10 @@ public boolean isIncludeTypeInfo()
return includeTypeInfo;
}

public String getLogLevel() {
return logLevel;
}

@Override
public boolean isUseInnerClassBuilders() {
return useInnerClassBuilders;
Expand Down Expand Up @@ -468,6 +479,10 @@ public boolean isConstructorsRequiredPropertiesOnly() {
return constructorsRequiredPropertiesOnly;
}

public boolean isPrintLogLevels() {
return printLogLevels;
}

@Override
public boolean isIncludeRequiredPropertiesConstructor() { return includeRequiredPropertiesConstructor; }

Expand Down
Loading